4.12. Gromacs portable run input TPR format parser

The TPRParser module allows reading of a Gromacs portable run input file (a TPR file). At the moment, only atom information is read and used to build a minimal topology. Because the file format of the TPR file is changing rapidly, not all versions are currently supported. The known working versions and the approximate Gromacs release numbers are listed in the table TPR format versions.

TPR format versions and generations read by MDAnalysis.topology.TPRParser.parse().
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

For further discussion and notes see Issue 2. Also add a comment to Issue 2 if a new or different TPR file format version should be supported.

4.12.1. Classes

class MDAnalysis.topology.TPRParser.TPRParser(filename, universe=None, guess_bonds_mode=False, **kwargs)[source]

Read topology information from a Gromacs TPR_ file.

See also

MDAnalysis.topology.TPR

Standard arguments for a TopologyReader:

Arguments:
filename

name of the topology file

Keywords:
universe

Supply a Universe to the Parser. This then passes it to the atom instances that are created within parsers.

guess_bonds_mode
  • True: attempt to derive bonds from a distance search if no connectivity information is available or parsed
  • False: only load a list of atoms (and possibly identify residues and segments)
  • default: False
kwargs

Other keyword arguments that can vary with the specific format. These are stored as self.kwargs

close()

Close the trajectory file.

close_trajectory()

Specific implementation of trajectory closing.

convert_forces_from_native(force, inplace=True)

In-place conversion of forces array force from native units to base units.

By default, the input force is modified in place and also returned.

New in version 0.7.7.

convert_forces_to_native(force, inplace=True)

In-place conversion of force array force from base units to native units.

By default, the input force is modified in place and also returned.

New in version 0.7.7.

convert_pos_from_native(x, inplace=True)

In-place conversion of coordinate array x from native units to base units.

By default, the input x is modified in place and also returned.

Changed in version 0.7.5: Keyword inplace can be set to False so that a modified copy is returned unless no conversion takes place, in which case the reference to the unmodified x is returned.

convert_pos_to_native(x, inplace=True)

Conversion of coordinate array x from base units to native units.

By default, the input x is modified in place and also returned.

Changed in version 0.7.5: Keyword inplace can be set to False so that a modified copy is returned unless no conversion takes place, in which case the reference to the unmodified x is returned.

convert_time_from_native(t, inplace=True)

Convert time t from native units to base units.

By default, the input t is modified in place and also returned (although note that scalar values t are passed by value in Python and hence an in-place modification has no effect on the caller.)

Changed in version 0.7.5: Keyword inplace can be set to False so that a modified copy is returned unless no conversion takes place, in which case the reference to the unmodified x is returned.

convert_time_to_native(t, inplace=True)

Convert time t from base units to native units.

By default, the input t is modified in place and also returned. (Also note that scalar values t are passed by value in Python and hence an in-place modification has no effect on the caller.)

Changed in version 0.7.5: Keyword inplace can be set to False so that a modified copy is returned unless no conversion takes place, in which case the reference to the unmodified x is returned.

convert_velocities_from_native(v, inplace=True)

In-place conversion of velocities array v from native units to base units.

By default, the input v is modified in place and also returned.

New in version 0.7.5.

convert_velocities_to_native(v, inplace=True)

In-place conversion of coordinate array v from base units to native units.

By default, the input v is modified in place and also returned.

New in version 0.7.5.

parse()[source]

Parse a Gromacs TPR file into a MDAnalysis internal topology structure.

Returns:structure dict

4.12.2. Development notes

The TPR reader is a pure-python implementation of a basic TPR parser. Currently the following sections of the topology are parsed:

  • Atoms: number, name, type, resname, resid, segid, mass, charge, [residue, segment, radius, bfactor, resnum]
  • Bonds:
  • Angels:
  • Dihedrals:
  • Impropers:

Potential Bug: in the result of gmxdump, the “Proper Dih.:” section is actually a list of Improper Dih.

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

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 haven’t be resolved for those other than 58 and 73 (or gromacs version before 4.x)