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.

/**********************************************************************
Copyright (C) 2006-2017 by OpenEye Scientific Software, Inc.
***********************************************************************/
#include "openeye.h"
#include "oechem.h"
#include "oeszybki.h"

using namespace OESystem;
using namespace OEChem;
using namespace OESz;

int main(int argc, char* argv[])
{
  if (argc!=3)
    OEThrow.Usage("%s <input> <output>", argv[0]);

  oemolistream ifs;
  if (!ifs.open(argv[1]))
    OEThrow.Fatal("Unable to open %s for reading", argv[1]);

  oemolostream ofs;
  if (!ofs.open(argv[2]))
    OEThrow.Fatal("Unable to open %s for writing", argv[2]);

  OEGraphMol mol;
  OEReadMolecule(ifs, mol);

  OESzybkiOptions opts;
  OESzybki sz(opts);
  OESzybkiResults res;
  if (!sz(mol, res)) return 1;

  OEWriteMolecule(ofs, mol);
  res.Print(OEOUT);
  return 0;
}

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.

/**********************************************************************
Copyright (C) 2006-2017 by OpenEye Scientific Software, Inc.
***********************************************************************/
#include "openeye.h"
#include "oeszybki.h"
#include "ligand_multiple_options.itf"

using namespace OESystem;
using namespace OEPlatform;
using namespace OEChem;
using namespace OESz;
using namespace std;

int main(int argc, char* argv[])
{
  //read and parse command line
  OEInterface itf(InterfaceData, argc, argv);

  //opening files
  oemolistream ifs;
  if (!ifs.open(itf.Get<string>("-in")))
    OEThrow.Fatal("Unable to open %s for reading", itf.Get<string>("-in").c_str());

  oemolostream ofs;
  if (!ofs.open(itf.Get<string>("-out")))
    OEThrow.Fatal("Unable to open %s for writing", itf.Get<string>("-out").c_str());

  oeofstream logfile = oeout;
  if (itf.Has<string>("-log"))
    if (!logfile.open(itf.Get<string>("-log")))
      OEThrow.Fatal("Unable to open %s for logging",
                    itf.Get<string>("-log").c_str());

  //Szybki options
  OESzybkiOptions opts;

  //select run type
  if (itf.Get<bool>("-t"))
    opts.SetRunType(OERunType::TorsionsOpt);
  if (itf.Get<bool>("-n"))
    opts.SetRunType(OERunType::SinglePoint);

  //apply solvent model
  if (itf.Get<bool>("-s"))
    opts.GetSolventOptions().SetSolventModel(OESolventModel::Sheffield);

  //remove attractive VdW forces
  if (itf.Get<bool>("-a"))
	  opts.GetGeneralOptions().SetRemoveAttractiveVdWForces(true);

  //Szybki object
  OESzybki sz(opts);

  //fix atoms
  if (itf.Has<string>("-f"))
    if (!sz.FixAtoms(itf.Get<string>("-f")))
      OEThrow.Warning("Failed to fix atoms for pattern %s",
                      itf.Get<string>("-f").c_str());

  //process molecules
  OEMol mol;
  OEIter<OESzybkiResults> results;   //iterator to energy results
  while(OEReadMolecule(ifs, mol))
  {
    logfile <<"\nMolecule "<<mol.GetTitle() << "\n";
    bool no_res = true;
    for (results = sz(mol); results; ++results)
    {
      results->Print(logfile);
      no_res = false;
    }

    if (no_res)
    {
      OEThrow.Warning("No results processing molecule: %s", mol.GetTitle());
      continue;
    }

    OEWriteMolecule(ofs, mol);
  }
  return 0;
}

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:

/**********************************************************************
 Copyright (C) 2017 by OpenEye Scientific Software, Inc.
***********************************************************************/
#include "openeye.h"
#include <oechem.h>
#include <oeszybki.h>

using namespace OEPlatform;
using namespace OEChem;
using namespace OESystem;
using namespace OESz;

int main(int argc,char** argv)
{
  if (argc != 3)
    OEThrow.Usage("%s input_molecule output_molecule", argv[0]);

  oemolistream ifs;
  if (!ifs.open(argv[1]))
    OEThrow.Fatal("Unable to open %s for reading", argv[1]);

  oemolostream ofs;
  if (!ofs.open(argv[2]))
    OEThrow.Fatal("Unable to open %s for writing", argv[2]);

  OEGraphMol mol;
  OEReadMolecule(ifs, mol);

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

  OESzybki sz(opts);
  OESzybkiResults res;
  if (sz(mol, res))
  {
    OEWriteMolecule(ofs, mol);
    res.Print(oeout);
  }

  return 0;
}

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.

