Examples: 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 compound properties, such as solvation free energy or free energy of selecting specific conformations out of the ensemble, the higher level API are 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. Optimization is done using the default MMFF94. Final energy results are available as SD tags in the returned molecule and optionally with a call of a method OESzybkiResults.Print.

Listing 1: Simple Ligand in a Vacuum

/* 
(C) 2022 Cadence Design Systems, Inc. (Cadence) 
All rights reserved.
TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
provided to current licensees or subscribers of Cadence products or
SaaS offerings (each a "Customer").
Customer is hereby permitted to use, copy, and modify the Sample Code,
subject to these terms. Cadence claims no rights to Customer's
modifications. Modification of Sample Code is at Customer's sole and
exclusive risk. Sample Code may require Customer to have a then
current license or subscription to the applicable Cadence offering.
THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
liable for any damages or liability in connection with the Sample Code
or its use.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OESzybki;
using OpenEye.OEQuacPac;

public class SimpleVacuum
{
    public static int Main(String[] args)
    {
        if (args.Length!=2)
        {
            OEChem.OEThrow.Usage("SimpleVacuum <molfile> <outfile>");
        }

        oemolistream ifs = new oemolistream();
        oemolostream ofs = new oemolostream();

        if (!ifs.open(args[0]))
        {
            OEChem.OEThrow.Fatal("Unable to open " + args[0] + " for reading");
        }
        if (!ofs.open(args[1]))
        {
            OEChem.OEThrow.Fatal("Unable to open " + args[1] + " for writing");
        }

        OEMol mol = new OEMol();
        OEChem.OEReadMolecule(ifs, mol);

        OESzybkiOptions opts = new OESzybkiOptions();
        OESzybki sz = new OESzybki(opts);
        OESzybkiResults res = new OESzybkiResults();

        if (!sz.Call(mol, res))
        {
            return 1;
        }

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

        return 0;
    }
}

Download code

SimpleVacuum.cs

Single ligand in vacuum using SMIRNOFF

The following example illustrates how to optimize a single ligand in vacuum using SMIRNOFF (see SMIRNOFF). 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(). Partial charges have to be preassigned to the input molecule. 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.

Listing 2: Simple Ligand in a Vacuum Using SMIRNOFF

/* 
(C) 2022 Cadence Design Systems, Inc. (Cadence) 
All rights reserved.
TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
provided to current licensees or subscribers of Cadence products or
SaaS offerings (each a "Customer").
Customer is hereby permitted to use, copy, and modify the Sample Code,
subject to these terms. Cadence claims no rights to Customer's
modifications. Modification of Sample Code is at Customer's sole and
exclusive risk. Sample Code may require Customer to have a then
current license or subscription to the applicable Cadence offering.
THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
liable for any damages or liability in connection with the Sample Code
or its use.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OESzybki;
using OpenEye.OEQuacPac;

public class SimpleSmirnoff
{
    public static int Main(String[] args)
    {
        if (args.Length!=2)
        {
            OEChem.OEThrow.Usage("SimpleSmirnoff <molfile> <outfile>");
        }

        oemolistream ifs = new oemolistream();
        oemolostream ofs = new oemolostream();

        if (!ifs.open(args[0]))
        {
            OEChem.OEThrow.Fatal("Unable to open " + args[0] + " for reading");
        }
        if (!ofs.open(args[1]))
        {
            OEChem.OEThrow.Fatal("Unable to open " + args[1] + " for writing");
        }

        OEMol mol = new OEMol();
        OEChem.OEReadMolecule(ifs, mol);

        OESzybkiOptions opts = new OESzybkiOptions();

        // Selection of SMIRNOFF force field
        opts.GetGeneralOptions().SetForceFieldType(OEForceFieldType.SMIRNOFF99FROSST);

        OESzybki sz = new OESzybki(opts);
        OESzybkiResults res = new OESzybkiResults();

        if (!sz.Call(mol, res))
        {
            return 1;
        }

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

        return 0;
    }
}

Download code

SimpleSmirnoff.cs

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.

Listing 3: Optimization of a Set of Ligands

/* 
(C) 2022 Cadence Design Systems, Inc. (Cadence) 
All rights reserved.
TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
provided to current licensees or subscribers of Cadence products or
SaaS offerings (each a "Customer").
Customer is hereby permitted to use, copy, and modify the Sample Code,
subject to these terms. Cadence claims no rights to Customer's
modifications. Modification of Sample Code is at Customer's sole and
exclusive risk. Sample Code may require Customer to have a then
current license or subscription to the applicable Cadence offering.
THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
liable for any damages or liability in connection with the Sample Code
or its use.
*/
using OpenEye.OEChem;
using OpenEye.OESzybki;
using OpenEye.OEQuacPac;

public class LigandMultipleOptions
{
    public static void Main(string[] args)
    {
        OEInterface itf = new OEInterface();
        if (!SetupInterface("LigandMultipleOptions", itf, args))
            return;

        oemolistream ifs = new oemolistream();
        if (!ifs.open(itf.GetString("-in")))
            OEChem.OEThrow.Fatal("Unable to open " + itf.GetString("-in") + " for reading");

        oemolostream ofs = new oemolostream();
        if (!ofs.open(itf.GetString("-out")))
            OEChem.OEThrow.Fatal("Unable to open " + itf.GetString("-out") + " for writing");

        oeostream logfile = OEChem.oeout;
        if (itf.HasString("-log")) {
            if (!logfile.open(itf.GetString("-log")))
                OEChem.OEThrow.Fatal("Unable to open " + itf.GetString("-log") + " for writing");
        }

        // Szybki options
        OESzybkiOptions opts = new 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;
        OESzybki sz = new OESzybki(opts);

        // fix atoms
        if (itf.HasString("-f"))
            if (!sz.FixAtoms(itf.GetString("-f")))
                OEChem.OEThrow.Warning("Failed to fix atoms for " + itf.GetString("-f"));

        // process molecules
        OEMol mol = new OEMol();
        while (OEChem.OEReadMolecule(ifs, mol)) {
            logfile.write("\nMolecule " + mol.GetTitle() + "\n");
            bool no_res = true;
            foreach (OESzybkiResults results in sz.Call(mol)) {
                results.Print(logfile);
                no_res = false;
            }

            if (no_res) {
                OEChem.OEThrow.Warning("No results processing molecule: " + mol.GetTitle());
                continue;
            }
            OEChem.OEWriteMolecule(ofs, mol);
        }
    }

    private static bool SetupInterface(string progName, OEInterface itf, string[] args)
    {
        OEChem.OEConfigure(itf, interfaceData);
        if (OEChem.OECheckHelp(itf, args, progName, false))
            return false;
        if (!OEChem.OEParseCommandLine(itf, args, progName))
            return false;
        if (!OEChem.OEIsReadable(OEChem.OEGetFileType(OEChem.OEGetFileExtension(itf.GetString("-in"))))) {
            OEChem.OEThrow.Warning(itf.GetString("-in") + " is not a readable input file");
            return false;
        }
        if (!OEChem.OEIsWriteable(OEChem.OEGetFileType(OEChem.OEGetFileExtension(itf.GetString("-out"))))) {
            OEChem.OEThrow.Warning(itf.GetString("-out") + " is not a writable output file");
            return false;
        }
        return true;
    }

