-
Notifications
You must be signed in to change notification settings - Fork 658
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
Fix and cover RMSD #889
Fix and cover RMSD #889
Changes from 4 commits
dfb3c99
a0c1bdb
ea41a49
023408d
40eb01c
91ba82a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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") | ||
|
@@ -338,9 +338,9 @@ def __init__(self, traj, reference=None, select='all', | |
self.reference = self.universe | ||
else: | ||
self.reference = reference | ||
self.select = _process_selection(select) | ||
self.select = process_selection(select) | ||
if groupselections is not None: | ||
self.groupselections = [_process_selection(s) for s in groupselections] | ||
self.groupselections = [process_selection(s) for s in groupselections] | ||
else: | ||
self.groupselections = [] | ||
self.mass_weighted = mass_weighted | ||
|
@@ -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') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (I think you can also leave the message for errmsg = "Reference and trajectory atom ... N_ref={0:d}, N_traj={1:d}".format(...)
logger.exception(errmsg)
raise SelectionError(errmsg) |
||
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') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above about logging/raising errors |
||
raise SelectionError( | ||
"Group selection {0}: {1} | {2}: Reference and trajectory " | ||
"atom selections do not contain the same number of atoms: " | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,11 +26,12 @@ | |
|
||
import os | ||
|
||
from MDAnalysis.exceptions import SelectionError, NoDataError | ||
from MDAnalysisTests.datafiles import GRO, XTC, rmsfArray, PSF, DCD | ||
from MDAnalysisTests import tempdir | ||
|
||
|
||
class TestRMSD(object): | ||
class Testrmsd(object): | ||
def __init__(self): | ||
shape = (5, 3) | ||
# vectors with length one | ||
|
@@ -128,6 +129,70 @@ 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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you!! |
||
def setUp(self): | ||
self.universe = MDAnalysis.Universe(PSF, DCD) | ||
self.tempdir = tempdir.TempDir() | ||
self.outfile = os.path.join(self.tempdir.name, 'rmsd.npy') | ||
|
||
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(step=49) | ||
correct_values = [[ 0, 0, 0], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. store the |
||
[ 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
A quick way to get the values is just to put in an assert with harbage values, run the test, note the real values, replace garbage values with real values and you're done. |
||
|
||
|
||
def test_mass_weighted_and_save(self): | ||
RMSD = MDAnalysis.analysis.rms.RMSD(self.universe, select='name CA') | ||
RMSD.run(step=49, mass_weighted= True) | ||
RMSD.save() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. read the save file and compare to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay thanks for the review. This is stuff I can get done in some free time
|
||
|
||
def test_rmsd_group_selections(self): | ||
RMSD = MDAnalysis.analysis.rms.RMSD(self.universe, | ||
groupselections= | ||
['backbone','name CA']) | ||
RMSD.run(step=49) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. excellent job testing the failure cases! |
||
@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): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a random "facebook.com" in the docs. Please remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird...