Working with Szybki TK

The basic Szybki TK API is provided to the users in the OESzybki, OESzybkiOptions, OESzybkiResults and OESzybkiEnsembleResults classes. In addition, when the purpose is to calculate such compound properties like solvation free energy or free energy of selecting specific conformations out of the ensemble, the higher level API defined in the free functions OEEstimateSolvFreeEnergy and OEEstimateConfFreeEnergies.

Ligand Energetics and Optimization

Single ligand in vacuum

The following example illustrates how to optimize a single ligand in vacuum. As one can see assuming a molecule is successfully read, only two objects are needed to perform the optimization: OESzybki and OESzybkiResults. The latter is passed as the second parameter to the parenthesis operator OESzybki.operator(). Molecule with the optimized coordinates is returned as a first parameter. Final energy results are available as SD tags in the returned molecule and optionally with a call of a method OESzybkiResults.Print.

#!/usr/bin/env python
#############################################################################
#  Copyright (C) 2006,2014-2017  OpenEye Scientific Software, Inc.
#############################################################################
import os, sys
from openeye.oechem import *
from openeye.oeszybki import *

def main(args = [__name__]):
    if len(args) != 3:
        OEThrow.Usage("%s <molfile> <outfile>" % args[0])

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

    ofs = oemolostream()
    if not ofs.open(args[2]):
        OEThrow.Fatal("Unable to open %s for writing" % args[2])
  
    mol = OEMol()
    OEReadMolecule(ifs,mol)
    
    opts = OESzybkiOptions()
    sz = OESzybki(opts)   
    results = OESzybkiResults()
    if not sz(mol, results):
        return 1

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

    return 0

if __name__ == "__main__":
    sys.exit(main(sys.argv))

Optimization of a set of ligands

The next example illustrates the usage of Szybki TK to optimize a set of compounds with the MMFF94 force field in vacuum or in solution using Sheffield solvation model. Optionally attractive VdW can be removed. The optimization is done by default in full Cartesian coordinates, however torsion space optimization or single point calculation could be done too. A group of atoms which belong to specified SMARTS pattern might be excluded from optimization so their positions will be fixed at their initial coordinates. Note that the OESzybki object is made with a constructor which takes the instance of the OESzybkiOptions class.

#!/usr/bin/env python
#############################################################################
#  Copyright (C) 2006-2017  OpenEye Scientific Software, Inc.
#############################################################################
import os, sys
from openeye.oechem import *
from openeye.oeszybki import *

def main(argv = [__name__]):
    itf = OEInterface()
    if not SetupInterface(argv, itf):
        return 1
  
    ifs = oemolistream()
    if not ifs.open(itf.GetString("-in")):
        OEThrow.Fatal("Unable to open %s for reading" % itf.GetString("-in"))

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

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

    #Szybki options
    opts = OESzybkiOptions()

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

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

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

    #Szybki object
    sz = OESzybki(opts)

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

    #process molecules
    mol = OEMol()
    while 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:
            OEThrow.Warning("No results processing molecule: %s" % mol.GetTitle())
            continue
        else:
            OEWriteMolecule(ofs, mol)

    return 0

InterfaceData = """
!PARAMETER -in
  !TYPE string
  !REQUIRED true
  !BRIEF Input molecule file name.
!END

!PARAMETER -out
  !TYPE string
  !REQUIRED true
  !BRIEF Output molecule file name.
!END

!PARAMETER -log
  !TYPE string
  !REQUIRED false
  !BRIEF Log file name. Defaults to standard out.
!END

!PARAMETER -s
  !TYPE bool
  !DEFAULT false
  !REQUIRED false
  !BRIEF Optimization in solution. 
!END

!PARAMETER -t
  !TYPE bool
  !DEFAULT false
  !REQUIRED false
  !BRIEF Optimization of torsions. 
!END

!PARAMETER -n
  !TYPE bool
  !DEFAULT false
  !REQUIRED false
  !BRIEF Single point calculation. 
!END

!PARAMETER -a
  !TYPE bool
  !DEFAULT false
  !REQUIRED false
  !BRIEF No attractive VdW forces.
!END

!PARAMETER -f
  !TYPE string
  !REQUIRED false
  !BRIEF SMARTS pattern of fixed atoms.
!END
"""


