Exemple #1
0
 def test_accepter_donor(self, universe_AD):
     '''Test zeroth order acceptor to donor hydrogen bonding'''
     wb = WaterBridgeAnalysis(universe_AD, 'protein and (resid 1)',
                              'protein and (resid 4)', order=0)
     wb.run(verbose=False)
     network = wb._network[0]
     assert_equal(list(network.keys())[0][:4], (0, None, 1, 2))
Exemple #2
0
 def test_donor_accepter_pbc(self, universe_DA_PBC):
     '''Test zeroth order donor to acceptor hydrogen bonding in PBC conditions'''
     wb = WaterBridgeAnalysis(universe_DA_PBC, 'protein and (resid 1)',
         'protein and (resid 4)', order=0, pbc=True)
     wb.run(verbose=False)
     network = wb._network[0]
     assert_equal(list(network.keys())[0][:4], (1, 0, 2, None))
    def test_water_network(self):
        '''
        This test tests if the internal water object is generated correctly.
        :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)
        water_network = wb._water_network[0]
        assert_equal(list(water_network.keys()), [('SOL', 2)])
        values = list(water_network.values())
        assert_equal(
            list(values[0][0])[0][:4],
            (1, 2, ('ALA', 1, 'H'), ('SOL', 2, 'OW')))
        assert_equal(
            list(values[0][1])[0][:4],
            (3, 4, ('SOL', 2, 'HW2'), ('ALA', 4, 'O')))
Exemple #4
0
 def test_donor_accepter(self, universe_DA):
     '''Test zeroth order donor to acceptor hydrogen bonding'''
     wb = WaterBridgeAnalysis(universe_DA, 'protein and (resid 1)',
     'protein and (resid 4)', order=0, update_selection=True, debug=True)
     wb.run(verbose=False)
     network = wb._network[0]
     assert_equal(list(network.keys())[0][:4], (1, 0, 2, None))
Exemple #5
0
 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.)])
Exemple #6
0
 def test_same_selection(self, universe_DWA):
     '''
     This test tests that if the selection 1 and selection 2 are both protein.
     However, the protein only forms one hydrogen bond with the water.
     This entry won't be included.
     '''
     wb = WaterBridgeAnalysis(universe_DWA, 'protein and resid 1',
                              'protein and resid 1')
     wb.run(verbose=False)
     assert_equal(wb._network[0], defaultdict(dict))
Exemple #7
0
 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]])
Exemple #8
0
 def test_count_by_time_empty(self, universe_AWA_AWWA):
     '''
     See if count_by_time() can handle zero well.
     :return:
     '''
     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)
     def analysis(current, output, u):
         pass
     assert_equal(wb.count_by_time(analysis_func=analysis), [(0,0), ])
Exemple #9
0
 def test_acceptor_water_accepter(self, universe_AWA):
     '''Test case where the hydrogen bond acceptor from selection 1 form
     water bridge with hydrogen bond acceptor from selection 2'''
     wb = WaterBridgeAnalysis(universe_AWA, 'protein and (resid 1)',
                              'protein and (resid 4)')
     wb.run(verbose=False)
     network = wb._network[0]
     assert_equal(list(network.keys())[0][:4], (0, None, 2, 1))
     second = network[list(network.keys())[0]]
     assert_equal(list(second.keys())[0][:4], (3, 1, 4, None))
     assert_equal(second[list(second.keys())[0]], None)
Exemple #10
0
 def test_donor_water_donor(self, universe_DWD):
     '''Test case where the hydrogen bond donor from selection 1 form
     water bridge with hydrogen bond donor from selection 2'''
     wb = WaterBridgeAnalysis(universe_DWD, 'protein and (resid 1)',
                              'protein and (resid 4)')
     wb.run(verbose=False)
     network = wb._network[0]
     assert_equal(list(network.keys())[0][:4], (1, 0, 2, None))
     second = network[list(network.keys())[0]]
     assert_equal(list(second.keys())[0][:4], (2, None, 3, 4))
     assert_equal(second[list(second.keys())[0]], None)
Exemple #11
0
    def test_timeseries_hba(self, universe_branch):
        '''Test if the time series data is correctly generated in hydrogen bond analysis format'''
        wb = WaterBridgeAnalysis(universe_branch, 'protein and (resid 1)',
                                 'protein and (resid 4 or resid 5)', order=2)
        wb.output_format = 'donor_acceptor'
        wb.run(verbose=False)
        timeseries = sorted(wb.timeseries[0])

        assert_equal(timeseries[0][:4], (2, 0, ('SOL', 2, 'HW1'), ('ALA', 1, 'O')))
        assert_equal(timeseries[1][:4], (3, 4, ('SOL', 2, 'HW2'), ('SOL', 3, 'OW')))
        assert_equal(timeseries[2][:4], (5, 7, ('SOL', 3, 'HW1'), ('ALA', 4, 'O')))
        assert_equal(timeseries[3][:4], (6, 8, ('SOL', 3, 'HW2'), ('ALA', 5, 'O')))
Exemple #12
0
    def test_empty(self):
        '''Test case where no water bridge exists'''
        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   3.000   0.000   0.000
    4ALA      H    4   0.500   0.000   0.000
    4ALA      N    5   0.600   0.000   0.000
  1.0   1.0   1.0'''
        u = MDAnalysis.Universe(StringIO(grofile), format='gro')
        wb = WaterBridgeAnalysis(u, 'protein', 'protein')
        wb.run(verbose=False)
        assert_equal(wb._timeseries, [[]])
