From f051b4772f4f2afe233540bc07f7aec42a878d58 Mon Sep 17 00:00:00 2001 From: John Detlefs Date: Fri, 8 Jul 2016 15:06:13 -0700 Subject: [PATCH] Added tests for RMSD, added a testfile. Changed RMSD class to save rmsd array as numpy file instead of text. --- package/MDAnalysis/analysis/rms.py | 2 +- .../MDAnalysisTests/analysis/test_rms.py | 28 ++++++++++++++++-- .../data/adk_oplsaa_CA_rmsd.npy | Bin 0 -> 320 bytes testsuite/MDAnalysisTests/datafiles.py | 3 +- 4 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 testsuite/MDAnalysisTests/data/adk_oplsaa_CA_rmsd.npy diff --git a/package/MDAnalysis/analysis/rms.py b/package/MDAnalysis/analysis/rms.py index 1d2bb7e392c..7d2e6586984 100644 --- a/package/MDAnalysis/analysis/rms.py +++ b/package/MDAnalysis/analysis/rms.py @@ -527,7 +527,7 @@ def save(self, filename=None): if filename is not None: if self.rmsd is None: raise NoDataError("rmsd has not been calculated yet") - np.savetxt(filename, self.rmsd) + np.save(filename, self.rmsd) logger.info("Wrote RMSD timeseries to file %r", filename) return filename diff --git a/testsuite/MDAnalysisTests/analysis/test_rms.py b/testsuite/MDAnalysisTests/analysis/test_rms.py index 48aba6b3523..12ee441f1cf 100644 --- a/testsuite/MDAnalysisTests/analysis/test_rms.py +++ b/testsuite/MDAnalysisTests/analysis/test_rms.py @@ -26,11 +26,11 @@ import os -from MDAnalysisTests.datafiles import GRO, XTC, rmsfArray, PSF, DCD +from MDAnalysisTests.datafiles import GRO, XTC, rmsfArray, rmsdArray, PSF, DCD from MDAnalysisTests import tempdir -class TestRMSD(object): +class Testrmsd(object): def __init__(self): shape = (5, 3) # vectors with length one @@ -128,6 +128,30 @@ def test_with_superposition_equal(self): rmsd_superposition = rms.rmsd(A, B, center=True, superposition=True) assert_almost_equal(rmsd, rmsd_superposition) +class TestRMSD(object): + def setUp(self): + self.universe = MDAnalysis.Universe(GRO, XTC) + self.tempdir = tempdir.TempDir() + self.outfile = os.path.join(self.tempdir.name, 'rmsd.xtc') + + def tearDown(self): + del self.universe + del self.tempdir + + def test_rmsd(self): + RMSD = MDAnalysis.analysis.rms.RMSD(self.universe, select='name CA') + RMSD.run() + test_rmsds = np.load(rmsdArray) + + assert_almost_equal(RMSD.rmsd, test_rmsds, 5, + err_msg="error: rmsd profile should match test " + + "values") + + def test_rmsd_single_frame(self): + RMSD = MDAnalysis.analysis.rms.RMSD(self.universe, select='name CA') + RMSD.run(start=5, stop=6) + + class TestRMSF(TestCase): def setUp(self): diff --git a/testsuite/MDAnalysisTests/data/adk_oplsaa_CA_rmsd.npy b/testsuite/MDAnalysisTests/data/adk_oplsaa_CA_rmsd.npy new file mode 100644 index 0000000000000000000000000000000000000000..8eed3d0037706424b37da15acc90e694e0b8354a GIT binary patch literal 320 zcmbR27wQ`j$;jZwP_3SlTAW;@Zl$1ZlV+i=qoAIaUsO_*m=~X4l#&V(cT3DEP6dh= zXCxM+0{I$-209AHnmP)#3NXOMfCd`$dD7(9?6rdkf3OGA3JeU94$oKY*=V*{*#RQX z0HPHb7&0B?G=c&$iWES6AmDHSQwNG1LMA;bo_R(R!e-w04jk*aR2}S literal 0 HcmV?d00001 diff --git a/testsuite/MDAnalysisTests/datafiles.py b/testsuite/MDAnalysisTests/datafiles.py index 824cc407ed2..e2b936c40b1 100644 --- a/testsuite/MDAnalysisTests/datafiles.py +++ b/testsuite/MDAnalysisTests/datafiles.py @@ -104,7 +104,7 @@ "two_water_gro_widebox", # Issue #548 "DLP_CONFIG", "DLP_CONFIG_order", "DLP_CONFIG_minimal", # dl_poly 4 config file "DLP_HISTORY", "DLP_HISTORY_order", "DLP_HISTORY_minimal", # dl_poly 4 history file - "waterPSF","waterDCD","rmsfArray", + "waterPSF","waterDCD","rmsfArray","rmsdArray", "HoomdXMLdata", "Make_Whole", # for testing the function lib.mdamath.make_whole, has 9 atoms "Plength", @@ -318,6 +318,7 @@ waterDCD = resource_filename(__name__, 'data/watdyn.dcd') rmsfArray = resource_filename(__name__, 'data/adk_oplsaa_CA_rmsf.npy') +rmsdArray = resource_filename(__name__, 'data/adk_oplsaa_CA_rmsd.npy') HoomdXMLdata = resource_filename(__name__, 'data/C12x64.xml.bz2')