Beispiel #1
0
def SplitMolComplexAllSites(oms, inmol, splitCovalent):
    lig = oechem.OEGraphMol()
    prot = oechem.OEGraphMol()
    wat = oechem.OEGraphMol()
    other = oechem.OEGraphMol()

    if splitCovalent:
        # @ <SNIPPET-SPLIT-MOL-COMPLEX-ALL-SITES-SPLIT>
        opt = oechem.OESplitMolComplexOptions()
        allSites = 0
        opt.ResetFilters(allSites)
        opt.SetSplitCovalent()
        # @ </SNIPPET-SPLIT-MOL-COMPLEX-ALL-SITES-SPLIT>

        if oechem.OESplitMolComplex(lig, prot, wat, other, inmol, opt):
            WriteResultMols(oms, lig, prot, wat, other)
    else:
        # @ <SNIPPET-SPLIT-MOL-COMPLEX-ALL-SITES>
        opt = oechem.OESplitMolComplexOptions()
        allSites = 0
        opt.ResetFilters(allSites)
        # @ </SNIPPET-SPLIT-MOL-COMPLEX-ALL-SITES>

        if oechem.OESplitMolComplex(lig, prot, wat, other, inmol, opt):
            WriteResultMols(oms, lig, prot, wat, other)
Beispiel #2
0
def SplitMolComplex(oms, inmol, splitCovalent, separateResidues):
    # limiting lig, prot and wat to just near the first binding site
    # (a very common pattern)

    lig = oechem.OEGraphMol()
    prot = oechem.OEGraphMol()
    wat = oechem.OEGraphMol()
    other = oechem.OEGraphMol()

    if not splitCovalent and not separateResidues:
        # @ <SNIPPET-SPLIT-MOL-COMPLEX-SIMPLE>
        # for input molecule inmol ...
        lig = oechem.OEGraphMol()
        prot = oechem.OEGraphMol()
        wat = oechem.OEGraphMol()
        other = oechem.OEGraphMol()

        if oechem.OESplitMolComplex(lig, prot, wat, other, inmol):
            # work with the output molecules lig, prot, ...
            # @ </SNIPPET-SPLIT-MOL-COMPLEX-SIMPLE>
            WriteResultMols(oms, lig, prot, wat, other)

    elif splitCovalent and not separateResidues:
        # @ <SNIPPET-SPLIT-MOL-COMPLEX-SPLIT-COVALENT>
        # given input and output molecules ...
        opt = oechem.OESplitMolComplexOptions()
        opt.SetSplitCovalent()

        if oechem.OESplitMolComplex(lig, prot, wat, other, inmol, opt):
            # ...
            # @ </SNIPPET-SPLIT-MOL-COMPLEX-SPLIT-COVALENT>
            WriteResultMols(oms, lig, prot, wat, other)
    elif not splitCovalent and separateResidues:
        # @ <SNIPPET-SPLIT-MOL-COMPLEX-SEPARATE-RES>
        opt = oechem.OESplitMolComplexOptions()
        opt.SetSeparateResidues()

        if not oechem.OESplitMolComplex(lig, prot, wat, other, inmol, opt):
            oechem.OEThrow.Fatal("Unable to split mol complex from %s" %
                                 inmol.GetTitle())
            # @ </SNIPPET-SPLIT-MOL-COMPLEX-SEPARATE-RES>
        else:
            WriteResultMols(oms, lig, prot, wat, other)
    else:
        # @ <SNIPPET-SPLIT-MOL-COMPLEX-OPTIONS>
        opt = oechem.OESplitMolComplexOptions()
        opt.SetSplitCovalent(splitCovalent)
        opt.SetSeparateResidues(separateResidues)

        if not oechem.OESplitMolComplex(lig, prot, wat, other, inmol, opt):
            oechem.OEThrow.Fatal("Unable to split mol complex from %s" %
                                 inmol.GetTitle())
            # @ </SNIPPET-SPLIT-MOL-COMPLEX-OPTIONS>
        else:
            WriteResultMols(oms, lig, prot, wat, other)
