-
Notifications
You must be signed in to change notification settings - Fork 664
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 all 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 |
---|---|---|
|
@@ -21,16 +21,19 @@ | |
import MDAnalysis as mda | ||
from MDAnalysis.analysis import rms, align | ||
|
||
from numpy.testing import TestCase, assert_almost_equal, raises, assert_ | ||
from numpy.testing import (TestCase, assert_almost_equal, raises, assert_, | ||
assert_array_almost_equal) | ||
|
||
import numpy as np | ||
|
||
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 +131,82 @@ 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.txt') | ||
self.correct_values = [[0, 0, 0], [49, 48.9999, 4.68953]] | ||
self.correct_values_group = [[0 , 0, 0, 0, 0], | ||
[49, 48.9999, 4.7857, 4.7002, | ||
4.68981]] | ||
|
||
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) | ||
assert_array_almost_equal(RMSD.rmsd, self.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. |
||
single_frame = [[ 5, 5, 0.91544906]] | ||
assert_array_almost_equal(RMSD.rmsd, single_frame, 4, | ||
err_msg="error: rmsd profile should match" + | ||
"test values") | ||
|
||
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(self.outfile) | ||
saved = np.loadtxt(self.outfile) | ||
assert_array_almost_equal(RMSD.rmsd, saved, 4, | ||
err_msg="error: rmsd profile should match " + | ||
"test values") | ||
|
||
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.
|
||
|
||
assert_array_almost_equal(RMSD.rmsd, self.correct_values_group, 4, | ||
err_msg="error: rmsd profile should match" + | ||
"test values") | ||
|
||
|
||
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.
see above about logging/raising errors