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

#!/usr/bin/env python
# (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.


from openeye import oechem
from openeye import oesaiph


def main(argv=[__name__]):
    if len(argv) != 2:
        oechem.OEThrow.Usage("%s <fileName>" % argv[0])

    converter = oesaiph.OEMolFileConverter()
    options = oesaiph.OEMolConversionOptions()
    converter.Open(sys.argv[1], options)

    record = oechem.OEMolRecord()
    recList = []
    while(converter.GetNextRecord(record) == oesaiph.Success):
        recList.append(record)
        record = oechem.OEMolRecord()
        

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

Download code

basicFileTraversal.py

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

#!/usr/bin/env python
# (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.


from openeye import oechem
from openeye import oesaiph


def main(argv=[__name__]):
    if len(argv) != 2:
        oechem.OEThrow.Usage("%s <fileName>" % argv[0])

    schema = oechem.OERecord()
    f1 = oechem.OEField("Molecule", oechem.Types.Chem.Mol)
    f1.set_meta(oechem.OEFieldMeta(options=[oechem.Meta.Hints.Chem.SMILES]))
    f2 = oechem.OEField("External_ID", oechem.Types.String)
    f3 = oechem.OEField("SAU Gyr IC50 (µM)", oechem.Types.Range)
    schema.add_field(f1)
    schema.add_field(f2)
    schema.add_field(f3)

    converter = oesaiph.OEMolFileConverter()
    options = oesaiph.OEMolConversionOptions()
    options.SetSchemaRecord(schema)
    converter.Open(sys.argv[1], options)

    record = oechem.OEMolRecord()
    recList = []
    while(converter.GetNextRecord(record) == oesaiph.Success):
        recList.append(record)
        record = oechem.OEMolRecord()
        

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

Download code

customSchemaETL.py

OERecord to OEMol

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

Listing 1: First OERecord to OEMol

#!/usr/bin/env python
# (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.


from openeye import oechem
from openeye import oesaiph


def main(argv=[__name__]):
    if len(argv) != 2:
        oechem.OEThrow.Usage("%s <fileName>" % argv[0])

    converter = oesaiph.OEMolFileConverter()
    options = oesaiph.OEMolConversionOptions()
    converter.Open(sys.argv[1], options)

    record = oechem.OEMolRecord()
    converter.GetNextRecord(record)

    mol = oechem.OEMol()
    oechem.OERecordToMol(record, mol, False, True)

    print("Molecule SMILES: ", oechem.OEMolToSmiles(mol))
    print("Number of Atoms: ", mol.NumAtoms())


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

Download code

record2mol.py

OEMol to OERecord

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

Listing 1: OEMol to OERecord

#!/usr/bin/env python
# (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.


from openeye import oechem
from openeye import oesaiph


def main(argv=[__name__]):
    if len(argv) != 2:
        oechem.OEThrow.Usage("%s <fileName>" % argv[0])

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

    mol = oechem.OEMol()
    oechem.OEReadMolecule(ifs, mol)
    rec = oesaiph.OEMolToRecord(mol)
    for fields in rec.get_fields(include_meta=False):
        print(fields.GetName())


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

Download code

mol2record.py

OERecord to OEDesignUnit

This example creates an OEDesignUnit from an OERecord.

Listing 1: Sets Schema Record for ETL

#!/usr/bin/env python
# (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.


from openeye import oechem
from openeye import oesaiph


def main(argv=[__name__]):
    if len(argv) != 2:
        oechem.OEThrow.Usage("%s <fileName>" % argv[0])

    converter = oesaiph.OEDUFileConverter()
    converter.Open(sys.argv[1])

    record = oechem.OEMolRecord()
    converter.GetNextRecord(record)

    du = oechem.OEDesignUnit()
    oechem.OERecordToDesignUnit(record, du)

    print("OEDesignUnit Title: ", du.GetTitle())


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

Download code

record2designunit.py

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.

Listing 1: Creates a DataFrame from File

#!/usr/bin/env python
# (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.

import pandas as pd
from openeye import oechem
from openeye import oesaiph


def main(argv=[__name__]):
    if len(argv) != 2:
        oechem.OEThrow.Usage("%s <fileName>" % argv[0])

    df = oesaiph.read_record_file_to_dataframe(sys.argv[1])
    print(df)

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