def test_solve_continuous(self, u, hydrogens, oxygens, nitrogens): hbond = HBAC( u, hydrogens=hydrogens, acceptors=oxygens, donors=nitrogens, bond_type='continuous', sample_time=0.06, ) def actual_function_cont(t): A1 = 0.75 A2 = 0.25 tau1 = 0.5 tau2 = 0.1 return A1 * np.exp(-t / tau1) + A2 * np.exp(-t / tau2) hbond.solution['time'] = time = np.arange(0, 0.06, 0.001) hbond.solution['results'] = actual_function_cont(time) hbond.solve() assert_almost_equal( hbond.solution['fit'], np.array([0.75, 0.5, 0.1]), )
def test_solve_intermittent(self, u, hydrogens, oxygens, nitrogens): hbond = HBAC( u, hydrogens=hydrogens, acceptors=oxygens, donors=nitrogens, bond_type='intermittent', sample_time=0.06, ) def actual_function_int(t): A1 = 0.33 A2 = 0.33 A3 = 0.34 tau1 = 5 tau2 = 1 tau3 = 0.1 return A1 * np.exp(-t / tau1) + A2 * np.exp( -t / tau2) + A3 * np.exp(-t / tau3) hbond.solution['time'] = time = np.arange(0, 6.0, 0.01) hbond.solution['results'] = actual_function_int(time) hbond.solve() assert_almost_equal( hbond.solution['fit'], np.array([0.33, 0.33, 5, 1, 0.1]), )
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, ) def actual_function_int(t): A1 = 0.33 A2 = 0.33 A3 = 0.34 tau1 = 5 tau2 = 1 tau3 = 0.1 return A1 * np.exp(-t/tau1) + A2 * np.exp(-t/tau2) + A3 * np.exp(-t/tau3) hbond.solution['time'] = time = np.arange(0, 6.0, 0.01) hbond.solution['results'] = actual_function_int(time) hbond.solve() assert_array_almost_equal( hbond.solution['fit'], np.array([0.33, 0.33, 5, 1, 0.1]), )
def test_save_without_run_VE(self, u, hydrogens, oxygens, nitrogens): hbond = HBAC(u, hydrogens=hydrogens, acceptors=oxygens, donors=nitrogens, bond_type='continuous', sample_time=0.06, ) with pytest.raises(ValueError): hbond.save_results()
def test_save_without_run_VE(self, u, hydrogens, oxygens, nitrogens): hbond = HBAC( u, hydrogens=hydrogens, acceptors=oxygens, donors=nitrogens, bond_type='continuous', sample_time=0.06, ) with pytest.raises(ValueError): hbond.save_results()
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)
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_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_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_save(self, u, hydrogens, oxygens, nitrogens, tmpdir): hbond = HBAC(u, hydrogens=hydrogens, acceptors=oxygens, donors=nitrogens, bond_type='continuous', sample_time=0.06, ) hbond.run() tmpfile = os.path.join(str(tmpdir), 'hbondout.npz') hbond.save_results(tmpfile) loaded = np.load(tmpfile) assert 'time' in loaded assert 'results' in loaded
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)
def test_intermittent(self, u, hydrogens, oxygens, nitrogens): hbond = HBAC( u, hydrogens=hydrogens, acceptors=oxygens, donors=nitrogens, bond_type='intermittent', sample_time=0.06, ) hbond.run() assert_almost_equal( hbond.solution['results'], np.array([ 1., 0.92668623, 0.84310848, 0.79325515, 0.76392961, 0.72287393 ], dtype=np.float32))
def test_save(self, u, hydrogens, oxygens, nitrogens): hbond = HBAC( u, hydrogens=hydrogens, acceptors=oxygens, donors=nitrogens, 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
def test_continuous(self, u, hydrogens, oxygens, nitrogens): hbond = HBAC( u, hydrogens=hydrogens, acceptors=oxygens, donors=nitrogens, bond_type='continuous', sample_time=0.06, ) hbond.run() assert_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, 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))
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_save(self, u, hydrogens, oxygens, nitrogens, tmpdir): hbond = HBAC( u, hydrogens=hydrogens, acceptors=oxygens, donors=nitrogens, bond_type='continuous', sample_time=0.06, ) hbond.run() tmpfile = os.path.join(str(tmpdir), 'hbondout.npz') hbond.save_results(tmpfile) loaded = np.load(tmpfile) assert 'time' in loaded assert 'results' in loaded
def test_intermittent_timecut(self, u, hydrogens, oxygens, nitrogens): hbond = HBAC( u, hydrogens=hydrogens, acceptors=oxygens, donors=nitrogens, bond_type='intermittent', time_cut=0.01, # time cut at traj.dt == continuous sample_time=0.06, ) hbond.run() assert_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, u, hydrogens, oxygens, nitrogens): hbond = HBAC(u, hydrogens=hydrogens, acceptors=oxygens, donors=nitrogens, bond_type='intermittent', exclusions=(np.arange(len(hydrogens)), np.array( range(len(oxygens)))), sample_time=0.06, ) hbond.run() assert_almost_equal( hbond.solution['results'], np.array([ 1. , 0.92668623, 0.84310848, 0.79325515, 0.76392961, 0.72287393], dtype=np.float32) )
def test_continuous_excl(self, u, hydrogens, oxygens, nitrogens): hbond = HBAC(u, hydrogens=hydrogens, acceptors=oxygens, donors=nitrogens, bond_type='continuous', exclusions=(np.arange(len(hydrogens)), np.array( range(len(oxygens)))), sample_time=0.06, ) hbond.run() assert_almost_equal( hbond.solution['results'], np.array([ 1. , 0.92668623, 0.83137828, 0.74486804, 0.67741936, 0.60263932], dtype=np.float32) )
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, ) def actual_function_cont(t): A1 = 0.75 A2 = 0.25 tau1 = 0.5 tau2 = 0.1 return A1 * np.exp(-t/tau1) + A2 * np.exp(-t/tau2) hbond.solution['time'] = time = np.arange(0, 0.06, 0.001) hbond.solution['results'] = actual_function_cont(time) hbond.solve() assert_array_almost_equal( hbond.solution['fit'], np.array([0.75, 0.5, 0.1]), )
'O6' : u.select_atoms('bynum 36'), 'O7' : u.select_atoms('bynum 23'), 'O8' : u.select_atoms('bynum 23'), 'O9' : u.select_atoms('bynum 64'), 'O10' : u.select_atoms('bynum 18') } oxygens = sum(list(oxygen_dict.values())) hydrogens = sum(list(hydrogen_dict.values())) nitrogens = sum(list(nitrogen_dict.values())) "" "Run HBond Autocorrelation" hb_ac = HydrogenBondAutoCorrel(u, acceptors = oxygens, hydrogens = hydrogens, donors = nitrogens, bond_type='continuous') hb_ac.run() hb_ac.solve() tau = hb_ac.solution['tau'] time = hb_ac.solution['time'] results = hb_ac.solution['results'] estimate = hb_ac.solution['estimate'] "Max Range" factor = 0.5 max_d = int(data[:,0].size * factor) max_h = int(time.size * factor) max_r = int(len(u.trajectory) * factor)