Traversing File with an OEMolFileConverter

This is an example of a OEMolFileConverter creating a vector of an OERecord from a string file input.

Listing 1: Simple file traversal

/* 
(C) 2025 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 "openeye.h"

#include "oeplatform.h"
#include "oesystem.h"
#include "oechem.h"
#include "oeshape.h"

#include <string>
#include <vector>

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


int main(int argc,char *argv[])
{
  if (argc!=2)
    OEThrow.Usage("traverse <fileName>");

  string fname(argv[1]);

  OEMolFileConverter conv;
  OEMolConversionOptions opts;
  conv.Open(fname, opts);

  OEMolRecord record;
  std::vector<OERecord> newRecs;
  while (conv.GetNextRecord(record) == SaiphReturnCode::Success)
  {
    newRecs.push_back(record);
    record = OEMolRecord();
  }

  return 0;
}

Download code

basicFileTraversal.cpp

Set Schema Record to Shape OERecord Extraction

This example sets an OERecord as the schema to the OEMolConversionOptions, giving the OEMolFileConverter specific OEField to extract from the file given.

Listing 1: Sets Schema Record for ETL

/* 
(C) 2025 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 "openeye.h"

#include "oeplatform.h"
#include "oesystem.h"
#include "oechem.h"
#include "oeshape.h"

#include <string>
#include <vector>

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


int main(int argc,char *argv[])
{
  if (argc!=2)
    OEThrow.Usage("schemaETL <fileName>");

  string fname(argv[1]);

  OERecord schema;
  auto f1 = OEMakeField("Molecule", Types::Chem::Mol);
  f1.SetMeta(OEFieldMeta().SetOption(OEMetadata::Hints::Chem::SMILES));
  auto f2 = OEMakeField("External_ID", Types::String);
  auto f3 = OEMakeField("SAU Gyr IC50 (µM)", Types::Range);
  schema.AddField(f1);
  schema.AddField(f2);
  schema.AddField(f3);

  OEMolFileConverter conv;
  OEMolConversionOptions opts;
  opts.SetSchemaRecord(schema);
  conv.Open(fname, opts);

  OEMolRecord record;
  std::vector<OERecord> newRecs;
  while (conv.GetNextRecord(record) == SaiphReturnCode::Success)
  {
    newRecs.push_back(record);
    record = OEMolRecord();
  }

  return 0;
}

Download code

customSchemaETL.cpp

OERecord to OEMol

This example creates an OEMol from the first OERecord produced by the input file.

Listing 1: First OERecord to OEMol

/* 
(C) 2025 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 "openeye.h"

#include "oeplatform.h"
#include "oesystem.h"
#include "oechem.h"
#include "oeshape.h"

#include <string>

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


int main(int argc,char *argv[])
{
  if (argc!=2)
    OEThrow.Usage("record2mol <fileName>");

  string fname(argv[1]);

  OEMolFileConverter conv;
  OEMolConversionOptions opts;
  conv.Open(fname, opts);

  OEMolRecord record;
  conv.GetNextRecord(record);
  OEMol mol;
  OERecordToMol(record, mol, false, true);

  cout << "Molecule SMILES: " << OEMolToSmiles(mol) << endl;
  cout << "Number of Atoms: " << mol.NumAtoms() << endl;

  return 0;
}

Download code

record2mol.cpp

OEMol to OERecord

This example creates an OERecord from the OEMol found in the input file.

Listing 1: OEMol to OERecord

/* 
(C) 2025 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 "openeye.h"

#include "oeplatform.h"
#include "oesystem.h"
#include "oechem.h"
#include "oeshape.h"

#include <string>
#include <vector>

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


int main(int argc,char *argv[])
{
  if (argc!=2)
    OEThrow.Usage("mol2record <fileName>");

  string fname(argv[1]);

  oemolistream ifs;
  if (ifs.open(filepath.toStdString()))
  {
    OEMol mol;
    OEReadMolecule(ifs, mol);
    OEMolRecord r = OEMolToRecord(mol);
    std::vector<OEFieldBase> fields = r.GetFields();
    for (size_t i = 0; i < fields.size(); ++i)
    {
      cout << fields[i].GetName() << endl;
    }
  }

  return 0;
}

Download code

mol2record.cpp

OERecord to OEDesignUnit

This example creates an OEDesignUnit from an OERecord.

Listing 1: Sets Schema Record for ETL

/* 
(C) 2025 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 "openeye.h"

#include "oeplatform.h"
#include "oesystem.h"
#include "oechem.h"
#include "oeshape.h"
#include "oebio.h"

#include <string>

using namespace OEPlatform;
using namespace OESystem;
using namespace OEChem;
using namespace OEBio;
using namespace std;


int main(int argc,char *argv[])
{
  if (argc!=2)
    OEThrow.Usage("record2du <fileName>");

  string fname(argv[1]);

  OEDUFileConverter conv;
  conv.Open(fname);

  OEMolRecord record;
  conv.GetNextRecord(record);
  OEDesignUnit du;
  OERecordToDesignUnit(record, du);
  cout << "OEDesignUnit Title: " << du.GetTitle() << endl;

  return 0;
}

Download code

record2designunit.cpp

File Records to Pandas DataFrame

This example takes in a file and creates a pandas DataFrame from the OERecord produced. The user must have pandas installed in their Python environment to gain access to this function.