Appendix: Selected Examples in Python

These are full listings of programming examples that are excerpted or offered for download, elsewhere in this chapter. See a full list of examples in the Graphsim chapter.

Listing 1: Full listing of DBSimCalcFromFile.py.

#!/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 openeye import oegraphsim
import sys

if len(sys.argv) != 3:
    oechem.OEThrow.Usage("%s <queryfile> <targetfile>" % sys.argv[0])

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

qmol = oechem.OEGraphMol()
oechem.OEReadMolecule(ifs, qmol)
qfp = oegraphsim.OEFingerPrint()
oegraphsim.OEMakeFP(qfp, qmol, oegraphsim.OEFPType_Path)

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

fpdb = oegraphsim.OEFPDatabase(qfp.GetFPTypeBase())
for tmol in ifs.GetOEGraphMols():
    fpdb.AddFP(tmol)

for score in fpdb.GetScores(qfp):
    print("%.3f" % score.GetScore())

Listing 2: Full listing of DBSimCalcFromOEB.py.

#!/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 openeye import oegraphsim
import sys

if len(sys.argv) != 3:
    oechem.OEThrow.Usage("%s <queryfile> <targetfile>" % sys.argv[0])

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

qmol = oechem.OEGraphMol()
oechem.OEReadMolecule(ifs, qmol)
qfp = oegraphsim.OEFingerPrint()
oegraphsim.OEMakeFP(qfp, qmol, oegraphsim.OEFPType_Path)

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

fpdb = oegraphsim.OEFPDatabase(qfp.GetFPTypeBase())
for tmol in ifs.GetOEGraphMols():
    if tmol.HasData("PATH_FP"):
        tfp = tmol.GetData("PATH_FP")
        fpdb.AddFP(tfp)
    else:
        oechem.OEThrow.Warning("Unable to access fingerprint for %s" % tmol.GetTitle())
        fpdb.AddFP(tmol)

for score in fpdb.GetScores(qfp):
    print("%.3f" % score.GetScore())

Listing 3: Full listing of FP2OEB.py.

#!/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
from openeye import oegraphsim

if len(sys.argv) != 3:
    oechem.OEThrow.Usage("%s <infile> <outfile>" % sys.argv[0])

ifs = oechem.oemolistream()
if not ifs.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])
if ofs.GetFormat() != oechem.OEFormat_OEB:
    oechem.OEThrow.Fatal("%s output file has to be an OEBinary file" % sys.argv[2])

fp = oegraphsim.OEFingerPrint()
for mol in ifs.GetOEGraphMols():
    oegraphsim.OEMakeFP(fp, mol, oegraphsim.OEFPType_Path)
    mol.SetData("PATH_FP", fp)
    oechem.OEWriteMolecule(ofs, mol)

Listing 4: Full listing of FP2SDF.py.

#!/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
from openeye import oegraphsim

if len(sys.argv) != 3:
    oechem.OEThrow.Usage("%s <infile> <outfile>" % sys.argv[0])

ifs = oechem.oemolistream()
if not ifs.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])
if ofs.GetFormat() != oechem.OEFormat_SDF:
    oechem.OEThrow.Fatal("%s output file has to be an SDF file" % sys.argv[2])

fp = oegraphsim.OEFingerPrint()
for mol in ifs.GetOEGraphMols():
    oegraphsim.OEMakeFP(fp, mol, oegraphsim.OEFPType_Circular)
    fptypestr = fp.GetFPTypeBase().GetFPTypeString()
    fphexdata = fp.ToHexString()
    oechem.OESetSDData(mol, fptypestr, fphexdata)
    oechem.OEWriteMolecule(ofs, mol)

Listing 5: Full listing of FPAtomTyping.py.

#!/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 openeye import oegraphsim


def PrintTanimoto(molA, molB, atype, btype):
    fpA = oegraphsim.OEFingerPrint()
    fpB = oegraphsim.OEFingerPrint()
    numbits = 2048
    minb = 0
    maxb = 5
    oegraphsim.OEMakePathFP(fpA, molA, numbits, minb, maxb, atype, btype)
    oegraphsim.OEMakePathFP(fpB, molB, numbits, minb, maxb, atype, btype)
    print("Tanimoto(A,B) = %.3f" % oegraphsim.OETanimoto(fpA, fpB))


molA = oechem.OEGraphMol()
oechem.OESmilesToMol(molA, "Oc1c2c(cc(c1)CF)CCCC2")
molB = oechem.OEGraphMol()
oechem.OESmilesToMol(molB, "c1ccc2c(c1)c(cc(n2)CCl)N")

PrintTanimoto(molA, molB, oegraphsim.OEFPAtomType_DefaultAtom, oegraphsim.OEFPBondType_DefaultBond)
PrintTanimoto(molA, molB, oegraphsim.OEFPAtomType_DefaultAtom | oegraphsim.OEFPAtomType_EqAromatic,
              oegraphsim.OEFPBondType_DefaultBond)
PrintTanimoto(molA, molB, oegraphsim.OEFPAtomType_Aromaticity, oegraphsim.OEFPBondType_DefaultBond)
PrintTanimoto(molA, molB, oegraphsim.OEFPAtomType_InRing, oegraphsim.OEFPBondType_InRing)

