diff --git a/package/CHANGELOG b/package/CHANGELOG index 66245c419ce..fcb409dc632 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -21,6 +21,7 @@ The rules for this file: * 0.16.0 Enhancements + * Added 'filename' attribute to 'MemoryReader' * Improved __str__ and __repr__ of 'GroupBase' class in MDAnalysis.core.groups (addresses Issue #1223) * Added dynamic selections (addresses Issues #175 and #1074). diff --git a/package/MDAnalysis/coordinates/memory.py b/package/MDAnalysis/coordinates/memory.py index b4e9a88b6d5..37ba9f1495d 100644 --- a/package/MDAnalysis/coordinates/memory.py +++ b/package/MDAnalysis/coordinates/memory.py @@ -222,7 +222,7 @@ class MemoryReader(base.ProtoReader): _Timestep = Timestep def __init__(self, coordinate_array, order='fac', - dimensions = None, dt=1, **kwargs): + dimensions=None, dt=1, filename=None, **kwargs): """ Parameters @@ -242,10 +242,14 @@ def __init__(self, coordinate_array, order='fac', dt: float, optional The time difference between frames (ps). If :attr:`time` is set, then `dt` will be ignored. + filename: string, optional + The name of the file from which this instance is created. Set to None + when created from an array """ super(MemoryReader, self).__init__() + self.filename = filename self.stored_order = order self.set_array(np.asarray(coordinate_array), order) self.n_frames = \ diff --git a/package/MDAnalysis/core/universe.py b/package/MDAnalysis/core/universe.py index eaf13aee934..3c4209f1e48 100644 --- a/package/MDAnalysis/core/universe.py +++ b/package/MDAnalysis/core/universe.py @@ -486,11 +486,12 @@ def transfer_to_memory(self, start=None, stop=None, step=None, self.trajectory = MemoryReader( coordinates, dimensions=self.trajectory.ts.dimensions, - dt=self.trajectory.ts.dt) + dt=self.trajectory.ts.dt, + filename=self.filename) # python 2 doesn't allow an efficient splitting of kwargs in function # argument signatures. - # In python3-only we'd be able to explicitely define this function with + # In python3-only we'd be able to explicitly define this function with # something like (sel, *othersels, updating=False, **selgroups) def select_atoms(self, *args, **kwargs): """Select atoms. diff --git a/testsuite/CHANGELOG b/testsuite/CHANGELOG index 6542d330032..c9429de654c 100644 --- a/testsuite/CHANGELOG +++ b/testsuite/CHANGELOG @@ -17,6 +17,7 @@ and https://github.com/MDAnalysis/mdanalysis/wiki/UnitTests tyler.je.reddy, utkbansal, vedantrathore, kash1102 * 0.16 + - Added two unit tests for MDAnalysis.coordinates.memory.MemoryReader - Make knownfailure work even without parentheses. - added two unit tests for MDAnalysis.analysis.polymer - added test for LeafletFinder handling a selection string diff --git a/testsuite/MDAnalysisTests/coordinates/test_memory.py b/testsuite/MDAnalysisTests/coordinates/test_memory.py index a8fda097fcf..5987fb5fe91 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_memory.py +++ b/testsuite/MDAnalysisTests/coordinates/test_memory.py @@ -58,12 +58,24 @@ def iter_ts(self, i): return ts - class TestMemoryReader(BaseReaderTest): def __init__(self): reference = MemoryReference() super(TestMemoryReader, self).__init__(reference) + def test_filename_transefer_to_memory(self): + # MemoryReader should have a filename attribute set to the trajaectory filename + universe = mda.Universe(PSF, DCD) + universe.transfer_to_memory() + assert_equal(universe.trajectory.filename, PSF) + + def test_filename_array(self): + # filename attribute of MemoryReader should be None when generated from an array + universe = mda.Universe(PSF, DCD) + coordinates = universe.trajectory.timeseries(universe.atoms) + universe2 = mda.Universe(PSF, coordinates, format=MemoryReader, order='afc') + assert_equal(universe2.trajectory.filename, None) + def test_default_memory_layout(self): universe1 = mda.Universe(PSF, DCD, in_memory=True) universe2 = mda.Universe(PSF, DCD, in_memory=True, order='fac')