    private static string 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
";
}

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:

Listing 4: Optimization of a Single Ligand with the Newton-Raphson Method

/* 
(C) 2022 Cadence Design Systems, Inc. (Cadence) 
All rights reserved.
TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
provided to current licensees or subscribers of Cadence products or
SaaS offerings (each a "Customer").
Customer is hereby permitted to use, copy, and modify the Sample Code,
subject to these terms. Cadence claims no rights to Customer's
modifications. Modification of Sample Code is at Customer's sole and
exclusive risk. Sample Code may require Customer to have a then
current license or subscription to the applicable Cadence offering.
THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
liable for any damages or liability in connection with the Sample Code
or its use.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OESzybki;
using OpenEye.OEQuacPac;

public class SimpleNewton
{
    public static void Main(string[] args)
    {
        if (args.Length != 2)
            OEChem.OEThrow.Usage("SimpleNewton input_molecule output_molecule");

        string inputFile  = args[0];
        string outputFile = args[1];

        oemolistream ifs = new oemolistream();
        if (!ifs.open(inputFile))
            OEChem.OEThrow.Fatal("Unable to open " + inputFile + " for reading");

        oemolostream ofs = new oemolostream();
        if (!ofs.open(outputFile))
            OEChem.OEThrow.Fatal("Unable to open " + outputFile + " for writing");

        OEMol mol = new OEMol();
        OEChem.OEReadMolecule(ifs, mol);
        ifs.close();

        OESzybkiOptions opts = new OESzybkiOptions();
        opts.GetOptOptions().SetOptimizerType(OEOptType.NEWTON);
        opts.GetSolventOptions().SetSolventModel(OESolventModel.Sheffield);

        OESzybki sz = new OESzybki(opts);
        OESzybkiResults res = new OESzybkiResults();
        if (sz.Call(mol, res)) {
            OEChem.OEWriteMolecule(ofs, mol);
            res.Print(OEChem.oeout);
        }
        ofs.close();
    }
}

Download code

SimpleNewton.cs

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.

Listing 5: Optimization of All Conformers of a Ligand

/* 
(C) 2022 Cadence Design Systems, Inc. (Cadence) 
All rights reserved.
TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
provided to current licensees or subscribers of Cadence products or
SaaS offerings (each a "Customer").
Customer is hereby permitted to use, copy, and modify the Sample Code,
subject to these terms. Cadence claims no rights to Customer's
modifications. Modification of Sample Code is at Customer's sole and
exclusive risk. Sample Code may require Customer to have a then
current license or subscription to the applicable Cadence offering.
THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
liable for any damages or liability in connection with the Sample Code
or its use.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OEQuacPac;
using OpenEye.OESzybki;

public class SimpleConformer
{
    public static void Main(string[] args)
    {
        if (args.Length != 2)
            OEChem.OEThrow.Usage("SimpleConformer input_molecule output_molecule");

        string inputFile  = args[0];
        string outputFile = args[1];

        oemolistream ifs = new oemolistream();
        if (!ifs.open(inputFile))
            OEChem.OEThrow.Fatal("Unable to open " + inputFile + " for reading");

        oemolostream ofs = new oemolostream();
        if (!ofs.open(outputFile))
            OEChem.OEThrow.Fatal("Unable to open " + outputFile + " for writing");

        OESzybkiOptions opts = new OESzybkiOptions();
        opts.GetOptOptions().SetOptimizerType(OEOptType.NEWTON);
        opts.GetSolventOptions().SetSolventModel(OESolventModel.Sheffield);
        opts.GetGeneralOptions().SetForceFieldType(OEForceFieldType.MMFF94S);
        OEChargeEngineNoOp chargeEngine = new OEChargeEngineNoOp();
        opts.GetSolventOptions().SetChargeEngine(chargeEngine);

        OESzybki sz = new OESzybki(opts);
        OESzybkiResults res = new OESzybkiResults();
        OEMol mol = new OEMol();
        while(OEChem.OEReadMolecule(ifs, mol))
        {
            foreach(OEConfBase conf in mol.GetConfs())
            {
                if (sz.Call(conf, res))
                {
                    OEChem.OESetSDData(conf, new OESDDataPair("Total_energy",
                        res.GetTotalEnergy().ToString("0.0000")));
                }
            }
            OEChem.OEWriteMolecule(ofs, mol);
        }

        ifs.close();
        ofs.close();
    }
}

Download code

SimpleConformer.cs

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.

Listing 5: Optimization of a Single Bound Ligand

/* 
(C) 2022 Cadence Design Systems, Inc. (Cadence) 
All rights reserved.
TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
provided to current licensees or subscribers of Cadence products or
SaaS offerings (each a "Customer").
Customer is hereby permitted to use, copy, and modify the Sample Code,
subject to these terms. Cadence claims no rights to Customer's
modifications. Modification of Sample Code is at Customer's sole and
exclusive risk. Sample Code may require Customer to have a then
current license or subscription to the applicable Cadence offering.
THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
liable for any damages or liability in connection with the Sample Code
or its use.
*/
using OpenEye.OEChem;
using OpenEye.OESzybki;
using OpenEye.OEQuacPac;

public class SimpleProtein
{
    public static void Main(string[] args)
    {
        if (args.Length != 3)
            OEChem.OEThrow.Usage("SimpleProtein <molfile> <protein> <outfile>");

        string inputLFile = args[0];
        string inputPFile = args[1];
        string outputFile = args[2];

        oemolistream lfs = new oemolistream();
        if (!lfs.open(inputLFile))
            OEChem.OEThrow.Fatal("Unable to open " + inputLFile + " for reading");

        oemolistream pfs = new oemolistream();
        if (!pfs.open(inputPFile))
            OEChem.OEThrow.Fatal("Unable to open " + inputPFile + " for reading");

        oemolostream ofs = new oemolostream();
        if (!ofs.open(outputFile))
            OEChem.OEThrow.Fatal("Unable to open " + outputFile + " for writing");

        OEGraphMol mol = new OEGraphMol();
        OEChem.OEReadMolecule(lfs, mol);
        lfs.close();

        OEGraphMol protein = new OEGraphMol();
        OEChem.OEReadMolecule(pfs, protein);
        pfs.close();

        OESzybkiOptions opts = new OESzybkiOptions();
        OESzybki sz = new OESzybki(opts);
        sz.SetProtein(protein);
        OESzybkiResults res = new OESzybkiResults();
        if (sz.Call(mol, res))
        {
            OEChem.OEWriteMolecule(ofs, mol);
            res.Print(OEChem.oeout);
        }
        ofs.close();
    }
}

Download code

SimpleProtein.cs

Protein-Ligand Energetics and Optimization

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

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.

Listing 6: Optimization of a Set of Bound Ligands in a Rigid Receptor

