예제 #1
0
    def test_count_by_time(self, universe):

        h = HydrogenBondAnalysis(universe, **self.kwargs)
        h.run()

        ref_times = np.array([0, 1, 2])  # u.trajectory.dt is 1
        ref_counts = np.array([1, 0, 1])

        counts = h.count_by_time()
        assert_array_almost_equal(h.times, ref_times)
        assert_array_equal(counts, ref_counts)
예제 #2
0
    def test_no_hydrogens(self, universe):
        # If no hydrogens are identified at a given frame, check an
        # empty donor atom group is created
        test_kwargs = TestHydrogenBondAnalysisTIP3P.kwargs.copy()
        test_kwargs['donors_sel'] = None  # use topology to find pairs
        test_kwargs['hydrogens_sel'] = "name H"  # no atoms have name H

        h = HydrogenBondAnalysis(universe, **test_kwargs)
        h.run()

        assert h._hydrogens.n_atoms == 0
        assert h._donors.n_atoms == 0
        assert h.hbonds.size == 0
예제 #3
0
    def test_first(self, universe):

        h = HydrogenBondAnalysis(universe, **self.kwargs)
        h.run()

        assert len(h.hbonds) == 2

        frame_no, donor_index, hydrogen_index, acceptor_index, da_dst, dha_angle = h.hbonds[
            0]
        assert_equal(donor_index, 0)
        assert_equal(hydrogen_index, 2)
        assert_equal(acceptor_index, 3)
        assert_almost_equal(da_dst, 2.5)
        assert_almost_equal(dha_angle, 180)
예제 #4
0
    def test_no_bond_info_exception(self, universe):

        kwargs = {
            'donors_sel': None,
            'hydrogens_sel': None,
            'acceptors_sel': None,
            'd_h_cutoff': 1.2,
            'd_a_cutoff': 3.0,
            'd_h_a_angle_cutoff': 120.0
        }

        with pytest.raises(NoDataError, match="no bond information"):
            h = HydrogenBondAnalysis(universe, **kwargs)
            h._get_dh_pairs()
예제 #5
0
def parallel_hb(PDB, XTC, donor_sel, acceptor_sel, start=0, stop=None, stride=1,
                up_sels=False, dist=3.5, angle=120.0, output_csv="hb"):
    """
    Perform hbond analysis for a chunk of the trajectory

    :param PDB: pdb/psf file
    :param XTC: traj file
    :param start:   first frame of computation
    :param stop:    last frame of computation (uses python convention, so it is not computed)
    :param stride:  step
    :param donor_sel:       selection of atoms involved in hbond (def: "protein")
    :param acceptor_sel:    selection of atoms involved in hbond (def: "protein")
    :param dist:    distance criterion for hbond
    :param angle:   angle criterion for hbond
    :param accepts: additional acceptor atoms
    :param dons:    additional donor atoms
    :param output_csv:    beginning of
    :return:
    save the temporary df as csv.
    """
    print('Initialising: ' + multiprocessing.current_process().name)
    input_uni = mda.Universe(PDB, XTC, inmemory=False)
    input_hb = HBA(input_uni,
                   update_selections=up_sels,
                   donors_sel=donor_sel,
                   acceptors_sel=acceptor_sel,
                   d_a_cutoff=dist,
                   d_h_a_angle_cutoff=angle)
    #    input_hb.donors_sel=donor_sel
    #    input_hb.acceptors_sel=acceptor_sel
    #    input_hb.hydrogens_sel = input_hb.guess_hydrogens("name ?H*")

    #     print(f"distance: {input_hb.distance}")
    print(f"{multiprocessing.current_process().name} doing from {start} to {stop}, every {stride} frame")
    input_hb.run(start=start, stop=stop, step=stride)
    hb_csv = f'{output_csv}_{start}_{stop}.csv'
    print('Creating table: ' + multiprocessing.current_process().name)
    _h_results = input_hb.hbonds
    _df = pd.DataFrame(_h_results, index=_h_results[:, 0],
                       columns=['time', 'donor_idx', 'hydrogen_idx', 'acceptor_idx', 'distance', 'angle'])

    _df.to_csv(hb_csv)
    return True
예제 #6
0
def hbonds_bound(props):
    g_anchor = U.select_atoms(props['anchor'])
    hbonds = defaultdict(list)
    for d_key, donor_h in props['donors_and_h'].items():
        d_residues = U.select_atoms(donor_h[0]).residues
        for a_key, acceptor in props['acceptors'].items():
            pair = "{}-->{}".format(d_key, a_key)
            print(pair)
            for d_res in d_residues[:1]:
                hba = HBA(universe=U,
                          donors_sel=donor_h[0] +
                          " and resid {}".format(d_res.resid),
                          hydrogens_sel=donor_h[1] +
                          " and resid {}".format(d_res.resid),
                          acceptors_sel=acceptor,
                          d_a_cutoff=props['d_a_cutoff'],
                          d_h_a_angle_cutoff=props['d_h_a_angle_cutoff'],
                          update_selections=False)
                hba.run()
                dists_d_anchor = np.array([
                    np.linalg.norm(d_res.atoms.center_of_mass() -
                                   g_anchor.center_of_mass())
                    for ts in U.trajectory
                ])
                bound_mask = dists_d_anchor < props['d_bound']
                try:
                    hba_time = hba.count_by_time()
                    hba_time_masked = list(hba_time[bound_mask])
                except:
                    hba_time_masked = []
                hbonds[pair] += hba_time_masked
            if hbonds[pair] == []:
                hbonds[pair] = (0.0, 0.0)
            else:
                hbonds[pair] = (np.mean(hbonds[pair]), np.std(hbonds[pair]))
    return hbonds
예제 #7
0
import MDAnalysis
from MDAnalysis.analysis.hydrogenbonds.hbond_analysis import HydrogenBondAnalysis as HBA

pdb = 'Triple_cWW_cHW_UAU_rpr_addChimera_onlyBases.pdb'
u = MDAnalysis.Universe(pdb)  #s, pdb)

hbonds = HBA(universe=u)
hbonds.run()
예제 #8
0
output_name = "fwd_Barrier2"
# Cut off Values to be used by MDAnalysis for Nucleotides 3.5Ang and 140 degrees is standard
distance_cutoff = 3.5
angle_cutoff = 140
donor_heavy = '(resname ARG and name NE NH1 NH2) or (resname ASN and name ND2) or (resname GLN and name NE2) or (resname GLU and name N) or (resname SER and name OG) or (resname THR and name OG1) or (resname TYR and name OH) or (resname CYS and name SG) or (resname LYS and name NZ)'
acceptor_heavy = "resname ATP and name N1 N3 N6 N7 O2' O3' O5' O1A O2A O3A O1B O2B O3B O1G O2G O3G'"

#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Analysis!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# Read in universe object and get total frames for occupancy percentage
u = MDAnalysis.Universe(topology, trajectory)
totalframes = len(u.trajectory)

# Create H-Bond Analysis class using input parameters
hbonds = HBA(universe=u,
             donors_sel=donor_heavy,
             acceptors_sel=acceptor_heavy,
             d_a_cutoff=distance_cutoff,
             d_h_a_angle_cutoff=angle_cutoff,
             update_selections=False)
print("Begin H Bond Analysis")
start = time.time()
hbonds.run()
print(f'Analysis complete total time = {time.time()-start} seconds')
print("Printing results .....")
# Get results
hbond_ids = hbonds.count_by_ids()
hcount = hbonds.count_by_time()

# Print out results
f1 = open(f'{output_name}_hbondInfo.dat', 'w')
for donor, hydro, acceptor, occupancy in hbond_ids:
    print(
예제 #9
0
 def h(self, universe):
     h = HydrogenBondAnalysis(universe, **self.kwargs)
     h.run()
     return h
예제 #10
0
 def h(self, universe):
     h = HydrogenBondAnalysis(universe, **self.kwargs)
     h.run(start=1, step=2)
     return h