Beispiel #3
0
    def split_complex_from_system(self):
        with self.logger("split_complex_from_system") as logger:
            if self.input_pdb is not None:
                pdb = oechem.OEMol()
                prot = oechem.OEMol()
                lig = oechem.OEMol()
                wat = oechem.OEGraphMol()
                other = oechem.OEGraphMol()
                ifs = oechem.oemolistream()
                ifs.SetFlavor(oechem.OEFormat_PDB, oechem.OEIFlavor_PDB_Default
                              | oechem.OEIFlavor_PDB_DATA
                              | oechem.OEIFlavor_PDB_ALTLOC)  # noqa
                if ifs.open(self.input_pdb):
                    oechem.OEReadMolecule(ifs, pdb)
                else:
                    logger.error("Could not open file!")
                ifs.close()
                logger.log(f"Reading input PDB {self.input_pdb}")
                if not oechem.OESplitMolComplex(lig, prot, wat, other, pdb):
                    logger.failure("could not split complex. exiting",
                                   exit_all=True)
                else:
                    logger.log(
                        f"Split complex. atom sizes-- lig: {len(list(lig.GetAtoms()))}, prot: {len(list(prot.GetAtoms()))}, water: {len(list(wat.GetAtoms()))}, other: {len(list(other.GetAtoms()))}"
                    )
            else:
                pdb = oechem.OEMol()
                prot = oechem.OEMol()
                lig = oechem.OEMol()
                wat = oechem.OEGraphMol()
                other = oechem.OEGraphMol()
                ifs = oechem.oemolistream()
                ifs.SetFlavor(oechem.OEFormat_PDB, oechem.OEIFlavor_PDB_Default
                              | oechem.OEIFlavor_PDB_DATA
                              | oechem.OEIFlavor_PDB_ALTLOC)  # noqa
                if ifs.open(self.input_pdb):
                    oechem.OEReadMolecule(ifs, pdb)
                else:
                    logger.error("Could not open file!")
                ifs.close()
                logger.log(f"Reading input PDB {self.input_pdb}")
                if not oechem.OESplitMolComplex(lig, prot, wat, other, pdb):
                    logger.failure("could not split complex. exiting",
                                   exit_all=True)
                else:
                    logger.log(
                        f"Split complex. atom sizes-- lig: {len(list(lig.GetAtoms()))}, prot: {len(list(prot.GetAtoms()))}, water: {len(list(wat.GetAtoms()))}, other: {len(list(other.GetAtoms()))}"
                    )

                ifs = oechem.oemolistream(self.lig)
                lig = oechem.OEMol()
                oechem.OEReadMolecule(ifs, lig)
                ifs.close()

            return prot, lig
Beispiel #4
0
    def choose_action(self, pdb_string):
        with self.logger("choose_action") as logger:
            with tempfile.TemporaryDirectory() as dirname:
                with open("{}/test.pdb".format(dirname), 'w') as f:
                    f.write(pdb_string)
                pdb = oechem.OEMol()
                prot = oechem.OEMol()
                lig = oechem.OEMol()
                wat = oechem.OEGraphMol()
                other = oechem.OEGraphMol()
                ifs = oechem.oemolistream()
                ifs.SetFlavor(oechem.OEFormat_PDB, oechem.OEIFlavor_PDB_Default
                              | oechem.OEIFlavor_PDB_DATA
                              | oechem.OEIFlavor_PDB_ALTLOC)  # noqa
                if not ifs.open("{}/test.pdb".format(dirname)):
                    logger.log("crap")
                oechem.OEReadMolecule(ifs, pdb)
                ifs.close()
                if not oechem.OESplitMolComplex(lig, prot, wat, other, pdb):
                    logger.failure("could not split complex. exiting",
                                   exit_all=True)
                else:
                    logger.log("atom sizes for incoming step",
                               len(list(lig.GetAtoms())),
                               len(list(prot.GetAtoms())),
                               len(list(wat.GetAtoms())),
                               len(list(other.GetAtoms())))
                original_smiles, oeclean_smiles = self.env.action.get_new_action_set(
                    aligner=lig)
                data = self.getscores(
                    original_smiles,
                    oeclean_smiles,
                    prot,
                    lig,
                    num_returns=self.num_returns,
                    return_docked_pose=self.return_docked_pose)
                not_worked = True
                idxs = list(range(len(data)))
                idx = idxs.pop(0)
                while not_worked:
                    try:
                        new_mol, new_mol2, gs, action = data[idx]

                        self.env.systemloader.reload_system(
                            gs, new_mol, "{}/test.pdb".format(dirname))
                        self.env.openmm_simulation = self.env.config.openmmWrapper.get_obj(
                            self.env.systemloader, self.env.openmm_simulation)
                        not_worked = False
                    except Exception as e:
                        logger.error("Could not buid system for smiles", gs,
                                     "with exception", e)
                        traceback.print_tb(e.__traceback__)

                        if len(idxs) == 0:
                            logger.failure("No system could build",
                                           exit_all=True)
                        idx = idxs.pop(0)
                self.env.action.apply_action(new_mol2, action)

        return new_mol2, action
Beispiel #5
0
    def split(self):

        lig = oechem.OEGraphMol()
        prot = oechem.OEGraphMol()
        wat = oechem.OEGraphMol()
        other = oechem.OEGraphMol()
        if oechem.OESplitMolComplex(lig, prot, wat, other, self.inmol):
            # work with the output molecules lig, prot, ...
            return [prot, lig]
        else:
            raise Exception('failure to detect prot & lig')
Beispiel #6
0
def split(mol):
    """
    This function splits the passed system in protein, ligand,
    water and excipients

    Parameters:
    ----------
    mol : oechem.OEMol
        The bio-molecular system to split

    Output:
    -------
    protein : oechem.OEMol
        The split protein
    ligand : oechem.OEMol
        The split ligand
    wat : oechem.OEMol
        The spit water
    other : oechem.OEMol
        The excipients
    
    """

    # Set empty molecule containers
    prot = oechem.OEMol()
    lig = oechem.OEMol()
    wat = oechem.OEMol()
    other = oechem.OEMol()

    # Define the Filter options before the splitting
    opt = oechem.OESplitMolComplexOptions()

    # The protein filter is set to avoid that multiple
    # chains are separated during the splitting
    pf = oechem.OEMolComplexFilterFactory(oechem.OEMolComplexFilterCategory_Protein)
    # The ligand filter is set to recognize just the ligand
    lf = oechem.OEMolComplexFilterFactory(oechem.OEMolComplexFilterCategory_Ligand)
    # The water filter is set to recognize just water molecules
    wf = oechem.OEMolComplexFilterFactory(oechem.OEMolComplexFilterCategory_Water)
    opt.SetProteinFilter(pf)
    opt.SetLigandFilter(lf)
    opt.SetWaterFilter(wf)
    
    # Splitting the system
    if not oechem.OESplitMolComplex(lig, prot, wat, other, mol, opt):
        oechem.OEThrow.Fatal('Unable to split the complex')
    
    # At this point prot contains the protein, lig contains the ligand,
    # wat contains the water and excipients contains the excipients

    return prot, lig, wat, other
