BALL  1.4.79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
18 namespace BALL
19 {
20  // forward declaration
21  class Molecule;
22 
45  {
46  public:
47 
51  typedef std::vector<std::set<const Atom*> > Match;
53 
54 
58  SmartsMatcher();
60 
62  virtual ~SmartsMatcher();
64 
65 
69  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 
97  SmartsMatcher& operator = (const SmartsMatcher& matcher);
100 
101 
102  protected:
103 
112 
115  {
116  public:
117 
119  RecStructCore_();
120 
123 
125  virtual ~RecStructCore_();
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 
158  RecStructPool_();
159 
161  virtual ~RecStructPool_();
162 
164  RecStructCore_* getNextFree();
165 
167  Position getLastPosition();
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 
204  RecStruct_();
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 
std::vector< std::set< const Atom * > > Match
Definition: smartsMatcher.h:51
SmartsParser::SPEdge SPEdge
core structure of the recursive matching algorithm for the object pool
std::vector< std::pair< const SPNode *, const Atom * > > & first_matches
reference to the first matches in the core structure
std::vector< std::map< const SPNode *, const Atom * > > & mapped_atoms
reference to the mapped SPNodes to Atoms in the core structure
std::vector< std::vector< Atom * > > sssr_
user sssr
std::vector< std::set< const Atom * > > matched_atoms
container which contains a vector of matched atoms from different matches
std::vector< std::set< const Atom * > > visited_atoms
contains vector of visited atoms of different matches
std::vector< std::set< const SPEdge * > > & visited_edges
reference to the visited edges in the core structure
static boost::shared_ptr< RecStructPool_ > pool_
the pool of rec struct objects
Smarts Parser Atom class.
Definition: smartsParser.h:188
std::vector< std::set< const SPEdge * > > visited_edges
contains vector of visited edges of the Smarts tree of different matches
Representation of a node in the smarts parser graph.
Definition: smartsParser.h:486
std::vector< std::pair< const SPNode *, const Atom * > > first_matches
contains the first matched atoms of different matches (needed for recursive Smarts) ...
std::map< SPNode *, std::vector< std::set< const Atom * > > > rec_matches_
matches from the recurive part
std::vector< std::set< const Bond * > > & visited_bonds
reference to the visited bonds in the core structure
std::vector< std::set< const Bond * > > visited_bonds
contains vector of visited bonds of different matches
bool has_user_sssr_
user SSSR set?
SmartsParser::SPAtom SPAtom
Bond representation of the smarts parser.
Definition: smartsParser.h:105
std::vector< std::map< const SPNode *, const Atom * > > mapped_atoms
container which contains a vector of mappings from different matches
SmartsParser::SPBond SPBond
Edge representation of the smarts parser graph.
Definition: smartsParser.h:385
class which does the pool operations of the RecStructCore_ pool
a wrapper class which is used as an interface in the matching code to the pool
std::vector< std::set< const Atom * > > & matched_atoms
reference to the matched atoms in the core structure
SmartsParser::SPNode SPNode
#define BALL_EXPORT
Definition: COMMON/global.h:50
std::vector< std::set< const Atom * > > & visited_atoms
reference to the visited atoms in the core structure