Ejemplo n.º 1
0
def main(args):
    if len(args) != 3:
        oechem.OEThrow.Usage("%s input_molecule output_molecule" % args[0])

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

    ofs = oechem.oemolostream()
    if not ofs.open(args[2]):
        oechem.OEThrow.Fatal("Unable to open %s for writing" % args[2])

    mol = oechem.OEMol()
    oechem.OEReadMolecule(ifs, mol)

    opts = oeszybki.OESzybkiOptions()
    opts.GetOptOptions().SetOptimizerType(oeszybki.OEOptType_NEWTON)
    opts.GetSolventOptions().SetSolventModel(oeszybki.OESolventModel_Sheffield)

    sz = oeszybki.OESzybki(opts)
    res = oeszybki.OESzybkiResults()
    if (sz(mol, res)):
        oechem.OEWriteMolecule(ofs, mol)
        res.Print(oechem.oeout)

    return 0
Ejemplo n.º 2
0
def optimize_poses(
    docking_poses: List[oechem.OEGraphMol],
    protein: Union[oechem.OEMolBase, oechem.OEGraphMol],
) -> List[oechem.OEGraphMol]:
    """
    Optimize the torsions of docking poses in a protein binding site.
    Parameters
    ----------
    docking_poses: list of oechem.OEGraphMol
        The docking poses to optimize.
    protein: oechem.OEGraphMol or oechem.MolBase
        The OpenEye molecule holding a protein structure.
    Returns
    -------
    optimized_docking_poses: list of oechem.OEGraphMol
        The optimized docking poses.
    """
    from openeye import oeszybki

    options = oeszybki.OESzybkiOptions()
    options.SetRunType(oeszybki.OERunType_TorsionsOpt)
    options.GetProteinOptions().SetExactVdWProteinLigand(True)
    options.GetProteinOptions().SetProteinElectrostaticModel(
        oeszybki.OEProteinElectrostatics_ExactCoulomb)
    options.GetOptOptions().SetGradTolerance(0.00001)
    szybki = oeszybki.OESzybki(options)
    szybki.SetProtein(protein)

    optimized_docking_poses = []
    for docking_pose in docking_poses:
        result = oeszybki.OESzybkiResults()
        szybki(docking_pose, result)
        optimized_docking_poses.append(oechem.OEGraphMol(docking_pose))

    return optimized_docking_poses
Ejemplo n.º 3
0
def QuickOpt(Mol):
    """
    Fast MM optimization to whittle down number of conformers before QM.
    Default Szybki OEOptType type set to steepest descent (SD) based on
       preliminary comparisons.

    Parameters
    ----------
    Mol:        single OEChem molecule (aka single conformer)

    Returns
    -------
    boolean: True if completed successfully, False otherwise.

    """
    # set general energy options along with the run type specification
    optSzybki = oeszybki.OESzybkiOptions()
    optSzybki.SetForceFieldType(oeszybki.OEForceFieldType_MMFF94S)
    optSzybki.SetSolventModel(oeszybki.OESolventModel_Sheffield)
    optSzybki.SetOptimizerType(oeszybki.OEOptType_SD)
    taglabel = 'MM Szybki SD Energy'

    # generate szybki MMFF94 engine for minimization
    szOpt = oeszybki.OESzybki(optSzybki)
    # construct a results object to contain the results of a szybki calculation
    szResults = oeszybki.OESzybkiResults()
    # work on a copy of the molecule
    tmpmol = oechem.OEMol(Mol)
    if not szOpt(tmpmol, szResults):
        print('szybki run failed for %s' % tmpmol.GetTitle())
        return False
    Mol.SetCoords(tmpmol.GetCoords())
    oechem.OESetSDData(Mol, oechem.OESDDataPair(taglabel, "%.12f" \
        % szResults.GetTotalEnergy()))
    return True
