Пример #1
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)
Пример #2
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
Пример #3
0
def test_to_biotite(path, altloc, state):
    pdbx_file = pdbx.PDBxFile.read(path)
    ref_array = pdbx.get_structure(pdbx_file, model=state, altloc=altloc)

    reset()
    cmd.load(path, "test")
    test_array = PyMOLObject("test").to_structure(state=state, altloc=altloc)

    for cat in [
            c for c in ref_array.get_annotation_categories()
            if c != "altloc_id"
    ]:
        assert (test_array.get_annotation(cat) == ref_array.get_annotation(cat)
                ).all()
    assert np.allclose(test_array.coord, ref_array.coord)
Пример #4
0
def test_to_pymol(path):
    reset()
    cmd.load(path, "test")
    ref_model = cmd.get_model("test", 1)

    pdbx_file = pdbx.PDBxFile.read(path)
    atom_array = pdbx.get_structure(
        pdbx_file, model=1, extra_fields=["b_factor", "occupancy", "charge"])
    test_model = convert_to_chempy_model(atom_array)

    test_atoms = test_model.atom
    ref_atoms = [atom for atom in ref_model.atom if atom.alt in ("", "A")]
    assert len(test_atoms) == len(ref_atoms)
    for test_atom, ref_atom in zip(test_atoms, ref_atoms):
        assert test_atom.symbol == ref_atom.symbol
        assert test_atom.name == ref_atom.name
        assert test_atom.resn == ref_atom.resn
        assert test_atom.ins_code == ref_atom.ins_code
        assert test_atom.resi_number == ref_atom.resi_number
        assert test_atom.b == pytest.approx(ref_atom.b)
        assert test_atom.q == pytest.approx(ref_atom.q)
        assert test_atom.hetatm == ref_atom.hetatm
        assert test_atom.chain == ref_atom.chain
        assert test_atom.coord == pytest.approx(ref_atom.coord)
Пример #5
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)