From e50390c5f213f47baa10f1e2f5b8d992887c8547 Mon Sep 17 00:00:00 2001 From: John Detlefs Date: Fri, 8 Jul 2016 17:40:36 -0700 Subject: [PATCH] g# This is a combination of 6 commits. Test group selections Reverted back to save. Updated test coverage for exceptions. Found some errors with logging requiring a message. Reverted inclusion of unnecessary RMSD array Fixed a small error and combined save and mass_weighted test No Data Error Cover save --- package/CHANGELOG | 1 - package/MDAnalysis/analysis/rms.py | 8 +-- .../MDAnalysisTests/analysis/test_rms.py | 61 ++++++++++++++---- .../data/adk_oplsaa_CA_rmsd.npy | Bin 320 -> 0 bytes testsuite/MDAnalysisTests/datafiles.py | 3 +- 5 files changed, 52 insertions(+), 21 deletions(-) delete mode 100644 testsuite/MDAnalysisTests/data/adk_oplsaa_CA_rmsd.npy diff --git a/package/CHANGELOG b/package/CHANGELOG index 08850e068fa..a01407ba373 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -25,7 +25,6 @@ Fixes next (Issue #869) * Display of Deprecation warnings doesn't affect other modules anymore (Issue #754) * Changed nframes to n_frames in analysis modules for consistency (Issue #890) - * Removed call to protected process_selection function in RMSD Changes * Added protected variable _frame_index to to keep track of frame iteration diff --git a/package/MDAnalysis/analysis/rms.py b/package/MDAnalysis/analysis/rms.py index 7d2e6586984..4e00c2b7eb8 100644 --- a/package/MDAnalysis/analysis/rms.py +++ b/package/MDAnalysis/analysis/rms.py @@ -83,7 +83,7 @@ import matplotlib.pyplot as plt rmsd = R.rmsd.T # transpose makes it easier for plotting - time = rmsd[1] + time = rmsd[1]facebook.com fig = plt.figure(figsize=(4,4)) ax = fig.add_subplot(111) ax.plot(time, rmsd[2], 'k-', label="all") @@ -351,7 +351,7 @@ def __init__(self, traj, reference=None, select='all', self.ref_atoms = self.reference.select_atoms(*self.select['reference']) self.traj_atoms = self.universe.select_atoms(*self.select['mobile']) if len(self.ref_atoms) != len(self.traj_atoms): - logger.exception() + logger.exception('SelectionError: ref_atoms, traj_atoms unequal') raise SelectionError("Reference and trajectory atom selections do " "not contain the same number of atoms: " "N_ref={0:d}, N_traj={1:d}".format( @@ -386,7 +386,7 @@ def __init__(self, traj, reference=None, select='all', for igroup, (sel, atoms) in enumerate(zip(self.groupselections, self.groupselections_atoms)): if len(atoms['mobile']) != len(atoms['reference']): - logger.exception() + logger.exception('SelectionError: Group Selection') raise SelectionError( "Group selection {0}: {1} | {2}: Reference and trajectory " "atom selections do not contain the same number of atoms: " @@ -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.save(filename, self.rmsd) + np.savetxt(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 5d320f1d506..227bd804b7d 100644 --- a/testsuite/MDAnalysisTests/analysis/test_rms.py +++ b/testsuite/MDAnalysisTests/analysis/test_rms.py @@ -26,7 +26,8 @@ import os -from MDAnalysisTests.datafiles import GRO, XTC, rmsfArray, rmsdArray, PSF, DCD +from MDAnalysis.exceptions import SelectionError, NoDataError +from MDAnalysisTests.datafiles import GRO, XTC, rmsfArray, PSF, DCD from MDAnalysisTests import tempdir @@ -130,7 +131,7 @@ def test_with_superposition_equal(self): class TestRMSD(object): def setUp(self): - self.universe = MDAnalysis.Universe(GRO, XTC) + self.universe = MDAnalysis.Universe(PSF, DCD) self.tempdir = tempdir.TempDir() self.outfile = os.path.join(self.tempdir.name, 'rmsd.npy') @@ -140,26 +141,58 @@ def tearDown(self): 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, + RMSD.run(step=49) + correct_values = [[ 0, 0, 0], + [ 49, 48.9999, 4.68953]] + assert_almost_equal(RMSD.rmsd, correct_values, 4, 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) - def test_rmsd_save(self): + + def test_mass_weighted_and_save(self): RMSD = MDAnalysis.analysis.rms.RMSD(self.universe, select='name CA') - RMSD.run() - RMSD.save(self.outfile) - saved_file = np.load(self.outfile) - test_rmsds = np.load(rmsdArray) - assert_almost_equal(saved_file, test_rmsds, 5, - err_msg="error: rmsd profile should match test " + - "values") + RMSD.run(step=49, mass_weighted= True) + RMSD.save() + + def test_rmsd_group_selections(self): + RMSD = MDAnalysis.analysis.rms.RMSD(self.universe, + groupselections= + ['backbone','name CA']) + RMSD.run(step=49) + + + @raises(SelectionError) + def test_ref_length_unequal_len(self): + reference = MDAnalysis.Universe(PSF, DCD) + reference.atoms = reference.atoms[:-1] + RMSD = MDAnalysis.analysis.rms.RMSD(self.universe, + reference=reference) + + @raises(SelectionError) + def test_mass_mismatches(self): + reference = MDAnalysis.Universe(PSF, DCD) + reference.atoms.masses = 10 + RMSD = MDAnalysis.analysis.rms.RMSD(self.universe, + reference=reference) + + + @raises(SelectionError) + def test_group_selections_unequal_len(self): + reference = MDAnalysis.Universe(PSF, DCD) + reference.atoms[0].resname='NOTMET' + RMSD = MDAnalysis.analysis.rms.RMSD(self.universe, + reference=reference, + groupselections= + ['resname MET','type NH3']) + @raises(NoDataError) + def test_save_before_run(self): + RMSD = MDAnalysis.analysis.rms.RMSD(self.universe) + RMSD.save('blah') 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 deleted file mode 100644 index 8eed3d0037706424b37da15acc90e694e0b8354a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 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 diff --git a/testsuite/MDAnalysisTests/datafiles.py b/testsuite/MDAnalysisTests/datafiles.py index e2b936c40b1..824cc407ed2 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","rmsdArray", + "waterPSF","waterDCD","rmsfArray", "HoomdXMLdata", "Make_Whole", # for testing the function lib.mdamath.make_whole, has 9 atoms "Plength", @@ -318,7 +318,6 @@ 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')