def dock_molecules_to_receptor(receptor_filename):
    """
    Dock the specified molecules, writing out to specified file

    Parameters
    ----------
    receptor_filename : str
        Receptor .oeb.gz filename
    fragment : str
        The fragment name to dock to

    """
    import os

    # Read the receptor
    from openeye import oechem, oedocking
    receptor = oechem.OEGraphMol()
    if not oedocking.OEReadReceptorFile(receptor, receptor_filename):
        oechem.OEThrow.Fatal("Unable to read receptor")

    if not oedocking.OEReceptorHasBoundLigand(receptor):
        raise Exception("Receptor does not have bound ligand")

    #print('Initializing receptor...')
    dockMethod = oedocking.OEDockMethod_Hybrid2
    dockResolution = oedocking.OESearchResolution_Default
    dock = oedocking.OEDock(dockMethod, dockResolution)
    success = dock.Initialize(receptor)

    # Set up Omega
    #print('Expanding conformers...')
    from openeye import oeomega
    #omegaOpts = oeomega.OEOmegaOptions(oeomega.OEOmegaSampling_Dense)
    omegaOpts = oeomega.OEOmegaOptions()
    omega = oeomega.OEOmega(omegaOpts)
    omega.SetStrictStereo(False)

    # Dock molecules
    docked_molecules = list()
    for mol in molecules:
        dockedMol = oechem.OEGraphMol()

        # Expand conformers
        omega.Build(mol)

        # Dock molecule
        #print(f'Docking {mol.NumConfs()} conformers...')
        retCode = dock.DockMultiConformerMolecule(dockedMol, mol)
        if (retCode != oedocking.OEDockingReturnCode_Success):
            print("Docking Failed with error code " + oedocking.OEDockingReturnCodeGetName(retCode))
            continue

        # Store docking data
        sdtag = oedocking.OEDockMethodGetName(dockMethod)
        oedocking.OESetSDScore(dockedMol, dock, sdtag)
        dock.AnnotatePose(dockedMol)

        docked_molecules.append( oechem.OEMol(dockedMol) )

    return docked_molecules
예제 #2
0
def dock_molecules(receptor_filename, molecules, filename):
    """
    Dock the specified molecules, writing out to specified file

    Parameters
    ----------
    receptor_filename : str
        Receptor .oeb.gz filename
    molecules : list of openeye.oechem.OEMol
        The read molecules to dock
    filename : str
        The filename to stream docked molecules to

    """
    # Read the receptor
    print('Loading receptor...')
    from openeye import oechem, oedocking
    receptor = oechem.OEGraphMol()
    if not oedocking.OEReadReceptorFile(receptor, 'receptor.oeb.gz'):
        oechem.OEThrow.Fatal("Unable to read receptor")

    if oedocking.OEReceptorHasBoundLigand(receptor):
        print("Receptor has a bound ligand")
    else:
        print("Receptor does not have bound ligand")

    print('Initializing receptor...')
    dockMethod = oedocking.OEDockMethod_Hybrid2
    dockResolution = oedocking.OESearchResolution_High
    dock = oedocking.OEDock(dockMethod, dockResolution)
    success = dock.Initialize(receptor)

    # Set up Omega
    from openeye import oeomega
    omegaOpts = oeomega.OEOmegaOptions(oeomega.OEOmegaSampling_Dense)
    #omegaOpts = oeomega.OEOmegaOptions()
    omega = oeomega.OEOmega(omegaOpts)
    omega.SetStrictStereo(False)

    # Dock molecules
    with oechem.oemolostream(filename) as ofs:
        from tqdm import tqdm
        for mol in tqdm(molecules):
            dockedMol = oechem.OEGraphMol()

            # Expand conformers
            omega.Build(mol)

            # Dock molecule
            retCode = dock.DockMultiConformerMolecule(dockedMol, mol)
            if (retCode != oedocking.OEDockingReturnCode_Success):
                oechem.OEThrow.Fatal("Docking Failed with error code " + oedocking.OEDockingReturnCodeGetName(retCode))

            # Store docking data
            sdtag = oedocking.OEDockMethodGetName(dockMethod)
            oedocking.OESetSDScore(dockedMol, dock, sdtag)
            dock.AnnotatePose(dockedMol)

            # Write molecule
            oechem.OEWriteMolecule(ofs, dockedMol)
