BALL  1.4.1
 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 namespace BALL
17 {
18  // forward declaration
19  class Molecule;
20 
43  {
44  public:
45 
49  typedef std::vector<std::set<const Atom*> > Match;
51 
52 
56 
57  SmartsMatcher();
58 
60  virtual ~SmartsMatcher();
62 
63 
67 
68  void match(Match& matches, Molecule& mol, const String& smarts)
69  throw(Exception::ParseError);
70 
72  void match(Match& matches, Molecule& mol, const String& smarts, const std::set<const Atom*>& start_atoms)
73  throw(Exception::ParseError);
74 
76  void match(std::vector<Match>& matches, Molecule& mol, const std::vector<String>& smarts)
77  throw(Exception::ParseError);
78 
80  void match(std::vector<Match>& matches, Molecule& mol, const std::vector<String>& smarts, const std::set<const Atom*>& start_atoms)
81  throw(Exception::ParseError);
82 
84  void setSSSR(const std::vector<std::vector<Atom*> >& sssr);
85 
87  void unsetSSSR();
89 
90 
91  private:
92 
94  SmartsMatcher(const SmartsMatcher& matcher);
95 
99 
100  SmartsMatcher& operator = (const SmartsMatcher& matcher);
102 
103 
104  protected:
105 
114 
117  {
118  public:
119 
121  RecStructCore_();
122 
125 
127  virtual ~RecStructCore_();
128 
130  RecStructCore_& operator = (const RecStructCore_&);
131 
133  void clear();
134 
136  std::vector<std::set<const Atom*> > matched_atoms;
137 
139  std::vector<std::map<const SPNode*, const Atom*> > mapped_atoms;
140 
142  std::vector<std::set<const Atom*> > visited_atoms;
143 
145  std::vector<std::set<const Bond*> > visited_bonds;
146 
148  std::vector<std::set<const SPEdge*> > visited_edges;
149 
151  std::vector<std::pair<const SPNode*, const Atom*> > first_matches;
152  };
153 
156  {
157  public:
158 
160  RecStructPool_();
161 
163  virtual ~RecStructPool_();
164 
166  RecStructCore_* getNextFree();
167 
169  Position getLastPosition();
170 
172  void destroy(Position pos);
173 
174  private:
175 
177  void resize_();
178 
181 
183  RecStructPool_& operator = (const RecStructPool_&);
184 
186  std::vector<RecStructCore_*> rec_struct_pool_;
187 
189  std::vector<Position> free_list_;
190 
193  };
194 
195 
198  {
199  private:
202 
203  public:
204 
206  RecStruct_();
207 
209  RecStruct_(const RecStruct_& rec_struct);
210 
212  virtual ~RecStruct_();
213 
215  RecStruct_& operator = (const RecStruct_&);
216 
218  std::vector<std::set<const Atom*> >& matched_atoms;
219 
221  std::vector<std::map<const SPNode*, const Atom*> >& mapped_atoms;
222 
224  std::vector<std::set<const Atom*> >& visited_atoms;
225 
227  std::vector<std::set<const Bond*> >& visited_bonds;
228 
230  std::vector<std::set<const SPEdge*> >& visited_edges;
231 
233  std::vector<std::pair<const SPNode*, const Atom*> >& first_matches;
234 
236  void add(const RecStruct_& rec_struct);
237 
239  void add(const RecStruct_& rec_struct, Size i);
240 
242  void clear();
243 
245  void dump(const String& name, Size depth_ = 0);
246 
247  private:
248 
251  };
252 
255 
257  bool evaluateRingEdges_(const std::set<const Atom*>& matching, const std::map<const SPNode*, const Atom*>& mapping, const String& smarts);
258 
260  void evaluate_( RecStruct_& rs, SPNode* start_node, const Atom* start_atom);
261 
263  bool evaluate_node_(RecStruct_& rs, SPNode* start_node, const Atom* start_atom);
264 
266  bool evaluate_edge_(RecStruct_& rs, SPEdge* start_node, const Atom* start_atom, const Bond* start_bond);
267 
269  std::map<SPNode*, std::vector<std::set<const Atom*> > > rec_matches_;
270 
273 
275  std::vector<std::vector<Atom*> > sssr_;
276 
277  // debug output depth
279  };
280 
281 } // namespace BALL
282 
283 #endif // BALL_STRUCTURE_SMARTSMATCHER_H
284