Exemple #1
0
def _retrieve_fragment(fragment, old_atoms, atom_core, hydrogen_core, atom_fragment, mapping):
    from rdkit import Chem

    # Get new added hydrogen
    try:
        added_hydrogen_idx = [atom.GetIdx() for atom in fragment.GetAtoms() if atom.GetIdx() not in old_atoms][0]
        no_hydrogens = False
        # Get fragment atom attached to newly added hydrogen
        atom_fragment_idx = fragment.GetAtomWithIdx(added_hydrogen_idx).GetNeighbors()[0].GetIdx()
    except IndexError:
        logger.info("Hydrogen detection failed won't have into account steriochemistry")
        added_hydrogen_idx = 0
        no_hydrogens = True
        atom_fragment_idx = mapping[atom_fragment]
        print("Final atom fragment", atom_fragment_idx)

    # Save fragment
    string = random_string(8)
    fragment_filename = fragment.GetProp("_Name").replace(" ", "_") + string + ".pdb"

    Chem.MolToPDBFile(fragment, fragment_filename)
    fragment = Chem.MolFromPDBFile(fragment_filename, removeHs=False)
    added_hydrogen = at.Atom(fragment, added_hydrogen_idx)
    atom_fragment_attach_to_hydrogen = at.Atom(fragment, atom_fragment_idx)

    # Build fragment object
    fragment = fr.Fragment(fragment_filename, atom_fragment_attach_to_hydrogen,
                           added_hydrogen, atom_core, hydrogen_core, no_hydrogens)
    return fragment
def _retrieve_fragment(fragment, old_atoms, atom_core, hydrogen_core):
    from rdkit import Chem
    import rdkit.Chem.rdmolops as rd
    import rdkit.Chem.rdchem as rc
    # Get new added hydrogen
    try:
        added_hydrogen_idx = [
            atom.GetIdx() for atom in fragment.GetAtoms()
            if atom.GetIdx() not in old_atoms
        ][0]
        no_hydrogens = False
    except IndexError:
        print(
            "Hydrogen detection failed won't have into account steriochemistry"
        )
        added_hydrogen_idx = 0
        no_hydrogens = True
    # Get fragment atom attached to newly added hydrogen
    atom_fragment_idx = fragment.GetAtomWithIdx(
        added_hydrogen_idx).GetNeighbors()[0].GetIdx()
    # Save fragment
    fragment_filename = fragment.GetProp("_Name") + ".pdb"
    Chem.MolToPDBFile(fragment, fragment_filename)
    fragment = Chem.MolFromPDBFile(fragment_filename, removeHs=False)
    added_hydrogen = at.Atom(fragment, added_hydrogen_idx)
    atom_fragment_attach_to_hydrogen = at.Atom(fragment, atom_fragment_idx)
    # Build fragment object
    fragment = fr.Fragment(fragment_filename, atom_fragment_attach_to_hydrogen,
                           added_hydrogen, atom_core, hydrogen_core,
                           no_hydrogens)
    return fragment
