Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds filename attribute to MemoryReader & associated tests #1252

Merged
merged 2 commits into from
Mar 22, 2017
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
1 change: 1 addition & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
6 changes: 5 additions & 1 deletion package/MDAnalysis/coordinates/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = \
Expand Down
5 changes: 3 additions & 2 deletions package/MDAnalysis/core/universe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions testsuite/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion testsuite/MDAnalysisTests/coordinates/test_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down