Ejemplo n.º 1
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.º 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 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.º 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])

    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.º 6
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.º 7
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.º 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(args):
    if len(args) != 2:
        oechem.OEThrow.Usage("%s <lig>" % args[0])

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

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

    szOpts = oeszybki.OESzybkiOptions()
    szOpts.GetSolventOptions().SetSolventModel(oeszybki.OESolventModel_Sheffield)
    sz = oeszybki.OESzybki(szOpts)
    eres = oeszybki.OESzybkiEnsembleResults()
    S = sz.GetEntropy(lig, eres, oeszybki.OEEntropyMethod_Analytic)

    print("Configurational entropy %10.2f" % eres.GetConfigurationalEntropy())
    print("Solvation entropy       %10.2f" % eres.GetEnsembleLigSolvEntropy())
    print("                            ======")
    print("Total solution entropy  %10.2f J/(mol K)" % S)

    return 0
Ejemplo n.º 13
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])

    # input set of conformations in solution
    mol = oechem.OEMol()
    oechem.OEReadMolecule(ifs, mol)

    opts = oeszybki.OESzybkiOptions()
    opts.GetSolventOptions().SetChargeEngine(oequacpac.OEChargeEngineNoOp())

    sz = oeszybki.OESzybki(opts)
    eres = oeszybki.OESzybkiEnsembleResults()
    entropy = sz.GetEntropy(mol, eres, oeszybki.OEEntropyMethod_Analytic,
                            oeszybki.OEEnvType_SolutionSPT)

    oechem.OEThrow.Info(
        "Estimated molar solution entropy of the input compound is: %5.1f J/(mol*K)"
        % entropy)

    oechem.OEThrow.Info(
        "Vibrational entropies (in J/(mol*K)) for all conformations:")
    for conf, r in zip(mol.GetConfs(), eres.GetResultsForConformations()):
        oechem.OEThrow.Info("%2d %5.1f" % (conf.GetIdx(), r.GetVibEntropy()))

    # ensemble of unique conformations
    oechem.OEWriteMolecule(ofs, mol)

    return 0
Ejemplo n.º 14
0
def main(args):
    if len(args) != 4:
        oechem.OEThrow.Usage("%s bound_ligand protein opt_ligand" % args[0])

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

    pfs = oechem.oemolistream()
    if not pfs.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])

    lig = oechem.OEMol()
    oechem.OEReadMolecule(lfs, lig)

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

    szOpts = oeszybki.OESzybkiOptions()
    sz = oeszybki.OESzybki(szOpts)
    sz.SetProtein(protein)

    eres = oeszybki.OESzybkiEnsembleResults()
    entropy = sz.GetEntropy(lig, eres, oeszybki.OEEntropyMethod_Analytic,
                            oeszybki.OEEnvType_Protein)

    oechem.OEThrow.Info(
        "Estimated entropy of the bound ligand is: %5.1f J/(mol*K)" % entropy)

    oechem.OEWriteMolecule(ofs, lig)

    return 0
