From fe0acb7af5bfac456afe719083e6dbc362749760 Mon Sep 17 00:00:00 2001 From: Richard Gowers Date: Sat, 2 Apr 2016 14:54:33 +0100 Subject: [PATCH 1/4] Added test for adding Universe with no trajectory to Sim --- src/mdsynthesis/tests/test_treants.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/mdsynthesis/tests/test_treants.py b/src/mdsynthesis/tests/test_treants.py index 630aaa4..0c17234 100644 --- a/src/mdsynthesis/tests/test_treants.py +++ b/src/mdsynthesis/tests/test_treants.py @@ -12,7 +12,7 @@ from datreant.core.tests.test_treants import TestTreant import MDAnalysis as mda -from MDAnalysisTests.datafiles import PDB, GRO, XTC +from MDAnalysisTests.datafiles import PDB, GRO, XTC, PSF class TestSim(TestTreant): @@ -55,6 +55,16 @@ def test_set_universe(self, treant): assert treant.udef.topology == GRO assert treant.udef.trajectory == XTC + def test_set_universe_only_topology(self, treant): + """Test setting the Universe to a topology-only universe""" + u = mda.Universe(PSF) + + treant.universe = u + + assert treant.universe.filename == PSF + assert treant.udef.topology == PSF + assert treant.udef.trajectory == None + def test_add_univese_typeerror(self, treant): """Test checking of what is passed to setter""" with pytest.raises(TypeError): From cca1b92c82b55e3b2b1de0dcfec4d7da72d2004c Mon Sep 17 00:00:00 2001 From: Richard Gowers Date: Sat, 2 Apr 2016 14:58:48 +0100 Subject: [PATCH 2/4] Added tests for Issue #52 --- src/mdsynthesis/tests/test_treants.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/mdsynthesis/tests/test_treants.py b/src/mdsynthesis/tests/test_treants.py index 0c17234..4f9bb0b 100644 --- a/src/mdsynthesis/tests/test_treants.py +++ b/src/mdsynthesis/tests/test_treants.py @@ -65,6 +65,15 @@ def test_set_universe_only_topology(self, treant): assert treant.udef.topology == PSF assert treant.udef.trajectory == None + def test_set_universe_chainreader(self, treant): + """Test setting the Universe to multiple file trajectory (chain)""" + u = mda.Universe(GRO, [XTC, XTC]) + + treant.universe = u + + assert treant.udef.topology == GRO + assert treant.udef.trajectory == [XTC, XTC] + def test_add_univese_typeerror(self, treant): """Test checking of what is passed to setter""" with pytest.raises(TypeError): From 3f15e4258a218ae69ab4eecd0109148095407fdc Mon Sep 17 00:00:00 2001 From: Richard Gowers Date: Sat, 2 Apr 2016 15:00:56 +0100 Subject: [PATCH 3/4] Adding ChainReader Universe to Sim now works properly Fixes Issue #52 --- src/mdsynthesis/treants.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mdsynthesis/treants.py b/src/mdsynthesis/treants.py index bd40a3e..3cce9f3 100644 --- a/src/mdsynthesis/treants.py +++ b/src/mdsynthesis/treants.py @@ -90,12 +90,12 @@ def universe(self, universe): type(universe))) self.udef.topology = universe.filename - try: - traj = universe.trajectory.filename + try: # ChainReader? + traj = universe.trajectory.filenames except AttributeError: - try: - traj = universe.trajectory.filenames - except AttributeError: + try: # Reader? + traj = universe.trajectory.filename + except AttributeError: # Only topology traj = None self.udef.trajectory = traj From 7bd6b761832d344d6aab4d907776de14a04d06c3 Mon Sep 17 00:00:00 2001 From: David Dotson Date: Sat, 2 Apr 2016 15:47:31 -0700 Subject: [PATCH 4/4] PEP8 fix --- src/mdsynthesis/tests/test_treants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mdsynthesis/tests/test_treants.py b/src/mdsynthesis/tests/test_treants.py index 4f9bb0b..dc1cef3 100644 --- a/src/mdsynthesis/tests/test_treants.py +++ b/src/mdsynthesis/tests/test_treants.py @@ -63,7 +63,7 @@ def test_set_universe_only_topology(self, treant): assert treant.universe.filename == PSF assert treant.udef.topology == PSF - assert treant.udef.trajectory == None + assert treant.udef.trajectory is None def test_set_universe_chainreader(self, treant): """Test setting the Universe to multiple file trajectory (chain)"""