Hi Eric,
On 11 Nov, 2014, at 20:43, Eric Smoll wrote:
> I see. I would like double precision coordinates, forces, etc. I started doing some digging and it seems that gromacs has a C library with the functions necessary to read and write trr files.
We based our XTC and TRR reader on libxdr but Manel added some significant improvements to what we now call libxdr2 (namely, fast seeking!). The code is under package/src/xdrfile in the distribution and you can browse it at
https://code.google.com/p/mdanalysis/source/browse/package#package%2Fsrc%2Fxdrfile
> When I look at the headers, the exported functions ("read_trr" and "write_trr") both return floats for the coordinates, forces, etc. Is this what you mean when you say I will have to add additional C-code? I need to implement versions of these functions that returns double precision values and then write a python wrapper using (for example) the ctypes module?
If you look at xdrfile_trr.h you see that coordinates are of type *rvec. In xdrfile.h,
typedef float rvec[DIM]
You would probably want to turn this into
typedef double rvec[DIM]
and also check that the rest of the code is compatible. You could then duplicate the exported routines and export them via the SWIG interface
https://code.google.com/p/mdanalysis/source/browse/package/src/xdrfile/libxdrfile2.i (which in my opinion makes it easy to create very pythonic wrappers).
Within MDAnalysis we actually assume that coordinate arrays are float32 or at least other cython/C-based code will only accept those but if you do not plan on using e.g. distance_array() then you should be fine.
If you come up with a solution that can be seamlessly integrated into MDAnalysis we're happy to consider it for a future release!