Listing 6: Full listing of FPBitString.py.

#!/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 openeye import oegraphsim


def GetBitString(fp):
    bitstring = ''
    for b in range(0, fp.GetSize()):
        if fp.IsBitOn(b):
            bitstring += '1'
        else:
            bitstring += '0'

    return bitstring


mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1ccncc1")
fp = oegraphsim.OEFingerPrint()
oegraphsim.OEMakeFP(fp, mol, oegraphsim.OEFPType_MACCS166)
print(GetBitString(fp))

Listing 7: Full listing of FPCoverage.py.

#!/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 openeye import oegraphsim

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "CCNCC")

fptype = oegraphsim.OEGetFPType(oegraphsim.OEFPType_Path)
unique = True
for idx, abset in enumerate(oegraphsim.OEGetFPCoverage(mol, fptype, unique)):
    print("%2d %s" % ((idx + 1), "".join([str(a) for a in abset.GetAtoms()])))

Listing 8: Full listing of FPData.py.

#!/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 openeye import oegraphsim

tag = "FP_DATA"
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1ccccc1")

fp = oegraphsim.OEFingerPrint()
oegraphsim.OEMakeLingoFP(fp, mol)
mol.SetData(tag, fp)

if mol.HasData(tag):
    f = mol.GetData(tag)
    if f.IsValid():
        fptype = f.GetFPTypeBase().GetFPTypeString()
        print("%s fingerprint with `%s` identifier" % (fptype, tag))

Listing 9: Full listing of FPOverlap.py.

#!/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 openeye import oegraphsim

pmol = oechem.OEGraphMol()
oechem.OESmilesToMol(pmol, "c1cnc2c(c1)CC(CC2O)CF")

tmol = oechem.OEGraphMol()
oechem.OESmilesToMol(tmol, "c1cc2c(cc1)CC(CCl)CC2N")

fptype = oegraphsim.OEGetFPType("Tree,ver=2.0.0,size=4096,bonds=5-5,"
                                "atype=AtmNum|HvyDeg|EqHalo,btype=Order")

for idx, match in enumerate(oegraphsim.OEGetFPOverlap(pmol, tmol, fptype)):
    ostring = "match %2d: " % (idx + 1)
    for mpair in match.GetAtoms():
        p = mpair.pattern
        t = mpair.target
        ostring += "%d%s-%d%s " % (p.GetIdx(), oechem.OEGetAtomicSymbol(p.GetAtomicNum()),
                                   t.GetIdx(), oechem.OEGetAtomicSymbol(t.GetAtomicNum()))
    print(ostring)

Listing 10: Full listing of FPPathLength.py.

#!/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 openeye import oegraphsim


def PrintTanimoto(molA, molB, minb, maxb):
    fpA = oegraphsim.OEFingerPrint()
    fpB = oegraphsim.OEFingerPrint()
    numbits = 2048
    atype = oegraphsim.OEFPAtomType_DefaultPathAtom
    btype = oegraphsim.OEFPBondType_DefaultPathBond
    oegraphsim.OEMakePathFP(fpA, molA, numbits, minb, maxb, atype, btype)
    oegraphsim.OEMakePathFP(fpB, molB, numbits, minb, maxb, atype, btype)
    print("Tanimoto(A,B) = %.3f" % oegraphsim.OETanimoto(fpA, fpB))


molA = oechem.OEGraphMol()
oechem.OESmilesToMol(molA, "c1ccncc1")
molB = oechem.OEGraphMol()
oechem.OESmilesToMol(molB, "c1cc[nH]c1")

PrintTanimoto(molA, molB, 0, 3)
PrintTanimoto(molA, molB, 1, 3)
PrintTanimoto(molA, molB, 0, 4)
PrintTanimoto(molA, molB, 0, 5)

Listing 11: Full listing of FPPattern.py.

#!/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 openeye import oegraphsim

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "NCC(=O)[O-]")

fptype = oegraphsim.OEGetFPType("Tree,ver=2.0.0,size=4096,bonds=0-4,"
                                "atype=AtmNum|Arom|FCharge|HvyDeg,btype=Order")

for idx, pattern in enumerate(oegraphsim.OEGetFPPatterns(mol, fptype)):
    atomstr = " ".join([str(a) for a in pattern.GetAtoms()])
    print("%2d %5d %50s %s" % ((idx + 1), pattern.GetBit(), pattern.GetSmarts(), atomstr))

Listing 12: Calculate Tanimoto similarity scores.

#!/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 openeye import oegraphsim

molA = oechem.OEGraphMol()
oechem.OESmilesToMol(molA, "c1ccc2c(c1)c(c(oc2=O)OCCSC(=N)N)Cl")
fpA = oegraphsim.OEFingerPrint()
oegraphsim.OEMakeFP(fpA, molA, oegraphsim.OEFPType_MACCS166)

molB = oechem.OEGraphMol()
oechem.OESmilesToMol(molB, "COc1cc2ccc(cc2c(=O)o1)NC(=N)N")
fpB = oegraphsim.OEFingerPrint()
oegraphsim.OEMakeFP(fpB, molB, oegraphsim.OEFPType_MACCS166)

