Beispiel #1
0
    def _prepare_input_file(self, logger=None):
        from rdkit import Chem
        import rdkit.Chem.rdmolops as rd

        self.parameters.input = "input.conf"

        params = self.parameters

        # Check input file
        limit_atoms_ligand = 100
        ch.check_limit_number_atoms(params.ligands, limit_atoms_ligand)

        # Get core of the ligand
        mol = Chem.MolFromPDBFile(params.core)
        try:
            ligand_core = rd.SplitMolByPDBResidues(mol)[params.residue]
        except KeyError:
            raise ce.MissResidueFlag("Missing residue flag to specify " +
                                     "the ligand core residue name. " +
                                     "i.e resname: 'LIG'")

        # Get sdf full grown ligands
        ligands_grown = Chem.SDMolSupplier(params.ligands, removeHs=False)
        fragment_files = []

        # For each full grown ligand create neutral fragment
        with open(params.input, "w") as fout:
            pass
        for ligand in ligands_grown:
            Chem.AssignAtomChiralTagsFromStructure(ligand)
            try:
                line, fragment = \
                    self._create_fragment_from_ligand(ligand,
                                                      ligand_core)
            except Exception as e:
                try:
                    line, fragment = \
                        self._create_fragment_from_ligand(ligand,
                                                          ligand_core,
                                                          substructure=False)
                except Exception as e:
                    try:
                        # Try to fix symmetry
                        line, fragment = \
                            self._create_fragment_from_ligand(ligand,
                                                              ligand_core,
                                                              symmetry=True)
                    except Exception as e:
                        # Try with second substructure search
                        line, fragment = \
                            self._create_fragment_from_ligand(
                                ligand, ligand_core,
                                result=1, substructure=False)

            logger.info(f"Ligand {fragment.file} preprocessed")
            fragment_files.append(fragment.file)
            with open(params.input, "a") as fout:
                fout.write(line + "\n")

        return fragment_files
Beispiel #2
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
    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
Beispiel #3
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
Beispiel #4
0
    def _prepare_input_file(self):
        from rdkit import Chem
        import rdkit.Chem.rdmolops as rd
        import rdkit.Chem.rdchem as rc
        import rdkit.Chem.AllChem as rp

        self.input = "input.conf"

        #Check input file
        limit_atoms_ligand = 100
        ch.check_limit_number_atoms(self.ligands, limit_atoms_ligand)

        #Get core of the ligand
        mol = Chem.MolFromPDBFile(self.core)
        try:
            ligand_core = rd.SplitMolByPDBResidues(mol)[self.residue]
        except KeyError:
            raise ce.MissResidueFlag(
                "Missing residue flag to specify the ligand core residue name. i.e resname: 'LIG'"
            )

        #Get sdf full grown ligands
        ligands_grown = Chem.SDMolSupplier(self.ligands, removeHs=False)

        #For each full grown ligand create neutral fragment
        self.fragments = []
        lines = []
        for ligand in ligands_grown:
            try:
                line, fragment = self._create_fragment_from_ligand(
                    ligand, ligand_core)
            except Exception as e:
                try:
                    # Try to fix simmetry
                    line, fragment = self._create_fragment_from_ligand(
                        ligand, ligand_core, simmetry=True)
                except Exception as e:
                    try:
                        # Try with second substructure search
                        line, fragment = self._create_fragment_from_ligand(
                            ligand, ligand_core, result=1, substructure=False)
                    except Exception as e:
                        #Skip the ligand
                        print("Ligand Skipped")
                        print(e)
                        continue
            lines.append(line)
            self.fragments.append(fragment)
            print(f"Ligand {fragment.file} preprocessed")
        with open(self.input, "w") as fout:
            fout.write(("\n").join(lines))
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