[gmx-users] Fw: last frame in trr

Tsjerk Wassenaar tsjerkw at gmail.com
Mon Oct 4 13:44:05 CEST 2010


Hey Floris,

Here's a python script to write out the last frame from a .trr file:

#<PYTHON>

#!/usr/bin/env python

import sys

# Read a 32 bit unsigned int
def i(x): return sum([ord(x[j])<<(24-j*8) for j in range(4)])

# Open the file, find the end and go back
f = open(sys.argv[1],'rb')
f.seek(0,2)
eof = f.tell()
f.seek(0)

# Have to read frame by frame since a TRR may have differently sized frames
start = 0
while True:
    tag  = f.read(12)
    tag  = tag + f.read(i(tag[-4:]))
    num  = f.read(40)
    size = sum( [ i(num[j:j+4]) for j in range(0,40,4) ] ) + 20
    if (f.tell() + size >= eof):
        break # May be an incomplete frame
    f.seek(size,1)
    start = f.tell()

# Go back to the start of the last good frame
f.seek(start)
# Open the output file
if len(sys.argv) > 2:
    o = sys.argv[2]
else:
    o = sys.argv[1][:-4]+"-last.trr"
open(o,"w").write(f.read())

#</PYTHON>

Hope it helps,

Tsjerk

On Mon, Oct 4, 2010 at 11:31 AM, Floris Buelens
<floris_buelens at yahoo.com> wrote:
> sorry for the incomplete post before, believe it or not my cat was to blame.
>
> I want to write out only the final frames from a set of trr trajectories. This
> was discussed here with apparently only a workaround:
>
> http://www.mail-archive.com/gmx-users@gromacs.org/msg19545.html
>
> however intuitively it seems trjconv should do this with the -dump option
> documented like this:
>
> -dump        time   -1      Dump frame nearest specified time (ps)
>
> if I give e.g. -dump 999999 trjconv doesn't do what the description led me to
> believe but falls off the end with "WARNING no output". Wouldn't it make more
> sense for trjconv to write out the last frame?
> Thanks,
>
> Floris
>
>
>
>
> ----- Forwarded Message ----
> From: Floris Buelens <floris_buelens at yahoo.com>
> To: gmx-users at gromacs.org
> Sent: Mon, 4 October, 2010 11:24:57
> Subject: last frame in trr
>
> Hi,
>
> I want to write out only the final frames from a set of trr trajectories. This
> was discussed here:
>
> however intuitively it seems trjconv should do this with the -dump option
> documented like this:
>
> -dump        time   -1      Dump frame nearest specified time (ps)
>
> if I give e.g. -dump 999999 trjconv doesn't do what the description led me to
> believe
>
>
>
> --
> gmx-users mailing list    gmx-users at gromacs.org
> http://lists.gromacs.org/mailman/listinfo/gmx-users
> Please search the archive at http://www.gromacs.org/Support/Mailing_Lists/Search before posting!
> Please don't post (un)subscribe requests to the list. Use the
> www interface or send it to gmx-users-request at gromacs.org.
> Can't post? Read http://www.gromacs.org/Support/Mailing_Lists
>



-- 
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



More information about the gromacs.org_gmx-users mailing list