molC = oechem.OEGraphMol()
oechem.OESmilesToMol(molC, "COc1c(c2ccc(cc2c(=O)o1)NC(=N)N)Cl")
fpC = oegraphsim.OEFingerPrint()
oegraphsim.OEMakeFP(fpC, molC, oegraphsim.OEFPType_MACCS166)

print("Tanimoto(A,B) = %.3f" % oegraphsim.OETanimoto(fpA, fpB))
print("Tanimoto(A,C) = %.3f" % oegraphsim.OETanimoto(fpA, fpC))
print("Tanimoto(B,C) = %.3f" % oegraphsim.OETanimoto(fpB, fpC))

Listing 13: Full listing of MemSimSearch.py.

#!/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
from openeye import oegraphsim

if len(sys.argv) != 2:
    oechem.OEThrow.Usage("%s <database>" % sys.argv[0])

ifs = oechem.oemolistream()
if not ifs.open(sys.argv[1]):
    oechem.OEThrow.Fatal("Cannot open database molecule file!")

# load molecules

moldb = oechem.OEMolDatabase(ifs)
nrmols = moldb.GetMaxMolIdx()

# generate fingerprints

fpdb = oegraphsim.OEFPDatabase(oegraphsim.OEFPType_Path)

emptyfp = oegraphsim.OEFingerPrint()
emptyfp.SetFPTypeBase(fpdb.GetFPTypeBase())

mol = oechem.OEGraphMol()
for idx in range(0, nrmols):
    if moldb.GetMolecule(mol, idx):
        fpdb.AddFP(mol)
    else:
        fpdb.AddFP(emptyfp)

nrfps = fpdb.NumFingerPrints()

timer = oechem.OEWallTimer()
while True:

    # read query SMILES from stdin

    sys.stdout.write("Enter SMILES> ")
    line = sys.stdin.readline()
    line = line.rstrip()
    if len(line) == 0:
        sys.exit(0)

    # parse query

    query = oechem.OEGraphMol()
    if not oechem.OESmilesToMol(query, line):
        oechem.OEThrow.Warning("Invalid SMILES string")
        continue

    # calculate similarity scores

    timer.Start()
    scores = fpdb.GetSortedScores(query, 5)
    oechem.OEThrow.Info("%5.2f seconds to search %i fingerprints" % (timer.Elapsed(), nrfps))

    hit = oechem.OEGraphMol()
    for si in scores:
        if moldb.GetMolecule(hit, si.GetIdx()):
            smi = oechem.OEMolToSmiles(hit)
            oechem.OEThrow.Info("Tanimoto score %4.3f %s" % (si.GetScore(), smi))

Listing 14: Full listing of PathFPType.py.

#!/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 openeye import oegraphsim

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1ccccc1")

fpA = oegraphsim.OEFingerPrint()
numbits = 1024
minbonds = 0
maxbonds = 5
oegraphsim.OEMakePathFP(fpA, mol, numbits, minbonds, maxbonds,
                        oegraphsim.OEFPAtomType_DefaultPathAtom,
                        oegraphsim.OEFPBondType_DefaultPathBond)
fpB = oegraphsim.OEFingerPrint()
numbits = 2048
oegraphsim.OEMakePathFP(fpB, mol, numbits, minbonds, maxbonds,
                        oegraphsim.OEFPAtomType_DefaultPathAtom,
                        oegraphsim.OEFPBondType_DefaultPathBond)
print("same fingerprint types = %r" % oegraphsim.OEIsSameFPType(fpA, fpB))
print(oegraphsim.OETanimoto(fpA, fpB))

Listing 15: Full listing of SDF2FP.py.

#!/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
from openeye import oegraphsim

if len(sys.argv) != 2:
    oechem.OEThrow.Usage("%s <infile>" % sys.argv[0])

ifs = oechem.oemolistream()
if not ifs.open(sys.argv[1]):
    oechem.OEThrow.Fatal("Unable to open %s for reading" % sys.argv[1])
if ifs.GetFormat() != oechem.OEFormat_SDF:
    oechem.OEThrow.Fatal("%s input file has to be an SDF file" % sys.argv[1])

molcounter = 0
fpcounter = 0
for mol in ifs.GetOEGraphMols():
    molcounter += 1
    for dp in oechem.OEGetSDDataPairs(mol):
        if oegraphsim.OEIsValidFPTypeString(dp.GetTag()):
            fpcounter += 1
            fptypestr = dp.GetTag()
            fphexdata = dp.GetValue()

            fp = oegraphsim.OEFingerPrint()
            fptype = oegraphsim.OEGetFPType(fptypestr)
            fp.SetFPTypeBase(fptype)
            fp.FromHexString(fphexdata)

print("Number of molecules = %d" % molcounter)
print("Number of fingerprints = %d" % fpcounter)

Listing 16: Full listing of SimCalcFromFile.py.

#!/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
from openeye import oegraphsim

if len(sys.argv) != 3:
    oechem.OEThrow.Usage("%s <queryfile> <targetfile>" % sys.argv[0])

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

qmol = oechem.OEGraphMol()
if not oechem.OEReadMolecule(ifs, qmol):
    oechem.OEThrow.Fatal("Unable to read query molecule")