def _build_fragment_from_complex(complex,
                                 residue,
                                 ligand,
                                 ligand_core,
                                 result=0,
                                 substructure=True,
                                 simmetry=False):
    from rdkit import Chem
    import rdkit.Chem.rdmolops as rd
    import rdkit.Chem.rdchem as rc
    import rdkit.Chem.AllChem as rp

    #Retrieve atom core linking fragment
    try:
        atom_core_idx, atoms_core, _ = _search_core_fragment_linker(
            ligand, ligand_core, result, simmetry)
    except TypeError:
        raise ce.SameMolecule(
            "Core and ligand are the exact same molecule. Check your inputs")
    atom_core = at.Atom(ligand_core, atom_core_idx)
    mol = Chem.MolFromPDBFile(complex, removeHs=False)

    #Retrieve hydrogen core attach to linking atom
    original = rd.SplitMolByPDBResidues(mol)[residue]
    hydrogen_core_idx = [
        atom.GetIdx()
        for atom in original.GetAtomWithIdx(atom_core_idx).GetNeighbors()
        if atom.GetAtomicNum() == 1
    ][0]
    hydrogen_core = at.Atom(original, hydrogen_core_idx)

    # Delete core for full ligand with substructure
    # and if it fails manually
    #Chem.MolToPDBFile(ligand, "int0.pdb")
    if substructure:
        fragment = rd.DeleteSubstructs(ligand, ligand_core)
        new_mol = rc.EditableMol(fragment)
        for atom in reversed(fragment.GetAtoms()):
            neighbours = atom.GetNeighbors()
            if len(neighbours) == 0: new_mol.RemoveAtom(atom.GetIdx())
    else:
        new_mol = rc.EditableMol(ligand)
        for atom in atoms_core:
            new_mol.RemoveAtom(atom)
        #Chem.MolToPDBFile(new_mol.GetMol(), "int1.pdb")
        for atom in reversed(new_mol.GetMol().GetAtoms()):
            neighbours = atom.GetNeighbors()
            if len(neighbours) == 0: new_mol.RemoveAtom(atom.GetIdx())

    #Add missing hydrogen to full ligand and create pdb differently
    #depending on the previous step
    fragment = new_mol.GetMol()
    #Chem.MolToPDBFile(fragment, "int2.pdb")
    old_atoms = [atom.GetIdx() for atom in fragment.GetAtoms()]
    if substructure:
        fragment = Chem.AddHs(fragment, False, True)
    else:
        #res = rp.EmbedMolecule(fragment)
        fragment = Chem.AddHs(fragment, False, True)
    return fragment, old_atoms, hydrogen_core, atom_core
Exemple #4
0
def _build_fragment_from_complex(complex, residue, ligand, ligand_core, result=0, substructure=True, simmetry=False):
    from rdkit import Chem
    import rdkit.Chem.rdmolops as rd
    import rdkit.Chem.rdchem as rc

    # Retrieve atom core linking fragment
    try:
        atom_core_idx, atoms_core, atom_fragment = _search_core_fragment_linker(ligand, ligand_core, result, simmetry)
        print("ATOM OF FRAGMENT ATTACHED TO CORE:", atom_fragment)
        print("ATOM OF CORE ATTACHED TO FRAGMENT:", atom_core_idx)
    except TypeError:
        raise ce.SameMolecule("Core and ligand are the exact same molecule. Check your inputs.")
    atom_core = at.Atom(ligand_core, atom_core_idx)
    mol = Chem.MolFromPDBFile(complex, removeHs=False)

    # Retrieve hydrogen core attach to linking atom
    original = rd.SplitMolByPDBResidues(mol)[residue]
    hydrogen_core_idx = \
        [atom.GetIdx() for atom in original.GetAtomWithIdx(atom_core_idx).GetNeighbors() if atom.GetAtomicNum() == 1][0]
    hydrogen_core = at.Atom(original, hydrogen_core_idx)


    # Delete core for full ligand with substructure and if it fails manually
    if substructure:
        fragment = rd.DeleteSubstructs(ligand, ligand_core)
        new_mol = rc.EditableMol(fragment)
        for atom in reversed(fragment.GetAtoms()):
            neighbours = atom.GetNeighbors()
            if len(neighbours) == 0 and atom.GetAtomicNum() == 1:
                new_mol.RemoveAtom(atom.GetIdx())
    else:
        new_mol = rc.EditableMol(ligand)

        for atom in reversed(atoms_core):
            new_mol.RemoveAtom(atom)


        for atom in reversed(new_mol.GetMol().GetAtoms()):
            neighbours = atom.GetNeighbors()
            if len(neighbours) == 0 and atom.GetAtomicNum() == 1:
                new_mol.RemoveAtom(atom.GetIdx())
    print("FRAGMENT ATOMS", [atom.GetIdx() for atom in new_mol.GetMol().GetAtoms()])

    # Add missing hydrogen to full ligand and create pdb differently depending on the previous step
    fragment = new_mol.GetMol()
    old_atoms = [atom.GetIdx() for atom in fragment.GetAtoms() if atom.GetAtomicNum() != 1]
    new_atoms = [atom.GetIdx() for atom in ligand.GetAtoms() if
                 atom.GetIdx() not in atoms_core and atom.GetAtomicNum() != 1]
    print("old_atoms", old_atoms, "new_atoms", new_atoms)
    mapping = {new_atom: old_atom for new_atom, old_atom in zip(new_atoms, old_atoms)}
    atom_fragment_mapped = mapping[atom_fragment]

    fragment = Chem.AddHs(fragment, False, True)
    correct = _check_fragment(fragment, ligand, mapping, atom_fragment, atom_fragment_mapped, ligand_core)
    Chem.MolToPDBFile(fragment, "int0.pdb")
    assert len(old_atoms) == len(new_atoms)
    return fragment, old_atoms, hydrogen_core, atom_core, atom_fragment, mapping, correct