Exemple #13
0
 def test_acceptor_22water_accepter(self, universe_branch):
     '''Test case where the hydrogen bond acceptor from selection 1 form a second order
     water bridge with hydrogen bond acceptor from selection 2
     and the last water is linked to two residues in selection 2'''
     wb = WaterBridgeAnalysis(universe_branch, 'protein and (resid 1)',
                              'protein and (resid 4 or resid 5)', order=2)
     wb.run(verbose=False)
     network = wb._network[0]
     assert_equal(list(network.keys())[0][:4], (0, None, 2, 1))
     second = network[list(network.keys())[0]]
     assert_equal(list(second.keys())[0][:4], (3, 1, 4, None))
     third = second[list(second.keys())[0]]
     assert_equal([(5, 4, 7, None), (6, 4, 8, None)],
                  sorted([key[:4] for key in list(third.keys())]))
    def test_empty(self):
        '''Test case where no water bridge exists'''
        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   3.000   0.000   0.000
    4ALA      H    4   0.500   0.000   0.000
    4ALA      N    5   0.600   0.000   0.000
  1.0   1.0   1.0'''
        u = MDAnalysis.Universe(StringIO(grofile), format='gro')
        wb = WaterBridgeAnalysis(u, 'protein', 'protein')
        wb.run(verbose=False)
        assert_equal(wb._timeseries, [[]])
Exemple #15
0
    def test_same_selection(self):
        '''
        This test tests that if the selection 1 and selection 2 are both protein.
        However, the protein only forms one hydrogen bond with the water.
        This entry won't be included.
        :return:
        '''
        grofile = '''Test gro file
3
    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
  1.0   1.0   1.0'''
        u = MDAnalysis.Universe(StringIO(grofile), format='gro')
        wb = WaterBridgeAnalysis(u, 'protein', 'protein')
        wb.run(verbose=False)
        assert_equal(wb._timeseries, [[]])
    def test_same_selection(self):
        '''
        This test tests that if the selection 1 and selection 2 are both protein.
        However, the protein only forms one hydrogen bond with the water.
        This entry won't be included.
        :return:
        '''
        grofile = '''Test gro file