Ejemplo n.º 4
0
def main(args=[__name__]):
    if len(args) != 3:
        oechem.OEThrow.Usage("%s <molfile> <outfile>" % args[0])

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

    ofs = oechem.oemolostream()
    if not ofs.open(args[2]):
        oechem.OEThrow.Fatal("Unable to open %s for writing" % args[2])

    mol = oechem.OEMol()
    oechem.OEReadMolecule(ifs, mol)

    opts = oeszybki.OESzybkiOptions()
    opts.GetGeneralOptions().SetForceFieldType(oeszybki.OEForceFieldType_SMIRNOFF)
    sz = oeszybki.OESzybki(opts)
    results = oeszybki.OESzybkiResults()
    if not sz(mol, results):
        return 1

    oechem.OEWriteMolecule(ofs, mol)
    results.Print(oechem.oeout)

    return 0
Ejemplo n.º 5
0
def main(args):
    if len(args) != 3:
        oechem.OEThrow.Usage("%s input_molecule output_molecule" % args[0])

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

    ofs = oechem.oemolostream()
    if not ofs.open(args[2]):
        oechem.OEThrow.Fatal("Unable to open %s for writing" % args[2])

    opts = oeszybki.OESzybkiOptions()
    opts.GetOptOptions().SetOptimizerType(oeszybki.OEOptType_NEWTON)
    opts.GetGeneralOptions().SetForceFieldType(
        oeszybki.OEForceFieldType_MMFF94S)
    opts.GetSolventOptions().SetSolventModel(oeszybki.OESolventModel_Sheffield)
    opts.GetSolventOptions().SetChargeEngine(oequacpac.OEChargeEngineNoOp())
    sz = oeszybki.OESzybki(opts)
    res = oeszybki.OESzybkiResults()
    for mol in ifs.GetOEMols():
        for conf in mol.GetConfs():
            if sz(conf, res):
                oechem.OESetSDData(
                    conf,
                    oechem.OESDDataPair('Total_energy',
                                        "%0.4f" % res.GetTotalEnergy()))

        oechem.OEWriteMolecule(ofs, mol)

    ifs.close()
    ofs.close()

    return 0
Ejemplo n.º 6
0
def main(argv=[__name__]):
    if len(argv) != 4:
        oechem.OEThrow.Usage("%s <molfile> <protein> <outfile>" % argv[0])

    lfs = oechem.oemolistream()
    if not lfs.open(argv[1]):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1])

    pfs = oechem.oemolistream()
    if not pfs.open(argv[2]):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[2])

    ofs = oechem.oemolostream()
    if not ofs.open(argv[3]):
        oechem.OEThrow.Fatal("Unable to open %s for writing" % argv[3])

    mol = oechem.OEGraphMol()
    oechem.OEReadMolecule(lfs, mol)

    protein = oechem.OEGraphMol()
    oechem.OEReadMolecule(pfs, protein)

    opts = oeszybki.OESzybkiOptions()
    sz = oeszybki.OESzybki(opts)
    sz.SetProtein(protein)
    res = oeszybki.OESzybkiResults()
    if not sz(mol, res):
        return 1

    oechem.OEWriteMolecule(ofs, mol)
    res.Print(oechem.oeout)

    return 0
