BALL
1.4.1
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
include
BALL
MOLMEC
AMBER
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
22
class
GAFFCESParser
23
{
24
public
:
25
26
//atomic property string
27
class
APSMatcher
28
{
29
public
:
30
//encode Ringatomtypes
31
enum
APSType
32
{
33
IS_RING_ATOM
,
34
IS_NON_RING_ATOM
,
35
IS_PLANAR
,
36
IS_PLANAR_WITH_DB_TO_NR
,
37
IS_PURELY_AROMATIC
,
38
IS_PURELY_ALIPHATIC
,
39
IS_OTHER_RING
,
40
IS_3_RING_ATOM
,
41
IS_4_RING_ATOM
,
42
IS_5_RING_ATOM
,
43
IS_6_RING_ATOM
,
44
IS_7_RING_ATOM
,
45
IS_8_RING_ATOM
,
46
IS_9_RING_ATOM
,
47
PURE_SINGLE_BOND
,
48
PURE_SINGLE_BOND_TO_PARENT
,
49
NO_PURE_SINGLE_BOND_TO_PARENT
,
50
SINGLE_BOND
,
51
SINGLE_BOND_TO_PARENT
,
52
NO_SINGLE_BOND_TO_PARENT
,
53
PURE_DOUBLE_BOND
,
54
PURE_DOUBLE_BOND_TO_PARENT
,
55
NO_PURE_DOUBLE_BOND_TO_PARENT
,
56
DOUBLE_BOND
,
57
DOUBLE_BOND_TO_PARENT
,
58
NO_DOUBLE_BOND_TO_PARENT
,
59
TRIPLE_BOND
,
60
TRIPLE_BOND_TO_PARENT
,
61
NO_TRIPLE_BOND_TO_PARENT
,
62
DELOCALIZED_BOND
,
63
DELOCALIZED_BOND_TO_PARENT
,
64
NO_DELOCALIZED_BOND_TO_PARENT
,
65
AROMATIC_BOND
,
66
AROMATIC_BOND_TO_PARENT
,
67
NO_AROMATIC_BOND_TO_PARENT
,
68
APS_TRUE
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
79
APSType
type
;
80
//contain the number of occurence of a given feature
81
int
feature_number
;
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"
116
GAFFCESParser
*
current_parser
;
117
118
APSMatcher::APSType
current_aps_type
;
119
int
feature_number
;
120
};
121
122
123
124
//chemical environment string
125
class
CESPredicate
126
{
127
public
:
128
//encode wildcard elements
129
enum
CESwildcards
130
{
131
XA
,
XB
,
XC
,
XD
,
XX
132
};
133
134
CESPredicate
(
GAFFCESParser
* parser)
135
:
parent
(0),
136
parser_
(parser)
137
{
138
initStringToWildcard
();
139
};
140
141
virtual
~CESPredicate
();
142
143
//initialize stringToWildcard map
144
void
initStringToWildcard
();
145
std::map<String, CESwildcards>
getStringToWildcard
();
146
147
//add a CESwildcardsConnectionPredicate to "predicate tree"
148
void
addCESwildcardsConnectionPredicate
(
String
wildcard,
Size
partners);
149
//add a CESwilddcardsPredicate to "predicate tree"
150
void
addCESwildcardsPredicate
(
String
wildcard);
151
//add an CESelementPredicate to "predicate tree"
152
void
addCESelementPredicate
(
String
name);
153
//add an CESelementConnectionPredicate to "predicate tree"
154
void
addCESelementConnectionPredicate
(
Size
partners,
String
name);
155
// add a TruePredicate to "predicate tree"
156
void
addTruePredicate
()
const
;
157
158
//check if atom and its environment match predicates
159
virtual
bool
operator ()
(
Atom
& atom);
160
//check if atom matches "predicates in predicate-tree"
161
virtual
bool
match
(
Atom
&){
return
false
;};
162
//delete children
163
void
clear
();
164
165
// check whether this atom is contained on a path to the root
166
bool
alreadySeenThisAtom
(
Atom
* atom);
167
168
//to expand aps_term in aps_matcher object
169
void
addNewAND
();
170
void
addNewOR
(
APSMatcher::APSType
aps,
int
feature_number);
171
172
//store existing atomic property string
173
APSMatcher
aps_matcher
;
174
175
//all CESPredicates for current_predicate ->children of current_predicate
176
std::vector<CESPredicate*>
children
;
177
//CESPredicate, that has current_predicate in his children vector
178
CESPredicate
*
parent
;
179
180
//The atom we are trying to match to this predicate
181
Atom
*
atom_to_test
;
182
protected
:
183
//map to convert String into wildcard-element
184
std::map<String, CESwildcards >
stringToWildcard_
;
185
GAFFCESParser
*
parser_
;
186
};
187
188
//element-name of the partnerAtom and number of its connected atoms
189
class
CESelementConnectionPredicate
:
public
CESPredicate
190
{
191
public
:
192
CESelementConnectionPredicate
(
GAFFCESParser
* parser)
193
:
CESPredicate
(parser),
194
numberOfPartners_
(0),
195
elementName_
(
"NoName"
)
196
{};
197
198
~CESelementConnectionPredicate
();
199
200
void
setNumberOfPartners
(
Size
number);
201
void
setElementName
(
String
name);
202
Size
getNumberOfPartners
();
203
String
getElementName
();
204
//check if atom matches predicate
205
bool
match
(
Atom
& atom);
206
protected
:
207
Size
numberOfPartners_
;
208
String
elementName_
;
209
};
210
211
//element-name of the partnerAtom
212
class
CESelementPredicate
:
public
CESPredicate
213
{
214
public
:
215
CESelementPredicate
(
GAFFCESParser
* parser)
216
:
CESPredicate
(parser),
217
elementName_
(
"NoName"
)
218
{
219
};
220
221
~CESelementPredicate
();
222
223
void
setElementName
(
String
name);
224
String
getElementName
();
225
//check if atom matches predicate
226
bool
match
(
Atom
& atom);
227
protected
:
228
String
elementName_
;
229
};
230
231
//XA,XB,XC,XD,XX
232
class
CESwildcardsPredicate
:
public
CESPredicate
233
{
234
public
:
235
CESwildcardsPredicate
(
GAFFCESParser
* parser)
236
:
CESPredicate
(parser)
237
{};
238
239
~CESwildcardsPredicate
();
240
241
void
setWildcards
(
String
new_wildcard);
242
CESwildcards
getWildcards
();
243
//checks if atom matches the given wildcard-element (XA, XB, XC, XD, XX)
244
bool
matchWildcards
(
Atom
& atom);
245
//check if atom matches predicate
246
bool
match
(
Atom
& atom);
247
protected
:
248
CESwildcards
wildcards_
;
249
};
250
251
//XA,XB,XC,XD,XX and number of partnerAtoms
252
class
CESwildcardsConnectionPredicate
:
public
CESPredicate
253
{
254
public
:
255
CESwildcardsConnectionPredicate
(
GAFFCESParser
* parser)
256
:
CESPredicate
(parser),
257
numberOfPartners_
(0)
258
{};
259
~CESwildcardsConnectionPredicate
();
260
261
void
setNumberOfPartners
(
Size
number);
262
void
setWildcards
(
String
new_wildcard);
263
Size
getNumberOfPartners
();
264
CESwildcards
getWildcards
();
265
//checks if atom matches the given wildcard-element (XA, XB, XC, XD, XX)
266
bool
matchWildcards
(
Atom
& atom);
267
//check if atom matches predicate
268
bool
match
(
Atom
& atom);
269
protected
:
270
CESwildcards
wildcards_
;
271
Size
numberOfPartners_
;
272
};
273
274
//string is "*" which means always true
275
class
TruePredicate
:
public
CESPredicate
276
{
277
public
:
278
TruePredicate
(
GAFFCESParser
* parser)
279
:
CESPredicate
(parser)
280
{};
281
~TruePredicate
() {};
282
//check if atom matches predicate (always true!)
283
bool
match
(
Atom
&) {
return
true
; }
284
};
285
286
//Parser-match-Function checking if atom's environment matches the "predicate tree"
287
bool
match
(
Atom
& atom)
const
;
288
289
//initialize Set of Elementsymbols
290
void
initElementSymbols
();
291
const
std::set<String>&
getElementSymbols
();
292
293
GAFFCESParser
();
294
GAFFCESParser
(
const
String
& cesstring);
295
~GAFFCESParser
();
296
297
//for lexer/parser
298
Size
read
(
char
* buf,
Size
max_size);
299
300
static
State
state
;
301
303
TruePredicate
root
;
304
//fixed root of the "predicate tree"
305
CESPredicate
*
root_predicate
;
306
//parent-predicate of current_predicate
307
CESPredicate
*
current_root_predicate
;
308
//"predicate-node" in the "predicate tree" we actually considering
309
CESPredicate
*
current_predicate
;
310
311
312
//parse chemical environment string
313
bool
parse
(
const
String
& cesstring);
314
//check if any atom matches parsed ces_string
315
bool
GAFFCESatomMatcher
(
Atom
& atom,
const
String
& cesstring);
316
//start filling the children vector for a current predicate
317
void
startChildPredicates
();
318
//end up filling the children vector for a current predicate
319
void
endChildPredicates
();
320
321
protected
:
322
//current chemical environment string
323
String
cesstring_
;
324
//set with all valid element symbols
325
std::set<String>
element_symbols_
;
326
//for Parser/Lexer function YYINPUT
327
Position
read_start_
;
328
};
329
330
}
331
332
#endif
Generated by
1.8.1.2