예제 #3
0
def main(argv=[__name__]):
    itf = oechem.OEInterface(InterfaceData)
    if not oechem.OEParseCommandLine(itf, argv):
        return 1

    imstr = oechem.oemolistream(itf.GetString("-in"))
    omstr = oechem.oemolostream(itf.GetString("-out"))

    receptors = []
    for receptor_filename in itf.GetStringList("-receptors"):
        receptor = oechem.OEGraphMol()
        if not oedocking.OEReadReceptorFile(receptor, receptor_filename):
            oechem.OEThrow.Fatal("Unable to read receptor from %s" %
                                 receptor_filename)
        receptors.append(receptor)

    poser = oedocking.OEPosit()
    for receptor in receptors:
        poser.AddReceptor(receptor)

    for mcmol in imstr.GetOEMols():
        print("posing", mcmol.GetTitle())
        result = oedocking.OESinglePoseResult()
        ret_code = poser.Dock(result, mcmol)
        if ret_code == oedocking.OEDockingReturnCode_Success:
            posedMol = result.GetPose()
            oechem.OESetSDData(posedMol, poser.GetName(),
                               str(result.GetProbability()))
            oechem.OESetSDData(posedMol, "Receptor Index",
                               str(result.GetReceptorIndex()))
            oechem.OEWriteMolecule(omstr, posedMol)
        else:
            errMsg = oedocking.OEDockingReturnCodeGetName(ret_code)
            oechem.OEThrow.Warning("%s: %s" % (mcmol.GetTitle(), errMsg))
    return 0
예제 #4
0
def DockConf_(dock, mol, lig, MAX_POSES=1, receptor_filename="Not Available"):
    err = dock.DockMultiConformerMolecule(lig, mol, MAX_POSES)
    if (err != oedocking.OEDockingReturnCode_Success):
        print("Docking Failed with error code " +
              oedocking.OEDockingReturnCodeGetName(err))
    sdtag = dock.GetName()
    oedocking.OESetSDScore(lig, dock, sdtag)
    dock.AnnotatePose(lig)
    oechem.OESetSDData(lig, "receptor", receptor_filename)
    return lig
예제 #5
0
파일: oe.py 프로젝트: RLMM/DockingEngine
def safe_dock_score_(dock, mol, oe_options=None):
    oe_options = oe_options or OEOptions()

    try:
        dockedMol = oechem.OEMol()
        retCode = dock.DockMultiConformerMolecule(dockedMol, mol, oe_options.num_poses)
        if (retCode != oedocking.OEDockingReturnCode_Success):
            rets = oedocking.OEDockingReturnCodeGetName(retCode)
            print('oeodock error', rets)
            return None
        score = dock.ScoreLigand(dockedMol)
        if oe_options.nan_to_none and (score > 10000 or np.isnan(score) or np.isinf(score)):
            return None
        else:
            return score
    except:
        return None