/**********************************************************************
 Copyright (C) 2017 by OpenEye Scientific Software, Inc.
***********************************************************************/
#include <openeye.h>
#include <oechem.h>
#include <oeszybki.h>

using namespace OEPlatform;
using namespace OEChem;
using namespace OESystem;
using namespace OESz;

int main(int argc, char** argv)
{
  if (argc != 3)
    OEThrow.Usage("%s input_molecule output_molecule", argv[0]);

  oemolistream ifs;
  if (!ifs.open(argv[1]))
    OEThrow.Fatal("Unable to open %s for reading", argv[1]);

  oemolostream ofs;
  if (!ofs.open(argv[2]))
    OEThrow.Fatal("Unable to open %s for writing", argv[2]);  

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

  OESzybki sz(opts);
  OEMol mol;
  while (OEReadMolecule(ifs, mol))
  {
    for (OEIter<OEConfBase> conf = mol.GetConfs(); conf; ++conf)
    {
      OESzybkiResults res;
      if (sz(conf, res))
      {
        std::string energy = OENumberToString(res.GetTotalEnergy());
        OESetSDData(conf, "Total_energy", energy);
      }
    }
    OEWriteMolecule(ofs, mol);
  }

  return 0;
}

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.

/**********************************************************************
Copyright (C) 2006-2017 by OpenEye Scientific Software, Inc.
***********************************************************************/
#include "openeye.h"
#include "oechem.h"
#include "oeszybki.h"

using namespace OESystem;
using namespace OEChem;
using namespace OESz;

int main(int argc, char* argv[])
{
  if (argc!=4)
    OEThrow.Usage("%s <protein> <ligand> <output>", argv[0]);

  oemolistream lfs;
  if (!lfs.open(argv[1]))
    OEThrow.Fatal("Unable to open %s for reading", argv[1]);

  oemolistream pfs;
  if (!pfs.open(argv[2]))
    OEThrow.Fatal("Unable to open %s for reading", argv[2]);

  oemolostream ofs;
  if (!ofs.open(argv[3]))
    OEThrow.Fatal("Unable to open %s for writing", argv[3]);

  OEGraphMol mol;
  OEReadMolecule(lfs, mol);

  OEGraphMol protein;
  OEReadMolecule(pfs, protein);

  OESzybkiOptions opts;
  OESzybki sz(opts);
  sz.SetProtein(protein);
  OESzybkiResults res;
  if (!sz(mol, res)) return 1;

  OEWriteMolecule(ofs, mol);
  res.Print(OEOUT);

  return 0;
}

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.

/**********************************************************************
Copyright (C) 2004-2017 by OpenEye Scientific Software, Inc.
***********************************************************************/
#include "openeye.h"
#include "oeszybki.h"
#include "protein_multiple_options.itf"

using namespace OESystem;
using namespace OEPlatform;
using namespace OESz;
using namespace OEChem;
using namespace std;

