Re: Get number of timesteps from DCD via script

From: Andrew Emerson (a.emerson_at_cineca.it)
Date: Tue Feb 08 2011 - 08:00:07 CST

Dear Bjoern

I dont know python but comparing your script with the fortran program I
wrote some time ago,

http://www.ks.uiuc.edu/Research/namd/mailing_list/namd-l/8441.html

it looks as if you are lacking the box dimension information (an array
of 6 doubles).
As for the timestep DELTA I guess this depends on what units it has been
stored in - I suspect it is a reduced time step and has been divided by
some other quantity such as the system mass.

regards
Andy

On 2/8/2011 12:24 PM, Bjoern Olausson wrote:
> 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
>

-- 
Dr Andrew Emerson
CINECA (High Performance Systems)
via Magnanelli, 6/3
40033 Casalecchio di Reno (BO)-ITALY
tel: +39-051-6171653, fax: +39-051-6137273
e-mail: a.emerson_at_cineca.it

This archive was generated by hypermail 2.1.6 : Wed Feb 29 2012 - 15:56:36 CST