-
Notifications
You must be signed in to change notification settings - Fork 666
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
Added regression tests for hydrogenbondautocorrel #917
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c464960
Added regression tests for hydrogenbondautocorrel
richardjgowers 70f7ca8
More tests for HBAC
richardjgowers 56c6bfa
Added better tests for HBAC Solve
richardjgowers 72ceff9
Merge branch 'hbondautocorreltests' of github.com:MDAnalysis/mdanalys…
richardjgowers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
194 changes: 194 additions & 0 deletions
194
testsuite/MDAnalysisTests/analysis/test_hydrogenbondautocorrel.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
# -*- Mode: python; tab-width: 4; indent-tabs-mode:nil; coding:utf-8 -*- | ||
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 fileencoding=utf-8 | ||
# | ||
# MDAnalysis --- http://www.MDAnalysis.org | ||
# Copyright (c) 2006-2015 Naveen Michaud-Agrawal, Elizabeth J. Denning, Oliver | ||
# Beckstein and contributors (see AUTHORS for the full list) | ||
# | ||
# Released under the GNU Public Licence, v2 or any higher version | ||
# | ||
# Please cite your use of MDAnalysis in published work: | ||
# | ||
# N. Michaud-Agrawal, E. J. Denning, T. B. Woolf, and O. Beckstein. | ||
# MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. | ||
# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 | ||
# | ||
from six.moves import zip, range | ||
from MDAnalysisTests.datafiles import TRZ, TRZ_psf | ||
from MDAnalysisTests import module_not_found | ||
from numpy.testing import assert_array_almost_equal, assert_raises, dec | ||
import numpy as np | ||
|
||
import MDAnalysis as mda | ||
from MDAnalysis.analysis.hbonds import HydrogenBondAutoCorrel as HBAC | ||
|
||
|
||
class TestHydrogenBondAutocorrel(object): | ||
def setUp(self): | ||
u = self.u = mda.Universe(TRZ_psf, TRZ) | ||
self.H = u.atoms.Hn | ||
self.N = u.atoms.N | ||
self.O = u.atoms.O | ||
self.excl_list = (np.array(range(len(self.H))), | ||
np.array(range(len(self.O)))) | ||
|
||
def tearDown(self): | ||
del self.H | ||
del self.N | ||
del self.O | ||
del self.u | ||
|
||
# regression tests for different conditions | ||
def test_continuous(self): | ||
hbond = HBAC(self.u, | ||
hydrogens=self.H, | ||
acceptors=self.O, | ||
donors=self.N, | ||
bond_type='continuous', | ||
sample_time=0.06, | ||
) | ||
hbond.run() | ||
|
||
assert_array_almost_equal( | ||
hbond.solution['results'], | ||
np.array([ 1. , 0.92668623, 0.83137828, | ||
0.74486804, 0.67741936, 0.60263932], | ||
dtype=np.float32) | ||
) | ||
|
||
|
||
def test_continuous_excl(self): | ||
hbond = HBAC(self.u, | ||
hydrogens=self.H, | ||
acceptors=self.O, | ||
donors=self.N, | ||
bond_type='continuous', | ||
exclusions=self.excl_list, | ||
sample_time=0.06, | ||
) | ||
hbond.run() | ||
|
||
assert_array_almost_equal( | ||
hbond.solution['results'], | ||
np.array([ 1. , 0.92668623, 0.83137828, | ||
0.74486804, 0.67741936, 0.60263932], | ||
dtype=np.float32) | ||
) | ||
|
||
|
||
def test_intermittent(self): | ||
hbond = HBAC(self.u, | ||
hydrogens=self.H, | ||
acceptors=self.O, | ||
donors=self.N, | ||
bond_type='intermittent', | ||
sample_time=0.06, | ||
) | ||
hbond.run() | ||
|
||
assert_array_almost_equal( | ||
hbond.solution['results'], | ||
np.array([ 1. , 0.92668623, 0.84310848, | ||
0.79325515, 0.76392961, 0.72287393], | ||
dtype=np.float32) | ||
) | ||
|
||
|
||
def test_intermittent_excl(self): | ||
hbond = HBAC(self.u, | ||
hydrogens=self.H, | ||
acceptors=self.O, | ||
donors=self.N, | ||
bond_type='intermittent', | ||
exclusions=self.excl_list, | ||
sample_time=0.06, | ||
) | ||
hbond.run() | ||
|
||
assert_array_almost_equal( | ||
hbond.solution['results'], | ||
np.array([ 1. , 0.92668623, 0.84310848, | ||
0.79325515, 0.76392961, 0.72287393], | ||
dtype=np.float32) | ||
) | ||
|
||
@dec.skipif(module_not_found('scipy')) | ||
def test_solve_continuous(self): | ||
hbond = HBAC(self.u, | ||
hydrogens=self.H, | ||
acceptors=self.O, | ||
donors=self.N, | ||
bond_type='continuous', | ||
sample_time=0.06, | ||
) | ||
hbond.run() | ||
hbond.solve() | ||
|
||
assert_array_almost_equal( | ||
hbond.solution['fit'], | ||
np.array([ 0.52727374, 0.10231721, 0.10231605]) | ||
) | ||
|
||
@dec.skipif(module_not_found('scipy')) | ||
def test_solve_intermittent(self): | ||
hbond = HBAC(self.u, | ||
hydrogens=self.H, | ||
acceptors=self.O, | ||
donors=self.N, | ||
bond_type='intermittent', | ||
sample_time=0.06, | ||
) | ||
hbond.run() | ||
hbond.solve() | ||
|
||
assert_array_almost_equal( | ||
hbond.solution['fit'], | ||
np.array([ 6.13695140e-01, 3.30614269e-06, 5.90645176e+00, | ||
2.00072251e-01, 4.15492813e-02]) | ||
) | ||
|
||
# setup errors | ||
def test_wronglength_DA(self): | ||
assert_raises(ValueError, | ||
HBAC, self.u, | ||
hydrogens=self.H[:-1], | ||
acceptors=self.O, | ||
donors=self.N, | ||
bond_type='intermittent', | ||
exclusions=self.excl_list, | ||
sample_time=0.06, | ||
) | ||
|
||
def test_exclusions(self): | ||
excl_list2 = self.excl_list[0], self.excl_list[1][:-1] | ||
assert_raises(ValueError, | ||
HBAC, self.u, | ||
hydrogens=self.H, | ||
acceptors=self.O, | ||
donors=self.N, | ||
bond_type='intermittent', | ||
exclusions=excl_list2, | ||
sample_time=0.06, | ||
) | ||
|
||
def test_bond_type_VE(self): | ||
assert_raises(ValueError, | ||
HBAC, self.u, | ||
hydrogens=self.H, | ||
acceptors=self.O, | ||
donors=self.N, | ||
bond_type='marzipan', | ||
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. haha |
||
exclusions=self.excl_list, | ||
sample_time=0.06, | ||
) | ||
|
||
@dec.skipif(module_not_found('scipy')) | ||
def test_solve_before_run_VE(self): | ||
hbond = HBAC(self.u, | ||
hydrogens=self.H, | ||
acceptors=self.O, | ||
donors=self.N, | ||
bond_type='continuous', | ||
sample_time=0.06, | ||
) | ||
assert_raises(ValueError, hbond.solve) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I wouldn't rely on the quick selectors and rather do explicit
select_atoms
.