qfp = oegraphsim.OEFingerPrint()
oegraphsim.OEMakeFP(qfp, qmol, oegraphsim.OEFPType_Path)

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

tfp = oegraphsim.OEFingerPrint()
for tmol in ifs.GetOEGraphMols():
    oegraphsim.OEMakeFP(tfp, tmol, oegraphsim.OEFPType_Path)
    print("%.3f" % oegraphsim.OETanimoto(qfp, tfp))

Listing 17: Full listing of SimCalcFromOEB.py.

#!/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
from openeye import oegraphsim

if len(sys.argv) != 3:
    oechem.OEThrow.Usage("%s <queryfile> <targetfile>" % sys.argv[0])

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

qmol = oechem.OEGraphMol()
if not oechem.OEReadMolecule(ifs, qmol):
    oechem.OEThrow.Fatal("Unable to read query molecule")
qfp = oegraphsim.OEFingerPrint()
oegraphsim.OEMakeFP(qfp, qmol, oegraphsim.OEFPType_Path)

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

tfp = oegraphsim.OEFingerPrint()
for tmol in ifs.GetOEGraphMols():
    if tmol.HasData("PATH_FP"):
        tfp = tmol.GetData("PATH_FP")
    else:
        oechem.OEThrow.Warning("Unable to access fingerprint for %s" % tmol.GetTitle())
        oegraphsim.OEMakeFP(tfp, tmol, oegraphsim.OEFPType_Path)
    print("%.3f" % oegraphsim.OETanimoto(qfp, tfp))

Listing 18: Generating fingerprint file for fast fingerprint 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 binary fingerprint file for fast fingerprint search
#############################################################################

import sys
import os
from openeye import oechem
from openeye import oegraphsim


def main(argv=[__name__]):

    itf = oechem.OEInterface()
    oechem.OEConfigure(itf, InterfaceData)
    oegraphsim.OEConfigureFingerPrint(itf, oegraphsim.OEGetFPType(oegraphsim.OEFPType_Tree))

    if not oechem.OEParseCommandLine(itf, argv):
        return 1

    ifname = itf.GetString("-in")
    ffname = itf.GetString("-fpdb")

    if oechem.OEGetFileExtension(ffname) != "fpbin":
        oechem.OEThrow.Fatal("Fingerprint database file should have '.fpbin' file extension!")

    idxfname = oechem.OEGetMolDatabaseIdxFileName(ifname)

    if not os.path.exists(idxfname):
        if not oechem.OECreateMolDatabaseIdx(ifname):
            oechem.OEThrow.Warning("Unable to create %s molecule index file" % idxfname)

    oechem.OEThrow.Info("Using %s index molecule file" % idxfname)

    moldb = oechem.OEMolDatabase()
    if not moldb.Open(ifname):
        oechem.OEThrow.Fatal("Cannot open molecule database file!")

    nrmols = moldb.GetMaxMolIdx()

    fptype = oegraphsim.OESetupFingerPrint(itf)
    oechem.OEThrow.Info("Using fingerprint type %s" % fptype.GetFPTypeString())

    opts = oegraphsim.OECreateFastFPDatabaseOptions(fptype)
    opts.SetTracer(oechem.OEDots(100000, 1000, "fingerprints"))
    oechem.OEThrow.Info("Generating fingerprints with %d threads" % opts.GetNumProcessors())

    timer = oechem.OEWallTimer()
    if not oegraphsim.OECreateFastFPDatabaseFile(ffname, ifname, opts):
        oechem.OEThrow.Fatal("Cannot create fingerprint database file!")

    oechem.OEThrow.Info("%5.2f secs to generate %d fingerprints" % (timer.Elapsed(), nrmols))

    return 0


InterfaceData = """
!BRIEF [-in] <input> [-fpdbfname] <output>

!CATEGORY "input/output options"

  !PARAMETER -in
    !ALIAS -i
    !TYPE string
    !REQUIRED true
    !KEYLESS 1
    !VISIBILITY simple
    !BRIEF Input molecule filename
  !END

  !PARAMETER -fpdbfname
    !ALIAS -fpdb
    !TYPE string
    !REQUIRED true
    !KEYLESS 2
    !VISIBILITY simple
    !BRIEF Output fingerprint database filename
  !END

!END
"""

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

Listing 19: Searching fast fingerprint database.

#!/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.

#############################################################################
# Searching fast fingerprint database
#############################################################################
import sys
from openeye import oechem
from openeye import oegraphsim


