Skip to content

Commit

Permalink
Added DCD to #239 style Readers
Browse files Browse the repository at this point in the history
  • Loading branch information
richardjgowers committed Aug 4, 2016
1 parent 9ef317c commit b278be8
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions package/MDAnalysis/coordinates/DCD.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def close(self):
self.dcdfile = None


class DCDReader(base.Reader):
class DCDReader(base.NewReader):
"""Reads from a DCD file
:Data:
Expand Down Expand Up @@ -419,22 +419,25 @@ def __init__(self, dcdfilename, **kwargs):
if stats.st_size == 0:
raise IOError(errno.EIO, "DCD file is zero size", self.filename)

self.dcdfile = open(self.filename, 'rb')
#self.dcdfile = open(self.filename, 'rb')
self.dcdfile = self._fh.fh # pointer to file handle
self.n_atoms = 0
self.n_frames = 0
self.fixed = 0
self.periodic = False

# This reads skip_timestep and delta from header
self._read_dcd_header()
with self._fh.from_last_position(remember_last=True):
self._read_dcd_header()
self._header_pos = self._fh.fh.tell() # make _fh.tell() == fh.fh.tell()

# Convert delta to ps
delta = mdaunits.convert(self.delta, self.units['time'], 'ps')
# Convert delta to ps
delta = mdaunits.convert(self.delta, self.units['time'], 'ps')

self._ts_kwargs.setdefault('dt', self.skip_timestep * delta)
self.ts = self._Timestep(self.n_atoms, **self._ts_kwargs)
# Read in the first timestep
self._read_next_timestep()
self._ts_kwargs.setdefault('dt', self.skip_timestep * delta)
self.ts = self._Timestep(self.n_atoms, **self._ts_kwargs)
# Read in the first timestep
self._read_next_timestep()

def _dcd_header(self): # pragma: no cover
"""Returns contents of the DCD header C structure::
Expand Down Expand Up @@ -474,7 +477,7 @@ def _dcd_header(self): # pragma: no cover

def _reopen(self):
self.ts.frame = -1
self._reset_dcd_read()
self._fh.fh.last_pos = self._header_pos

def _read_next_timestep(self, ts=None):
"""Read the next frame
Expand Down

0 comments on commit b278be8

Please sign in to comment.