OBSmartsPattern Class Reference

SMARTS (SMiles ARbitrary Target Specification) substructure searching. More...

#include <parsmart.h>

List of all members.

Public Member Functions

 OBSmartsPattern ()
virtual ~OBSmartsPattern ()
 OBSmartsPattern (const OBSmartsPattern &cp)
OBSmartsPatternoperator= (const OBSmartsPattern &cp)
unsigned int NumMatches () const
unsigned int NumAtoms () const
unsigned int NumBonds () const
int GetAtomicNum (int)
void GetBond (int &, int &, int &, int)
int GetCharge (int)
const std::string & GetSMARTS () const
std::string & GetSMARTS ()
int GetVectorBinding (int idx) const
bool Empty () const
bool IsValid () const
bool Init (const char *)
bool Init (const std::string &)
void WriteMapList (std::ostream &)
bool Match (OBMol &mol, bool single=false)
bool RestrictedMatch (OBMol &mol, std::vector< std::pair< int, int > > &pairs, bool single=false)
bool RestrictedMatch (OBMol &mol, OBBitVec &bv, bool single=false)
std::vector< std::vector<
int > > & 
GetMapList ()
std::vector< std::vector<
int > > & 
GetUMapList ()
std::vector< std::vector<
int > >::iterator 
BeginMList ()
std::vector< std::vector<
int > >::iterator 
EndMList ()

Protected Attributes

std::vector< bool > _growbond
std::vector< std::vector<
int > > 
_mlist
Pattern_pat
std::string _str


Detailed Description

SMARTS (SMiles ARbitrary Target Specification) substructure searching.

Substructure search is an incredibly useful tool in the context of a small molecule programming library. Having an efficient substructure search engine reduces the amount of hard code needed for molecule perception, as well as increases the flexibility of certain operations. For instance, atom typing can be easily performed based on hard coded rules of element type and bond orders (or hybridization). Alternatively, atom typing can also be done by matching a set of substructure rules read at run time. In the latter case customization based on application (such as changing the pH) becomes a facile operation. Fortunately for Open Babel and its users, Roger Sayle donated a SMARTS parser which became the basis for SMARTS matching in Open Babel.

The SMARTS matcher, or OBSmartsPattern, is a separate object which can match patterns in the OBMol class. The following code demonstrates how to use the OBSmartsPattern class:

  OBMol mol;
  ...
  OBSmartsPattern sp;
  sp.Init("CC");
  sp.Match(mol);
  vector<vector<int> > maplist;
  maplist = sp.GetMapList();
  //or maplist = sp.GetUMapList();
  //print out the results
  vector<vector<int> >::iterator i;
  vector<int>::iterator j;
  for (i = maplist.begin();i != maplist.end();i++)
  {
  for (j = i->begin();j != i->end();j++)
  cout << j << ' `;
  cout << endl;
  }
The preceding code reads in a molecule, initializes a smarts pattern of two single-bonded carbons, and locates all instances of the pattern in the molecule. Note that calling the Match() function does not return the results of the substructure match. The results from a match are stored in the OBSmartsPattern, and a call to GetMapList() or GetUMapList() must be made to extract the results. The function GetMapList() returns all matches of a particular pattern while GetUMapList() returns only the unique matches. For instance, the pattern [OD1]~C~[OD1] describes a carboxylate group. This pattern will match both atom number permutations of the carboxylate, and if GetMapList() is called, both matches will be returned. If GetUMapList() is called only unique matches of the pattern will be returned. A unique match is defined as one which does not cover the identical atoms that a previous match has covered.


Constructor & Destructor Documentation

OBSmartsPattern (  )  [inline]

~OBSmartsPattern (  )  [virtual]

OBSmartsPattern ( const OBSmartsPattern cp  )  [inline]


Member Function Documentation

OBSmartsPattern& operator= ( const OBSmartsPattern cp  )  [inline]

unsigned int NumMatches (  )  const [inline]

unsigned int NumAtoms (  )  const [inline]

unsigned int NumBonds (  )  const [inline]

int GetAtomicNum ( int   ) 

void GetBond ( int &  ,
int &  ,
int &  ,
int   
)

int GetCharge ( int   ) 

const std::string& GetSMARTS (  )  const [inline]

std::string& GetSMARTS (  )  [inline]

int GetVectorBinding ( int  idx  )  const [inline]

bool Empty (  )  const [inline]

bool IsValid (  )  const [inline]

bool Init ( const char *   ) 

bool Init ( const std::string &   ) 

void WriteMapList ( std::ostream &   ) 

bool Match ( OBMol mol,
bool  single = false 
)

bool RestrictedMatch ( OBMol mol,
std::vector< std::pair< int, int > > &  pairs,
bool  single = false 
)

bool RestrictedMatch ( OBMol mol,
OBBitVec bv,
bool  single = false 
)

std::vector<std::vector<int> >& GetMapList (  )  [inline]

std::vector< std::vector< int > > & GetUMapList (  ) 

std::vector<std::vector<int> >::iterator BeginMList (  )  [inline]

std::vector<std::vector<int> >::iterator EndMList (  )  [inline]


Member Data Documentation

std::vector<bool> _growbond [protected]

std::vector<std::vector<int> > _mlist [protected]

Pattern* _pat [protected]

std::string _str [protected]


The documentation for this class was generated from the following files: