Oliver Beckstein edited this page Sep 26, 2015 · 2 revisions


The starting point of this story is the TPRReader. TPR is a binary format file, generated by grompp, that contains the complete information about the simulation system.

Reading a TPR can be accomplished in at least two ways: read the file into python library and then reading data types one by one (give me a 3 floats, these i know will be the box size, then give me one int, this is the number of atoms). This approach is independent of gromacs libraries, however, it has to be adjusted everytime the TPR format changes (and it does so frequently).

The second approach is to wrap-around the gromacs libraries, using them to do the heavy lifting and only extract the information via a python interface to the C classes of gromacs.

Importantly, the wrapping of gromacs libraries opens up a broader (and more important) question than the TPR reader. Can we wrap all the gromacs libraries inside python?

TPRReader (xdrlib)

The TPR Reader uses 'xdrlib' to process a TPR file, reading out a primitive after a primitive (unpack_int(), unpackt_float()). Advantages: pure python, independent of GROMACS libraries, license it as you wish Disadvantages: need to update every time the gromacs format changes

grompy (ctypes)

GromPy https://github.com/GromPy/GromPy is broken for the most recent version of gromacs, highlighting the advantage of relying on GROMACS libraries to do the reading.


By Daniel Seeliger, I have no idea how this code can help us. http://wwwuser.gwdg.de/~dseelig/pymacs.html

pyxdr (cython)

From the forge of Erik Lindahl and David van der Spoel, comes a solution that's closest to ideal. A cython-based wrapper of the GROMACS library fragment, used to read a trajectory XDR files. Advantages: cython is now considered the proper way to wrap c libraries; for reasons that i don't understand, cython's more extendable than ctypes (grompy) https://bitbucket.org/mczwier/pyxdr


MDAnalysis uses a SWIG wrapper around the XTC/TRR library libxdr, see src/xdrfile, in particular libxdrfile.i. It allows seamless integration with Python/NumPy (but maybe the Cython approach is providing something similar?).

The general problem is that once you rely on the Gromacs libs you'll always have to recompile when a new Gromacs release comes along. What's really needed is a stable API to access the TPR data (and providing a stable API definition can only be done by the Gromacs developers).

Cython and distutils documentation





Project Information

GNU GPL v2 code license
Labels: python, molecular dynamics, analysis, DCD, CHARMM, LAMMPS, NAMD, Gromacs, computer simulation, atoms, coordinates, trajectory, XTC, Library, object-oriented
Core Developers


Release Notes
Guide for Developers
Google Summer of Code

Code of Conduct


@mdanalysis on Twitter
Downloads (PyPi)
Mailing Lists:
User discussion group
Developer mailing list

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.