def SetupInterface(argv, itf):
    OEConfigure(itf, InterfaceData)
    if OECheckHelp(itf, argv):
        return False
    if not OEParseCommandLine(itf, argv):
        return False
    if not OEIsReadable(OEGetFileType(OEGetFileExtension(itf.GetString("-in")))):
        OEThrow.Warning("%s is not a readable input file" % itf.GetString("-in"))
        return False
    if not OEIsWriteable(OEGetFileType(OEGetFileExtension(itf.GetString("-out")))):
        OEThrow.Warning("%s is not a writable output file" % itf.GetString("-out"))
        return False
    return True


if __name__ == "__main__":
    sys.exit(main(sys.argv))

Optimization of a single ligand with the Newton-Raphson method

The next example in this section shows how to use Newton-Raphson optimization method, rather than the default BFGS:

#!/usr/bin/env python
#############################################################################
# Copyright (C) 2014-2017 OpenEye Scientific Software, Inc.
#############################################################################
import sys

from openeye.oechem import *
from openeye.oeszybki import *

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

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

    ofs = oemolostream()
    if not ofs.open(args[2]):
        OEThrow.Fatal("Unable to open %s for writing" % args[2])
                
    mol = OEMol()
    OEReadMolecule(ifs, mol)

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

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

    return 0

if __name__ == "__main__":
    sys.exit(main(sys.argv))

Optimization of all conformers of a ligand

Finally, the last example in this section shows how to use Newton-Raphson optimization method on all conformers of a ligand. The current charges of the ligand are used and will not be changed during the optimization.

#!/usr/bin/env python
#############################################################################
# Copyright (C) 2015-2017 OpenEye Scientific Software, Inc.
#############################################################################
import sys

from openeye.oechem import *
from openeye.oequacpac import *
from openeye.oeszybki import *

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

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

    ofs = oemolostream()
    if not ofs.open(args[2]):
        OEThrow.Fatal("Unable to open %s for writing" % args[2])
                
    opts = OESzybkiOptions()
    opts.GetOptOptions().SetOptimizerType(OEOptType_NEWTON)
    opts.GetGeneralOptions().SetForceFieldType(OEForceFieldType_MMFF94S)
    opts.GetSolventOptions().SetSolventModel(OESolventModel_Sheffield)
    opts.GetSolventOptions().SetChargeEngine(OEChargeEngineNoOp())
    sz = OESzybki(opts)
    res = OESzybkiResults()
    for mol in ifs.GetOEMols():
        for conf in mol.GetConfs():
            if sz(conf, res):
                OESetSDData(conf, OESDDataPair( 'Total_energy', "%0.4f" % res.GetTotalEnergy()))
               
        OEWriteMolecule(ofs, mol)

    ifs.close()
    ofs.close()

    return 0

if __name__ == "__main__":
    sys.exit(main(sys.argv))

Protein-Ligand Energetics and Optimization

Examples in this section show how to optimize a bound ligand.

Optimization of a single bound ligand

The simplest case is illustrated below. Notice the usage of the method OESzybki.SetProtein which tells Szybki that the ligand is placed inside the protein. Since no protein-ligand electrostatics have been specified, neither the coordinates types which should be used by the optimizer, the code below performs the optimization for a rigid ligand using 6 translational-rotational coordinates in the MMFF94 VdW potential field.

#!/usr/bin/env python
#############################################################################
#  Copyright (C) 2006, 2014-2017 OpenEye Scientific Software, Inc.
#############################################################################
import os, sys
from openeye.oechem import *
from openeye.oeszybki import *

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

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

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

    ofs = oemolostream()
    if not ofs.open(argv[3]):
         OEThrow.Fatal("Unable to open %s for writing" % argv[3])
  
    mol = OEGraphMol()
    OEReadMolecule(lfs, mol)

    protein = OEGraphMol()
    OEReadMolecule(pfs, protein)

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

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

    return 0

if __name__ == "__main__":
    sys.exit(main(sys.argv))

Optimization of a set of bound ligands in a rigid receptor

The next example illustrates the usage of Szybki TK to optimize a set of ligands with MMFF94 force field inside a protein receptor. By default only VdW protein-ligand interaction is used. Optionally exact or grid Coulomb potential as well as PB solvent screening potentials could be added. When grid potential is selected (either Coulomb or PB) optionally it could be saved or read in when the corresponding grid file is present in the specified directory. Notice that when the exact Coulomb electrostatics is chosen, also the exact VdW potential is chosen (method OESzybkiProteinOptions.SetExactVdWProteinLigand) which allows for tight gradients convergence (methods OESzybkiOptOptions.SetMaxIter and OESzybkiOptOptions.SetGradTolerance). By default ligand is treated as a solid body, that is only its translational and rotational degrees of freedom are optimized. Optionally also torsional degrees could be optimized. In this example protein receptor is rigid. Molecular input file should contain initial 3D coordinates of molecules in any format supported by OEChem TK. Output file is specified with the -out flag. In addition a log file containing energy data terms values is written to stdout or a file specified by -log.

