Example #1
0
def test_array_conversion(path):
    pdbx_file = pdbx.PDBxFile.read(path)
    ref_structure = pdbx.get_structure(pdbx_file,
                                       model=1,
                                       extra_fields=["charge"])
    ref_structure.bonds = struc.connect_via_residue_names(ref_structure)

    pdbqt_file = pdbqt.PDBQTFile()
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        # Ignore warnings about atoms not parametrized
        mask = pdbqt.set_structure(pdbqt_file, ref_structure)
    ref_structure = ref_structure[mask]
    temp = TemporaryFile("r+")
    pdbqt_file.write(temp)

    temp.seek(0)
    pdbqt_file = pdbqt.PDBQTFile.read(temp)
    test_structure = pdbqt.get_structure(pdbqt_file, model=1)
    temp.close()

    assert np.allclose(test_structure.coord, ref_structure.coord)
    for category in test_structure.get_annotation_categories():
        if category == "element":
            # PDBQT uses special atom types, which replace the usual
            # elements
            # -> there cannot be equality of the 'element' annotation
            continue
        try:
            assert np.array_equal(test_structure.get_annotation(category),
                                  ref_structure.get_annotation(category))
        except AssertionError:
            print(f"Inequality in '{category}' category")
            raise
Example #2
0
def test_command(command_name, kwargs):
    reset()
    pdbx_file = pdbx.PDBxFile.read(join(data_dir, "1l2y.cif"))
    structure = pdbx.get_structure(pdbx_file)
    structure.bonds = struc.connect_via_residue_names(structure)
    pymol_obj = PyMOLObject.from_structure(structure)
    command = getattr(PyMOLObject, command_name)
    command(pymol_obj, **kwargs)
Example #3
0
def test_both_directions(path, state):
    pdbx_file = pdbx.PDBxFile.read(path)
    ref_array = pdbx.get_structure(pdbx_file, model=state)
    ref_array.bonds = struc.connect_via_residue_names(ref_array)

    reset()
    test_array = PyMOLObject.from_structure(ref_array) \
                            .to_structure(state=state, include_bonds=True)

    for cat in ref_array.get_annotation_categories():
        assert (test_array.get_annotation(cat) == ref_array.get_annotation(cat)
                ).all()
    assert np.allclose(test_array.coord, ref_array.coord)
    assert test_array.bonds == ref_array.bonds
Example #4
0
def test_bond_parsing():
    """
    Compare parsing of bonds from PDB with output from
    :func:`connect_via_residue_names()`.
    """
    # Choose a structure with CONECT records to test these as well
    path = join(data_dir("structure"), "3o5r.pdb")
    pdb_file = pdb.PDBFile.read(path)
    atoms = pdb.get_structure(pdb_file, model=1, include_bonds=True)

    test_bonds = atoms.bonds

    ref_bonds = struc.connect_via_residue_names(atoms)
    ref_bonds.remove_bond_order()

    assert test_bonds.as_set() == ref_bonds.as_set()
Example #5
0
def test_connect_via_residue_names(single_model):
    """
    Test whether the created bond list is equal to the bonds deposited
    in the MMTF file.
    """
    # Structure with peptide, nucleotide, small molecules and water
    file = mmtf.MMTFFile.read(join(data_dir("structure"), "5ugo.mmtf"))
    if single_model:
        atoms = mmtf.get_structure(file, include_bonds=True, model=1)
    else:
        atoms = mmtf.get_structure(file, include_bonds=True)

    ref_bonds = atoms.bonds

    test_bonds = struc.connect_via_residue_names(atoms)

    assert test_bonds == ref_bonds
Example #6
0
def test_select(random_seed):
    reset()

    pdbx_file = pdbx.PDBxFile.read(join(data_dir, "1l2y.cif"))
    array = pdbx.get_structure(pdbx_file, model=1)
    # Add bonds to avoid warning
    array.bonds = struc.connect_via_residue_names(array)
    
    # Use B factor as indicator if the selection was correctly applied
    array.set_annotation("b_factor", np.zeros(array.array_length()))
    pymol_object = PyMOLObject.from_structure(array)
    
    np.random.seed(random_seed)
    ref_mask = np.random.choice([False, True], array.array_length())
    
    # The method that is actually tested
    test_selection = pymol_object.where(ref_mask)
    # Set B factor of all masked atoms to 1
    cmd.alter(test_selection, "b=1.0")
    test_b_factor = pymol_object.to_structure(state=1).b_factor
    # Get the mask from the occupancy back again
    test_mask = (test_b_factor == 1.0)

    assert np.array_equal(test_mask, ref_mask)
Example #7
0
import biotite
import biotite.structure as struc
import ammolite

PNG_SIZE = (1000, 750)

# General configuration
ammolite.cmd.set("cartoon_oval_length", 0.8)
ammolite.cmd.set("depth_cue", 0)

# Define colors
for color_name, color_value in biotite.colors.items():
    ammolite.cmd.set_color("biotite_" + color_name, to_rgb(color_value))

# Add bonds to structures and convert to PyMOL
ku_dna.bonds = struc.connect_via_residue_names(ku_dna)
ku_superimposed.bonds = struc.connect_via_residue_names(ku_superimposed)
pymol_obj_1 = ammolite.PyMOLObject.from_structure(ku_dna)
pymol_obj_2 = ammolite.PyMOLObject.from_structure(ku_superimposed)

# Set overall colors
pymol_obj_1.color("biotite_lightorange", ku_dna.chain_id == "A")
pymol_obj_1.color("biotite_dimorange", ku_dna.chain_id == "B")
pymol_obj_2.color("biotite_lightgreen", ku_superimposed.chain_id == "A")
pymol_obj_2.color("biotite_green", ku_superimposed.chain_id == "B")

# Set view
pymol_obj_1.orient()

# Save image
ammolite.cmd.ray(*PNG_SIZE)
PNG_SIZE = (1000, 550)

# General configuration
ammolite.cmd.set("cartoon_side_chain_helper", 1)
ammolite.cmd.set("cartoon_discrete_colors", 1)
ammolite.cmd.set("depth_cue", 0)
ammolite.cmd.set("cartoon_oval_length", 0.8)

# Define colors
for color_name, color_value in biotite.colors.items():
    ammolite.cmd.set_color("biotite_" + color_name, to_rgb(color_value))

# Add bonds to structure and convert to PyMOL
structure = structure[~struc.filter_solvent(structure)]
structure.bonds = struc.connect_via_residue_names(structure)
pymol_obj = ammolite.PyMOLObject.from_structure(structure)

# Set overall colors
pymol_obj.color("gray", np.isin(structure.chain_id, ["A", "B"]))
pymol_obj.color("biotite_brightorange", structure.chain_id == "L")
pymol_obj.color("biotite_lightgreen", structure.chain_id == "R")

# Set view
ammolite.cmd.set_view(
    (-0.044524662, 0.767611504, 0.639355302, 0.998693943, 0.018437184,
     0.047413416, 0.024606399, 0.640637815, -0.767439663, 0.000000000,
     0.000000000, -115.614288330, 56.031833649, 23.317802429, 3.761308193,
     73.517341614, 157.711288452, -20.000000000))

# Highlight contacts