diff --git a/testsuite/MDAnalysisTests/analysis/test_hydrogenbondautocorrel.py b/testsuite/MDAnalysisTests/analysis/test_hydrogenbondautocorrel.py index 463c30a7566..8a831fa8026 100644 --- a/testsuite/MDAnalysisTests/analysis/test_hydrogenbondautocorrel.py +++ b/testsuite/MDAnalysisTests/analysis/test_hydrogenbondautocorrel.py @@ -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 @@ -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)))) @@ -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): @@ -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, @@ -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, @@ -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)