Re: Recover high precision coordinates from binary .coor file

From: Rajan Vatassery (rajan_at_umn.edu)
Date: Wed Dec 08 2010 - 15:15:56 CST

Also concerns:
Re: namd-l: Format of namd restartfile *.coor, *.vel) (2nd try ;) )

A while back I had tried to get the full-precision coordinates of output
from a NAMD simulation because the 3 digits after the decimal were not
enough for my purposes. You can produce a binary file of output with the
binaryoutput set to "yes" in the conf file, and this binary file is much
smaller and contains more information.

Nicholas Glykos had suggested correctly that I could use vmd to convert
the output pdb file into an xyz file format, which has 6 digits after
the decimal. However, I could not figure out how to write an xyz file as
part of a batch script. I got as far as finding the portion of the vmd
manual that suggested how to open vmd in batch mode:
$ vmd -dispdev text -eofexit < input.tcl > output.log
but I stopped there.

An orthogonal solution came from Nick from the MSI (www.msi.umn.edu),
who suggested that python be used to open these binary files. He also
provided a compact example script that would open and print the
coordinates of a NAMD simulation:

--------------------------------------------------------------------
import sys
import struct

file = open(sys.argv[1],'rb')

Natoms = struct.unpack('i',file.read(4))[0]
print "Number of Atoms = ",Natoms

for cart in range(0,Natoms):
    x = struct.unpack('d',file.read(8))[0]
    y = struct.unpack('d',file.read(8))[0]
    z = struct.unpack('d',file.read(8))[0]
    print "%20.15f %20.15f %20.15f" % (x,y,z)

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

In a trial run, this printed the coordinates perfectly, although for
some reason I am suddenly unable to open binary files with vmd (this may
turn into a namd-l or vmd-l post if it continues to be a problem). This
means that I wasn't able to verify that the coordinates were faithfully
reproduced. Since this was a test structure, I know many of the
coordinates and the ones I have checked have been correct.

In summary, I hope this addresses the problems opening the binary output
files that NAMD produces. I have searched a bit online and I don't see a
similar python script on the NAMD-l archives, and there are plenty of
people searching for a way to open such files with python or similar
utilities.

Thanks to all that helped,

Rajan

PS I am also still interested in hearing from people that have been
unable to open binary files with vmd, with the error given:

..
Info) File loading in progress, please wait.
PDB file 'TerthiopheneOutBin.pdb' contains no atoms.
ERROR) Could not read file TerthiopheneOutBin.pdb
ERROR) Loading of startup molecule files aborted.
vmd > Info) VMD for LINUXAMD64, version 1.8.7 (August 1, 2009)

On Sat, 2010-11-06 at 13:30 +0200, Nicholas M Glykos wrote:
> Hi Rajan,
>
> I just tested it, and VMD can read binary coordinate files produced by
> NAMD with something in the spirit of 'vmd my.psf my_bin.coor'. It would
> appear that a bit (or, maybe, more than just a bit) of scripting for VMD
> can do the trick. For example, telling VMD to save coordinates in the
> 'xyz' format is giving you six significant digits (instead of three for
> the straight PDB). You could possibly even write-out the coordinates
> yourself in any format you would care for.
>
> Nicholas
>

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