def _build_fragment_from_complex(complex,
                                 residue,
                                 ligand,
                                 ligand_core,
                                 result=0,
                                 substructure=True,
                                 symmetry=False,
                                 frag_core_atom=None):
    """

    Parameters
    ----------
    complex : str
              Path of PDB file with protein-ligand complex.

    residue : str
              Residue name.

    ligand : RDKit molecule object
             Ligand to grow during the simulation.

    ligand_core : RDKit molecule object
                  Common structure of each grown ligand.

    result : int
             Index to extract core atoms from the substructure search.

    substructure : bool
                   Delete core for full ligand with substructure.

    symmetry : bool
               Check the symmetry of the ligand.

    Returns
    -------
    fragment : RDKit molecule object
               Grown ligand with deleted core atoms.

    old_atoms : list
                Idx for each atom of grown ligand without core.

    hydrogen_core : pele_platform.Frag.atoms.Atom
                    Hydrogen core attached to linking atom.

    atom_core : pele_platform.Frag.atoms.Atom
                Atom object of the hydrogen core atom attached to linking atom.

    atom_fragment : int
                    Atom of the fragment attached to the core.

    mapping : dict
              Mapping of Idx for old atoms and full fragment atoms.

    correct : bool
              Checks if the fragment is correct (fragment size, chirality, missing hydrogens)

    Raises
    ------
    TypeError
        If the core and ligand are the same molecule.
    """

    # Retrieve atom core linking fragment
    try:
        atom_core_idx, atoms_core, atom_fragment = _search_core_fragment_linker(
            ligand, ligand_core, result, symmetry, frag_core_atom)
        print("ATOM OF FRAGMENT ATTACHED TO CORE:", atom_fragment)
        print("ATOM OF CORE ATTACHED TO FRAGMENT:", atom_core_idx)
    except TypeError:
        raise ce.SameMolecule(
            "Core and ligand are the exact same molecule. Check your inputs.")
    atom_core = at.Atom(ligand_core, atom_core_idx)
    mol = Chem.MolFromPDBFile(complex, removeHs=False)

    # Retrieve hydrogen core attach to linking atom
    original = rd.SplitMolByPDBResidues(mol)[residue]
    hydrogen_core_idx = \
        [atom.GetIdx() for atom in original.GetAtomWithIdx(atom_core_idx).GetNeighbors() if atom.GetAtomicNum() == 1][0]
    hydrogen_core = at.Atom(original, hydrogen_core_idx)

    # Delete core for full ligand with substructure and if it fails manually
    if substructure:
        fragment = rd.DeleteSubstructs(ligand, ligand_core)
        new_mol = rc.EditableMol(fragment)
        for atom in reversed(fragment.GetAtoms()):
            neighbours = atom.GetNeighbors()
            if len(neighbours) == 0 and atom.GetAtomicNum() == 1:
                new_mol.RemoveAtom(atom.GetIdx())
    else:
        new_mol = rc.EditableMol(ligand)

        for atom in reversed(atoms_core):
            new_mol.RemoveAtom(atom)

        for atom in reversed(new_mol.GetMol().GetAtoms()):
            neighbours = atom.GetNeighbors()
            if len(neighbours) == 0 and atom.GetAtomicNum() == 1:
                new_mol.RemoveAtom(atom.GetIdx())
    print("FRAGMENT ATOMS",
          [atom.GetIdx() for atom in new_mol.GetMol().GetAtoms()])

    # Add missing hydrogen to full ligand and create pdb differently depending on the previous step
    fragment = new_mol.GetMol()
    old_atoms = [
        atom.GetIdx() for atom in fragment.GetAtoms()
        if atom.GetAtomicNum() != 1
    ]
    new_atoms = [
        atom.GetIdx() for atom in ligand.GetAtoms()
        if atom.GetIdx() not in atoms_core and atom.GetAtomicNum() != 1
    ]
    print("old_atoms", old_atoms, "new_atoms", new_atoms)
    mapping = {
        new_atom: old_atom
        for new_atom, old_atom in zip(new_atoms, old_atoms)
    }
    atom_fragment_mapped = mapping[atom_fragment]

    # Retrieve all atom idxs before adding hydrogen to fragment_atom
    fragment_atoms_wo_hydrogen = [
        atom.GetIdx() for atom in fragment.GetAtoms()
    ]

    fragment = Chem.AddHs(fragment, False, True)
    correct = _check_fragment(fragment, ligand, mapping, atom_fragment,
                              atom_fragment_mapped, ligand_core)
    Chem.MolToPDBFile(fragment, "int0.pdb")
    assert len(old_atoms) == len(new_atoms)
    return fragment, old_atoms, hydrogen_core, atom_core, atom_fragment, mapping, correct, fragment_atoms_wo_hydrogen
