Skip to content

Commit

Permalink
g# This is a combination of 6 commits.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jdetle committed Jul 9, 2016
1 parent ea41a49 commit e50390c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 21 deletions.
1 change: 0 additions & 1 deletion package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions package/MDAnalysis/analysis/rms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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: "
Expand Down Expand Up @@ -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

Expand Down
61 changes: 47 additions & 14 deletions testsuite/MDAnalysisTests/analysis/test_rms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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')

Expand All @@ -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):
Expand Down
Binary file removed testsuite/MDAnalysisTests/data/adk_oplsaa_CA_rmsd.npy
Binary file not shown.
3 changes: 1 addition & 2 deletions testsuite/MDAnalysisTests/datafiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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')

Expand Down

0 comments on commit e50390c

Please sign in to comment.