def main(argv=[__name__]):

    itf = oechem.OEInterface()
    oechem.OEConfigure(itf, InterfaceData)

    defopts = oegraphsim.OEFPDatabaseOptions(10, oegraphsim.OESimMeasure_Tanimoto)
    oegraphsim.OEConfigureFPDatabaseOptions(itf, defopts)
    oegraphsim.OEConfigureFPDatabaseMemoryType(itf)

    if not oechem.OEParseCommandLine(itf, argv):
        return 0

    qfname = itf.GetString("-query")
    mfname = itf.GetString("-molfname")
    ffname = itf.GetString("-fpdbfname")
    ofname = itf.GetString("-out")

    # initialize databases

    timer = oechem.OEWallTimer()
    timer.Start()

    ifs = oechem.oemolistream()
    if not ifs.open(qfname):
        oechem.OEThrow.Fatal("Cannot open input file!")

    query = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, query):
        oechem.OEThrow.Fatal("Cannot read query molecule!")

    moldb = oechem.OEMolDatabase()
    if not moldb.Open(mfname):
        oechem.OEThrow.Fatal("Cannot open molecule database!")

    memtype = oegraphsim.OEGetFPDatabaseMemoryType(itf)

    fpdb = oegraphsim.OEFastFPDatabase(ffname, memtype)
    if not fpdb.IsValid():
        oechem.OEThrow.Fatal("Cannot open fingerprint database!")
    nrfps = fpdb.NumFingerPrints()
    memtypestr = fpdb.GetMemoryTypeString()

    ofs = oechem.oemolostream()
    if not ofs.open(ofname):
        oechem.OEThrow.Fatal("Cannot open output file!")

    if not oegraphsim.OEAreCompatibleDatabases(moldb, fpdb):
        oechem.OEThrow.Fatal("Databases are not compatible!")

    oechem.OEThrow.Info("%5.2f sec to initialize databases" % timer.Elapsed())

    fptype = fpdb.GetFPTypeBase()
    oechem.OEThrow.Info("Using fingerprint type %s" % fptype.GetFPTypeString())

    opts = oegraphsim.OEFPDatabaseOptions()
    oegraphsim.OESetupFPDatabaseOptions(opts, itf)

    # search fingerprint database

    timer.Start()
    scores = fpdb.GetSortedScores(query, opts)
    oechem.OEThrow.Info("%5.2f sec to search %d fingerprints %s"
                        % (timer.Elapsed(), nrfps, memtypestr))

    timer.Start()
    nrhits = 0
    hit = oechem.OEGraphMol()
    for si in scores:
        if moldb.GetMolecule(hit, si.GetIdx()):
            nrhits += 1
            oechem.OESetSDData(hit, "Similarity score", "%.2f" % si.GetScore())
            oechem.OEWriteMolecule(ofs, hit)
    oechem.OEThrow.Info("%5.2f sec to write %d hits" % (timer.Elapsed(), nrhits))

    return 0


InterfaceData = """
!BRIEF [-query] <molfile> [-molfname] <molfile> [-fpdbfname] <fpfile>  [-out] <molfile>

!CATEGORY "input/output options"

  !PARAMETER -query
    !ALIAS -q
    !TYPE string
    !REQUIRED true
    !KEYLESS 1
    !VISIBILITY simple
    !BRIEF Input query filename
  !END

  !PARAMETER -molfname
    !ALIAS -mol
    !TYPE string
    !REQUIRED true
    !KEYLESS 2
    !VISIBILITY simple
    !BRIEF Input molecule filename
  !END

  !PARAMETER -fpdbfname
    !ALIAS -fpdb
    !TYPE string
    !REQUIRED true
    !KEYLESS 3
    !VISIBILITY simple
    !BRIEF Input fast fingerprint database filename
  !END

  !PARAMETER -out
    !ALIAS -o
    !TYPE string
    !REQUIRED true
    !KEYLESS 4
    !VISIBILITY simple
    !BRIEF Output molecule filename
  !END

!END
"""

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

Listing 20: Building and searching fingerprint database.

#!/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.

#############################################################################
# Searching fingerprint database
#############################################################################
import sys
from openeye import oechem
from openeye import oegraphsim


def main(argv=[__name__]):

    itf = oechem.OEInterface()
    oechem.OEConfigure(itf, InterfaceData)

    defopts = oegraphsim.OEFPDatabaseOptions(10, oegraphsim.OESimMeasure_Tanimoto)
    oegraphsim.OEConfigureFPDatabaseOptions(itf, defopts)
    oegraphsim.OEConfigureFingerPrint(itf, oegraphsim.OEGetFPType(oegraphsim.OEFPType_Tree))

    if not oechem.OEParseCommandLine(itf, argv):
        return 0

    qfname = itf.GetString("-query")
    mfname = itf.GetString("-molfname")
    ofname = itf.GetString("-out")

    # initialize databases

    timer = oechem.OEWallTimer()
    timer.Start()

    ifs = oechem.oemolistream()
    if not ifs.open(qfname):
        oechem.OEThrow.Fatal("Cannot open input file!")

    query = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, query):
        oechem.OEThrow.Fatal("Cannot read query molecule!")

    moldb = oechem.OEMolDatabase()
    if not moldb.Open(mfname):
        oechem.OEThrow.Fatal("Cannot open molecule database!")

    ofs = oechem.oemolostream()
    if not ofs.open(ofname):
        oechem.OEThrow.Fatal("Cannot open output file!")

    fptype = oegraphsim.OESetupFingerPrint(itf)
    oechem.OEThrow.Info("Using fingerprint type %s" % fptype.GetFPTypeString())
    fpdb = oegraphsim.OEFPDatabase(fptype)

    emptyfp = oegraphsim.OEFingerPrint()
    emptyfp.SetFPTypeBase(fptype)

    nrmols = moldb.GetMaxMolIdx()

    mol = oechem.OEGraphMol()
    for idx in range(0, nrmols):
        if moldb.GetMolecule(mol, idx):
            fpdb.AddFP(mol)
        else:
            fpdb.AddFP(emptyfp)

    nrfps = fpdb.NumFingerPrints()
    oechem.OEThrow.Info("%5.2f sec to initialize databases" % timer.Elapsed())

    opts = oegraphsim.OEFPDatabaseOptions()
    oegraphsim.OESetupFPDatabaseOptions(opts, itf)

    # search fingerprint database

    timer.Start()
    scores = fpdb.GetSortedScores(query, opts)
    oechem.OEThrow.Info("%5.2f sec to search %d fingerprints" % (timer.Elapsed(), nrfps))

    timer.Start()
    hit = oechem.OEGraphMol()
    for si in scores:
        if moldb.GetMolecule(hit, si.GetIdx()):
            oechem.OEWriteMolecule(ofs, hit)
    oechem.OEThrow.Info("%5.2f sec to write %d hits" % (timer.Elapsed(), opts.GetLimit()))

    return 0