Ejemplo n.º 7
0
def resolve_clashes(mol, clashfile):
    """
    Minimize conformers with severe steric interaction.

    Parameters
    ----------
    mol : single OEChem molecule (single conformer)
    clashfile : string
        name of file to write output

    Returns
    -------
    boolean
        True if completed successfully, False otherwise.

    """

    # set general energy options along with the single-point specification
    spSzybki = oeszybki.OESzybkiOptions()
    spSzybki.SetForceFieldType(oeszybki.OEForceFieldType_MMFF94S)
    spSzybki.SetSolventModel(oeszybki.OESolventModel_Sheffield)
    spSzybki.SetRunType(oeszybki.OERunType_SinglePoint)
    # generate the szybki MMFF94 engine for single points
    szSP = oeszybki.OESzybki(spSzybki)
    # construct minimiz options from single-points options to get general optns
    optSzybki = oeszybki.OESzybkiOptions(spSzybki)
    # now reset the option for minimization
    optSzybki.SetRunType(oeszybki.OERunType_CartesiansOpt)
    # generate szybki MMFF94 engine for minimization
    szOpt = oeszybki.OESzybki(optSzybki)
    # add strong harmonic restraints to nonHs
    szOpt.SetHarmonicConstraints(10.0)
    # construct a results object to contain the results of a szybki calculation
    szResults = oeszybki.OESzybkiResults()
    # work on a copy of the molecule
    tmpmol = oechem.OEMol(mol)
    if not szSP(tmpmol, szResults):
        print('szybki run failed for %s' % tmpmol.GetTitle())
        return False
    Etotsp = szResults.GetTotalEnergy()
    Evdwsp = szResults.GetEnergyTerm(oeszybki.OEPotentialTerms_MMFFVdW)
    if Evdwsp > 35:
        if not szOpt(tmpmol, szResults):
            print('szybki run failed for %s' % tmpmol.GetTitle())
            return False
        Etot = szResults.GetTotalEnergy()
        Evdw = szResults.GetEnergyTerm(oeszybki.OEPotentialTerms_MMFFVdW)
        wfile = open(clashfile, 'a')
        wfile.write('%s resolved bad clash: initial vdW: %.4f ; '
                    'resolved EvdW: %.4f\n' %
                    (tmpmol.GetTitle(), Evdwsp, Evdw))
        wfile.close()
        mol.SetCoords(tmpmol.GetCoords())
    oechem.OESetSDData(mol, oechem.OESDDataPair('MM Szybki Single Point Energy'\
, "%.12f" % szResults.GetTotalEnergy()))
    return True
Ejemplo n.º 8
0
def optMMFF(Mol, FF, fname):
    """

    Take an OEMol, conduct an energy minimization, and write
       this molecule's output to a .mol2 file.
    Note: the optimization type is BFGS.

    Parameters
    ----------
    Mol: an OEChem molecule
    FF: string for OEForceFieldType to use. Either "MMFF94" or "MMFF94S"
    fname: string name of the output .mol2 file to save molecule.


    Returns
    -------
    boolean True if the function successfully completed, False otherwise
    
    """

    tmpmol = oechem.OEMol( Mol)  # work on a copy of the molecule

    # Open output file to write molecule.
    ofs = oechem.oemolostream()
    if os.path.exists(fname):
        print("Output .mol2 file already exists. Skipping.\n")
        return
    if not ofs.open(fname):
        oechem.OEThrow.Fatal("Unable to open %s for writing" % fname)

    # set general energy options along with the run type specification
    optSzybki = oeszybki.OESzybkiOptions()
    optSzybki.SetSolventModel(oeszybki.OESolventModel_Sheffield)
    optSzybki.SetOptimizerType(oeszybki.OEOptType_BFGS)

    # set the particular force field
    if FF == "MMFF94":
        optSzybki.SetForceFieldType(oeszybki.OEForceFieldType_MMFF94)
    elif FF == "MMFF94S":
        optSzybki.SetForceFieldType(oeszybki.OEForceFieldType_MMFF94S)
    else:
        print( 'optMMFF failed for %s' %  tmpmol.GetTitle() )
        return False

    # create additional dependencies, then perform opt (in if statement)
    szOpt = oeszybki.OESzybki( optSzybki)   # generate minimization engine
    szResults = oeszybki.OESzybkiResults()  # make object to hold szybki results
    if not szOpt(tmpmol, szResults):
        print( 'optMMFF failed for %s' %  tmpmol.GetTitle() )
        return False

    # write out mol2 file and close the output filestream.
    oechem.OEWriteConstMolecule(ofs, tmpmol)
    ofs.close()

    return True