int main(int argc, char* argv[])
{
  //read and parse command line
  OEInterface itf(InterfaceData, argc, argv);

  //opening files
  oemolistream lfs;
  if (!lfs.open(itf.Get<string>("-in")))
    OEThrow.Fatal("Unable to open %s for reading", itf.Get<string>("-in").c_str());

  oemolistream pfs;
  if (!pfs.open(itf.Get<string>("-p")))
    OEThrow.Fatal("Unable to open %s for reading", itf.Get<string>("-p").c_str());

  oemolostream ofs;
  if (!ofs.open(itf.Get<string>("-out")))
    OEThrow.Fatal("Unable to open %s for writing", itf.Get<string>("-out").c_str());

  oeofstream logfile = oeout;
  if (itf.Has<string>("-log"))
    if (!logfile.open(itf.Get<string>("-log")))
      OEThrow.Fatal("Unable to open %s for logging",
                    itf.Get<string>("-log").c_str());

  //Szybki options object
  OESzybkiOptions opts;

  //select optimization type
  if (itf.Get<bool>("-t")) opts.SetRunType(OERunType::TorsionsOpt);
  else opts.SetRunType(OERunType::CartesiansOpt);

  //select protein-electrostatic model
  string emodel = itf.Get<string>("-e");
  unsigned int elecModel = OEProteinElectrostatics::NoElectrostatics;
  if (emodel == "VdW")
	  elecModel = OEProteinElectrostatics::NoElectrostatics;
  else if (emodel == "PB")
	  elecModel = OEProteinElectrostatics::GridPB;
  else if (emodel == "Coulomb")
	  elecModel = OEProteinElectrostatics::GridCoulomb;
  else if (emodel == "ExactCoulomb")
  {
	  elecModel = OEProteinElectrostatics::ExactCoulomb;
	  opts.GetProteinOptions().SetExactVdWProteinLigand(true);
	  opts.GetOptOptions().SetMaxIter(1000);
	  opts.GetOptOptions().SetGradTolerance(1e-6);
  }  
  opts.GetProteinOptions().SetProteinElectrostaticModel(elecModel);

  //Szybki object
  OESzybki sz(opts);

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

  //save or load grid potential
  if (emodel == "PB" || emodel == "Coulomb")
  {
    if (itf.Has<string>("-s")) sz.SavePotentialGrid(itf.Get<string>("-s"));
    if (itf.Has<string>("-l")) sz.LoadPotentialGrid(itf.Get<string>("-l"));
  }

  //process molecules
  OEMol mol;
  OEIter<OESzybkiResults> res;   //iterator to energy results
  while(OEReadMolecule(lfs, mol))
  {
    logfile << "\nMolecule " << mol.GetTitle() << "\n";
    bool no_res = true;
    for (res = sz(mol); res; ++res)
    {
      res->Print(logfile);
      no_res = false;
    }

    if (no_res)
    {
      OEThrow.Warning("No results processing molecule: %s", mol.GetTitle());
      continue;
    }

    OEWriteMolecule(ofs, mol);

  }
  return 0;
}

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.

/**********************************************************************
Copyright (C) 2006-2017 by OpenEye Scientific Software, Inc.
***********************************************************************/
#include "openeye.h"
#include "oeszybki.h"
#include "flexible_protein.itf"

using namespace OESystem;
using namespace OEPlatform;
using namespace OESz;
using namespace OEChem;
using namespace std;

