Previous Thread
Next Thread
Print Thread
DCD file format?
#4092 11/09/04 10:26 AM
Joined: Nov 2004
Posts: 2
A
ariock Offline OP
Forum Member
OP Offline
Forum Member
A
Joined: Nov 2004
Posts: 2
Does somebody have a complete description of the dcd file format?
I'm making a C++ programm that should read/write those files, but I cannot find any information on what must be in the different fields...

I'll apreciate any help. Thanks

Re: DCD file format?
ariock #4093 11/09/04 05:20 PM
Joined: Sep 2003
Posts: 8,501
rmv Online Content
Forum Member
Online Content
Forum Member
Joined: Sep 2003
Posts: 8,501
The CHARMM source code is the most authoritative reference, but the VMD program has also had some success reading these files.


Rick Venable
computational chemist

Re: DCD file format?
rmv #4094 11/10/04 08:33 AM
Joined: Nov 2004
Posts: 2
A
ariock Offline OP
Forum Member
OP Offline
Forum Member
A
Joined: Nov 2004
Posts: 2
Well, I cannot use CHARMM to produce or read these dcds, but I will look into source code to see if I can find informations... maybe could you give me a hint on where to search?

Re: DCD file format?
ariock #4095 11/10/04 11:25 PM
Joined: Sep 2003
Posts: 8,501
rmv Online Content
Forum Member
Online Content
Forum Member
Joined: Sep 2003
Posts: 8,501
Quote:

Well, I cannot use CHARMM to produce or read these dcds, but I will look into source code to see if I can find informations... maybe could you give me a hint on where to search?




A curious remark about not being able to use CHARMM to produce or read CHARMM trajectory files.

The Fortran code to read CHARMM trajectories is found in source/dynamc/dynio.src

For info on the VMD program, see http://www.ks.uiuc.edu/Research/vmd/


Rick Venable
computational chemist

Re: DCD file format?
ariock #4096 12/21/04 01:11 AM
Joined: Apr 2004
Posts: 4
Z
Forum Member
Offline
Forum Member
Z
Joined: Apr 2004
Posts: 4
ariock, how do you solve this problem finally? I am facing the same question. Thanks.

Re: DCD file format?
zjnjuct #4097 12/23/04 08:36 PM
Joined: Jan 2004
Posts: 4
P
Forum Member
Offline
Forum Member
P
Joined: Jan 2004
Posts: 4
below is the code i use to read DCD files.....

Most of this i decyphered by trial and error writing 4 byte words as integers and single fpns to spreadsheets and workin it out from there.

The formats a bit of a nitemare.... different for ewald files and regular, bigendian and littleendian written files, variable size header too. The below routines cope with most of this. Written in VBA... but essentially its basic.

The file format generally:
Header Xbytes
n x Frames blocks written as
frame header (contains crystal params for ewald, but not otherwise), all x coords, all y coords, all z coords.

Remember if you wanna read bigendian files on little endian machine you gotta reverse the byte order on yer 4byte words (see end routine)


Sub readlittleendian()

Dim temptext As String * 4
Dim title1 As String * 80
Dim title2 As String * 80
Dim tempint As Long
Dim tempsingle As Single
Dim tempdouble As Double
'THIS ONLY READ THE HEADER

Get #1, 1, temptext ' first block size 84
Get #1, 5, temptext ' checkcode "CORD"
Get #1, 9, dcdsteps ' coordinate steps in file
Get #1, 13, dcdstartingstep ' starting time step
Get #1, 17, dcdstepsbetweencoord ' timesteps between coord steps
Get #1, 45, dcdtimestep


Get #1, 93, tempint



' Get #1, 97, xxx ' no. of times 2 repeat title
Get #1, 101, title1 'first 80 str title
Get #1, 181, title2 '2nd 80 str title
' Get #1, 261, d1.Int 'end check byte 2nd block size 164
'Get #1, 265, d1.Int '265 checkcode 0004

'rountine needed to read atomcount from DCD file
'determine number of extra 80 char lines in dcdheader

If ewaldfile = False Then
noofextra80charlines = (dcdheadersize - 277) / 320
Else
noofextra80charlines = (dcdheadersize - 333) / 320
End If

Get #1, 277 - 8 + (noofextra80charlines * 320), atomcount 'atom no. in 269
If (atomcount = Sheets("atominfo").Cells(1, 1)) = False Then

Title = "atoms on sheet dont match those in DCD file: sheet" + Str(Sheets("atominfo").Cells(1, 1)) + " dcd " + Str(atomcount) 'dcd file incompatable with card file used
MsgBox (Title)
fileerror = True
Close #1
Close #2
Exit Sub
End If

'Get #1, 277, blocksize
Get #1, dcdheadersize, tempint

Get #1, dcdheadersize + (X * (atomcount + 2) * 12), tempint


Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(dcdfilename)
'f.size is the file size of the target file
If ewaldfile = True Then
noofframes = Int((f.Size - (276 + (noofextra80charlines * 320))) / ((atomcount + 2) * 12 + 56))
Else
noofframes = Int((f.Size - (276 + (noofextra80charlines * 320))) / ((atomcount + 2) * 12))
End If

ReDim frameholder(atomcount, 3)
Close #2



End Sub

Sub readlittleendianframeread(ascube)
Dim tempsingle As Single

If ewaldfile = True Then
'read in x coord
For X = 1 To atomcount
Get #1, (dcdheadersize + ((processingframe - 1) * (atomcount + 2) * 12) + X * 4 + (processingframe - 1) * 56), tempsingle
frameholder(X, 1) = tempsingle
If ascube = True Then
If frameholder(X, 1) < -boxsize / 2 Then frameholder(X, 1) = frameholder(X, 1) + boxsize
If frameholder(X, 1) > boxsize / 2 Then frameholder(X, 1) = frameholder(X, 1) - boxsize
End If
Next X

