Beispiel #1
0
    def _parse_header(self):
        """Parses in the first header.

        Not for public use
        """
        log.debug('---In dcd.py, parse_header()')
        #process the first header block

        header1 = self._fo.read(92)
        header1_format=\
        "i---cccci---i---i---i---xxxxxxxxxxxxxxxxxxxxf---i---i---xxxxxxxxxxxxxxxxxxxxxxxxxxxxi---i---"
        # |1  |5   |10  |15  |20  |25  |30  |35  |40  |45  |50  |55  |60  |65  |70  |75  |80  |85  |90
        #|header size=84     |nframes*tstep          |tstep_size                             |charm_ver
        #    |CORD=has coordinates                       |block_a                                |header_size=84
        #        |nframes                                    |block_b
        #            |starting timestep
        #                |timestep between coord sets                                                  
        header1_format = string.replace(header1_format, "-", "")
        header1 = struct.unpack(header1_format, header1)
        header1_size1, c1, c2, c3, c4, self._nframes, self._firsttstep, self._dcdfreq, self._ntsteps, self._tstep_size, self._block_a, self._block_b, self._charm_v, header1_size2 = header1  #unpack the tuple header1
    
    
        self._dcdtype = "".join((c1,c2,c3,c4))   #get the data-type field. I it should always be cord...
        if header1_size1 != 84 or header1_size2 !=84:
            log.error("error-- header size fields not correct (should be 84)\n")
        if self._block_a != 0 or self._block_b != 0:
            log.info("I've found a signal possibly indicating an extra record block")
            log.info("    I'll try to parse it, but it might fail.  Also, I won't use")
            log.info("    any data from them.")
Beispiel #2
0
    def init(self):
        """Initilize by reading in the header information.

        You shouldn't need to directly call this anymore, unless you
        are doing something wierd.  It won't hurt to call this more
        than once.  It is now called automatically by setinput().
        """
        log.debug('--in corddcd.py, init()')
Beispiel #3
0
 def zero_frame(self):
     """makes it where the next frame returned is 0. This function itself
     does not return anything.
     """
     if self._fo == None:
         self._openfo()
     log.debug('---In dcd.py, zero_frame(). self.framen=%s'%self.framen())
     log.debug("dcd.py, zero_frame(), resetting file object and framen")
     self._framen = -1
     self._fo.close()
     self._fo = None
Beispiel #4
0
    def _parse_atoms(self):
        """Parses in the natoms record.

        Not for public use.
        """
        ##
        ##Parse the number of atoms
        ##
        #format: 3 ints, first one is blocksize (must equal 4), second is natoms, third is blocksize (must equal 4)
        log.debug("---in dcd.py, parse_atoms()")
        blocksize, self._natoms, blocksize2 = struct.unpack("iii", self._fo.read(12))
        if blocksize != 4 or blocksize2 != 4:
            log.error("blocksizes in the number of atoms record is broken\n")
Beispiel #5
0
    def _parse_title(self):
        """Parses in the title.

        Not for public use.
        """
        log.debug('---In dcd.py, parse_title()')
        ##
        ##Parse the title field
        ##
        #title field format: int that specifies the block size = 80n + 4
        #                    int that specifies the number of 80-char title blocks = x
        #                    x * 80 char title blocks
        #                      ...
        #                    int that specifies the block size = 80n +4
        title = ""
        blocksize, n = struct.unpack("ii", self._fo.read(8))   #read in 8 bytes, convert to ints, store in blocksize, n
        if blocksize != 80*n+4:
            log.error("beginningblock size in title block is wrong\n")
        for i in range(0,n):
            title = title + self._fo.read(80)          # read the next title string onto the current one.
        if (blocksize, ) != struct.unpack("i", self._fo.read(4)):
            log.error("ending blocksize on the title block is not correct !\n")
        self._title = title
Beispiel #6
0
    def _get_header(self):
        """Reads in the header of the dcd.

        Not for public use.
        Wrapper method. Calls methods to read in all the headers.
        """
        log.debug('---In dcd.py, get_header()')
        self._parse_header()
        self._parse_title()
        self._parse_atoms()
    
        log.debug("Parsing: %s"% self._title)    #print out some useful information
        for i in range(0,len(self._title),80):
            log.debug(self._title[i:i+80])

        if self._nframes*self._dcdfreq != self._ntsteps:
            log.warn("error-- the wierd ntsteps frame is not what I think it should be!")
Beispiel #7
0
import sys, string, struct
import mp3.log as log
log.debug('Loading corddcd.py')
import numpy
import mp3.cord
"""
This module contains definitions that pertain only to
single dcd files. Inherets from cord, which has
more general commands (like dcd printing)
"""



class CordDCD(mp3.cord.Cord):

    def __init__(self, dcd):
        """Create the CordDCD object.

        The keyword argument 'dcd' should be the filename to read.
        """
        # This is the initilization method for a dcd-cord object.  This
        # basically lets you set the dcd when you initilize the class.
        #
        self._filename = dcd
        self._fo = file(dcd, "r")

        self._get_header()
        self._initted = True  #make a record saying that we've been set up already
        self._framen = -1   #THE FIRST FRAME IS FRAME 0--- just like python
                           # BUT!!!!!!!!
                           # the actual DCD does not contain the initial