[gmx-developers] How to get the number of frames contained by an .xtc trajectory file??

Paolo Franz paolo.franz at gmail.com
Mon Jun 4 22:56:47 CEST 2012


Hi Tsjerk,
Thanks, but I don't really want to use a python script, I am doing this
from some c/c++ code. I think I figured out a way to do it, but I haven't
tested it yet:

i)    open the file
ii)   do a read_first_xtc
iii)  then get the file pointer positon from ftellg, which should be the
length of the frame in bytes;
iv)  place the file pointer at the end of the file with an fseek, then get
the length with an ftellg
v)   Divide the total length by the length of a frame and obtain the number
of written frames.

I am only wondering what to do when the length in bytes of the file is too
large for a long int!

On 4 June 2012 16:11, Tsjerk Wassenaar <tsjerkw at gmail.com> wrote:

> Hey Paolo,
>
> I think I posted a script for extracting a last frame before, but if I
> can't even find it myself... Here it is:
>
> #!/usr/bin/env python
>
> from struct import unpack
> import sys
>
> def i(x): return sum([ord(x[j])<<(24-j*8) for j in range(4)])
>
> f = open(sys.argv[1])
> tag = f.read(8)                   # Tag: magic number and number of atoms
> n = 92 + i(f.read(84)[-4:])       # Size of frame in bytes
>
> f.seek(-5*n/4, 2)                 # This should contain a complete frame
> frame = f.read()                  # Read the remaining part in
> frame = frame[frame.index(tag):]  # Find the tag
>
> # Open the output file
> if len(sys.argv) > 2:
>    o = sys.argv[2]
> else:
>    o = sys.argv[1][:-4]+"-last.xtc"
> open(o,"w").write(frame)
>
> ###
>
> Hope it helps. Cheers,
>
> Tsjerk
> On Mon, Jun 4, 2012 at 12:59 PM, Paolo Franz <paolo.franz at gmail.com>
> wrote:
> > Hello everybody!
> >
> > I am wondering how I can figure out the number of frames contained in an
> > .xtc file. Indeed, I need to read a particular frame of a trajectory and
> I
> > thought that the function
> > xtc_seek_frame(FILE * , int *, int *)
> > would return 0 if the frame was there and 1 when it was not. Instead, if
> I
> > call it with a frame outside the boundaries it seems to go into an
> infinite
> > loop. What I am doing wrong? Is there a way to read the last frame of an
> > .xtc file?
> >
> > Sincerely
> > Paolo
> >
> >
> >
> >
> > --
> > gmx-developers mailing list
> > gmx-developers at gromacs.org
> > http://lists.gromacs.org/mailman/listinfo/gmx-developers
> > Please don't post (un)subscribe requests to the list. Use the
> > www interface or send it to gmx-developers-request at gromacs.org.
>
>
>
> --
> Tsjerk A. Wassenaar, Ph.D.
>
> post-doctoral researcher
> Molecular Dynamics Group
> * Groningen Institute for Biomolecular Research and Biotechnology
> * Zernike Institute for Advanced Materials
> University of Groningen
> The Netherlands
> --
> gmx-developers mailing list
> gmx-developers at gromacs.org
> http://lists.gromacs.org/mailman/listinfo/gmx-developers
> Please don't post (un)subscribe requests to the list. Use the
> www interface or send it to gmx-developers-request at gromacs.org.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://maillist.sys.kth.se/pipermail/gromacs.org_gmx-developers/attachments/20120604/5d9aa26e/attachment.html>


More information about the gromacs.org_gmx-developers mailing list