def wb_multiframe(): '''A water bridge object with multipley frames''' grofile = '''Test gro file 13 1ALA O 1 0.000 0.000 0.000 1ALA H 2 0.000 0.000 0.000 2SOL OW 3 0.300 0.000 0.000 2SOL HW1 4 0.200 0.000 0.000 2SOL HW2 5 0.400 0.000 0.000 3SOL OW 6 0.600 0.000 0.000 3SOL HW1 7 0.700 0.000 0.000 4SOL OW 8 0.900 0.000 0.000 4SOL HW1 9 1.000 0.000 0.000 5SOL OW 10 1.200 0.000 0.000 5SOL HW1 11 1.300 0.000 0.000 6ALA H 12 1.400 0.000 0.000 6ALA O 13 1.400 0.000 0.000 10.0 10.0 10.0''' u = MDAnalysis.Universe(StringIO(grofile), format='gro') wb = WaterBridgeAnalysis(u, 'protein and (resid 1)', 'protein and (resid 4)', order=4) # Build an dummy WaterBridgeAnalysis object for testing wb._network = [] wb._network.append({(1, 0, 12, None, 2.0, 180.0): None}) wb._network.append({(0, None, 12, 13, 2.0, 180.0): None}) wb._network.append({(1, 0, 3, None, 2.0, 180.0): {(4, 2, 12, None, 2.0, 180.0): None}}) wb._network.append({(0, None, 3, 2, 2.0, 180.0): {(4, 2, 5, None, 2.0, 180.0): {(5, None, 11, 12, 2.0, 180.0): None}}}) wb.timesteps = range(len(wb._network)) return wb
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_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)