OESmartsLexReplace(smarts: str, bindings: List[(name, definition)]) -> modsmarts: str

Replaces all the instances of $varname in the SMARTS pattern smarts with the variables as defined by the mapping in bindings.

The following code demonstrates how to use SmartsLexReplace.

from openeye import oechem

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1ccccc1Cl chlorobenzene")

bindings = [("halogen", "[$smallhals,$largehals]"),
            ("smallhals", "[F,Cl]"),
            ("largehals", "[Br,I]")]

smarts = oechem.OESmartsLexReplace("c[$halogen]", bindings)
print("SMARTS =", smarts)

subsrch = oechem.OESubSearch(smarts)

oechem.OEPrepareSearch(mol, subsrch)
if subsrch.SingleMatch(mol):
    print("Match to", mol.GetTitle())

The output of the above code snippet is the following:

SMARTS = c[$([$([F,Cl]),$([Br,I])])]
Match to chlorobenzene