Eon Examples

The following table lists the currently available Eon TK examples:

Program

Description

overlap

Computing Eon overlap

simple overlay

Simple Eon (Shape and Charge Density) overlay

pb overlay

Eon PB (Shape and PB Potential) overlay

Computing Eon Overlap

This example reads in a reference molecule and fit molecules and performs static shape charge similarity calculations. Results are outputted to a file.

Listing 1: Computing Eon Overlap

/*
 (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.
 */
#include <cstdio>
#include <string>
#include <openeye.h>

#include <oeplatform.h>
#include <oesystem.h>
#include <oechem.h>
#include <oeshape.h>
#include <oequacpac.h>
#include <oeet.h>

class EonOverlapOption : public OESystem::OEOptions
{
public:
  EonOverlapOption(std::string name = "EonOverlapOption")
  :OESystem::OEOptions(name)
  {
    OESystem::OEStringParameter chargesParam("-charges", "mmff94");
    chargesParam.SetIsList(false);
    chargesParam.SetRequired(true);
    chargesParam.SetBrief("Choices for this parameter are mmff94 (fix pka and set charges to mmff94), or existing (assume input has charges)");
    m_chargesParam = AddParameter(chargesParam);
  }
  
  EonOverlapOption(const EonOverlapOption&) = default;
  EonOverlapOption& operator=(const EonOverlapOption&) = default;
  ~EonOverlapOption() override =default;
  EonOverlapOption* CreateCopy() const override { return new EonOverlapOption(*this);}
  
  std::string GetCharges()
  {
    if(!m_chargesParam->GetHasValue())
      return m_chargesParam->GetStringDefault();
    
    return m_chargesParam->GetStringValue();
  }
  
private:
  OESystem::OEParameter* m_chargesParam;
};

void prepMol(OEChem::OEMol &mol)
{
  if (OEShape::OEHasColorAtoms(mol))
      OEShape::OERemoveColorAtoms(mol);

  OEChem::OEAddExplicitHydrogens(mol);
  OEChem::OEAssignBondiVdWRadii(mol);

  OEProton::OESetNeutralpHModel(mol);
  OEProton::OEAssignCharges(mol, OEProton::OEMMFF94Charges());
  mol.Sweep();
}