#!/usr/bin/env python
#############################################################################
# Copyright (C) 2014-2017 OpenEye Scientific Software, Inc.
#############################################################################
import sys

from openeye.oechem import *
from openeye.oeszybki import *

def main(argv=[__name__]):
    itf = OEInterface(Interface, argv)

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

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

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

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


    #Szybki options
    opts = OESzybkiOptions()

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

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

    #Szybki object
    sz = OESzybki(opts)

    #read and setup protein
    protein = OEGraphMol()
    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
    res = OESzybkiResults()
    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:
            OEThrow.Warning("No results processing molecule: %s" % mol.GetTitle())
            continue
        else:
            OEWriteMolecule(ofs, mol)

    return 0

Interface = """
!PARAMETER -in
  !TYPE string
  !REQUIRED true
  !BRIEF Input molecule file name.
!END

!PARAMETER -p
  !TYPE string
  !REQUIRED true
  !BRIEF Input protein file name.
!END

!PARAMETER -out
  !TYPE string
  !REQUIRED true
  !BRIEF Output molecule file name.
!END

!PARAMETER -log
  !TYPE string
  !REQUIRED false
  !BRIEF Log file name. Defaults to standard out.
!END

!PARAMETER -e
  !TYPE string
  !DEFAULT VdW
  !LEGAL_VALUE VdW
  !LEGAL_VALUE PB
  !LEGAL_VALUE Coulomb
  !LEGAL_VALUE ExactCoulomb
  !BRIEF Protein ligand electrostatic model.
!END

!PARAMETER -t
  !TYPE bool
  !DEFAULT false
  !REQUIRED false
  !BRIEF Torsions added to the optimized variables.
!END

!PARAMETER -l
  !TYPE string
  !REQUIRED false
  !BRIEF File name of the potential grid to be read.
!END

!PARAMETER -s
  !TYPE string
  !REQUIRED false
  !BRIEF File name of the potential grid to be saved.
!END
"""

if __name__ == "__main__":
    sys.exit(main(sys.argv))

Optimization of a set of bound ligands in a partially flexible receptor

The next example is very similar with respect to the previous one, but the side chains of the protein which are within the specified range from the ligand, are made flexible during optimization (methods OESzybkiProteinOptions.SetProteinFlexibilityType and OESzybkiProteinOptions.SetProteinFlexibilityRange). Optionally, partially optimized structure can be saved to a file.

#!/usr/bin/env python
#############################################################################
# Copyright (C) 2014-2017 OpenEye Scientific Software, Inc.
#############################################################################
import sys

from openeye.oechem import *
from openeye.oeszybki import *

def main(argv=[__name__]):
    itf = OEInterface(Interface, argv)

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

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

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

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

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

    #Szybki options
    opts = OESzybkiOptions()

    #select optimization type
    opt = itf.GetString("-opt")
    if opt == "Cartesian":
        opts.SetRunType(OERunType_CartesiansOpt)
    if opt == "Torsion":
        opts.SetRunType(OERunType_TorsionsOpt)
    if opt == "SolidBody":
        opts.SetRunType(OERunType_SolidBodyOpt)
    
    #select protein-electrostatic model
    emodel = itf.GetString("-e")
    elecModel = OEProteinElectrostatics_NoElectrostatics
    if emodel == "VdW":
        elecModel = OEProteinElectrostatics_NoElectrostatics
    elif emodel == "PB":
        elecModel = OEProteinElectrostatics_GridPB
    elif emodel == "Coulomb":
        elecModel = OEProteinElectrostatics_GridCoulomb
    elif emodel == "ExactCoulomb":
        elecModel = OEProteinElectrostatics_ExactCoulomb
    opts.GetProteinOptions().SetProteinElectrostaticModel(elecModel)

    #use smooth potential and tight convergence
    if (emodel == "VdW" or emodel == "ExactCoulomb"):
        opts.GetProteinOptions().SetExactVdWProteinLigand(True)
        opts.GetOptOptions().SetMaxIter(1000)
        opts.GetOptOptions().SetGradTolerance(1e-6)

    #protein flexibility
    opts.GetProteinOptions().SetProteinFlexibilityType(OEProtFlex_SideChains)
    opts.GetProteinOptions().SetProteinFlexibilityRange(itf.GetDouble("-d"))

    #Szybki object
    sz = OESzybki(opts)

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

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

        OEWriteMolecule(olfs, mol)
        if itf.HasString("-s"):
            sz.GetProtein(oprotein)
            OEWriteMolecule(opfs, oprotein)

    return 0

