예제 #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),
        ])
예제 #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 == [{}]
예제 #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.)])
예제 #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))
예제 #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))
예제 #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))
예제 #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)
예제 #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)
예제 #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))
예제 #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]])
예제 #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())]))
예제 #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),
        ])
예제 #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')))
예제 #14
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())]))
예제 #15
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)
예제 #16
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)
예제 #17
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))
예제 #18
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)