From 3f5874047398087c2189ae44410c69b8885e7318 Mon Sep 17 00:00:00 2001 From: Dominik 'Rathann' Mierzejewski Date: Thu, 22 Jun 2017 13:19:09 +0200 Subject: [PATCH] fix TRZ file reader on big-endian arches - Numpy dtype int (iN) and float (fN) specifiers assume native-endian by default, so force them to be little-endian. - Closes #1424. - added CHANGELOG entry and docs --- package/CHANGELOG | 4 +- package/MDAnalysis/coordinates/TRZ.py | 185 +++++++++++++------------- 2 files changed, 96 insertions(+), 93 deletions(-) diff --git a/package/CHANGELOG b/package/CHANGELOG index 6859b765b25..e71090832c8 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -13,8 +13,6 @@ The rules for this file: * release numbers follow "Semantic Versioning" http://semver.org ------------------------------------------------------------------------------ - - mm/dd/17 richardjgowers, rathann, jbarnoud, orbeckst * 0.16.2 @@ -28,6 +26,8 @@ Fixes * fixed GROWriter truncating long resids from the wrong end (Issue #1395) * Fixed dtype of numpy arrays to accomodate 32 bit architectures (Issue #1362) * Groups are hashable on python 3 (Issue #1397) + * correctly read little-endian TRZ files on big-endian architectures (issue + #1424) Changes * scipy and matplotlib are now required dependencies (Issue #1159) diff --git a/package/MDAnalysis/coordinates/TRZ.py b/package/MDAnalysis/coordinates/TRZ.py index 58fb5abe819..71ee8bdc9a0 100644 --- a/package/MDAnalysis/coordinates/TRZ.py +++ b/package/MDAnalysis/coordinates/TRZ.py @@ -24,10 +24,12 @@ """TRZ trajectory I/O --- :mod:`MDAnalysis.coordinates.TRZ` ============================================================ -Classes to read `IBIsCO`_ / `YASP`_ binary trajectories. +Classes to read `IBIsCO`_ / `YASP`_ TRZ binary trajectories, including +coordinates, velocities and more (see attributes of the :class:`Timestep`). -Reads coordinates, velocities and more (see attributes of the -:class:`Timestep`). +Data are read and written in binary representation but because this depends on +the machine hardware architecture, MDAnalysis *always* reads and writes TRZ +trajectories in *little-endian* byte order. .. _IBIsCO: http://www.theo.chemie.tu-darmstadt.de/ibisco/IBISCO.html .. _YASP: http://www.theo.chemie.tu-darmstadt.de/group/services/yaspdoc/yaspdoc.html @@ -79,6 +81,7 @@ .. autoclass:: TRZWriter :members: + """ from __future__ import division, absolute_import import six @@ -123,28 +126,26 @@ def dimensions(self, box): class TRZReader(base.ReaderBase): - """ Reads an IBIsCO or YASP trajectory file - - :Data: - ts - :class:`~MDAnalysis.coordinates.TRZ.Timestep` object - containing coordinates of current frame - - :Methods: - ``len(trz)`` - returns the number of frames - ``for ts in trz`` - iterates through the trajectory - ``for ts in trz[start:stop:skip]`` - iterate through a trajectory using slicing - ``trz[i]`` - random access of a trajectory frame + """Reads an IBIsCO or YASP trajectory file + + Attributes + ---------- + ts : TRZ.Timestep + :class:`~MDAnalysis.coordinates.TRZ.Timestep` object containing + coordinates of current frame + + Note + ---- + Binary TRZ trajectories are *always* assumed to be written in + *little-endian* byte order and are read as such. + .. versionchanged:: 0.11.0 - Frames now 0-based instead of 1-based + Frames now 0-based instead of 1-based. Extra data (Temperature, Energies, Pressures, etc) now read - into ts.data dictionary - Now passes a weakref of self to ts (ts._reader) + into ts.data dictionary. + Now passes a weakref of self to ts (ts._reader). + """ format = "TRZ" @@ -180,46 +181,46 @@ def __init__(self, trzfilename, n_atoms=None, **kwargs): **self._ts_kwargs) # structured dtype of a single trajectory frame - readarg = str(n_atoms) + 'f4' + readarg = str(n_atoms) + '