Beispiel #7
0
def split_complex(protein, ligand, sopts, complexmol):

    water = oechem.OEGraphMol()
    other = oechem.OEGraphMol()

    pfilter = sopts.GetProteinFilter()
    wfilter = sopts.GetWaterFilter()
    sopts.SetProteinFilter(oechem.OEOrRoleSet(pfilter, wfilter))
    filter = oechem.OEMolComplexFilterCategory_Nothing
    sopts.SetWaterFilter(oechem.OEMolComplexFilterFactory(filter))

    oechem.OESplitMolComplex(ligand, protein, water, other, complexmol, sopts)

    return ligand.NumAtoms() != 0 and protein.NumAtoms() != 0
Beispiel #8
0
def SplitMolComplexCombineFilters(oms, inmol):
    lig = oechem.OEGraphMol()
    prot = oechem.OEGraphMol()
    wat = oechem.OEGraphMol()
    other = oechem.OEGraphMol()

    # @ <SNIPPET-SPLIT-MOL-COMPLEX-COMBINE-FILTERS>
    opt = oechem.OESplitMolComplexOptions()
    p = opt.GetProteinFilter()
    w = opt.GetWaterFilter()
    opt.SetProteinFilter(oechem.OEOrRoleSet(p, w))

    opt.SetWaterFilter(
        oechem.OEMolComplexFilterFactory(
            oechem.OEMolComplexFilterCategory_Nothing))
    # @ </SNIPPET-SPLIT-MOL-COMPLEX-COMBINE-FILTERS>

    if oechem.OESplitMolComplex(lig, prot, wat, other, inmol, opt):
        WriteResultMols(oms, lig, prot, wat, other)
def main(argv=[__name__]):

    itf = oechem.OEInterface()
    oechem.OEConfigure(itf, InterfaceData)
    oedepict.OEConfigureImageWidth(itf, 900.0)
    oedepict.OEConfigureImageHeight(itf, 600.0)
    oedepict.OEConfigure2DMolDisplayOptions(
        itf, oedepict.OE2DMolDisplaySetup_AromaticStyle)
    oechem.OEConfigureSplitMolComplexOptions(
        itf, oechem.OESplitMolComplexSetup_LigName)

    if not oechem.OEParseCommandLine(itf, argv):
        return 1

    iname = itf.GetString("-complex")
    oname = itf.GetString("-out")

    ifs = oechem.oemolistream()
    if not ifs.open(iname):
        oechem.OEThrow.Fatal("Cannot open input file!")

    ext = oechem.OEGetFileExtension(oname)
    if not oedepict.OEIsRegisteredImageFile(ext):
        oechem.OEThrow.Fatal("Unknown image type!")

    ofs = oechem.oeofstream()
    if not ofs.open(oname):
        oechem.OEThrow.Fatal("Cannot open output file!")

    complexmol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, complexmol):
        oechem.OEThrow.Fatal("Unable to read molecule from %s" % iname)

    if not oechem.OEHasResidues(complexmol):
        oechem.OEPerceiveResidues(complexmol, oechem.OEPreserveResInfo_All)

    # Separate ligand and protein

    sopts = oechem.OESplitMolComplexOptions()
    oechem.OESetupSplitMolComplexOptions(sopts, itf)

    ligand = oechem.OEGraphMol()
    protein = oechem.OEGraphMol()
    water = oechem.OEGraphMol()
    other = oechem.OEGraphMol()

    pfilter = sopts.GetProteinFilter()
    wfilter = sopts.GetWaterFilter()
    sopts.SetProteinFilter(oechem.OEOrRoleSet(pfilter, wfilter))
    sopts.SetWaterFilter(
        oechem.OEMolComplexFilterFactory(
            oechem.OEMolComplexFilterCategory_Nothing))

    oechem.OESplitMolComplex(ligand, protein, water, other, complexmol, sopts)

    if ligand.NumAtoms() == 0:
        oechem.OEThrow.Fatal("Cannot separate complex!")

    # Perceive interactions

    asite = oechem.OEInteractionHintContainer(protein, ligand)
    if not asite.IsValid():
        oechem.OEThrow.Fatal("Cannot initialize active site!")
    asite.SetTitle(ligand.GetTitle())

    oechem.OEPerceiveInteractionHints(asite)

    oegrapheme.OEPrepareActiveSiteDepiction(asite)

    # Depict active site with interactions

    width, height = oedepict.OEGetImageWidth(itf), oedepict.OEGetImageHeight(
        itf)
    image = oedepict.OEImage(width, height)

    cframe = oedepict.OEImageFrame(image, width * 0.80, height,
                                   oedepict.OE2DPoint(0.0, 0.0))
    lframe = oedepict.OEImageFrame(image, width * 0.20, height,
                                   oedepict.OE2DPoint(width * 0.80, 0.0))

    opts = oegrapheme.OE2DActiveSiteDisplayOptions(cframe.GetWidth(),
                                                   cframe.GetHeight())
    oedepict.OESetup2DMolDisplayOptions(opts, itf)

    adisp = oegrapheme.OE2DActiveSiteDisplay(asite, opts)
    oegrapheme.OERenderActiveSite(cframe, adisp)

    lopts = oegrapheme.OE2DActiveSiteLegendDisplayOptions(10, 1)
    oegrapheme.OEDrawActiveSiteLegend(lframe, adisp, lopts)

    oedepict.OEWriteImage(oname, image)

    return 0
