def test_multiple_mutations(pdb3aid):
    mol = pdb3aid
    mut = mdt.mutate_residues(
        mol, ['A.2S', 'B.3S'])  # Mutate Chain A res 2 and B 3 to SER
    assert [r.resname
            for r in mut.chains['A'].get_residues(pdbindex=2)] == ['SER']
    assert [r.resname
            for r in mut.chains['B'].get_residues(pdbindex=3)] == ['SER']
def test_mutation_nomenclature_string_only(pdb3aid):
    mol = pdb3aid
    res25 = mol.get_residues(pdbindex=25)
    assert len(res25) == 2
    assert [r.resname for r in res25] == ['ASP', 'ASP']

    mut = mdt.mutate_residues(mol, 'D25M')  # Mutate ALA43 to MET43
    assert mut.get_residues()
    mut25 = mut.get_residues(pdbindex=25)
    assert len(mut25) == 2
    assert [r.resname for r in mut25] == ['MET', 'MET']
def test_mutation_nomenclature_string_only(pdb3aid):
    mol = pdb3aid
    res25 = mol.get_residues(pdbindex=25)
    assert len(res25) == 2
    assert [r.resname for r in res25] == ['ASP', 'ASP']

    mut = mdt.mutate_residues(mol, 'D25M')  # Mutate ALA43 to MET43
    assert mut.get_residues()
    mut25 = mut.get_residues(pdbindex=25)
    assert len(mut25) == 2
    assert [r.resname for r in mut25] == ['MET', 'MET']
def test_mutation_topology(pdb1yu8):
    """ Test the topology of the backbone atoms for a mutated molecule. """
    molecule = pdb1yu8 
    mutation_residues = ["X.13G"]
    mutated_molecule = mdt.mutate_residues(molecule, mutation_residues)
    # Check that the number of bonds for backbone atoms match.
    for res, mut_res in zip(molecule.residues, mutated_molecule.residues):
        if not res.backbone:
            continue 
        for atom in res.backbone:
            bonds = [bond for bond in molecule.bond_graph[atom] if bond.name in res.backbone]
            mut_atom = mutated_molecule.chains["X"].residues[mut_res.name].atoms[atom.name]
            mut_bonds = mutated_molecule.bond_graph[mut_atom]
            mut_bonds = [bond for bond in mutated_molecule.bond_graph[mut_atom] \
                if bond.name in mut_res.backbone]
            assert len(bonds) == len(mut_bonds)
def test_mutation_topology(pdb1yu8):
    """ Test the topology of the backbone atoms for a mutated molecule. """
    molecule = pdb1yu8
    mutation_residues = ["X.13G"]
    mutated_molecule = mdt.mutate_residues(molecule, mutation_residues)
    # Check that the number of bonds for backbone atoms match.
    for res, mut_res in zip(molecule.residues, mutated_molecule.residues):
        if not res.backbone:
            continue
        for atom in res.backbone:
            bonds = [
                bond for bond in molecule.bond_graph[atom]
                if bond.name in res.backbone
            ]
            mut_atom = mutated_molecule.chains["X"].residues[
                mut_res.name].atoms[atom.name]
            mut_bonds = mutated_molecule.bond_graph[mut_atom]
            mut_bonds = [bond for bond in mutated_molecule.bond_graph[mut_atom] \
                if bond.name in mut_res.backbone]
            assert len(bonds) == len(mut_bonds)
def _mutate_and_check(mol, residx, resname, allatoms):
    newmol = mdt.mutate_residues(mol, {mol.residues[residx]: resname})

    assert newmol.num_chains == mol.num_chains
    assert mol.num_residues == newmol.num_residues
    foundnew = False

    for i, (res, newres) in enumerate(zip(mol.residues, newmol.residues)):
        if i == residx:
            foundnew = True
            assert newres.resname == resname
            assert newres.name == resname+str(newres.pdbindex)
            atomnames = set(atom.name for atom in newres)
            assert len(atomnames) == newres.num_atoms
            assert atomnames.issubset(allatoms)
        else:
            assert res.name == newres.name
            assert res.num_atoms == newres.num_atoms

            for oldatom, newatom in zip(res, newres):
                assert oldatom.name == newatom.name
                assert oldatom.atnum == newatom.atnum
                if not foundnew:
                    assert oldatom.pdbindex == newatom.pdbindex
def _mutate_and_check(mol, residx, resname, allatoms):
    newmol = mdt.mutate_residues(mol, {mol.residues[residx]: resname})

    assert newmol.num_chains == mol.num_chains
    assert mol.num_residues == newmol.num_residues
    foundnew = False

    for i, (res, newres) in enumerate(zip(mol.residues, newmol.residues)):
        if i == residx:
            foundnew = True
            assert newres.resname == resname
            assert newres.name == resname + str(newres.pdbindex)
            atomnames = set(atom.name for atom in newres)
            assert len(atomnames) == newres.num_atoms
            assert atomnames.issubset(allatoms)
        else:
            assert res.name == newres.name
            assert res.num_atoms == newres.num_atoms

            for oldatom, newatom in zip(res, newres):
                assert oldatom.name == newatom.name
                assert oldatom.atnum == newatom.atnum
                if not foundnew:
                    assert oldatom.pdbindex == newatom.pdbindex
def test_mutate_docstring_dict_example(pdb3aid):
    mol = pdb3aid
    assert mol.residues[5].resname != 'ALA'
    mut = mdt.mutate_residues(mol, {mol.residues[5]: 'ALA'})  # mutate residue 5 to ALA
    assert mut.residues[5].resname == 'ALA'
def test_multiple_mutations(pdb3aid):
    mol = pdb3aid
    mut = mdt.mutate_residues(mol, ['A.2S', 'B.3S'])  # Mutate Chain A res 2 and B 3 to SER
    assert [r.resname for r in mut.chains['A'].get_residues(pdbindex=2)] == ['SER']
    assert [r.resname for r in mut.chains['B'].get_residues(pdbindex=3)] == ['SER']
def test_mutate_docstring_dict_example(pdb3aid):
    mol = pdb3aid
    assert mol.residues[5].resname != 'ALA'
    mut = mdt.mutate_residues(
        mol, {mol.residues[5]: 'ALA'})  # mutate residue 5 to ALA
    assert mut.residues[5].resname == 'ALA'