3
    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
  1.0   1.0   1.0'''
        u = MDAnalysis.Universe(StringIO(grofile), format='gro')
        wb = WaterBridgeAnalysis(u, 'protein', 'protein')
        wb.run(verbose=False)
        assert_equal(wb._timeseries, [[]])
Exemple #17
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.)])
Exemple #18
0
 def test_acceptor_12water_accepter(self, universe_AWA_AWWA):
     '''Test of independent first order and second can be recognised correctely'''
     wb = WaterBridgeAnalysis(universe_AWA_AWWA, 'protein and (resid 1 or resid 5)',
                              'protein and (resid 4 or resid 8)', order=1)
     wb.run(verbose=False)
     network = wb._network[0]
     assert_equal(list(network.keys())[0][:4], (0, None, 2, 1))
     second = network[list(network.keys())[0]]
     assert_equal(list(second.keys())[0][:4], (3, 1, 4, None))
     assert_equal(second[list(second.keys())[0]], None)
     network = wb._network[0]
     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)
     network = wb._network[0]
     assert_equal([(0, None, 2, 1), (5, None, 7, 6)],
                  sorted([key[:4] for key in list(network.keys())]))
Exemple #19
0
    def test_acceptor_water_accepter(self):
        '''Test case where the hydrogen bond acceptor from selection 1 form
        water bridge with hydrogen bond acceptor from selection 2'''
        grofile = '''Test gro file
5
    1ALA      O    1   0.000   0.000   0.000
    2SOL     OW    2   0.300   0.000   0.000
    2SOL    HW1    3   0.200   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)
        timeseries = wb._timeseries
        assert_equal(timeseries[0][0][:4], (2, 0, ('SOL', 2, 'HW1'), ('ALA', 1, 'O')))
        assert_equal(timeseries[0][1][:4], (3, 4, ('SOL', 2, 'HW2'), ('ALA', 4, 'O')))
Exemple #20
0
    def test_donor_water_donor(self):
        '''Test case where the hydrogen bond donor from selection 1 form
        water bridge with hydrogen bond donor from selection 2'''
        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
    4ALA      H    4   0.500   0.000   0.000
    4ALA      N    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)
        timeseries = wb._timeseries
        assert_equal(timeseries[0][0][:4], (1, 2, ('ALA', 1, 'H'), ('SOL', 2, 'OW')))
        assert_equal(timeseries[0][1][:4], (3, 2, ('ALA', 4, 'H'), ('SOL', 2, 'OW')))
Exemple #21
0
 def test_count_by_time_weight(self, universe_AWA_AWWA):
     '''
     This test tests if modyfing the analysis_func allows the weight to be changed
     in count_by_type().
     :return:
     '''
     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)
     def analysis(current, output, u):
         sele1_index, sele1_heavy_index, atom2, heavy_atom2, dist, angle = current[0]
         atom1, heavy_atom1, sele2_index, sele2_heavy_index, dist, angle = current[-1]
         sele1 = u.atoms[sele1_index]
         sele2 = u.atoms[sele2_index]
         (s1_resname, s1_resid, s1_name) = (sele1.resname, sele1.resid, sele1.name)
         (s2_resname, s2_resid, s2_name) = (sele2.resname, sele2.resid, sele2.name)
         key = (s1_resname, s1_resid, s2_resname, s2_resid)
         output[key] += len(current)-1
     assert_equal(wb.count_by_time(analysis_func=analysis), [(0,3), ])
    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_acceptor_water_accepter(self):
        '''Test case where the hydrogen bond acceptor from selection 1 form
        water bridge with hydrogen bond acceptor from selection 2'''
        grofile = '''Test gro file
5
    1ALA      O    1   0.000   0.000   0.000
    2SOL     OW    2   0.300   0.000   0.000
    2SOL    HW1    3   0.200   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)
        timeseries = wb._timeseries
        assert_equal(timeseries[0][0][:4],
                     (2, 0, ('SOL', 2, 'HW1'), ('ALA', 1, 'O')))
        assert_equal(timeseries[0][1][:4],
                     (3, 4, ('SOL', 2, 'HW2'), ('ALA', 4, 'O')))
    def test_donor_water_donor(self):
        '''Test case where the hydrogen bond donor from selection 1 form
        water bridge with hydrogen bond donor from selection 2'''
        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
    4ALA      H    4   0.500   0.000   0.000
    4ALA      N    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)
        timeseries = wb._timeseries
        assert_equal(timeseries[0][0][:4],
                     (1, 2, ('ALA', 1, 'H'), ('SOL', 2, 'OW')))
        assert_equal(timeseries[0][1][:4],
                     (3, 2, ('ALA', 4, 'H'), ('SOL', 2, 'OW')))
Exemple #25
0
    def test_water_network(self):
        '''
        This test tests if the internal water object is generated correctly.
        :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)
        water_network = wb._water_network[0]
        assert_equal(list(water_network.keys()), [('SOL', 2)])
        values = list(water_network.values())
        assert_equal(list(values[0][0])[0][:4], (1, 2, ('ALA', 1, 'H'), ('SOL', 2, 'OW')))
        assert_equal(list(values[0][1])[0][:4], (3, 4, ('SOL', 2, 'HW2'), ('ALA', 4, 'O')))
