[gmx-users] box vectors

Tsjerk Wassenaar tsjerkw at gmail.com
Wed Dec 7 19:34:49 CET 2011


#!/usr/bin/env python

# Python compliant email -- Just save the content :)


"""

Hey :)

The neatest way is using python to extract them from the XTC file :)

"""

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]) ]
f       = open(sys.argv[1])
print (10*"%10s")%("Time","XX","XY","XZ","YX","YY","YZ","ZX","ZY","ZZ")
for i in frames:
    print (10*" %10.5f")%(f.seek(i) or unpack(">ffffffffff",f.read(52)[-40:]))

"""
Cheers,

Tsjerk
"""

"""

On Wed, Dec 7, 2011 at 7:29 PM, Justin A. Lemkul <jalemkul at vt.edu> wrote:
>
>
> Chandan Choudhury wrote:
>>
>>
>> Dear gmx_users,
>>
>> I am using gmx_4.0.7. I need to print the box vectors from the trajectory
>> of a simulated system. How can this be achieved? Can someone help me out?
>>
>
> Box vectors are stored in the .edr file.
>
> -Justin
>
> --
> ========================================
>
> Justin A. Lemkul
> Ph.D. Candidate
> ICTAS Doctoral Scholar
> MILES-IGERT Trainee
> Department of Biochemistry
> Virginia Tech
> Blacksburg, VA
> jalemkul[at]vt.edu | (540) 231-9080
> http://www.bevanlab.biochem.vt.edu/Pages/Personal/justin
>
> ========================================
> --
> 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