Ejemplo n.º 15
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
Ejemplo n.º 16
0
def main(args):
    if len(args) != 4:
        oechem.OEThrow.Usage(
            "%s ligand_file protein_file output_file (SDF or OEB)" % args[0])

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

    pfs = oechem.oemolistream()
    if not pfs.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])

    if not oechem.OEIsSDDataFormat(ofs.GetFormat()):
        oechem.OEThrow.Fatal(
            "Output file does not support SD data used by this example")

    # Szybki options for VdW-Coulomb calculations
    optsC = oeszybki.OESzybkiOptions()
    optsC.GetProteinOptions().SetProteinElectrostaticModel(
        oeszybki.OEProteinElectrostatics_ExactCoulomb)
    optsC.SetRunType(oeszybki.OERunType_CartesiansOpt)

    # Szybki options for PB calculations
    optsPB = oeszybki.OESzybkiOptions()
    optsPB.GetProteinOptions().SetProteinElectrostaticModel(
        oeszybki.OEProteinElectrostatics_SolventPBForces)
    optsPB.SetRunType(oeszybki.OERunType_SinglePoint)

    # Szybki objects
    szC = oeszybki.OESzybki(optsC)
    szPB = oeszybki.OESzybki(optsPB)

    # read and setup protein
    protein = oechem.OEGraphMol()
    oechem.OEReadMolecule(pfs, protein)
    szC.SetProtein(protein)
    szPB.SetProtein(protein)

    terms = set([
        oeszybki.OEPotentialTerms_ProteinLigandInteraction,
        oeszybki.OEPotentialTerms_VdWProteinLigand,
        oeszybki.OEPotentialTerms_CoulombProteinLigand,
        oeszybki.OEPotentialTerms_ProteinDesolvation,
        oeszybki.OEPotentialTerms_LigandDesolvation,
        oeszybki.OEPotentialTerms_SolventScreening
    ])

    # process molecules
    for mol in lfs.GetOEMols():

        # optimize mol
        if not list(szC(mol)):
            oechem.OEThrow.Warning("No results processing molecule: %s" %
                                   mol.GetTitle())
            continue

        # do single point with better electrostatics
        for conf, results in zip(mol.GetConfs(), szPB(mol)):
            for i in terms:
                strEnergy = ("%9.4f" % results.GetEnergyTerm(i))
                oechem.OEAddSDData(conf, oeszybki.OEGetEnergyTermName(i),
                                   strEnergy)

        oechem.OEWriteMolecule(ofs, mol)

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

    lfs = oechem.oemolistream()
    if not lfs.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("-p")):
        oechem.OEThrow.Fatal("Unable to open %s for reading",
                             itf.GetString("-p"))

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

    logfile = oechem.oeout
    if itf.HasString("-log"):
        if not logfile.open(itf.GetString("-log")):
            oechem.OEThrow.Fatal("Unable to open %s for writing" %
                                 itf.GetString("-log"))

    # Szybki options
    opts = oeszybki.OESzybkiOptions()

    # select optimization type
    if (itf.GetBool("-t")):
        opts.SetRunType(oeszybki.OERunType_TorsionsOpt)
    else:
        opts.SetRunType(oeszybki.OERunType_CartesiansOpt)

    # select protein-electrostatic model
    emodel = itf.GetString("-e")
    elecModel = oeszybki.OEProteinElectrostatics_NoElectrostatics
    if emodel == "VdW":
        elecModel = oeszybki.OEProteinElectrostatics_NoElectrostatics
    elif emodel == "PB":
        elecModel = oeszybki.OEProteinElectrostatics_GridPB
    elif emodel == "Coulomb":
        elecModel = oeszybki.OEProteinElectrostatics_GridCoulomb
    elif emodel == "ExactCoulomb":
        elecModel = oeszybki.OEProteinElectrostatics_ExactCoulomb
        opts.GetProteinOptions().SetExactVdWProteinLigand(True)
        opts.GetOptOptions().SetMaxIter(1000)
        opts.GetOptOptions().SetGradTolerance(1e-6)
    opts.GetProteinOptions().SetProteinElectrostaticModel(elecModel)

    # Szybki object
    sz = oeszybki.OESzybki(opts)

    # read and setup protein
    protein = oechem.OEGraphMol()
    oechem.OEReadMolecule(pfs, protein)
    sz.SetProtein(protein)

    # save or load grid potential
    if (emodel == "PB" or emodel == "Coulomb"):
        if (itf.HasString("-s")):
            sz.SavePotentialGrid(itf.GetString("-s"))
        if (itf.HasString("-l")):
            sz.LoadPotentialGrid(itf.GetString("-l"))

    # process molecules
    for mol in lfs.GetOEMols():
        logfile.write("\nMolecule %s\n" % mol.GetTitle())
        no_res = True
        for res in sz(mol):
            res.Print(logfile)
            no_res = False

        if no_res:
            oechem.OEThrow.Warning("No results processing molecule: %s" %
                                   mol.GetTitle())
            continue
        else:
            oechem.OEWriteMolecule(ofs, mol)

    return 0
def main(argv=[__name__]):
    itf = oechem.OEInterface()
    if not SetupInterface(argv, itf):
        return 1

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

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

    logfile = oechem.oeout
    if itf.HasString("-log"):
        if not logfile.open(itf.GetString("-log")):
            oechem.OEThrow.Fatal("Unable to open %s for writing" %
                                 itf.GetString("-log"))

    # Szybki options
    opts = oeszybki.OESzybkiOptions()

    # select run type
    if itf.GetBool("-t"):
        opts.SetRunType(oeszybki.OERunType_TorsionsOpt)
    if itf.GetBool("-n"):
        opts.SetRunType(oeszybki.OERunType_SinglePoint)

    # apply solvent model
    if itf.GetBool("-s"):
        opts.GetSolventOptions().SetSolventModel(
            oeszybki.OESolventModel_Sheffield)

    # remove attractive VdW forces
    if itf.GetBool("-a"):
        opts.GetGeneralOptions().SetRemoveAttractiveVdWForces(True)

    # Szybki object
    sz = oeszybki.OESzybki(opts)

    # fix atoms
    if itf.HasString("-f"):
        if not sz.FixAtoms(itf.GetString("-f")):
            oechem.OEThrow.Warning("Failed to fix atoms for %s" %
                                   itf.GetString("-f"))

    # process molecules
    mol = oechem.OEMol()
    while oechem.OEReadMolecule(ifs, mol):
        logfile.write("\nMolecule %s\n" % mol.GetTitle())
        no_res = True
        for results in sz(mol):
            results.Print(logfile)
            no_res = False

        if no_res:
            oechem.OEThrow.Warning("No results processing molecule: %s" %
                                   mol.GetTitle())
            continue
        else:
            oechem.OEWriteMolecule(ofs, mol)

    return 0