Ejemplo n.º 9
0
def optMMFF(Mol, FF, fname, log):
    """

    Take an OEMol, conduct an energy minimization, and write
       this molecule's output to a .mol2 file.
    Note: the optimization type is BFGS.

    Parameters
    ----------
    Mol: an OEChem molecule
    FF: string for OEForceFieldType to use. Either "MMFF94" or "MMFF94S"
    fname: string name of the output .mol2 file to save molecule.


    Returns
    -------
    boolean True if the function successfully completed, False otherwise

    """

    tmpmol = oechem.OEMol( Mol)  # work on a copy of the molecule

    if os.path.exists(fname):
        log.write("Output .mol2 file already exists. Skipping.\n")
        return False

    # set general energy options along with the run type specification
    optSzybki = oeszybki.OESzybkiOptions()
    optSzybki.SetSolventModel(oeszybki.OESolventModel_NoSolv)
    optSzybki.SetOptimizerType(oeszybki.OEOptType_BFGS)

    # set the particular force field
    if FF == "MMFF94":
        optSzybki.SetForceFieldType(oeszybki.OEForceFieldType_MMFF94)
    elif FF == "MMFF94S":
        optSzybki.SetForceFieldType(oeszybki.OEForceFieldType_MMFF94S)
    else:
        log.write( 'optMMFF failed for %s\n' %  tmpmol.GetTitle() )
        return False

    # create additional dependencies, then perform opt (in if statement)
    szOpt = oeszybki.OESzybki( optSzybki)  # generate minimization engine
    szResults = oeszybki.OESzybkiResults() # make object to hold szybki results
    if not szOpt(tmpmol, szResults):
        log.write( 'optMMFF failed for %s\n' %  tmpmol.GetTitle() )
        return False

    # try writing output file and return result
    return writeUpdatedMol(tmpmol, fname, log)
Ejemplo n.º 10
0
def min_mmff94x(mol, ofs, mmff94s=False):
    """
    Minimize the mol with MMFF94 or MMFF94S force field.

    Parameters
    ----------
    mol : OpenEye single-conformer molecule
    ofs : OpenEye output filestream
    mmff94s : Boolean
        True to minimize with MMFF94S

    """

    # make copy of the input mol
    oe_mol = oechem.OEGraphMol(mol)

    # set general energy options along with the run type specification
    optSzybki = oeszybki.OESzybkiOptions()
    optSzybki.SetSolventModel(oeszybki.OESolventModel_NoSolv)
    optSzybki.SetOptimizerType(oeszybki.OEOptType_BFGS)

    # minimize with input charges not mmff94(s) charges
    # https://docs.eyesopen.com/toolkits/python/szybkitk/examples.html#optimization-of-all-conformers-of-a-ligand
    optSzybki.GetSolventOptions().SetChargeEngine(oequacpac.OEChargeEngineNoOp())

    # set the particular force field
    if mmff94s:
        sdlabel = "MMFF94S"
        optSzybki.SetForceFieldType(oeszybki.OEForceFieldType_MMFF94S)
    else:
        sdlabel = "MMFF94"
        optSzybki.SetForceFieldType(oeszybki.OEForceFieldType_MMFF94)

    # generate minimization engine
    szOpt = oeszybki.OESzybki(optSzybki)

    # make object to hold szybki results
    szResults = oeszybki.OESzybkiResults()

    # perform minimization
    if not szOpt(oe_mol, szResults):
        smilabel = oechem.OEGetSDData(oe_mol, "SMILES QCArchive")
        print( ' >>> MMFF94x minimization failed for %s\n' % smilabel )
    energy = szResults.GetTotalEnergy()

    # save geometry, save energy as tag, write mol to file
    oechem.OESetSDData(oe_mol, f"Energy {sdlabel}", str(energy))
    oechem.OEWriteConstMolecule(ofs, oe_mol)
