Loading...
Searching...
No Matches
smartsMatcher.h
Go to the documentation of this file.
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#ifndef BALL_STRUCTURE_SMARTSMATCHER_H
#define BALL_STRUCTURE_SMARTSMATCHER_H
#ifndef BALL_STRUCTURE_SMARTSPARSER_H
# include <BALL/STRUCTURE/smartsParser.h>
#endif
#include <vector>
#include <set>
#include <map>
#include <boost/shared_ptr.hpp>
namespace BALL
{
// forward declaration
class Molecule;
class BALL_EXPORT SmartsMatcher
{
public:
typedef std::vector<std::set<const Atom*> > Match;
SmartsMatcher();
virtual ~SmartsMatcher();
void match(Match& matches, Molecule& mol, const String& smarts);
void match(Match& matches, Molecule& mol, const String& smarts, const std::set<const Atom*>& start_atoms);
void match(std::vector<Match>& matches, Molecule& mol, const std::vector<String>& smarts);
void match(std::vector<Match>& matches, Molecule& mol, const std::vector<String>& smarts, const std::set<const Atom*>& start_atoms);
void setSSSR(const std::vector<std::vector<Atom*> >& sssr);
void unsetSSSR();
private:
SmartsMatcher(const SmartsMatcher& matcher);
SmartsMatcher& operator = (const SmartsMatcher& matcher);
protected:
typedef SmartsParser::SPNode SPNode;
typedef SmartsParser::SPEdge SPEdge;
typedef SmartsParser::SPAtom SPAtom;
typedef SmartsParser::SPBond SPBond;
class RecStructCore_
{
public:
RecStructCore_();
RecStructCore_(const RecStructCore_&);
virtual ~RecStructCore_();
RecStructCore_& operator = (const RecStructCore_&);
void clear();
std::vector<std::set<const Atom*> > matched_atoms;
std::vector<std::map<const SPNode*, const Atom*> > mapped_atoms;
std::vector<std::set<const Atom*> > visited_atoms;
std::vector<std::set<const Bond*> > visited_bonds;
std::vector<std::set<const SPEdge*> > visited_edges;
std::vector<std::pair<const SPNode*, const Atom*> > first_matches;
};
class RecStructPool_
{
public:
RecStructPool_();
virtual ~RecStructPool_();
RecStructCore_* getNextFree();
Position getLastPosition();
void destroy(Position pos);
private:
void resize_();
RecStructPool_(const RecStructPool_&);
RecStructPool_& operator = (const RecStructPool_&);
std::vector<RecStructCore_*> rec_struct_pool_;
std::vector<Position> free_list_;
Position last_position_;
};
class RecStruct_
{
private:
RecStructCore_* rec_struct_core_;
public:
RecStruct_();
RecStruct_(const RecStruct_& rec_struct);
virtual ~RecStruct_();
RecStruct_& operator = (const RecStruct_&);
std::vector<std::set<const Atom*> >& matched_atoms;
std::vector<std::map<const SPNode*, const Atom*> >& mapped_atoms;
std::vector<std::set<const Atom*> >& visited_atoms;
std::vector<std::set<const Bond*> >& visited_bonds;
std::vector<std::set<const SPEdge*> >& visited_edges;
std::vector<std::pair<const SPNode*, const Atom*> >& first_matches;
void add(const RecStruct_& rec_struct);
void add(const RecStruct_& rec_struct, Size i);
void clear();
void dump(const String& name, Size depth_ = 0);
private:
Position pos_;
};
static boost::shared_ptr<RecStructPool_> pool_;
bool evaluateRingEdges_(const std::set<const Atom*>& matching, const std::map<const SPNode*, const Atom*>& mapping, const String& smarts);
void evaluate_( RecStruct_& rs, SPNode* start_node, const Atom* start_atom);
bool evaluate_node_(RecStruct_& rs, SPNode* start_node, const Atom* start_atom);
bool evaluate_edge_(RecStruct_& rs, SPEdge* start_node, const Atom* start_atom, const Bond* start_bond);
std::map<SPNode*, std::vector<std::set<const Atom*> > > rec_matches_;
bool has_user_sssr_;
std::vector<std::vector<Atom*> > sssr_;
// debug output depth
Size depth_;
};
} // namespace BALL
#endif // BALL_STRUCTURE_SMARTSMATCHER_H
BALL_EXPORT
#define BALL_EXPORT
Definition COMMON/global.h:50
BALL::Atom
Definition atom.h:90
BALL::Bond
Definition bond.h:57
BALL::Molecule
Definition molecule.h:31
BALL::SmartsMatcher::RecStructCore_
core structure of the recursive matching algorithm for the object pool
Definition smartsMatcher.h:115
BALL::SmartsMatcher::RecStructCore_::visited_atoms
std::vector< std::set< const Atom * > > visited_atoms
contains vector of visited atoms of different matches
Definition smartsMatcher.h:140
BALL::SmartsMatcher::RecStructCore_::visited_bonds
std::vector< std::set< const Bond * > > visited_bonds
contains vector of visited bonds of different matches
Definition smartsMatcher.h:143
BALL::SmartsMatcher::RecStructCore_::visited_edges
std::vector< std::set< const SPEdge * > > visited_edges
contains vector of visited edges of the Smarts tree of different matches
Definition smartsMatcher.h:146
BALL::SmartsMatcher::RecStructCore_::~RecStructCore_
virtual ~RecStructCore_()
destructor
BALL::SmartsMatcher::RecStructCore_::RecStructCore_
RecStructCore_(const RecStructCore_ &)
copy constructor
BALL::SmartsMatcher::RecStructCore_::mapped_atoms
std::vector< std::map< const SPNode *, const Atom * > > mapped_atoms
container which contains a vector of mappings from different matches
Definition smartsMatcher.h:137
BALL::SmartsMatcher::RecStructCore_::clear
void clear()
method that deletes all content from the containers
BALL::SmartsMatcher::RecStructCore_::first_matches
std::vector< std::pair< const SPNode *, const Atom * > > first_matches
contains the first matched atoms of different matches (needed for recursive Smarts)
Definition smartsMatcher.h:149
BALL::SmartsMatcher::RecStructCore_::RecStructCore_
RecStructCore_()
default constructor
BALL::SmartsMatcher::RecStructCore_::matched_atoms
std::vector< std::set< const Atom * > > matched_atoms
container which contains a vector of matched atoms from different matches
Definition smartsMatcher.h:134
BALL::SmartsMatcher::RecStructPool_::destroy
void destroy(Position pos)
frees the structure at position pos
BALL::SmartsMatcher::RecStructPool_::getNextFree
RecStructCore_ * getNextFree()
returns the a free RecStructCore_ of the pool (creates new ones if needed)
BALL::SmartsMatcher::RecStructPool_::getLastPosition
Position getLastPosition()
returns the position of the last RecStructCore_* from getNextFree()
BALL::SmartsMatcher::RecStructPool_::~RecStructPool_
virtual ~RecStructPool_()
destructor
BALL::SmartsMatcher::RecStructPool_::RecStructPool_
RecStructPool_()
default constructors
BALL::SmartsMatcher::RecStruct_
a wrapper class which is used as an interface in the matching code to the pool
Definition smartsMatcher.h:196
BALL::SmartsMatcher::RecStruct_::dump
void dump(const String &name, Size depth_=0)
dumps the contents (for debugging)
BALL::SmartsMatcher::RecStruct_::~RecStruct_
virtual ~RecStruct_()
destructor
BALL::SmartsMatcher::RecStruct_::visited_edges
std::vector< std::set< const SPEdge * > > & visited_edges
reference to the visited edges in the core structure
Definition smartsMatcher.h:228
BALL::SmartsMatcher::RecStruct_::RecStruct_
RecStruct_(const RecStruct_ &rec_struct)
copy constructor
BALL::SmartsMatcher::RecStruct_::clear
void clear()
deletes all contents
BALL::SmartsMatcher::RecStruct_::mapped_atoms
std::vector< std::map< const SPNode *, const Atom * > > & mapped_atoms
reference to the mapped SPNodes to Atoms in the core structure
Definition smartsMatcher.h:219
BALL::SmartsMatcher::RecStruct_::first_matches
std::vector< std::pair< const SPNode *, const Atom * > > & first_matches
reference to the first matches in the core structure
Definition smartsMatcher.h:231
BALL::SmartsMatcher::RecStruct_::visited_atoms
std::vector< std::set< const Atom * > > & visited_atoms
reference to the visited atoms in the core structure
Definition smartsMatcher.h:222
BALL::SmartsMatcher::RecStruct_::visited_bonds
std::vector< std::set< const Bond * > > & visited_bonds
reference to the visited bonds in the core structure
Definition smartsMatcher.h:225
BALL::SmartsMatcher::RecStruct_::matched_atoms
std::vector< std::set< const Atom * > > & matched_atoms
reference to the matched atoms in the core structure
Definition smartsMatcher.h:216
BALL::SmartsMatcher::RecStruct_::add
void add(const RecStruct_ &rec_struct)
adds the content of the given struct
BALL::SmartsMatcher::RecStruct_::RecStruct_
RecStruct_()
default constructor
BALL::SmartsMatcher::RecStruct_::add
void add(const RecStruct_ &rec_struct, Size i)
adds the the ith part of the content of the given struct
BALL::SmartsMatcher::SPBond
SmartsParser::SPBond SPBond
Definition smartsMatcher.h:110
BALL::SmartsMatcher::sssr_
std::vector< std::vector< Atom * > > sssr_
user sssr
Definition smartsMatcher.h:273
BALL::SmartsMatcher::evaluate_edge_
bool evaluate_edge_(RecStruct_ &rs, SPEdge *start_node, const Atom *start_atom, const Bond *start_bond)
method for evaluating a edge of a pseudo-tree
BALL::SmartsMatcher::unsetSSSR
void unsetSSSR()
this function is used to cause the matcher to do an ring perception if needed (do not use the set SSS...
BALL::SmartsMatcher::SPAtom
SmartsParser::SPAtom SPAtom
Definition smartsMatcher.h:109
BALL::SmartsMatcher::setSSSR
void setSSSR(const std::vector< std::vector< Atom * > > &sssr)
sets an SSSR which is used instead of doing an ring perception
BALL::SmartsMatcher::SPNode
SmartsParser::SPNode SPNode
Definition smartsMatcher.h:107
BALL::SmartsMatcher::evaluate_node_
bool evaluate_node_(RecStruct_ &rs, SPNode *start_node, const Atom *start_atom)
method for evaluating a node of a pseudo-tree
BALL::SmartsMatcher::SPEdge
SmartsParser::SPEdge SPEdge
Definition smartsMatcher.h:108
BALL::SmartsMatcher::rec_matches_
std::map< SPNode *, std::vector< std::set< const Atom * > > > rec_matches_
matches from the recurive part
Definition smartsMatcher.h:267
BALL::SmartsMatcher::match
void match(std::vector< Match > &matches, Molecule &mol, const std::vector< String > &smarts, const std::set< const Atom * > &start_atoms)
method to match several Smarts patterns given as a vector of string. The atoms used for start matchin...
BALL::SmartsMatcher::evaluate_
void evaluate_(RecStruct_ &rs, SPNode *start_node, const Atom *start_atom)
method for the evaluation of a pseudo-tree
BALL::SmartsMatcher::~SmartsMatcher
virtual ~SmartsMatcher()
destructor
BALL::SmartsMatcher::has_user_sssr_
bool has_user_sssr_
user SSSR set?
Definition smartsMatcher.h:270
BALL::SmartsMatcher::pool_
static boost::shared_ptr< RecStructPool_ > pool_
the pool of rec struct objects
Definition smartsMatcher.h:252
BALL::SmartsMatcher::Match
std::vector< std::set< const Atom * > > Match
Definition smartsMatcher.h:51
BALL::SmartsMatcher::match
void match(Match &matches, Molecule &mol, const String &smarts, const std::set< const Atom * > &start_atoms)
method to match a Smarts pattern given as a string to given molecule. The atoms which will be used fo...
BALL::SmartsMatcher::evaluateRingEdges_
bool evaluateRingEdges_(const std::set< const Atom * > &matching, const std::map< const SPNode *, const Atom * > &mapping, const String &smarts)
method for evaluation of ring edges, after the the smarts tree is matched to molcule
BALL::SmartsMatcher::depth_
Size depth_
Definition smartsMatcher.h:276
BALL::SmartsMatcher::match
void match(Match &matches, Molecule &mol, const String &smarts)
method to match a Smarts pattern given as a string to given molecule
BALL::SmartsMatcher::match
void match(std::vector< Match > &matches, Molecule &mol, const std::vector< String > &smarts)
method to match several Smarts patterns given as a vector of strings
BALL::SmartsMatcher::SmartsMatcher
SmartsMatcher()
default constructor
BALL::SmartsParser::SPAtom
Smarts Parser Atom class.
Definition smartsParser.h:189
BALL::SmartsParser::SPBond
Bond representation of the smarts parser.
Definition smartsParser.h:106
BALL::SmartsParser::SPEdge
Edge representation of the smarts parser graph.
Definition smartsParser.h:386
BALL::SmartsParser::SPNode
Representation of a node in the smarts parser graph.
Definition smartsParser.h:487
BALL::String
Definition string.h:57
BALL
Definition constants.h:13
BALL::Size
BALL_SIZE_TYPE Size
Definition COMMON/global.h:114
BALL::Position
BALL_SIZE_TYPE Position
Definition COMMON/global.h:140
smartsParser.h