def test_hbond_with_selections(): """ When selection1 and selection2 is defined, no hydrogen bonds outside of this boundary should be found. Also, hbond should respect the selection type. """ stack = load_structure(join(data_dir, "1l2y.mmtf")) selection1 = (stack.res_id == 3) & (stack.atom_name == 'O') # 3TYR BB Ox selection2 = stack.res_id == 7 # backbone hbond should be found if selection1/2 type is both triplets, mask = struc.hbond(stack, selection1, selection2, selection1_type="both") assert len(triplets) == 1 assert triplets[0][0] == 116 assert triplets[0][2] == 38 # backbone hbond should be found if selection1 is acceptor and # selection2 is donor triplets, mask = struc.hbond(stack, selection1, selection2, selection1_type="acceptor") assert len(triplets) == 1 assert triplets[0][0] == 116 assert triplets[0][2] == 38 # no hbond should be found, # because the backbone oxygen cannot be a donor triplets, mask = struc.hbond(stack, selection1, selection2, selection1_type="donor") assert len(triplets) == 0
def test_hbond_structure(pdb_id): file_name = join(data_dir("structure"), pdb_id + ".mmtf") array = load_structure(file_name) # Only consider amino acids for consistency # with bonded hydrogen detection in MDTraj array = array[..., struc.filter_amino_acids(array)] if isinstance(array, struc.AtomArrayStack): # For consistency with MDTraj 'S' cannot be acceptor element # https://github.com/mdtraj/mdtraj/blob/master/mdtraj/geometry/hbond.py#L365 triplets, mask = struc.hbond(array, acceptor_elements=("O", "N")) else: triplets = struc.hbond(array, acceptor_elements=("O", "N")) # Save to new pdb file for consistent treatment of inscode/altloc # im MDTraj temp = NamedTemporaryFile("w+", suffix=".pdb") save_structure(temp.name, array) # Compare with MDTraj import mdtraj traj = mdtraj.load(temp.name) temp.close() triplets_ref = mdtraj.baker_hubbard(traj, freq=0, periodic=False) # Both packages may use different order # -> use set for comparison triplets_set = set([tuple(tri) for tri in triplets]) triplets_ref_set = set([tuple(tri) for tri in triplets_ref]) assert triplets_set == triplets_ref_set
def test_hbond_single_selection(): """ If only selection1 or selection2 is defined, hbond should run against all other atoms as the other selection. """ stack = load_structure(join(data_dir("structure"), "1l2y.mmtf")) selection = (stack.res_id == 2) & (stack.atom_name == "O") # 2LEU BB Ox triplets, mask = struc.hbond(stack, selection1=selection) assert len(triplets) == 2 triplets, mask = struc.hbond(stack, selection2=selection) assert len(triplets) == 2
def test_hbond_total_count(): """ With the standart Baker & Hubbard criterion, 1l2y should have 28 hydrogen bonds with a frequency > 0.1 (comparision with MDTraj results) """ stack = load_structure(join(data_dir("structure"), "1l2y.mmtf")) triplets, mask = struc.hbond(stack) freq = struc.hbond_frequency(mask) assert len(freq[freq >= 0.1]) == 28
def test_hbond_same_res(): """ Check if hydrogen bonds in the same residue are detected. At least one of such bonds is present in 1L2Y (1ASN with N-terminus) (model 2). """ stack = load_structure(join(data_dir("structure"), "1l2y.mmtf")) selection = stack.res_id == 1 # Focus on second model array = stack[1] triplets = struc.hbond(array, selection, selection) assert len(triplets) == 1
def test_hbond_periodicity(translation_vector): """ Test whether hydrogen bond identification uses periodic boundary conditions correctly. For this purpose a structure containing water is loaded and the hydrogen bonds are identified. Then the position of the periodic boundary is changed and it is expected that all hydrogen bonds are still the same """ stack = load_structure(join(data_dir("structure"), "waterbox.gro")) array = stack[0] ref_hbonds = struc.hbond(array, periodic=True) # Put H-bond triplets into as stack for faster comparison with # set for moved atoms ref_hbonds = set([tuple(triplet) for triplet in ref_hbonds]) # Move system and put back into box # -> Equal to move of periodic boundary array = struc.translate(array, translation_vector) array.coord = struc.move_inside_box(array.coord, array.box) hbonds = struc.hbond(array, periodic=True) hbonds = set([tuple(triplet) for triplet in hbonds]) assert ref_hbonds == hbonds
import matplotlib.pyplot as plt import biotite.structure as struc import biotite.structure.io as strucio import biotite.database.rcsb as rcsb file_name = rcsb.fetch("2KB1", "mmtf", biotite.temp_dir()) stack = strucio.load_structure(file_name) # Four identical chains, consider only chain A chain_a = stack[:, stack.chain_id == "A"] # Selection for p-helix p_helix = (chain_a.res_id >= 40) & (chain_a.res_id <= 52) # Selection for selectivity filter sf = (chain_a.res_id >= 53) & (chain_a.res_id <= 58) # Calculate the hydrogen bonds and the frequency of each bond triplets, mask = struc.hbond(chain_a, selection1=p_helix, selection2=sf) freq = struc.hbond_frequency(mask) # Create names of bonds label = "{d_resid}{d_resnm}-{d_a} -- {a_resid}{a_resnm}-{a_a}" names = [label.format( d_resid=chain_a.res_id[donor], d_resnm=chain_a.res_name[donor], d_a=chain_a.atom_name[donor], a_resid=chain_a.res_id[acceptor], a_resnm=chain_a.res_name[acceptor], a_a=chain_a.atom_name[acceptor] ) for donor, _, acceptor in triplets] plt.subplots(figsize=(11,4.5)) plt.bar(names, freq, color=biotite.colors["orange"])
atoms = pairs[0][0] + pairs[0][1] + pairs[1][0] + pairs[1][1] # Color by element colors = np.zeros((atoms.array_length(), 3)) colors[atoms.element == "H"] = (0.8, 0.8, 0.8) # gray colors[atoms.element == "C"] = (0.2, 0.2, 0.2) # darkgray colors[atoms.element == "N"] = (0.0, 0.0, 0.8) # blue colors[atoms.element == "O"] = (0.8, 0.0, 0.0) # red colors[atoms.element == "P"] = (0.0, 0.6, 0.0) # green graphics.plot_atoms( ax, atoms, colors, line_width=3, background_color="white" ) # Plot hydrogen bonds for purine, pyrimidine in pairs: pair = purine + pyrimidine bonds = struc.hbond(pair) for donor, hydrogen, acceptor in bonds: hydrogen_coord = pair.coord[hydrogen] acceptor_coord = pair.coord[acceptor] x, y, z = zip(hydrogen_coord, acceptor_coord) ax.plot(x, y, z, linestyle=":", color="gold", linewidth=2) # Label bases for pair in pairs: for base in pair: label = base.res_name[0][1] ring_center = struc.centroid(base[ np.isin(base.atom_name, ["N1", "C2", "N3", "C4", "C5", "C6"]) ]) x, y, z = ring_center ax.text(
structure = structure[~struc.filter_solvent(structure) & ~struc.filter_monoatomic_ions(structure)] strep_mask = struc.filter_amino_acids(structure) biotin_mask = (structure.res_name == "BTN") pymol_obj = ammolite.PyMOLObject.from_structure(structure) pymol_obj.cartoon("loop", strep_mask) pymol_obj.set("cartoon_transparency", 0.5) pymol_obj.color("salmon", strep_mask & (structure.element == "C")) pymol_obj.color("forest", biotin_mask & (structure.element == "C")) pymol_obj.zoom(biotin_mask, buffer=5.0) ammolite.show(PNG_SIZE) ######################################################################## bonds = struc.hbond(structure, strep_mask, biotin_mask) res_ids = [] for i, (donor, hydrogen, acceptor) in enumerate(bonds): # Highlight streptavidin residues bound to biotin if structure.res_name[donor] != "BTN": res_id = structure.res_id[donor] res_name = structure.res_name[donor] elif structure.res_name[acceptor] != "BTN": res_id = structure.res_id[acceptor] res_name = structure.res_name[acceptor] else: ValueError("The bond is not between streptavidin and biotin") res_ids.append(res_id) pymol_obj.show("sticks", (structure.res_id == res_id) & ~np.isin(structure.atom_name, BACKBONE_ATOMS))