Interface = """
!BRIEF -in input_molecule -p protein -out output_molecule
!PARAMETER -in
  !TYPE string
  !REQUIRED true
  !BRIEF Input molecule file name.
!END

!PARAMETER -p
  !TYPE string
  !REQUIRED true
  !BRIEF Input protein file name.
!END

!PARAMETER -out
  !TYPE string
  !REQUIRED true
  !BRIEF Output molecule file name.
!END

!PARAMETER -log
  !TYPE string
  !REQUIRED false
  !BRIEF Log file name. Defaults to standard out.
!END

!PARAMETER -e
  !TYPE string
  !DEFAULT VdW
  !LEGAL_VALUE VdW
  !LEGAL_VALUE PB
  !LEGAL_VALUE Coulomb
  !LEGAL_VALUE ExactCoulomb
  !BRIEF Protein ligand electrostatic model.
!END

!PARAMETER -opt
  !TYPE string
  !DEFAULT Cartesian
  !LEGAL_VALUE Cartesian
  !LEGAL_VALUE Torsion
  !LEGAL_VALUE SolidBody
  !BRIEF Optimization method
!END

!PARAMETER -d
  !TYPE double
  !DEFAULT 5.0
  !BRIEF Distance criteria from protein side-chains flexibility. 
!END

!PARAMETER -s
  !TYPE string
  !REQUIRED false
  !BRIEF File name the partially optimized protein will be saved.
!END
"""

if __name__ == "__main__":
    sys.exit(main(sys.argv))

Estimation of PB binding for a set of ligands

This example shows how to fast estimate binding for a set of ligands using PB electrostatics. Two OESzybki objects are instantiated: one for the optimization of bound ligands in VdW-Coulomb potential, and the second one which performs single-point PB calculations. Final results are attached as SD tags to the output molecules.

#!/usr/bin/env python
#############################################################################
#  Copyright (C) 2014-2017 OpenEye Scientific Software, Inc.
#############################################################################
import sys

from openeye.oechem import *
from openeye.oeszybki import *

def main(args):
    if len(args) != 4:
        OEThrow.Usage("%s ligand_file protein_file output_file (SDF or OEB)" % args[0])

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

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

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

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

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

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

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

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

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


    #process molecules
    res = OESzybkiResults()
    for mol in lfs.GetOEMols():
        
        #optimize mol
        if not list(szC(mol)):
            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))
                OEAddSDData(conf, OEGetEnergyTermName(i), strEnergy)

        OEWriteMolecule(ofs, mol)

    return 0

if __name__ == "__main__":
    sys.exit(main(sys.argv))

Optimization of a bound ligand using Newton-Raphson method

The last example in this section illustrates how to use SzybkiTK to optimize a ligand in partially flexible protein with Newton-Raphson optimization method.

#!/usr/bin/env python
#############################################################################
# Copyright (C) 2014-2017 OpenEye Scientific Software, Inc.
#############################################################################
import sys

from openeye.oechem import *
from openeye.oeszybki import *

def main(args):
    if len(args) != 4:
        OEThrow.Usage("%s protein input_ligand output_ligand" % args[0])
                
    pfs = oemolistream()
    if not pfs.open(args[1]):
        OEThrow.Fatal("Unable to open %s for reading" % args[1])

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

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

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

    opts = OESzybkiOptions()
    opts.GetOptOptions().SetOptimizerType(OEOptType_NEWTON)
    opts.GetProteinOptions().SetProteinElectrostaticModel(OEProteinElectrostatics_ExactCoulomb)
    opts.GetProteinOptions().SetProteinFlexibilityType(OEProtFlex_Residues)
    opts.GetProteinOptions().SetProteinFlexibilityRange(2.0)
  
    sz = OESzybki(opts)
    sz.SetProtein(protein)

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

    return 0

if __name__ == "__main__":
    sys.exit(main(sys.argv))

Entropy estimation

Estimation of solution ligand entropy

The following 2 codes illustrate how to estimate compound entropy in solution with Szybki TK. In the second example partial charges used for Sheffield solvation are taken from the input molecule.