int main(int argc, char* argv[])
{
  EonOverlapOption eonOpts;
  OEChem::OERefInputAppOptions opts(
      eonOpts,
      "EonOverlapOptions",
      OEChem::OEFileStringType::Mol3D,
      OEChem::OEFileStringType::Mol3D,
      OEChem::OEFileStringType::Mol3D,
      "-query");
  
  if (OESystem::OEConfigureOpts(opts, argc, argv, false) == OESystem::OEOptsConfigureStatus::Help)
    return 0;
  
  eonOpts.UpdateValues(opts);

  OEChem::oemolistream qfs;
  if (!qfs.open(opts.GetRefFile()))
    OESystem::OEThrow.Fatal("Unable to open %s for reading", opts.GetRefFile().c_str());
  
  OEChem::oemolistream ifs;
  if (!ifs.open(opts.GetInFile()))
    OESystem::OEThrow.Fatal("Unable to open %s for reading", opts.GetInFile().c_str());
  
  OEChem::oemolostream ofs;
  if (!ofs.open(opts.GetOutFile()))
    OESystem::OEThrow.Fatal("Unable to open %s for writing", opts.GetOutFile().c_str());
  
  OEChem::OEMol refmol;
  if (!OEChem::OEReadMolecule(qfs, refmol))
    OESystem::OEThrow.Fatal("Unable to load molecule");
  
  const std::string charges = eonOpts.GetCharges();
  OEEon::OEExactChargeFunc chargeFunc;

  if (charges.compare("mmff94") == 0)
    prepMol(refmol);

  chargeFunc.SetupRef(refmol);
  OEChem::OEWriteMolecule(ofs, refmol);
  OEChem::OEMol mol;
  while (OEChem::OEReadMolecule(ifs, mol))
  {
      if (charges.compare("mmff94") == 0)
        prepMol(mol);
      OEEon::OEEonOverlapScore score;
      chargeFunc.Setup(mol);
      for (OESystem::OEIter<OEChem::OEConfBase> conf = mol.GetConfs(); conf; ++conf)
      {
          chargeFunc.Overlap(conf, score);
          OEChem::OESetSDData(conf, "(Static) Charge Tanimoto", std::to_string(score.GetETTanimoto()));
      }
      OEChem::OEWriteMolecule(ofs, mol);
  }

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

Download code

eon_overlap.cpp

Simple Eon Overlay

This example reads in a reference molecule and fit molecules and overlays them according to their shape and charge density similarity.

Listing 2: Computing Simple Eon Overlay

/*
 (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.
 */
#include <cstdio>
#include <string>
#include <openeye.h>

#include <oeplatform.h>
#include <oesystem.h>
#include <oechem.h>
#include <oeshape.h>
#include <oequacpac.h>
#include <oeet.h>

class EonOverlayOptions : public OESystem::OEOptions
{
public:
  EonOverlayOptions(std::string name = "EonOverlayOptions")
  :OESystem::OEOptions(name)
  {
    OESystem::OEStringParameter chargesParam("-charges", "mmff94");
    chargesParam.SetIsList(false);
    chargesParam.SetRequired(true);
    chargesParam.SetBrief("Choices for this parameter are mmff94 (fix pka and set charges to mmff94), or existing (assume input has charges)");
    m_chargesParam = AddParameter(chargesParam);

    m_HitlistOptions = static_cast<OEEon::OEEonHitlistOptions*>(AddOption(OEEon::OEEonHitlistOptions()));
  }
  
  EonOverlayOptions(const EonOverlayOptions&) = default;
  EonOverlayOptions& operator=(const EonOverlayOptions&) = default;
  ~EonOverlayOptions() override =default;
  EonOverlayOptions* CreateCopy() const override { return new EonOverlayOptions(*this);}
  
  std::string GetCharges()
  {
    if(!m_chargesParam->GetHasValue())
      return m_chargesParam->GetStringDefault();
    
    return m_chargesParam->GetStringValue();
  }

  OEEon::OEEonHitlistOptions* GetHitlistOptions() const { return m_HitlistOptions; }

private:
  OESystem::OEParameter* m_chargesParam;  
  OEEon::OEEonHitlistOptions* m_HitlistOptions;
};

void prepMol(OEChem::OEMol &mol)
{
  if (OEShape::OEHasColorAtoms(mol))
      OEShape::OERemoveColorAtoms(mol);

  OEChem::OEAddExplicitHydrogens(mol);
  OEChem::OEAssignBondiVdWRadii(mol);

  OEProton::OESetNeutralpHModel(mol);
  OEProton::OEAssignCharges(mol, OEProton::OEMMFF94Charges());
  mol.Sweep();
}

int main(int argc, char* argv[])
{
  EonOverlayOptions eonOpts;
  OEChem::OERefInputAppOptions opts(
      eonOpts,
      "EonOverlayOptions",
      OEChem::OEFileStringType::Mol3D,
      OEChem::OEFileStringType::Mol3D,
      OEChem::OEFileStringType::Mol3D,
      "-query");
  
  if (OESystem::OEConfigureOpts(opts, argc, argv, false) == OESystem::OEOptsConfigureStatus::Help)
    return 0;
  
  eonOpts.UpdateValues(opts);

  OEChem::oemolistream qfs;
  if (!qfs.open(opts.GetRefFile()))
    OESystem::OEThrow.Fatal("Unable to open %s for reading", opts.GetRefFile().c_str());
  
  OEChem::oemolistream ifs;
  if (!ifs.open(opts.GetInFile()))
    OESystem::OEThrow.Fatal("Unable to open %s for reading", opts.GetInFile().c_str());
  
  OEChem::oemolostream ofs;
  if (!ofs.open(opts.GetOutFile()))
    OESystem::OEThrow.Fatal("Unable to open %s for writing", opts.GetOutFile().c_str());
  
  OEChem::OEMol refmol;
  if (!OEChem::OEReadMolecule(qfs, refmol))
    OESystem::OEThrow.Fatal("Unable to load molecule");
  
  const std::string charges = eonOpts.GetCharges();

  OEEon::OEEonOverlapFunc overlapFunc; //by default this will be shape and charge with Grid approach

  OEShape::OEOverlayOptions overlayOpts;

  overlayOpts.SetOverlapFunc(overlapFunc);

  OEEon::OEEonOverlay eonOverlay(overlayOpts);
 
  if (charges.compare(std::string("mmff94")) == 0)
      prepMol(refmol);

  eonOverlay.SetupRef(refmol);
  OEChem::OEWriteMolecule(ofs, refmol);
  OEChem::OEMol mol;
  OEEon::OEEonHitlistBuilder hitlist(*eonOpts.GetHitlistOptions());

  while (OEChem::OEReadMolecule(ifs, mol))
  {
    if (charges.compare(std::string("mmff94")) == 0)
          prepMol(mol);
      OEEon::OEEonOverlayScore score;
      eonOverlay.BestOverlay(score, mol);
      hitlist.AddScore(score, mol);
  }
  hitlist.Build();

  for (auto hit : hitlist.GetHits())
  {
    OEChem::OEGraphMol hitMol = hit.GetMol();
    OEChem::OESetSDData(hitMol, "Shape Tanimoto", std::to_string(hit.GetTanimoto()));
    OEChem::OESetSDData(hitMol, "Charge Tanimoto", std::to_string(hit.GetETTanimoto()));
    OEChem::OESetSDData(hitMol, "Shape + Charge Tanimoto Combo", std::to_string(hit.GetTanimotoCombo()));
    OEChem::OEWriteMolecule(ofs, hitMol);
  }

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

Download code

eon_simple_overlay.cpp

Eon PB Overlay

This example reads in a reference molecule and fit molecules and overlays them according to their shape and potential similarity.

Listing 3: Computing Eon PB Overlay

/*
 (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.
 */
#include <cstdio>
#include <string>
#include <openeye.h>

#include <oeplatform.h>
#include <oesystem.h>
#include <oechem.h>
#include <oeshape.h>
#include <oequacpac.h>
#include <oeet.h>

class EonPBOverlayOptions : public OESystem::OEOptions
{
public:
  EonPBOverlayOptions(std::string name = "EonPBOverlayOptions")
  :OESystem::OEOptions(name)
  {
    OESystem::OEStringParameter chargesParam("-charges", "mmff94");
    chargesParam.SetIsList(false);
    chargesParam.SetRequired(true);
    chargesParam.SetBrief("Choices for this parameter are mmff94 (fix pka and set charges to mmff94), or existing (assume input has charges)");
    m_chargesParam = AddParameter(chargesParam);

    OESystem::OEUIntParameter numTopHitsParam("-numtophits", 5);
    numTopHitsParam.SetIsList(false);
    numTopHitsParam.SetRequired(true);
    numTopHitsParam.SetVisibility(OESystem::OEParamVisibility::Simple);
    numTopHitsParam.SetBrief("Number of shape charge overlay hits to rescore with shape and PB potential similarity");

    m_numTopHitsParam = AddParameter(numTopHitsParam);
    m_HitlistOptions = static_cast<OEEon::OEEonHitlistOptions*>(AddOption(OEEon::OEEonHitlistOptions()));
    m_PBOptions = static_cast<OEEon::OEEonPBOptions*>(AddOption(OEEon::OEEonPBOptions()));
  }
  
  EonPBOverlayOptions(const EonPBOverlayOptions&) = default;
  EonPBOverlayOptions& operator=(const EonPBOverlayOptions&) = default;
  ~EonPBOverlayOptions() override =default;
  EonPBOverlayOptions* CreateCopy() const override { return new EonPBOverlayOptions(*this);}
  
  std::string GetCharges()
  {
    if(!m_chargesParam->GetHasValue())
      return m_chargesParam->GetStringDefault();
    return m_chargesParam->GetStringValue();
  }

  unsigned int GetNumTopHits()
  {
    if (m_numTopHitsParam->GetHasValue())
      return std::stoi(m_numTopHitsParam->GetStringValue());
    
    return std::stoi(m_numTopHitsParam->GetStringDefault());

  }

  OEEon::OEEonHitlistOptions* GetHitlistOptions() const { return m_HitlistOptions; }
  OEEon::OEEonPBOptions* GetPBOptions() const { return m_PBOptions; }

  
private:
  OESystem::OEParameter* m_chargesParam;  
  OESystem::OEParameter* m_numTopHitsParam;  
  OEEon::OEEonPBOptions* m_PBOptions;
  OEEon::OEEonHitlistOptions* m_HitlistOptions;
};


void prepMol(OEChem::OEMol &mol)
{
  if (OEShape::OEHasColorAtoms(mol))
      OEShape::OERemoveColorAtoms(mol);

  OEChem::OEAddExplicitHydrogens(mol);
  OEChem::OEAssignBondiVdWRadii(mol);

  OEProton::OESetNeutralpHModel(mol);
  OEProton::OEAssignCharges(mol, OEProton::OEMMFF94Charges());
  mol.Sweep();
}
    
int main(int argc, char* argv[])
{
  EonPBOverlayOptions eonOpts;
  OEChem::OERefInputAppOptions opts(
      eonOpts,
      "EonOverlayOptions",
      OEChem::OEFileStringType::Mol3D,
      OEChem::OEFileStringType::Mol3D,
      OEChem::OEFileStringType::Mol3D,
      "-query");
  
  if (OESystem::OEConfigureOpts(opts, argc, argv, false) == OESystem::OEOptsConfigureStatus::Help)
    return 0;
  eonOpts.UpdateValues(opts);

  OEChem::oemolistream qfs;
  if (!qfs.open(opts.GetRefFile()))
    OESystem::OEThrow.Fatal("Unable to open %s for reading", opts.GetRefFile().c_str());
  
  OEChem::oemolistream ifs;
  if (!ifs.open(opts.GetInFile()))
    OESystem::OEThrow.Fatal("Unable to open %s for reading", opts.GetInFile().c_str());
  
  OEChem::oemolostream ofs;
  if (!ofs.open(opts.GetOutFile()))
    OESystem::OEThrow.Fatal("Unable to open %s for writing", opts.GetOutFile().c_str());
  
  OEChem::OEMol refmol;
  if (!OEChem::OEReadMolecule(qfs, refmol))
    OESystem::OEThrow.Fatal("Unable to load molecule");
  
  const std::string charges = eonOpts.GetCharges();
  const unsigned int numtophits = eonOpts.GetNumTopHits();

  OEEon::OEEonOverlapFunc overlapFunc; //by default this will be shape and charge with Grid approach
  OEShape::OEOverlayOptions overlayOpts;
  overlayOpts.SetOverlapFunc(overlapFunc);
  OEEon::OEEonPBOverlay eonPBOverlay(overlayOpts, *eonOpts.GetPBOptions());
  if (charges.compare(std::string("mmff94")) == 0)
      prepMol(refmol);
  eonPBOverlay.SetupRef(refmol);
  OEChem::OEWriteMolecule(ofs, refmol);
  OEChem::OEMol mol;
  OEEon::OEEonHitlistBuilder hitlist(*eonOpts.GetHitlistOptions());

  while (OEChem::OEReadMolecule(ifs, mol))
  {
      if (charges.compare(std::string("mmff94")) == 0)
          prepMol(mol);
      OEEon::OEEonOverlayScore score;
      eonPBOverlay.BestOverlay(score, mol, numtophits);
      hitlist.AddScore(score, mol);
  }
  hitlist.Build();
  for (auto hit : hitlist.GetHits())
  {
    OEChem::OEGraphMol hitMol = hit.GetMol();
    OEChem::OESetSDData(hitMol, "Shape Tanimoto", std::to_string(hit.GetTanimoto()));
    OEChem::OESetSDData(hitMol, "Potential Tanimoto", std::to_string(hit.GetETTanimoto()));
    OEChem::OESetSDData(hitMol, "Shape + Potential Tanimoto Combo", std::to_string(hit.GetTanimotoCombo()));
    OEChem::OEWriteMolecule(ofs, hitMol);
  }
  qfs.close();
  ifs.close();
  ofs.close();
}

Download code

eon_pb_overlay.cpp