6 |
|
* redistribute this software in source and binary code form, provided |
7 |
|
* that the following conditions are met: |
8 |
|
* |
9 |
< |
* 1. Acknowledgement of the program authors must be made in any |
10 |
< |
* publication of scientific results based in part on use of the |
11 |
< |
* program. An acceptable form of acknowledgement is citation of |
12 |
< |
* the article in which the program was described (Matthew |
13 |
< |
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
14 |
< |
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
15 |
< |
* Parallel Simulation Engine for Molecular Dynamics," |
16 |
< |
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
17 |
< |
* |
18 |
< |
* 2. Redistributions of source code must retain the above copyright |
9 |
> |
* 1. Redistributions of source code must retain the above copyright |
10 |
|
* notice, this list of conditions and the following disclaimer. |
11 |
|
* |
12 |
< |
* 3. Redistributions in binary form must reproduce the above copyright |
12 |
> |
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
|
* notice, this list of conditions and the following disclaimer in the |
14 |
|
* documentation and/or other materials provided with the |
15 |
|
* distribution. |
28 |
|
* arising out of the use of or inability to use software, even if the |
29 |
|
* University of Notre Dame has been advised of the possibility of |
30 |
|
* such damages. |
31 |
+ |
* |
32 |
+ |
* SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your |
33 |
+ |
* research, please cite the appropriate papers when you publish your |
34 |
+ |
* work. Good starting points are: |
35 |
+ |
* |
36 |
+ |
* [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |
37 |
+ |
* [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |
38 |
+ |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). |
39 |
+ |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 |
+ |
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
41 |
|
*/ |
42 |
|
|
43 |
+ |
#include <stack> |
44 |
|
#include "selection/SelectionEvaluator.hpp" |
45 |
< |
namespace oopse { |
45 |
> |
#include "primitives/Atom.hpp" |
46 |
> |
#include "primitives/DirectionalAtom.hpp" |
47 |
> |
#include "primitives/RigidBody.hpp" |
48 |
> |
#include "primitives/Molecule.hpp" |
49 |
> |
#include "io/ifstrstream.hpp" |
50 |
|
|
51 |
+ |
namespace OpenMD { |
52 |
|
|
53 |
< |
bool SelectionEvaluator::loadScript(const std::string& filename, const std::string& script) { |
53 |
> |
|
54 |
> |
SelectionEvaluator::SelectionEvaluator(SimInfo* si) |
55 |
> |
: info(si), nameFinder(info), distanceFinder(info), hullFinder(info), |
56 |
> |
indexFinder(info), |
57 |
> |
isLoaded_(false){ |
58 |
> |
nStuntDouble = info->getNGlobalAtoms() + info->getNGlobalRigidBodies(); |
59 |
> |
} |
60 |
> |
|
61 |
> |
bool SelectionEvaluator::loadScript(const std::string& filename, |
62 |
> |
const std::string& script) { |
63 |
> |
clearDefinitionsAndLoadPredefined(); |
64 |
|
this->filename = filename; |
65 |
|
this->script = script; |
66 |
|
if (! compiler.compile(filename, script)) { |
67 |
< |
error = true; |
68 |
< |
errorMessage = compiler.getErrorMessage(); |
69 |
< |
return false; |
67 |
> |
error = true; |
68 |
> |
errorMessage = compiler.getErrorMessage(); |
69 |
> |
|
70 |
> |
sprintf( painCave.errMsg, |
71 |
> |
"SelectionCompiler Error: %s\n", errorMessage.c_str()); |
72 |
> |
painCave.severity = OPENMD_ERROR; |
73 |
> |
painCave.isFatal = 1; |
74 |
> |
simError(); |
75 |
> |
return false; |
76 |
|
} |
77 |
|
|
78 |
|
pc = 0; |
79 |
|
aatoken = compiler.getAatokenCompiled(); |
80 |
|
linenumbers = compiler.getLineNumbers(); |
81 |
|
lineIndices = compiler.getLineIndices(); |
82 |
+ |
|
83 |
+ |
std::vector<std::vector<Token> >::const_iterator i; |
84 |
+ |
|
85 |
+ |
isDynamic_ = false; |
86 |
+ |
for (i = aatoken.begin(); i != aatoken.end(); ++i) { |
87 |
+ |
if (containDynamicToken(*i)) { |
88 |
+ |
isDynamic_ = true; |
89 |
+ |
break; |
90 |
+ |
} |
91 |
+ |
} |
92 |
+ |
|
93 |
+ |
isLoaded_ = true; |
94 |
|
return true; |
95 |
< |
} |
95 |
> |
} |
96 |
|
|
97 |
< |
void SelectionEvaluator::clearState() { |
63 |
< |
for (int i = scriptLevelMax; --i >= 0; ) |
64 |
< |
stack[i].clear(); |
65 |
< |
scriptLevel = 0; |
97 |
> |
void SelectionEvaluator::clearState() { |
98 |
|
error = false; |
99 |
|
errorMessage = ""; |
100 |
< |
} |
100 |
> |
} |
101 |
|
|
102 |
< |
bool SelectionEvaluator::loadScriptString(const std::string& script) { |
102 |
> |
bool SelectionEvaluator::loadScriptString(const std::string& script) { |
103 |
|
clearState(); |
104 |
|
return loadScript("", script); |
105 |
< |
} |
105 |
> |
} |
106 |
|
|
107 |
< |
bool SelectionEvaluator::loadScriptFile(const std::string& filename) { |
107 |
> |
bool SelectionEvaluator::loadScriptFile(const std::string& filename) { |
108 |
|
clearState(); |
109 |
|
return loadScriptFileInternal(filename); |
110 |
< |
} |
110 |
> |
} |
111 |
|
|
112 |
< |
bool SelectionEvaluator::loadScriptFileInternal(const string & filename) { |
113 |
< |
|
114 |
< |
} |
115 |
< |
|
116 |
< |
void SelectionEvaluator::instructionDispatchLoop(){ |
117 |
< |
|
112 |
> |
bool SelectionEvaluator::loadScriptFileInternal(const std::string & filename) { |
113 |
> |
ifstrstream ifs(filename.c_str()); |
114 |
> |
if (!ifs.is_open()) { |
115 |
> |
return false; |
116 |
> |
} |
117 |
> |
|
118 |
> |
const int bufferSize = 65535; |
119 |
> |
char buffer[bufferSize]; |
120 |
> |
std::string script; |
121 |
> |
while(ifs.getline(buffer, bufferSize)) { |
122 |
> |
script += buffer; |
123 |
> |
} |
124 |
> |
return loadScript(filename, script); |
125 |
> |
} |
126 |
> |
|
127 |
> |
void SelectionEvaluator::instructionDispatchLoop(OpenMDBitSet& bs){ |
128 |
> |
|
129 |
|
while ( pc < aatoken.size()) { |
130 |
< |
statement = aatoken[pc++]; |
131 |
< |
statementLength = statement.size(); |
132 |
< |
Token token = statement[0]; |
133 |
< |
switch (token.tok) { |
134 |
< |
case Token::define: |
135 |
< |
define(); |
136 |
< |
break; |
137 |
< |
case Token::select: |
138 |
< |
select(); |
139 |
< |
break; |
140 |
< |
default: |
141 |
< |
unrecognizedCommand(token); |
142 |
< |
return; |
143 |
< |
} |
130 |
> |
statement = aatoken[pc++]; |
131 |
> |
statementLength = statement.size(); |
132 |
> |
Token token = statement[0]; |
133 |
> |
switch (token.tok) { |
134 |
> |
case Token::define: |
135 |
> |
define(); |
136 |
> |
break; |
137 |
> |
case Token::select: |
138 |
> |
select(bs); |
139 |
> |
break; |
140 |
> |
default: |
141 |
> |
unrecognizedCommand(token); |
142 |
> |
return; |
143 |
> |
} |
144 |
|
} |
102 |
– |
} |
145 |
|
|
146 |
< |
BitSet SelectionEvaluator::expression(std::vector<Token>& code, int pcStart) { |
105 |
< |
int numberOfAtoms = viewer.getAtomCount(); |
106 |
< |
BitSet bs; |
107 |
< |
BitSet[] stack = new BitSet[10]; |
108 |
< |
int sp = 0; |
146 |
> |
} |
147 |
|
|
148 |
< |
for (int pc = pcStart; ; ++pc) { |
148 |
> |
OpenMDBitSet SelectionEvaluator::expression(const std::vector<Token>& code, |
149 |
> |
int pcStart) { |
150 |
> |
OpenMDBitSet bs; |
151 |
> |
std::stack<OpenMDBitSet> stack; |
152 |
> |
|
153 |
> |
for (unsigned int pc = pcStart; pc < code.size(); ++pc) { |
154 |
|
Token instruction = code[pc]; |
155 |
|
|
156 |
|
switch (instruction.tok) { |
159 |
|
case Token::expressionEnd: |
160 |
|
break; |
161 |
|
case Token::all: |
162 |
< |
bs = stack[sp++] = new BitSet(numberOfAtoms); |
163 |
< |
for (int i = numberOfAtoms; --i >= 0; ) |
121 |
< |
bs.set(i); |
162 |
> |
bs = allInstruction(); |
163 |
> |
stack.push(bs); |
164 |
|
break; |
165 |
|
case Token::none: |
166 |
< |
stack[sp++] = new BitSet(); |
166 |
> |
bs = OpenMDBitSet(nStuntDouble); |
167 |
> |
stack.push(bs); |
168 |
|
break; |
169 |
|
case Token::opOr: |
170 |
< |
bs = stack[--sp]; |
171 |
< |
stack[sp-1].or(bs); |
170 |
> |
bs = stack.top(); |
171 |
> |
stack.pop(); |
172 |
> |
stack.top() |= bs; |
173 |
|
break; |
174 |
|
case Token::opAnd: |
175 |
< |
bs = stack[--sp]; |
176 |
< |
stack[sp-1].and(bs); |
175 |
> |
bs = stack.top(); |
176 |
> |
stack.pop(); |
177 |
> |
stack.top() &= bs; |
178 |
|
break; |
179 |
|
case Token::opNot: |
180 |
< |
bs = stack[sp - 1]; |
136 |
< |
notSet(bs); |
180 |
> |
stack.top().flip(); |
181 |
|
break; |
182 |
|
case Token::within: |
183 |
< |
bs = stack[sp - 1]; |
140 |
< |
stack[sp - 1] = new BitSet(); |
141 |
< |
withinInstruction(instruction, bs, stack[sp - 1]); |
183 |
> |
withinInstruction(instruction, stack.top()); |
184 |
|
break; |
185 |
< |
case Token::selected: |
186 |
< |
stack[sp++] = copyBitSet(viewer.getSelectionSet()); |
185 |
> |
case Token::hull: |
186 |
> |
stack.push(hull()); |
187 |
|
break; |
188 |
+ |
//case Token::selected: |
189 |
+ |
// stack.push(getSelectionSet()); |
190 |
+ |
// break; |
191 |
|
case Token::name: |
192 |
< |
|
192 |
> |
stack.push(nameInstruction(boost::any_cast<std::string>(instruction.value))); |
193 |
|
break; |
194 |
< |
case Token::index: |
195 |
< |
|
194 |
> |
case Token::index: |
195 |
> |
stack.push(indexInstruction(instruction.value)); |
196 |
|
break; |
152 |
– |
case Token::molname: |
153 |
– |
|
154 |
– |
break; |
155 |
– |
case Token::molindex: |
156 |
– |
break; |
197 |
|
case Token::identifier: |
198 |
< |
stack[sp++] = lookupIdentifierValue((std::string)instruction.value); |
198 |
> |
stack.push(lookupValue(boost::any_cast<std::string>(instruction.value))); |
199 |
|
break; |
200 |
|
case Token::opLT: |
201 |
|
case Token::opLE: |
203 |
|
case Token::opGT: |
204 |
|
case Token::opEQ: |
205 |
|
case Token::opNE: |
206 |
< |
bs = stack[sp++] = new BitSet(); |
167 |
< |
comparatorInstruction(instruction, bs); |
206 |
> |
stack.push(comparatorInstruction(instruction)); |
207 |
|
break; |
208 |
|
default: |
209 |
|
unrecognizedExpression(); |
210 |
|
} |
211 |
|
} |
212 |
< |
if (sp != 1) |
212 |
> |
if (stack.size() != 1) |
213 |
|
evalError("atom expression compiler error - stack over/underflow"); |
214 |
< |
return stack[0]; |
214 |
> |
|
215 |
> |
return stack.top(); |
216 |
|
} |
217 |
|
|
218 |
|
|
219 |
|
|
220 |
< |
void SelectionEvaluator::comparatorInstruction(Token instruction, BitSet bs) { |
220 |
> |
OpenMDBitSet SelectionEvaluator::comparatorInstruction(const Token& instruction) { |
221 |
|
int comparator = instruction.tok; |
222 |
|
int property = instruction.intValue; |
223 |
< |
float propertyValue = 0; // just for temperature |
224 |
< |
int comparisonValue = ((Integer)instruction.value).intValue(); |
225 |
< |
int numberOfAtoms = viewer.getAtomCount(); |
226 |
< |
Frame frame = viewer.getFrame(); |
227 |
< |
for (int i = 0; i < numberOfAtoms; ++i) { |
228 |
< |
Atom atom = frame.getAtomAt(i); |
229 |
< |
switch (property) { |
230 |
< |
case Token::mass: |
231 |
< |
//propertyValue = atom.getAtomNumber(); |
232 |
< |
break; |
193 |
< |
case Token::charge: |
223 |
> |
float comparisonValue = boost::any_cast<float>(instruction.value); |
224 |
> |
OpenMDBitSet bs(nStuntDouble); |
225 |
> |
bs.clearAll(); |
226 |
> |
|
227 |
> |
SimInfo::MoleculeIterator mi; |
228 |
> |
Molecule* mol; |
229 |
> |
Molecule::AtomIterator ai; |
230 |
> |
Atom* atom; |
231 |
> |
Molecule::RigidBodyIterator rbIter; |
232 |
> |
RigidBody* rb; |
233 |
|
|
234 |
< |
break; |
235 |
< |
case Token::dipole: |
234 |
> |
for (mol = info->beginMolecule(mi); mol != NULL; |
235 |
> |
mol = info->nextMolecule(mi)) { |
236 |
|
|
237 |
< |
break; |
238 |
< |
default: |
200 |
< |
unrecognizedAtomProperty(property); |
237 |
> |
for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
238 |
> |
compareProperty(atom, bs, property, comparator, comparisonValue); |
239 |
|
} |
240 |
< |
bool match = false; |
241 |
< |
switch (comparator) { |
242 |
< |
case Token::opLT: |
243 |
< |
match = propertyValue < comparisonValue; |
206 |
< |
break; |
207 |
< |
case Token::opLE: |
208 |
< |
match = propertyValue <= comparisonValue; |
209 |
< |
break; |
210 |
< |
case Token::opGE: |
211 |
< |
match = propertyValue >= comparisonValue; |
212 |
< |
break; |
213 |
< |
case Token::opGT: |
214 |
< |
match = propertyValue > comparisonValue; |
215 |
< |
break; |
216 |
< |
case Token::opEQ: |
217 |
< |
match = propertyValue == comparisonValue; |
218 |
< |
break; |
219 |
< |
case Token::opNE: |
220 |
< |
match = propertyValue != comparisonValue; |
221 |
< |
break; |
240 |
> |
|
241 |
> |
for (rb = mol->beginRigidBody(rbIter); rb != NULL; |
242 |
> |
rb = mol->nextRigidBody(rbIter)) { |
243 |
> |
compareProperty(rb, bs, property, comparator, comparisonValue); |
244 |
|
} |
223 |
– |
if (match) |
224 |
– |
bs.set(i); |
245 |
|
} |
246 |
+ |
|
247 |
+ |
return bs; |
248 |
|
} |
249 |
|
|
250 |
< |
void SelectionEvaluator::withinInstruction(const Token& instruction, BitSet& bs, BitSet& bsResult) |
251 |
< |
|
252 |
< |
boost::any withinSpec = instruction.value; |
253 |
< |
if (withinSpec.type() == typeid(float)){ |
254 |
< |
withinDistance(boost::any_cast<float>(withinSpec), bs, bsResult); |
255 |
< |
return; |
256 |
< |
} |
257 |
< |
|
258 |
< |
evalError("Unrecognized within parameter:" + withinSpec); |
259 |
< |
} |
260 |
< |
|
261 |
< |
void SelectionEvaluator::withinDistance(float distance, const BitSet& bs, const BitSet& bsResult) { |
262 |
< |
Frame frame = viewer.getFrame(); |
263 |
< |
for (int i = frame.getAtomCount(); --i >= 0; ) { |
264 |
< |
if (bs.get(i)) { |
265 |
< |
Atom atom = frame.getAtomAt(i); |
266 |
< |
AtomIterator iterWithin = |
267 |
< |
frame.getWithinIterator(atom, distance); |
268 |
< |
while (iterWithin.hasNext()) |
247 |
< |
bsResult.set(iterWithin.next().getAtomIndex()); |
250 |
> |
void SelectionEvaluator::compareProperty(StuntDouble* sd, OpenMDBitSet& bs, |
251 |
> |
int property, int comparator, |
252 |
> |
float comparisonValue) { |
253 |
> |
RealType propertyValue = 0.0; |
254 |
> |
switch (property) { |
255 |
> |
case Token::mass: |
256 |
> |
propertyValue = sd->getMass(); |
257 |
> |
break; |
258 |
> |
case Token::charge: |
259 |
> |
if (sd->isAtom()){ |
260 |
> |
Atom* atom = static_cast<Atom*>(sd); |
261 |
> |
propertyValue = getCharge(atom); |
262 |
> |
} else if (sd->isRigidBody()) { |
263 |
> |
RigidBody* rb = static_cast<RigidBody*>(sd); |
264 |
> |
RigidBody::AtomIterator ai; |
265 |
> |
Atom* atom; |
266 |
> |
for (atom = rb->beginAtom(ai); atom != NULL; atom = rb->nextAtom(ai)) { |
267 |
> |
propertyValue+= getCharge(atom); |
268 |
> |
} |
269 |
|
} |
270 |
+ |
break; |
271 |
+ |
case Token::x: |
272 |
+ |
propertyValue = sd->getPos().x(); |
273 |
+ |
break; |
274 |
+ |
case Token::y: |
275 |
+ |
propertyValue = sd->getPos().y(); |
276 |
+ |
break; |
277 |
+ |
case Token::z: |
278 |
+ |
propertyValue = sd->getPos().z(); |
279 |
+ |
break; |
280 |
+ |
case Token::r: |
281 |
+ |
propertyValue = sd->getPos().length(); |
282 |
+ |
break; |
283 |
+ |
default: |
284 |
+ |
unrecognizedAtomProperty(property); |
285 |
|
} |
286 |
+ |
|
287 |
+ |
bool match = false; |
288 |
+ |
switch (comparator) { |
289 |
+ |
case Token::opLT: |
290 |
+ |
match = propertyValue < comparisonValue; |
291 |
+ |
break; |
292 |
+ |
case Token::opLE: |
293 |
+ |
match = propertyValue <= comparisonValue; |
294 |
+ |
break; |
295 |
+ |
case Token::opGE: |
296 |
+ |
match = propertyValue >= comparisonValue; |
297 |
+ |
break; |
298 |
+ |
case Token::opGT: |
299 |
+ |
match = propertyValue > comparisonValue; |
300 |
+ |
break; |
301 |
+ |
case Token::opEQ: |
302 |
+ |
match = propertyValue == comparisonValue; |
303 |
+ |
break; |
304 |
+ |
case Token::opNE: |
305 |
+ |
match = propertyValue != comparisonValue; |
306 |
+ |
break; |
307 |
+ |
} |
308 |
+ |
if (match) |
309 |
+ |
bs.setBitOn(sd->getGlobalIndex()); |
310 |
+ |
|
311 |
|
} |
312 |
|
|
313 |
+ |
void SelectionEvaluator::withinInstruction(const Token& instruction, |
314 |
+ |
OpenMDBitSet& bs){ |
315 |
+ |
|
316 |
+ |
boost::any withinSpec = instruction.value; |
317 |
+ |
float distance; |
318 |
+ |
if (withinSpec.type() == typeid(float)){ |
319 |
+ |
distance = boost::any_cast<float>(withinSpec); |
320 |
+ |
} else if (withinSpec.type() == typeid(int)) { |
321 |
+ |
distance = boost::any_cast<int>(withinSpec); |
322 |
+ |
} else { |
323 |
+ |
evalError("casting error in withinInstruction"); |
324 |
+ |
bs.clearAll(); |
325 |
+ |
} |
326 |
+ |
|
327 |
+ |
bs = distanceFinder.find(bs, distance); |
328 |
+ |
} |
329 |
+ |
|
330 |
|
void SelectionEvaluator::define() { |
331 |
|
assert(statement.size() >= 3); |
332 |
< |
|
332 |
> |
|
333 |
|
std::string variable = boost::any_cast<std::string>(statement[1].value); |
334 |
|
|
335 |
< |
variables.insert(std::make_pair(variable, expression(statement, 2))); |
335 |
> |
variables.insert(VariablesType::value_type(variable, |
336 |
> |
expression(statement, 2))); |
337 |
|
} |
338 |
< |
} |
338 |
> |
|
339 |
|
|
340 |
< |
/** @todo */ |
341 |
< |
void SelectionEvaluator::predefine(const std::string& script) { |
342 |
< |
|
340 |
> |
/** @todo */ |
341 |
> |
void SelectionEvaluator::predefine(const std::string& script) { |
342 |
> |
|
343 |
|
if (compiler.compile("#predefine", script)) { |
344 |
< |
std::vector<std::vector<Token> > aatoken = compiler.getAatokenCompiled(); |
345 |
< |
if (aatoken.size() != 1) { |
346 |
< |
evalError("predefinition does not have exactly 1 command:" |
347 |
< |
+ script); |
348 |
< |
return; |
349 |
< |
} |
350 |
< |
std::vector<Token> statement = aatoken[0]; |
351 |
< |
if (statement.size() > 2) { |
352 |
< |
int tok = statement[1].tok; |
353 |
< |
if (tok == Token::identifier || (tok & Token::predefinedset) == Token::predefinedset) { |
354 |
< |
std::string variable = (std::string)statement[1].value; |
355 |
< |
variables.insert(std::make_pair(variable, statement)); |
356 |
< |
|
357 |
< |
} else { |
358 |
< |
evalError("invalid variable name:" + script); |
359 |
< |
} |
360 |
< |
}else { |
361 |
< |
evalError("bad predefinition length:" + script); |
362 |
< |
} |
363 |
< |
|
344 |
> |
std::vector<std::vector<Token> > aatoken = compiler.getAatokenCompiled(); |
345 |
> |
if (aatoken.size() != 1) { |
346 |
> |
evalError("predefinition does not have exactly 1 command:" |
347 |
> |
+ script); |
348 |
> |
return; |
349 |
> |
} |
350 |
> |
std::vector<Token> statement = aatoken[0]; |
351 |
> |
if (statement.size() > 2) { |
352 |
> |
int tok = statement[1].tok; |
353 |
> |
if (tok == Token::identifier || |
354 |
> |
(tok & Token::predefinedset) == Token::predefinedset) { |
355 |
> |
std::string variable = boost::any_cast<std::string>(statement[1].value); |
356 |
> |
variables.insert(VariablesType::value_type(variable, statement)); |
357 |
> |
|
358 |
> |
} else { |
359 |
> |
evalError("invalid variable name:" + script); |
360 |
> |
} |
361 |
> |
}else { |
362 |
> |
evalError("bad predefinition length:" + script); |
363 |
> |
} |
364 |
|
|
365 |
|
} else { |
366 |
< |
evalError("predefined set compile error:" + script + |
367 |
< |
"\ncompile error:" + compiler.getErrorMessage()); |
366 |
> |
evalError("predefined set compile error:" + script + |
367 |
> |
"\ncompile error:" + compiler.getErrorMessage()); |
368 |
|
} |
369 |
+ |
} |
370 |
|
|
371 |
< |
} |
371 |
> |
void SelectionEvaluator::select(OpenMDBitSet& bs){ |
372 |
> |
bs = expression(statement, 1); |
373 |
> |
} |
374 |
> |
|
375 |
> |
OpenMDBitSet SelectionEvaluator::lookupValue(const std::string& variable){ |
376 |
> |
|
377 |
> |
OpenMDBitSet bs(nStuntDouble); |
378 |
> |
std::map<std::string, boost::any>::iterator i = variables.find(variable); |
379 |
> |
|
380 |
> |
if (i != variables.end()) { |
381 |
> |
if (i->second.type() == typeid(OpenMDBitSet)) { |
382 |
> |
return boost::any_cast<OpenMDBitSet>(i->second); |
383 |
> |
} else if (i->second.type() == typeid(std::vector<Token>)){ |
384 |
> |
bs = expression(boost::any_cast<std::vector<Token> >(i->second), 2); |
385 |
> |
i->second = bs; /**@todo fixme */ |
386 |
> |
return bs; |
387 |
> |
} |
388 |
> |
} else { |
389 |
> |
unrecognizedIdentifier(variable); |
390 |
> |
} |
391 |
> |
|
392 |
> |
return bs; |
393 |
> |
} |
394 |
> |
|
395 |
> |
OpenMDBitSet SelectionEvaluator::nameInstruction(const std::string& name){ |
396 |
> |
return nameFinder.match(name); |
397 |
> |
} |
398 |
|
|
399 |
< |
void SelectionEvaluator::select(){ |
400 |
< |
viewer.setSelectionSet(expression(statement, 1)); |
401 |
< |
} |
399 |
> |
bool SelectionEvaluator::containDynamicToken(const std::vector<Token>& tokens){ |
400 |
> |
std::vector<Token>::const_iterator i; |
401 |
> |
for (i = tokens.begin(); i != tokens.end(); ++i) { |
402 |
> |
if (i->tok & Token::dynamic) { |
403 |
> |
return true; |
404 |
> |
} |
405 |
> |
} |
406 |
> |
|
407 |
> |
return false; |
408 |
> |
} |
409 |
|
|
410 |
< |
BitSet SelectionEvaluator::lookupValue(const std::string& variable){ |
410 |
> |
void SelectionEvaluator::clearDefinitionsAndLoadPredefined() { |
411 |
> |
variables.clear(); |
412 |
> |
//load predefine |
413 |
> |
//predefine(); |
414 |
> |
} |
415 |
|
|
416 |
< |
std::map<std::string, boost::any>::iterator i = variables.find(variable); |
416 |
> |
OpenMDBitSet SelectionEvaluator::evaluate() { |
417 |
> |
OpenMDBitSet bs(nStuntDouble); |
418 |
> |
if (isLoaded_) { |
419 |
> |
pc = 0; |
420 |
> |
instructionDispatchLoop(bs); |
421 |
> |
} |
422 |
|
|
423 |
< |
if (i != variables.end()) { |
424 |
< |
if (i->second.type() == typeid(BitSet)) { |
425 |
< |
return boost::any_cast<BitSet>(i->second); |
426 |
< |
} else if (i->second.type() == typeid(std::vector<Token>)){ |
427 |
< |
BitSet bs = expression(boost::any_cast(i->second), 2); |
428 |
< |
i->second = bs; /**@todo fixme */ |
429 |
< |
return bs; |
430 |
< |
} |
423 |
> |
return bs; |
424 |
> |
} |
425 |
> |
|
426 |
> |
OpenMDBitSet SelectionEvaluator::indexInstruction(const boost::any& value) { |
427 |
> |
OpenMDBitSet bs(nStuntDouble); |
428 |
> |
|
429 |
> |
if (value.type() == typeid(int)) { |
430 |
> |
int index = boost::any_cast<int>(value); |
431 |
> |
if (index < 0 || index >= bs.size()) { |
432 |
> |
invalidIndex(index); |
433 |
> |
} else { |
434 |
> |
bs = indexFinder.find(index); |
435 |
> |
} |
436 |
> |
} else if (value.type() == typeid(std::pair<int, int>)) { |
437 |
> |
std::pair<int, int> indexRange= boost::any_cast<std::pair<int, int> >(value); |
438 |
> |
assert(indexRange.first <= indexRange.second); |
439 |
> |
if (indexRange.first < 0 || indexRange.second >= bs.size()) { |
440 |
> |
invalidIndexRange(indexRange); |
441 |
> |
}else { |
442 |
> |
bs = indexFinder.find(indexRange.first, indexRange.second); |
443 |
> |
} |
444 |
|
} |
445 |
|
|
446 |
< |
} |
446 |
> |
return bs; |
447 |
> |
} |
448 |
|
|
449 |
+ |
OpenMDBitSet SelectionEvaluator::allInstruction() { |
450 |
+ |
OpenMDBitSet bs(nStuntDouble); |
451 |
+ |
|
452 |
+ |
SimInfo::MoleculeIterator mi; |
453 |
+ |
Molecule* mol; |
454 |
+ |
Molecule::AtomIterator ai; |
455 |
+ |
Atom* atom; |
456 |
+ |
Molecule::RigidBodyIterator rbIter; |
457 |
+ |
RigidBody* rb; |
458 |
+ |
|
459 |
+ |
// Doing the loop insures that we're actually on this processor. |
460 |
+ |
|
461 |
+ |
for (mol = info->beginMolecule(mi); mol != NULL; |
462 |
+ |
mol = info->nextMolecule(mi)) { |
463 |
+ |
|
464 |
+ |
for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
465 |
+ |
bs.setBitOn(atom->getGlobalIndex()); |
466 |
+ |
} |
467 |
+ |
|
468 |
+ |
for (rb = mol->beginRigidBody(rbIter); rb != NULL; |
469 |
+ |
rb = mol->nextRigidBody(rbIter)) { |
470 |
+ |
bs.setBitOn(rb->getGlobalIndex()); |
471 |
+ |
} |
472 |
+ |
} |
473 |
+ |
|
474 |
+ |
return bs; |
475 |
+ |
} |
476 |
+ |
|
477 |
+ |
OpenMDBitSet SelectionEvaluator::hull() { |
478 |
+ |
OpenMDBitSet bs(nStuntDouble); |
479 |
+ |
|
480 |
+ |
bs = hullFinder.findHull(); |
481 |
+ |
|
482 |
+ |
return bs; |
483 |
+ |
} |
484 |
+ |
|
485 |
+ |
RealType SelectionEvaluator::getCharge(Atom* atom) { |
486 |
+ |
RealType charge =0.0; |
487 |
+ |
AtomType* atomType = atom->getAtomType(); |
488 |
+ |
if (atomType->isCharge()) { |
489 |
+ |
GenericData* data = atomType->getPropertyByName("Charge"); |
490 |
+ |
if (data != NULL) { |
491 |
+ |
DoubleGenericData* doubleData= dynamic_cast<DoubleGenericData*>(data); |
492 |
+ |
|
493 |
+ |
if (doubleData != NULL) { |
494 |
+ |
charge = doubleData->getData(); |
495 |
+ |
|
496 |
+ |
} else { |
497 |
+ |
sprintf( painCave.errMsg, |
498 |
+ |
"Can not cast GenericData to DoubleGenericData\n"); |
499 |
+ |
painCave.severity = OPENMD_ERROR; |
500 |
+ |
painCave.isFatal = 1; |
501 |
+ |
simError(); |
502 |
+ |
} |
503 |
+ |
} |
504 |
+ |
} |
505 |
+ |
|
506 |
+ |
return charge; |
507 |
+ |
} |
508 |
+ |
|
509 |
|
} |