Example #1
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),
        ])
Example #2
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 == [{}]
Example #3
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.)])
Example #4
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))
Example #5
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))
Example #6
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))
Example #7
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)
Example #8
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)
Example #9
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))
Example #10
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]])
Example #11
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())]))
Example #12
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),
        ])
Example #13
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')))
Example #14
0
    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
Example #15
0
 def test_selection_type_error(self, universe_DA):
     '''Test the case when the wrong selection1_type is given'''
     try:
         wb = WaterBridgeAnalysis(universe_DA,
                                  'protein and (resid 1)',
                                  'protein and (resid 4)',
                                  order=0,
                                  selection1_type='aaa')
     except ValueError:
         pass
     else:
         raise pytest.fail("selection_type aaa should rasie error")
Example #16
0
 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)
Example #17
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())]))
Example #18
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))
Example #19
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)
Example #20
0
 def test_acceptor_2water_accepter(self, universe_AWWA):
     '''Test case where the hydrogen bond acceptor from selection 1 form second order
     water bridge with hydrogen bond acceptor from selection 2'''
     # test first order
     wb = WaterBridgeAnalysis(universe_AWWA, 'protein and (resid 1)',
                              'protein and (resid 4)')
     wb.run(verbose=False)
     assert_equal(wb._network[0], defaultdict(dict))
     # test second order
     wb = WaterBridgeAnalysis(universe_AWWA,
                              'protein and (resid 1)',
                              'protein and (resid 4)',
                              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(list(third.keys())[0][:4], (5, 4, 6, None))
     assert_equal(third[list(third.keys())[0]], None)
     # test third order
     wb = WaterBridgeAnalysis(universe_AWWA,
                              'protein and (resid 1)',
                              'protein and (resid 4)',
                              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))
     assert_equal(third[list(third.keys())[0]], None)
Example #21
0
    def test_acceptor_4water_accepter(self, universe_AWWWWA):
        '''Test case where the hydrogen bond acceptor from selection 1 form fourth order
        water bridge with hydrogen bond acceptor from selection 2'''
        wb = WaterBridgeAnalysis(universe_AWWWWA,
                                 'protein and (resid 1)',
                                 'protein and (resid 6)',
                                 order=3)
        wb.run(verbose=False)
        assert_equal(wb._network[0], defaultdict(dict))

        wb = WaterBridgeAnalysis(universe_AWWWWA,
                                 'protein and (resid 1)',
                                 'protein and (resid 6)',
                                 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))
        fifth = fourth[list(fourth.keys())[0]]
        assert_equal(list(fifth.keys())[0][:4], (9, 8, 10, None))
        assert_equal(fifth[list(fifth.keys())[0]], None)

        wb = WaterBridgeAnalysis(universe_AWWWWA,
                                 'protein and (resid 1)',
                                 'protein and (resid 6)',
                                 order=5)
        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))
        fifth = fourth[list(fourth.keys())[0]]
        assert_equal(list(fifth.keys())[0][:4], (9, 8, 10, None))
        assert_equal(fifth[list(fifth.keys())[0]], None)