/* 
(C) 2022 Cadence Design Systems, Inc. (Cadence) 
All rights reserved.
TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
provided to current licensees or subscribers of Cadence products or
SaaS offerings (each a "Customer").
Customer is hereby permitted to use, copy, and modify the Sample Code,
subject to these terms. Cadence claims no rights to Customer's
modifications. Modification of Sample Code is at Customer's sole and
exclusive risk. Sample Code may require Customer to have a then
current license or subscription to the applicable Cadence offering.
THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
liable for any damages or liability in connection with the Sample Code
or its use.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OESzybki;
using OpenEye.OEQuacPac;

public class ProteinMultipleOptions
{
    public static void Main(string[] args)
    {
        OEInterface itf = new OEInterface(interfaceData, "ProteinMultipleOptions", args);

        oemolistream lfs = new oemolistream();
        if (!lfs.open(itf.GetString("-in")))
            OEChem.OEThrow.Fatal("Unable to open " + itf.GetString("-in") + " for reading");

        oemolistream pfs = new oemolistream();
        if (!pfs.open(itf.GetString("-p")))
            OEChem.OEThrow.Fatal("Unable to open " + itf.GetString("-p") + " for reading");

        oemolostream ofs = new oemolostream();
        if (!ofs.open(itf.GetString("-out")))
            OEChem.OEThrow.Fatal("Unable to open " + itf.GetString("-out") + " for writing");

        oeostream logfile = OEChem.oeout;
        if (itf.HasString("-log")) {
            if (!logfile.open(itf.GetString("-log")))
                OEChem.OEThrow.Fatal("Unable to open " + itf.GetString("-log") + " for writing");
        }

        // Szybki options
        OESzybkiOptions opts = new OESzybkiOptions();

        // select optimization type
        if (itf.GetBool("-t"))
            opts.SetRunType(OERunType.TorsionsOpt);
        else
            opts.SetRunType(OERunType.CartesiansOpt);

        // select protein-electrostatic model
        string emodel = itf.GetString("-e");
        uint elecModel = OEProteinElectrostatics.NoElectrostatics;
        if (emodel.Equals("VdW"))
            elecModel = OEProteinElectrostatics.NoElectrostatics;
        else if (emodel.Equals("PB"))
            elecModel = OEProteinElectrostatics.GridPB;
        else if (emodel.Equals("Coulomb"))
            elecModel = OEProteinElectrostatics.GridCoulomb;
        else if (emodel.Equals("ExactCoulomb"))
            elecModel = OEProteinElectrostatics.ExactCoulomb;
        opts.GetProteinOptions().SetProteinElectrostaticModel(elecModel);

        opts.GetProteinOptions().SetExactVdWProteinLigand(true);
        opts.GetOptOptions().SetMaxIter(1000);
        opts.GetOptOptions().SetGradTolerance(1e-6);

        // Szybki object
        OESzybki sz = new OESzybki(opts);

        // read and setup protein
        OEGraphMol protein = new OEGraphMol();
        OEChem.OEReadMolecule(pfs, protein);
        sz.SetProtein(protein);

        // save or load grid potential
        if (emodel.Equals("PB") || emodel.Equals("Coulomb")) {
            if(itf.HasString("-s"))
                sz.SavePotentialGrid(itf.GetString("-s"));
            if(itf.HasString("-l"))
                sz.LoadPotentialGrid(itf.GetString("-l"));
        }

        // process molecules
        foreach (OEMol mol in lfs.GetOEMols()) {
            logfile.write("\nMolecule " + mol.GetTitle() + "\n");
            bool no_res = true;
            foreach (OESzybkiResults res in sz.Call(mol)) {
                res.Print(logfile);
                no_res = false;
            }

            if (no_res) {
                OEChem.OEThrow.Warning("No results processing molecule: " + mol.GetTitle());
                continue;
            }

            OEChem.OEWriteMolecule(ofs, mol);
        }
    }

    private static string interfaceData = @"
!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
";

}

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.

Listing 7: Optimization of a Set of Bound Ligands in a Partially Flexible Receptor

/* 
(C) 2022 Cadence Design Systems, Inc. (Cadence) 
All rights reserved.
TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
provided to current licensees or subscribers of Cadence products or
SaaS offerings (each a "Customer").
Customer is hereby permitted to use, copy, and modify the Sample Code,
subject to these terms. Cadence claims no rights to Customer's
modifications. Modification of Sample Code is at Customer's sole and
exclusive risk. Sample Code may require Customer to have a then
current license or subscription to the applicable Cadence offering.
THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
liable for any damages or liability in connection with the Sample Code
or its use.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OESzybki;
using OpenEye.OEQuacPac;

public class FlexibleProtein
{
    public static void Main(string[] args)
    {
        OEInterface itf = new OEInterface(interfaceData, "FlexibleProtein", args);

        oemolistream lfs = new oemolistream();
        if (!lfs.open(itf.GetString("-in")))
          OEChem.OEThrow.Fatal("Unable to open " + itf.GetString("-in") + " for reading");

        oemolistream pfs = new oemolistream();
        if (!pfs.open(itf.GetString("-p")))
            OEChem.OEThrow.Fatal("Unable to open " + itf.GetString("-p") + " for reading");

        oemolostream olfs = new oemolostream();
        if (!olfs.open(itf.GetString("-out")))
            OEChem.OEThrow.Fatal("Unable to open " + itf.GetString("-out") + " for writing");

        oemolostream opfs = new oemolostream();
        if (itf.HasString("-s")) {
            if (!opfs.open(itf.GetString("-s")))
                OEChem.OEThrow.Fatal("Unable to open " + itf.GetString("-s") + " for writing");
        }

        oeostream logfile = OEChem.oeout;
        if (itf.HasString("-log")) {
            if (!logfile.open(itf.GetString("-log")))
              OEChem.OEThrow.Fatal("Unable to open " + itf.GetString("-log") + " for writing");
        }

        // Szybki options
        OESzybkiOptions opts = new OESzybkiOptions();

        // select optimization type
        string opt = itf.GetString("-opt");
        if (opt.Equals("Cartesian"))
            opts.SetRunType(OERunType.CartesiansOpt);
        else if (opt.Equals("Torsion"))
            opts.SetRunType(OERunType.TorsionsOpt);
        else if (opt.Equals("SolidBody"))
            opts.SetRunType(OERunType.SolidBodyOpt);

        // select protein-electrostatic model
        string emodel = itf.GetString("-e");
        uint elecModel = OEProteinElectrostatics.NoElectrostatics;
        if (emodel.Equals("VdW"))
            elecModel = OEProteinElectrostatics.NoElectrostatics;
        else if (emodel.Equals("PB"))
            elecModel = OEProteinElectrostatics.GridPB;
        else if (emodel.Equals("Coulomb"))
            elecModel = OEProteinElectrostatics.GridCoulomb;
        else if (emodel.Equals("ExactCoulomb"))
            elecModel = OEProteinElectrostatics.ExactCoulomb;
        opts.GetProteinOptions().SetProteinElectrostaticModel(elecModel);

        // use smooth potential and tight convergence
        if (emodel.Equals("VdW") || emodel.Equals("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
        OESzybki sz = new OESzybki(opts);

        // read and setup protein
        OEGraphMol protein = new OEGraphMol();
        OEGraphMol oprotein = new OEGraphMol();  // optimized protein
        OEChem.OEReadMolecule(pfs, protein);
        sz.SetProtein(protein);
        pfs.close();

        // process molecules
        foreach (OEMol mol in lfs.GetOEMols()) {
            logfile.write("\nMolecule " + mol.GetTitle() + "\n");
            foreach (OESzybkiResults res in sz.Call(mol))
                res.Print(logfile);

            OEChem.OEWriteMolecule(olfs, mol);
            if (itf.HasString("-s")) {
                sz.GetProtein(oprotein);
                OEChem.OEWriteMolecule(opfs, oprotein);
            }
        }
        opfs.close();
    }

    private static string interfaceData = @"
!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
";
}

Download code

FlexibleProtein.cs

Optimization of a bound ligand in a partially flexible receptor

The next example is very similar with respect to the previous one, but the list of residue numbers of the protein that are made flexible during optimization is specified by the -residues flag (see method OESzybkiProteinOptions.AddFlexibleResidue). Partially optimized ligand and protein structures are saved to files specified by the -outl and -outp flags, respectively.

Listing 8: Optimization of a Bound Ligand in a Partially Flexible Feceptor

/* 
(C) 2022 Cadence Design Systems, Inc. (Cadence) 
All rights reserved.
TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
provided to current licensees or subscribers of Cadence products or
SaaS offerings (each a "Customer").
Customer is hereby permitted to use, copy, and modify the Sample Code,
subject to these terms. Cadence claims no rights to Customer's
modifications. Modification of Sample Code is at Customer's sole and
exclusive risk. Sample Code may require Customer to have a then
current license or subscription to the applicable Cadence offering.
THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
liable for any damages or liability in connection with the Sample Code
or its use.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OESzybki;
using OpenEye.OEQuacPac;

public class FlexResidues
{
    public static void Main(string[] args)
    {
        OEInterface itf = new OEInterface(interfaceData, "FlexResidues", args);

        oemolistream ifs = new oemolistream();
        if (!ifs.open(itf.GetString("-in")))
          OEChem.OEThrow.Fatal("Unable to open " + itf.GetString("-in") + " for reading");

        oemolistream pfs = new oemolistream();
        if (!pfs.open(itf.GetString("-protein")))
            OEChem.OEThrow.Fatal("Unable to open " + itf.GetString("-protein") + " for reading");

        oemolostream olfs = new oemolostream();
        if (!olfs.open(itf.GetString("-outl")))
            OEChem.OEThrow.Fatal("Unable to open " + itf.GetString("-outl") + " for writing");

        oemolostream opfs = new oemolostream();
        if (!opfs.open(itf.GetString("-outp")))
            OEChem.OEThrow.Fatal("Unable to open " + itf.GetString("-outp") + " for writing");

        OEGraphMol protein = new OEGraphMol();
        OEGraphMol ligand = new OEGraphMol();
        OEChem.OEReadMolecule(pfs, protein);
        OEChem.OEReadMolecule(ifs, ligand);
        pfs.close();
        ifs.close();

        // Szybki options
        OESzybkiOptions opts = new OESzybkiOptions();
        opts.GetGeneralOptions().SetForceFieldType(OEForceFieldType.MMFF94S);
        opts.GetProteinOptions().SetProteinElectrostaticModel(OEProteinElectrostatics.ExactCoulomb);
        opts.GetProteinOptions().SetProteinFlexibilityType(OEProtFlex.SideChainsList);
        opts.SetRunType(OERunType.CartesiansOpt);
        opts.GetOptOptions().SetMaxIter(2000);
        opts.GetOptOptions().SetGradTolerance(1.0e-6);

        OEStringIter res_num = itf.GetStringList("-residues");
        res_num.ToFirst();
        foreach (string rn in res_num) {
            foreach (OEAtomBase atom in protein.GetAtoms()) {
                OEResidue res = OEChem.OEAtomGetResidue(atom);
                if(res.GetResidueNumber().ToString().Equals(rn)) {
                    opts.AddFlexibleResidue(res);
                    break;
                }
            }
        }

        //optimization
        OESzybki sz = new OESzybki(opts);
        sz.SetProtein(protein);
        OESzybkiResults result = new OESzybkiResults();
        sz.Call(ligand, result);

        OEChem.OEWriteMolecule(olfs, ligand);
        sz.GetProtein(protein);
        OEChem.OEWriteMolecule(opfs, protein);

        olfs.close();
        opfs.close();
    }

    private static string interfaceData = @"
!PARAMETER -in
!TYPE string
!REQUIRED true
!BRIEF Input molecule file name.
!END

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

!PARAMETER -outl
!TYPE string
!REQUIRED true
!BRIEF Output ligand file name.
!END

!PARAMETER -outp
!TYPE string
!REQUIRED true
!BRIEF Output protein file name.
!END

!PARAMETER -residues
!TYPE int
!LIST true
!REQUIRED true
!BRIEF List of residues numbers to be optimized along with the ligand
!END
";
}

Download code

FlexResidues.cs

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.

Listing 9: Estimation of PB Binding for a Set of Ligands

/* 
(C) 2022 Cadence Design Systems, Inc. (Cadence) 
All rights reserved.
TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
provided to current licensees or subscribers of Cadence products or
SaaS offerings (each a "Customer").
Customer is hereby permitted to use, copy, and modify the Sample Code,
subject to these terms. Cadence claims no rights to Customer's
modifications. Modification of Sample Code is at Customer's sole and
exclusive risk. Sample Code may require Customer to have a then
current license or subscription to the applicable Cadence offering.
THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
liable for any damages or liability in connection with the Sample Code
or its use.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OESzybki;
using OpenEye.OEQuacPac;

public class ProteinLigandPB
{
    public static void Main(string[] args)
    {
        if (args.Length != 3)
            OEChem.OEThrow.Usage("ProteinLigandPB ligand_file protein_file output_file (SDF or OEB)");

        string ligandFile  = args[0];
        string proteinFile = args[1];
        string outputFile  = args[2];

        oemolistream ligfs = new oemolistream();
        if (!ligfs.open(ligandFile))
            OEChem.OEThrow.Fatal("Unable to open " + ligandFile + " for reading");

        oemolistream prtfs = new oemolistream();
        if (!prtfs.open(proteinFile))
            OEChem.OEThrow.Fatal("Unable to open " + proteinFile + " for reading");

        oemolostream outfs = new oemolostream();
        if (!outfs.open(outputFile))
            OEChem.OEThrow.Fatal("Unable to open " + outputFile + " for writing");

        if (!OEChem.OEIsSDDataFormat(outfs.GetFormat()))
            OEChem.OEThrow.Fatal("Output file does not support SD data used by this example");

        // Szybki options for VdW-Coulomb calculations
        OESzybkiOptions optsC = new OESzybkiOptions();
        optsC.GetProteinOptions().SetProteinElectrostaticModel(OEProteinElectrostatics.ExactCoulomb);
        optsC.SetRunType(OERunType.CartesiansOpt);

        // Szybki options for PB calculations
        OESzybkiOptions optsPB = new OESzybkiOptions();
        optsPB.GetProteinOptions().SetProteinElectrostaticModel(OEProteinElectrostatics.SolventPBForces);
        optsPB.SetRunType(OERunType.SinglePoint);

        // Szybki objects
        OESzybki szC = new OESzybki(optsC);
        OESzybki szPB = new OESzybki(optsPB);

        // read and setup protein
        OEGraphMol protein = new OEGraphMol();
        OEChem.OEReadMolecule(prtfs, protein);
        prtfs.close();
        szC.SetProtein(protein);
        szPB.SetProtein(protein);

        // process molecules
        OEMol mol = new OEMol();
        while(OEChem.OEReadMolecule(ligfs, mol)) {

            OESzybkiResultsIter results = szC.Call(mol); // optimize mol
            if (!results.IsValid()) {
                OEChem.OEThrow.Warning("No results processing molecule: " + mol.GetTitle());
                continue;
            }

            results = szPB.Call(mol);
            OEConfBaseIter conf = mol.GetConfs();
            if (results.IsValid()) {
                foreach (OESzybkiResults res in results) {
                    if (!conf.IsValid())
                        continue;

                    for (uint i = 0; i < OEPotentialTerms.Max; ++i) {
                        if (i == OEPotentialTerms.ProteinLigandInteraction || i == OEPotentialTerms.VdWProteinLigand ||
                            i == OEPotentialTerms.CoulombProteinLigand     || i == OEPotentialTerms.ProteinDesolvation ||
                            i == OEPotentialTerms.LigandDesolvation        || i == OEPotentialTerms.SolventScreening) {
                           String energy = String.Format("{0,9:F4}", res.GetEnergyTerm(i));
                           OEChem.OEAddSDData(conf.Target(), OESzybkilib.OEGetEnergyTermName(i), energy);
                        }
                    }
                    conf.Increment();
                }
            }
            OEChem.OEWriteMolecule(outfs, mol);
        }
        ligfs.close();
        outfs.close();
    }
}

Download code

ProteinLigandPB.cs

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.

Listing 10: Optimization of a Bound Ligand Using Newton-Raphson Method

/* 
(C) 2022 Cadence Design Systems, Inc. (Cadence) 
All rights reserved.
TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
provided to current licensees or subscribers of Cadence products or
SaaS offerings (each a "Customer").
Customer is hereby permitted to use, copy, and modify the Sample Code,
subject to these terms. Cadence claims no rights to Customer's
modifications. Modification of Sample Code is at Customer's sole and
exclusive risk. Sample Code may require Customer to have a then
current license or subscription to the applicable Cadence offering.
THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
liable for any damages or liability in connection with the Sample Code
or its use.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OESzybki;
using OpenEye.OEQuacPac;

public class LigandFlexProteinNewton
{
    public static void Main(string[] args)
    {
        if (args.Length != 3)
            OEChem.OEThrow.Usage("LigandFlexProteinNewton protein input_ligand output_ligand");

        string proteinFile = args[0];
        string ligandFile  = args[1];
        string outligandFile = args[2];

        oemolistream pfs = new oemolistream();
        if (!pfs.open(proteinFile))
            OEChem.OEThrow.Fatal("Unable to open " + proteinFile + " for reading");

        oemolistream lfs = new oemolistream();
        if (!lfs.open(ligandFile))
            OEChem.OEThrow.Fatal("Unable to open " + ligandFile + " for reading");

        oemolostream ofs = new oemolostream();
        if (!ofs.open(outligandFile))
            OEChem.OEThrow.Fatal("Unable to open " + outligandFile + " for writing");

        OEGraphMol mol = new OEGraphMol();
        OEGraphMol protein = new OEGraphMol();
        OEChem.OEReadMolecule(lfs, mol);
        lfs.close();
        OEChem.OEReadMolecule(pfs, protein);
        pfs.close();

        OESzybkiOptions opts = new OESzybkiOptions();
        opts.GetOptOptions().SetOptimizerType(OEOptType.NEWTON);
        opts.GetProteinOptions().SetProteinElectrostaticModel(OEProteinElectrostatics.ExactCoulomb);
        opts.GetProteinOptions().SetProteinFlexibilityType(OEProtFlex.Residues);
        opts.GetProteinOptions().SetProteinFlexibilityRange(2.0f);

        OESzybki sz = new OESzybki(opts);
        sz.SetProtein(protein);

        OESzybkiResults res = new OESzybkiResults();
        if (sz.Call(mol, res)) {
            OEChem.OEWriteMolecule(ofs, mol);
            res.Print(OEChem.oeout);
        }
        ofs.close();
    }
}

DU Protein-Ligand Optimization with FF14SB-Parsley

Examples in this section show how to optimize a ligand in the protein active site using the OEFixedProteinLigandOptimizer and the OEFlexProteinLigandOptimizer classes. Both of these classes allow use of the FF14SB-Parsley forcefield, along with the MMFF and the MMFF-AMBER forcefields. These examples also demonstrate how to use design units as a source for the protein or the ligand. The first example optimizes an external ligand in a protein active site from a design unit, and the second example uses both the ligand and the protein from the same design unit.

Optimization of ligand in a rigid active site

This examples shows how to optimize a series of ligands in a rigid active site. The active site input is taken from a OEDesignUnit.

Optimization of ligand in a partially flexible active site

This examples shows how to optimize a ligand in a partially flexible active site. In this example, both the ligand and the active site is taken from a single OEDesignUnit.

Entropy estimation

Estimation of solution ligand entropy

The following code illustrates how to estimate compound entropy in solution with Szybki TK.

Listing 13: Ligand Entropy

/* 
(C) 2022 Cadence Design Systems, Inc. (Cadence) 
All rights reserved.
TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
provided to current licensees or subscribers of Cadence products or
SaaS offerings (each a "Customer").
Customer is hereby permitted to use, copy, and modify the Sample Code,
subject to these terms. Cadence claims no rights to Customer's
modifications. Modification of Sample Code is at Customer's sole and
exclusive risk. Sample Code may require Customer to have a then
current license or subscription to the applicable Cadence offering.
THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
liable for any damages or liability in connection with the Sample Code
or its use.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OESzybki;
using OpenEye.OEQuacPac;

public class LigandEntropy
{
    public static void Main(string[] args)
    {
        OELigandEntropyOptions szOpts = new OELigandEntropyOptions();
        OESimpleAppOptions opts = new OESimpleAppOptions(szOpts, "LigandEntropy", OEFileStringType.Mol3D);
        if(OEChem.OEConfigureOpts(opts, args, false) == OEOptsConfigureStatus.Help)
            Environment.Exit(1);
        szOpts.UpdateValues(opts);

        oemolistream ifs = new oemolistream();
        if(!ifs.open(opts.GetInFile()))
            OEChem.OEThrow.Fatal("Unable to open " + opts.GetInFile() + " for reading");

        OEMol mol = new OEMol();
        while (OEChem.OEReadMolecule(ifs, mol)) 
        {
            OEChem.OEThrow.Info("Title: " + mol.GetTitle());
            OEEntropyResults res = new OEEntropyResults();
            uint ret_code = OESzybkilib.OELigandEntropy(res, mol, szOpts);
            if(ret_code == OESzybkiReturnCode.Success)
            {
                Console.WriteLine(String.Format("Configurational entropy {0,10:F2}", res.GetConfigurationalEntropy()));
                Console.WriteLine(String.Format("Solvation entropy       {0,10:F2}", res.GetSolvationEntropy()));
                Console.WriteLine(String.Format("Total entropy  {0,10:F2}", res.GetTotalEntropy()));
            }
            else
                OEChem.OEThrow.Warning("Entropy Calculation Failed");
        }
    }
}

Download code

LigandEntropy.cs

Estimation of bound ligand entropy

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

Listing 15: Estimation of Bound Ligand Entropy

/* 
(C) 2022 Cadence Design Systems, Inc. (Cadence) 
All rights reserved.
TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
provided to current licensees or subscribers of Cadence products or
SaaS offerings (each a "Customer").
Customer is hereby permitted to use, copy, and modify the Sample Code,
subject to these terms. Cadence claims no rights to Customer's
modifications. Modification of Sample Code is at Customer's sole and
exclusive risk. Sample Code may require Customer to have a then
current license or subscription to the applicable Cadence offering.
THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
liable for any damages or liability in connection with the Sample Code
or its use.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OESzybki;
using OpenEye.OEQuacPac;

public class BoundEntropy
{
    public static void Main(string[] args)
    {
        OEBoundEntropyOptions szOpts = new OEBoundEntropyOptions();
        OERefInputAppOptions opts = new OERefInputAppOptions(szOpts, "BoundEntropy", OEFileStringType.Mol3D,
            OEFileStringType.Mol3D, "-protein");
        if(OEChem.OEConfigureOpts(opts, args, false) == OEOptsConfigureStatus.Help)
            Environment.Exit(1);
        szOpts.UpdateValues(opts);

        oemolistream ifs = new oemolistream();
        if(!ifs.open(opts.GetInFile()))
            OEChem.OEThrow.Fatal("Unable to open " + opts.GetInFile() + " for reading");
        oemolistream pfs = new oemolistream();
        if (!pfs.open(opts.GetRefFile()))
            OEChem.OEThrow.Fatal("Unable to open " + opts.GetRefFile() + " for reading");

        OEMol protein = new OEMol();
        if (!OEChem.OEReadMolecule(pfs, protein))
            OEChem.OEThrow.Fatal("Failed to read protein");

        OEMol mol = new OEMol();
        while (OEChem.OEReadMolecule(ifs, mol)) 
        {
            OEChem.OEThrow.Info("Title: " + mol.GetTitle());
            OEEntropyResults res = new OEEntropyResults();
            uint ret_code = OESzybkilib.OEBoundLigandEntropy(res, protein, mol, szOpts);
            if(ret_code == OESzybkiReturnCode.Success)
            {
                Console.WriteLine(String.Format("Configurational entropy {0,10:F2}", res.GetConfigurationalEntropy()));
                Console.WriteLine(String.Format("Solvation entropy       {0,10:F2}", res.GetSolvationEntropy()));
                Console.WriteLine(String.Format("Total entropy  {0,10:F2}", res.GetTotalEntropy()));
            }
            else
                OEChem.OEThrow.Warning("Entropy Calculation Failed");
        }
    }
}

Download code

BoundEntropy.cs

Solvation free energy estimation

Listing 16: Solvation Free Energy Estimation

/* 
(C) 2022 Cadence Design Systems, Inc. (Cadence) 
All rights reserved.
TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
provided to current licensees or subscribers of Cadence products or
SaaS offerings (each a "Customer").
Customer is hereby permitted to use, copy, and modify the Sample Code,
subject to these terms. Cadence claims no rights to Customer's
modifications. Modification of Sample Code is at Customer's sole and
exclusive risk. Sample Code may require Customer to have a then
current license or subscription to the applicable Cadence offering.
THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
liable for any damages or liability in connection with the Sample Code
or its use.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OESzybki;
using OpenEye.OEQuacPac;

public class FreeFormSolv
{
    public static void Main(string[] args)
    {
        if (args.Length != 2)
            OEChem.OEThrow.Usage("FreeFormSolv <input> <output>");

        string inputFile  = args[0];
        string outputFile = args[1];

        oemolistream ifs = new oemolistream();
        if (!ifs.open(inputFile))
            OEChem.OEThrow.Fatal("Unable to open " + inputFile + " for reading");

        oemolostream ofs = new oemolostream();
        if (!ofs.open(outputFile))
            OEChem.OEThrow.Fatal("Unable to open " + outputFile + " for writing");

        OEMol mol = new OEMol();
        OEChem.OEReadMolecule(ifs, mol);
        ifs.close();

        OEFreeFormSolvOptions opts = new OEFreeFormSolvOptions();
        opts.SetIonicState(OEFreeFormIonicState.Uncharged);
        OEFreeFormSolvResults res = new OEFreeFormSolvResults();

        OEGraphMol omol = new OEGraphMol();
        if (!OESzybkilib.OEEstimateSolvFreeEnergy(res, omol, mol, opts))
            OEChem.OEThrow.Error("Failed to calculate solvation free energy for molecule " + mol.GetTitle());

        double solvenergy = res.GetSolvationFreeEnergy();
        OEChem.OEThrow.Info(String.Format("Solvation free energy for compound {0} is {1,6:F2} kcal/mol",
                                          mol.GetTitle(), solvenergy));

        OEChem.OEWriteMolecule(ofs, omol);
        ofs.close();
    }
}

Download code

FreeFormSolv.cs

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.

Listing 17: Simple Free Energy Estimation

/* 
(C) 2022 Cadence Design Systems, Inc. (Cadence) 
All rights reserved.
TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
provided to current licensees or subscribers of Cadence products or
SaaS offerings (each a "Customer").
Customer is hereby permitted to use, copy, and modify the Sample Code,
subject to these terms. Cadence claims no rights to Customer's
modifications. Modification of Sample Code is at Customer's sole and
exclusive risk. Sample Code may require Customer to have a then
current license or subscription to the applicable Cadence offering.
THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
liable for any damages or liability in connection with the Sample Code
or its use.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OESzybki;
using OpenEye.OEQuacPac;

public class FreeFormConf
{
    public static void Main(string[] args)
    {
        if (args.Length != 2)
            OEChem.OEThrow.Usage("FreeFormConf <input> <output>");

        string inputFile  = args[0];
        string outputFile = args[1];

        oemolistream ifs = new oemolistream();
        if (!ifs.open(inputFile))
            OEChem.OEThrow.Fatal("Unable to open " + inputFile + " for reading");

        oemolostream ofs = new oemolostream();
        if (!ofs.open(outputFile))
            OEChem.OEThrow.Fatal("Unable to open " + outputFile + " for writing");

        OEMol mol = new OEMol();
        OEChem.OEReadMolecule(ifs, mol);
        ifs.close();

        OEFreeFormConfOptions opts = new OEFreeFormConfOptions();
        OEFreeFormConf ffconf = new OEFreeFormConf(opts);

        OEMol omol = new OEMol(mol);
        if (!(ffconf.EstimateFreeEnergies(omol) == OEFreeFormReturnCode.Success))
            OEChem.OEThrow.Error("Failed to estimate conformational free energies for molecule " + mol.GetTitle());

        OEFreeFormConfResults res = new OEFreeFormConfResults(omol);
        OEChem.OEThrow.Info(String.Format("Number of unique conformations: {0}", res.GetNumUniqueConfs()));
        OEChem.OEThrow.Info("Conf.  Delta_G   Vibrational_Entropy");
        OEChem.OEThrow.Info("      [kcal/mol]     [J/(mol K)]");
        foreach (OESingleConfResult r in res.GetResultsForConformations()) {
            OEChem.OEThrow.Info(String.Format("{0,2} {1,10:F2} {2,14:F2}",
                                              r.GetConfIdx(), r.GetDeltaG(), r.GetVibrationalEntropy()));
        }
        OEChem.OEWriteMolecule(ofs, omol);
        ofs.close();
    }
}

Download code

FreeFormConf.cs

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.

Listing 18: Simple Restriction Energy Estimation

/* 
(C) 2022 Cadence Design Systems, Inc. (Cadence) 
All rights reserved.
TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
provided to current licensees or subscribers of Cadence products or
SaaS offerings (each a "Customer").
Customer is hereby permitted to use, copy, and modify the Sample Code,
subject to these terms. Cadence claims no rights to Customer's
modifications. Modification of Sample Code is at Customer's sole and
exclusive risk. Sample Code may require Customer to have a then
current license or subscription to the applicable Cadence offering.
THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
liable for any damages or liability in connection with the Sample Code
or its use.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OESzybki;
using OpenEye.OEQuacPac;

public class FreeFormConfRstr
{
    public static void Main(string[] args)
    {
        if (args.Length != 2)
            OEChem.OEThrow.Usage("FreeFormConfRstr <input> <output>");

        string inputFile  = args[0];
        string outputFile = args[1];

        oemolistream ifs = new oemolistream();
        if (!ifs.open(inputFile))
            OEChem.OEThrow.Fatal("Unable to open " + inputFile + " for reading");

        oemolostream ofs = new oemolostream();
        if (!ofs.open(outputFile))
            OEChem.OEThrow.Fatal("Unable to open " + outputFile + " for writing");

        OEMol mol = new OEMol();
        OEChem.OEReadMolecule(ifs, mol);
        ifs.close();

        OEFreeFormConfOptions opts = new OEFreeFormConfOptions();
        OEFreeFormConf ffconf = new OEFreeFormConf(opts);

        OEMol omol = new OEMol(mol);
        OEMol rmol = new OEMol(mol);
        if (ffconf.EstimateFreeEnergies(omol, rmol) != OEFreeFormReturnCode.Success)
            OEChem.OEThrow.Error("Failed to estimate conformational free energies for molecule " + mol.GetTitle());

        OEFreeFormConfResults res = new OEFreeFormConfResults(omol);
        OEChem.OEThrow.Info(String.Format("Number of unique conformations: {0}", res.GetNumUniqueConfs()));
        OEChem.OEThrow.Info("Conf.  Delta_G   Vibrational_Entropy");
        OEChem.OEThrow.Info("      [kcal/mol]     [J/(mol K)]");
        foreach (OESingleConfResult r in res.GetResultsForConformations()) {
            OEChem.OEThrow.Info(String.Format("{0,2} {1,10:F2} {2,14:F2}",
                                              r.GetConfIdx(), r.GetDeltaG(), r.GetVibrationalEntropy()));
        }

        OERestrictionEnergyResult rstrRes = new OERestrictionEnergyResult(rmol);
        OEChem.OEThrow.Info(String.Format("Global strain: {0}", rstrRes.GetGlobalStrain()));
        OEChem.OEThrow.Info(String.Format("Local strain: {0}", rstrRes.GetLocalStrain()));
        OEChem.OEWriteMolecule(ofs, omol);
        ofs.close();
    }
}

Download code

FreeFormConfRstr.cs

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.

Listing 19: Advanced Free Energy Estimation

/* 
(C) 2022 Cadence Design Systems, Inc. (Cadence) 
All rights reserved.
TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
provided to current licensees or subscribers of Cadence products or
SaaS offerings (each a "Customer").
Customer is hereby permitted to use, copy, and modify the Sample Code,
subject to these terms. Cadence claims no rights to Customer's
modifications. Modification of Sample Code is at Customer's sole and
exclusive risk. Sample Code may require Customer to have a then
current license or subscription to the applicable Cadence offering.
THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
liable for any damages or liability in connection with the Sample Code
or its use.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OESzybki;
using OpenEye.OEQuacPac;

public class FreeFormConfAdvanced
{
    public static void Main(string[] args)
    {
        if (args.Length != 2)
            OEChem.OEThrow.Usage("FreeFormConfAdvanced <input> <output>");

        string inputFile  = args[0];
        string outputFile = args[1];

        oemolistream ifs = new oemolistream();
        if (!ifs.open(inputFile))
            OEChem.OEThrow.Fatal("Unable to open " + inputFile + " for reading");

        oemolostream ofs = new oemolostream();
        if (!ofs.open(outputFile))
            OEChem.OEThrow.Fatal("Unable to open " + outputFile + " for writing");

        OEMol mol = new OEMol();
        OEChem.OEReadMolecule(ifs, mol);
        ifs.close();

        OEFreeFormConfOptions opts = new OEFreeFormConfOptions();
        OEFreeFormConfAdvanced ffconf = new 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. 
        OEMol omol = new 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 (ffconf.PrepareEnsemble(omol)!=OEFreeFormReturnCode.Success)
            OEChem.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(ffconf.PreOptimizeEnsemble(omol)!=OEFreeFormReturnCode.Success)
            OEChem.OEThrow.Error("Pre-optimization of the ensembles failed");

        // Remove duplicates from the pre-optimized ensemble
        if(ffconf.RemoveDuplicates(omol)!=OEFreeFormReturnCode.Success)
            OEChem.OEThrow.Error("Duplicate removal from the ensembles failed");

        // Perform the desired optimization.  This uses a stricter convergence
        // criteria in the default settings.
        if(ffconf.Optimize(omol)!=OEFreeFormReturnCode.Success)
            OEChem.OEThrow.Error("Optimization of the ensembles failed");

        // Remove duplicates to obtain the set of minimum energy conformers
        if(ffconf.RemoveDuplicates(omol)!=OEFreeFormReturnCode.Success)
            OEChem.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(ffconf.EstimateEnergies(omol)!=OEFreeFormReturnCode.Success)
            OEChem.OEThrow.Error("Estimation of FreeFormConf energies failed");

        // Gather results of calculation into a results object for ease of viewing, etc.
        OEFreeFormConfResults res = new OEFreeFormConfResults(omol);
        OEChem.OEThrow.Info(String.Format("Number of unique conformations: {0}", res.GetNumUniqueConfs()));
        OEChem.OEThrow.Info("Conf.  Delta_G   Vibrational_Entropy");
        OEChem.OEThrow.Info("      [kcal/mol]     [J/(mol K)]");
        foreach (OESingleConfResult r in res.GetResultsForConformations()) {
            OEChem.OEThrow.Info(String.Format("{0,2} {1,10:F2} {2,14:F2}",
                                              r.GetConfIdx(), r.GetDeltaG(), r.GetVibrationalEntropy()));
        }
        
        OEChem.OEWriteMolecule(ofs, omol);
        ofs.close();
    }
}

Download code

FreeFormConfAdvanced.cs

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.

Listing 20: Advanced Restriction Energy Estimation

/* 
(C) 2022 Cadence Design Systems, Inc. (Cadence) 
All rights reserved.
TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
provided to current licensees or subscribers of Cadence products or
SaaS offerings (each a "Customer").
Customer is hereby permitted to use, copy, and modify the Sample Code,
subject to these terms. Cadence claims no rights to Customer's
modifications. Modification of Sample Code is at Customer's sole and
exclusive risk. Sample Code may require Customer to have a then
current license or subscription to the applicable Cadence offering.
THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
liable for any damages or liability in connection with the Sample Code
or its use.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OESzybki;
using OpenEye.OEQuacPac;

public class FreeFormConfAdvRstr
{
    public static void Main(string[] args)
    {
        if (args.Length != 2)
            OEChem.OEThrow.Usage("FreeFormConfAdvRstr <input> <output>");

        string inputFile  = args[0];
        string outputFile = args[1];

        oemolistream ifs = new oemolistream();
        if (!ifs.open(inputFile))
            OEChem.OEThrow.Fatal("Unable to open " + inputFile + " for reading");

        oemolostream ofs = new oemolostream();
        if (!ofs.open(outputFile))
            OEChem.OEThrow.Fatal("Unable to open " + outputFile + " for writing");

        OEMol mol = new OEMol();
        OEChem.OEReadMolecule(ifs, mol);
        ifs.close();

        OEFreeFormConfOptions opts = new OEFreeFormConfOptions();
        OEFreeFormConfAdvanced ffconf = new 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. 
        OEMol omol = new 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
        OEMol rmol = new OEMol(mol);
        OEMol fmol = new 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 (ffconf.PrepareEnsemble(omol, rmol, fmol)!=OEFreeFormReturnCode.Success)
            OEChem.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(ffconf.PreOptimizeEnsemble(omol)!=OEFreeFormReturnCode.Success)
            OEChem.OEThrow.Error("Pre-optimization of the ensembles failed");

        // Remove duplicates from the pre-optimized ensemble
        if(ffconf.RemoveDuplicates(omol)!=OEFreeFormReturnCode.Success)
            OEChem.OEThrow.Error("Duplicate removal from the ensembles failed");

        // Perform the desired optimization.  This uses a stricter convergence
        // criteria in the default settings.
        if(ffconf.Optimize(omol)!=OEFreeFormReturnCode.Success)
            OEChem.OEThrow.Error("Optimization of the ensembles failed");

        // Remove duplicates to obtain the set of minimum energy conformers
        if(ffconf.RemoveDuplicates(omol)!=OEFreeFormReturnCode.Success)
            OEChem.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(ffconf.EstimateEnergies(omol)!=OEFreeFormReturnCode.Success)
            OEChem.OEThrow.Error("Estimation of FreeFormConf energies failed");

        // Gather results of calculation into a results object for ease of viewing, etc.
        OEFreeFormConfResults res = new OEFreeFormConfResults(omol);
        OEChem.OEThrow.Info(String.Format("Number of unique conformations: {0}", res.GetNumUniqueConfs()));
        OEChem.OEThrow.Info("Conf.  Delta_G   Vibrational_Entropy");
        OEChem.OEThrow.Info("      [kcal/mol]     [J/(mol K)]");
        foreach (OESingleConfResult r in res.GetResultsForConformations()) {
            OEChem.OEThrow.Info(String.Format("{0,2} {1,10:F2} {2,14:F2}",
                                              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(ffconf.IdentifyConformer(fmol, omol)!=OEFreeFormReturnCode.Success)
            OEChem.OEThrow.Error("Identification of free conformer(s) failed");

        // Estimate restriction energies. Since both restricted and free conformer
        // energy components are already available, this operation is fast.
        if(ffconf.EstimateRestrictionEnergy(fmol, rmol)!=OEFreeFormReturnCode.Success)
            OEChem.OEThrow.Error("Restriction energy estimation failed");

        // Gather restriction energies into a results object for ease of viewing, etc.
        OERestrictionEnergyResult rstrRes = new OERestrictionEnergyResult(fmol);
        OEChem.OEThrow.Info(String.Format("Global strain: {0}", rstrRes.GetGlobalStrain()));
        OEChem.OEThrow.Info(String.Format("Local strain: {0}", 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 (ffconf.OptimizeRestraint(rmol) != OEFreeFormReturnCode.Success)
            OEChem.OEThrow.Error("Restraint optimization of the conformer(s) failed");

        // Estimate restriction energies. Since both restricted and free conformer
        // energy components are already available, this operation is fast.
        if (ffconf.EstimateRestrictionEnergy(fmol, rmol) != OEFreeFormReturnCode.Success)
            OEChem.OEThrow.Error("Restriction energy estimation failed");

        // Gather restriction energies into a results object for ease of viewing, etc.
        OERestrictionEnergyResult rstrRes2 = new OERestrictionEnergyResult(fmol);
        OEChem.OEThrow.Info(String.Format("Global strain: {0}", rstrRes2.GetGlobalStrain()));
        OEChem.OEThrow.Info(String.Format("Local strain: {0}", rstrRes2.GetLocalStrain()));

        OEChem.OEWriteMolecule(ofs, omol);
        ofs.close();
    }
}

Download code

FreeFormConfAdvRstr.cs

Finding similar conformers

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

Listing 21: Finding Similar Conformers

/* 
(C) 2022 Cadence Design Systems, Inc. (Cadence) 
All rights reserved.
TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
provided to current licensees or subscribers of Cadence products or
SaaS offerings (each a "Customer").
Customer is hereby permitted to use, copy, and modify the Sample Code,
subject to these terms. Cadence claims no rights to Customer's
modifications. Modification of Sample Code is at Customer's sole and
exclusive risk. Sample Code may require Customer to have a then
current license or subscription to the applicable Cadence offering.
THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
liable for any damages or liability in connection with the Sample Code
or its use.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OESzybki;
using OpenEye.OEQuacPac;

public class FindSimilarConfs
{
    public static void Main(string[] args)
    {
        if (args.Length != 2)
            OEChem.OEThrow.Usage("FindSimilarConfs <input> <output>");

        string inputFile  = args[0];
        string outputFile = args[1];

        oemolistream ifs = new oemolistream();
        if (!ifs.open(inputFile))
            OEChem.OEThrow.Fatal("Unable to open " + inputFile + " for reading");

        oemolostream ofs = new oemolostream();
        if (!ofs.open(outputFile))
            OEChem.OEThrow.Fatal("Unable to open " + outputFile + " for writing");

        OEMol mol = new OEMol();
        OEChem.OEReadMolecule(ifs, mol);
        ifs.close();

        OEFreeFormConfOptions opts = new OEFreeFormConfOptions();
        OEFreeFormConf ffconf = new OEFreeFormConf(opts);

        // Estimate free energies to ontain the minimum energy conformers
        OEMol omol = new OEMol(mol);
        if (!(ffconf.EstimateFreeEnergies(omol) == OEFreeFormReturnCode.Success))
            OEChem.OEThrow.Error("Failed to estimate conformational free energies for molecule " + mol.GetTitle());

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

        OEChem.OEWriteMolecule(ofs, fmol);
        ofs.close();
    }
}

Download code

FindSimilarConfs.cs

Torsion scan

The following code shows how to scan all torsions in the input molecule