int main(int argc, char* argv[])
{
  //read and parse command line
  OEInterface itf(InterfaceData, argc, argv);

  //opening files
  oemolistream lfs;
  if (!lfs.open(itf.Get<string>("-in")))
    OEThrow.Fatal("Unable to open %s for reading", itf.Get<string>("-in").c_str());

  oemolistream pfs;
  if (!pfs.open(itf.Get<string>("-p")))
    OEThrow.Fatal("Unable to open %s for reading", itf.Get<string>("-p").c_str());

  oemolostream olfs;
  if (!olfs.open(itf.Get<string>("-out")))
    OEThrow.Fatal("Unable to open %s for writing", itf.Get<string>("-out").c_str());

  oemolostream opfs;
  if (itf.Has<string>("-s"))
    if (!opfs.open(itf.Get<string>("-s")))
      OEThrow.Error("Unable to open %s for protein output",
                    itf.Get<string>("-s").c_str());

  oeofstream logfile = oeout;
  if (itf.Has<string>("-log"))
    if (!logfile.open(itf.Get<string>("-log")))
      OEThrow.Error("Unable to open %s for logging",
                    itf.Get<string>("-log").c_str());

  //Szybki options
  OESzybkiOptions opts;

  //select optimization type
  string opt = itf.Get<string>("-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
  string emodel = itf.Get<string>("-e");
  unsigned int elecModel = OEProteinElectrostatics::NoElectrostatics;
  if (emodel == "VdW")
    elecModel = OEProteinElectrostatics::NoElectrostatics;
  else if (emodel == "PB")
	  elecModel = OEProteinElectrostatics::GridPB;
  else if (emodel == "Coulomb")
	  elecModel = OEProteinElectrostatics::GridCoulomb;
  else if (emodel == "ExactCoulomb")
	  elecModel = OEProteinElectrostatics::ExactCoulomb;
  opts.GetProteinOptions().SetProteinElectrostaticModel(elecModel);

  //use smooth potential and tight convergence
  if (emodel == "VdW" || 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.Get<double>("-d"));

  //Szybki object
  OESzybki sz(opts);

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

  //process molecules
  OEMol mol;
  OEIter<OESzybkiResults> results;   //iterator to energy results
  while (OEReadMolecule(lfs, mol))
  {
    logfile << "\nMolecule " << mol.GetTitle() << "\n";
    for (results = sz(mol); results; ++results)
      results->Print(logfile);

    OEWriteMolecule(olfs, mol);
    if (itf.Has<string>("-s"))
    {
      sz.GetProtein(oprotein);
      OEWriteMolecule(opfs, oprotein);
    }
  }
  return 0;
}

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.

/**********************************************************************
 Copyright (C) 2009-2017 by OpenEye Scientific Software, Inc.
***********************************************************************/
#include "openeye.h"
#include "oeszybki.h"

using namespace OESystem;
using namespace OEPlatform;
using namespace OESz;
using namespace OEChem;
using namespace std;

int main(int argc, char* argv[])
{
  if (argc != 4) OEThrow.Usage("%s ligand_file protein_file output_file (SDF or OEB)", argv[0]);

  oemolistream lfs;
  if (!lfs.open(argv[1]))
    OEThrow.Fatal("Unable to open %s for reading", argv[1]);

  oemolistream pfs;
  if (!pfs.open(argv[2]))
    OEThrow.Fatal("Unable to open %s for reading", argv[2]);

  oemolostream ofs;
  if (!ofs.open(argv[3]))
    OEThrow.Fatal("Unable to open %s for writing", argv[3]);

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

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

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

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

  //read and setup protein
  OEGraphMol protein;
  OEReadMolecule(pfs, protein);
  szC.SetProtein(protein);
  szPB.SetProtein(protein);

  //process molecules
  OEMol mol;
  OEIter<OESzybkiResults> results;   //iterators to energy results
  OEIter<OEConfBase>conf;            //iterator over conformations
  char buf[20];
  while(OEReadMolecule(lfs, mol))
  {
    //optimize mol
    bool no_res = true;
    for (results=szC(mol); results; ++results)
    {
      no_res = false;
      break;
    }

    if (no_res)
    {
      OEThrow.Warning("No results processing molecule: %s", mol.GetTitle());
      continue;
    }

    //do single point with better electrostatics and output results
    for (results = szPB(mol), conf = mol.GetConfs(); (bool)results && (bool)conf; ++results, ++conf)
    {
      for (unsigned int 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)
        {
          sprintf(buf, "%9.4f", results->GetEnergyTerm(i));
          OEAddSDData(conf, OEGetEnergyTermName(i), string(buf));
        }
      }
    }
    OEWriteMolecule(ofs, mol);
  }
  return 0;
}

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.

/**********************************************************************
Copyright (C) 2013-2017 by OpenEye Scientific Software, Inc.
***********************************************************************/
#include "openeye.h"
#include "oechem.h"
#include "oeszybki.h"

using namespace OEPlatform;
using namespace OEChem;
using namespace OESystem;
using namespace OESz;

int main(int argc,char** argv)
{
  if (argc != 4)
    OEThrow.Usage("%s protein input_ligand output_ligand", argv[0]);

  oemolistream pfs;
  if (!pfs.open(argv[1]))
    OEThrow.Fatal("Unable to open %s for reading", argv[1]);

  oemolistream lfs;
  if (!lfs.open(argv[2]))
    OEThrow.Fatal("Unable to open %s for reading", argv[2]);

  oemolostream ofs;
  if (!ofs.open(argv[3]))
    OEThrow.Fatal("Unable to open %s for writing", argv[3]);

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

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

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

  OESzybkiResults res;
  if (sz(mol, res))
  {
    OEWriteMolecule(ofs, mol);
    res.Print(oeout);
  }

  return 0;
}

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.

/**********************************************************************
 Copyright (C) 2011, 2014-2017 by OpenEye Scientific Software, Inc.
***********************************************************************/
#include "openeye.h"
#include "oechem.h"
#include "oeszybki.h"

using namespace OESystem;
using namespace OEChem;
using namespace OESz;

using namespace std;

