def test_count_by_type_multiple_link(self): ''' This test tests if count_by_type() can assemble linkage from water network. :return: ''' grofile = '''Test gro file 5 1ALA N 1 0.000 0.000 0.000 1ALA H 2 0.100 0.000 0.000 2SOL OW 3 0.300 0.000 0.000 2SOL HW2 4 0.400 0.000 0.000 4ALA O 5 0.600 0.000 0.000 1.0 1.0 1.0''' u = MDAnalysis.Universe(StringIO(grofile), format='gro') wb = WaterBridgeAnalysis(u, 'protein and (resid 1)', 'protein and (resid 4)') # Build an dummy WaterBridgeAnalysis object for testing wb._timeseries = True wb.timesteps = [0] wb._water_network = [{ ('SOL', 2): [{(2, 0, ('SOL', 2, 'HW1'), ('ALA', 1, 'O'), 2.0, 179.99998), (1, 2, ('ALA', 1, 'H'), ('SOL', 2, 'OW'), 2.0, 179.99998)}, {(3, 4, ('SOL', 2, 'HW2'), ('ALA', 4, 'O'), 2.0, 179.99998), (3, 2, ('ALA', 4, 'H'), ('SOL', 2, 'OW'), 2.0, 179.99998)}] }] result = [(0, 3, 'ALA', 1, 'O', 'ALA', 4, 'H', 1.0), (0, 4, 'ALA', 1, 'O', 'ALA', 4, 'O', 1.0), (1, 3, 'ALA', 1, 'H', 'ALA', 4, 'H', 1.0), (1, 4, 'ALA', 1, 'H', 'ALA', 4, 'O', 1.0)] assert_equal(sorted(wb.count_by_type().tolist()), result)
def test_count_by_type_multiple_link(self): ''' This test tests if count_by_type() can assemble linkage from water network. :return: ''' grofile = '''Test gro file 5 1ALA N 1 0.000 0.000 0.000 1ALA H 2 0.100 0.000 0.000 2SOL OW 3 0.300 0.000 0.000 2SOL HW2 4 0.400 0.000 0.000 4ALA O 5 0.600 0.000 0.000 1.0 1.0 1.0''' u = MDAnalysis.Universe(StringIO(grofile), format='gro') wb = WaterBridgeAnalysis(u, 'protein and (resid 1)', 'protein and (resid 4)') # Build an dummy WaterBridgeAnalysis object for testing wb._timeseries = True wb.timesteps = [0] wb._water_network = [{('SOL', 2): [{(2, 0, ('SOL', 2, 'HW1'), ('ALA', 1, 'O'), 2.0, 179.99998), (1, 2, ('ALA', 1, 'H'), ('SOL', 2, 'OW'), 2.0, 179.99998)}, {(3, 4, ('SOL', 2, 'HW2'), ('ALA', 4, 'O'), 2.0, 179.99998), (3, 2, ('ALA', 4, 'H'), ('SOL', 2, 'OW'), 2.0, 179.99998)}]}] result = [(0, 3, 'ALA', 1, 'O', 'ALA', 4, 'H', 1.0), (0, 4, 'ALA', 1, 'O', 'ALA', 4, 'O', 1.0), (1, 3, 'ALA', 1, 'H', 'ALA', 4, 'H', 1.0), (1, 4, 'ALA', 1, 'H', 'ALA', 4, 'O', 1.0)] assert_equal(sorted(wb.count_by_type().tolist()), result)
def test_count_by_type_single_link(self, universe_DWA): ''' This test tests the simplest water bridge to see if count_by_type() works. ''' wb = WaterBridgeAnalysis(universe_DWA, 'protein and (resid 1)', 'protein and (resid 4)') wb.run(verbose=False) assert_equal(wb.count_by_type(), [(1, 4, 'ALA', 1, 'H', 'ALA', 4, 'O', 1.)])
def test_nodata(self, universe_DA): '''Test if the funtions can run when there is no data. This is achieved by not runing the run() first.''' wb = WaterBridgeAnalysis(universe_DA, 'protein and (resid 1)', 'protein and (resid 4)', order=0) wb.generate_table() assert_equal(wb.timesteps_by_type(), None) assert_equal(wb.count_by_time(), None) assert_equal(wb.count_by_type(), None)
def test_count_by_type_multiple_link(self, universe_AWA_AWWA): ''' This test tests if count_by_type() can give the correct result for more than 1 links. ''' wb = WaterBridgeAnalysis(universe_AWA_AWWA, 'protein and (resid 1 or resid 5)', 'protein and (resid 4 or resid 8)', order=2) wb.run(verbose=False) assert_equal(sorted(wb.count_by_type()), [[0, 4, 'ALA', 1, 'O', 'ALA', 4, 'O', 1.0], [5, 11, 'ALA', 5, 'O', 'ALA', 8, 'O', 1.0]])
def test_count_by_type_single_link(self): ''' This test tests the simplest water bridge to see if count_by_type() works. :return: ''' grofile = '''Test gro file 5 1ALA N 1 0.000 0.000 0.000 1ALA H 2 0.100 0.000 0.000 2SOL OW 3 0.300 0.000 0.000 2SOL HW2 4 0.400 0.000 0.000 4ALA O 5 0.600 0.000 0.000 1.0 1.0 1.0''' u = MDAnalysis.Universe(StringIO(grofile), format='gro') wb = WaterBridgeAnalysis(u, 'protein and (resid 1)', 'protein and (resid 4)') wb.run(verbose=False) assert_equal(wb.count_by_type().tolist(), [(1, 4, 'ALA', 1, 'H', 'ALA', 4, 'O', 1.)])
def test_count_by_type_multiple_frame(self): ''' This test tests if count_by_type() works in multiply situations. :return: ''' grofile = '''Test gro file 5 1ALA N 1 0.000 0.000 0.000 1ALA H 2 0.100 0.000 0.000 2SOL OW 3 0.300 0.000 0.000 2SOL HW2 4 0.400 0.000 0.000 4ALA O 5 0.600 0.000 0.000 1.0 1.0 1.0''' u = MDAnalysis.Universe(StringIO(grofile), format='gro') wb = WaterBridgeAnalysis(u, 'protein and (resid 1)', 'protein and (resid 4)') # Build an dummy WaterBridgeAnalysis object for testing wb._timeseries = True wb.timesteps = [0, 1, 2, 3, 4, 5] wb._water_network = [# a 2 * 2 water netwrok consists of all four links {('SOL', 2): [{(2, 0, ('SOL', 2, 'HW1'), ('ALA', 1, 'O'), 2.0, 179.99998), (1, 2, ('ALA', 1, 'H'), ('SOL', 2, 'OW'), 2.0, 179.99998)}, {(3, 4, ('SOL', 2, 'HW2'), ('ALA', 4, 'O'), 2.0, 179.99998), (3, 2, ('ALA', 4, 'H'), ('SOL', 2, 'OW'), 2.0, 179.99998)}]}, # a repeat {('SOL', 2): [{(2, 0, ('SOL', 2, 'HW1'), ('ALA', 1, 'O'), 2.0, 179.99998), (1, 2, ('ALA', 1, 'H'), ('SOL', 2, 'OW'), 2.0, 179.99998)}, {(3, 4, ('SOL', 2, 'HW2'), ('ALA', 4, 'O'), 2.0, 179.99998), (3, 2, ('ALA', 4, 'H'), ('SOL', 2, 'OW'), 2.0, 179.99998)}]}, # single link 1 {('SOL', 2): [{(2, 0, ('SOL', 2, 'HW1'), ('ALA', 1, 'O'), 2.0, 179.99998)}, {(3, 4, ('SOL', 2, 'HW2'), ('ALA', 4, 'O'), 2.0, 179.99998)}]}, # single link 2 {('SOL', 2): [{(2, 0, ('SOL', 2, 'HW1'), ('ALA', 1, 'O'), 2.0, 179.99998)}, {(3, 1, ('ALA', 4, 'H'), ('SOL', 2, 'OW'), 2.0, 179.99998)}]}, # single link 3 {('SOL', 2): [{(1, 2, ('ALA', 1, 'H'), ('SOL', 2, 'OW'), 2.0, 179.99998)}, {(3, 4, ('SOL', 2, 'HW2'), ('ALA', 4, 'O'), 2.0, 179.99998)}]}, # single link 4 {('SOL', 2): [{(1, 2, ('ALA', 1, 'H'), ('SOL', 2, 'OW'), 2.0, 179.99998)}, {(3, 2, ('ALA', 4, 'H'), ('SOL', 2, 'OW'), 2.0, 179.99998)}]}] result = [(0, 3, 'ALA', 1, 'O', 'ALA', 4, 'H', 0.5), (0, 4, 'ALA', 1, 'O', 'ALA', 4, 'O', 0.5), (1, 3, 'ALA', 1, 'H', 'ALA', 4, 'H', 0.5), (1, 4, 'ALA', 1, 'H', 'ALA', 4, 'O', 0.5)] assert_equal(sorted(wb.count_by_type().tolist()), result)
def test_count_by_type_multiple_frame(self): ''' This test tests if count_by_type() works in multiply situations. :return: ''' grofile = '''Test gro file 5 1ALA N 1 0.000 0.000 0.000 1ALA H 2 0.100 0.000 0.000 2SOL OW 3 0.300 0.000 0.000 2SOL HW2 4 0.400 0.000 0.000 4ALA O 5 0.600 0.000 0.000 1.0 1.0 1.0''' u = MDAnalysis.Universe(StringIO(grofile), format='gro') wb = WaterBridgeAnalysis(u, 'protein and (resid 1)', 'protein and (resid 4)') # Build an dummy WaterBridgeAnalysis object for testing wb._timeseries = True wb.timesteps = [0, 1, 2, 3, 4, 5] wb._water_network = [ # a 2 * 2 water netwrok consists of all four links { ('SOL', 2): [{(2, 0, ('SOL', 2, 'HW1'), ('ALA', 1, 'O'), 2.0, 179.99998), (1, 2, ('ALA', 1, 'H'), ('SOL', 2, 'OW'), 2.0, 179.99998)}, {(3, 4, ('SOL', 2, 'HW2'), ('ALA', 4, 'O'), 2.0, 179.99998), (3, 2, ('ALA', 4, 'H'), ('SOL', 2, 'OW'), 2.0, 179.99998)}] }, # a repeat { ('SOL', 2): [{(2, 0, ('SOL', 2, 'HW1'), ('ALA', 1, 'O'), 2.0, 179.99998), (1, 2, ('ALA', 1, 'H'), ('SOL', 2, 'OW'), 2.0, 179.99998)}, {(3, 4, ('SOL', 2, 'HW2'), ('ALA', 4, 'O'), 2.0, 179.99998), (3, 2, ('ALA', 4, 'H'), ('SOL', 2, 'OW'), 2.0, 179.99998)}] }, # single link 1 { ('SOL', 2): [{(2, 0, ('SOL', 2, 'HW1'), ('ALA', 1, 'O'), 2.0, 179.99998)}, {(3, 4, ('SOL', 2, 'HW2'), ('ALA', 4, 'O'), 2.0, 179.99998)}] }, # single link 2 { ('SOL', 2): [{(2, 0, ('SOL', 2, 'HW1'), ('ALA', 1, 'O'), 2.0, 179.99998)}, {(3, 1, ('ALA', 4, 'H'), ('SOL', 2, 'OW'), 2.0, 179.99998)}] }, # single link 3 { ('SOL', 2): [{(1, 2, ('ALA', 1, 'H'), ('SOL', 2, 'OW'), 2.0, 179.99998)}, {(3, 4, ('SOL', 2, 'HW2'), ('ALA', 4, 'O'), 2.0, 179.99998)}] }, # single link 4 { ('SOL', 2): [{(1, 2, ('ALA', 1, 'H'), ('SOL', 2, 'OW'), 2.0, 179.99998)}, {(3, 2, ('ALA', 4, 'H'), ('SOL', 2, 'OW'), 2.0, 179.99998)}] } ] result = [(0, 3, 'ALA', 1, 'O', 'ALA', 4, 'H', 0.5), (0, 4, 'ALA', 1, 'O', 'ALA', 4, 'O', 0.5), (1, 3, 'ALA', 1, 'H', 'ALA', 4, 'H', 0.5), (1, 4, 'ALA', 1, 'H', 'ALA', 4, 'O', 0.5)] assert_equal(sorted(wb.count_by_type().tolist()), result)