#!/usr/bin/env python

# Python compliant e-mail
# Save it as xtcrev.py

# Hi Thomas,

# Here's a piece of python code that reverses a trajectory.

### xtcrev.py: ###

#!/usr/bin/env python

# Reverse an XTC trajectory
#
# (c)2011 Tsjerk A. Wassenaar
#   University of Groningen
#

from struct import unpack
import sys
import os

def i(x): return sum([ord(x[j])<<(24-j*8) for j in range(4)])

def strseek(stream,s,bufsize=10000):
    v = len(s)
    x = stream.read(bufsize)
    n = 0
    while len(x) >= v:
        m = x.find(s)
        if m > -1:
            # If we found the tag, the position is the total length
            # read plus the index at which the tag was found
            n += m
            yield n
            # Now we strip the part up to and including the tag
            x = x[m+v:]
            n += v
        elif len(x) > v:
            # If the tag was not found, strip the string, keeping only
            # the last v-1 characters, as these could combine with the
            # next part to be read in.
            # n is incremented with the number of characters taken from
            # the current string x (len(x)-v+1)
            n += len(x)-v+1
            x = x[1-v:]
        if len(x) <= v:
            x += stream.read(bufsize)

# Get the tag to identify the start of a frame
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.close()

# Find all positions at which the tag is found and the frame lengths
frames  = [ i for i in strseek(open(sys.argv[1]),tag) ]
nf      = len(frames)
lengths = [ j-i for i,j in zip(frames,frames[1:]+[nf]) ]

# Reverse the lists
frames.reverse()
lengths.reverse()

# Write the frames in reversed order
f = open(sys.argv[1])
o = open(sys.argv[2],"w")
for pos,bytes in zip(frames,lengths):
    f.seek(pos)
    o.write(f.read(bytes))
f.close()
o.close()

sys.exit()





On Tue, May 17, 2011 at 6:05 PM, Thomas Schlesier <schl...@uni-mainz.de> wrote:
> Hi all,
> is it possible to mirror a trajectorie?
>
> I have done pulling simulations, where i first pulled two molecules apart
> and later used the pulled them together (starting form the last frame of the
> pulling-(apart)-simulation).
>
> Now want to calculate the rmsd of structures for the path. So i would like
> to compared first frame of pull-apart with last frame of pull-together ...
>
> Only way i could think of, would be to write the .xtc into individual
> .gro-files, then order them and finally put them together to the mirrored
> .xtc
> This should work, but probably there is an easier way of doing this?
>
> Greetings
> Thomas
> --
> gmx-users mailing list    gmx-users@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-requ...@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
--
gmx-users mailing list    gmx-users@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-requ...@gromacs.org.
Can't post? Read http://www.gromacs.org/Support/Mailing_Lists

Reply via email to