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.")
def _parse_unknown_block(self, mode=None): """This parses a block, doing nothing with it. """ (length1, ) = struct.unpack("i", self._fo.read(4)) data = self._fo.read(length1) (length2, ) = struct.unpack("i", self._fo.read(4)) if length1 != length2: log.error("We tried to read the extra block, but it didn't work out quite right.") if mode: values = struct.unpack(mode, data) return values
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")
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