BALL 1.5.0
Loading...
Searching...
No Matches
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
13#endif
14
15#include <set>
16#include <map>
17#include <vector>
18
19namespace BALL
20{
21
23 {
24 public:
25
26 //atomic property string
28 {
29 public:
30 //encode Ringatomtypes
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
98
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
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
146 std::map<String, CESwildcards> getStringToWildcard();
147
148 //add a CESwildcardsConnectionPredicate to "predicate tree"
150 //add a CESwilddcardsPredicate to "predicate tree"
152 //add an CESelementPredicate to "predicate tree"
154 //add an CESelementConnectionPredicate to "predicate tree"
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
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),
196 elementName_("NoName")
197 {};
198
200
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
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:
261
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
292 const std::set<String>& getElementSymbols();
293
295 GAFFCESParser(const String& cesstring);
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
319 //end up filling the children vector for a current predicate
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
TruePredicate root
The root atom has no CESPredicate to test, so it's considered always true.
bool match(Atom &atom) const
CESPredicate * root_predicate
const std::set< String > & getElementSymbols()
CESPredicate * current_root_predicate
Size read(char *buf, Size max_size)
std::set< String > element_symbols_
bool GAFFCESatomMatcher(Atom &atom, const String &cesstring)
CESPredicate * current_predicate
bool parse(const String &cesstring)
GAFFCESParser(const String &cesstring)
std::vector< std::vector< APSTerm > > aps_terms
bool operator()(Atom &atom, Atom &predecessor)
bool checkGAFFProperties(Atom &atom, Atom &predecessor, APSTerm aps)
int isNRingAtom(Size size, Atom &atom)
bool hasBond_(Atom *atom, Atom *predecessor, int bond_type, int feature_number)
APSTerm(APSType new_type, int new_feature_number)
GAFFCESParser * current_parser
APSMatcher::APSType current_aps_type
CESPredicate(GAFFCESParser *parser)
std::vector< CESPredicate * > children
void addNewOR(APSMatcher::APSType aps, int feature_number)
void addCESelementPredicate(String name)
virtual bool operator()(Atom &atom)
std::map< String, CESwildcards > stringToWildcard_
void addCESwildcardsConnectionPredicate(String wildcard, Size partners)
bool alreadySeenThisAtom(Atom *atom)
void addCESwildcardsPredicate(String wildcard)
std::map< String, CESwildcards > getStringToWildcard()
void addCESelementConnectionPredicate(Size partners, String name)
void setWildcards(String new_wildcard)
TruePredicate(GAFFCESParser *parser)