int main(int argc, char* argv[])
{
  if (argc != 2)
    OEThrow.Usage("%s <lig>", argv[0]);

  oemolistream ifs;
  if (!ifs.open(argv[1]))
    OEThrow.Fatal("Unable to open %s for reading", argv[1]);

  OEMol lig;
  OEReadMolecule(ifs, lig);

  OESzybkiOptions opts;
  OESzybki sz(opts);
  OESzybkiEnsembleResults eres;
  double S = sz.GetEntropy(lig, eres, OEEntropyMethod::Analytic, OEEnvType::SolutionSPT);

  printf("Configurational entropy %10.2f\n", eres.GetConfigurationalEntropy());
  printf("Solvation entropy       %10.2f\n", eres.GetEnsembleLigSolvEntropy());
  printf("                            ======\n");
  printf("Total solution entropy  %10.2f J/(mol K)\n", S);

  return 0;
}
/**********************************************************************
 Copyright (C) 2014-2017 by OpenEye Scientific Software, Inc.
***********************************************************************/
#include "openeye.h"

#include <oechem.h>
#include <oesystem.h>
#include <oequacpac.h>
#include <oeszybki.h>

using namespace OEChem;
using namespace OESystem;
using namespace OESz;

int main(int argc,char** argv)
{
  if (argc != 3)
    OEThrow.Usage("%s input_file output_file", argv[0]);

  oemolistream ifs;
  if (!ifs.open(argv[1]))
    OEThrow.Fatal("Unable to open %s for reading", argv[1]);

  oemolostream ofs;
  if (!ofs.open(argv[2]))
    OEThrow.Fatal("Unable to open %s for writing", argv[2]);

  //input set of conformations in solution
  OEMol mol;
  OEReadMolecule(ifs, mol);

  OESzybkiOptions opts;
  opts.GetSolventOptions().SetChargeEngine(OEProton::OEChargeEngineNoOp());
  OESzybki sz(opts);

  OESzybkiEnsembleResults eres;
  double 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:");
  OEIter<OEConfBase> conf;
  OEIter<OESzybkiResults> r;
  for (r = eres.GetResultsForConformations(), conf=mol.GetConfs(); (bool)conf && r; ++conf, ++r)
    OEThrow.Info("%2d %5.1f", conf->GetIdx(), r->GetVibEntropy());

  //ensemble of unique conformations
  OEWriteMolecule(ofs, mol);

  return 0;
}

Estimation of bound ligand entropy

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

/**********************************************************************
Copyright (C) 2017 by OpenEye Scientific Software, Inc.
***********************************************************************/
#include "openeye.h"

#include <oechem.h>
#include <oesystem.h>
#include <oeszybki.h>

using namespace OEChem;
using namespace OESystem;
using namespace OESz;

int main(int argc,char** argv)
{
  if(argc != 4)
    OEThrow.Usage("%s bound_ligand protein opt_ligand", argv[0]);

  oemolistream lfs;
  if (!lfs.open(argv[1]))
    OEThrow.Fatal("Unable to open %s for reading", argv[1]);

  oemolistream pfs;
  if (!pfs.open(argv[2]))
    OEThrow.Fatal("Unable to open %s for reading", argv[2]);

  oemolostream ofs;
  if (!ofs.open(argv[3]))
    OEThrow.Fatal("Unable to open %s for writing", argv[3]);

  OEMol lig;
  OEReadMolecule(lfs, lig);

  OEGraphMol protein;
  OEReadMolecule(pfs, protein);

  OESzybkiOptions opts;
  OESzybki sz(opts);
  sz.SetProtein(protein);

  OESzybkiEnsembleResults eres;
  double 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;
}

Solvation free energy estimation

/**********************************************************************
 Copyright (C) 2014 by OpenEye Scientific Software, Inc.
***********************************************************************/
#include "openeye.h"
#include "oechem.h"
#include "oeszybki.h"

using namespace OESystem;
using namespace OEChem;
using namespace OESz;

int main(int argc, char* argv[])
{
  if (argc!=3)
    OEThrow.Usage("%s <input> <output>", argv[0]);
    
  oemolistream ifs;
  if (!ifs.open(argv[1]))
    OEThrow.Fatal("Unable to open %s for reading", argv[1]);

  oemolostream ofs;
  if (!ofs.open(argv[2]))
    OEThrow.Fatal("Unable to open %s for writing", argv[2]);

  OEMol mol;
  OEReadMolecule(ifs, mol);

  OEFreeFormSolvOptions opts;
  opts.SetIonicState(OEFreeFormIonicState::Uncharged);
  OEFreeFormSolvResults res;

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

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

  OEWriteMolecule(ofs, omol);

  return 0;
}

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.

