Re: Get number of timesteps from DCD via script

From: Bjoern Olausson (namdlist_at_googlemail.com)
Date: Tue Feb 08 2011 - 05:24:29 CST

On Monday 07 February 2011 19:53:56 Joshua D. Moore wrote:
> catdcd can tell you the number of frames in the trajectory
>
> http://www.ks.uiuc.edu/Development/MDTools/catdcd/
>
> The other information is written in the header of the dcd file. You can
> print that out if you wanted to using a simple C or fortran code.
>
> The format is here with one correct in that the the PBCs are written in
> double precision while the coordinates are in single precision (not double
> as is written on the page).
>
> http://www.ks.uiuc.edu/Research/vmd/plugins/molfile/dcdplugin.html
>
> The format can also be ascertained fairly easily from the plugin in the VMD
> source code.
>
> Josh
>
Interesting, thanks!

So when I understand the header correctly I can get NSET (Number of overall
frames?), integration time (DELTA), write out frequency (NSAVC) and the first
timestep (not sure about the meaning of ISTRT - step 1).

With these information every thing else I want is at ones hand :-)

Since I am a noob regarding C or Fortran I'll played around with python and
came up with the appended script. But after the "NSAVC" header, something pops
up which is not documented on the above website. Does anyone know what it
exactly refers to?
Furthermore the "DELTA" looks messed up. It should be 2.0 fs.

Any clue what went wrong?

http://paste.pocoo.org/show/FeirO5JuypU7XzrUmQtK/
----------------------------------------------------
#!/bin/env python
# -*- coding: utf-8 -*-
#
#

import sys, struct

#HDR NSET ISTRT NSAVC 5-ZEROS NATOM-NFREAT
DELTA 9-ZEROS
#`CORD' #files step 1 step interv. zeroes (zero)
                timestep (zeroes)
#C*4 INT INT INT 5INT INT
                DOUBLE 9INT
#==========================================================================
#NTITLE TITLE
#INT (=2) C*MAXTITL (=32)
#==========================================================================
#NATOM
##atoms
#INT
#==========================================================================
#X(I), I=1,NATOM (SINGLE)
#Y(I), I=1,NATOM
#Z(I), I=1,NATOM
#==========================================================================

f = open(sys.argv[1], 'rb')
HDR = struct.unpack('i4c',f.read(struct.calcsize('i4c')))
NSET = struct.unpack('i', f.read(struct.calcsize('i')))[0]
ISTART = struct.unpack('i', f.read(struct.calcsize('i')))[0]
NSAVC = struct.unpack('i', f.read(struct.calcsize('i')))[0]
##NOTE: The following seems not to be documented on
##NOTE: http://www.ks.uiuc.edu/Research/vmd/plugins/molfile/dcdplugin.html
UNDOC = struct.unpack('i', f.read(struct.calcsize('i')))[0]
ZEROS5 = struct.unpack('4i', f.read(struct.calcsize('4i')))
NFREAT = struct.unpack('i', f.read(struct.calcsize('i')))
DELTA = struct.unpack('d',f.read(struct.calcsize('d')))
ZEROS9 = struct.unpack('8i', f.read(struct.calcsize('8i')))

ISTOP = ISTART + (NSET * NSAVC)
NSTP = ISTOP - ISTART

print "%(ID)-13s %(DATA)s" %{"ID": "HDR:", "DATA": HDR}
print "%(ID)-13s %(DATA)i" %{"ID": "Coor Sets:", "DATA": NSET}
print "%(ID)-13s %(DATA)i" %{"ID": "First Step:", "DATA": ISTART}
print "%(ID)-13s %(DATA)i" %{"ID": "Save Int.:", "DATA": NSAVC}
print "%(ID)-13s %(DATA)i" %{"ID": "UNDOC:", "DATA": UNDOC}
print "%(ID)-13s %(DATA)s" %{"ID": "5-ZEROS:", "DATA": ZEROS5}
print "%(ID)-13s %(DATA)s" %{"ID": "NATOM-NFREAT:", "DATA": NFREAT}
print "%(ID)-13s %(DATA)s" %{"ID": "Int. Time:", "DATA": DELTA}
print "%(ID)-13s %(DATA)s" %{"ID": "9-ZEROS:", "DATA": ZEROS9}
print "\n%(ID)-13s %(DATA)i" %{"ID": "Last Step:", "DATA": ISTOP}
print "%(ID)-13s %(DATA)i" %{"ID": "Num Steps:", "DATA": NSTP}

----------------------------------------------------

Cheers and kind regards,
Bjoern

-- 
Bjoern Olausson
Martin-Luther-Universität Halle-Wittenberg 
Fachbereich Biochemie/Biotechnologie
Kurt-Mothes-Str. 3
06120 Halle/Saale
Phone: +49-345-55-24942

This archive was generated by hypermail 2.1.6 : Mon Dec 31 2012 - 23:19:47 CST