Beispiel #10
0
def main(argv=[__name__]):

    itf = oechem.OEInterface()
    oechem.OEConfigure(itf, InterfaceData)
    oedepict.OEConfigureImageWidth(itf, 600.0)
    oedepict.OEConfigureImageHeight(itf, 600.0)
    oedepict.OEConfigure2DMolDisplayOptions(itf, oedepict.OE2DMolDisplaySetup_AromaticStyle)
    oechem.OEConfigureSplitMolComplexOptions(itf, oechem.OESplitMolComplexSetup_LigName)

    if not oechem.OEParseCommandLine(itf, argv):
        return 1

    iname = itf.GetString("-complex")
    oname = itf.GetString("-out")

    ifs = oechem.oemolistream()
    if not ifs.open(iname):
        oechem.OEThrow.Fatal("Cannot open input file!")

    ext = oechem.OEGetFileExtension(oname)
    if not oedepict.OEIsRegisteredImageFile(ext):
        oechem.OEThrow.Fatal("Unknown image type!")

    ofs = oechem.oeofstream()
    if not ofs.open(oname):
        oechem.OEThrow.Fatal("Cannot open output file!")

    complexmol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, complexmol):
        oechem.OEThrow.Fatal("Unable to read molecule from %s" % iname)

    if not oechem.OEHasResidues(complexmol):
        oechem.OEPerceiveResidues(complexmol, oechem.OEPreserveResInfo_All)

    # Separate ligand and protein

    sopts = oechem.OESplitMolComplexOptions()
    oechem.OESetupSplitMolComplexOptions(sopts, itf)

    ligand = oechem.OEGraphMol()
    protein = oechem.OEGraphMol()
    water = oechem.OEGraphMol()
    other = oechem.OEGraphMol()

    oechem.OESplitMolComplex(ligand, protein, water, other, complexmol, sopts)

    if ligand.NumAtoms() == 0:
        oechem.OEThrow.Fatal("Cannot separate complex!")

    # Calculate average BFactor of the whole complex

    avgbfactor = GetAverageBFactor(complexmol)

    # Calculate minimum and maximum BFactor of the ligand and its environment

    minbfactor, maxbfactor = GetMinAndMaxBFactor(ligand, protein)

    # Attach to each ligand atom the average BFactor of the nearby protein atoms

    stag = "avg residue BFfactor"
    itag = oechem.OEGetTag(stag)
    SetAverageBFactorOfNearbyProteinAtoms(ligand, protein, itag)

    oechem.OEThrow.Info("Average BFactor of the complex = %+.3f" % avgbfactor)
    oechem.OEThrow.Info("Minimum BFactor of the ligand and its environment = %+.3f" % minbfactor)
    oechem.OEThrow.Info("Maximum BFactor of the ligand and its environment = %+.3f" % maxbfactor)

    # Create image

    imagewidth, imageheight = oedepict.OEGetImageWidth(itf), oedepict.OEGetImageHeight(itf)
    image = oedepict.OEImage(imagewidth, imageheight)

    mframe = oedepict.OEImageFrame(image, imagewidth,
                                   imageheight * 0.90, oedepict.OE2DPoint(0.0, 0.0))
    lframe = oedepict.OEImageFrame(image, imagewidth, imageheight * 0.10,
                                   oedepict.OE2DPoint(0.0, imageheight * 0.90))

    opts = oedepict.OE2DMolDisplayOptions(mframe.GetWidth(), mframe.GetHeight(),
                                          oedepict.OEScale_AutoScale)
    oedepict.OESetup2DMolDisplayOptions(opts, itf)
    opts.SetAtomColorStyle(oedepict.OEAtomColorStyle_WhiteMonochrome)

    # Create BFactor color gradient

    colorg = oechem.OELinearColorGradient()
    colorg.AddStop(oechem.OEColorStop(0.0, oechem.OEDarkBlue))
    colorg.AddStop(oechem.OEColorStop(10.0, oechem.OELightBlue))
    colorg.AddStop(oechem.OEColorStop(25.0, oechem.OEYellowTint))
    colorg.AddStop(oechem.OEColorStop(50.0, oechem.OERed))
    colorg.AddStop(oechem.OEColorStop(100.0, oechem.OEDarkRose))

    # Prepare ligand for depiction

    oegrapheme.OEPrepareDepictionFrom3D(ligand)
    arcfxn = BFactorArcFxn(colorg, itag)
    for atom in ligand.GetAtoms():
        oegrapheme.OESetSurfaceArcFxn(ligand, atom, arcfxn)
    opts.SetScale(oegrapheme.OEGetMoleculeSurfaceScale(ligand, opts))

    # Render ligand and visualize BFactor

    disp = oedepict.OE2DMolDisplay(ligand, opts)
    colorbfactor = ColorLigandAtomByBFactor(colorg)
    oegrapheme.OEAddGlyph(disp, colorbfactor, oechem.OEIsTrueAtom())
    oegrapheme.OEDraw2DSurface(disp)
    oedepict.OERenderMolecule(mframe, disp)

    # Draw color gradient

    opts = oegrapheme.OEColorGradientDisplayOptions()
    opts.SetColorStopPrecision(1)
    opts.AddMarkedValue(avgbfactor)
    opts.SetBoxRange(minbfactor, maxbfactor)

    oegrapheme.OEDrawColorGradient(lframe, colorg, opts)

    oedepict.OEWriteImage(oname, image)

    return 0