def _retrieve_fragment(fragment, old_atoms, atom_core, hydrogen_core,
                       atom_fragment, mapping, fragment_atoms_wo_hydrogen):
    """

    Parameters
    ----------
    old_atoms : list
                Idx for each atom of grown ligand without core.

    atom_core : pele_platform.Frag.atoms.Atom
                Atom object of the hydrogen core atom attached to linking atom.

    hydrogen_core : pele_platform.Frag.atoms.Atom
                    Hydrogen core attached to linking atom.

    atom_fragment : int
                    Atom of the fragment attached to the core.

    mapping : dict
              Mapping of Idx for old atoms and full fragment atoms.

    Returns
    -------
    fragment : pele_platform.Frag.fragments.Fragment
               Fragment grown to the ligand during the simulation.

    Raises
    ------
    IndexError
        If the hydrogen detection failed.
    """
    from rdkit import Chem

    # Get new added hydrogen
    try:
        # Identify idx from added hydrogen
        added_hydrogen_idx = [
            atom.GetIdx() for atom in fragment.GetAtoms()
            if atom.GetIdx() not in fragment_atoms_wo_hydrogen
        ][0]
        no_hydrogens = False
        # Get fragment atom attached to newly added hydrogen
        atom_fragment_idx = fragment.GetAtomWithIdx(
            added_hydrogen_idx).GetNeighbors()[0].GetIdx()
    except IndexError:
        print(
            "Hydrogen detection failed won't have into account stereochemistry"
        )
        added_hydrogen_idx = 0
        no_hydrogens = True
        atom_fragment_idx = mapping[atom_fragment]
        print("Final atom fragment", atom_fragment_idx)

    # Save fragment
    string = random_string(8)
    fragment_filename = fragment.GetProp("_Name").replace(
        " ", "_") + string + ".pdb"

    Chem.MolToPDBFile(fragment, fragment_filename)
    fragment = Chem.MolFromPDBFile(fragment_filename, removeHs=False)
    added_hydrogen = at.Atom(fragment, added_hydrogen_idx)
    atom_fragment_attach_to_hydrogen = at.Atom(fragment, atom_fragment_idx)

    # Build fragment object
    fragment = fr.Fragment(fragment_filename, atom_fragment_attach_to_hydrogen,
                           added_hydrogen, atom_core, hydrogen_core,
                           no_hydrogens)
    return fragment