Skip to content
Merged
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
3 changes: 3 additions & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ Changes
* use fast scipy.io.netcdf pure python implementation for reading of Amber
netcdf3 trajctories instead of netCDF4 but use netCDF4 for fast
writing (if available) or fall back to netcdf (see also Issue #506)
* libmdaxdr classes now accept more argument types for a write (PR #1442)
* libmdaxdr classes now raise EOFError when accessing another frame after
the end of the file. Used to raise IOError.


mm/dd/17 richardjgowers, rathann, jbarnoud, orbeckst, utkbansal
Expand Down
31 changes: 22 additions & 9 deletions package/MDAnalysis/lib/formats/libmdaxdr.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ cdef class _XDRFile:
opening_mode = b'w'
else:
raise IOError('mode must be one of "r" or "w", you '
'supplied {}'.format(mode))
'supplied {}'.format(mode))
self.mode = mode

if self.mode == 'r':
Expand Down Expand Up @@ -293,9 +293,11 @@ cdef class _XDRFile:
cdef int64_t offset
if frame == 0:
offset = 0
elif frame < 0:
raise IOError("Can't seek to negative frame")
else:
if frame >= self.offsets.size:
raise IOError('Trying to seek over max number of frames')
raise EOFError('Trying to seek over max number of frames')
offset = self.offsets[frame]
self.reached_eof = False
ok = xdr_seek(self.xfp, offset, SEEK_SET)
Expand Down Expand Up @@ -446,7 +448,7 @@ cdef class TRRFile(_XDRFile):
IOError
"""
if self.reached_eof:
raise IOError('Reached last frame in TRR, seek to 0')
raise EOFError('Reached last frame in TRR, seek to 0')
if not self.is_open:
raise IOError('No file opened')
if self.mode != 'r':
Expand Down Expand Up @@ -502,9 +504,13 @@ cdef class TRRFile(_XDRFile):

Parameters
----------
xyz : ndarray, shape=(`n_atoms`, 3)
cartesion coordinates
box : ndarray, shape=(3, 3)
xyz : array_like, shape=(`n_atoms`, 3), optional
cartesion coordinates. Only written if not ``None``.
velocity : array_like, shape=(`n_atoms`, 3), optional
cartesion velocities. Only written if not ``None``.
forces : array_like, shape=(`n_atoms`, 3), optional
cartesion forces. Only written if not ``None``.
box : array_like, shape=(3, 3)
Box vectors for this frame
step : int
current step number, 1 indexed
Expand Down Expand Up @@ -536,15 +542,19 @@ cdef class TRRFile(_XDRFile):
cdef np.ndarray forces_helper

if xyz is not None:
xyz = np.asarray(xyz)
xyz_helper = np.ascontiguousarray(xyz, dtype=DTYPE)
xyz_ptr = <float*>xyz_helper.data
if velocity is not None:
velocity = np.asarray(velocity)
velocity_helper = np.ascontiguousarray(velocity, dtype=DTYPE)
velocity_ptr = <float*>velocity_helper.data
if forces is not None:
forces = np.asarray(forces)
forces_helper = np.ascontiguousarray(forces, dtype=DTYPE)
forces_ptr = <float*>forces_helper.data

box = np.asarray(box)
cdef np.ndarray box_helper = np.ascontiguousarray(box, dtype=DTYPE)
cdef float* box_ptr = <float*>box_helper.data

Expand Down Expand Up @@ -651,7 +661,7 @@ cdef class XTCFile(_XDRFile):
IOError
"""
if self.reached_eof:
raise IOError('Reached last frame in XTC, seek to 0')
raise EOFError('Reached last frame in XTC, seek to 0')
if not self.is_open:
raise IOError('No file opened')
if self.mode != 'r':
Expand Down Expand Up @@ -685,9 +695,9 @@ cdef class XTCFile(_XDRFile):

Parameters
----------
xyz : ndarray, shape=(`n_atoms`, 3)
xyz : array_like, shape=(`n_atoms`, 3)
cartesion coordinates
box : ndarray, shape=(3, 3)
box : array_like, shape=(3, 3)
Box vectors for this frame
step : int
current step number, 1 indexed
Expand All @@ -712,6 +722,9 @@ cdef class XTCFile(_XDRFile):
raise IOError('File opened in mode: {}. Writing only allow '
'in mode "w"'.format('self.mode'))

xyz = np.asarray(xyz)
box = np.asarray(box)

cdef DTYPE_T[:, ::1] xyz_view = np.ascontiguousarray(xyz, dtype=DTYPE)
cdef DTYPE_T[:, ::1] box_view = np.ascontiguousarray(box, dtype=DTYPE)

Expand Down
Binary file not shown.
Binary file not shown.
6 changes: 0 additions & 6 deletions testsuite/MDAnalysisTests/datafiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@
"CONECT", # HIV Reverse Transcriptase with inhibitor
"TRZ", "TRZ_psf",
"TRIC",
"XTC_single_frame",
"XTC_multi_frame",
"TRR_single_frame",
"TRR_multi_frame",
"merge_protein", "merge_ligand", "merge_water",
"mol2_molecules", "mol2_molecule", "mol2_broken_molecule",
Expand Down Expand Up @@ -235,13 +233,9 @@
XTC_sub_sol = resource_filename(__name__, 'data/cobrotoxin.xtc')
PDB_sub_sol = resource_filename(__name__, 'data/cobrotoxin.pdb')
PDB_xlserial = resource_filename(__name__, 'data/xl_serial.pdb')
XTC_single_frame = resource_filename(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we remove the XTC and TRR single frame files?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I noticed they weren't needed in the first place. They test nothing that isn't tested in the other files

__name__, 'data/xtc_test_only_single_frame_10_atoms.xtc')
XTC_multi_frame = resource_filename(
__name__, 'data/xtc_test_only_10_frame_10_atoms.xtc'
)
TRR_single_frame = resource_filename(
__name__, 'data/trr_test_only_single_frame_10_atoms.trr')
TRR_multi_frame = resource_filename(
__name__, 'data/trr_test_only_10_frame_10_atoms.trr'
)
Expand Down
Loading