-
Notifications
You must be signed in to change notification settings - Fork 659
WrappingGromacsInPython
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?
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 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
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).
http://docs.cython.org/src/tutorial/clibraries.html
http://docs.cython.org/src/userguide/external_C_code.html
http://docs.cython.org/src/userguide/source_files_and_compilation.html