Beispiel #11
0
    def __init__(self,
                 env,
                 sort='dscores',
                 return_docked_pose=False,
                 num_returns=-1,
                 orig_pdb=None,
                 useHybrid=False,
                 trackHScores=True,
                 optimize=False):
        self.logger = make_message_writer(env.verbose, self.__class__.__name__)
        with self.logger("__init__") as logger:
            self.sort = sort
            if self.sort not in ['iscores', 'dscores', 'hscores', 'pscores']:
                logger.failure(
                    f"{self.sort} is not a valid sorting method. Exiting",
                    exit_all=True)
            self.return_docked_pose = return_docked_pose
            self.num_returns = num_returns
            self.env = env

            self.orig_pdb = orig_pdb
            self.start_dobj = None
            self.start_receptor = None
            self.track_hscores = trackHScores
            if not self.track_hscores and self.sort == 'hscores':
                logger.error(
                    "Track hscores is set to false but the sorting method desired is hscores. Assuming this was error, continuing  by setting track_hscores to True"
                )
                self.track_hscores = True

            self.past_receptors = []
            self.past_dockobjs = []
            self.past_coordinates = []
            self.optimize = optimize

            self.dockmethod = oedocking.OEDockMethod_Hybrid if useHybrid else oedocking.OEDockMethod_Chemgauss4
            if (not (self.sort != 'iscores'
                     and self.optimize)) and self.orig_pdb is not None:
                pdb = oechem.OEMol()
                prot = oechem.OEMol()
                lig = oechem.OEMol()
                wat = oechem.OEGraphMol()
                other = oechem.OEGraphMol()
                ifs = oechem.oemolistream(self.orig_pdb)
                oechem.OEReadMolecule(ifs, pdb)
                ifs.close()
                if not oechem.OESplitMolComplex(lig, prot, wat, other, pdb):
                    logger.failure("Could not split complex", exit_all=True)

                self.start_receptor = oechem.OEGraphMol()
                logger.log("Building initial receptor file...")
                oedocking.OEMakeReceptor(self.start_receptor, prot, lig)

                self.start_dobj = oedocking.OEDock(self.dockmethod)
                self.start_dobj.Initialize(self.start_receptor)
                assert (self.start_dobj.IsInitialized())
                logger.log("done")
            elif self.sort != 'iscores' and self.optimize:
                logger.log(
                    "Skipping building inital receptor because optmize is set and sorting method is not iscore"
                )
            else:
                logger.log(
                    "Skipping building inital receptor because orig_pdb was not provided."
                )
Beispiel #12
0
def main(argv=[__name__]):

    itf = oechem.OEInterface()
    oechem.OEConfigure(itf, InterfaceData)
    oechem.OEConfigureSplitMolComplexOptions(
        itf, oechem.OESplitMolComplexSetup_LigName)

    if not oechem.OEParseCommandLine(itf, argv):
        return 1

    iname = itf.GetString("-complex")

    ifs = oechem.oemolistream()
    if not ifs.open(iname):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % iname)

    complexmol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, complexmol):
        oechem.OEThrow.Fatal("Unable to read molecule from %s" % iname)

    if not oechem.OEHasResidues(complexmol):
        oechem.OEPerceiveResidues(complexmol, oechem.OEPreserveResInfo_All)

    # Separate ligand and protein

    sopts = oechem.OESplitMolComplexOptions()
    oechem.OESetupSplitMolComplexOptions(sopts, itf)

    ligand = oechem.OEGraphMol()
    protein = oechem.OEGraphMol()
    water = oechem.OEGraphMol()
    other = oechem.OEGraphMol()

    pfilter = sopts.GetProteinFilter()
    wfilter = sopts.GetWaterFilter()
    sopts.SetProteinFilter(oechem.OEOrRoleSet(pfilter, wfilter))
    sopts.SetWaterFilter(
        oechem.OEMolComplexFilterFactory(
            oechem.OEMolComplexFilterCategory_Nothing))

    oechem.OESplitMolComplex(ligand, protein, water, other, complexmol, sopts)

    if ligand.NumAtoms() == 0:
        oechem.OEThrow.Fatal("Cannot separate complex!")

    # Perceive interactions

    asite = oechem.OEInteractionHintContainer(protein, ligand)
    if not oechem.OEIsValidActiveSite(asite):
        oechem.OEThrow.Fatal("Cannot initialize active site!")

    oechem.OEPerceiveInteractionHints(asite)

    print("Number of interactions:", asite.NumInteractions())
    for itype in oechem.OEGetActiveSiteInteractionHintTypes():
        numinters = asite.NumInteractions(
            oechem.OEHasInteractionHintType(itype))
        if numinters == 0:
            continue
        print("%d %s :" % (numinters, itype.GetName()))

        inters = [
            s for s in asite.GetInteractions(
                oechem.OEHasInteractionHintType(itype))
        ]
        print("\n".join(sorted(GetInteractionString(s) for s in inters)))

    print("\nResidue interactions:")
    for res in oechem.OEGetResidues(
            asite.GetMolecule(oechem.OEProteinInteractionHintComponent())):
        PrintResidueInteractions(asite, res)

    print("\nLigand atom interactions:")
    for atom in asite.GetMolecule(
            oechem.OELigandInteractionHintComponent()).GetAtoms():
        PrintLigandAtomInteractions(asite, atom)
