BALL  1.4.79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GAFFCESParser.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 
4 #ifndef BALL_MOLMEC_AMBER_GAFFCESPARSER_H
5 #define BALL_MOLMEC_AMBER_GAFFCESPARSER_H
6 
7 #ifndef BALL_KERNEL_ATOM_H
8 #include <BALL/KERNEL/atom.h>
9 #endif
10 
11 #ifndef BALL_DATATYPE_STRING_H
12 #include <BALL/DATATYPE/string.h>
13 #endif
14 
15 #include <set>
16 #include <map>
17 #include <vector>
18 
19 namespace BALL
20 {
21 
23  {
24  public:
25 
26  //atomic property string
27  class APSMatcher
28  {
29  public:
30  //encode Ringatomtypes
31  enum APSType
32  {
69  };
70 
71  class APSTerm
72  {
73  public:
74  APSTerm(APSType new_type, int new_feature_number)
75  : type(new_type),
76  feature_number(new_feature_number)
77  {}
78 
80  //contain the number of occurence of a given feature
82  };
83 
84  //check if current atom is in a ring
85  bool isRingAtom(Atom& atom);
86  //check if the current atom is in a ring with size n
87  //and return the number of occurence
88  int isNRingAtom(Size size, Atom& atom);
89  //check if the current atom is not a ringatom or
90  //in a ten-membered or larger ring
91  bool isNonRingAtom(Atom& atom);
92 
93  bool checkGAFFProperties(Atom& atom, Atom& predecessor, APSTerm aps);
94 
95 
96  APSMatcher();
97  ~APSMatcher();
98 
99  String printAPS();
100 
101  // check if atom matches atomic property string
102  bool operator() (Atom& atom, Atom& predecessor);
103 
104  //store atomic property string
105  //external vector: all AND (",") types
106  //internal vector: all OR (".")types
107  std::vector < std::vector< APSTerm> > aps_terms;
108 
109  protected:
110  bool hasBond_(Atom* atom, Atom* predecessor, int bond_type, int feature_number);
111  };
112 
113  struct State
114  {
115  //not "thread-safe"
117 
120  };
121 
122 
123 
124  //chemical environment string
126  {
127  public:
128  //encode wildcard elements
130  {
131  XA, XB, XC, XD, XX
132  };
133 
135  : parent(0),
136  atom_to_test(0),
137  parser_(parser)
138  {
140  };
141 
142  virtual ~CESPredicate();
143 
144  //initialize stringToWildcard map
145  void initStringToWildcard();
146  std::map<String, CESwildcards> getStringToWildcard();
147 
148  //add a CESwildcardsConnectionPredicate to "predicate tree"
149  void addCESwildcardsConnectionPredicate(String wildcard, Size partners);
150  //add a CESwilddcardsPredicate to "predicate tree"
151  void addCESwildcardsPredicate(String wildcard);
152  //add an CESelementPredicate to "predicate tree"
153  void addCESelementPredicate(String name);
154  //add an CESelementConnectionPredicate to "predicate tree"
155  void addCESelementConnectionPredicate(Size partners, String name);
156  // add a TruePredicate to "predicate tree"
157  void addTruePredicate() const;
158 
159  //check if atom and its environment match predicates
160  virtual bool operator () (Atom& atom);
161  //check if atom matches "predicates in predicate-tree"
162  virtual bool match(Atom&){return false;};
163  //delete children
164  void clear();
165 
166  // check whether this atom is contained on a path to the root
167  bool alreadySeenThisAtom(Atom* atom);
168 
169  //to expand aps_term in aps_matcher object
170  void addNewAND();
171  void addNewOR(APSMatcher::APSType aps, int feature_number);
172 
173  //store existing atomic property string
175 
176  //all CESPredicates for current_predicate ->children of current_predicate
177  std::vector<CESPredicate*> children;
178  //CESPredicate, that has current_predicate in his children vector
180 
181  //The atom we are trying to match to this predicate
183  protected:
184  //map to convert String into wildcard-element
185  std::map<String, CESwildcards > stringToWildcard_;
187  };
188 
189  //element-name of the partnerAtom and number of its connected atoms
191  {
192  public:
194  : CESPredicate(parser),
195  numberOfPartners_(0),
196  elementName_("NoName")
197  {};
198 
200 
201  void setNumberOfPartners(Size number);
202  void setElementName(String name);
205  //check if atom matches predicate
206  bool match(Atom& atom);
207  protected:
210  };
211 
212  //element-name of the partnerAtom
214  {
215  public:
217  : CESPredicate(parser),
218  elementName_("NoName")
219  {
220  };
221 
223 
224  void setElementName(String name);
226  //check if atom matches predicate
227  bool match(Atom& atom);
228  protected:
230  };
231 
232  //XA,XB,XC,XD,XX
234  {
235  public:
237  : CESPredicate(parser)
238  {};
239 
241 
242  void setWildcards(String new_wildcard);
244  //checks if atom matches the given wildcard-element (XA, XB, XC, XD, XX)
245  bool matchWildcards(Atom& atom);
246  //check if atom matches predicate
247  bool match(Atom& atom);
248  protected:
250  };
251 
252  //XA,XB,XC,XD,XX and number of partnerAtoms
254  {
255  public:
257  : CESPredicate(parser),
259  {};
261 
262  void setNumberOfPartners(Size number);
263  void setWildcards(String new_wildcard);
266  //checks if atom matches the given wildcard-element (XA, XB, XC, XD, XX)
267  bool matchWildcards(Atom& atom);
268  //check if atom matches predicate
269  bool match(Atom& atom);
270  protected:
273  };
274 
275  //string is "*" which means always true
277  {
278  public:
280  : CESPredicate(parser)
281  {};
283  //check if atom matches predicate (always true!)
284  bool match(Atom&) { return true; }
285  };
286 
287  //Parser-match-Function checking if atom's environment matches the "predicate tree"
288  bool match(Atom& atom) const;
289 
290  //initialize Set of Elementsymbols
291  void initElementSymbols();
292  const std::set<String>& getElementSymbols();
293 
294  GAFFCESParser();
295  GAFFCESParser(const String& cesstring);
296  ~GAFFCESParser();
297 
298  //for lexer/parser
299  Size read(char* buf, Size max_size);
300 
301  static State state;
302 
305  //fixed root of the "predicate tree"
307  //parent-predicate of current_predicate
309  //"predicate-node" in the "predicate tree" we actually considering
311 
312 
313  //parse chemical environment string
314  bool parse(const String& cesstring);
315  //check if any atom matches parsed ces_string
316  bool GAFFCESatomMatcher(Atom& atom, const String& cesstring);
317  //start filling the children vector for a current predicate
318  void startChildPredicates();
319  //end up filling the children vector for a current predicate
320  void endChildPredicates();
321 
322  protected:
323  //current chemical environment string
325  //set with all valid element symbols
326  std::set<String> element_symbols_;
327  //for Parser/Lexer function YYINPUT
329  };
330 
331 }
332 
333 #endif
std::map< String, CESwildcards > getStringToWildcard()
bool alreadySeenThisAtom(Atom *atom)
Size read(char *buf, Size max_size)
CESPredicate * root_predicate
bool GAFFCESatomMatcher(Atom &atom, const String &cesstring)
void addNewOR(APSMatcher::APSType aps, int feature_number)
bool checkGAFFProperties(Atom &atom, Atom &predecessor, APSTerm aps)
TruePredicate(GAFFCESParser *parser)
void addCESelementConnectionPredicate(Size partners, String name)
void addCESwildcardsPredicate(String wildcard)
CESwildcardsPredicate(GAFFCESParser *parser)
GAFFCESParser * current_parser
CESPredicate * current_root_predicate
CESPredicate * current_predicate
bool match(Atom &atom) const
CESelementPredicate(GAFFCESParser *parser)
bool operator()(Atom &atom, Atom &predecessor)
virtual bool operator()(Atom &atom)
bool hasBond_(Atom *atom, Atom *predecessor, int bond_type, int feature_number)
int isNRingAtom(Size size, Atom &atom)
bool parse(const String &cesstring)
std::map< String, CESwildcards > stringToWildcard_
std::set< String > element_symbols_
TruePredicate root
The root atom has no CESPredicate to test, so it's considered always true.
std::vector< std::vector< APSTerm > > aps_terms
void addCESelementPredicate(String name)
CESPredicate(GAFFCESParser *parser)
void addCESwildcardsConnectionPredicate(String wildcard, Size partners)
APSMatcher::APSType current_aps_type
void setWildcards(String new_wildcard)
static State state
const std::set< String > & getElementSymbols()
APSTerm(APSType new_type, int new_feature_number)
Definition: GAFFCESParser.h:74
std::vector< CESPredicate * > children