InterfaceData = """
!BRIEF [-query] <molfile> [-molfname] <molfile> [-out] <molfile>

!CATEGORY "input/output options"

  !PARAMETER -query
    !ALIAS -q
    !TYPE string
    !REQUIRED true
    !KEYLESS 1
    !VISIBILITY simple
    !BRIEF Input query filename
  !END

  !PARAMETER -molfname
    !ALIAS -mol
    !TYPE string
    !REQUIRED true
    !KEYLESS 2
    !VISIBILITY simple
    !BRIEF Input molecule filename
  !END

  !PARAMETER -out
    !ALIAS -o
    !TYPE string
    !REQUIRED true
    !KEYLESS 3
    !VISIBILITY simple
    !BRIEF Output molecule filename
  !END

!END
"""

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

Listing 21: Calculate similarity scores.

#!/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 openeye import oegraphsim
import sys

if len(sys.argv) != 3:
    oechem.OEThrow.Usage("%s <queryfile> <targetfile>" % sys.argv[0])

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

qmol = oechem.OEGraphMol()
oechem.OEReadMolecule(ifs, qmol)
qfp = oegraphsim.OEFingerPrint()
oegraphsim.OEMakeFP(qfp, qmol, oegraphsim.OEFPType_Path)

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


fpdb = oegraphsim.OEFPDatabase(qfp.GetFPTypeBase())
for tmol in ifs.GetOEGraphMols():
    fpdb.AddFP(tmol)

print("Tanimoto scores:")
descending = True
fpdb.SetSimFunc(oegraphsim.OESimMeasure_Tanimoto, descending)
fpdb.SetCutoff(0.1)
for score in fpdb.GetScores(qfp, 0, 100):
    print("%.3f" % score.GetScore())

fpdb.ClearCutoff()
print("Tversky scores:")
fpdb.SetSimFunc(oegraphsim.OETverskySim(0.9))
for score in fpdb.GetScores(qfp):
    print("%.3f" % score.GetScore())

print("Dice scores:")
descending = True
fpdb.SetSimFunc(oegraphsim.OESimMeasure_Dice, not descending)
fpdb.SetCutoff(0.5)
for score in fpdb.GetScores(qfp, 100):
    print("%.3f" % score.GetScore())

print("Cosine scores with option:")
opts = oegraphsim.OEFPDatabaseOptions()
opts.SetCutoff(0.3)
opts.SetSimFunc(oegraphsim.OESimMeasure_Cosine)
for score in fpdb.GetScores(qfp, opts):
    print("%.3f" % score.GetScore())

print("Tanimoto sorted scores:")
fpdb.ClearCutoff()  # default
descending = True
fpdb.SetSimFunc(oegraphsim.OESimMeasure_Tanimoto, descending)  # default
for score in fpdb.GetSortedScores(qfp, 10):
    print("%.3f" % score.GetScore())

print("Dice sorted scores:")
descending = True
fpdb.SetSimFunc(oegraphsim.OESimMeasure_Dice, descending)
fpdb.SetCutoff(0.5)
for score in fpdb.GetSortedScores(qfp, 0, 0, 100):
    print("%.3f" % score.GetScore())

print("Manhattan sorted scores:")
descending = True
fpdb.SetSimFunc(oegraphsim.OESimMeasure_Manhattan, not descending)
fpdb.SetCutoff(0.3)
for score in fpdb.GetSortedScores(qfp, 5, 100):
    print("%.3f" % score.GetScore())

print("Tversky sorted scores with options:")
opts = oegraphsim.OEFPDatabaseOptions()
opts.SetDescendingOrder(True)
opts.SetCutoff(0.3)
opts.SetSimFunc(oegraphsim.OESimMeasure_Tversky)
opts.SetTverskyCoeffs(0.9, 0.1)
opts.SetLimit(10)
for score in fpdb.GetSortedScores(qfp, opts):
    print("%.3f" % score.GetScore())

Listing 22: Perform multithreaded similarity calculation.

#!/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
from openeye import oegraphsim

if len(sys.argv) != 3:
    oechem.OEThrow.Usage("%s <molfname> <fpdbfname>" % sys.argv[0])

