예제 #1
0
def test_select_chain(package, resource, chain_id, expectation, n_atoms):
    """Compare results to expected number of atoms."""
    with resources.path(package, resource) as path:
        molecule = read_molecules(str(path))[0]
        with expectation:
            selection = select_chain(molecule, chain_id)
            assert selection.NumAtoms() == n_atoms
예제 #2
0
def test_remove_non_protein(package, resource, exceptions, remove_water,
                            n_atoms):
    """Compare results to expected number of atoms."""
    with resources.path(package, resource) as path:
        molecule = read_molecules(str(path))[0]
    selection = remove_non_protein(molecule, exceptions, remove_water)
    assert selection.NumAtoms() == n_atoms
예제 #3
0
def test_delete_clashing_sidechains(package, resource, cutoff, sequence):
    """Compare results to expected sequence."""
    with resources.path(package, resource) as path:
        structure = read_molecules(str(path))[0]
        structure = delete_clashing_sidechains(structure, cutoff)
        structure = delete_partial_residues(structure)
        assert get_sequence(structure) == sequence
예제 #4
0
def test_split_molecule_components(package, resource, n_components):
    """
    Compare results to have the expected number of molecular components.
    """
    with resources.path(package, resource) as path:
        structure = read_molecules(str(path))[0]
        components = split_molecule_components(structure)
        assert len(components) == n_components
예제 #5
0
def test_select_altloc(package, resource, alternate_location, expectation,
                       n_atoms):
    """Compare results to expected number of atoms."""
    with resources.path(package, resource) as path:
        molecule = read_molecules(str(path))[0]
        with expectation:
            selection = select_altloc(molecule, alternate_location)
            assert selection.NumAtoms() == n_atoms
예제 #6
0
def test_get_structure_sequence_alignment(package, resource, sequence,
                                          expected_alignment):
    """Compare results to expected sequence alignment."""
    with resources.path(package, resource) as path:
        structure = read_molecules(str(path))[0]
        structure = remove_non_protein(structure, remove_water=True)
        alignment = get_structure_sequence_alignment(structure, sequence)
        for sequence1, sequence2 in zip(alignment, expected_alignment):
            assert sequence1 == sequence2
예제 #7
0
def test_delete_residue(package, resource, chain_id, residue_name, residue_id,
                        expectation, n_atoms):
    """Compare results to number of expected atoms."""
    with resources.path(package, resource) as path:
        with expectation:
            molecule = read_molecules(str(path))[0]
            selection = delete_residue(molecule, chain_id, residue_name,
                                       residue_id)
            assert selection.NumAtoms() == n_atoms
예제 #8
0
def test_read_molecules(package, resource, add_hydrogens, expectation,
                        n_atoms_list):
    """Compare results to expected number of read molecules as well as atoms of each interpreted molecule."""
    with resources.path(package, resource) as path:
        with expectation:
            molecules = read_molecules(str(path), add_hydrogens)
            assert len(molecules) == len(n_atoms_list)
            for molecule, n_atoms in zip(molecules, n_atoms_list):
                assert molecule.NumAtoms() == n_atoms
예제 #9
0
def test_apply_insertions(package_list, resource_list, sequence):
    """Compare results to expected sequence."""
    with resources.path(package_list[0], resource_list[0]) as pdb_path:
        with resources.path(package_list[1], resource_list[1]) as loop_db_path:
            structure = read_molecules(str(pdb_path))[0]
            structure = remove_non_protein(structure, remove_water=True)
            structure_with_insertions = apply_insertions(
                structure, sequence, loop_db_path)
            sequence_with_insertions = get_sequence(structure_with_insertions)
            assert sequence_with_insertions == sequence
예제 #10
0
def test_apply_mutations(package, resource, sequence, delete_fallback,
                         expectation, expected_sequence):
    """Compare results to expected sequence."""
    with resources.path(package, resource) as pdb_path:
        structure = read_molecules(str(pdb_path))[0]
        structure = remove_non_protein(structure, remove_water=True)
        with expectation:
            structure_with_mutations = apply_mutations(structure, sequence,
                                                       delete_fallback)
            sequence_with_mutations = get_sequence(structure_with_mutations)
            assert sequence_with_mutations == expected_sequence
예제 #11
0
def test_assign_caps(package, resource, real_termini, caps):
    """Compare results to expected caps."""
    from openeye import oechem

    with resources.path(package, resource) as path:
        molecule = read_molecules(str(path))[0]
        molecule = select_altloc(molecule, "A")
        molecule = assign_caps(molecule, real_termini)
        hier_view = oechem.OEHierView(molecule)
        found_caps = set([
            residue.GetResidueName() for residue in hier_view.GetResidues()
            if residue.GetResidueName() in ["ACE", "NME"]
        ])
        assert found_caps == caps
예제 #12
0
def test_residue_ids_to_residue_names(package, resource, residue_ids, chain_id,
                                      expectation, residue_names):
    """
    Compare results to have the expected residue names.
    """
    with resources.path(package, resource) as path:
        structure = read_molecules(str(path))[0]
        with expectation:
            found_residue_names = residue_ids_to_residue_names(
                structure, residue_ids, chain_id)
            assert all([
                True for x, y in zip(found_residue_names, residue_names)
                if x == y
            ])