'read in y coord
For X = 1 To atomcount
Get #1, (dcdheadersize + (atomcount + 2) * 4 + ((processingframe - 1) * (atomcount + 2) * 12 + (processingframe - 1) * 56) + X * 4), tempsingle
frameholder(X, 2) = tempsingle
If ascube = True Then
If frameholder(X, 2) < -boxsize / 2 Then frameholder(X, 2) = frameholder(X, 2) + boxsize
If frameholder(X, 2) > boxsize / 2 Then frameholder(X, 2) = frameholder(X, 2) - boxsize
End If
Next X

'read in z coord
For X = 1 To atomcount
Get #1, (dcdheadersize + (atomcount + 2) * 8 + ((processingframe - 1) * (atomcount + 2) * 12 + (processingframe - 1) * 56) + X * 4), tempsingle
frameholder(X, 3) = tempsingle
If ascube = True Then
If frameholder(X, 3) < -boxsize / 2 Then frameholder(X, 3) = frameholder(X, 3) + boxsize
If frameholder(X, 3) > boxsize / 2 Then frameholder(X, 3) = frameholder(X, 3) - boxsize
End If
Next X

Else 'regular file... not ewald
'read in x coord
For X = 1 To atomcount
Get #1, (dcdheadersize + ((processingframe - 1) * (atomcount + 2) * 12) + X * 4), tempsingle
frameholder(X, 1) = tempsingle
If ascube = True Then
If frameholder(X, 1) < -boxsize / 2 Then frameholder(X, 1) = frameholder(X, 1) + boxsize
If frameholder(X, 1) > boxsize / 2 Then frameholder(X, 1) = frameholder(X, 1) - boxsize
End If
Next X

'read in y coord
For X = 1 To atomcount
Get #1, (dcdheadersize + (atomcount + 2) * 4 + ((processingframe - 1) * (atomcount + 2) * 12) + X * 4), tempsingle
frameholder(X, 2) = tempsingle
If ascube = True Then
If frameholder(X, 2) < -boxsize / 2 Then frameholder(X, 2) = frameholder(X, 2) + boxsize
If frameholder(X, 2) > boxsize / 2 Then frameholder(X, 2) = frameholder(X, 2) - boxsize
End If
Next X

'read in z coord
For X = 1 To atomcount
Get #1, (dcdheadersize + (atomcount + 2) * 8 + ((processingframe - 1) * (atomcount + 2) * 12) + X * 4), tempsingle
frameholder(X, 3) = tempsingle
If ascube = True Then
If frameholder(X, 3) < -boxsize / 2 Then frameholder(X, 3) = frameholder(X, 3) + boxsize
If frameholder(X, 3) > boxsize / 2 Then frameholder(X, 3) = frameholder(X, 3) - boxsize
End If
Next X
End If
End Sub


Function read4bword(positionofword, typeofvar)
Dim tempbyte As datatype
Get #1, (positionofword), tempbyte.b1
Get #1, (positionofword + 1), tempbyte.b2
Get #1, (positionofword + 2), tempbyte.b3
Get #1, (positionofword + 3), tempbyte.b4
Put #2, 1, tempbyte.b4
Put #2, 2, tempbyte.b3
Put #2, 3, tempbyte.b2
Put #2, 4, tempbyte.b1

If typeofvar = "int" Then Get #2, 1, tempbyte.int: read4bword = tempbyte.int
If typeofvar = "single" Then Get #2, 1, tempbyte.single: read4bword = tempbyte.single

End Function

Re: DCD file format?
Proteios #4098 12/23/04 10:50 PM
Joined: Sep 2003
Posts: 8,501
rmv Online Content
Forum Member
Online Content
Forum Member
Joined: Sep 2003
Posts: 8,501
I should add that part of the "header" is a fixed length integer array (20 elements) which has various flags set, including whether or not crystal data is included. It also includes the title record, which may be variable in length, and is preceded by an integer giving the number of 80 char title records. The first record is a string indicating the file type, either coords or velocities. The order of header records is

4 char string
20 integer array
title count, text

Each is written as a "record", which is only loosely defined by the Fortran standard; typically, each is preceded and followed by a 4-byte integer used as a record pointer, but may be OS and compiler dependent.

The crystal data is not part of the header per se, but is written with each set the XYZ coordinates for each frame, as 6 double precision values. The crystal setup can be used for a wide range of applications besides Ewald; Ewald implies crystal, but crystal does not imply Ewald.

Some of the information needed to read and properly process a DCD file is included in the PSF file.

Best of luck.


Rick Venable
computational chemist

Re: DCD file format?
zjnjuct #4099 01/06/05 08:40 AM
Joined: Apr 2004
Posts: 26
Forum Member
Offline
Forum Member
Joined: Apr 2004
Posts: 26
I faced the same problem. Having noticed, that, as mentioned, vmd and namd have no problems reading dcds and since the source-code (C++ !) is available from their homepage, I wrote my own C++ dcd analysis tool. It works very good!

Sincerely

ST


S. Tayefeh

Moderated by  lennart, rmv 

Link Copied to Clipboard
Powered by UBB.threads™ PHP Forum Software 7.7.4
(Release build 20200307)
Responsive Width:

PHP: 5.6.33-0+deb8u1 Page Time: 0.009s Queries: 30 (0.004s) Memory: 0.9587 MB (Peak: 1.0738 MB) Data Comp: Off Server Time: 2020-10-21 07:22:53 UTC
Valid HTML 5 and Valid CSS