/**********************************************************************
 Copyright (C) 2017 by OpenEye Scientific Software, Inc.
***********************************************************************/
#include "openeye.h"
#include "oechem.h"
#include "oeszybki.h"

using namespace OESystem;
using namespace OEChem;
using namespace OESz;

int main(int argc, char* argv[])
{
  if (argc!=3)
    OEThrow.Usage("%s <input> <output>", argv[0]);
    
  oemolistream ifs;
  if (!ifs.open(argv[1]))
    OEThrow.Fatal("Unable to open %s for reading", argv[1]);

  oemolostream ofs;
  if (!ofs.open(argv[2]))
    OEThrow.Fatal("Unable to open %s for writing", argv[2]);

  OEMol mol;
  OEReadMolecule(ifs, mol);

  OEFreeFormConfOptions opts;
  OEFreeFormConf ffconf(opts);

  OEMol omol(mol);
  if(ffconf.EstimateFreeEnergies(omol)!=OEFreeFormReturnCode::Success)
    OEThrow.Error("Failed to estimate conformations free energies");

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

  OEWriteMolecule(ofs, omol);

  return 0;
}

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.

/**********************************************************************
 Copyright (C) 2017 by OpenEye Scientific Software, Inc.
***********************************************************************/
#include "openeye.h"
#include "oechem.h"
#include "oeszybki.h"

using namespace OESystem;
using namespace OEChem;
using namespace OESz;

int main(int argc, char* argv[])
{
  if (argc!=3)
    OEThrow.Usage("%s <input> <output>", argv[0]);
    
  oemolistream ifs;
  if (!ifs.open(argv[1]))
    OEThrow.Fatal("Unable to open %s for reading", argv[1]);

  oemolostream ofs;
  if (!ofs.open(argv[2]))
    OEThrow.Fatal("Unable to open %s for writing", argv[2]);

  OEMol mol;
  OEReadMolecule(ifs, mol);

  OEFreeFormConfOptions opts;
  OEFreeFormConf ffconf(opts);

  OEMol omol(mol);
  OEMol rmol(mol);
  if(ffconf.EstimateFreeEnergies(omol, rmol)!=OEFreeFormReturnCode::Success)
    OEThrow.Error("Failed to estimate conformations free energies");

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

  OERestrictionEnergyResult rstrRes(rmol);
  OEThrow.Info("Global strain: %f", rstrRes.GetGlobalStrain());
  OEThrow.Info("Local strain: %f", rstrRes.GetLocalStrain());
  OEWriteMolecule(ofs, omol);

  return 0;
}

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.

/**********************************************************************
 Copyright (C) 2017 by OpenEye Scientific Software, Inc.
***********************************************************************/
#include "openeye.h"
#include "oechem.h"
#include "oeszybki.h"

using namespace OESystem;
using namespace OEChem;
using namespace OESz;