예제 #13
0
def test_superpose_protein(package_list, resource_list, residues, chain_id):
    """
    Check if superposed proteins share a similar protein center.
    This test does not check if the superposition is a good solution.
    """
    import numpy as np

    with resources.path(package_list[0], resource_list[0]) as reference_path:
        reference_structure = read_molecules(str(reference_path))[0]
        with resources.path(package_list[1], resource_list[1]) as fit_path:
            fit_structure = read_molecules(str(fit_path))[0]
            superposed_structure = superpose_proteins(reference_structure,
                                                      fit_structure, residues,
                                                      chain_id)
            superposed_protein = remove_non_protein(superposed_structure,
                                                    remove_water=True)
            reference_protein = remove_non_protein(reference_structure,
                                                   remove_water=True)
            superposed_protein_center = np.mean(
                get_atom_coordinates(superposed_protein))
            reference_protein_center = np.mean(
                get_atom_coordinates(reference_protein))
            assert np.linalg.norm(superposed_protein_center -
                                  reference_protein_center) < 1
예제 #14
0
def test_delete_partial_residues(package, resource, delete_backbone_C,
                                 sequence):
    """Compare results to expected sequence."""
    from openeye import oechem

    with resources.path(package, resource) as path:
        structure = read_molecules(str(path))[0]
        if delete_backbone_C:
            hier_view = oechem.OEHierView(structure)
            hier_residue = hier_view.GetResidue("A", delete_backbone_C[:3],
                                                int(delete_backbone_C[3:]))
            for atom in hier_residue.GetAtoms():
                atom_name = atom.GetName().strip()
                if atom_name == "C":
                    structure.DeleteAtom(atom)
        structure = delete_partial_residues(structure)
        assert get_sequence(structure) == sequence
예제 #15
0
def test_get_atom_coordinates(package, resource):
    """
    Compare results to have the same number of coordinates as atoms and to have exactly three
    floats as coordinates.
    """
    import itertools

    with resources.path(package, resource) as path:
        structure = read_molecules(str(path))[0]
        coordinates = get_atom_coordinates(structure)
        all_floats = all([
            isinstance(coordinate, float)
            for coordinate in itertools.chain.from_iterable(coordinates)
        ])
        assert structure.NumAtoms() == len(coordinates)
        assert set([len(coordinate) for coordinate in coordinates]) == {3}
        assert all_floats
예제 #16
0
def test_renumber_structure(package, resource, residue_ids, expectation):
    """
    Compare results to have the given residue IDs.
    """
    from openeye import oechem

    with resources.path(package, resource) as path:
        structure = read_molecules(str(path))[0]
        with expectation:
            structure = renumber_structure(structure, residue_ids)
            hierview = oechem.OEHierView(structure)
            new_residue_ids = [
                residue.GetResidueNumber()
                for residue in hierview.GetResidues()
            ]
            assert len(residue_ids) == len(new_residue_ids)
            assert all(
                [True for x, y in zip(residue_ids, new_residue_ids) if x == y])
예제 #17
0
def test_prepare_structure(
    package,
    resource,
    has_ligand,
    chain_id,
    altloc,
    ligand_name,
    expectation,
    title_contains,
):
    """Check if returned design unit title contains expected strings."""
    with resources.path(package, resource) as path:
        structure = read_molecules(str(path))[0]
        with expectation:
            design_unit = prepare_structure(
                structure,
                has_ligand=has_ligand,
                chain_id=chain_id,
                alternate_location=altloc,
                ligand_name=ligand_name,
            )
            assert all(x in design_unit.GetTitle() for x in title_contains)
예제 #18
0
def test_update_residue_identifiers(
    package,
    resource,
    keep_protein_residue_ids,
    keep_chain_id,
    chain_ids,
    first_residue_id,
    last_residue_id,
):
    """
    Compare results to contain expected chains, to start with atom serial 1 and for correct residue ID handling.
    """
    from openeye import oechem

    with resources.path(package, resource) as path:
        structure = read_molecules(str(path))[0]
        structure = update_residue_identifiers(
            structure,
            keep_protein_residue_ids=keep_protein_residue_ids,
            keep_chain_ids=keep_chain_id,
        )
        hierview = oechem.OEHierView(structure)
        # check chain IDs
        found_chain_ids = [
            chain.GetChainID() for chain in hierview.GetChains()
        ]
        assert set(found_chain_ids) == set(chain_ids)
        # check atom numbering starts with one
        atoms = structure.GetAtoms()
        assert oechem.OEAtomGetResidue(atoms.next()).GetSerialNumber() == 1
        # check max and min residue ID
        residue_ids = [
            residue.GetResidueNumber() for residue in hierview.GetResidues()
        ]
        assert min(residue_ids) == first_residue_id
        assert max(residue_ids) == last_residue_id
예제 #19
0
def test_get_sequence(package, resource, sequence):
    """Compare results to expected sequence."""
    with resources.path(package, resource) as path:
        structure = read_molecules(str(path))[0]
        assert get_sequence(structure) == sequence
예제 #20
0
def test_get_expression_tags(package, resource, n_expression_tags):
    """Compare results to expected number of expression tags."""
    with resources.path(package, resource) as path:
        molecule = read_molecules(str(path))[0]
    expression_tags = get_expression_tags(molecule)
    assert len(expression_tags) == n_expression_tags
예제 #21
0
def test_delete_short_protein_segments(package, resource, sequence):
    """Compare results to expected sequence."""
    with resources.path(package, resource) as path:
        structure = read_molecules(str(path))[0]
        structure = delete_short_protein_segments(structure)
        assert get_sequence(structure) == sequence