Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions package/MDAnalysis/auxiliary/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ def __init__(self, represent_ts_as='closest', auxname=None, cutoff=-1,
self.auxstep._dt = self.time - self.initial_time
self.rewind()

def __getstate__(self):
# probably works fine, but someone needs to write tests to confirm
return NotImplementedError

def copy(self):
raise NotImplementedError("Copy not implemented for AuxReader")

Expand Down
37 changes: 19 additions & 18 deletions package/MDAnalysis/coordinates/DLPoly.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

from . import base
from . import core
from ..lib import util

_DLPOLY_UNITS = {'length': 'Angstrom', 'velocity': 'Angstrom/ps', 'time': 'ps'}

Expand Down Expand Up @@ -141,7 +142,7 @@ def _read_first_frame(self):
ts.frame = 0


class HistoryReader(base.ReaderBase):
class HistoryReader(base.ReaderBase, base._AsciiPickle):
"""Reads DLPoly format HISTORY files

.. versionadded:: 0.11.0
Expand All @@ -154,9 +155,9 @@ def __init__(self, filename, **kwargs):
super(HistoryReader, self).__init__(filename, **kwargs)

# "private" file handle
self._file = open(self.filename, 'r')
self.title = self._file.readline().strip()
self._levcfg, self._imcon, self.n_atoms = np.int64(self._file.readline().split()[:3])
self._f = util.anyopen(self.filename, 'r')
self.title = self._f.readline().strip()
self._levcfg, self._imcon, self.n_atoms = np.int64(self._f.readline().split()[:3])
self._has_vels = True if self._levcfg > 0 else False
self._has_forces = True if self._levcfg == 2 else False

Expand All @@ -170,20 +171,20 @@ def _read_next_timestep(self, ts=None):
if ts is None:
ts = self.ts

line = self._file.readline() # timestep line
line = self._f.readline() # timestep line
if not line.startswith('timestep'):
raise IOError
if not self._imcon == 0:
ts._unitcell[0] = self._file.readline().split()
ts._unitcell[1] = self._file.readline().split()
ts._unitcell[2] = self._file.readline().split()
ts._unitcell[0] = self._f.readline().split()
ts._unitcell[1] = self._f.readline().split()
ts._unitcell[2] = self._f.readline().split()

# If ids are given, put them in here
# and later sort by them
ids = []

for i in range(self.n_atoms):
line = self._file.readline().strip() # atom info line
line = self._f.readline().strip() # atom info line
try:
idx = int(line.split()[1])
except IndexError:
Expand All @@ -192,11 +193,11 @@ def _read_next_timestep(self, ts=None):
ids.append(idx)

# Read in this order for now, then later reorder in place
ts._pos[i] = self._file.readline().split()
ts._pos[i] = self._f.readline().split()
if self._has_vels:
ts._velocities[i] = self._file.readline().split()
ts._velocities[i] = self._f.readline().split()
if self._has_forces:
ts._forces[i] = self._file.readline().split()
ts._forces[i] = self._f.readline().split()

if ids:
ids = np.array(ids)
Expand All @@ -214,7 +215,7 @@ def _read_next_timestep(self, ts=None):

def _read_frame(self, frame):
"""frame is 0 based, error checking is done in base.getitem"""
self._file.seek(self._offsets[frame])
self._f.seek(self._offsets[frame])
self.ts.frame = frame - 1 # gets +1'd in read_next_frame
return self._read_next_timestep()

Expand All @@ -234,7 +235,7 @@ def _read_n_frames(self):
"""
offsets = self._offsets = []

with open(self.filename, 'r') as f:
with util.anyopen(self.filename, 'r') as f:
n_frames = 0

f.readline()
Expand Down Expand Up @@ -262,10 +263,10 @@ def _read_n_frames(self):

def _reopen(self):
self.close()
self._file = open(self.filename, 'r')
self._file.readline() # header is 2 lines
self._file.readline()
self._f = util.anyopen(self.filename, 'r')
self._f.readline() # header is 2 lines
self._f.readline()
self.ts.frame = -1

def close(self):
self._file.close()
self._f.close()
22 changes: 11 additions & 11 deletions package/MDAnalysis/coordinates/GMS.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import MDAnalysis.lib.util as util


class GMSReader(base.ReaderBase):
class GMSReader(base.ReaderBase, base._AsciiPickle):
"""Reads from an GAMESS output file

:Data:
Expand Down Expand Up @@ -82,7 +82,7 @@ def __init__(self, outfilename, **kwargs):
super(GMSReader, self).__init__(outfilename, **kwargs)

# the filename has been parsed to be either b(g)zipped or not
self.outfile = util.anyopen(self.filename)
self._f = util.anyopen(self.filename)

# note that, like for xtc and trr files, _n_atoms and _n_frames are used quasi-private variables
# to prevent the properties being recalculated
Expand Down Expand Up @@ -177,7 +177,7 @@ def _read_out_n_frames(self):
return len(offsets)

def _read_frame(self, frame):
self.outfile.seek(self._offsets[frame])
self._f.seek(self._offsets[frame])
self.ts.frame = frame - 1 # gets +1'd in _read_next
return self._read_next_timestep()

Expand All @@ -186,7 +186,7 @@ def _read_next_timestep(self, ts=None):
if ts is None:
ts = self.ts
# check that the outfile object exists; if not reopen the trajectory
if self.outfile is None:
if self._f is None:
self.open_trajectory()
x = []
y = []
Expand All @@ -195,7 +195,7 @@ def _read_next_timestep(self, ts=None):
flag = 0
counter = 0

for line in self.outfile:
for line in self._f:
if self.runtyp == 'optimize':
if (flag == 0) and (re.match(r'^.NSERCH=.*', line) is not None):
flag = 1
Expand Down Expand Up @@ -246,22 +246,22 @@ def _reopen(self):
self.open_trajectory()

def open_trajectory(self):
if self.outfile is not None:
if self._f is not None:
raise IOError(errno.EALREADY, 'GMS file already opened', self.filename)
if not os.path.exists(self.filename):
# must check; otherwise might segmentation fault
raise IOError(errno.ENOENT, 'GMS file not found', self.filename)

self.outfile = util.anyopen(self.filename)
self._f = util.anyopen(self.filename)

# reset ts
ts = self.ts
ts.frame = -1
return self.outfile
return self._f

def close(self):
"""Close out trajectory file if it was open."""
if self.outfile is None:
if self._f is None:
return
self.outfile.close()
self.outfile = None
self._f.close()
self._f = None
12 changes: 6 additions & 6 deletions package/MDAnalysis/coordinates/PDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
# Pairs of residue name / atom name in use to deduce PDB formatted atom names
Pair = collections.namedtuple('Atom', 'resname name')

class PDBReader(base.ReaderBase):
class PDBReader(base.ReaderBase, base._BAsciiPickle):
"""PDBReader that reads a `PDB-formatted`_ file, no frills.

The following *PDB records* are parsed (see `PDB coordinate section`_ for
Expand Down Expand Up @@ -277,7 +277,7 @@ def __init__(self, filename, **kwargs):
if isinstance(filename, util.NamedStream) and isinstance(filename.stream, StringIO):
filename.stream = BytesIO(filename.stream.getvalue().encode())

pdbfile = self._pdbfile = util.anyopen(filename, 'rb')
pdbfile = self._f = util.anyopen(filename, 'rb')

line = "magical"
while line:
Expand Down Expand Up @@ -345,7 +345,7 @@ def _reopen(self):
# Pretend the current TS is -1 (in 0 based) so "next" is the
# 0th frame
self.close()
self._pdbfile = util.anyopen(self.filename, 'rb')
self._f = util.anyopen(self.filename, 'rb')
self.ts.frame = -1

def _read_next_timestep(self, ts=None):
Expand All @@ -371,8 +371,8 @@ def _read_frame(self, frame):
occupancy = np.ones(self.n_atoms)

# Seek to start and read until start of next frame
self._pdbfile.seek(start)
chunk = self._pdbfile.read(stop - start).decode()
self._f.seek(start)
chunk = self._f.read(stop - start).decode()

tmp_buf = []
for line in chunk.splitlines():
Expand Down Expand Up @@ -411,7 +411,7 @@ def _read_frame(self, frame):
return self.ts

def close(self):
self._pdbfile.close()
self._f.close()


class PDBWriter(base.WriterBase):
Expand Down
Loading