Hi Sara, Please find the script as attachment. When saved, you have to make it executable using
chmod +x xtcrev.py Then it should work... Cheers, Tsjerk On Sat, Dec 31, 2011 at 5:59 AM, mohammad agha <mra...@yahoo.com> wrote: > Hi Tsjerk, > > Thank you for your reply, yes it is #!/usr/bin/env python > May I ask you to help me? > > Best Regards > Sara > > ________________________________ > From: Tsjerk Wassenaar <tsje...@gmail.com> > To: mohammad agha <mra...@yahoo.com>; Discussion list for GROMACS users > <gmx-users@gromacs.org> > Sent: Friday, December 30, 2011 8:06 PM > Subject: Re: Fw: [gmx-users] trjconv in martini > > Hi Sara, > Make sure the first line of the script is: > #!/usr/bin/env python > Cheers, > Tsjerk > > On Dec 30, 2011 1:25 PM, "mohammad agha" <mra...@yahoo.com> wrote: > > ----- Forwarded Message ----- From: mohammad agha <mra...@yahoo.com> To: > Tsjerk Wassenaar <tsjerkw@... > > -- > 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 > > > > > -- > 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
#!/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))
-- 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