How to use xtcio.h?

GROMACS version: 2020.1
GROMACS modification: No
I did the simulation in gromacs and received a trajectory in .xtc format. I used to analyse it with gromacs tools, but now i need to write my own program. My coding skills are poor and I can’t understand how to use the xtcio.h to read .xtc files.

Now I’ve moved xtcio.h file to directory including .cpp file and .xtc file. And successfully included “xtcio.h” in my code. But i don’t understand how to use “open_xtc” and other functions from xtcio.h. I also can’t understand what to pass into “open_xtc” as XDR and mode arguments. As i understood
“read_first_xtc recieves” as arguments XDR, filename, and some adresses of variables witn natoms, step and others, is it?

Can someone provide me an example of code wich will open .xtc file or explain the work of “xtcio.h” functions? Thanks!

Hi,

there’s an example of using read_first_xtc and read_next_xtc in gmx dump. It’s located in src/gromacs/tools/dump.cpp. But you can’t just copy xtcio.h/cpp into your directory, they depend on other files in the Gromacs code.

A quick way to write a tool of your own that I’ve often used is to simply modify one of the built-in Gromacs tools. gmx vanhove (src/gromacs/gmxana/gmx_vanhove.cpp) is relatively friendly, unless you need that analysis tool installed. It has a simple loop that reads atom positions of a given trajectory. Replace whatever it is doing to those positions with your own analysis, cut out the rest, recompile the Gromacs distribution, et voila – a functioning analysis tool accessed through gmx vanhove!

The other tools in the same directory have plenty of examples for reading velocities, etc.

Regards,
Petter

Thank you very much, Peter! That’s a good idea, i’ll try it!

1 Like