def main(args):
    if len(args) != 4:
        oechem.OEThrow.Usage("%s protein input_ligand output_ligand" % args[0])

    pfs = oechem.oemolistream()
    if not pfs.open(args[1]):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % args[1])

    lfs = oechem.oemolistream()
    if not lfs.open(args[2]):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % args[2])

    ofs = oechem.oemolostream()
    if not ofs.open(args[3]):
        oechem.OEThrow.Fatal("Unable to open %s for writing" % args[3])

    mol = oechem.OEGraphMol()
    protein = oechem.OEGraphMol()
    oechem.OEReadMolecule(lfs, mol)
    oechem.OEReadMolecule(pfs, protein)

    opts = oeszybki.OESzybkiOptions()
    opts.GetOptOptions().SetOptimizerType(oeszybki.OEOptType_NEWTON)
    opts.GetProteinOptions().SetProteinElectrostaticModel(
        oeszybki.OEProteinElectrostatics_ExactCoulomb)
    opts.GetProteinOptions().SetProteinFlexibilityType(
        oeszybki.OEProtFlex_Residues)
    opts.GetProteinOptions().SetProteinFlexibilityRange(2.0)

    sz = oeszybki.OESzybki(opts)
    sz.SetProtein(protein)

    res = oeszybki.OESzybkiResults()
    if (sz(mol, res)):
        oechem.OEWriteMolecule(ofs, mol)
        res.Print(oechem.oeout)

    return 0
Ejemplo n.º 12
0
def main(argv=[__name__]):
    itf = oechem.OEInterface(Interface, argv)

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

    pfs = oechem.oemolistream()
    if not pfs.open(itf.GetString("-protein")):
        oechem.OEThrow.Fatal("Unable to open %s for reading",
                             itf.GetString("-protein"))

    ofs = oechem.oemolostream()
    if not ofs.open(itf.GetString("-outl")):
        oechem.OEThrow.Fatal("Unable to open %s for writing" %
                             itf.GetString("-outl"))

    opfs = oechem.oemolostream()
    if not opfs.open(itf.GetString("-outp")):
        oechem.OEThrow.Fatal("Unable to open %s for writing" %
                             itf.GetString("-outp"))

    ligand = oechem.OEGraphMol()
    oechem.OEReadMolecule(ifs, ligand)
    protein = oechem.OEGraphMol()
    oechem.OEReadMolecule(pfs, protein)

    # Szybki options
    opts = oeszybki.OESzybkiOptions()
    opts.SetRunType(oeszybki.OERunType_CartesiansOpt)
    opts.GetOptOptions().SetMaxIter(2000)
    opts.GetOptOptions().SetGradTolerance(1e-6)
    opts.GetGeneralOptions().SetForceFieldType(
        oeszybki.OEForceFieldType_MMFF94S)
    opts.GetProteinOptions().SetProteinFlexibilityType(
        oeszybki.OEProtFlex_SideChainsList)
    opts.GetProteinOptions().SetProteinElectrostaticModel(
        oeszybki.OEProteinElectrostatics_ExactCoulomb)

    res_num = []
    for res in itf.GetStringList('-residues'):
        intres = None
        try:
            intres = int(res)
        except ValueError:
            print('Illegal residue value: {}'.format(res))

        if intres is None:
            continue
        res_num.append(intres)

    for i in res_num:
        for atom in protein.GetAtoms():
            residue = oechem.OEAtomGetResidue(atom)
            if (residue.GetResidueNumber() == i):
                opts.AddFlexibleResidue(residue)
                break

    sz = oeszybki.OESzybki(opts)
    sz.SetProtein(protein)
    result = oeszybki.OESzybkiResults()
    sz(ligand, result)
    sz.GetProtein(protein)
    oechem.OEWriteMolecule(opfs, protein)
    oechem.OEWriteMolecule(ofs, ligand)

    return 0