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.

#include <openeye.h>
#include <oeplatform.h>
#include <oesystem.h>
#include <oechem.h>

using namespace std;
using namespace OEPlatform;
using namespace OESystem;
using namespace OEChem;

int main()
{
  OEGraphMol mol;
  OESmilesToMol(mol, "c1ccccc1Cl chlorobenzene");

  const vector<pair<string, string> > bindings = { make_pair("halogen", "[$smallhals,$largehals]"),
                                                   make_pair("smallhals", "[F,Cl]"),
                                                   make_pair("largehals", "[Br,I]")};

  string smarts("c[$halogen]");
  OESmartsLexReplace(smarts, bindings);
  OEThrow.Info("SMARTS = %s", smarts.c_str());

  OESubSearch subsrch(smarts.c_str());

  OEPrepareSearch(mol, subsrch);
  if (subsrch.SingleMatch(mol))
    OEThrow.Info("Match to %s", mol.GetTitle());

  return 0;
}

The output of the above code snippet is the following:

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