mfname = sys.argv[1]
ffname = sys.argv[2]

moldb = oechem.OEMolDatabase()
if not moldb.Open(mfname):
    oechem.OEThrow.Fatal("Cannot open molecule database!")

memtype = oegraphsim.OEFastFPDatabaseMemoryType_InMemory

fpdb = oegraphsim.OEFastFPDatabase(ffname, memtype)
if not fpdb.IsValid():
    oechem.OEThrow.Fatal("Cannot open fingerprint database!")

if not oegraphsim.OEAreCompatibleDatabases(moldb, fpdb):
    oechem.OEThrow.Fatal("Databases are not compatible!")

query = oechem.OEGraphMol()
oechem.OESmilesToMol(query, "Cc1c(c2cc(ccc2n1C(=O)c3ccc(cc3)Cl)OC)CC(=O)O")

limit = 5
opts = oegraphsim.OEFPDatabaseOptions(limit, oegraphsim.OESimMeasure_Tanimoto)

nrbins = 5
result = oegraphsim.OESimSearchResult(nrbins)
status = fpdb.SortedSearch(result, query, opts)
print("Search status = {}".format(oegraphsim.OESimSearchStatusToName(status)))
print("Number of searched = {}".format(result.NumSearched()))

# print scores
for score in result.GetSortedScores():
    print("{:.3f}".format(score.GetScore()))

# print histogram
hist = result.GetHistogram()
bounds = hist.GetBinBoundaries()
for idx, count in enumerate(hist.GetCounts()):
    print("[{:.3f}-{:.3f}] = {}".format(bounds[idx], bounds[idx+1], count))

Listing 23: Print out string representation of a circular fingerprint.

#!/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 oegraphsim

fptype = oegraphsim.OEGetFPType(oegraphsim.OEFPType_Circular)
print(fptype.GetFPTypeString())

Listing 24: Print out string representation of a path fingerprint.

#!/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 oegraphsim

fptype = oegraphsim.OEGetFPType(oegraphsim.OEFPType_Path)
print(fptype.GetFPTypeString())

Listing 25: Print out string representation of a tree fingerprint.

#!/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 oegraphsim

fptype = oegraphsim.OEGetFPType(oegraphsim.OEFPType_Tree)
print(fptype.GetFPTypeString())

Listing 26: simfunc.py full listing.

#!/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 openeye import oegraphsim


class SimpsonSimFunc(oegraphsim.OESimFuncBase):

    def __call__(self, fpA, fpB):
        onlyA, onlyB, bothAB, neitherAB = oechem.OEGetBitCounts(fpA, fpB)
        if onlyA + onlyB == 0:
            return 1.0
        if bothAB == 0:
            return 0.0
        sim = float(bothAB)
        sim /= min(float(onlyA + bothAB), float(onlyB + bothAB))
        return sim

    def GetSimTypeString(self):
        return "Simpson"

    def CreateCopy(self):
        return SimpsonSimFunc().__disown__()


smiles = ["c1ccc2c(c1)c(c(oc2=O)OCCSC(=N)N)Cl",
          "COc1cc2ccc(cc2c(=O)o1)NC(=N)N"]

fpdb = oegraphsim.OEFPDatabase(oegraphsim.OEFPType_Path)
fpdb.SetSimFunc(SimpsonSimFunc())

mol = oechem.OEGraphMol()
for smi in smiles:
    mol.Clear()
    oechem.OESmilesToMol(mol, smi)
    fpdb.AddFP(mol)

query = oechem.OEGraphMol()
oechem.OESmilesToMol(query, "COc1c(c2ccc(cc2c(=O)o1)NC(=N)N)Cl")
for score in fpdb.GetScores(query):
    print("%.3f" % score.GetScore())

Listing 27: makemaccsfp.py full listing.

#!/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 openeye import oegraphsim

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1ccccc1")

fp = oegraphsim.OEFingerPrint()
oegraphsim.OEMakeMACCS166FP(fp, mol)

print(fp.GetFPTypeBase().GetFPTypeString())

oegraphsim.OEMakeFP(fp, mol, oegraphsim.OEFPType_MACCS166)

print(fp.GetFPTypeBase().GetFPTypeString())

Listing 28: makelingofp.py full listing.

#!/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 openeye import oegraphsim

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1ccccc1")

fp = oegraphsim.OEFingerPrint()
oegraphsim.OEMakeLingoFP(fp, mol)

print(fp.GetFPTypeBase().GetFPTypeString())

oegraphsim.OEMakeFP(fp, mol, oegraphsim.OEFPType_Lingo)

print(fp.GetFPTypeBase().GetFPTypeString())

Listing 29: MakeCircularFP.py full listing.

#!/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 openeye import oegraphsim

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1ccccc1")

fp = oegraphsim.OEFingerPrint()
oegraphsim.OEMakeCircularFP(fp, mol)

print(fp.GetFPTypeBase().GetFPTypeString())

oegraphsim.OEMakeFP(fp, mol, oegraphsim.OEFPType_Circular)

print(fp.GetFPTypeBase().GetFPTypeString())