Exemple #26
0
    def test_acceptor_3water_accepter(self, universe_AWWWA):
        '''Test case where the hydrogen bond acceptor from selection 1 form third order
        water bridge with hydrogen bond acceptor from selection 2'''
        wb = WaterBridgeAnalysis(universe_AWWWA, 'protein and (resid 1)',
                                 'protein and (resid 5)', order=2)
        wb.run(verbose=False)
        assert_equal(wb._network[0], defaultdict(dict))

        wb = WaterBridgeAnalysis(universe_AWWWA, 'protein and (resid 1)',
                                 'protein and (resid 5)', order=3)
        wb.run(verbose=False)
        network = wb._network[0]
        assert_equal(list(network.keys())[0][:4], (0, None, 2, 1))
        second = network[list(network.keys())[0]]
        assert_equal(list(second.keys())[0][:4], (3, 1, 4, None))
        third = second[list(second.keys())[0]]
        assert_equal(list(third.keys())[0][:4], (5, 4, 6, None))
        fourth = third[list(third.keys())[0]]
        assert_equal(list(fourth.keys())[0][:4], (7, 6, 8, None))
        assert_equal(fourth[list(fourth.keys())[0]], None)

        wb = WaterBridgeAnalysis(universe_AWWWA, 'protein and (resid 1)',
                                 'protein and (resid 5)', order=4)
        wb.run(verbose=False)
        network = wb._network[0]
        assert_equal(list(network.keys())[0][:4], (0, None, 2, 1))
        second = network[list(network.keys())[0]]
        assert_equal(list(second.keys())[0][:4], (3, 1, 4, None))
        third = second[list(second.keys())[0]]
        assert_equal(list(third.keys())[0][:4], (5, 4, 6, None))
        fourth = third[list(third.keys())[0]]
        assert_equal(list(fourth.keys())[0][:4], (7, 6, 8, None))
        assert_equal(fourth[list(fourth.keys())[0]], None)
Exemple #27
0
 def test_empty(self, universe_empty):
     '''Test case where no water bridge exists'''
     wb = WaterBridgeAnalysis(universe_empty, 'protein', 'protein')
     wb.run(verbose=False)
     assert_equal(wb._network[0], defaultdict(dict))
Exemple #28
0
 def test_empty_selection(self, universe_DA):
     '''Test the case when selection yields empty result'''
     wb = WaterBridgeAnalysis(universe_DA, 'protein and (resid 9)',
                              'protein and (resid 10)', order=0)
     wb.run()
     assert wb._network == [{}]
Exemple #29
0
 def test_loop(self, universe_loop):
     '''Test if loop can be handled correctly'''
     wb = WaterBridgeAnalysis(universe_loop, 'protein and (resid 1)',
                              'protein and (resid 1 or resid 4)')
     wb.run()
     assert_equal(len(wb._network[0].keys()), 2)