Beispiel #13
0
def hybrid_docking(receptor_path,
                   molecules_path,
                   docked_molecules_path,
                   n_poses=10):
    """Automated hybrid docking of small molecules to a receptor.

    Parameters
    ----------
    receptor_path : str
        Path to PDB file containing receptor and reference ligand, or pre-prepared receptor for docking
    molecules_path : str
        Path to file containing one or more molecules (in OpenEye readable format) to be docked.
        (For example, list of SMILES)
    docked_molecules_path : str
        Path to output file to be created to contain docked molecules
        Uses OpenEye recognized file extension, such as .mol2 or .sdf
    n_poses : int, optional, default=1
        Number of docked poses to generate
    receptor_filename : str, optional, default=None
        If not None, the pre-prepared receptor is loaded

    TODO: How can this API be improved?

    """
    from .docking import create_receptor, load_receptor, pose_molecule
    from openeye import oedocking, oechem
    #import openmoltools as moltools # TODO: Bring these methods into this module

    # Try to load pre-prepared receptor from specified file
    receptor = oechem.OEGraphMol()
    print('Attempting to load receptor from {}...'.format(receptor_path))
    if not oedocking.OEReadReceptorFile(receptor, receptor_path):
        # Load complex of receptor and reference ligand
        complex_istream = oechem.oemolistream(receptor_path)
        complex = oechem.OEGraphMol()
        oechem.OEReadMolecule(complex_istream, complex)

        # Attempt to split into components and build receptor based on reference ligand
        print('Attempting to split complex into components...')
        ligand = oechem.OEGraphMol()
        protein = oechem.OEGraphMol()
        water = oechem.OEGraphMol()
        other = oechem.OEGraphMol()
        if oechem.OESplitMolComplex(ligand, protein, water, other, complex):
            # Create receptor using bound ligand reference
            print('Creating receptor using reference ligand...')
            oedocking.OEMakeReceptor(receptor, protein, ligand)
            # TODO: We can store prepared receptor file if desired
            oedocking.OEWriteReceptorFile(
                receptor,
                '/home/guoj1/projects/INSPIRE/kinomodel/kinomodel/data/docking/prepared_receptor.oeb'
            )

        else:
            raise Exception(
                'Could not split specified PDB file {} into receptor and reference ligand'
                .format(receptor_path))

    # Open file for writing docked molecules
    docked_molecules_ostream = oechem.oemolostream(docked_molecules_path)

    # Configure omega
    # From canonical recipe: https://docs.eyesopen.com/toolkits/cookbook/python/modeling/am1-bcc.html
    from openeye import oeomega
    omega = oeomega.OEOmega()
    omega.SetIncludeInput(False)
    omega.SetCanonOrder(False)
    omega.SetSampleHydrogens(True)
    eWindow = 15.0
    omega.SetEnergyWindow(eWindow)
    omega.SetMaxConfs(800)
    omega.SetRMSThreshold(1.0)

    # Dock all molecules requested
    dock_method = oedocking.OEDockMethod_Hybrid2
    dock_resolution = oedocking.OESearchResolution_Standard
    dock = oedocking.OEDock(dock_method, dock_resolution)
    dock.Initialize(receptor)
    molecules_istream = oechem.oemolistream(molecules_path)
    molecule = oechem.OEGraphMol()
    for molecule in molecules_istream.GetOEMols():
        print("docking", molecule.GetTitle())
        #docked_molecules = pose_molecule(receptor, molecule, n_poses=n_poses)
        #molecule = moltools.openeye.get_charges(molecule, keep_confs=10)

        # Generate conformers
        if not omega(molecule):
            continue

        # Apply charges
        from openeye import oequacpac
        oequacpac.OEAssignCharges(molecule, oequacpac.OEAM1BCCELF10Charges())

        # Dock
        docked_molecule = oechem.OEGraphMol()
        dock.DockMultiConformerMolecule(docked_molecule, molecule)
        sdtag = oedocking.OEDockMethodGetName(dock_method)
        oedocking.OESetSDScore(docked_molecule, dock, sdtag)
        dock.AnnotatePose(docked_molecule)
        oechem.OEWriteMolecule(docked_molecules_ostream, docked_molecule)