int main(int argc, char* argv[])
{
  if (argc!=3)
    OEThrow.Usage("%s <input> <output>", argv[0]);
    
  oemolistream ifs;
  if (!ifs.open(argv[1]))
    OEThrow.Fatal("Unable to open %s for reading", argv[1]);

  oemolostream ofs;
  if (!ofs.open(argv[2]))
    OEThrow.Fatal("Unable to open %s for writing", argv[2]);

  OEMol mol;
  OEReadMolecule(ifs, mol);

  OEFreeFormConfOptions opts;
  OEFreeFormConfAdvanced ffconf(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(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)
    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)
    OEThrow.Error("Pre-optimization of the ensembles failed");

  // Remove duplicates from the pre-optimized ensemble
  if(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(ffconf.Optimize(omol)!=OEFreeFormReturnCode::Success)
    OEThrow.Error("Optimization of the ensembles failed");

  // Remove duplicates to obtain the set of minimum energy conformers
  if(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(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.
  OEFreeFormConfResults res(omol);
  OEThrow.Info("Number of unique conformations: %d", res.GetNumUniqueConfs());
  OEThrow.Info("Conf.  Delta_G   Vibrational_Entropy");
  OEThrow.Info("      [kcal/mol]     [J/(mol K)]");
  OEIter<OESingleConfResult> r;
  for (r = res.GetResultsForConformations(); r; ++r)
    OEThrow.Info("%2d %10.2f %14.2f", r->GetConfIdx(), r->GetDeltaG(), 
                 r->GetVibrationalEntropy());

  OEWriteMolecule(ofs, omol);
  return 0;
}

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.

/**********************************************************************
 Copyright (C) 2017 by OpenEye Scientific Software, Inc.
***********************************************************************/
#include "openeye.h"
#include "oechem.h"
#include "oeszybki.h"

using namespace OESystem;
using namespace OEChem;
using namespace OESz;

int main(int argc, char* argv[])
{
  if (argc!=3)
    OEThrow.Usage("%s <input> <output>", argv[0]);
    
  oemolistream ifs;
  if (!ifs.open(argv[1]))
    OEThrow.Fatal("Unable to open %s for reading", argv[1]);

  oemolostream ofs;
  if (!ofs.open(argv[2]))
    OEThrow.Fatal("Unable to open %s for writing", argv[2]);

  OEMol mol;
  OEReadMolecule(ifs, mol);

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

  // Remove duplicates from the pre-optimized ensemble
  if(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(ffconf.Optimize(omol)!=OEFreeFormReturnCode::Success)
    OEThrow.Error("Optimization of the ensembles failed");

  // Remove duplicates to obtain the set of minimum energy conformers
  if(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(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.
  OEFreeFormConfResults res(omol);
  OEThrow.Info("Number of unique conformations: %d", res.GetNumUniqueConfs());
  OEThrow.Info("Conf.  Delta_G   Vibrational_Entropy");
  OEThrow.Info("      [kcal/mol]     [J/(mol K)]");
  OEIter<OESingleConfResult> r;
  for (r = res.GetResultsForConformations(); r; ++r)
    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 (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 (ffconf.EstimateRestrictionEnergy(fmol, rmol) != OEFreeFormReturnCode::Success)
	  OEThrow.Error("Restriction energy estimation failed");

  // Gather restriction energies into a results object for ease of viewing, etc.
  OERestrictionEnergyResult rstrRes(fmol);
  OEThrow.Info("Global strain: %f", rstrRes.GetGlobalStrain());
  OEThrow.Info("Local strain: %f", 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)
    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)
	  OEThrow.Error("Restriction energy estimation failed");

  // Gather restriction energies into a results object for ease of viewing, etc.
  OERestrictionEnergyResult rstrRes2(fmol);
  OEThrow.Info("Global strain: %f", rstrRes2.GetGlobalStrain());
  OEThrow.Info("Local strain: %f", rstrRes2.GetLocalStrain());
  
  OEWriteMolecule(ofs, omol);
  return 0;
}

Finding similar conformers

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

/**********************************************************************
 Copyright (C) 2017 by OpenEye Scientific Software, Inc.
***********************************************************************/
#include "openeye.h"
#include "oechem.h"
#include "oeszybki.h"

using namespace OESystem;
using namespace OEChem;
using namespace OESz;

int main(int argc, char* argv[])
{
  if (argc!=3)
    OEThrow.Usage("%s <input> <output>", argv[0]);
    
  oemolistream ifs;
  if (!ifs.open(argv[1]))
    OEThrow.Fatal("Unable to open %s for reading", argv[1]);

  oemolostream ofs;
  if (!ofs.open(argv[2]))
    OEThrow.Fatal("Unable to open %s for writing", argv[2]);

  OEMol mol;
  OEReadMolecule(ifs, mol);

  OEFreeFormConfOptions opts;
  OEFreeFormConf ffconf(opts);

  // Estimate free energies to ontain the minimum energy conformers
  OEMol omol(mol);
  if(ffconf.EstimateFreeEnergies(omol)!=OEFreeFormReturnCode::Success)
    OEThrow.Error("Failed to estimate conformations free energies");

  // Find similar conformers to the ones we started with, from the
  // pool of minimum energy conformers
  OEMol fmol(mol);
  for (OEIter<OEChem::OEConfBase> conf = mol.GetConfs(); (bool)conf; ++conf)
    ffconf.FindSimilarConfs(fmol, omol, conf, OESimilarByRMSD(0.05));

  OEWriteMolecule(ofs, fmol);

  return 0;
}