예제 #6
0
def main(argv=[__name__]):
    itf = oechem.OEInterface(InterfaceData)
    # @ <SNIPPET-DOCK-MOLECULES-CONFIGURE>
    oedocking.OEDockMethodConfigure(itf, "-method")
    oedocking.OESearchResolutionConfigure(itf, "-resolution")
    # @ </SNIPPET-DOCK-MOLECULES-CONFIGURE>
    if not oechem.OEParseCommandLine(itf, argv):
        return 1

    imstr = oechem.oemolistream(itf.GetString("-in"))
    omstr = oechem.oemolostream(itf.GetString("-out"))

    receptor = oechem.OEGraphMol()
    if not oedocking.OEReadReceptorFile(receptor, itf.GetString("-receptor")):
        oechem.OEThrow.Fatal("Unable to read receptor")

    # @ <SNIPPET-DOCK-MOLECULES-GET-VALUE>
    dockMethod = oedocking.OEDockMethodGetValue(itf, "-method")
    dockResolution = oedocking.OESearchResolutionGetValue(itf, "-resolution")
    # @ </SNIPPET-DOCK-MOLECULES-GET-VALUE>
    # @ <SNIPPET-DOCK-MOLECULES-SETUP>
    dock = oedocking.OEDock(dockMethod, dockResolution)
    # @ </SNIPPET-DOCK-MOLECULES-SETUP>
    # @ <SNIPPET-DOCK-MOLECULES-INITIALIZE>
    dock.Initialize(receptor)
    # @ </SNIPPET-DOCK-MOLECULES-INITIALIZE>

    for mcmol in imstr.GetOEMols():
        print("docking", mcmol.GetTitle())
        dockedMol = oechem.OEGraphMol()
        # @ <SNIPPET-DOCK-MOLECULES-DOCK>
        retCode = dock.DockMultiConformerMolecule(dockedMol, mcmol)
        if (retCode != oedocking.OEDockingReturnCode_Success):
            oechem.OEThrow.Fatal("Docking Failed with error code " + oedocking.OEDockingReturnCodeGetName(retCode))

        # @ </SNIPPET-DOCK-MOLECULES-DOCK>
        sdtag = oedocking.OEDockMethodGetName(dockMethod)
        # @ <SNIPPET-DOCK-MOLECULES-ASSIGN-SCORE>
        oedocking.OESetSDScore(dockedMol, dock, sdtag)
        # @ </SNIPPET-DOCK-MOLECULES-ASSIGN-SCORE>
        # @ <SNIPPET-DOCK-MOLECULES-ANNOTATE>
        dock.AnnotatePose(dockedMol)
        # @ </SNIPPET-DOCK-MOLECULES-ANNOTATE>
        oechem.OEWriteMolecule(omstr, dockedMol)

    return 0
예제 #7
0
def main(argv=[__name__]):
    itf = oechem.OEInterface(InterfaceData)
    if not oechem.OEParseCommandLine(itf, argv):
        return 1

    imstr = oechem.oemolistream(itf.GetString("-in"))
    omstr = oechem.oemolostream(itf.GetString("-out"))

    receptor = oechem.OEGraphMol()
    if not oedocking.OEReadReceptorFile(receptor, itf.GetString("-receptor")):
        oechem.OEThrow.Fatal("Unable to read receptor")

    # @ <SNIPPET-POSE-MOLECULES-SETUP>
    poser = oedocking.OEPosit()
    # @ </SNIPPET-POSE-MOLECULES-SETUP>
    # @ <SNIPPET-POSE-MOLECULES-INITIALIZE>
    poser.Initialize(receptor)
    # @ </SNIPPET-POSE-MOLECULES-INITIALIZE>

    for mcmol in imstr.GetOEMols():
        print("posing", mcmol.GetTitle())
        # @ <SNIPPET-POSE-MOLECULES-DOCK>
        result = oedocking.OESinglePoseResult()
        ret_code = poser.Dock(result, mcmol)
        # @ </SNIPPET-POSE-MOLECULES-DOCK>

        # @ <SNIPPET-POSE-MOLECULES-ASSIGN-SCORE>
        if ret_code == oedocking.OEDockingReturnCode_Success:
            posedMol = result.GetPose()
            oedocking.OESetSDScore(posedMol, poser)
            # @ </SNIPPET-POSE-MOLECULES-ASSIGN-SCORE>
            oechem.OEWriteMolecule(omstr, posedMol)
        else:
            errMsg = oedocking.OEDockingReturnCodeGetName(ret_code)
            oechem.OEThrow.Warning("%s: %s" % (mcmol.GetTitle(), errMsg))
    return 0