Beispiel #14
0
def split(complex, ligand_res_name='LIG'):
    """
    This function splits the passed system in protein, ligand,
    water and excipients

    Parameters:
    ----------
    complex : oechem.OEMol
        The bio-molecular complex to split
    ligand_res_name : Python string
        The ligand residue name used to recognize the ligand

    Output:
    -------
    protein : oechem.OEMol
        The split protein
    ligand : oechem.OEMol
        The split ligand
    wat : oechem.OEMol
        The spit water
    other : oechem.OEMol
        The excipients

    """

    # Set empty molecule containers
    prot = oechem.OEMol()
    lig = oechem.OEMol()
    wat = oechem.OEMol()
    other = oechem.OEMol()

    # Define the Filter options before the splitting
    opt = oechem.OESplitMolComplexOptions()

    # The protein filter is set to avoid that multiple
    # chains are separated during the splitting and peptide
    # molecules are recognized as ligands
    pf = oechem.OEMolComplexFilterFactory(
        oechem.OEMolComplexFilterCategory_Protein)
    peptide = oechem.OEMolComplexFilterFactory(
        oechem.OEMolComplexFilterCategory_Peptide)
    protein_filter = oechem.OEOrRoleSet(pf, peptide)
    opt.SetProteinFilter(protein_filter)

    # The ligand filter is set to recognize just the ligand
    lf = oechem.OEMolComplexFilterFactory(
        oechem.OEMolComplexFilterCategory_Ligand)
    not_protein_filter = oechem.OENotRoleSet(protein_filter)
    ligand_filter = oechem.OEAndRoleSet(lf, not_protein_filter)
    opt.SetLigandFilter(ligand_filter)

    # The water filter is set to recognize just water molecules
    wf = oechem.OEMolComplexFilterFactory(
        oechem.OEMolComplexFilterCategory_Water)
    opt.SetWaterFilter(wf)

    # Set Category
    cat = oechem.OEMolComplexCategorizer()
    cat.AddLigandName(ligand_res_name)
    opt.SetCategorizer(cat)

    # Splitting the system
    if not oechem.OESplitMolComplex(lig, prot, wat, other, complex, opt):
        raise ValueError('Unable to split the complex')

    # At this point prot contains the protein, lig contains the ligand,
    # wat contains the water and excipients contains the excipients

    return prot, lig, wat, other
Beispiel #15
0
def split(complex, ligand_res_name='LIG'):
    """
    This function splits the passed system in protein, ligand,
    water and excipients.

    Parameters:
    ----------
    complex : oechem.OEMol
        The bio-molecular complex to split
    ligand_res_name : Python string
        The ligand residue name used to recognize the ligand

    Output:
    -------
    protein : oechem.OEMol
        The split protein
    ligand : oechem.OEMol
        The split ligand
    wat : oechem.OEMol
        The spit water
    cofactors : oechem.OEMol
        The cofactors
    lipids : oechem.OEMol
        The lipids
    metals : oechem.OEMol
        The metals
    excipients : oechem.OEMol
        The excipients
    """

    # Set empty molecule containers
    protein = oechem.OEMol()
    ligand = oechem.OEMol()
    water = oechem.OEMol()
    other = oechem.OEMol()

    # Define the Filter options before the splitting
    opt = oechem.OESplitMolComplexOptions()

    # The protein filter is set to avoid that multiple
    # chains are separated during the splitting and peptide
    # molecules are recognized as ligands
    pf = oechem.OEMolComplexFilterFactory(
        oechem.OEMolComplexFilterCategory_Protein)
    peptide = oechem.OEMolComplexFilterFactory(
        oechem.OEMolComplexFilterCategory_Peptide)
    protein_filter = oechem.OEOrRoleSet(pf, peptide)
    opt.SetProteinFilter(protein_filter)

    # The ligand filter is set to recognize just the ligand
    lf = oechem.OEMolComplexFilterFactory(
        oechem.OEMolComplexFilterCategory_Ligand)
    not_protein_filter = oechem.OENotRoleSet(protein_filter)
    ligand_filter = oechem.OEAndRoleSet(lf, not_protein_filter)
    opt.SetLigandFilter(ligand_filter)

    # The water filter is set to recognize just water molecules
    wf = oechem.OEMolComplexFilterFactory(
        oechem.OEMolComplexFilterCategory_Water)
    opt.SetWaterFilter(wf)

    # Set Category
    cat = oechem.OEMolComplexCategorizer()
    cat.AddLigandName(ligand_res_name)
    opt.SetCategorizer(cat)

    # Splitting the system
    if not oechem.OESplitMolComplex(ligand, protein, water, other, complex,
                                    opt):
        raise ValueError('Unable to split the complex')

    cofactors = oechem.OEMol()
    lipids = oechem.OEMol()
    metals = oechem.OEMol()
    excipients = oechem.OEMol()

    # Splitting the subsystem
    if other.NumAtoms():

        opt_other = oechem.OESplitMolComplexOptions()

        lipid_filter = oechem.OEMolComplexFilterFactory(
            oechem.OEMolComplexFilterCategory_Lipid)
        opt_other.SetProteinFilter(lipid_filter)

        cofactor_filter = oechem.OEMolComplexFilterFactory(
            oechem.OEMolComplexFilterCategory_Cofactor)
        opt_other.SetLigandFilter(cofactor_filter)

        metal_filter = oechem.OEMolComplexFilterFactory(
            oechem.OEMolComplexFilterCategory_Metal)
        opt_other.SetWaterFilter(metal_filter)

        # Set Category
        cat_other = oechem.OEMolComplexCategorizer()
        opt_other.SetCategorizer(cat_other)

        if not oechem.OESplitMolComplex(cofactors, lipids, metals, excipients,
                                        other, opt_other):
            raise ValueError('Unable to split the Subcategories')

    return protein, ligand, water, cofactors, lipids, metals, excipients
