Skip to content

Commit

Permalink
More tests for HBAC
Browse files Browse the repository at this point in the history
  • Loading branch information
richardjgowers committed Jul 29, 2016
1 parent c464960 commit 70f7ca8
Showing 1 changed file with 66 additions and 6 deletions.
72 changes: 66 additions & 6 deletions testsuite/MDAnalysisTests/analysis/test_hydrogenbondautocorrel.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
# 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
from MDAnalysisTests.datafiles import TRZ, TRZ_psf, PRM, TRJ
from MDAnalysisTests import module_not_found, tempdir
from numpy.testing import assert_, assert_array_almost_equal, assert_raises, dec
import numpy as np

import MDAnalysis as mda
Expand All @@ -26,9 +26,9 @@
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.H = u.atoms.select_atoms('name Hn')
self.N = u.atoms.select_atoms('name N')
self.O = u.atoms.select_atoms('name O')
self.excl_list = (np.array(range(len(self.H))),
np.array(range(len(self.O))))

Expand All @@ -37,6 +37,7 @@ def tearDown(self):
del self.N
del self.O
del self.u
del self.excl_list

# regression tests for different conditions
def test_continuous(self):
Expand Down Expand Up @@ -94,6 +95,24 @@ def test_intermittent(self):
)


def test_intermittent_timecut(self):
hbond = HBAC(self.u,
hydrogens=self.H,
acceptors=self.O,
donors=self.N,
bond_type='intermittent',
time_cut=0.01, # time cut at traj.dt == 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_intermittent_excl(self):
hbond = HBAC(self.u,
hydrogens=self.H,
Expand Down Expand Up @@ -147,6 +166,23 @@ def test_solve_intermittent(self):
2.00072251e-01, 4.15492813e-02])
)

def test_save(self):
hbond = HBAC(self.u,
hydrogens=self.H,
acceptors=self.O,
donors=self.N,
bond_type='continuous',
sample_time=0.06,
)
hbond.run()

with tempdir.in_tempdir():
hbond.save_results('hbondout.npz')

loaded = np.load('hbondout.npz')
assert_('time' in loaded)
assert_('results' in loaded)

# setup errors
def test_wronglength_DA(self):
assert_raises(ValueError,
Expand Down Expand Up @@ -192,3 +228,27 @@ def test_solve_before_run_VE(self):
sample_time=0.06,
)
assert_raises(ValueError, hbond.solve)

def test_unslicable_traj_VE(self):
u = mda.Universe(PRM, TRJ)
H = u.atoms[:10]
O = u.atoms[10:20]
N = u.atoms[20:30]
assert_raises(ValueError, HBAC,
u,
hydrogens=H,
acceptors=O,
donors=N,
bond_type='continuous',
sample_time=0.06
)

def test_save_without_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.save_results)

0 comments on commit 70f7ca8

Please sign in to comment.