TPR (GROMACS run topology files)
Topology parser |
A GROMACS TPR file is a portable binary run input file. It contains both topology and coordinate information. However, MDAnalysis currently only reads topology information about atoms, bonds, dihedrals, and impropers; it does not read the coordinate information.
Important
Atom ids, residue resids, and molnums
GROMACS indexes atom numbers and residue numbers from 1 in user-readable files.
However, the MDAnalysis TPRParser creates atom ids
and residue resids
from 0.
This means that if your atom is numbered 3 in your GRO, ITP, or TOP file, it will have an Atom.id
of 2 in MDAnalysis.
Likewise, if your residue ALA has a residue number of 4 in your GRO file, it will have a Residue.resid
number of 3 in MDAnalysis.
Finally, molecules are also numbered from 0, in the attribute molnums
.
This will change in version 2.0.0. The TPRParser will number resids, ids, etc. from 1 to be consistent with other formats.
Atom indices
and residue resindices
are MDAnalysis derived and always index from 0, no matter the file type.
Supported versions
TPX format |
TPX generation |
Gromacs release |
read |
---|---|---|---|
?? |
?? |
3.3, 3.3.1 |
no |
58 |
17 |
4.0, 4.0.2, 4.0.3, 4.0.4, 4.0.5, 4.0.6, 4.0.7 |
yes |
73 |
23 |
4.5.0, 4.5.1, 4.5.2, 4.5.3, 4.5.4, 4.5.5 |
yes |
83 |
24 |
4.6, 4.6.1 |
yes |
100 |
26 |
5.0, 5.0.1, 5.0.2, 5.0.3,5.0.4, 5.0.5 |
yes |
103 |
26 |
5.1 |
yes |
110 |
26 |
2016 |
yes |
112 |
26 |
2018 |
yes |
116 |
26 |
2019 |
yes |
For further discussion and notes see Issue 2. Please open a new issue in the Issue Tracker when a new or different TPR file format version should be supported.
TPR specification
The TPR reader is a pure-python implementation of a basic TPR parser. Currently the following topology attributes are parsed:
Atoms: number, name, type, resname, resid, segid, chainID, mass, charge, [residue, segment, radius, bfactor, resnum, moltype]
Bonds
Angles
Dihedrals
Impropers
segid
and chainID
MDAnalysis gets the segment
and chainID
attributes from the TPR molblock
field.
Since TPR files are built from GROMACS topology files, molblock
fields get their names from the
compounds listed under the [ molecules ]
header. For example:
[ molecules ]
; Compound #mols
Protein_chain_A 1
Protein_chain_B 1
SOL 40210
So, the TPR will get 3 molblock
s: Protein_chain_A
, Protein_chain_B
and SOL
, while
MDAnalysis will set the segid
s to seg_{segment_index}_{molblock}
, thus:
seg_0_Protein_chain_A
, seg_1_Protein_chain_B
and seg_2_SOL
. On the other hand,
chainID
will be identical to molblock
unless molblock
is named “Protein_chain_XXX”,
in which case chainID
will be set to XXX
. Thus in this case the chainID
s will be:
A
, B
and SOL
.
Bonds
Bonded interactions available in Gromacs are described in the Gromacs manual. The following ones are used to build the topology (see Issue 463):
Directive |
Type |
Description |
---|---|---|
bonds |
1 |
|
bonds |
2 |
|
bonds |
3 |
|
bonds |
4 |
|
bonds |
5 |
|
bonds |
6 |
|
bonds |
7 |
|
bonds |
8 |
|
bonds |
9 |
|
bonds |
10 |
|
constraints |
1 |
|
constraints |
2 |
|
settles |
1 |
Directive |
Type |
Description |
---|---|---|
angles |
1 |
|
angles |
2 |
|
angles |
3 |
|
angles |
4 |
|
angles |
5 |
|
angles |
6 |
|
angles |
8 |
|
angles |
10 |
Directive |
Type |
Description |
---|---|---|
dihedrals |
1 |
|
dihedrals |
3 |
|
dihedrals |
5 |
|
dihedrals |
8 |
|
dihedrals |
9 |
|
dihedrals |
10 |
|
dihedrals |
11 |
Directive |
Type |
Description |
---|---|---|
dihedrals |
2 |
|
dihedrals |
4 |
Developer notes
This tpr parser is written according to the following files
gromacs_dir/src/kernel/gmxdump.c
gromacs_dir/src/gmxlib/tpxio.c
(the most important one)gromacs_dir/src/gmxlib/gmxfio_rw.c
gromacs_dir/src/gmxlib/gmxfio_xdr.c
gromacs_dir/include/gmxfiofio.h
or their equivalent in more recent versions of Gromacs.
The function read_tpxheader()
is based on the
TPRReaderDevelopment notes. Functions with names starting with
read_
or do_
are trying to be similar to those in
gmxdump.c
or tpxio.c
, those with extract_
are new.
Wherever fver_err(fver)
is used, it means the tpx version problem
has not been solved. Versions prior to Gromacs 4.0.x are not supported.