Beispiel #16
0
def main(argv=[__name__]):

    itf = oechem.OEInterface(InterfaceData)
    oechem.OEConfigureSplitMolComplexOptions(itf)

    if not oechem.OEParseCommandLine(itf, argv):
        oechem.OEThrow.Fatal("Unable to interpret command line!")

    if itf.GetBool("-verbose"):
        oechem.OEThrow.SetLevel(oechem.OEErrorLevel_Verbose)

    iname = itf.GetString("-in")
    oname = itf.GetString("-out")

    ims = oechem.oemolistream()
    if not itf.GetUnsignedInt("-modelnum") == 1:
        ims.SetFlavor(oechem.OEFormat_PDB,
                      oechem.OEGetDefaultIFlavor(oechem.OEFormat_PDB) & ~oechem.OEIFlavor_PDB_ENDM)
    if not ims.open(iname):
        oechem.OEThrow.Fatal("Cannot open input file!")

    oms = oechem.oemolostream()
    if not oms.open(oname):
        oechem.OEThrow.Fatal("Cannot open output file!")

    inmol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ims, inmol):
        oechem.OEThrow.Fatal("Cannot read input file!")

    opts = oechem.OESplitMolComplexOptions()
    oechem.OESetupSplitMolComplexOptions(opts, itf)

    if itf.GetBool("-verbose"):
        # don't bother counting sites unless we're going to print them
        numSites = oechem.OECountMolComplexSites(inmol, opts)
        oechem.OEThrow.SetLevel(oechem.OEErrorLevel_Verbose)
        oechem.OEThrow.Verbose("sites %d" % numSites)

    lig = oechem.OEGraphMol()
    prot = oechem.OEGraphMol()
    wat = oechem.OEGraphMol()
    other = oechem.OEGraphMol()

    if not oechem.OESplitMolComplex(lig, prot, wat, other, inmol, opts):
        oechem.OEThrow.Fatal("Unable to split mol complex from %s" % iname)

    if not lig.NumAtoms() == 0:
        oechem.OEThrow.Verbose("  lig %s" % lig.GetTitle())
        oechem.OEWriteMolecule(oms, lig)

    if not prot.NumAtoms() == 0:
        oechem.OEThrow.Verbose(" prot %s" % prot.GetTitle())
        oechem.OEWriteMolecule(oms, prot)

    if not wat.NumAtoms() == 0:
        oechem.OEThrow.Verbose("  wat %s" % wat.GetTitle())
        oechem.OEWriteMolecule(oms, wat)

    if not other.NumAtoms() == 0:
        oechem.OEThrow.Verbose("other %s" % other.GetTitle())
        oechem.OEWriteMolecule(oms, other)

    oms.close()
Beispiel #17
0
def main(argv=[__name__]):

    itf = oechem.OEInterface(InterfaceData)
    oechem.OEConfigureSplitMolComplexOptions(itf)

    if not oechem.OEParseCommandLine(itf, argv):
        oechem.OEThrow.Fatal("Unable to interpret command line!")

    opts = oechem.OESplitMolComplexOptions()
    oechem.OESetupSplitMolComplexOptions(opts, itf)
    # @ </SNIPPET-SPLIT-MOL-COMPLEX-ITF>

    iname = itf.GetString("-in")
    oname = itf.GetString("-out")

    ims = oechem.oemolistream()
    if not itf.GetUnsignedInt("-modelnum") == 1:
        ims.SetFlavor(
            oechem.OEFormat_PDB,
            oechem.OEGetDefaultIFlavor(oechem.OEFormat_PDB)
            & ~oechem.OEIFlavor_PDB_ENDM)
    if not ims.open(iname):
        oechem.OEThrow.Fatal("Cannot open input file!")

    oms = oechem.oemolostream()
    if not oms.open(oname):
        oechem.OEThrow.Fatal("Cannot open output file!")
    bfixTitles = (oms.GetFormat() == oechem.OEFormat_SDF)
    sTitleSDTag = "TITLE"

    inmol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ims, inmol):
        oechem.OEThrow.Fatal("Cannot read input file!")

    lig = oechem.OEGraphMol()
    prot = oechem.OEGraphMol()
    wat = oechem.OEGraphMol()
    other = oechem.OEGraphMol()

    if not oechem.OESplitMolComplex(lig, prot, wat, other, inmol, opts):
        oechem.OEThrow.Fatal("Unable to split mol complex from %s" % iname)

    if not lig.NumAtoms() == 0:
        if bfixTitles:
            FixSDFTitle(sTitleSDTag, lig)
        oechem.OEWriteMolecule(oms, lig)

    if not prot.NumAtoms() == 0:
        if bfixTitles:
            FixSDFTitle(sTitleSDTag, prot)
        oechem.OEWriteMolecule(oms, prot)

    if not wat.NumAtoms() == 0:
        if bfixTitles:
            FixSDFTitle(sTitleSDTag, wat)
        oechem.OEWriteMolecule(oms, wat)

    if not other.NumAtoms() == 0:
        if bfixTitles:
            FixSDFTitle(sTitleSDTag, other)
        oechem.OEWriteMolecule(oms, other)

    oms.close()