OESmartsLexReplaceΒΆ

bool OESmartsLexReplace(std::string &smarts,
                        const std::vector<std::pair<std::string,std::string> > &bindings)

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.

#!/usr/bin/env python
from __future__ import print_function
from openeye.oechem import *

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

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

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

subsrch = OESubSearch(smarts)

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