#!/usr/bin/env python
#############################################################################
#  Copyright (C) 2014-2017 OpenEye Scientific Software, Inc.
#############################################################################
from __future__ import print_function
import sys

from openeye.oechem import *
from openeye.oeszybki import *

def main(args):
    if len(args) != 2:
        OEThrow.Usage("%s <lig>" % args[0])

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

    lig = OEMol()
    OEReadMolecule(ifs, lig)

    szOpts = OESzybkiOptions()
    szOpts.GetSolventOptions().SetSolventModel(OESolventModel_Sheffield)
    sz = OESzybki(szOpts)
    eres = OESzybkiEnsembleResults()
    S = sz.GetEntropy(lig, eres, 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

if __name__ == "__main__":
    sys.exit(main(sys.argv))
#!/usr/bin/env python
#############################################################################
#  Copyright (C) 2014-2017 OpenEye Scientific Software, Inc.
#############################################################################
import sys

from openeye.oechem import *
from openeye.oequacpac import *
from openeye.oeszybki import *

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

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

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

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

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

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

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

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

    #ensemble of unique conformations
    OEWriteMolecule(ofs, mol)

    return 0

if __name__ == "__main__":
    sys.exit(main(sys.argv))

Estimation of bound ligand entropy

The next example below shows how to calculate entropy of a bound ligand.

#!/usr/bin/env python
#############################################################################
#  Copyright (C) 2014-2017 OpenEye Scientific Software, Inc.
#############################################################################
import sys

from openeye.oechem import *
from openeye.oeszybki import *

def main(args):
    if len(args) != 4:
        OEThrow.Usage("%s bound_ligand protein opt_ligand" % args[0])
                
    lfs = oemolistream()
    if not lfs.open(args[1]):
        OEThrow.Fatal("Unable to open %s for reading" % args[1])

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

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

    lig = OEMol()
    OEReadMolecule(lfs, lig)

    protein =  OEGraphMol()
    OEReadMolecule(pfs, protein)

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

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

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

    OEWriteMolecule(ofs, lig)

    return 0

if __name__ == "__main__":
    sys.exit(main(sys.argv))

Solvation free energy estimation

#!/usr/bin/env python
#############################################################################
# Copyright (C) 2014 OpenEye Scientific Software, Inc.
#############################################################################
import sys

from openeye.oechem import *
from openeye.oeszybki import *

def main(args):
    if len(args) != 3:
        OEThrow.Usage("%s <input> <output>" % args[0])

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

    ofs = oemolostream()
    if not ofs.open(args[2]):
        OEThrow.Fatal("Unable to open %s for writing" % args[2])
                
    mol = OEMol()
    OEReadMolecule(ifs, mol)

    opts = OEFreeFormSolvOptions()
    opts.SetIonicState(OEFreeFormIonicState_Uncharged)
    res = OEFreeFormSolvResults()

    omol = OEGraphMol()
    if not OEEstimateSolvFreeEnergy(res, omol, mol, opts):
        OEThrow.Error("Failed to calculate solvation free energy for molecule %s" %
                      mol.GetTitle())

    solvenergy = res.GetSolvationFreeEnergy()
    OEThrow.Info("Solvation free energy for compound %s is %6.2f kcal/mol" %
                 (mol.GetTitle(), solvenergy))

    OEWriteMolecule(ofs, omol)
    
    return 0

if __name__ == "__main__":
    sys.exit(main(sys.argv))

Conformations free energy estimation

Warning

This capability should not be used on 32-bit platforms because the memory requirements are too high.

Simple free energy estimation

The following code illustrates how to use the high level commands from OEFreeFormConf to estimate conformer free energies in solution with Szybki TK.

#!/usr/bin/env python
#############################################################################
# Copyright (C) 2017 OpenEye Scientific Software, Inc.
#############################################################################
import sys

from openeye.oechem import *
from openeye.oeszybki import *

def main(args):
    if len(args) != 3:
        OEThrow.Usage("%s <input> <output>" % args[0])

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

    ofs = oemolostream()
    if not ofs.open(args[2]):
        OEThrow.Fatal("Unable to open %s for writing" % args[2])
                
    mol = OEMol()
    OEReadMolecule(ifs, mol)

    opts = OEFreeFormConfOptions()
    ffconf = OEFreeFormConf(opts)

    omol = OEMol(mol)
    if not (ffconf.EstimateFreeEnergies(omol) == OEFreeFormReturnCode_Success):
        OEThrow.Error("Failed to estimate conformational free energies")

    res = OEFreeFormConfResults(omol)
    OEThrow.Info("Number of unique conformations: %d" % res.GetNumUniqueConfs())
    OEThrow.Info("Conf.  Delta_G   Vibrational_Entropy")
    OEThrow.Info("      [kcal/mol]     [J/(mol K)]")
    for r in res.GetResultsForConformations():
        OEThrow.Info("%2d %10.2f %14.2f" % (r.GetConfIdx(), r.GetDeltaG(), 
                                            r.GetVibrationalEntropy()))

    OEWriteMolecule(ofs, omol)

    return 0

if __name__ == "__main__":
    sys.exit(main(sys.argv))

Simple restriction energy estimation

The following code illustrates how to use the high level commands from OEFreeFormConf to estimate restriction energies on conformers, along with conformer free energies in solution, with Szybki TK.

#!/usr/bin/env python
#############################################################################
# Copyright (C) 2017 OpenEye Scientific Software, Inc.
#############################################################################
import sys

from openeye.oechem import *
from openeye.oeszybki import *

def main(args):
    if len(args) != 3:
        OEThrow.Usage("%s <input> <output>" % args[0])

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

    ofs = oemolostream()
    if not ofs.open(args[2]):
        OEThrow.Fatal("Unable to open %s for writing" % args[2])
                
    mol = OEMol()
    OEReadMolecule(ifs, mol)

    opts = OEFreeFormConfOptions()
    ffconf = OEFreeFormConf(opts)

    omol = OEMol(mol)
    rmol = OEMol(mol)
    if not (ffconf.EstimateFreeEnergies(omol, rmol) == OEFreeFormReturnCode_Success):
        OEThrow.Error("Failed to estimate conformational free energies")

    res = OEFreeFormConfResults(omol)
    OEThrow.Info("Number of unique conformations: %d" % res.GetNumUniqueConfs())
    OEThrow.Info("Conf.  Delta_G   Vibrational_Entropy")
    OEThrow.Info("      [kcal/mol]     [J/(mol K)]")
    for r in res.GetResultsForConformations():
        OEThrow.Info("%2d %10.2f %14.2f" % (r.GetConfIdx(), r.GetDeltaG(), 
                                            r.GetVibrationalEntropy()))

    rstrRes = OERestrictionEnergyResult(rmol)
    OEThrow.Info("Global strain: %d" % rstrRes.GetGlobalStrain())
    OEThrow.Info("Local strain: %d" % rstrRes.GetLocalStrain())

    OEWriteMolecule(ofs, omol)

    return 0

if __name__ == "__main__":
    sys.exit(main(sys.argv))

Advanced free energy estimation

The following code illustrates how to use the low level commands from OEFreeFormConfAdvanced to estimate the conformer free energies in solution with Szybki TK. These low level methods of estimation gives an advantage over the high level methods of OEFreeFormConf in that these gives the user control over better managing certain expensive parts of the calculation.

#!/usr/bin/env python
#############################################################################
# Copyright (C) 2017 OpenEye Scientific Software, Inc.
#############################################################################
import sys

from openeye.oechem import *
from openeye.oeszybki import *

def main(args):
    if len(args) != 3:
        OEThrow.Usage("%s <input> <output>" % args[0])

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

    ofs = oemolostream()
    if not ofs.open(args[2]):
        OEThrow.Fatal("Unable to open %s for writing" % args[2])
                
    mol = OEMol()
    OEReadMolecule(ifs, mol)

    opts = OEFreeFormConfOptions()
    ffconf = OEFreeFormConfAdvanced(opts)

    # Make a copy of our MCMol.  We will execute the FreeFormConf commands on
    # the copied molecule so that our original molecule stays intact. 
    omol = OEMol(mol)

    # Prepare a comprehensive ensemble of molecule conformers. This will
    # generate a comprehensive set of conformers, assign solvent charges on the molecule
    # and check that the ensemble is otherwise ready for FreeFormConf calculations.
    if not (ffconf.PrepareEnsemble(omol) == OEFreeFormReturnCode_Success):
        OEThrow.Error("Failed to prepare ensemble for FreeFormConf calculations")

    # Perform loose optimization of the ensemble conformers.  We will remove
    # duplicates based on the loose optimization, to reduce the time needed for
    # tighter, more stricter optimization
    if not (ffconf.PreOptimizeEnsemble(omol) == OEFreeFormReturnCode_Success):
        OEThrow.Error("Pre-optimization of the ensembles failed")

    # Remove duplicates from the pre-optimized ensemble
    if not (ffconf.RemoveDuplicates(omol) == OEFreeFormReturnCode_Success):
        OEThrow.Error("Duplicate removal from the ensembles failed")

    # Perform the desired optimization.  This uses a stricter convergence
    # criteria in the default settings.
    if not (ffconf.Optimize(omol) == OEFreeFormReturnCode_Success):
        OEThrow.Error("Optimization of the ensembles failed")

    # Remove duplicates to obtain the set of minimum energy conformers
    if not (ffconf.RemoveDuplicates(omol) == OEFreeFormReturnCode_Success):
        OEThrow.Error("Duplicate removal from the ensembles failed")

    # Perform FreeFormConf free energy calculations.  When all the above steps
    # have already been performed on the ensemble, this energy calculation
    # step is fast.
    if not (ffconf.EstimateEnergies(omol) == OEFreeFormReturnCode_Success):
        OEThrow.Error("Estimation of FreeFormConf energies failed")

    # Gather results of calculation into a results object for ease of viewing, etc.
    res = OEFreeFormConfResults(omol)
    OEThrow.Info("Number of unique conformations: %d" % res.GetNumUniqueConfs())
    OEThrow.Info("Conf.  Delta_G   Vibrational_Entropy")
    OEThrow.Info("      [kcal/mol]     [J/(mol K)]")
    for r in res.GetResultsForConformations():
        OEThrow.Info("%2d %10.2f %14.2f" % (r.GetConfIdx(), r.GetDeltaG(), 
                                            r.GetVibrationalEntropy()))

    OEWriteMolecule(ofs, omol)

    return 0

if __name__ == "__main__":
    sys.exit(main(sys.argv))

Advanced restriction energy estimation

The following code illustrates how to use the low level commands from OEFreeFormConfAdvanced to estimate the restriction energies of conformers, along with conformer free energies in solution, with Szybki TK. These low level methods of estimation gives an advantage over the high level methods of OEFreeFormConf in that these gives the user control over better managing certain expensive parts of the calculation.

#!/usr/bin/env python
#############################################################################
# Copyright (C) 2017 OpenEye Scientific Software, Inc.
#############################################################################
import sys

from openeye.oechem import *
from openeye.oeszybki import *

def main(args):
    if len(args) != 3:
        OEThrow.Usage("%s <input> <output>" % args[0])

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

    ofs = oemolostream()
    if not ofs.open(args[2]):
        OEThrow.Fatal("Unable to open %s for writing" % args[2])
                
    mol = OEMol()
    OEReadMolecule(ifs, mol)

    opts = OEFreeFormConfOptions()
    ffconf = OEFreeFormConfAdvanced(opts)

    # Make a copy of our MCMol.  We will execute the FreeFormConf commands on
    # the copied molecule so that our original molecule stays intact. 
    omol = OEMol(mol)

    # Make further copies of our original molecule.  The copied molecule(s) would be used
    # as source on which retriction energies would be calculated
    rmol = OEMol(mol)
    fmol = OEMol(mol)

    # Prepare a comprehensive ensemble of molecule conformers.  For calculation
    # of restriction energies we want to make sure that all the corresponding free
    # conformers are also part of the comprehensive ensemble.  This will also
    # assign solvent charges on the molecule and check that the ensemble is
    # otherwise ready for FreeFormConf calculations. The resulting `fmol`
    # contains the correspondig free conformers.
    if not (ffconf.PrepareEnsemble(omol, rmol, fmol) == OEFreeFormReturnCode_Success):
        OEThrow.Error("Failed to prepare ensemble for FreeFormConf calculations")

    # Perform loose optimization of the ensemble conformers.  We will remove
    # duplicates based on the loose optimization, to reduce the time needed for
    # tighter, more stricter optimization
    if not (ffconf.PreOptimizeEnsemble(omol) == OEFreeFormReturnCode_Success):
        OEThrow.Error("Pre-optimization of the ensembles failed")

    # Remove duplicates from the pre-optimized ensemble
    if not (ffconf.RemoveDuplicates(omol) == OEFreeFormReturnCode_Success):
        OEThrow.Error("Duplicate removal from the ensembles failed")

    # Perform the desired optimization.  This uses a stricter convergence
    # criteria in the default settings.
    if not (ffconf.Optimize(omol) == OEFreeFormReturnCode_Success):
        OEThrow.Error("Optimization of the ensembles failed")

    # Remove duplicates to obtain the set of minimum energy conformers
    if not (ffconf.RemoveDuplicates(omol) == OEFreeFormReturnCode_Success):
        OEThrow.Error("Duplicate removal from the ensembles failed")

    # Perform FreeFormConf free energy calculations.  When all the above steps
    # have already been performed on the ensemble, this energy calculation
    # step is fast.
    if not (ffconf.EstimateEnergies(omol) == OEFreeFormReturnCode_Success):
        OEThrow.Error("Estimation of FreeFormConf energies failed")

    # Gather results of calculation into a results object for ease of viewing, etc.
    res = OEFreeFormConfResults(omol)
    OEThrow.Info("Number of unique conformations: %d" % res.GetNumUniqueConfs())
    OEThrow.Info("Conf.  Delta_G   Vibrational_Entropy")
    OEThrow.Info("      [kcal/mol]     [J/(mol K)]")
    for r in res.GetResultsForConformations():
        OEThrow.Info("%2d %10.2f %14.2f" % (r.GetConfIdx(), r.GetDeltaG(), 
                                            r.GetVibrationalEntropy()))

    # Identify the corresponding conformer(s) to the free minimized conformer(s).
    # If identified, the corresponding (Conf)Free energy information is also
    # copied to the free conformers
    if not (ffconf.IdentifyConformer(fmol, omol) == OEFreeFormReturnCode_Success):
        OEThrow.Error("Identifican of free conformer(s) failed")

    # Estimate restriction energies. Since both restricted and free conformer
    # energy components are already available, this operation is fast.
    if not (ffconf.EstimateRestrictionEnergy(fmol, rmol) == OEFreeFormReturnCode_Success):
        OEThrow.Error("Restriction energy estimation failed")

    # Gather restriction energies into a results object for ease of viewing, etc.
    rstrRes = OERestrictionEnergyResult(fmol)
    OEThrow.Info("Global strain: %d" % rstrRes.GetGlobalStrain())
    OEThrow.Info("Local strain: %d" % rstrRes.GetLocalStrain())

    # Optionally it is desired to perform a restrained optimization of the
    # restricted conformer(s) to brush out any energy differences due to
    # force field constaints or the sources of coonformer coordinates.  Note: The
    # high level EstimateFreeEnergy method does not perform this opertion.
    if not (ffconf.OptimizeRestraint(rmol) == OEFreeFormReturnCode_Success):
        OEThrow.Error("Restraint optimization of the conformer(s) failed")

    # Estimate restriction energies on this optimized conformers. Since both restricted and free conformer
    # energy components are already available, this operation is fast.
    if not (ffconf.EstimateRestrictionEnergy(fmol, rmol) == OEFreeFormReturnCode_Success):
        OEThrow.Error("Restriction energy estimation failed")

    # Gather restriction energies into a results object for ease of viewing, etc.
    rstrRes = OERestrictionEnergyResult(fmol)
    OEThrow.Info("Global strain: %d" % rstrRes.GetGlobalStrain())
    OEThrow.Info("Local strain: %d" % rstrRes.GetLocalStrain())

    OEWriteMolecule(ofs, omol)

    return 0

if __name__ == "__main__":
    sys.exit(main(sys.argv))

Finding similar conformers

The following code illustrates how to find similar conformers to the ones at hand, from a pool of minimum energy conformers.

#!/usr/bin/env python
#############################################################################
# Copyright (C) 2017 OpenEye Scientific Software, Inc.
#############################################################################
import sys

from openeye.oechem import *
from openeye.oeszybki import *

def main(args):
    if len(args) != 3:
        OEThrow.Usage("%s <input> <output>" % args[0])

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

    ofs = oemolostream()
    if not ofs.open(args[2]):
        OEThrow.Fatal("Unable to open %s for writing" % args[2])
                
    mol = OEMol()
    OEReadMolecule(ifs, mol)

    opts = OEFreeFormConfOptions()
    ffconf = OEFreeFormConf(opts)

    # Estimate free energies to ontain the minimum energy conformers
    omol = OEMol(mol)
    if not (ffconf.EstimateFreeEnergies(omol) == OEFreeFormReturnCode_Success):
        OEThrow.Error("Failed to estimate conformational free energies")

    # Find similar conformers to the ones we started with, from the
    # pool of minimum energy conformers
    fmol = OEMol(mol)
    for conf in mol.GetConfs():
        ffconf.FindSimilarConfs(fmol, omol, conf, OESimilarByRMSD(0.05));

    OEWriteMolecule(ofs, fmol)

    return 0

if __name__ == "__main__":
    sys.exit(main(sys.argv))