numbits = 1024
minradius = 0
maxradius = 3
oegraphsim.OEMakeCircularFP(fp, mol, numbits, minradius, maxradius,
                            oegraphsim.OEFPAtomType_DefaultCircularAtom,
                            oegraphsim.OEFPBondType_DefaultCircularBond)

print(fp.GetFPTypeBase().GetFPTypeString())

Listing 30: Make a path fingerprint.

#!/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 openeye import oegraphsim

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1ccccc1")

fp = oegraphsim.OEFingerPrint()
oegraphsim.OEMakePathFP(fp, mol)

print(fp.GetFPTypeBase().GetFPTypeString())

oegraphsim.OEMakeFP(fp, mol, oegraphsim.OEFPType_Path)

print(fp.GetFPTypeBase().GetFPTypeString())

numbits = 1024
minbonds = 0
maxbonds = 5
oegraphsim.OEMakePathFP(fp, mol, numbits, minbonds, maxbonds,
                        oegraphsim.OEFPAtomType_DefaultPathAtom,
                        oegraphsim.OEFPBondType_DefaultPathBond)

print(fp.GetFPTypeBase().GetFPTypeString())

Listing 31: Fingerprint types.

#!/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 openeye import oegraphsim

fpA = oegraphsim.OEFingerPrint()
fpB = oegraphsim.OEFingerPrint()
if not fpA.IsValid():
    print("uninitialized fingerprint")

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1ccccc1")

oegraphsim.OEMakeFP(fpA, mol, oegraphsim.OEFPType_Path)
oegraphsim.OEMakeFP(fpB, mol, oegraphsim.OEFPType_Lingo)

if oegraphsim.OEIsFPType(fpA, oegraphsim.OEFPType_Lingo):
    print("Lingo")
if oegraphsim.OEIsFPType(fpA, oegraphsim.OEFPType_Path):
    print("Path")

if oegraphsim.OEIsSameFPType(fpA, fpB):
    print("same fingerprint types")
else:
    print("different fingerprint types")

Listing 32: Compare fingerprint objects.

#!/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 openeye import oegraphsim

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1ccccc1")

fpA = oegraphsim.OEFingerPrint()
fpB = oegraphsim.OEFingerPrint()

oegraphsim.OEMakeFP(fpA, mol, oegraphsim.OEFPType_Path)
oegraphsim.OEMakeFP(fpB, mol, oegraphsim.OEFPType_Path)

if fpA == fpB:
    print("same fingerprints")
else:
    print("different fingerprints")

Listing 33: Return string representation of fingerprint type.

#!/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 openeye import oegraphsim

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1ccccc1")

fp = oegraphsim.OEFingerPrint()
oegraphsim.OEMakeFP(fp, mol, oegraphsim.OEFPType_Path)
print(fp.GetFPTypeBase().GetFPTypeString())

fp = oegraphsim.OEFingerPrint()
oegraphsim.OEMakeFP(fp, mol, oegraphsim.OEFPType_Path)
print(fp.GetFPTypeBase().GetFPVersionString())

Listing 34: Yule similarity measures.

#!/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 openeye import oegraphsim

molA = oechem.OEGraphMol()
oechem.OESmilesToMol(molA, "c1ccc2c(c1)c(c(oc2=O)OCCSC(=N)N)Cl")
fpA = oegraphsim.OEFingerPrint()

molB = oechem.OEGraphMol()
oechem.OESmilesToMol(molB, "COc1cc2ccc(cc2c(=O)o1)NC(=N)N")
fpB = oegraphsim.OEFingerPrint()

molC = oechem.OEGraphMol()
oechem.OESmilesToMol(molC, "COc1c(c2ccc(cc2c(=O)o1)NC(=N)N)Cl")
fpC = oegraphsim.OEFingerPrint()


def CalculateYule(fpA, fpB):
    onlyA, onlyB, bothAB, neitherAB = oechem.OEGetBitCounts(fpA, fpB)
    yule = float(bothAB * neitherAB - onlyA * onlyB)
    yule /= float(bothAB * neitherAB + onlyA * onlyB)
    return yule


oegraphsim.OEMakeFP(fpA, molA, oegraphsim.OEFPType_Path)
oegraphsim.OEMakeFP(fpB, molB, oegraphsim.OEFPType_Path)
oegraphsim.OEMakeFP(fpC, molC, oegraphsim.OEFPType_Path)

print("Yule(A,B) = %.3f" % CalculateYule(fpA, fpB))
print("Yule(A,C) = %.3f" % CalculateYule(fpA, fpC))
print("Yule(B,C) = %.3f" % CalculateYule(fpB, fpC))

Listing 35: Fingerprint 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 oegraphsim

fptype = oegraphsim.OEGetFPType(oegraphsim.OEFPType_Path)
prms = oegraphsim.OEFPTypeParams(fptype.GetFPTypeString())
print("version = %s" % oegraphsim.OEGetFingerPrintVersionString(prms.GetVersion()))
print("number of bits = %d" % prms.GetNumBits())
print("min bonds = %d" % prms.GetMinDistance())
print("max bonds = %d" % prms.GetMaxDistance())
print("atom types = %s" % oegraphsim.OEGetFPAtomType(prms.GetAtomTypes()))
print("bond types = %s" % oegraphsim.OEGetFPBondType(prms.GetBondTypes()))