Extract Last Frame from GROMACS trajectory

I was looking for a simple way to extract the last frame of a GROMACS trajectory. I came up with this script, which I ran to get the last frame of +3000 trajectories fast enough. I overlooked some opinions (here) that suggested dumping the whole thing and selecting the last frame. Instead, I went for an approach that parses out of the md.log file the last step (in my particular case, of the l-BFGS minimisation) and uses this together with trjconv‘s -dump flag.

To automate the script, I also used make_ndx to select whatever parts of the system I wanted to extract (otherwise it would ask me in each trajectory), as referenced here and here.

The script below needs obviously some modifications if you intend to use it, but gives a rough idea of how to. Suggestions? :)

Because WordPress doesn’t support text-wrapping, I’m saving the script in

—-> HERE <——

for whoever needs to peek into it.

The algorithm, if you can call it so, is the following:

1. Iterate each folder with traj.trr and conf.gro files in there

2. Use make_ndx on conf.gro with a pre-written text file with whatever input you would give to make_ndx (don’t forget the q for quit!) * and redirect the output to /dev/null

3. Use trjconv with the traj.trr and the -n flag with the traj.ndx that make_ndx created, redirecting the output to a file if needed so (best).

4. Copy the produced frame somewhere else (optional).

* Check this link for an alternative to that text file.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s