Appendix: Additional Examples in Python
These are full listings of programming examples that are excerpted or offered for download in this chapter. See the full list of examples elsewhere in this chapter.
Listing 1: Alternate location factory groups
#!/usr/bin/env python
# (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.
import sys
from openeye import oechem
def PrintAltGroupInfo(mol):
if not oechem.OEHasResidues(mol):
oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)
alf = oechem.OEAltLocationFactory(mol) # create factory for mol
print("%s\t(%s groups)" % (mol.GetTitle(), alf.GetGroupCount()))
for grp in alf.GetGroups():
print("\t%s locs:%s" % (grp.GetLocationCount(), alf.GetLocationCodes(grp)))
def main(argv=[__name__]):
if len(argv) != 2:
oechem.OEThrow.Usage("%s <mol-infile>" % argv[0])
ims = oechem.oemolistream()
if not ims.open(argv[1]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1])
# need this flavor to read alt loc atoms
ims.SetFlavor(oechem.OEFormat_PDB, oechem.OEIFlavor_PDB_ALTLOC)
ims.SetFlavor(oechem.OEFormat_MMCIF, oechem.OEIFlavor_MMCIF_ALTLOC)
for mol in ims.GetOEGraphMols():
PrintAltGroupInfo(mol)
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 2: Aromaticity perception with various models
#!/usr/bin/env python
# (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.
from openeye import oechem
def PerceiveAromaticity(mol, modelname, aromodel):
oechem.OEAssignAromaticFlags(mol, aromodel)
cansmi = oechem.OECreateCanSmiString(mol)
print(modelname, ":", cansmi)
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1ncncc1c2cocc2-c3[nH]ccc(=O)c3")
PerceiveAromaticity(mol, "OEAroModelOpenEye ", oechem.OEAroModel_OpenEye)
PerceiveAromaticity(mol, "OEAroModelDaylight", oechem.OEAroModel_Daylight)
PerceiveAromaticity(mol, "OEAroModelTripos ", oechem.OEAroModel_Tripos)
PerceiveAromaticity(mol, "OEAroModelMMFF ", oechem.OEAroModel_MMFF)
PerceiveAromaticity(mol, "OEAroModelMDL ", oechem.OEAroModel_MDL)
Listing 3: Substructure search with atom mappings
#!/usr/bin/env python
# (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.
from openeye import oechem
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1ccccc1C")
# create a substructure search object
ss = oechem.OESubSearch("c1ccccc1")
oechem.OEPrepareSearch(mol, ss)
# loop over matches
for count, match in enumerate(ss.Match(mol)):
print("Match", count + 1, ":", end=" ")
print("pattern atoms:", end=" ")
for ma in match.GetAtoms():
print(ma.pattern.GetIdx(), end=" ")
print("target atoms:", end=" ")
for ma in match.GetAtoms():
print(ma.target.GetIdx(), end=" ")
print()
Listing 4: Combining predefined atom predicates
#!/usr/bin/env python
# (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.
from openeye import oechem
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1cnc(O)cc1CCCBr")
print("Number of chain atoms =", end=" ")
print(oechem.OECount(mol, oechem.OENotAtom(oechem.OEAtomIsInRing())))
print("Number of aromatic nitrogens =", end=" ")
print(oechem.OECount(mol, oechem.OEAndAtom(oechem.OEIsNitrogen(), oechem.OEIsAromaticAtom())))
print("Number of non-carbons =", end=" ")
print(oechem.OECount(mol, oechem.OENotAtom(oechem.OEHasAtomicNum(oechem.OEElemNo_C))))
print("Number of nitrogen and oxygen atoms =", end=" ")
print(oechem.OECount(mol, oechem.OEOrAtom(oechem.OEHasAtomicNum(oechem.OEElemNo_N),
oechem.OEHasAtomicNum(oechem.OEElemNo_O))))
Listing 5: Combining predefined bond predicates
#!/usr/bin/env python
# (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.
from openeye import oechem
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "N#CCC1CCNC=C1")
print("Number of non-rotatable bonds =", end=" ")
print(oechem.OECount(mol, oechem.OENotBond(oechem.OEIsRotor())))
print("Number of ring double bonds =", end=" ")
print(oechem.OECount(mol, oechem.OEAndBond(oechem.OEBondIsInRing(), oechem.OEHasOrder(2))))
print("Number of double or triple bonds =", end=" ")
print(oechem.OECount(mol, oechem.OEOrBond(oechem.OEHasOrder(2), oechem.OEHasOrder(3))))
Listing 6: Clearing aromaticity
#!/usr/bin/env python
# (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.
from openeye import oechem
mol = oechem.OEGraphMol()
oechem.OEParseSmiles(mol, "n1ccncc1")
print("Canonical smiles :", oechem.OECreateCanSmiString(mol))
oechem.OEClearAromaticFlags(mol)
oechem.OEKekulize(mol)
print("Kekule smiles :", oechem.OECreateCanSmiString(mol))
Listing 7: Looping over hierarchical components
#!/usr/bin/env python
# (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.
import sys
from openeye import oechem
def CalcResCounts(mol):
hv = oechem.OEHierView(mol)
chainCt = 0
fragCt = 0
resCt = 0
watCt = 0
for chain in hv.GetChains():
chainCt += 1
for frag in chain.GetFragments():
fragCt += 1
for hres in frag.GetResidues():
resCt += 1
if (oechem.OEGetResidueIndex(hres.GetOEResidue()) ==
oechem.OEResidueIndex_HOH):
watCt += 1
print("Molecule : %s" % mol.GetTitle())
print("Chains : %d" % chainCt)
print("Fragments: %d" % fragCt)
print("Residues : %d (%d waters)" % (resCt, watCt))
def main(argv=[__name__]):
if len(argv) != 2:
oechem.OEThrow.Usage("%s <mol-infile>" % argv[0])
ims = oechem.oemolistream()
if not ims.open(argv[1]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1])
for mol in ims.GetOEGraphMols():
if not oechem.OEHasResidues(mol):
oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)
CalcResCounts(mol)
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 10: Retrieving a subset of a file
#!/usr/bin/env python
# (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.
from openeye import oechem
import sys
if len(sys.argv) != 5:
oechem.OEThrow.Usage("%s <input> <output> <offset> <limit>" % sys.argv[0])
moldb = oechem.OEMolDatabase()
if not moldb.Open(sys.argv[1]):
oechem.OEThrow.Fatal("Unable to open %s" % sys.argv[1])
if moldb.GetFormat() != oechem.OEGetFileType(oechem.OEGetFileExtension(sys.argv[2])):
oechem.OEThrow.Fatal("Output format does not match input format: %s != %s" %
(oechem.OEGetFileExtension(sys.argv[1]),
oechem.OEGetFileExtension(sys.argv[2])))
ofs = oechem.oemolostream()
if not ofs.open(sys.argv[2]):
oechem.OEThrow.Fatal("Unable to open %s for writing" % sys.argv[2])
offset = int(sys.argv[3])
limit = int(sys.argv[4])
maxIdx = offset + limit
for idx in range(offset, maxIdx):
moldb.WriteMolecule(ofs, idx)
Listing 11: Extract molecules by title
#!/usr/bin/env python
# (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.
from openeye import oechem
import sys
if len(sys.argv) != 4:
oechem.OEThrow.Usage("%s <input> <output> <title>" % sys.argv[0])
moldb = oechem.OEMolDatabase()
if not moldb.Open(sys.argv[1]):
oechem.OEThrow.Fatal("Unable to open %s" % sys.argv[1])
if moldb.GetFormat() != oechem.OEGetFileType(oechem.OEGetFileExtension(sys.argv[2])):
oechem.OEThrow.Fatal("Output format does not match input format: %s != %s" %
(oechem.OEGetFileExtension(sys.argv[1]),
oechem.OEGetFileExtension(sys.argv[2])))
ofs = oechem.oemolostream()
if not ofs.open(sys.argv[2]):
oechem.OEThrow.Fatal("Unable to open %s for writing" % sys.argv[2])
title = sys.argv[3]
for idx in range(moldb.GetMaxMolIdx()):
if moldb.GetTitle(idx) == title:
moldb.WriteMolecule(ofs, idx)
Listing 12: SD data manipulation
#!/usr/bin/env python
# (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.
from openeye import oechem
def DumpSDData(mol):
print("SD data of", mol.GetTitle())
# loop over SD data
for dp in oechem.OEGetSDDataPairs(mol):
print(dp.GetTag(), ':', dp.GetValue())
print()
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1ccccc1")
mol.SetTitle("benzene")
# set some tagged data
oechem.OESetSDData(mol, "color", "brown")
oechem.OESetSDData(mol, oechem.OESDDataPair("size", "small"))
DumpSDData(mol)
# check for existence of data, then delete it
if oechem.OEHasSDData(mol, "size"):
oechem.OEDeleteSDData(mol, "size")
DumpSDData(mol)
# add additional color data
oechem.OEAddSDData(mol, "color", "black")
DumpSDData(mol)
# remove all SD data
oechem.OEClearSDData(mol)
DumpSDData(mol)
Listing 13: Using Threaded Input and Output
#!/usr/bin/env python
# (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.
from openeye import oechem
import sys
ss = oechem.OESubSearch(sys.argv[1])
ifs = oechem.oemolithread(sys.argv[2])
ofs = oechem.oemolothread(sys.argv[3])
for mol in ifs.GetOEGraphMols():
oechem.OEPrepareSearch(mol, ss)
if ss.SingleMatch(mol):
oechem.OEWriteMolecule(ofs, mol)
Listing 14: Using multiple threads to read and write to molthreads
#!/usr/bin/env python
# (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.
from openeye import oechem
from threading import Thread
import sys
ss = oechem.OESubSearch(sys.argv[1])
ifs = oechem.oemolithread(sys.argv[2])
ofs = oechem.oemolothread(sys.argv[3])
class MultiCoreMolFind(Thread):
def run(self):
for mol in ifs.GetOEGraphMols():
oechem.OEPrepareSearch(mol, ss)
if ss.SingleMatch(mol):
oechem.OEWriteMolecule(ofs, mol)
thrds = []
for i in range(oechem.OEGetNumProcessors()):
thrd = MultiCoreMolFind()
thrd.start()
thrds.append(thrd)
for thrd in thrds:
thrd.join()
Listing 15: Setting mutexed memory pool mode
#!/usr/bin/env python
# (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.
from openeye import oechem
from threading import Thread
try:
from queue import Queue
except ImportError:
from Queue import Queue
import sys
ss = oechem.OESubSearch(sys.argv[1])
ifs = oechem.oemolithread(sys.argv[2])
ofs = oechem.oemolothread(sys.argv[3])
iqueue = Queue(1024)
oqueue = Queue(1024)
class ParseThread(Thread):
def run(self):
mol = oechem.OEGraphMol()
while oechem.OEReadMolecule(ifs, mol):
iqueue.put(mol, block=True)
mol = oechem.OEGraphMol()
# signal SearchThread to die
iqueue.put(None, block=True)
class SearchThread(Thread):
def run(self):
mol = iqueue.get(block=True)
while mol is not None:
oechem.OEPrepareSearch(mol, ss)
if ss.SingleMatch(mol):
oqueue.put(mol, block=True)
mol = iqueue.get(block=True)
# signal main thread to die
oqueue.put(None, block=True)
pthrd = ParseThread()
pthrd.start()
sthrd = SearchThread()
sthrd.start()
# main thread will handle output
mol = oqueue.get(block=True)
while mol is not None:
oechem.OEWriteMolecule(ofs, mol)
mol = oqueue.get(block=True)
Listing 16: PDB data manipulation
#!/usr/bin/env python
# (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.
from openeye import oechem
import sys
if len(sys.argv) != 2:
oechem.OEThrow.Usage("%s <pdbfile>" % sys.argv[0])
ifs = oechem.oemolistream()
if not ifs.open(sys.argv[1]):
oechem.OEThrow.Fatal("Unable to open %s" % sys.argv[1])
# need to set input flavor to ensure PDB data is stored on molecule
ifs.SetFlavor(oechem.OEFormat_PDB, oechem.OEIFlavor_PDB_SpruceDefault)
ifs.SetFlavor(oechem.OEFormat_MMCIF, oechem.OEIFlavor_MMCIF_SpruceDefault)
mol = oechem.OEGraphMol()
while oechem.OEReadMolecule(ifs, mol):
if oechem.OEHasPDBData(mol, "COMPND"):
print("COMPND:")
print(oechem.OEGetPDBData(mol, "COMPND"))
if oechem.OEHasPDBData(mol, "HELIX "):
print("HELIX:")
print(oechem.OEGetPDBData(mol, "HELIX "))
if oechem.OEHasPDBData(mol, "SSBOND"):
print("SSBOND:")
for dp in oechem.OEGetPDBDataPairs(mol):
if dp.GetTag() == "SSBOND":
print(dp.GetValue())
Listing 17: Simple substructure search example
#!/usr/bin/env python
# (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.
from openeye import oechem
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1ccccc1C")
# create a substructure search object
ss = oechem.OESubSearch("c1ccccc1")
oechem.OEPrepareSearch(mol, ss)
if ss.SingleMatch(mol):
print("benzene matches toluene")
else:
print("benzene does not match toluene")
Listing 18: Extracting molecules based upon a substructure
#!/usr/bin/env python
# (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.
from openeye import oechem
import sys
ss = oechem.OESubSearch(sys.argv[1])
ifs = oechem.oemolistream(sys.argv[2])
ofs = oechem.oemolostream(sys.argv[3])
for mol in ifs.GetOEGraphMols():
oechem.OEPrepareSearch(mol, ss)
if ss.SingleMatch(mol):
oechem.OEWriteMolecule(ofs, mol)
Listing 19: Substructures match for query molecule
#!/usr/bin/env python
# (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.
from openeye import oechem
qmol = oechem.OEGraphMol()
oechem.OESmilesToMol(qmol, "c1ccccc1")
# create a substructure search object
itag = oechem.OEGetTag("__orig_idx")
for ai in qmol.GetAtoms():
ai.SetData(itag, ai.GetIdx())
ss = oechem.OESubSearch(qmol, oechem.OEExprOpts_DefaultAtoms, oechem.OEExprOpts_DefaultBonds)
tmol = oechem.OEGraphMol()
oechem.OESmilesToMol(tmol, "Cc1ccccc1")
oechem.OEPrepareSearch(tmol, ss)
for mi in ss.Match(tmol, True):
match = oechem.OEMatch()
for apairi in mi.GetAtoms():
pidx = apairi.pattern.GetData(itag)
pattern = qmol.GetAtom(oechem.OEHasAtomIdx(pidx))
match.AddPair(pattern, apairi.target)
Listing 20: Using functor callbacks
#!/usr/bin/env python
# (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.
from openeye import oechem
def CountAtoms(mol, pred):
counts = 0
for atom in mol.GetAtoms():
if pred(atom):
counts += 1
return counts
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1cc[nH]c1CC2COCNC2")
print("Number of oxygen atoms =", CountAtoms(mol, oechem.OEIsOxygen()))
Listing 21: Using predefined atom functors
#!/usr/bin/env python
# (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.
from openeye import oechem
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1cc[nH]c1CC2COCNC2")
print("Number of heavy atoms =", oechem.OECount(mol, oechem.OEIsHeavy()))
print("Number of ring atoms =", oechem.OECount(mol, oechem.OEAtomIsInRing()))
Listing 22: Using predefined bond functors
#!/usr/bin/env python
# (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.
from openeye import oechem
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "CC(=O)Nc1c[nH]cc1")
print("Number of ring bonds =", oechem.OECount(mol, oechem.OEBondIsInRing()))
print("Number of rotor bonds =", oechem.OECount(mol, oechem.OEIsRotor()))
Listing 23: Functor substructure-based matching
#!/usr/bin/env python
# (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.
from openeye import oechem
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "C1(Cl)C(N)C(F)OC1C(=O)NCCCN")
NonAmideNitrogenPred = oechem.OEMatchAtom("[N;!$(NC=O)]")
print("Number of non-amide nitrogen =", oechem.OECount(mol, NonAmideNitrogenPred))
FiveMemberedRingOxygenPred = oechem.OEMatchAtom("[O;r5]")
print("Number of 5-membered ring oxygen =", oechem.OECount(mol, FiveMemberedRingOxygenPred))
CarbonAttachedToHalogenPred = oechem.OEMatchAtom("[#6][Cl,Br,F]")
print("Number of carbon attached to halogen =", oechem.OECount(mol, CarbonAttachedToHalogenPred))
Listing 24: Ring system extraction
#!/usr/bin/env python
# (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.
from openeye import oechem
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1cc[nH]c1CC2COCNC2")
nrrings, rings = oechem.OEDetermineRingSystems(mol)
pred = oechem.OEPartPredAtom(rings)
print("Number of rings =", nrrings)
for r in range(1, nrrings + 1):
pred.SelectPart(r)
ringmol = oechem.OEGraphMol()
oechem.OESubsetMol(ringmol, mol, pred, True)
print(r, "->", oechem.OEMolToSmiles(ringmol))
Listing 25: Ring system extraction
#!/usr/bin/env python
# (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.
from openeye import oechem
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1cc[nH]c1CC2COCNC2")
submol = oechem.OEGraphMol()
oechem.OESubsetMol(submol, mol, oechem.OEAtomIsInRing(), True)
print(oechem.OEMolToSmiles(submol))
Listing 26: Example of attaching a molecule as generic data
#!/usr/bin/env python
# (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.
from openeye import oechem
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1ccccc1O")
frag = oechem.OEGraphMol()
oechem.OESubsetMol(frag, mol, oechem.OEIsCarbon())
mol.SetData("just_carbon", frag)
justCarbon = mol.GetData("just_carbon")
Listing 27: Example of using generic data
#!/usr/bin/env python
# (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.
from openeye import oechem
def CalculateMoleculeWeight(mol):
mol.SetData("MolWeight", oechem.OECalculateMolecularWeight(mol))
def PrintMoleculeWeight(mol):
tag = oechem.OEGetTag("MolWeight")
if mol.HasData(tag):
print("molecule weight =", mol.GetData(tag))
else:
print("molecule weight is not calculated!")
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "C1CCCC(C(=O)O)C1")
CalculateMoleculeWeight(mol)
PrintMoleculeWeight(mol)
Listing 28: Example of attaching generic data to atoms
#!/usr/bin/env python
# (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.
from openeye import oechem
IsDonorAtom = oechem.OEMatchAtom("[!H0;#7,#8]")
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1c(Cl)cncc1C(=O)O")
for atom in mol.GetAtoms():
atom.SetData("isdonor", IsDonorAtom(atom))
class IsDonorAtomPred(oechem.OEUnaryAtomPred):
def __call__(self, atom):
return atom.GetData("isdonor")
print("Donor atoms:", end=" ")
for atom in mol.GetAtoms(IsDonorAtomPred()):
print(atom.GetIdx(), oechem.OEGetAtomicSymbol(atom.GetAtomicNum()), end=" ")
print()
Listing 29: Getting started with OEInterface command line parsing
#!/usr/bin/env python
# (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.
from openeye import oechem
import sys
InterfaceData = """
!PARAMETER -b
!TYPE bool
!BRIEF A boolean parameter
!END
!PARAMETER -i
!TYPE int
!BRIEF An integer parameter
!END
!PARAMETER -f
!TYPE float
!BRIEF A float parameter
!END
!PARAMETER -str
!TYPE string
!BRIEF A string parameter
!END
"""
itf = oechem.OEInterface(InterfaceData, sys.argv)
print("-b =", itf.GetBool("-b"))
print("-i =", itf.GetInt("-i"))
print("-f =", itf.GetFloat("-f"))
print("-str =", itf.GetString("-str"))
Listing 30: Retrieving the Nth molecule in a file
#!/usr/bin/env python
# (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.
from openeye import oechem
import sys
if len(sys.argv) != 4:
oechem.OEThrow.Usage("%s <input> <output> <index>" % sys.argv[0])
moldb = oechem.OEMolDatabase()
if not moldb.Open(sys.argv[1]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % sys.argv[1])
ofs = oechem.oemolostream()
if not ofs.open(sys.argv[2]):
oechem.OEThrow.Fatal("Unable to open %s for writing" % sys.argv[2])
idx = int(sys.argv[3])
mol = oechem.OEMol()
if not moldb.GetMolecule(mol, idx):
oechem.OEThrow.Fatal("Unable to read a molecule from index %u" % idx)
oechem.OEWriteMolecule(ofs, mol)
Listing 31: Example of using molecule parameter
#!/usr/bin/env python
# (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.
from openeye import oechem
import sys
InterfaceData = """
!PARAMETER -mol
!TYPE OEGraphMol
!BRIEF Molecule file
!REQUIRED true
!KEYLESS 1
!END
"""
def main(argv=[__name__]):
itf = oechem.OEInterface(InterfaceData, argv)
mol = itf.GetOEGraphMol("-mol")
print("Number of heavy atoms in molecule = %d" % oechem.OECount(mol, oechem.OEIsHeavy()))
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 32: Aromatic ring system identification
#!/usr/bin/env python
# (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.
from openeye import oechem
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "C(O)(=O)c1cccc2c1[nH]c(C3CCCc4c3cccc4)c2")
nraromsystems, parts = oechem.OEDetermineAromaticRingSystems(mol)
print("Aliphatic atoms:", end=" ")
for atom in mol.GetAtoms():
if parts[atom.GetIdx()] == 0:
print(atom.GetIdx(), end=" ")
print()
print("Number of aromatic ring systems =", nraromsystems)
for ringidx in range(1, nraromsystems + 1):
print(ringidx, ". aromatic ring system:", end=" ")
for atom in mol.GetAtoms():
if parts[atom.GetIdx()] == ringidx:
print(atom.GetIdx(), end=" ")
print()
Listing 33: Accessing atom stereo information
#!/usr/bin/env python
# (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.
from openeye import oechem
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "[H][C@]1(NC[C@@H](CC1CO[C@H]2CC[C@@H](CC2)O)N)[H]")
for atom in mol.GetAtoms():
chiral = atom.IsChiral()
stereo = oechem.OEAtomStereo_Undefined
if atom.HasStereoSpecified(oechem.OEAtomStereo_Tetrahedral):
v = []
for nbr in atom.GetAtoms():
v.append(nbr)
stereo = atom.GetStereo(v, oechem.OEAtomStereo_Tetrahedral)
if chiral or stereo != oechem.OEAtomStereo_Undefined:
print("Atom:", atom.GetIdx(), "chiral=", chiral, "stereo=", end=" ")
if stereo == oechem.OEAtomStereo_RightHanded:
print("right handed")
elif stereo == oechem.OEAtomStereo_LeftHanded:
print("left handed")
else:
print("undefined")
Listing 34: Accessing bond stereo information
#!/usr/bin/env python
# (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.
from openeye import oechem
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "C\\C=C\\C=C/C=CC")
for bond in mol.GetBonds():
if bond.HasStereoSpecified(oechem.OEBondStereo_CisTrans):
for atomB in bond.GetBgn().GetAtoms():
if atomB == bond.GetEnd():
continue
for atomE in bond.GetEnd().GetAtoms():
if atomE == bond.GetBgn():
continue
v = []
v.append(atomB)
v.append(atomE)
stereo = bond.GetStereo(v, oechem.OEBondStereo_CisTrans)
print("Atoms:", atomB.GetIdx(), "and", atomE.GetIdx(), "are", end=" ")
if stereo == oechem.OEBondStereo_Cis:
print("cis")
elif stereo == oechem.OEBondStereo_Trans:
print("trans")
Listing 35: Perceiving CIP atom stereo information
#!/usr/bin/env python
# (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.
from openeye import oechem
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "N[C@@H]1N[C@@H](O)CC(O)C1.C2[C@@H](O)CC[C@@H](O)C2")
for atom in mol.GetAtoms():
cip = oechem.OEPerceiveCIPStereo(mol, atom)
if atom.HasStereoSpecified():
print("atom %d is" % atom.GetIdx(), end=" ")
if cip == oechem.OECIPAtomStereo_S:
print('S')
if cip == oechem.OECIPAtomStereo_R:
print('R')
if cip == oechem.OECIPAtomStereo_NotStereo:
print('not a CIP stereo center')
if cip == oechem.OECIPAtomStereo_UnspecStereo:
print("atom %d is" % atom.GetIdx(), end=" ")
print('a CIP stereo center without specified stereochemistry')
Listing 36: Perceiving CIP bond stereo information
#!/usr/bin/env python
# (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.
from openeye import oechem
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "C\\C(C)=C(\\C)C.O\\C(C)=C(\\C)O.O\\C(C)=C(\\O)C.CC(O)=C(O)C")
for bond in mol.GetBonds():
if bond.GetOrder() == 2:
cip = oechem.OEPerceiveCIPStereo(mol, bond)
print("bond %d is" % bond.GetIdx(), end=" ")
if bond.HasStereoSpecified():
if cip == oechem.OECIPBondStereo_E:
print('E')
if cip == oechem.OECIPBondStereo_Z:
print('Z')
if cip == oechem.OECIPBondStereo_NotStereo:
print('not a CIP stereo center')
if cip == oechem.OECIPBondStereo_UnspecStereo:
print('a CIP stereo center without specified stereochemistry')
Listing 37: Constructing a scalar grid
#!/usr/bin/env python
# (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.
from openeye import oegrid
grid = oegrid.OEScalarGrid(64, 64, 64, 0.0, 0.0, 0.0, 0.5)
Listing 38: Setting atom stereo information
#!/usr/bin/env python
# (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.
from openeye import oechem
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "[H][C@]1(NC[C@@H](CC1CO[C@H]2CC[C@@H](CC2)O)N)[H]")
for atom in mol.GetAtoms():
if atom.IsChiral() and not atom.HasStereoSpecified(oechem.OEAtomStereo_Tetrahedral):
v = []
for neigh in atom.GetAtoms():
v.append(neigh)
atom.SetStereo(v, oechem.OEAtomStereo_Tetra, oechem.OEAtomStereo_Left)
print(oechem.OEMolToSmiles(mol))
Listing 39: Setting bond stereo information
#!/usr/bin/env python
# (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.
from openeye import oechem
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "C\\C=C\\C=C/C=CC")
for bond in mol.GetBonds():
if bond.GetOrder() == 2 and not bond.HasStereoSpecified(oechem.OEBondStereo_CisTrans):
v = []
for neigh in bond.GetBgn().GetAtoms():
if neigh != bond.GetEnd():
v.append(neigh)
break
for neigh in bond.GetEnd().GetAtoms():
if neigh != bond.GetBgn():
v.append(neigh)
break
bond.SetStereo(v, oechem.OEBondStereo_CisTrans, oechem.OEBondStereo_Trans)
print(oechem.OEMolToSmiles(mol))
Listing 40: Accessing OEResidue properties
#!/usr/bin/env python
# (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.
import sys
from openeye import oechem
def CalcResCounts(mol):
if not oechem.OEHasResidues(mol):
oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)
resCt = 0
hetCt = 0
prevRes = oechem.OEResidue()
for atom in mol.GetAtoms():
thisRes = oechem.OEAtomGetResidue(atom)
if not oechem.OESameResidue(prevRes, thisRes):
resCt += 1
if thisRes.IsHetAtom():
hetCt += 1
prevRes = thisRes
print("Molecule: %s" % mol.GetTitle())
print("Residues: %d (%d hets)" % (resCt, hetCt))
def main(argv=[__name__]):
if len(argv) != 2:
oechem.OEThrow.Usage("%s <mol-infile>" % argv[0])
ims = oechem.oemolistream()
if not ims.open(argv[1]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1])
for mol in ims.GetOEGraphMols():
CalcResCounts(mol)
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 41: User defined atom predicate
#!/usr/bin/env python
# (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.
from openeye import oechem
class PredAliphaticNitrogen(oechem.OEUnaryAtomPred):
def __call__(self, atom):
return atom.IsNitrogen() and not atom.IsAromatic()
def CreateCopy(self):
# __disown__ is required to allow C++ to take ownership of this
# object and its memory
return PredAliphaticNitrogen().__disown__()
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1cc[nH]c1CC2COCNC2")
print("Number of aliphatic N atoms =", end=" ")
print(oechem.OECount(mol, PredAliphaticNitrogen()))
Listing 42: User defined atom predicate with state
#!/usr/bin/env python
# (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.
from openeye import oechem
class PredAtomicNumList(oechem.OEUnaryAtomPred):
def __init__(self, alist):
oechem.OEUnaryAtomPred.__init__(self)
self.atomiclist = alist
def __call__(self, atom):
return (atom.GetAtomicNum() in self.atomiclist)
def CreateCopy(self):
# __disown__ is required to allow C++ to take ownership of this
# object and its memory
return PredAtomicNumList(self.atomiclist).__disown__()
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1cc[nH]c1CC2COCNC2")
alist = [oechem.OEElemNo_O, oechem.OEElemNo_N]
print("Number of oxygen or nitrogen atoms =", end=" ")
print(oechem.OECount(mol, PredAtomicNumList(alist)))
Listing 43: User defined bond predicate
#!/usr/bin/env python
# (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.
from openeye import oechem
class PredHasDoubleBondO(oechem.OEUnaryAtomPred):
def __call__(self, atom):
for bond in atom.GetBonds():
if bond.GetOrder() == 2 and bond.GetNbr(atom).IsOxygen():
return True
return False
def CreateCopy(self):
# __disown__ is required to allow C++ to take ownership of this
# object and its memory
return PredHasDoubleBondO().__disown__()
class PredAmideBond(oechem.OEUnaryBondPred):
def __call__(self, bond):
if bond.GetOrder() != 1:
return False
atomB = bond.GetBgn()
atomE = bond.GetEnd()
pred = PredHasDoubleBondO()
if atomB.IsCarbon() and atomE.IsNitrogen() and pred(atomB):
return True
if atomB.IsNitrogen() and atomE.IsCarbon() and pred(atomE):
return True
return False
def CreateCopy(self):
# __disown__ is required to allow C++ to take ownership of this
# object and its memory
return PredAmideBond().__disown__()
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "CC(=O)Nc1c[nH]cc1")
print("Number of amide bonds =", oechem.OECount(mol, PredAmideBond()))
Listing 44: Setting a default value for a parameter
#!/usr/bin/env python
# (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.
from openeye import oechem
import sys
InterfaceData = """
!PARAMETER -b
!TYPE bool
!DEFAULT false
!BRIEF An boolean parameter
!END
!PARAMETER -i
!TYPE int
!DEFAULT 2
!BRIEF An integer parameter
!END
!PARAMETER -f
!TYPE float
!DEFAULT 0.5
!BRIEF A float parameter
!END
!PARAMETER -str
!TYPE string
!DEFAULT foo
!BRIEF A string parameter
!END
"""
itf = oechem.OEInterface(InterfaceData, sys.argv)
print("-b =", itf.GetBool("-b"))
print("-i =", itf.GetInt("-i"))
print("-f =", itf.GetFloat("-f"))
print("-str =", itf.GetString("-str"))
Listing 45: Testing for parameter existence with the Has method
#!/usr/bin/env python
# (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.
from openeye import oechem
import sys
InterfaceData = """
!PARAMETER -b
!TYPE bool
!BRIEF An boolean parameter
!END
!PARAMETER -i
!TYPE int
!BRIEF An integer parameter
!END
!PARAMETER -f
!TYPE float
!BRIEF A float parameter
!END
!PARAMETER -str
!TYPE string
!BRIEF A string parameter
!END
"""
itf = oechem.OEInterface(InterfaceData, sys.argv)
if itf.HasBool("-b"):
print("-b =", itf.GetBool("-b"))
if itf.HasInt("-i"):
print("-i =", itf.GetInt("-i"))
if itf.HasFloat("-f"):
print("-f =", itf.GetFloat("-f"))
if itf.HasString("-str"):
print("-str =", itf.GetString("-str"))
Listing 46: A program to concatenate any number of molecules together
#!/usr/bin/env python
# (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.
from openeye import oechem
import sys
InterfaceData = """
!BRIEF UsingOEInterfaceHelp.py [-d <delimiter>] [-o] <output> [-i] <input1> <input2> ...
!PARAMETER -delim
!ALIAS -d
!TYPE string
!SIMPLE true
!DEFAULT _
!BRIEF Title delimiter
!DETAIL
This is the value given to the OEChem function OEAddMols to
separate the titles of the input molecules in the output.
!END
!PARAMETER -output
!ALIAS -o
!TYPE string
!SIMPLE true
!REQUIRED true
!KEYLESS 1
!BRIEF The output file
!DETAIL
The molecule file to output to, can be any file format
OEChem supports.
!END
!PARAMETER -inputs
!ALIAS -i
!TYPE string
!SIMPLE true
!REQUIRED true
!LIST true
!KEYLESS 2
!BRIEF The input files
!DETAIL
A list of molecule files to add together. Note, only the
first molecule from every file will be added.
!END
"""
def main(argv=[__name__]):
itf = oechem.OEInterface(InterfaceData, argv)
outmol = oechem.OEGraphMol()
for fname in itf.GetStringList("-inputs"):
ims = oechem.oemolistream(fname)
inmol = oechem.OEGraphMol()
oechem.OEReadMolecule(ims, inmol)
oechem.OEAddMols(outmol, inmol, itf.GetString("-delim"))
oms = oechem.oemolostream(itf.GetString("-output"))
oechem.OEWriteMolecule(oms, outmol)
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 47: Specifying keyless input and output file parameters
#!/usr/bin/env python
# (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.
from openeye import oechem
import sys
InterfaceData = """
!PARAMETER -i
!TYPE string
!KEYLESS 1
!BRIEF Input file name
!END
!PARAMETER -o
!TYPE string
!KEYLESS 2
!BRIEF Output file name
!END
"""
itf = oechem.OEInterface(InterfaceData, sys.argv)
print("Input file name =", itf.GetString("-i"))
print("Output file name =", itf.GetString("-o"))
Listing 48: Specifying that a parameter is a list of values
#!/usr/bin/env python
# (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.
from openeye import oechem
import sys
InterfaceData = """
!PARAMETER -strs
!TYPE string
!LIST true
!BRIEF Some string parameters
!END
"""
itf = oechem.OEInterface(InterfaceData, sys.argv)
print("-strs =", end=" ")
for param in itf.GetStringList("-strs"):
print(param)
print(" ", end=" ")
Listing 49: Requiring all parameters to be specified.
#!/usr/bin/env python
# (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.
from openeye import oechem
import sys
InterfaceData = """
!PARAMETER -b
!TYPE bool
!REQUIRED true
!BRIEF An boolean parameter
!END
!PARAMETER -i
!TYPE int
!REQUIRED true
!BRIEF An integer parameter
!END
!PARAMETER -f
!TYPE float
!REQUIRED true
!BRIEF A float parameter
!END
!PARAMETER -str
!TYPE string
!REQUIRED true
!BRIEF A string parameter
!END
"""
itf = oechem.OEInterface(InterfaceData, sys.argv)
print("-b =", itf.GetBool("-b"))
print("-i =", itf.GetInt("-i"))
print("-f =", itf.GetFloat("-f"))
print("-str =", itf.GetString("-str"))
Listing 50: Writing out SD data as CSV
#!/usr/bin/env python
# (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.
from openeye import oechem
ofs = oechem.oemolostream()
ofs.SetFormat(oechem.OEFormat_CSV)
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "O")
mol.SetTitle("water")
oechem.OESetSDData(mol, "phases", "gas,liquid,solid")
oechem.OESetSDData(mol, "uses", "bathing\nwater guns\ntea|earl grey|hot")
oechem.OEWriteMolecule(ofs, mol)
Listing 51: Print anisotropic B-factors.
#!/usr/bin/env python
# (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.
#############################################################################
# Output anisotropic B factor information
#############################################################################
import sys
from openeye import oechem
def main(argv=[__name__]):
itf = oechem.OEInterface(InterfaceData, argv)
verbose = itf.GetBool("-verbose")
ifname = itf.GetString("-input")
ims = oechem.oemolistream()
if not ims.open(ifname):
oechem.OEThrow.Fatal("Unable to open %s for reading" % ifname)
ims.SetFlavor(oechem.OEFormat_PDB, oechem.OEIFlavor_PDB_Default | oechem.OEIFlavor_PDB_DATA)
for mol in ims.GetOEMols():
if verbose:
if not oechem.OEHasResidues(mol):
oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)
for atom in mol.GetAtoms():
res = oechem.OEAtomGetResidue(atom)
uij = oechem.OEAnisoUij()
if oechem.OEGetAnisou(uij, atom):
oechem.OEThrow.Info("%s %s%c %s%d%c %c (u11=%5d, u22=%5d, u33=%5d, \
u12=%5d, u13=%5d, u23=%5d)" %
(mol.GetTitle(),
atom.GetName(),
res.GetAlternateLocation(),
res.GetName(),
res.GetResidueNumber(),
res.GetInsertCode(),
res.GetChainID(),
uij.GetU11(),
uij.GetU22(),
uij.GetU33(),
uij.GetU12(),
uij.GetU13(),
uij.GetU23()))
else:
oechem.OEThrow.Info("%s %s%c %s%d%c %c -no-anisou-" % (mol.GetTitle(),
atom.GetName(),
res.GetAlternateLocation(),
res.GetName(),
res.GetResidueNumber(),
res.GetInsertCode(),
res.GetChainID()))
oechem.OEThrow.Info("%s %d atoms with anisou data (out of %d)" % (mol.GetTitle(),
oechem.OECount(mol, oechem.OEHasAnisou()),
mol.NumAtoms()))
return 0
InterfaceData = """\
!BRIEF [-v] [-i] <mol file>
!CATEGORY "input options"
!PARAMETER -input
!ALIAS -i
!TYPE string
!REQUIRED true
!BRIEF input mol file name
!KEYLESS 1
!END
!END
!CATEGORY "options"
!PARAMETER -verbose
!ALIAS -v
!TYPE bool
!DEFAULT false
!BRIEF verbose
!END
!END
"""
#############################################################################
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 52: Append 2D ring dictionary.
#!/usr/bin/env python
# (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.
#############################################################################
# Appends rings to an existing 2D rings dictionary
#############################################################################
import sys
from openeye import oechem
def main(argv=[__name__]):
itf = oechem.OEInterface(InterfaceData, argv)
ifname = itf.GetString("-in")
irdfname = itf.GetString("-inringdict")
ordfname = itf.GetString("-outringdict")
ifs = oechem.oemolistream()
if not ifs.open(ifname):
oechem.OEThrow.Fatal("Unable to open %s for reading!" % ifname)
if not oechem.OEIs2DFormat(ifs.GetFormat()):
oechem.OEThrow.Fatal("Invalid input file format for 2D coordinates!")
if not oechem.OEIsValid2DRingDictionary(irdfname):
oechem.OEThrow.Fatal("Invalid ring dirctinary file!")
ringdict = oechem.OE2DRingDictionary(irdfname)
nrrings = ringdict.NumRings()
dots = oechem.OEDots(10000, 100, "molecules")
for mol in ifs.GetOEGraphMols():
dots.Update()
ringdict.AddRings(mol)
dots.Total()
nrnewrings = ringdict.NumRings() - nrrings
oechem.OEThrow.Info("%d new ring templates have been added!" % nrnewrings)
oechem.OEWrite2DRingDictionary(ordfname, ringdict)
return 0
#############################################################################
# INTERFACE
#############################################################################
InterfaceData = """
!BRIEF [-in] <input> [-inringdict] <input ringdict> [-outringdict] <output ringdict>
!CATEGORY "input/output options :"
!PARAMETER -in
!ALIAS -i
!TYPE string
!REQUIRED true
!KEYLESS 1
!VISIBILITY simple
!BRIEF Input 2D molecule filename
!END
!PARAMETER -inringdict
!ALIAS -ird
!TYPE string
!REQUIRED true
!KEYLESS 2
!VISIBILITY simple
!BRIEF Input ring dictionary OEB filename
!DETAIL
2D ring dictionaries can be generated by the following OEChem examples:
C++ - createringdict.cpp
Python - createringdict.py
Java - CreateRingDict.java
C# - CreateRingDict.cs
!END
!PARAMETER -outringdict
!ALIAS -ord
!TYPE string
!REQUIRED true
!KEYLESS 3
!VISIBILITY simple
!BRIEF Output ring dictionary OEB filename
!END
!END
"""
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 53: Use a SMIRKS specification to perform individual reaction transformations on single molecules.
#!/usr/bin/env python
# (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.
#############################################################################
# Apply a transformation
#############################################################################
import sys
from openeye import oechem
def main(argv=[__name__]):
itf = oechem.OEInterface(InterfaceData, argv)
opts = oechem.OEUniMolecularRxnOptions()
opts.SetStrictSmirks(itf.GetBool("-strict"))
opts.SetClearCoordinates(itf.GetBool("-clearcoords"))
opts.SetValidateKekule(itf.GetBool("-validkek"))
opts.SetMaxMatches(itf.GetInt("-max"))
altered = itf.GetString("-alteredtag")
opts.SetAlteredTag("")
if altered:
opts.SetAlteredTag(altered)
fixval = itf.GetString("-fixval")
if fixval.upper() == "EXPLICIT" or fixval.upper() == "NONE":
opts.SetFixValence(oechem.OEUniMolecularRxnFixValence_Explicit)
elif fixval.upper() == "ALTERED":
opts.SetFixValence(oechem.OEUniMolecularRxnFixValence_Altered)
elif fixval.upper() == "ALL":
opts.SetFixValence(oechem.OEUniMolecularRxnFixValence_All)
else:
oechem.Error("Unknown fix valence request: {}".format(fixval))
xform = itf.GetString("-smirks")
xformname = None
if " " in xform:
xform, xformname = xform.split(" ")[:2]
qrxn = oechem.OEQMol()
if not oechem.OEParseSmirks(qrxn, xform):
oechem.Fatal("SMIRKS parse error: {}".format(xform))
umr = oechem.OEUniMolecularRxn()
if not umr.Init(xform, opts):
oechem.Fatal("Error initializing OEUniMolecularRxn: {}".format(xform))
ifs = oechem.oemolistream()
if not ifs.open(itf.GetString("-in")):
oechem.OEThrow.Fatal(
"Unable to open {} for reading".format(itf.GetString("-in"))
)
ofs = oechem.oemolostream()
if not ofs.open(itf.GetString("-out")):
oechem.OEThrow.Fatal(
"Unable to open {} for writing".format(itf.GetString("-out"))
)
outfails = None
if itf.HasString("-noxform"):
print('noform=[{}]'.format(itf.GetString("-noxform")))
outfails = oechem.oemolostream()
if not outfails.open(itf.GetString("-noxform")):
oechem.OEThrow.Fatal(
"Unable to open failure file {} for writing".format(itf.GetString("-noxform"))
)
all2output = itf.GetBool("-passfail")
asrxn = itf.GetBool("-asrxn")
outmol = oechem.OEGraphMol()
for mol in ifs.GetOEGraphMols():
title = mol.GetTitle()
insmi = oechem.OEMolToSmiles(mol)
status = umr(mol)
if status or all2output:
if not asrxn:
if status and xformname:
mol.SetTitle("{}({})".format(xformname, mol.GetTitle()))
if (
oechem.OEWriteMolecule(ofs, mol)
!= oechem.OEWriteMolReturnCode_Success
):
oechem.Fatal(
"Error writing molecule: {}".format(oechem.OEMolToSmiles(mol))
)
else:
if not status:
outmol = mol
else:
oechem.OESmilesToMol(
outmol, "{}>>{}".format(insmi, oechem.OEMolToSmiles(mol))
)
if xformname:
outmol.SetTitle("{}({})".format(xformname, title))
else:
outmol.SetTitle(title)
if (
oechem.OEWriteMolecule(ofs, outmol)
!= oechem.OEWriteMolReturnCode_Success
):
oechem.Fatal(
"Error writing molecule: {}".format(
oechem.OEMolToSmiles(outmol)
)
)
elif outfails and not status:
if (
oechem.OEWriteMolecule(outfails, mol)
!= oechem.OEWriteMolReturnCode_Success
):
oechem.Fatal(
"Error writing molecule: {}".format(oechem.OEMolToSmiles(mol))
)
return 0
InterfaceData = """
!BRIEF -smirks SMIRKS -in <input> -out <output>
!CATEGORY I/O
!PARAMETER -smirks 1
!ALIAS -xform
!TYPE string
!REQUIRED true
!BRIEF Transformation SMIRKS
!KEYLESS 1
!END
!PARAMETER -in 2
!ALIAS -i
!TYPE string
!REQUIRED true
!BRIEF Input file name
!KEYLESS 2
!END
!PARAMETER -out 3
!ALIAS -o
!ALIAS -success
!TYPE string
!REQUIRED true
!BRIEF Output file name
!KEYLESS 3
!END
!PARAMETER -noxform 4
!ALIAS -failure
!TYPE string
!REQUIRED false
!BRIEF Output file name for untransformed structures
!END
!END
!CATEGORY Options
!PARAMETER -strict 1
!ALIAS -strictsmirks
!TYPE bool
!REQUIRED false
!DEFAULT true
!BRIEF requested strict flag which controls the interpretation of the transformation SMIRKS (true:Daylight convention, false:OpenEye convention)
!END
!PARAMETER -clearcoords 2
!TYPE bool
!REQUIRED false
!DEFAULT true
!BRIEF whether to clear coordinates for transformed products
!END
!PARAMETER -validkek 3
!ALIAS -validkekule
!TYPE bool
!REQUIRED false
!DEFAULT true
!BRIEF whether the transformation validates the Kekule form of the transformed products
!END
!PARAMETER -fixval 4
!TYPE string
!REQUIRED false
!DEFAULT Explicit
!BRIEF type of valence correction to apply to the transformed products: Explicit(None), Altered, All
!END
!PARAMETER -max 5
!ALIAS -maxxforms
!TYPE int
!REQUIRED false
!DEFAULT 10
!BRIEF maximum number of transformation to apply to each processed molecule
!END
!PARAMETER -alteredtag 6
!TYPE string
!REQUIRED false
!DEFAULT None
!BRIEF A generic data tag to mark altered atom information from transformed products
!END
!PARAMETER -passfail 7
!TYPE bool
!REQUIRED false
!DEFAULT false
!BRIEF If true, include untransformed structures in -out
!END
!PARAMETER -asrxn 8
!TYPE bool
!REQUIRED false
!DEFAULT false
!BRIEF If true, output the transformation as a reaction
!END
!END
!END
"""
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 54: Use a SMIRKS specification to perform individual reaction transformations on each input molecule.
#!/usr/bin/env python
# (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.
#############################################################################
# Apply a transformation
#############################################################################
import sys
from openeye import oechem
def main(argv=[__name__]):
itf = oechem.OEInterface(InterfaceData, argv)
opts = oechem.OEUniMolecularRxnOptions()
opts.SetStrictSmirks(itf.GetBool("-strict"))
opts.SetClearCoordinates(itf.GetBool("-clearcoords"))
opts.SetValidateKekule(itf.GetBool("-validkek"))
opts.SetMaxMatches(itf.GetInt("-max"))
altered = itf.GetString("-alteredtag")
opts.SetAlteredTag("")
if altered:
opts.SetAlteredTag(altered)
fixval = itf.GetString("-fixval")
if fixval.upper() == "EXPLICIT" or fixval.upper() == "NONE":
opts.SetFixValence(oechem.OEUniMolecularRxnFixValence_Explicit)
elif fixval.upper() == "ALTERED":
opts.SetFixValence(oechem.OEUniMolecularRxnFixValence_Altered)
elif fixval.upper() == "ALL":
opts.SetFixValence(oechem.OEUniMolecularRxnFixValence_All)
else:
oechem.Error("Unknown fix valence request: {}".format(fixval))
xform = itf.GetString("-smirks")
xformname = None
if " " in xform:
xform, xformname = xform.split(" ")[:2]
qrxn = oechem.OEQMol()
if not oechem.OEParseSmirks(qrxn, xform):
oechem.Fatal("SMIRKS parse error: {}".format(xform))
ifs = oechem.oemolistream()
if not ifs.open(itf.GetString("-in")):
oechem.OEThrow.Fatal(
"Unable to open {} for reading".format(itf.GetString("-in"))
)
ofs = oechem.oemolostream()
if not ofs.open(itf.GetString("-out")):
oechem.OEThrow.Fatal(
"Unable to open {} for writing".format(itf.GetString("-out"))
)
outfails = None
if itf.HasString("-noxform"):
print('noform=[{}]'.format(itf.GetString("-noxform")))
outfails = oechem.oemolostream()
if not outfails.open(itf.GetString("-noxform")):
oechem.OEThrow.Fatal(
"Unable to open failure file {} for writing".format(itf.GetString("-noxform"))
)
all2output = itf.GetBool("-passfail")
asrxn = itf.GetBool("-asrxn")
outxfmmol = oechem.OEGraphMol()
for mol in ifs.GetOEGraphMols():
title = mol.GetTitle()
insmi = oechem.OEMolToSmiles(mol)
nxforms = 0
for xfmmol in oechem.OEGetUniMolecularRxnIter(mol, qrxn, opts):
nxforms += 1
if not asrxn:
if xformname:
xfmmol.SetTitle("{}:{}({})".format(nxforms, xformname, mol.GetTitle()))
if (
oechem.OEWriteMolecule(ofs, xfmmol)
!= oechem.OEWriteMolReturnCode_Success
):
oechem.Fatal(
"Error writing molecule: {}".format(oechem.OEMolToSmiles(xfmmol))
)
else:
oechem.OESmilesToMol(
outxfmmol, "{}>>{}".format(insmi, oechem.OEMolToSmiles(xfmmol))
)
if xformname:
outxfmmol.SetTitle("{}:{}({})".format(nxforms, xformname, title))
else:
outxfmmol.SetTitle(title)
if (
oechem.OEWriteMolecule(ofs, outxfmmol)
!= oechem.OEWriteMolReturnCode_Success
):
oechem.Fatal(
"Error writing molecule: {}".format(
oechem.OEMolToSmiles(outxfmmol)
)
)
if not nxforms:
if all2output:
if (
oechem.OEWriteMolecule(ofs, mol)
!= oechem.OEWriteMolReturnCode_Success
):
oechem.Fatal(
"Error writing untransformed molecule: {}".format(oechem.OEMolToSmiles(xfmmol))
)
elif outfails:
if (
oechem.OEWriteMolecule(outfails, mol)
!= oechem.OEWriteMolReturnCode_Success
):
oechem.Fatal(
"Error writing untransformed molecule: {}".format(oechem.OEMolToSmiles(mol))
)
return 0
InterfaceData = """
!BRIEF -smirks SMIRKS -in <input> -out <output>
!CATEGORY I/O
!PARAMETER -smirks 1
!ALIAS -xform
!TYPE string
!REQUIRED true
!BRIEF Transformation SMIRKS
!KEYLESS 1
!END
!PARAMETER -in 2
!ALIAS -i
!TYPE string
!REQUIRED true
!BRIEF Input file name
!KEYLESS 2
!END
!PARAMETER -out 3
!ALIAS -o
!ALIAS -success
!TYPE string
!REQUIRED true
!BRIEF Output file name
!KEYLESS 3
!END
!PARAMETER -noxform 4
!ALIAS -fails
!ALIAS -failures
!TYPE string
!REQUIRED false
!BRIEF Output file name for untransformed structures
!END
!END
!CATEGORY Options
!PARAMETER -strict 1
!ALIAS -strictsmirks
!TYPE bool
!REQUIRED false
!DEFAULT true
!BRIEF requested strict flag which controls the interpretation of the transformation SMIRKS (true:Daylight convention, false:OpenEye convention)
!END
!PARAMETER -clearcoords 2
!TYPE bool
!REQUIRED false
!DEFAULT true
!BRIEF whether to clear coordinates for transformed products
!END
!PARAMETER -validkek 3
!ALIAS -validkekule
!TYPE bool
!REQUIRED false
!DEFAULT true
!BRIEF whether the transformation validates the Kekule form of the transformed products
!END
!PARAMETER -fixval 4
!TYPE string
!REQUIRED false
!DEFAULT Explicit
!BRIEF type of valence correction to apply to the transformed products: Explicit(None), Altered, All
!END
!PARAMETER -max 5
!ALIAS -maxxforms
!TYPE int
!REQUIRED false
!DEFAULT 10
!BRIEF maximum number of transformation to apply to each processed molecule
!END
!PARAMETER -alteredtag 6
!TYPE string
!REQUIRED false
!DEFAULT None
!BRIEF A generic data tag to mark altered atom information from transformed products
!END
!PARAMETER -passfail 7
!TYPE bool
!REQUIRED false
!DEFAULT false
!BRIEF If true, include untransformed structures in -out
!END
!PARAMETER -asrxn 8
!TYPE bool
!REQUIRED false
!DEFAULT false
!BRIEF If true, output the transformation as a reaction
!END
!END
!END
"""
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 55: Setting up an OE3DMolStyle on a molecule.
#!/usr/bin/env python
# (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.
import sys
from openeye import oechem
def main(argv=[__name__]):
if len(argv) != 3:
oechem.OEThrow.Usage("%s <infile>" % argv[0])
ifs = oechem.oemolistream()
if not ifs.open(argv[1]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1])
ofs = oechem.oemolostream()
if not ofs.open(argv[2]):
oechem.OEThrow.Fatal("Unable to open %s for writing" % argv[2])
for mol in ifs.GetOEMols():
molSty = oechem.OE3DMolStyle()
protCol = oechem.OEMolStyleColorer(oechem.OEAtomColorScheme_Residue)
atomCol = oechem.OEMolStyleColorer(oechem.OEAtomColorScheme_Element, oechem.OEWhite)
atomCol.AddColor(6, oechem.OEGreen)
atomCol.AddColor(7, oechem.OERed)
atomCol.AddColor(8, oechem.OEBlue)
molSty.SetAtomColorer(atomCol)
molSty.SetProteinColorer(protCol)
molSty.SetProteinStyle(oechem.OEProteinStyle_Ribbons)
molSty.SetAtomLabelType(oechem.OEAtomLabelScheme_Element)
molSty.SetAtomStyle(oechem.OEAtomStyle_BallAndStick)
molSty.SetHydrogenVisibility(oechem.OEHydrogenVisibility_Polar)
molSty.SetInteractionStyle(oechem.OEInteractionStyle_IntermolecularHBonds)
oechem.OESetStyle(mol, molSty)
if not oechem.OEHasStyle(mol):
oechem.OEThrow.Fatal("OE3DMolStyle was not applied to the OEMol")
oechem.OEWriteMolecule(ofs, mol)
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 56: OE3DMolStyle focused on B-Factor styling.
#!/usr/bin/env python
# (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.
import sys
from openeye import oechem
def main(argv=[__name__]):
if len(argv) != 3:
oechem.OEThrow.Usage("%s <infile>" % argv[0])
ifs = oechem.oemolistream()
if not ifs.open(argv[1]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1])
ofs = oechem.oemolostream()
if not ofs.open(argv[2]):
oechem.OEThrow.Fatal("Unable to open %s for writing" % argv[2])
for mol in ifs.GetOEMols():
molSty = oechem.OE3DMolStyle()
molCol = oechem.OEMolStyleColorer(oechem.OEAtomColorScheme_BFactor)
molSty.SetAtomColorer(molCol)
molSty.SetProteinColorer(molCol)
molSty.SetProteinStyle(oechem.OEProteinStyle_Ribbons)
molSty.SetAtomLabelType(oechem.OEAtomLabelScheme_BFactor)
oechem.OESetStyle(mol, molSty)
if not oechem.OEHasStyle(mol):
oechem.OEThrow.Fatal("OE3DMolStyle was not applied to the OEMol")
oechem.OEWriteMolecule(ofs, mol)
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 57: Generate canonical SMILES.
#!/usr/bin/env python
# (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.
#############################################################################
# Generate canonical smiles of various flavors
#############################################################################
import sys
from openeye import oechem
#############################################################################
# To create unique Kekule smiles, must reperceive bond orders from
# scratch to avoid arbitrary non-deterministic variations, e.g.,
# CC1=C(O)C=CC=C1 vs. CC1=CC=CC=C1O
# This is why oechem.OESMILESFlag_Kekule is not sufficient and not used.
#############################################################################
def CanSmi(mol, isomeric, kekule):
oechem.OEFindRingAtomsAndBonds(mol)
oechem.OEAssignAromaticFlags(mol, oechem.OEAroModel_OpenEye)
smiflag = oechem.OESMILESFlag_Canonical
if isomeric:
smiflag |= oechem.OESMILESFlag_ISOMERIC
if kekule:
for bond in mol.GetBonds(oechem.OEIsAromaticBond()):
bond.SetIntType(5)
oechem.OECanonicalOrderAtoms(mol)
oechem.OECanonicalOrderBonds(mol)
oechem.OEClearAromaticFlags(mol)
oechem.OEKekulize(mol)
smi = oechem.OECreateSmiString(mol, smiflag)
return smi
def main(argv=[__name__]):
itf = oechem.OEInterface(InterfaceData, argv)
isomeric = itf.GetBool("-isomeric")
kekule = itf.GetBool("-kekule")
from3d = itf.GetBool("-from3d")
if from3d:
isomeric = True
ifs = oechem.oemolistream()
ifile = itf.GetString("-i")
if not ifs.open(ifile):
oechem.OEThrow.Fatal("Unable to open %s for reading" % ifile)
if itf.HasString("-o"):
ofile = itf.GetString("-o")
try:
ofs = open(ofile, 'w')
except Exception:
oechem.OEThrow.Fatal("Unable to open %s for writing" % ofile)
else:
ofs = sys.stdout
mol = oechem.OEGraphMol()
while oechem.OEReadMolecule(ifs, mol):
if from3d:
oechem.OE3DToInternalStereo(mol)
smi = CanSmi(mol, isomeric, kekule)
if mol.GetTitle():
smi += (" %s" % mol.GetTitle())
ofs.write("%s\n" % smi)
InterfaceData = """\
!BRIEF [options] [-i] <input> [[-o] <output>]
!PARAMETER -i
!ALIAS -in
!TYPE string
!REQUIRED true
!BRIEF input file name
!KEYLESS 1
!END
!PARAMETER -o
!ALIAS -out
!TYPE string
!BRIEF output file name
!KEYLESS 2
!END
!PARAMETER -isomeric
!TYPE bool
!DEFAULT false
!BRIEF generate isomeric smiles
!END
!PARAMETER -from3d
!TYPE bool
!DEFAULT false
!BRIEF perceive stereo from 3D coords
!END
!PARAMETER -kekule
!TYPE bool
!DEFAULT false
!BRIEF generate kekule form
!END
"""
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 58: Concatenating molecules.
#!/usr/bin/env python
# (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.
#############################################################################
# This program concatenates molecules into one file.
# It can be useful for generating ROCS queries or reattach ligands to an
# protein structure
#############################################################################
import sys
from openeye import oechem
def CatMols(infnames, outfname):
omol = oechem.OEGraphMol()
for fname in infnames:
ifs = oechem.oemolistream()
if ifs.open(fname):
for imol in ifs.GetOEGraphMols():
oechem.OEAddMols(omol, imol)
else:
oechem.OEThrow.Fatal("Unable to open %s for reading" % fname)
ofs = oechem.oemolostream()
if not ofs.open(outfname):
oechem.OEThrow.Fatal("Unable to open %s for writing" % outfname)
oechem.OEWriteMolecule(ofs, omol)
Interface = """
!BRIEF -i <infile1> [<infile2>...] -o <outfile>
!PARAMETER -i
!ALIAS -in
!TYPE string
!LIST true
!REQUIRED true
!BRIEF input file name(s)
!END
!PARAMETER -o
!ALIAS -out
!TYPE string
!REQUIRED true
!BRIEF output file name
!END
"""
def main(argv=[__name__]):
itf = oechem.OEInterface(Interface, argv)
CatMols(itf.GetStringList("-i"), itf.GetString("-o"))
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 59: Creating an OECIFData Object.
#!/usr/bin/env python
# (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.
import sys
import os
from openeye import oechem
def main(argv=sys.argv):
if len(argv) != 2:
oechem.OEThrow.Usage("%s 5nev.cif" % argv[0])
filename = argv[1]
filebase = os.path.basename(filename)
filebase, extension = os.path.splitext(filebase)
if filebase.split(".")[0].upper() != "5NEV" or extension != ".cif":
oechem.OEThrow.Usage("%s must be the 5nev cif file" % argv[1])
ifs = oechem.oemolistream()
ifs.open(filename)
mol = oechem.OEMol()
oechem.OEReadMolecule(ifs, mol)
cifData = oechem.OECIFData(mol)
print(cifData.GetNumCategories()) # 81
cifCategory = cifData.GetCategory("_audit_conform.")
print(cifCategory.GetCategoryName()) # "_audit_conform."
# Getting Data
for attribute in cifData.GetAttributes("_audit_author."):
print(attribute) # name, pdbx_ordinal, identifier_ORCID
for attributeValue in cifData.GetAttributeValues("_audit_author.", "name"):
print(attributeValue) # Various author Names
print(cifData.GetAttributeValues("_audit_author.", "name")[0]) # Coxon, C.R.
print(cifData.GetAttributeValues("_audit_author.", "name", raw=True)[0]) # 'Coxon, C.R.'
# Setting, Adding and Deleting Data
# Pair Data
cifData.SetData("_pdbx_audit_revision_details.", "details", "No details")
cifData.AddData("_database_2.", "details")
# Loop Data
cifData.SetData("_entity_name_com.", "name", 0, "No Cell Division Protein Kinase 2,p33 protein kinase")
cifData.AddRow("_audit_author.", ["Doe J.", "19", "0000-0000-0867-5309"])
# Deleting a Category
cifData.DeleteCategory("_pdbx_poly_seq_scheme.")
print(cifData.GetNumCategories()) # 80
# Saving
oechem.OESetMMCIFData(mol, cifData)
# Modifying the Molecule
mol.SetTitle("mod5NEV")
for atom in mol.GetAtoms():
res = oechem.OEAtomGetResidue(atom)
if oechem.OEGetResidueIndex(res) == oechem.OEResidueIndex_HOH:
continue
if res.GetExtChainID() == "A" and res.GetEntityID() == "1":
res.SetExtChainID("Z")
res.SetSubChainID("Z")
res.SetEntityID("9")
oechem.OEAtomSetResidue(atom, res)
# Update header with molecule changes
copts = oechem.OECIFOptions()
copts.SetPerceiveEntity(True)
copts.SetPerceiveStruct(True)
cifData.Update(mol, copts)
print(cifData.GetAttributeValue("_entry.", "id")) # mod5NEV
struct_asym_id_idx = cifData.GetAttributeIndex("_struct_asym.", "id")
struct_asym_entity_id_idx = cifData.GetAttributeIndex("_struct_asym.", "entity_id")
struct_asym_row = cifData.GetRow("_struct_asym.", 9)
print(struct_asym_row[struct_asym_id_idx]) # "Z"
print(struct_asym_row[struct_asym_entity_id_idx]) # "9"
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 60: Align molecules by clique match.
#!/usr/bin/env python
# (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.
#############################################################################
# Align two compounds based on the clique match
#############################################################################
import sys
from openeye import oechem
def CliqueAlign(refmol, fitmol, ofs):
cs = oechem.OECliqueSearch(refmol, oechem.OEExprOpts_DefaultAtoms,
oechem.OEExprOpts_DefaultBonds)
cs.SetSaveRange(5)
cs.SetMinAtoms(6)
for mi in cs.Match(fitmol):
rmat = oechem.OEDoubleArray(9)
trans = oechem.OEDoubleArray(3)
overlay = True
oechem.OERMSD(cs.GetPattern(), fitmol, mi, overlay, rmat, trans)
oechem.OERotate(fitmol, rmat)
oechem.OETranslate(fitmol, trans)
oechem.OEWriteMolecule(ofs, fitmol)
def main(argv=[__name__]):
if len(argv) != 4:
oechem.OEThrow.Usage("%s <refmol> <fitmol> <outfile>" % argv[0])
reffs = oechem.oemolistream()
if not reffs.open(argv[1]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1])
if not oechem.OEIs3DFormat(reffs.GetFormat()):
oechem.OEThrow.Fatal("Invalid input format: need 3D coordinates")
refmol = oechem.OEGraphMol()
if not oechem.OEReadMolecule(reffs, refmol):
oechem.OEThrow.Fatal("Unable to read molecule in %s" % argv[1])
if not refmol.GetDimension() == 3:
oechem.OEThrow.Fatal("%s doesn't have 3D coordinates" % refmol.GetTitle())
fitfs = oechem.oemolistream()
if not fitfs.open(argv[2]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[2])
if not oechem.OEIs3DFormat(fitfs.GetFormat()):
oechem.OEThrow.Fatal("Invalid input format: need 3D coordinates")
ofs = oechem.oemolostream()
if not ofs.open(argv[3]):
oechem.OEThrow.Fatal("Unable to open %s for writing" % argv[3])
if not oechem.OEIs3DFormat(ofs.GetFormat()):
oechem.OEThrow.Fatal("Invalid output format: need 3D coordinates")
oechem.OEWriteConstMolecule(ofs, refmol)
oechem.OESuppressHydrogens(refmol)
for fitmol in fitfs.GetOEGraphMols():
if not fitmol.GetDimension() == 3:
oechem.OEThrow.Warning("%s doesn't have 3D coordinates" % fitmol.GetTitle())
continue
CliqueAlign(refmol, fitmol, ofs)
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 61: Convert molecules.
#!/usr/bin/env python
# (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.
#############################################################################
# Program to convert from one molecule format to another
#############################################################################
import sys
from openeye import oechem
def main(argv=sys.argv):
if len(argv) != 3:
oechem.OEThrow.Usage("%s <infile> <outfile>" % argv[0])
ifs = oechem.oemolistream()
if not ifs.open(argv[1]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1])
ofs = oechem.oemolostream()
if not ofs.open(argv[2]):
oechem.OEThrow.Fatal("Unable to open %s for writing" % argv[2])
for mol in ifs.GetOEMols():
oechem.OEWriteMolecule(ofs, mol)
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 62: Create 2D ring dictionary.
#!/usr/bin/env python
# (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.
#############################################################################
# Creates a new 2D ring dictionary
#############################################################################
import sys
from openeye import oechem
def main(argv=[__name__]):
itf = oechem.OEInterface(InterfaceData, argv)
ifname = itf.GetString("-in")
ofname = itf.GetString("-ringdict")
ifs = oechem.oemolistream()
if not ifs.open(ifname):
oechem.OEThrow.Fatal("Unable to open %s for reading!" % ifname)
if not oechem.OEIs2DFormat(ifs.GetFormat()):
oechem.OEThrow.Fatal("Invalid input file format for 2D coordinates!")
ofs = oechem.oemolostream()
if not ofs.open(ofname):
oechem.OEThrow.Fatal("Unable to open %s for writing!" % ofname)
if ofs.GetFormat() != oechem.OEFormat_OEB:
oechem.OEThrow.Fatal("Output file has to be OEB format!")
opts = oechem.OE2DRingDictionaryCreatorOptions()
opts.SetRetainExistingBuiltInTemplates(itf.GetBool('-retain-built-in'))
ringdict = oechem.OE2DRingDictionary(opts)
dots = oechem.OEDots(10000, 100, "molecules")
for mol in ifs.GetOEGraphMols():
dots.Update()
ringdict.AddRings(mol)
nrrings = ringdict.NumRings()
oechem.OEThrow.Info("%d ring template(s) have been extracted!" % nrrings)
if nrrings != 0:
oechem.OEWrite2DRingDictionary(ofname, ringdict)
return 0
#############################################################################
# INTERFACE
#############################################################################
InterfaceData = """
!BRIEF [-in] <input> [-ringdict] <output ringdict>
!CATEGORY "input/output options :"
!PARAMETER -in
!ALIAS -i
!TYPE string
!REQUIRED true
!KEYLESS 1
!VISIBILITY simple
!BRIEF Input 2D molecule filename
!END
!PARAMETER -ringdict
!ALIAS -rd
!TYPE string
!REQUIRED true
!KEYLESS 2
!VISIBILITY simple
!BRIEF Output ring dictionary OEB filename
!END
!END
!CATEGORY "ring dictionary options :"
!PARAMETER -retain-built-in
!TYPE bool
!REQUIRED false
!DEFAULT false
!VISIBILITY simple
!BRIEF Ignore ring template if built-in exists
!END
!END
"""
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 63: Adding CSV data as SD tags.
#!/usr/bin/env python
# (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.
#############################################################################
# Merge a CSV file of data/properties, key on compound name in first column
# and use column titles as keys. All data is read/written as strings
#############################################################################
import sys
import csv
from openeye import oechem
def CSV2SDF(csvfile, ifs, ofs):
reader = csv.reader(csvfile, delimiter=',')
propnames = next(reader)
values = {}
for row in reader:
title = row[0]
if title == "":
oechem.OEThrow.Warning("Skipping entry with no title")
continue
value = row[1:]
values[title] = value
for mol in ifs.GetOEGraphMols():
if mol.GetTitle() in values:
count = 0
for v in values[mol.GetTitle()]:
count += 1
if v == "":
continue
else:
oechem.OESetSDData(mol, propnames[count], v)
oechem.OEWriteMolecule(ofs, mol)
def main(argv=[__name__]):
if len(argv) != 4:
oechem.OEThrow.Usage("%s <csvfile> <infile> <outsdfile>" % argv[0])
try:
csvfile = open(argv[1])
except Exception:
oechem.OEThrow.Fatal("Unable to open %s csv for reading" % argv[1])
ifs = oechem.oemolistream()
if not ifs.open(argv[2]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[2])
ofs = oechem.oemolostream()
if not ofs.open(argv[3]):
oechem.OEThrow.Fatal("Unable to open %s for writing" % argv[3])
if ofs.GetFormat() not in [oechem.OEFormat_SDF, oechem.OEFormat_OEB]:
oechem.OEThrow.Fatal("Only works for sdf or oeb output files")
CSV2SDF(csvfile, ifs, ofs)
csvfile.close()
if __name__ == '__main__':
sys.exit(main(sys.argv))
Listing 64: Print dots.
#!/usr/bin/env python
# (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.
#############################################################################
# Show dots when piping example programs
#############################################################################
import sys
from openeye import oechem
def main(argv=[__name__]):
if len(argv) < 3 or len(argv) > 4:
oechem.OEThrow.Usage("%s <infile> <outfile> [interval, default = 100]" % argv[0])
ifs = oechem.oemolistream()
if not ifs.open(argv[1]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1])
ofs = oechem.oemolostream()
if not ofs.open(argv[2]):
oechem.OEThrow.Fatal("Unable to open %s for writing" % argv[2])
dots = oechem.OEDots(100, 10, "molecules")
if len(argv) == 4:
i = int(argv[3])
dots.SetBigStep(i)
dots.SetSmallStep(i / 10)
for mol in ifs.GetOEMols():
oechem.OEWriteMolecule(ofs, mol)
dots.Update()
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 65: Extract 2D ring templates.
#!/usr/bin/env python
# (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.
#############################################################################
# Extracts ring templates for 2D coordinate generation
#############################################################################
import sys
from openeye import oechem
def main(argv=[__name__]):
itf = oechem.OEInterface(InterfaceData, argv)
ifname = itf.GetString("-in")
ofname = itf.GetString("-out")
ifs = oechem.oemolistream()
if not ifs.open(ifname):
oechem.OEThrow.Fatal("Unable to open %s for reading" % ifname)
if not oechem.OEIs2DFormat(ifs.GetFormat()):
oechem.OEThrow.Fatal("Invalid input format: need 2D coordinates")
ofs = oechem.oemolostream()
if not ofs.open(ofname):
oechem.OEThrow.Fatal("Unable to open %s for writing" % ofname)
if not oechem.OEIs2DFormat(ofs.GetFormat()):
oechem.OEThrow.Fatal("Invalid output format: unable to write 2D coordinates")
nrrings = 0
for mol in ifs.GetOEGraphMols():
for ring in oechem.OEExtractRingTemplates(mol):
nrrings += 1
oechem.OEWriteMolecule(ofs, ring)
oechem.OEThrow.Info("%d number of ring templates extracted" % nrrings)
InterfaceData = """
!BRIEF [-i] <input> [-o] <output>
!PARAMETER -i
!ALIAS -in
!TYPE string
!REQUIRED true
!BRIEF input file name
!KEYLESS 1
!END
!PARAMETER -o
!ALIAS -out
!TYPE string
!REQUIRED true
!BRIEF output file name
!KEYLESS 2
!END
"""
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 66: Extract molecule scaffolds.
#!/usr/bin/env python
# (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.
#############################################################################
# Extract the ring scaffold of a molecule
#############################################################################
from openeye import oechem
try:
set()
except NameError:
from sets import Set as set
import sys
def TraverseForRing(visited, atom):
visited.add(atom.GetIdx())
for nbor in atom.GetAtoms():
if nbor.GetIdx() not in visited:
if nbor.IsInRing():
return True
if TraverseForRing(visited, nbor):
return True
return False
def DepthFirstSearchForRing(root, nbor):
visited = set()
visited.add(root.GetIdx())
return TraverseForRing(visited, nbor)
class IsInScaffold(oechem.OEUnaryAtomPred):
def __call__(self, atom):
if atom.IsInRing():
return True
count = 0
for nbor in atom.GetAtoms():
if DepthFirstSearchForRing(atom, nbor):
count += 1
return count > 1
def main(argv=[__name__]):
itf = oechem.OEInterface(InterfaceData, argv)
exo_dbl_bonds = itf.GetBool("-exo")
ifs = oechem.oemolistream()
if not ifs.open(itf.GetString("-i")):
oechem.OEThrow.Fatal("Unable to open %s for reading" % itf.GetString("-i"))
ofs = oechem.oemolostream()
if not ofs.open(itf.GetString("-o")):
oechem.OEThrow.Fatal("Unable to open %s for writing" % itf.GetString("-o"))
for src in ifs.GetOEMols():
dst = oechem.OEMol()
pred = IsInScaffold()
if exo_dbl_bonds:
pred = oechem.OEOrAtom(pred, oechem.OEIsNonRingAtomDoubleBondedToRing())
adjustHcount = True
oechem.OESubsetMol(dst, src, pred, adjustHcount)
if dst.IsValid():
oechem.OEWriteMolecule(ofs, dst)
InterfaceData = """
!BRIEF [-exo] [-i] <input> [-o] <scaffolds>
!PARAMETER -i
!ALIAS -in
!TYPE string
!REQUIRED true
!BRIEF input file name
!KEYLESS 1
!END
!PARAMETER -o
!ALIAS -out
!TYPE string
!REQUIRED true
!BRIEF output file name
!KEYLESS 2
!END
!PARAMETER -exo
!TYPE bool
!DEFAULT true
!BRIEF Exclude double bonds exo to ring in scaffold
!END
"""
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 67: Generate 2D coordinates with user-defined ring templates.
#!/usr/bin/env python
# (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.
#############################################################################
# Generates 2D coordinates using user-defined ring templates
#############################################################################
import sys
from openeye import oechem
def main(argv=[__name__]):
itf = oechem.OEInterface(InterfaceData, argv)
ifname = itf.GetString("-in")
ofname = itf.GetString("-out")
ifs = oechem.oemolistream()
if not ifs.open(ifname):
oechem.OEThrow.Fatal("Unable to open %s for reading!" % ifname)
ofs = oechem.oemolostream()
if not ofs.open(ofname):
oechem.OEThrow.Fatal("Unable to open %s for writing!" % ofname)
if not oechem.OEIs2DFormat(ofs.GetFormat()):
oechem.OEThrow.Fatal("Invalid output file format for 2D coordinates!")
if itf.HasString("-ringdict"):
rdfname = itf.GetString("-ringdict")
if not oechem.OEIsValid2DRingDictionary(rdfname):
oechem.OEThrow.Warning("Invalid 2D ring dictionary file!")
else:
oechem.OEInit2DRingDictionary(rdfname)
for mol in ifs.GetOEGraphMols():
oechem.OEGenerate2DCoordinates(mol)
oechem.OEWriteMolecule(ofs, mol)
return 0
#############################################################################
# INTERFACE
#############################################################################
InterfaceData = """
!BRIEF [-in] <input> [-out] <output> [-ringdict] <ringdict file>
!CATEGORY "input/output options :"
!PARAMETER -in
!ALIAS -i
!TYPE string
!REQUIRED true
!KEYLESS 1
!VISIBILITY simple
!BRIEF Input filename
!END
!PARAMETER -out
!ALIAS -o
!TYPE string
!REQUIRED true
!KEYLESS 2
!VISIBILITY simple
!BRIEF Output filename
!END
!PARAMETER -ringdict
!ALIAS -rd
!TYPE string
!REQUIRED false
!VISIBILITY simple
!BRIEF Ring dictionary file
!DETAIL
2D ring dictionaries can be generated by the following OEChem examples:
C++ - createringdict.cpp
Python - createringdict.py
Java - CreateRingDict.java
C# - CreateRingDict.cs
!END
!END
"""
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 68: Get molecule titles.
#!/usr/bin/env python
# (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.
#############################################################################
# Output all molecule titles
#############################################################################
import sys
from openeye import oechem
def GenerateList(ifs, ofs):
for mol in ifs.GetOEMols():
title = mol.GetTitle()
if len(title) == 0:
title = "untitled"
ofs.write('%s\n' % title)
def main(argv=[__name__]):
if not (2 <= len(argv) <= 3):
oechem.OEThrow.Usage("%s <infile> [<outfile>]" % argv[0])
ifs = oechem.oemolistream()
if not ifs.open(argv[1]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1])
ofs = oechem.oeofstream()
if len(argv) == 3:
if not ofs.open(argv[2]):
oechem.OEThrow.Fatal("Unable to open %s for writing" % argv[2])
else:
ofs = sys.stdout
GenerateList(ifs, ofs)
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 69: Library generation.
#!/usr/bin/env python
# (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.
#############################################################################
# Perform library generation with SMIRKS
#############################################################################
import sys
from openeye import oechem
def LibGen(libgen, ofs, unique, isomeric):
smiflag = oechem.OESMILESFlag_DEFAULT # Canonical|AtomMaps|Rgroup
if isomeric:
smiflag |= oechem.OESMILESFlag_ISOMERIC
# access products
uniqproducts = []
for mol in libgen.GetProducts():
smiles = oechem.OECreateSmiString(mol, smiflag)
if not unique or smiles not in uniqproducts:
uniqproducts.append(smiles)
oechem.OEWriteMolecule(ofs, mol)
def main(argv=[__name__]):
itf = oechem.OEInterface(InterfaceData, argv)
if not itf.HasString("-smirks") and not itf.HasString("-rxn"):
oechem.OEThrow.Fatal("Please provide SMIRKS string or MDL reaction file")
if itf.HasString("-smirks") and itf.HasString("-rxn"):
oechem.OEThrow.Fatal("Please provide only SMIRKS string or MDL reaction file")
reaction = oechem.OEQMol()
if itf.HasString("-smirks"):
smirks = itf.GetString("-smirks")
if not oechem.OEParseSmirks(reaction, smirks):
oechem.OEThrow.Fatal("Unable to parse SMIRKS: %s" % smirks)
else:
rxn = itf.GetString("-rxn")
rfile = oechem.oemolistream(rxn)
opt = oechem.OEMDLQueryOpts_ReactionQuery | oechem.OEMDLQueryOpts_SuppressExplicitH
if not oechem.OEReadMDLReactionQueryFile(rfile, reaction, opt):
oechem.OEThrow.Fatal("Unable to read reaction file: %s" % rxn)
relax = itf.GetBool("-relax")
unique = itf.GetBool("-unique")
implicitH = itf.GetBool("-implicitH")
valcorrect = itf.GetBool("-valence")
isomeric = itf.GetBool("-isomeric")
libgen = oechem.OELibraryGen()
if not libgen.Init(reaction, not relax):
oechem.OEThrow.Fatal("failed to initialize library generator")
libgen.SetValenceCorrection(valcorrect)
libgen.SetExplicitHydrogens(not implicitH)
libgen.SetClearCoordinates(True)
ofs = oechem.oemolostream(".smi")
if itf.HasString("-product"):
ofs.open(itf.GetString("-product"))
nrReacts = 0
while itf.HasString("-reactants", nrReacts):
fileName = itf.GetString("-reactants", nrReacts)
if nrReacts >= libgen.NumReactants():
oechem.OEThrow.Fatal("Number of reactant files exceeds number of \
reactants specified in reaction")
ifs = oechem.oemolistream()
if not ifs.open(fileName):
oechem.OEThrow.Fatal("Unable to read %s reactant file" % fileName)
for mol in ifs.GetOEGraphMols():
libgen.AddStartingMaterial(mol, nrReacts, unique)
nrReacts += 1
if nrReacts != libgen.NumReactants():
oechem.OEThrow.Fatal("Reactions requires %d reactant files!" % libgen.NumReactants())
LibGen(libgen, ofs, unique, isomeric)
InterfaceData = """
!BRIEF [options] [-smirks <string> | -rxn <rfile>] -reactants <infile> [-product <outfile>]
!CATEGORY "input/output options"
!PARAMETER -smirks
!ALIAS -s
!TYPE string
!VISIBILITY simple
!BRIEF SMIRKS reaction string
!END
!PARAMETER -rxn
!TYPE string
!VISIBILITY simple
!BRIEF MDL reaction file
!END
!PARAMETER -reactants
!ALIAS -r
!TYPE string
!LIST true
!REQUIRED true
!VISIBILITY simple
!BRIEF list of input reactant filenames
!END
!PARAMETER -product
!ALIAS -p
!TYPE string
!REQUIRED false
!VISIBILITY simple
!BRIEF output product filename
!END
!END
!CATEGORY "OELibraryGen options"
!PARAMETER -relax
!TYPE bool
!REQUIRED false
!DEFAULT false
!VISIBILITY simple
!BRIEF unmapped atoms on reactant side are not deleted during reaction
!END
!PARAMETER -implicitH
!TYPE bool
!REQUIRED false
!DEFAULT false
!VISIBILITY simple
!BRIEF reaction will be performed using implicit hydrogens
!END
!PARAMETER -valence
!TYPE bool
!REQUIRED false
!DEFAULT false
!VISIBILITY simple
!BRIEF automatic valence correction will be applied
!END
!END
!CATEGORY "product smiles generation options"
!PARAMETER -unique
!TYPE bool
!REQUIRED false
!DEFAULT false
!VISIBILITY simple
!BRIEF only unique product canonical smiles will be written
!END
!PARAMETER -isomeric
!TYPE bool
!REQUIRED false
!DEFAULT false
!VISIBILITY simple
!BRIEF include atom and bond stereochemistry in product smiles string
!END
!END
"""
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 70: Generate database for fast substructure search.
#!/usr/bin/env python
# (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.
#############################################################################
# Generates database for fast substructure search.
#############################################################################
import sys
from openeye import oechem
def main(argv=[__name__]):
itf = oechem.OEInterface(InterfaceData)
if not oechem.OEParseCommandLine(itf, argv):
oechem.OEThrow.Fatal("Unable to interpret command line.")
ifname = itf.GetString("-in")
ofname = itf.GetString("-out")
stype = itf.GetString("-stype")
sort = itf.GetBool("-sort")
keeptitle = itf.GetBool("-keep-title")
nrthreads = itf.GetUnsignedInt("-nrthreads")
screentype = None
if stype == "Molecule":
screentype = oechem.OEGetSubSearchScreenType(oechem.OESubSearchScreenType_Molecule)
elif stype == "MDL":
screentype = oechem.OEGetSubSearchScreenType(oechem.OESubSearchScreenType_MDL)
elif stype == "SMARTS":
screentype = oechem.OEGetSubSearchScreenType(oechem.OESubSearchScreenType_SMARTS)
if screentype is None:
oechem.OEThrow.Fatal("stype %s is not supported" % stype)
opts = oechem.OECreateSubSearchDatabaseOptions(screentype)
opts.SetSortByBitCounts(sort)
opts.SetKeepTitle(keeptitle)
opts.SetNumProcessors(nrthreads)
screenstr = screentype.GetName()
infomsg = "Using %d processor(s) to generate database with '%s'"
oechem.OEThrow.Info(infomsg % (opts.GetNumProcessors(), screenstr))
tracer = oechem.OEConsoleProgressTracer()
if not oechem.OECreateSubSearchDatabaseFile(ofname, ifname, opts, tracer):
oechem.OEThrow.Fatal("Substructure search database can not be generated!")
return 0
#############################################################################
InterfaceData = """\
!BRIEF [options] -in <input> -out <output> -stype <screentype>
!CATEGORY "input/output options"
!PARAMETER -in 1
!ALIAS -i
!TYPE string
!REQUIRED true
!VISIBILITY simple
!BRIEF Input molecule filename
!END
!PARAMETER -out 2
!ALIAS -o
!TYPE string
!REQUIRED true
!VISIBILITY simple
!BRIEF Output substructure database filename
!END
!END
!CATEGORY "other options"
!PARAMETER -screentype
!ALIAS -stype
!TYPE string
!REQUIRED true
!LEGAL_VALUE Molecule
!LEGAL_VALUE MDL
!LEGAL_VALUE SMARTS
!BRIEF Screen type generated
!END
!PARAMETER -nrthreads
!TYPE unsigned
!DEFAULT 0
!BRIEF Number of processors used (zero means all available)
!DETAIL
!END
!PARAMETER -sort
!TYPE bool
!DEFAULT true
!BRIEF Whether to sort the molecules based on their screen bit counts.
!DETAIL
Generating sorted databases can be slower, but searching them will
be faster.
!END
!PARAMETER -keep-title
!TYPE bool
!DEFAULT true
!BRIEF Whether to keep the title of the molecule as unique identifier
!DETAIL
If false, then a 16 character long unique identifier will be generated
for each molecule as a new title.
!END
!END
"""
#############################################################################
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 71: Align molecules by maximum common substructure.
#!/usr/bin/env python
# (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.
#############################################################################
# Align two compounds based on the maximum common substructure
#############################################################################
import sys
from openeye import oechem
def MCSAlign(refmol, fitmol, ofs):
atomexpr = oechem.OEExprOpts_AtomicNumber | oechem.OEExprOpts_Aromaticity
bondexpr = 0
mcss = oechem.OEMCSSearch(oechem.OEMCSType_Exhaustive)
mcss.Init(refmol, atomexpr, bondexpr)
mcss.SetMCSFunc(oechem.OEMCSMaxBondsCompleteCycles())
rmat = oechem.OEDoubleArray(9)
trans = oechem.OEDoubleArray(3)
unique = True
overlay = True
for match in mcss.Match(fitmol, unique):
rms = oechem.OERMSD(mcss.GetPattern(), fitmol, match, overlay, rmat, trans)
if rms < 0.0:
oechem.OEThrow.Warning("RMS overlay failure")
continue
oechem.OERotate(fitmol, rmat)
oechem.OETranslate(fitmol, trans)
oechem.OEWriteMolecule(ofs, fitmol)
def main(argv=[__name__]):
if len(argv) != 4:
oechem.OEThrow.Usage("%s <refmol> <fitmol> <outfile>" % argv[0])
reffs = oechem.oemolistream()
if not reffs.open(argv[1]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1])
if not oechem.OEIs3DFormat(reffs.GetFormat()):
oechem.OEThrow.Fatal("Invalid input format: need 3D coordinates")
refmol = oechem.OEGraphMol()
if not oechem.OEReadMolecule(reffs, refmol):
oechem.OEThrow.Fatal("Unable to read molecule in %s" % argv[1])
if not refmol.GetDimension() == 3:
oechem.OEThrow.Fatal("%s doesn't have 3D coordinates" % refmol.GetTitle())
fitfs = oechem.oemolistream()
if not fitfs.open(argv[2]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[2])
if not oechem.OEIs3DFormat(fitfs.GetFormat()):
oechem.OEThrow.Fatal("Invalid input format: need 3D coordinates")
ofs = oechem.oemolostream()
if not ofs.open(argv[3]):
oechem.OEThrow.Fatal("Unable to open %s for writing" % argv[3])
if not oechem.OEIs3DFormat(ofs.GetFormat()):
oechem.OEThrow.Fatal("Invalid output format: need 3D coordinates")
oechem.OEWriteConstMolecule(ofs, refmol)
oechem.OESuppressHydrogens(refmol)
for fitmol in fitfs.GetOEGraphMols():
if not fitmol.GetDimension() == 3:
oechem.OEThrow.Warning("%s doesn't have 3D coordinates" % fitmol.GetTitle())
continue
MCSAlign(refmol, fitmol, ofs)
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 72: Find minimum path in a molecule.
#!/usr/bin/env python
# (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.
#############################################################################
# Find the minimum path length between 2 smarts patterns
# or the path length between 2 named atoms
#############################################################################
import sys
from openeye import oechem
def AtomPathLength(ifs, ofs, itf, atm1, atm2):
for mol in ifs.GetOEGraphMols():
oechem.OETriposAtomNames(mol)
a1 = None
a2 = None
for atm in mol.GetAtoms():
if atm.GetName() == atm1:
a1 = atm
if atm.GetName() == atm2:
a2 = atm
if a1 is not None and a2 is not None:
break
if a1 is None or a2 is None:
oechem.OEThrow.Warning("Failed to find atoms %s and %s in molecule" % (atm1, atm2))
continue
pathlen = oechem.OEGetPathLength(a1, a2)
if itf.GetBool("-verbose") or not itf.HasString("-o"):
print("Path length: %s in %s" % (pathlen, oechem.OEMolToSmiles(mol)))
spath = oechem.OEShortestPath(a1, a2)
spathmol = oechem.OEGraphMol()
adjustHCount = True
oechem.OESubsetMol(spathmol, mol, oechem.OEIsAtomMember(spath), adjustHCount)
spathsmiles = oechem.OEMolToSmiles(spathmol)
if itf.HasString("-o"):
oechem.OEWriteMolecule(ofs, spathmol)
elif itf.GetBool("-verbose"):
print(spathsmiles)
def SmartsPathLength(ifs, ofs, itf, ss1, ss2):
for mol in ifs.GetOEGraphMols():
oechem.OEPrepareSearch(mol, ss1)
oechem.OEPrepareSearch(mol, ss2)
if not (ss1.SingleMatch(mol) and ss2.SingleMatch(mol)):
oechem.OEThrow.Warning("Unable to find SMARTS matches in %s, skipping" % mol.GetTitle())
continue
unique = True
allminlen = sys.maxsize
for match1 in ss1.Match(mol, unique):
for match2 in ss2.Match(mol, unique):
minlen = sys.maxsize
for atom1 in match1.GetTargetAtoms():
for atom2 in match2.GetTargetAtoms():
pathlen = oechem.OEGetPathLength(atom1, atom2)
if minlen > pathlen:
minlen = pathlen
atompairs = []
atompairs.append([atom1, atom2])
elif minlen == pathlen:
atompairs.append([atom1, atom2])
if minlen < allminlen:
allminlen = minlen
allatompairs = atompairs[:]
elif minlen == allminlen:
allatompairs += atompairs[:]
if itf.GetBool("-verbose") or not itf.HasString("-o"):
print("Shortest path length: %s in %s" % (allminlen, oechem.OEMolToSmiles(mol)))
spathlist = set()
for satom1, satom2, in allatompairs:
spath = oechem.OEShortestPath(satom1, satom2)
spathmol = oechem.OEGraphMol()
oechem.OESubsetMol(spathmol, mol, oechem.OEIsAtomMember(spath))
spathsmiles = oechem.OEMolToSmiles(spathmol)
if spathsmiles in spathlist:
continue
spathlist.add(spathsmiles)
if itf.HasString("-o"):
oechem.OEWriteMolecule(ofs, spathmol)
elif itf.GetBool("-verbose"):
print(spathsmiles)
return
def main(argv=[__name__]):
itf = oechem.OEInterface(Interface, argv)
if not ((itf.HasString("-smarts1") and itf.HasString("-smarts2")) ^
(itf.HasString("-atom1") and itf.HasString("-atom2"))):
oechem.OEThrow.Fatal("-smarts1 and -smarts2 or -atom1 and -atom2 must be set")
ifs = oechem.oemolistream()
if not ifs.open(itf.GetString("-i")):
oechem.OEThrow.Fatal("Unable to open %s for reading" %
itf.GetString("-i").rstrip())
ofs = oechem.oemolostream()
if itf.HasString("-o"):
if not ofs.open(itf.GetString("-o")):
oechem.OEThrow.Fatal("Unable to open %s for writing" % itf.GetString("-o"))
if itf.HasString("-smarts1") and itf.HasString("-smarts2"):
ss1 = oechem.OESubSearch()
smarts1 = itf.GetString("-smarts1")
if not ss1.Init(smarts1):
oechem.OEThrow.Fatal("Unable to parse SMARTS1: %s" % smarts1.rstrip())
ss2 = oechem.OESubSearch()
smarts2 = itf.GetString("-smarts2")
if not ss2.Init(smarts2):
oechem.OEThrow.Fatal("Unable to parse SMARTS2: %s" % smarts2.rstrip())
SmartsPathLength(ifs, ofs, itf, ss1, ss2)
else:
atom1 = itf.GetString("-atom1")
atom2 = itf.GetString("-atom2")
AtomPathLength(ifs, ofs, itf, atom1, atom2)
Interface = """
!BRIEF -i <input> [-o <output>] -smarts1 <smarts> -smarts2 <smarts> | -atom1 <name> -atom2 <name>
!PARAMETER -i
!TYPE string
!REQUIRED true
!BRIEF Input file name
!KEYLESS 1
!END
!PARAMETER -o
!TYPE string
!REQUIRED false
!BRIEF Output file name
!KEYLESS 2
!END
!PARAMETER -smarts1
!TYPE string
!BRIEF Smarts pattern to identify 1st atom
!END
!PARAMETER -smarts2
!TYPE string
!BRIEF Smarts pattern to identify 2nd atom
!END
!PARAMETER -atom1
!TYPE string
!BRIEF Name of 1st atom
!END
!PARAMETER -atom2
!TYPE string
!BRIEF Name of 2nd atom
!END
!PARAMETER -verbose
!TYPE bool
!REQUIRED false
!DEFAULT false
!BRIEF Print verbose output
!END
"""
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 73: Split molecule file.
#!/usr/bin/env python
# (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.
#############################################################################
# Split molecule file into N chunks or chunks of size N
#############################################################################
import os
import sys
from openeye import oechem
def NewOutputStream(outbase, ext, chunk):
newname = outbase + ('_%07d' % chunk) + ext
ofs = oechem.oemolostream()
if not ofs.open(newname):
oechem.OEThrow.Fatal("Unable to open %s for writing" % newname)
return ofs
def SplitNParts(ifs, nparts, countconfs, outbase, ext):
# first read entire file to determine number of molecules
molconfcount = 0
for mol in ifs.GetOEMols():
if countconfs:
molconfcount += mol.NumConfs()
else:
molconfcount += 1
ifs.rewind()
chunksize, lft = divmod(molconfcount, nparts)
if lft != 0:
chunksize += 1
chunk = 1
count = 0
ofs = NewOutputStream(outbase, ext, chunk)
for mol in ifs.GetOEMols():
if countconfs:
count += mol.NumConfs()
else:
count += 1
if count > chunksize:
if chunk == lft:
chunksize -= 1
ofs.close()
chunk += 1
count = 1
ofs = NewOutputStream(outbase, ext, chunk)
oechem.OEWriteMolecule(ofs, mol)
def SplitChunk(ifs, chunksize, countconfs, outbase, ext):
chunk = 1
ofs = NewOutputStream(outbase, ext, chunk)
count = 0
for mol in ifs.GetOEMols():
if count >= chunksize:
ofs.close()
count = 0
chunk += 1
ofs = NewOutputStream(outbase, ext, chunk)
if countconfs:
count += mol.NumConfs()
else:
count += 1
oechem.OEWriteMolecule(ofs, mol)
def main(argv=[__name__]):
itf = oechem.OEInterface(InterfaceData, argv)
if not (itf.HasInt("-num") ^ itf.HasInt("-size")):
oechem.OEThrow.Fatal("Number of chunks (-num) or the size of each chunk "
"(-size) must be specified and are mutually exclusive.")
ifs = oechem.oemolistream()
if not ifs.open(itf.GetString("-i")):
oechem.OEThrow.Fatal("Unable to open %s for reading" % itf.GetString("-i"))
if (ifs.GetFormat() != oechem.OEFormat_OEB):
ifs.SetConfTest(oechem.OEIsomericConfTest(False))
elif itf.GetBool("-rotcompress"):
oechem.OEPreserveRotCompress(ifs) # only for OEB
outbase, ext = os.path.splitext(itf.GetString("-o"))
if ext == '':
oechem.OEThrow.Fatal("Failed to find file extension")
if ext == '.gz':
outbase, ext = os.path.splitext(outbase)
ext = ext + '.gz'
countconfs = itf.GetBool("-confs")
if itf.HasInt("-num"):
nparts = itf.GetInt("-num")
SplitNParts(ifs, nparts, countconfs, outbase, ext)
else:
chunksize = itf.GetInt("-size")
SplitChunk(ifs, chunksize, countconfs, outbase, ext)
#############################################################################
InterfaceData = """\
!BRIEF -num|-size [-i] <input> [-o] <output>
!PARAMETER -i 1
!TYPE string
!REQUIRED true
!BRIEF Input file name
!KEYLESS 1
!END
!PARAMETER -o 2
!TYPE string
!REQUIRED true
!BRIEF Output file name
!KEYLESS 2
!END
!PARAMETER -num 3
!TYPE int
!BRIEF The number of chunks
!END
!PARAMETER -size 4
!TYPE int
!BRIEF The size of each chunk
!END
!PARAMETER -confs 5
!TYPE bool
!DEFAULT true
!BRIEF Split by number of conformers not molecules
!END
!PARAMETER -rotcompress 6
!TYPE bool
!DEFAULT false
!BRIEF Preserve rotor compression
!END
"""
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 74: Counting molecules.
#!/usr/bin/env python
# (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.
#############################################################################
# Counts molecule (and conformers) in input files
#############################################################################
import sys
from openeye import oechem
def PrintConfInfo(nconfs, nmols):
print("Total # of conformers: ", nconfs)
avg = 0
if nmols:
avg = float(nconfs) / nmols
print("Average # of conformers:", avg)
def MolCount(ifs, fname, conffrag):
nummols = 0
numconfs = 0
for mol in ifs.GetOEMols():
nummols += 1
if conffrag:
numconfs += mol.NumConfs()
print("%s contains %d molecule(s)." % (fname, nummols))
if conffrag:
PrintConfInfo(numconfs, nummols)
print("-----------------------------------------------------------")
return nummols, numconfs
def main(argv=[__name__]):
itf = oechem.OEInterface(Interface, argv)
conffrag = itf.GetBool("-conf")
confomega = itf.GetBool("-confomega")
totmols = 0
totconfs = 0
for fname in itf.GetStringList("-i"):
ifs = oechem.oemolistream()
if not ifs.open(fname):
oechem.OEThrow.Warning("Unable to open %s for reading" % fname)
continue
if confomega:
conffrag = True
ifs.SetConfTest(oechem.OEOmegaConfTest(False))
nummol, numconfs = MolCount(ifs, fname, conffrag)
totmols += nummol
totconfs += numconfs
print("===========================================================")
print("Total %d molecules" % totmols)
if conffrag:
PrintConfInfo(totconfs, totmols)
Interface = """
!BRIEF [-conf | -confomega] [-i] <infile1> [<infile2>...]
!PARAMETER -i
!ALIAS -in
!TYPE string
!LIST true
!REQUIRED true
!BRIEF Input file name(s)
!KEYLESS 1
!END
!PARAMETER -conf
!ALIAS -c
!TYPE bool
!DEFAULT false
!BRIEF Count conformers
!END
!PARAMETER -confomega
!TYPE bool
!DEFAULT false
!BRIEF Count Omega conformers
!END
"""
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 75: Extract molecules by title.
#!/usr/bin/env python
# (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.
#############################################################################
# Extract compound(s) from a file based on molecule title
#############################################################################
import sys
try:
set()
except NameError:
from sets import Set as set
from openeye import oechem
def MolExtract(ifs, ofs, nameset):
for mol in ifs.GetOEMols():
title = mol.GetTitle()
if title in nameset:
oechem.OEWriteMolecule(ofs, mol)
def main(argv=[__name__]):
itf = oechem.OEInterface(InterfaceData, argv)
haslist = itf.HasString("-list")
hastitle = itf.HasString("-title")
if not (haslist ^ hastitle):
oechem.OEThrow.Usage("Must give either -list or -title")
ifs = oechem.oemolistream()
if not ifs.open(itf.GetString("-i")):
oechem.OEThrow.Fatal("Unable to open %s for reading" % itf.GetString("-i"))
ofs = oechem.oemolostream()
if not ofs.open(itf.GetString("-o")):
oechem.OEThrow.Fatal("Unable to open %s for writing" % itf.GetString("-o"))
# collect names
nameset = set()
if itf.HasString("-list"):
try:
lfs = open(itf.GetString("-list"))
except IOError:
oechem.OEThrow.Fatal("Unable to open %s for reading" % itf.GetString("-list"))
for name in lfs.readlines():
name = name.strip()
nameset.add(name)
elif itf.HasString("-title"):
nameset.add(itf.GetString("-title"))
if len(nameset) == 0:
oechem.OEThrow.Fatal("No titles requested")
MolExtract(ifs, ofs, nameset)
InterfaceData = """\
!BRIEF -title title | -list <moltitles.file> [-i] <input> [-o] <output>
!PARAMETER -i
!ALIAS -in
!TYPE string
!REQUIRED true
!BRIEF Input file name
!KEYLESS 1
!END
!PARAMETER -o
!ALIAS -out
!TYPE string
!REQUIRED true
!BRIEF Output file name
!KEYLESS 2
!END
!PARAMETER -title
!ALIAS -t
!TYPE string
!BRIEF Single mol title to extract
!END
!PARAMETER -list
!ALIAS -l
!TYPE string
!BRIEF List file of mol titles to extract
!END
"""
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 76: Perform substructure searches.
#!/usr/bin/env python
# (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.
#############################################################################
# Perform substructure search on molecule file
#############################################################################
import sys
from openeye import oechem
def SubSearch(itf, ss, ifs, ofs):
reverseflag = itf.GetBool("-r")
countflag = itf.GetBool("-c")
count = 0
for mol in ifs.GetOEGraphMols():
oechem.OEPrepareSearch(mol, ss)
if ss.SingleMatch(mol) != reverseflag:
if countflag:
count += 1
else:
oechem.OEWriteMolecule(ofs, mol)
if countflag:
print("%d matching molecules\n" % (count), end=" ")
def main(argv=[__name__]):
itf = oechem.OEInterface(InterfaceData, argv)
if not (itf.GetBool("-c") ^ itf.HasString("-o")):
oechem.OEThrow.Fatal("Counting (-c) or output (-o) must be \
specified and are mutually exclusive.")
ifs = oechem.oemolistream()
filename = itf.GetString("-i")
if not ifs.open(filename):
oechem.OEThrow.Fatal("Unable to open %s for reading" % filename)
ofs = oechem.oemolostream()
if not itf.GetBool("-c"):
filename = itf.GetString("-o")
if not ofs.open(filename):
oechem.OEThrow.Fatal("Unable to open %s for writing" % filename)
smarts = itf.GetString("-p")
ss = oechem.OESubSearch()
if not ss.Init(smarts):
oechem.OEThrow.Fatal("Unable to parse SMARTS: %s" % smarts)
SubSearch(itf, ss, ifs, ofs)
InterfaceData = """
!BRIEF [-r][-c] -p smarts [-i] <input> [[-o] <output>]
!PARAMETER -i 1
!ALIAS -in
!TYPE string
!REQUIRED true
!BRIEF Input file name
!KEYLESS 1
!END
!PARAMETER -p 2
!TYPE string
!REQUIRED true
!BRIEF SMARTS pattern, quote for safety
!END
!PARAMETER -o 3
!ALIAS -out
!TYPE string
!BRIEF Output file name
!KEYLESS 2
!END
!PARAMETER -r 4
!ALIAS -v
!TYPE bool
!DEFAULT false
!BRIEF Reverse logic, not matched
!END
!PARAMETER -c 5
!TYPE bool
!DEFAULT false
!BRIEF Just output count of number matched
!END
"""
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 77: Print simple molecule information.
#!/usr/bin/env python
# (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.
#############################################################################
# Output some basic molecule properties
#############################################################################
import sys
from openeye import oechem
def main(argv=[__name__]):
if len(argv) != 2:
oechem.OEThrow.Usage("%s <infile>" % argv[0])
ifs = oechem.oemolistream()
if not ifs.open(argv[1]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1])
print("Title MolWt NumAtoms NumHeavyAtoms NumRingAtoms NumRotors NumConfs")
for mol in ifs.GetOEMols():
title = mol.GetTitle()
if not title:
title = "Untitled"
print("%s %.3f %d %d %d %d %d" % (title,
oechem.OECalculateMolecularWeight(mol),
mol.NumAtoms(),
oechem.OECount(mol, oechem.OEIsHeavy()),
oechem.OECount(mol, oechem.OEAtomIsInRing()),
oechem.OECount(mol, oechem.OEIsRotor()),
mol.NumConfs()))
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 78: Print OEChem and file format information.
#!/usr/bin/env python
# (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.
#############################################################################
# Print toolkit release date platform and build information. Also print out
# all formats supported by OEChem and whether they are readable or writable
#############################################################################
import os
import sys
import openeye
from openeye import oechem
def GetYesNo(ok):
if ok:
return "yes"
return "no"
def PrintFormats():
print("code| ext | description |read? |write?")
print("----+---------------+------------------------------------------+------+------")
for numformat in range(1, oechem.OEFormat_MAXFORMAT):
extension = oechem.OEGetFormatExtension(numformat)
description = oechem.OEGetFormatString(numformat)
readable = GetYesNo(oechem.OEIsReadable(numformat))
writeable = GetYesNo(oechem.OEIsWriteable(numformat))
print(' %2d | %-13s | %-40s | %-4s | %-4s'
% (numformat, extension, description, readable, writeable))
print("----+---------------+------------------------------------------+------+------")
def ShowExamples():
parent = os.path.abspath(os.path.dirname(openeye.__file__))
print()
print("Examples:", os.path.join(parent, 'examples'))
print("Doc Examples:", os.path.join(parent, 'docexamples'))
print()
def main(argv=sys.argv):
print("Installed OEChem version: %s platform: %s built: %s release name: %s" %
(oechem.OEChemGetRelease(), oechem.OEChemGetPlatform(),
oechem.OEChemGetVersion(), oechem.OEToolkitsGetRelease()))
ShowExamples()
PrintFormats()
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 79: Define parameters.
#!/usr/bin/env python
# (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.
import sys
from openeye import oechem
class MyOptions(oechem.OEOptions):
def __init__(self):
oechem.OEOptions.__init__(self, "MyOption")
param1 = oechem.OEDoubleParameter("-value", 10.0)
param1.AddLegalRange("20.0", "-20.0")
param1.SetBrief("Brief description of parameter value")
self.AddParameter(param1)
pass
def main(argv=[__name__]):
opts = MyOptions()
oechem.OEConfigureOpts(opts, argv, True)
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 80: Splitting multicomponent molecules.
#!/usr/bin/env python
# (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.
#############################################################################
# Writes each component of a molecule as a separate molecule
#############################################################################
import sys
from openeye import oechem
def main(argv=[__name__]):
if len(argv) != 3:
oechem.OEThrow.Usage("%s <infile> <outfile>" % argv[0])
ifs = oechem.oemolistream()
ifs.SetFlavor(oechem.OEFormat_PDB, oechem.OEIFlavor_PDB_Default ^ oechem.OEIFlavor_PDB_DATA)
if not ifs.open(argv[1]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1])
ofs = oechem.oemolostream()
if not ofs.open(argv[2]):
oechem.OEThrow.Fatal("Unable to open %s for writing" % argv[2])
for mol in ifs.GetOEGraphMols():
numparts, partlist = oechem.OEDetermineComponents(mol)
pred = oechem.OEPartPredAtom(partlist)
for i in range(1, numparts + 1):
pred.SelectPart(i)
partmol = oechem.OEGraphMol()
oechem.OESubsetMol(partmol, mol, pred)
oechem.OEWriteMolecule(ofs, partmol)
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 81: Print molecule atom names.
#!/usr/bin/env python
# (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.
#############################################################################
# Print out atom names
#############################################################################
import sys
from openeye import oechem
def main(argv=[__name__]):
if len(argv) != 2:
oechem.OEThrow.Usage("%s <infile>" % argv[0])
ifs = oechem.oemolistream()
if not ifs.open(argv[1]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1])
for mol in ifs.GetOEMols():
oechem.OETriposAtomNames(mol)
for atm in mol.GetAtoms():
print(atm.GetName())
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 82: Randomize molecules of atom.
#!/usr/bin/env python
# (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.
#############################################################################
# Demonstrates how to randomly reorder atoms and bonds of a molecule
#############################################################################
import sys
from openeye import oechem
def OrderMolecules(ifs, ofs):
for mol in ifs.GetOEGraphMols():
oechem.OEScrambleMolecule(mol)
oechem.OEWriteMolecule(ofs, mol)
def main(argv=[__name__]):
if len(argv) != 3:
oechem.OEThrow.Usage("%s <infile> <outfile>" % argv[0])
ifs = oechem.oemolistream()
if not ifs.open(argv[1]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1])
ofs = oechem.oemolostream()
if not ofs.open(argv[2]):
oechem.OEThrow.Fatal("Unable to open %s for writing" % argv[2])
OrderMolecules(ifs, ofs)
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 83: Extract random molecule subset.
#!/usr/bin/env python
# (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.
#############################################################################
# Randomly reorder molecules and optionally obtain a random subset
#############################################################################
import sys
from random import Random
from openeye import oechem
def LoadDatabase(ifs, mlist, count):
for pos, mol in enumerate(ifs.GetOEMols()):
newmol = oechem.OEMol(mol, oechem.OEMCMolType_OEDBMCMol)
newmol.Compress()
mlist.append(newmol)
if pos + 1 == count:
break
def WriteDatabase(ofs, mlist, size):
for mol in mlist[:size]:
mol.UnCompress()
oechem.OEWriteMolecule(ofs, mol)
mol.Clear()
def RandomizePercent(ifs, ofs, percent, rand):
mlist = []
LoadDatabase(ifs, mlist, 0)
rand.shuffle(mlist)
size = len(mlist)
size = int(percent * 0.01 * size)
if size < 1:
size = 1
WriteDatabase(ofs, mlist, size)
def Randomize(ifs, ofs, rand):
wholedb = 100
RandomizePercent(ifs, ofs, wholedb, rand)
def RandomizeN(ifs, ofs, count, rand):
mlist = []
LoadDatabase(ifs, mlist, count)
for pos, mol in enumerate(ifs.GetOEMols()):
if float(count / float(count + pos + 1)) > rand.random():
idx = int(float(count) * rand.random())
newmol = oechem.OEMol(mol, oechem.OEMCMolType_OEDBMCMol)
newmol.Compress()
mlist[idx] = newmol
rand.shuffle(mlist)
WriteDatabase(ofs, mlist, count)
def main(argv=[__name__]):
itf = oechem.OEInterface(InterfaceData, argv)
if itf.HasFloat("-p") and itf.HasInt("-n"):
oechem.OEThrow.Usage("Give only one option, -p or -n")
ifs = oechem.oemolistream()
if not ifs.open(itf.GetString("-i")):
oechem.OEThrow.Fatal("Unable to open %s for reading" % itf.GetString("-i"))
ofs = oechem.oemolostream(".ism")
if itf.HasString("-o"):
if not ofs.open(itf.GetString("-o")):
oechem.OEThrow.Fatal("Unable to open %s for writing" % itf.GetString("-o"))
if itf.HasInt("-seed"):
rand = Random(itf.GetInt("-seed"))
else:
rand = Random()
if itf.HasInt("-n"):
RandomizeN(ifs, ofs, itf.GetInt("-n"), rand)
elif itf.HasFloat("-p"):
RandomizePercent(ifs, ofs, itf.GetFloat("-p"), rand)
else:
Randomize(ifs, ofs, rand)
InterfaceData = """
!BRIEF [-seed <int>] [-n <number>] [-p <percent>] [-i] <input> [-o] <output>
!PARAMETER -i
!TYPE string
!REQUIRED true
!BRIEF Input file name
!KEYLESS 1
!END
!PARAMETER -o
!TYPE string
!REQUIRED false
!BRIEF Output file name
!KEYLESS 2
!END
!PARAMETER -p
!TYPE float
!REQUIRED false
!BRIEF Percentage of output molecules
!END
!PARAMETER -n
!TYPE int
!REQUIRED false
!BRIEF Number of output molecules
!END
!PARAMETER -seed
!TYPE int
!REQUIRED false
!BRIEF Integer value for random seed, default is system time
!END
"""
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 84: Extract rings.
#!/usr/bin/env python
# (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.
#######################################################################
# Extracting rings/ring systems from input molecules
#######################################################################
import sys
from openeye import oechem
def RingSubSet(ifs, ofs, exo):
for mol in ifs.GetOEGraphMols():
submol = oechem.OEGraphMol()
adjustHcount = True
if exo:
isinring = oechem.OEAtomIsInRing()
isexo = oechem.OEIsNonRingAtomDoubleBondedToRing()
includeexo = oechem.OEOrAtom(isinring, isexo)
oechem.OESubsetMol(submol, mol, includeexo, adjustHcount)
else:
oechem.OESubsetMol(submol, mol, oechem.OEAtomIsInRing(), adjustHcount)
submol.SetTitle(mol.GetTitle() + "_rings")
if submol.NumAtoms() != 0:
oechem.OEWriteMolecule(ofs, submol)
def main(argv=[__name__]):
itf = oechem.OEInterface(InterfaceData, argv)
exo_dbl_bonds = itf.GetBool("-exo")
ifs = oechem.oemolistream()
if not ifs.open(itf.GetString("-i")):
oechem.OEThrow.Fatal("Unable to open %s for reading" % itf.GetString("-i"))
ofs = oechem.oemolostream(".ism")
if itf.HasString("-o"):
if not ofs.open(itf.GetString("-o")):
oechem.OEThrow.Fatal("Unable to open %s for writing" % itf.GetString("-o"))
RingSubSet(ifs, ofs, exo_dbl_bonds)
InterfaceData = """
!BRIEF [-exo] [-i] <infile> [[-o] <outfile>]
!PARAMETER -i
!ALIAS -in
!TYPE string
!REQUIRED true
!BRIEF input file name
!KEYLESS 1
!END
!PARAMETER -o
!ALIAS -out
!TYPE string
!REQUIRED false
!BRIEF output file name
!KEYLESS 2
!END
!PARAMETER -exo
!TYPE bool
!DEFAULT true
!BRIEF Include non-ring atoms double bonded to a ring
!END
"""
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 85: Align multiconformer molecules.
#!/usr/bin/env python
# (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.
#############################################################################
# Performing RMSD calculation between a 3D reference molecule and
# multi-conformation molecules
#############################################################################
import sys
from openeye import oechem
def main(argv=[__name__]):
itf = oechem.OEInterface(InterfaceData, argv)
if not itf.GetBool("-verbose"):
oechem.OEThrow.SetLevel(oechem.OEErrorLevel_Warning)
rfname = itf.GetString("-ref")
ifname = itf.GetString("-in")
automorph = itf.GetBool("-automorph")
heavy = itf.GetBool("-heavyonly")
overlay = itf.GetBool("-overlay")
ifs = oechem.oemolistream()
if not ifs.open(rfname):
oechem.OEThrow.Fatal("Unable to open %s for reading" % rfname)
rmol = oechem.OEGraphMol()
if not oechem.OEReadMolecule(ifs, rmol):
oechem.OEThrow.Fatal("Unable to read reference molecule")
ifs = oechem.oemolistream()
if not ifs.open(ifname):
oechem.OEThrow.Fatal("Unable to open %s for reading" % ifname)
ofs = oechem.oemolostream()
if itf.HasString("-out"):
ofname = itf.GetString("-out")
if not ofs.open(ofname):
oechem.OEThrow.Fatal("Unable to open %s for writing" % ofname)
if not overlay:
oechem.OEThrow.Warning("Output is the same as input when overlay is false")
for mol in ifs.GetOEMols():
oechem.OEThrow.Info(mol.GetTitle())
rmsds = oechem.OEDoubleArray(mol.GetMaxConfIdx())
rmtx = oechem.OEDoubleArray(9 * mol.GetMaxConfIdx())
tmtx = oechem.OEDoubleArray(3 * mol.GetMaxConfIdx())
# perform RMSD for all confomers
oechem.OERMSD(rmol, mol, rmsds, automorph, heavy, overlay, rmtx, tmtx)
for conf in mol.GetConfs():
cidx = conf.GetIdx()
oechem.OEThrow.Info("Conformer %i : rmsd = %f" % (cidx, rmsds[cidx]))
if itf.GetBool("-overlay"):
oechem.OERotate(conf, rmtx[cidx * 9: cidx * 9 + 9])
oechem.OETranslate(conf, tmtx[cidx * 3: cidx * 3 + 3])
if itf.HasString("-out"):
oechem.OEWriteMolecule(ofs, mol)
return 0
#############################################################################
InterfaceData = """\
!BRIEF [options] [-ref <mol file>] [-in <mol file>] [-out <mol file>]
!CATEGORY "input/output options"
!PARAMETER -ref
!TYPE string
!REQUIRED true
!BRIEF input reference mol file name
!KEYLESS 1
!END
!PARAMETER -in
!ALIAS -i
!TYPE string
!REQUIRED true
!BRIEF input mol file name
!KEYLESS 2
!END
!PARAMETER -out
!ALIAS -o
!TYPE string
!REQUIRED false
!BRIEF output file name, this implies that -overlay should be true
!KEYLESS 3
!END
!END
!CATEGORY "options"
!PARAMETER -automorph
!TYPE bool
!DEFAULT true
!BRIEF assign best atom association
!DETAIL
If false, atoms are associated by order.
If true, graph isomorphism is determined with symmetry perception.
!END
!PARAMETER -overlay
!TYPE bool
!DEFAULT true
!BRIEF Minimize to the smallest RMSD
!END
!PARAMETER -heavyonly
!TYPE bool
!DEFAULT true
!BRIEF Ignore hydrogens for RMSD calculation
!END
!PARAMETER -verbose
!ALIAS -v
!TYPE bool
!DEFAULT false
!BRIEF verbose
!END
!END
"""
#############################################################################
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 86: Print rotor count distribution.
#!/usr/bin/env python
# (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.
#############################################################################
# Counts the number of rotatable bonds in the input compound file and
# outputs the maximum number of rotamers and the rotomer distribution
#############################################################################
import sys
from openeye import oechem
def CountRotors(ifs):
rotcounts = []
for mol in ifs.GetOEMols():
nrots = oechem.OECount(mol, oechem.OEIsRotor())
while nrots >= len(rotcounts):
rotcounts.append(0)
rotcounts[nrots] += 1
print("Max rotors:", len(rotcounts) - 1)
print("Rotorcount distribution:")
for rots, numrot in enumerate(rotcounts):
print("\t%d:\t%d" % (rots, numrot))
def main(argv=[__name__]):
if len(argv) != 2:
oechem.OEThrow.Usage("%s <infile>" % argv[0])
ifs = oechem.oemolistream()
if not ifs.open(argv[1]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1])
CountRotors(ifs)
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 87: Exporting SD data to a CSV file.
#!/usr/bin/env python
# (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.
#############################################################################
# Extract properties from SD file and save as CSV
#############################################################################
import sys
from openeye import oechem
def SDF2CSV(ifs, csv):
taglist = []
# read through once to find all unique tags
for mol in ifs.GetOEGraphMols():
for dp in oechem.OEGetSDDataPairs(mol):
if dp.GetTag() not in taglist:
taglist.append(dp.GetTag())
ifs.rewind()
# print out column labels
header = "Title"
for tag in taglist:
header += ",%s" % tag
header += '\n'
csv.write(header)
# build csv file
for mol in ifs.GetOEGraphMols():
line = [mol.GetTitle()]
for tag in taglist:
if oechem.OEHasSDData(mol, tag):
value = oechem.OEGetSDData(mol, tag)
else:
value = ''
line.append(',')
line.append(value)
csv.write(''.join(line))
csv.write('\n')
def main(argv=[__name__]):
if len(argv) != 3:
oechem.OEThrow.Usage("%s <infile> <csvfile>" % argv[0])
ifs = oechem.oemolistream()
if not ifs.open(argv[1]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1])
if ifs.GetFormat() not in [oechem.OEFormat_SDF, oechem.OEFormat_OEB]:
oechem.OEThrow.Fatal("Only works for sdf or oeb input files")
csv = oechem.oeofstream()
if not csv.open(argv[2]):
oechem.OEThrow.Fatal("Unable to open %s for writing" % argv[2])
SDF2CSV(ifs, csv)
if __name__ == '__main__':
sys.exit(main(sys.argv))
Listing 88: Filter molecules by SD data.
#!/usr/bin/env python
# (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.
#############################################################################
# Filter molecules by SD data
#############################################################################
import sys
from openeye import oechem
def main(argv=[__name__]):
itf = oechem.OEInterface(InterfaceData, argv)
if not (itf.HasDouble("-min") or itf.HasDouble("-max")):
oechem.OEThrow.Fatal("Please set a filter value with -min or -max")
ifs = oechem.oemolistream()
if not ifs.open(itf.GetString("-i")):
oechem.OEThrow.Fatal("Unable to open %s for reading" % itf.GetString("-i"))
if not oechem.OEIsSDDataFormat(ifs.GetFormat()):
oechem.OEThrow.Fatal("Only works for input file formats that support SD data (sdf,oeb,csv)")
ofs = oechem.oemolostream()
if not ofs.open(itf.GetString("-o")):
oechem.OEThrow.Fatal("Unable to open %s for writing" % itf.GetString("-i"))
if not oechem.OEIsSDDataFormat(ofs.GetFormat()):
oechem.OEThrow.Fatal("Only works for output file formats that support SD data \
(sdf,oeb,csv)")
tag = itf.GetString("-tag")
minval = float("-inf")
if itf.HasDouble("-min"):
minval = itf.GetDouble("-min")
maxval = float("inf")
if itf.HasDouble("-max"):
maxval = itf.GetDouble("-max")
for mol in ifs.GetOEGraphMols():
if not oechem.OEHasSDData(mol, tag):
oechem.OEThrow.Warning(
"Unable to find %s tag on %s" % (tag, mol.GetTitle()))
continue
value = oechem.OEGetSDData(mol, tag)
try:
tagvalue = float(value)
except ValueError:
oechem.OEThrow.Warning("Failed to convert (%s) to a number in %s" %
(value, mol.GetTitle()))
continue
if tagvalue < minval:
continue
if tagvalue > maxval:
continue
oechem.OEWriteMolecule(ofs, mol)
InterfaceData = """
!BRIEF -i <input> -o <output> -tag <name> [-min <num>] [-max <num>]
!PARAMETER -i
!TYPE string
!REQUIRED true
!BRIEF Input file name
!KEYLESS 1
!END
!PARAMETER -o
!TYPE string
!REQUIRED true
!BRIEF Output file name
!KEYLESS 2
!END
!PARAMETER -tag
!TYPE string
!REQUIRED true
!BRIEF SD tag
!END
!PARAMETER -min
!TYPE double
!REQUIRED false
!BRIEF minimum value of SD tag
!END
!PARAMETER -max
!TYPE double
!REQUIRED false
!BRIEF maximum value of SD tag
!END
"""
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 89: Modifying SD tags.
#!/usr/bin/env python
# (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.
#############################################################################
# Modifies the SD data of a set of input molecules by clearing all tags,
# defining which tags to keep or defining which tags to remove
#############################################################################
import sys
from openeye import oechem
def ClearProps(ifs, ofs):
for mol in ifs.GetOEGraphMols():
oechem.OEClearSDData(mol)
oechem.OEWriteMolecule(ofs, mol)
def KeepProps(proplist, ifs, ofs):
for mol in ifs.GetOEGraphMols():
for dp in oechem.OEGetSDDataPairs(mol):
if dp.GetTag() not in proplist:
oechem.OEDeleteSDData(mol, dp.GetTag())
oechem.OEWriteMolecule(ofs, mol)
def RemoveProps(proplist, ifs, ofs):
for mol in ifs.GetOEGraphMols():
for tag in proplist:
oechem.OEDeleteSDData(mol, tag)
oechem.OEWriteMolecule(ofs, mol)
def ModProps(itf, ifs, ofs):
proplist = []
if itf.HasString("-keep"):
for prop in itf.GetStringList("-keep"):
proplist.append(prop)
KeepProps(proplist, ifs, ofs)
elif itf.HasString("-remove"):
for prop in itf.GetStringList("-remove"):
proplist.append(prop)
RemoveProps(proplist, ifs, ofs)
elif itf.GetBool("-clearAll"):
ClearProps(ifs, ofs)
def main(argv=[__name__]):
itf = oechem.OEInterface(InterfaceData, argv)
haskeep = itf.HasString("-keep")
hasremove = itf.HasString("-remove")
hasclear = itf.GetBool("-clearAll")
numoption = 0
for hasoption in [haskeep, hasremove, hasclear]:
if hasoption:
numoption += 1
if numoption != 1:
oechem.OEThrow.Usage("Need to pick one from -keep, -remove, or -clearAll")
ifs = oechem.oemolistream()
if not ifs.open(itf.GetString("-i")):
oechem.OEThrow.Fatal("Unable to open %s for reading" % itf.GetString("-i"))
if not oechem.OEIsSDDataFormat(ifs.GetFormat()):
oechem.OEThrow.Fatal("Only works for input file formats that support SD data (sdf,oeb,csv)")
ofs = oechem.oemolostream()
if not ofs.open(itf.GetString("-o")):
oechem.OEThrow.Fatal("Unable to open %s for writing" % itf.GetString("-o"))
if not oechem.OEIsSDDataFormat(ofs.GetFormat()):
oechem.OEThrow.Fatal("Only works for output file formats that support SD data \
(sdf,oeb,csv)")
ModProps(itf, ifs, ofs)
InterfaceData = """
!BRIEF [-remove] <prop1 prop2...> [-keep] <prop1 prop2...> [-clearAll] -i <input> -o <output>
!PARAMETER -i
!ALIAS -in
!TYPE string
!REQUIRED true
!BRIEF Input file name
!END
!PARAMETER -o
!ALIAS -out
!TYPE string
!REQUIRED true
!BRIEF Output file name
!END
!PARAMETER -keep
!ALIAS -k
!TYPE string
!LIST true
!BRIEF SD tags to be kept
!END
!PARAMETER -remove
!ALIAS -r
!TYPE string
!LIST true
!BRIEF SD tags to be removed
!END
!PARAMETER -clearAll
!ALIAS -c
!TYPE bool
!DEFAULT false
!BRIEF Removes all SD tags
!END
!END
"""
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 90: Renaming molecules by SD field.
#!/usr/bin/env python
# (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.
#############################################################################
# Rename SDF molecules by specified field
#############################################################################
import sys
from openeye import oechem
def Rename(ifs, ofs, fieldname):
for mol in ifs.GetOEGraphMols():
if oechem.OEHasSDData(mol, fieldname):
mol.SetTitle(oechem.OEGetSDData(mol, fieldname))
else:
title = mol.GetTitle()
oechem.OEThrow.Warning("Renaming of molecule %s failed; no field %s" %
(title, fieldname))
oechem.OEWriteMolecule(ofs, mol)
def main(argv=[__name__]):
if len(argv) != 4:
oechem.OEThrow.Usage("%s <fieldname> <infile> <outfile>" % argv[0])
fieldname = argv[1]
ifs = oechem.oemolistream()
if not ifs.open(argv[2]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[2])
if not oechem.OEIsSDDataFormat(ifs.GetFormat()):
oechem.OEThrow.Fatal("Only works for input file formats that support SD data (sdf,oeb,csv)")
ofs = oechem.oemolostream()
if not ofs.open(argv[3]):
oechem.OEThrow.Fatal("Unable to open %s for writing" % argv[3])
Rename(ifs, ofs, fieldname)
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 91: Perform SMARTS search on substructure database file.
#!/usr/bin/env python
# (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.
#############################################################################
# Performs SMARTS search on substructure database file
#############################################################################
import sys
from openeye import oechem
def main(argv=[__name__]):
itf = oechem.OEInterface(InterfaceData)
if not oechem.OEParseCommandLine(itf, argv):
oechem.OEThrow.Fatal("Unable to interpret command line.")
# check parameters
c = itf.GetBool("-count")
t = itf.GetBool("-titles")
o = itf.HasString("-out")
if not((c and not t and not o) or (not c and t and not o) or (not c and not t and o)):
oechem.OEThrow.Fatal("Counting (-c) or outputting titles (-t) or molecules (-o) "
"must be specified and are mutually exclusive.")
ofs = oechem.oemolostream()
if itf.HasString("-out"):
ofname = itf.GetString("-out")
if not ofs.open(ofname):
oechem.OEThrow.Fatal("Cannot open output file!")
dbfname = itf.GetString("-db")
smarts = itf.GetString("-smarts")
nrthreads = itf.GetUnsignedInt("-nrthreads")
maxmatches = itf.GetUnsignedInt("-maxmatches")
# initialize query
qmol = oechem.OEQMol()
if not oechem.OEParseSmarts(qmol, smarts):
oechem.OEThrow.Fatal("Unable to parse SMARTS pattern: %s" % smarts)
# initialize substructure search database
screentype = oechem.OEGetSubSearchScreenType(oechem.OESubSearchScreenType_SMARTS)
if not oechem.OEIsValidSubSearchDatabase(dbfname, screentype):
oechem.OEThrow.Fatal("Invalid SMARTS substructure search database file!")
ssdb = oechem.OESubSearchDatabase(oechem.OESubSearchDatabaseType_Default, nrthreads)
tracer = oechem.OEConsoleProgressTracer()
if not ssdb.Open(dbfname, tracer):
oechem.OEThrow.Fatal("Substructure search database can not be initialized!")
screenstr = screentype.GetName()
infomsg = "Using %d processor(s) to search database with '%s'"
oechem.OEThrow.Info(infomsg % (ssdb.NumProcessors(), screenstr))
# search database
if itf.GetBool("-count"):
oechem.OEThrow.Info("Number of hits: %d" % ssdb.NumMatches(qmol))
else:
query = oechem.OESubSearchQuery(qmol, maxmatches)
result = oechem.OESubSearchResult()
status = ssdb.Search(result, query)
print("Search status = ", oechem.OESubSearchStatusToName(status))
print("Number of targets = ", result.NumTargets())
print("Number of screened = ", result.NumScreened())
print("Number of searched = ", result.NumSearched())
print("Number of total matches = ", result.NumTotalMatches())
print("Number of kept matches = ", result.NumMatches())
if itf.GetBool("-titles"):
print("Matches:")
for index in result.GetMatchIndices():
print(ssdb.GetTitle(index))
elif itf.HasString("-out"):
mol = oechem.OEGraphMol()
for index in result.GetMatchIndices():
if ssdb.GetMolecule(mol, index):
oechem.OEWriteMolecule(ofs, mol)
return 0
#############################################################################
InterfaceData = """\
!BRIEF [options] -db <database> -s <smarts> -nrthreads <unsigned int>
!CATEGORY "input/output options"
!PARAMETER -database 1
!ALIAS -db
!TYPE string
!REQUIRED true
!VISIBILITY simple
!BRIEF Input substructure search database filename
!END
!PARAMETER -smarts 2
!ALIAS -s
!TYPE string
!REQUIRED true
!BRIEF SMARTS pattern, quote for safety
!END
!END
!CATEGORY "search types"
!PARAMETER -count
!ALIAS -c
!TYPE bool
!DEFAULT false
!BRIEF Output count of number matched
!END
!PARAMETER -titles
!ALIAS -t
!TYPE bool
!DEFAULT false
!BRIEF Output title of matches
!END
!PARAMETER -out
!ALIAS -o
!TYPE string
!BRIEF Output molecule filename of matches
!END
!END
!CATEGORY "other options"
!PARAMETER -nrthreads
!TYPE unsigned
!REQUIRED true
!DEFAULT 1
!BRIEF Number of processors used (zero means all available)
!END
!PARAMETER -maxmatches
!ALIAS -max
!TYPE unsigned
!DEFAULT 1000
!BRIEF The maximum number of matches returned in case of parameters (-titles) and (-out)
!END
!END
"""
#############################################################################
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 92: Setting mmCIF Chemical Component Header.
#!/usr/bin/env python
# (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.
#############################################################################
# Simple superimposition of a fit protein on to a reference protein
#############################################################################
import sys
import os
from openeye import oechem
def main(argv=[__name__]):
if len(argv) < 3:
oechem.OEThrow.Usage(f"{argv[0]} <input CIF> <reference cif oeb> <output CIF>") # noqa
file1 = os.path.basename(argv[1])
_, ext1 = os.path.splitext(argv[1])
if ext1 != '.cif':
oechem.OEThrow.Usage(f"Input file {argv[1]} should be a CIF file.")
file2 = os.path.basename(argv[2])
_, ext3 = os.path.splitext(argv[3])
if ext3 != '.cif':
oechem.OEThrow.Usage(f"Output file {argv[3]} should be a CIF file.")
ifs = oechem.oemolistream()
if not ifs.open(argv[1]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1])
mol = oechem.OEMol()
if not oechem.OEReadMolecule(ifs, mol):
oechem.OEThrow.Fatal("Unable to read molecule from %s" % argv[1])
ifs = oechem.oemolistream()
if not ifs.open(argv[2]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[2])
rmol = oechem.OEMol()
if not oechem.OEReadMolecule(ifs, rmol):
oechem.OEThrow.Fatal("Unable to read molecule from %s" % argv[2])
if not oechem.OEHasResidues(mol) or not oechem.OEHasResidues(rmol):
oechem.OEThrow.Fatal("Input molecule(s) do not contain any residues.")
cifData = oechem.OECIFData(mol)
opts = oechem.OECIFOptions()
opts.SetPerceiveChemComp(True)
if not cifData.Update(mol, opts):
oechem.OEThrow.Warning("Molecule missing header information and could not update.")
if not cifData.SetMMCIFChemCompData(mol, rmol, False):
oechem.OEThrow.Fatal(f"Could not apply reference molecule {file2} to _chem_comp header in {file1}.")
oechem.OESetMMCIFData(mol, cifData)
ofs = oechem.oemolostream(argv[3])
if not ofs.open(argv[3]):
oechem.OEThrow.Fatal("Unable to open %s for writing" % argv[3])
oechem.OEWriteMolecule(ofs, mol)
ofs.close()
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 93: Filter molecules by weight or heavy atom count.
#!/usr/bin/env python
# (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.
#############################################################################
# Filter out molecules by their molecular weight or heavy atom count
#############################################################################
import sys
from openeye import oechem
def IsBetween(min, max, val):
if min <= val <= max:
return True
return False
def IsMoleculeInHeavyAtomCountRange(min, max, mol):
count = oechem.OECount(mol, oechem.OEIsHeavy())
return IsBetween(min, max, count)
def IsMoleculeInMolWtRange(min, max, mol):
molwt = oechem.OECalculateMolecularWeight(mol)
return IsBetween(min, max, molwt)
def main(argv=[__name__]):
itf = oechem.OEInterface(InterfaceData, argv)
ifs = oechem.oemolistream()
if not ifs.open(itf.GetString("-i")):
oechem.OEThrow.Fatal("Unable to open %s for reading" % itf.GetString("-i"))
ofs = oechem.oemolostream(".ism")
if itf.HasString("-o"):
if not ofs.open(itf.GetString("-o")):
oechem.OEThrow.Fatal("Unable to open %s for writing" % itf.GetString("-o"))
minhac = float("-inf")
if itf.HasInt("-minhac"):
minhac = itf.GetInt("-minhac")
maxhac = float("inf")
if itf.HasInt("-maxhac"):
maxhac = itf.GetInt("-maxhac")
minwt = float("-inf")
if itf.HasDouble("-minwt"):
minwt = itf.GetDouble("-minwt")
maxwt = float("inf")
if itf.HasDouble("-maxwt"):
maxwt = itf.GetDouble("-maxwt")
for mol in ifs.GetOEMols():
if not IsMoleculeInHeavyAtomCountRange(minhac, maxhac, mol):
continue
if not IsMoleculeInMolWtRange(minwt, maxwt, mol):
continue
oechem.OEWriteMolecule(ofs, mol)
InterfaceData = """
!BRIEF [-minhac <num>] [-maxhac <num>] [-minwt <num>] [-maxwt <num>] [-i] <input> [[-o] <output>]
!PARAMETER -i
!TYPE string
!REQUIRED true
!BRIEF Input file name
!KEYLESS 1
!END
!PARAMETER -o
!TYPE string
!REQUIRED false
!BRIEF Output file name
!KEYLESS 2
!END
!PARAMETER -minhac
!TYPE int
!REQUIRED false
!BRIEF minimum heavy atom count
!END
!PARAMETER -maxhac
!TYPE int
!REQUIRED false
!BRIEF maximum heavy atom count
!END
!PARAMETER -minwt
!TYPE double
!REQUIRED false
!BRIEF minimum molecular weight
!END
!PARAMETER -maxwt
!TYPE double
!REQUIRED false
!BRIEF maximum molecular weight
!END
"""
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 94: Align molecules by SMARTS match.
#!/usr/bin/env python
# (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.
#############################################################################
# Align two compounds based on smarts match
#############################################################################
import sys
from openeye import oechem
def SmartsAlign(refmol, fitmol, ss, ofs):
unique = True
for match1 in ss.Match(refmol, unique):
for match2 in ss.Match(fitmol, unique):
match = oechem.OEMatch()
for mp1, mp2 in zip(match1.GetAtoms(), match2.GetAtoms()):
match.AddPair(mp1.target, mp2.target)
overlay = True
rmat = oechem.OEDoubleArray(9)
trans = oechem.OEDoubleArray(3)
oechem.OERMSD(refmol, fitmol, match, overlay, rmat, trans)
oechem.OERotate(fitmol, rmat)
oechem.OETranslate(fitmol, trans)
oechem.OEWriteConstMolecule(ofs, fitmol)
def main(argv=[__name__]):
if len(argv) != 5:
oechem.OEThrow.Usage("%s <refmol> <fitmol> <outfile> <smarts>" % argv[0])
reffs = oechem.oemolistream()
if not reffs.open(argv[1]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1])
if not oechem.OEIs3DFormat(reffs.GetFormat()):
oechem.OEThrow.Fatal("Invalid input format: need 3D coordinates")
refmol = oechem.OEGraphMol()
if not oechem.OEReadMolecule(reffs, refmol):
oechem.OEThrow.Fatal("Unable to read molecule in %s" % argv[1])
if not refmol.GetDimension() == 3:
oechem.OEThrow.Fatal("%s doesn't have 3D coordinates" % refmol.GetTitle())
fitfs = oechem.oemolistream()
if not fitfs.open(argv[2]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[2])
if not oechem.OEIs3DFormat(fitfs.GetFormat()):
oechem.OEThrow.Fatal("Invalid input format: need 3D coordinates")
ofs = oechem.oemolostream()
if not ofs.open(argv[3]):
oechem.OEThrow.Fatal("Unable to open %s for writing" % argv[3])
if not oechem.OEIs3DFormat(ofs.GetFormat()):
oechem.OEThrow.Fatal("Invalid output format: need 3D coordinates")
oechem.OEWriteConstMolecule(ofs, refmol)
ss = oechem.OESubSearch()
if not ss.Init(argv[4]):
oechem.OEThrow.Fatal("Unable to parse SMARTS: %s" % argv[4])
oechem.OEPrepareSearch(refmol, ss)
if not ss.SingleMatch(refmol):
oechem.OEThrow.Fatal("SMARTS fails to match refmol")
for fitmol in fitfs.GetOEGraphMols():
if not fitmol.GetDimension() == 3:
oechem.OEThrow.Warning("%s doesn't have 3D coordinates" % fitmol.GetTitle())
continue
oechem.OEPrepareSearch(fitmol, ss)
if not ss.SingleMatch(fitmol):
oechem.OEThrow.Warning("SMARTS fails to match fitmol %s" % fitmol.GetTitle())
continue
SmartsAlign(refmol, fitmol, ss, ofs)
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 95: Strip salts.
#!/usr/bin/env python
# (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.
#############################################################################
# Remove salts and/or remove all but the largest molecule
#############################################################################
import sys
from openeye import oechem
def main(argv=[__name__]):
if len(argv) != 3:
oechem.OEThrow.Usage("%s <infile> <outfile>" % argv[0])
ifs = oechem.oemolistream()
if not ifs.open(argv[1]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1])
ofs = oechem.oemolostream()
if not ofs.open(argv[2]):
oechem.OEThrow.Fatal("Unable to open %s for writing" % argv[2])
for mol in ifs.GetOEMols():
oechem.OEDeleteEverythingExceptTheFirstLargestComponent(mol)
oechem.OEWriteMolecule(ofs, mol)
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 96: OE3DMolStyle hierarchy between molecule, conformers, and atoms.
#!/usr/bin/env python
# (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.
import sys
from openeye import oechem
def main(argv=[__name__]):
if len(argv) != 3:
oechem.OEThrow.Usage("%s <infile> <outfile>" % argv[0])
ifs = oechem.oemolistream()
if not ifs.open(argv[1]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1])
ofs = oechem.oemolostream()
if not ofs.open(argv[2]):
oechem.OEThrow.Fatal("Unable to open %s for writing" % argv[2])
for mol in ifs.GetOEMols():
mol.NewConf(mol)
mol.NewConf(mol)
molSty = oechem.OE3DMolStyle()
molSty.SetAtomStyle(oechem.OEAtomStyle_Wireframe)
molSty.SetAtomColorer(oechem.OEMolStyleColorer(oechem.OEBlue))
molSty.SetSurfaceColorer(oechem.OEMolStyleColorer(oechem.OEYellow))
molSty.SetHydrogenVisibility(oechem.OEHydrogenVisibility_Off)
molSty.SetSurfaceType(oechem.OESurfaceType_Molecular)
confSty = oechem.OE3DMolStyle()
confSty.SetAtomStyle(oechem.OEAtomStyle_CPK)
confSty.SetHydrogenVisibility(oechem.OEHydrogenVisibility_Polar)
atomSty = oechem.OE3DMolStyle()
atomSty.SetAtomStyle(oechem.OEAtomStyle_Stick)
atomSty.SetAtomColorer(oechem.OEMolStyleColorer(oechem.OEWhite))
atomSty.SetSurfaceType(oechem.OESurfaceType_Off)
atomSty2 = oechem.OE3DMolStyle()
atomSty2.SetAtomColorer(oechem.OEMolStyleColorer(oechem.OEPink))
oechem.OESetStyle(mol, molSty)
molConf1 = mol.GetConf(oechem.OEHasConfIdx(0))
oechem.OESetStyle(molConf1, confSty)
molAtom1 = mol.GetAtom(oechem.OEHasAtomIdx(0))
oechem.OESetStyle(molAtom1, atomSty)
molAtom2 = mol.GetAtom(oechem.OEHasAtomIdx(1))
oechem.OESetStyle(molAtom2, atomSty2)
if not oechem.OEHasStyle(mol):
oechem.OEThrow.Fatal("OE3DMolStyle was not applied to the OEMol")
oechem.OEWriteMolecule(ofs, mol)
# for conf in mol.GetConfs():
# tempConfSty = oechem.OE3DMolStyle()
# tempConfSty = oechem.OEGetStyle(conf)
# print(tempConfSty.GetString())
# for atom in mol.GetAtoms():
# tempAtomSty = oechem.OE3DMolStyle()
# tempAtomSty = oechem.OEGetStyle(atom)
# print(tempAtomSty.GetString())
# tempMolSty = oechem.OE3DMolStyle()
# tempMolSty = oechem.OEGetStyle(mol)
# print(tempMolSty.GetString())
if __name__ == "__main__":
sys.exit(main(sys.argv))
#This is a complicated example of adding multiple OE3DMolStyles to the connfomer, atoms, and molecule
#The mol will have a style that includes: Wireframe, blue, yellow molecular surface, no hydrogens
#The first conf will have a style that indludes: CPK, blue, yellow molecular surface, polar hydrogens
#The second conf will have the same style of the mol
#The first atom on the first conf will have a style that includes: Stick, white, no surface, polar hydrogens
#The first atom on the second conf will have a style that includes: Stick, white, no surface, no hydrogens
#The second atom on the first conf will have a style that includes: CPK, pink, blue molecular surface, polar H
#This shows the hierarchy of how the stle moves from mol to conf to atom
#The top level is always the mol, but the style in a conf will take priority
#The atom will have the style from the mol and conf, but if a OE3DMolStyle is added to an atom then it will take priority
Listing 97: Performing a reaction.
#!/usr/bin/env python
# (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.
#############################################################################
# Perform reactions on the given compounds
#############################################################################
import sys
from openeye import oechem
def UniMolRxn(ifs, ofs, umr):
for mol in ifs.GetOEGraphMols():
if umr(mol):
oechem.OEWriteMolecule(ofs, mol)
def main(argv=[__name__]):
if not (3 <= len(argv) <= 4):
oechem.OEThrow.Usage("%s SMIRKS <infile> [<outfile>]" % argv[0])
qmol = oechem.OEQMol()
if not oechem.OEParseSmirks(qmol, argv[1]):
oechem.OEThrow.Fatal("Unable to parse SMIRKS: %s" % argv[1])
umr = oechem.OEUniMolecularRxn()
if not umr.Init(qmol):
oechem.OEThrow.Fatal("Failed to initialize reaction with %s SMIRKS" % argv[1])
umr.SetClearCoordinates(True)
ifs = oechem.oemolistream()
if not ifs.open(argv[2]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[2])
ofs = oechem.oemolostream(".ism")
if len(argv) == 4:
if not ofs.open(argv[3]):
oechem.OEThrow.Fatal("Unable to open %s for writing" % argv[3])
UniMolRxn(ifs, ofs, umr)
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 98: Write out unique molecules (InChi).
#!/usr/bin/env python
# (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.
#############################################################################
# Read molecules and write out the unique ones. Two molecules are considered
# identical if their InChIs are identical.
#############################################################################
import sys
from openeye import oechem
def UniqInChI(ifs, ofs):
inchis = {}
for mol in ifs.GetOEMols():
inchi = oechem.OECreateInChI(mol)
if inchi not in inchis:
inchis[inchi] = True
oechem.OEWriteMolecule(ofs, mol)
def main(argv=[__name__]):
if len(argv) != 3:
oechem.OEThrow.Usage("%s <infile> <outfile>" % argv[0])
ifs = oechem.oemolistream()
if not ifs.open(argv[1]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1])
ofs = oechem.oemolostream()
if not ofs.open(argv[2]):
oechem.OEThrow.Fatal("Unable to open %s for writing" % argv[2])
UniqInChI(ifs, ofs)
if __name__ == "__main__":
sys.exit(main(sys.argv))
Listing 99: Write out unique molecules (canonical SMILES).
#!/usr/bin/env python
# (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.
#############################################################################
# Read molecules and write out the unique ones. Two molecules are considered
# identical if their canonical isomeric smiles are identical.
#############################################################################
import sys
from openeye import oechem
def UniqMol(ifs, ofs):
smiles = {}
for mol in ifs.GetOEMols():
smi = oechem.OEMolToSmiles(mol)
if smi not in smiles:
smiles[smi] = True
oechem.OEWriteMolecule(ofs, mol)
def main(argv=[__name__]):
if len(argv) != 3:
oechem.OEThrow.Usage("%s <infile> <outfile>" % argv[0])
ifs = oechem.oemolistream()
if not ifs.open(argv[1]):
oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1])
ofs = oechem.oemolostream()
if not ofs.open(argv[2]):
oechem.OEThrow.Fatal("Unable to open %s for writing" % argv[2])
UniqMol(ifs, ofs)
if __name__ == "__main__":
sys.exit(main(sys.argv))