BALL 1.5.0
smartsMatcher.h
Go to the documentation of this file.
1// -*- Mode: C++; tab-width: 2; -*-
2// vi: set ts=2:
3//
4
5#ifndef BALL_STRUCTURE_SMARTSMATCHER_H
6#define BALL_STRUCTURE_SMARTSMATCHER_H
7
8#ifndef BALL_STRUCTURE_SMARTSPARSER_H
10#endif
11
12#include <vector>
13#include <set>
14#include <map>
15
16#include <boost/shared_ptr.hpp>
17
18namespace BALL
19{
20 // forward declaration
21 class Molecule;
22
45 {
46 public:
47
51 typedef std::vector<std::set<const Atom*> > Match;
53
54
60
62 virtual ~SmartsMatcher();
64
65
70 void match(Match& matches, Molecule& mol, const String& smarts);
71
73 void match(Match& matches, Molecule& mol, const String& smarts, const std::set<const Atom*>& start_atoms);
74
76 void match(std::vector<Match>& matches, Molecule& mol, const std::vector<String>& smarts);
77
79 void match(std::vector<Match>& matches, Molecule& mol, const std::vector<String>& smarts, const std::set<const Atom*>& start_atoms);
80
82 void setSSSR(const std::vector<std::vector<Atom*> >& sssr);
83
85 void unsetSSSR();
87
88
89 private:
90
92 SmartsMatcher(const SmartsMatcher& matcher);
93
98 SmartsMatcher& operator = (const SmartsMatcher& matcher);
100
101
102 protected:
103
112
115 {
116 public:
117
120
123
126
128 RecStructCore_& operator = (const RecStructCore_&);
129
131 void clear();
132
134 std::vector<std::set<const Atom*> > matched_atoms;
135
137 std::vector<std::map<const SPNode*, const Atom*> > mapped_atoms;
138
140 std::vector<std::set<const Atom*> > visited_atoms;
141
143 std::vector<std::set<const Bond*> > visited_bonds;
144
146 std::vector<std::set<const SPEdge*> > visited_edges;
147
149 std::vector<std::pair<const SPNode*, const Atom*> > first_matches;
150 };
151
154 {
155 public:
156
159
162
165
168
170 void destroy(Position pos);
171
172 private:
173
175 void resize_();
176
179
181 RecStructPool_& operator = (const RecStructPool_&);
182
184 std::vector<RecStructCore_*> rec_struct_pool_;
185
187 std::vector<Position> free_list_;
188
190 Position last_position_;
191 };
192
193
196 {
197 private:
199 RecStructCore_* rec_struct_core_;
200
201 public:
202
205
207 RecStruct_(const RecStruct_& rec_struct);
208
210 virtual ~RecStruct_();
211
213 RecStruct_& operator = (const RecStruct_&);
214
216 std::vector<std::set<const Atom*> >& matched_atoms;
217
219 std::vector<std::map<const SPNode*, const Atom*> >& mapped_atoms;
220
222 std::vector<std::set<const Atom*> >& visited_atoms;
223
225 std::vector<std::set<const Bond*> >& visited_bonds;
226
228 std::vector<std::set<const SPEdge*> >& visited_edges;
229
231 std::vector<std::pair<const SPNode*, const Atom*> >& first_matches;
232
234 void add(const RecStruct_& rec_struct);
235
237 void add(const RecStruct_& rec_struct, Size i);
238
240 void clear();
241
243 void dump(const String& name, Size depth_ = 0);
244
245 private:
246
248 Position pos_;
249 };
250
252 static boost::shared_ptr<RecStructPool_> pool_;
253
255 bool evaluateRingEdges_(const std::set<const Atom*>& matching, const std::map<const SPNode*, const Atom*>& mapping, const String& smarts);
256
258 void evaluate_( RecStruct_& rs, SPNode* start_node, const Atom* start_atom);
259
261 bool evaluate_node_(RecStruct_& rs, SPNode* start_node, const Atom* start_atom);
262
264 bool evaluate_edge_(RecStruct_& rs, SPEdge* start_node, const Atom* start_atom, const Bond* start_bond);
265
267 std::map<SPNode*, std::vector<std::set<const Atom*> > > rec_matches_;
268
271
273 std::vector<std::vector<Atom*> > sssr_;
274
275 // debug output depth
277 };
278
279} // namespace BALL
280
281#endif // BALL_STRUCTURE_SMARTSMATCHER_H
282
Definition: constants.h:13
SmartsParser::SPBond SPBond
std::vector< std::vector< Atom * > > sssr_
user sssr
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
void unsetSSSR()
this function is used to cause the matcher to do an ring perception if needed (do not use the set SSS...
SmartsParser::SPAtom SPAtom
void setSSSR(const std::vector< std::vector< Atom * > > &sssr)
sets an SSSR which is used instead of doing an ring perception
SmartsParser::SPNode SPNode
bool evaluate_node_(RecStruct_ &rs, SPNode *start_node, const Atom *start_atom)
method for evaluating a node of a pseudo-tree
SmartsParser::SPEdge SPEdge
std::map< SPNode *, std::vector< std::set< const Atom * > > > rec_matches_
matches from the recurive part
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...
void evaluate_(RecStruct_ &rs, SPNode *start_node, const Atom *start_atom)
method for the evaluation of a pseudo-tree
virtual ~SmartsMatcher()
destructor
bool has_user_sssr_
user SSSR set?
static boost::shared_ptr< RecStructPool_ > pool_
the pool of rec struct objects
std::vector< std::set< const Atom * > > Match
Definition: smartsMatcher.h:51
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...
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
void match(Match &matches, Molecule &mol, const String &smarts)
method to match a Smarts pattern given as a string to given molecule
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
SmartsMatcher()
default constructor
core structure of the recursive matching algorithm for the object pool
std::vector< std::set< const Atom * > > visited_atoms
contains vector of visited atoms of different matches
std::vector< std::set< const Bond * > > visited_bonds
contains vector of visited bonds of different matches
std::vector< std::set< const SPEdge * > > visited_edges
contains vector of visited edges of the Smarts tree of different matches
virtual ~RecStructCore_()
destructor
RecStructCore_(const RecStructCore_ &)
copy constructor
std::vector< std::map< const SPNode *, const Atom * > > mapped_atoms
container which contains a vector of mappings from different matches
void clear()
method that deletes all content from the containers
std::vector< std::pair< const SPNode *, const Atom * > > first_matches
contains the first matched atoms of different matches (needed for recursive Smarts)
RecStructCore_()
default constructor
std::vector< std::set< const Atom * > > matched_atoms
container which contains a vector of matched atoms from different matches
class which does the pool operations of the RecStructCore_ pool
void destroy(Position pos)
frees the structure at position pos
RecStructCore_ * getNextFree()
returns the a free RecStructCore_ of the pool (creates new ones if needed)
Position getLastPosition()
returns the position of the last RecStructCore_* from getNextFree()
virtual ~RecStructPool_()
destructor
RecStructPool_()
default constructors
a wrapper class which is used as an interface in the matching code to the pool
void dump(const String &name, Size depth_=0)
dumps the contents (for debugging)
virtual ~RecStruct_()
destructor
std::vector< std::set< const SPEdge * > > & visited_edges
reference to the visited edges in the core structure
RecStruct_(const RecStruct_ &rec_struct)
copy constructor
void clear()
deletes all contents
std::vector< std::map< const SPNode *, const Atom * > > & mapped_atoms
reference to the mapped SPNodes to Atoms in the core structure
std::vector< std::pair< const SPNode *, const Atom * > > & first_matches
reference to the first matches in the core structure
std::vector< std::set< const Atom * > > & visited_atoms
reference to the visited atoms in the core structure
std::vector< std::set< const Bond * > > & visited_bonds
reference to the visited bonds in the core structure
std::vector< std::set< const Atom * > > & matched_atoms
reference to the matched atoms in the core structure
void add(const RecStruct_ &rec_struct)
adds the content of the given struct
RecStruct_()
default constructor
void add(const RecStruct_ &rec_struct, Size i)
adds the the ith part of the content of the given struct
Bond representation of the smarts parser.
Definition: smartsParser.h:106
Smarts Parser Atom class.
Definition: smartsParser.h:189
Edge representation of the smarts parser graph.
Definition: smartsParser.h:386
Representation of a node in the smarts parser graph.
Definition: smartsParser.h:487
#define BALL_EXPORT
Definition: COMMON/global.h:50