ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/selection/SelectionEvaluator.cpp
Revision: 1953
Committed: Thu Dec 5 18:19:26 2013 UTC (11 years, 4 months ago) by gezelter
File size: 24297 byte(s)
Log Message:
Rewrote much of selection module, added a bond correlation function

File Contents

# User Rev Content
1 tim 277 /*
2     * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3     *
4     * The University of Notre Dame grants you ("Licensee") a
5     * non-exclusive, royalty free, license to use, modify and
6     * redistribute this software in source and binary code form, provided
7     * that the following conditions are met:
8     *
9 gezelter 1390 * 1. Redistributions of source code must retain the above copyright
10 tim 277 * notice, this list of conditions and the following disclaimer.
11     *
12 gezelter 1390 * 2. Redistributions in binary form must reproduce the above copyright
13 tim 277 * notice, this list of conditions and the following disclaimer in the
14     * documentation and/or other materials provided with the
15     * distribution.
16     *
17     * This software is provided "AS IS," without a warranty of any
18     * kind. All express or implied conditions, representations and
19     * warranties, including any implied warranty of merchantability,
20     * fitness for a particular purpose or non-infringement, are hereby
21     * excluded. The University of Notre Dame and its licensors shall not
22     * be liable for any damages suffered by licensee as a result of
23     * using, modifying or distributing the software or its
24     * derivatives. In no event will the University of Notre Dame or its
25     * licensors be liable for any lost revenue, profit or data, or for
26     * direct, indirect, special, consequential, incidental or punitive
27     * damages, however caused and regardless of the theory of liability,
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 gezelter 1390 *
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 gezelter 1879 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
39 gezelter 1782 * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
40     * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41 tim 277 */
42    
43 tim 283 #include <stack>
44 tim 277 #include "selection/SelectionEvaluator.hpp"
45 tim 283 #include "primitives/Atom.hpp"
46     #include "primitives/DirectionalAtom.hpp"
47     #include "primitives/RigidBody.hpp"
48     #include "primitives/Molecule.hpp"
49 gezelter 1782 #include "io/ifstrstream.hpp"
50 gezelter 1816 #include "types/FixedChargeAdapter.hpp"
51     #include "types/FluctuatingChargeAdapter.hpp"
52 tim 283
53 gezelter 1816
54 gezelter 1390 namespace OpenMD {
55 tim 277
56    
57 gezelter 507 SelectionEvaluator::SelectionEvaluator(SimInfo* si)
58 gezelter 1412 : info(si), nameFinder(info), distanceFinder(info), hullFinder(info),
59 gezelter 1903 indexFinder(info), hasSurfaceArea_(false),
60 cli2 1364 isLoaded_(false){
61 gezelter 1953 nObjects.push_back(info->getNGlobalAtoms() + info->getNGlobalRigidBodies());
62     nObjects.push_back(info->getNGlobalBonds());
63     nObjects.push_back(info->getNGlobalBends());
64     nObjects.push_back(info->getNGlobalTorsions());
65     nObjects.push_back(info->getNGlobalInversions());
66     }
67    
68 cli2 1364 bool SelectionEvaluator::loadScript(const std::string& filename,
69     const std::string& script) {
70 tim 288 clearDefinitionsAndLoadPredefined();
71 tim 278 this->filename = filename;
72     this->script = script;
73     if (! compiler.compile(filename, script)) {
74 gezelter 507 error = true;
75     errorMessage = compiler.getErrorMessage();
76 cli2 1364
77     sprintf( painCave.errMsg,
78     "SelectionCompiler Error: %s\n", errorMessage.c_str());
79 gezelter 1390 painCave.severity = OPENMD_ERROR;
80 cli2 1364 painCave.isFatal = 1;
81     simError();
82 gezelter 507 return false;
83 tim 278 }
84    
85     pc = 0;
86     aatoken = compiler.getAatokenCompiled();
87     linenumbers = compiler.getLineNumbers();
88     lineIndices = compiler.getLineIndices();
89 tim 288
90     std::vector<std::vector<Token> >::const_iterator i;
91    
92     isDynamic_ = false;
93     for (i = aatoken.begin(); i != aatoken.end(); ++i) {
94 gezelter 507 if (containDynamicToken(*i)) {
95     isDynamic_ = true;
96     break;
97     }
98 tim 288 }
99    
100     isLoaded_ = true;
101 tim 278 return true;
102 gezelter 507 }
103 tim 278
104 gezelter 507 void SelectionEvaluator::clearState() {
105 tim 278 error = false;
106 tim 281 errorMessage = "";
107 gezelter 507 }
108 tim 278
109 gezelter 507 bool SelectionEvaluator::loadScriptString(const std::string& script) {
110 tim 278 clearState();
111 tim 281 return loadScript("", script);
112 gezelter 507 }
113 tim 278
114 gezelter 507 bool SelectionEvaluator::loadScriptFile(const std::string& filename) {
115 tim 278 clearState();
116     return loadScriptFileInternal(filename);
117 gezelter 507 }
118 tim 278
119 cli2 1364 bool SelectionEvaluator::loadScriptFileInternal(const std::string & filename) {
120     ifstrstream ifs(filename.c_str());
121 tim 288 if (!ifs.is_open()) {
122 gezelter 507 return false;
123 tim 288 }
124 cli2 1364
125 tim 288 const int bufferSize = 65535;
126     char buffer[bufferSize];
127     std::string script;
128     while(ifs.getline(buffer, bufferSize)) {
129 gezelter 507 script += buffer;
130 tim 288 }
131     return loadScript(filename, script);
132 gezelter 507 }
133 cli2 1364
134 gezelter 1953 void SelectionEvaluator::instructionDispatchLoop(SelectionSet& bs){
135 tim 288
136 tim 281 while ( pc < aatoken.size()) {
137 gezelter 507 statement = aatoken[pc++];
138     statementLength = statement.size();
139     Token token = statement[0];
140     switch (token.tok) {
141     case Token::define:
142     define();
143     break;
144     case Token::select:
145     select(bs);
146     break;
147     default:
148     unrecognizedCommand(token);
149     return;
150     }
151 tim 278 }
152 tim 288
153 gezelter 507 }
154 tim 278
155 gezelter 1953 void SelectionEvaluator::instructionDispatchLoop(SelectionSet& bs, int frame){
156 gezelter 1816
157     while ( pc < aatoken.size()) {
158     statement = aatoken[pc++];
159     statementLength = statement.size();
160     Token token = statement[0];
161     switch (token.tok) {
162     case Token::define:
163     define();
164     break;
165     case Token::select:
166     select(bs, frame);
167     break;
168     default:
169     unrecognizedCommand(token);
170     return;
171     }
172     }
173    
174     }
175    
176 gezelter 1953 SelectionSet SelectionEvaluator::expression(const std::vector<Token>& code,
177 cli2 1364 int pcStart) {
178 gezelter 1953 SelectionSet bs = createSelectionSets();
179     std::stack<SelectionSet> stack;
180     vector<int> bsSize = bs.size();
181 cli2 1364
182 gezelter 1782 for (unsigned int pc = pcStart; pc < code.size(); ++pc) {
183 tim 278 Token instruction = code[pc];
184 tim 282
185 tim 278 switch (instruction.tok) {
186 tim 281 case Token::expressionBegin:
187 tim 278 break;
188 tim 281 case Token::expressionEnd:
189 tim 282 break;
190 tim 281 case Token::all:
191 gezelter 1801 bs = allInstruction();
192 gezelter 1953 stack.push(bs);
193 tim 278 break;
194 tim 281 case Token::none:
195 gezelter 1953 bs = createSelectionSets();
196     stack.push(bs);
197 tim 278 break;
198 tim 281 case Token::opOr:
199 gezelter 1953 bs= stack.top();
200     stack.pop();
201     stack.top() |= bs;
202 tim 278 break;
203 tim 281 case Token::opAnd:
204 gezelter 1953 bs = stack.top();
205     stack.pop();
206     stack.top() &= bs;
207 tim 278 break;
208 tim 281 case Token::opNot:
209 gezelter 1953 stack.top().flip();
210 tim 278 break;
211 tim 281 case Token::within:
212 tim 283 withinInstruction(instruction, stack.top());
213 tim 278 break;
214 gezelter 1412 case Token::hull:
215 gezelter 1953 stack.push(hull());
216 gezelter 1412 break;
217 gezelter 507 //case Token::selected:
218     // stack.push(getSelectionSet());
219     // break;
220 tim 281 case Token::name:
221 gezelter 1953 stack.push(nameInstruction(boost::any_cast<std::string>(instruction.value)));
222 tim 278 break;
223 tim 295 case Token::index:
224 gezelter 1953 stack.push(indexInstruction(instruction.value));
225 tim 281 break;
226     case Token::identifier:
227 gezelter 1953 stack.push(lookupValue(boost::any_cast<std::string>(instruction.value)));
228 tim 281 break;
229     case Token::opLT:
230     case Token::opLE:
231     case Token::opGE:
232     case Token::opGT:
233     case Token::opEQ:
234     case Token::opNE:
235 tim 283 stack.push(comparatorInstruction(instruction));
236 tim 278 break;
237     default:
238     unrecognizedExpression();
239     }
240     }
241 tim 283 if (stack.size() != 1)
242 tim 278 evalError("atom expression compiler error - stack over/underflow");
243 tim 283
244     return stack.top();
245 tim 278 }
246    
247    
248 gezelter 1953 SelectionSet SelectionEvaluator::expression(const std::vector<Token>& code,
249 gezelter 1816 int pcStart, int frame) {
250 gezelter 1953 SelectionSet bs = createSelectionSets();
251     std::stack<SelectionSet> stack;
252 gezelter 1816
253     for (unsigned int pc = pcStart; pc < code.size(); ++pc) {
254     Token instruction = code[pc];
255 tim 278
256 gezelter 1816 switch (instruction.tok) {
257     case Token::expressionBegin:
258     break;
259     case Token::expressionEnd:
260     break;
261     case Token::all:
262     bs = allInstruction();
263     stack.push(bs);
264     break;
265     case Token::none:
266 gezelter 1953 bs = SelectionSet(nObjects);
267 gezelter 1816 stack.push(bs);
268     break;
269     case Token::opOr:
270     bs = stack.top();
271     stack.pop();
272     stack.top() |= bs;
273     break;
274     case Token::opAnd:
275     bs = stack.top();
276     stack.pop();
277     stack.top() &= bs;
278     break;
279     case Token::opNot:
280     stack.top().flip();
281     break;
282     case Token::within:
283     withinInstruction(instruction, stack.top(), frame);
284     break;
285     case Token::hull:
286     stack.push(hull(frame));
287     break;
288     //case Token::selected:
289     // stack.push(getSelectionSet());
290     // break;
291     case Token::name:
292     stack.push(nameInstruction(boost::any_cast<std::string>(instruction.value)));
293     break;
294     case Token::index:
295     stack.push(indexInstruction(instruction.value));
296     break;
297     case Token::identifier:
298     stack.push(lookupValue(boost::any_cast<std::string>(instruction.value)));
299     break;
300     case Token::opLT:
301     case Token::opLE:
302     case Token::opGE:
303     case Token::opGT:
304     case Token::opEQ:
305     case Token::opNE:
306     stack.push(comparatorInstruction(instruction, frame));
307     break;
308     default:
309     unrecognizedExpression();
310     }
311     }
312     if (stack.size() != 1)
313     evalError("atom expression compiler error - stack over/underflow");
314    
315     return stack.top();
316     }
317    
318    
319    
320 gezelter 1953 SelectionSet SelectionEvaluator::comparatorInstruction(const Token& instruction) {
321 tim 278 int comparator = instruction.tok;
322     int property = instruction.intValue;
323 tim 283 float comparisonValue = boost::any_cast<float>(instruction.value);
324 gezelter 1953 SelectionSet bs = createSelectionSets();
325 tim 295 bs.clearAll();
326 tim 283
327     SimInfo::MoleculeIterator mi;
328     Molecule* mol;
329     Molecule::AtomIterator ai;
330     Atom* atom;
331     Molecule::RigidBodyIterator rbIter;
332     RigidBody* rb;
333 tim 281
334 cli2 1364 for (mol = info->beginMolecule(mi); mol != NULL;
335     mol = info->nextMolecule(mi)) {
336    
337 gezelter 507 for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
338     compareProperty(atom, bs, property, comparator, comparisonValue);
339     }
340 cli2 1364
341     for (rb = mol->beginRigidBody(rbIter); rb != NULL;
342     rb = mol->nextRigidBody(rbIter)) {
343     compareProperty(rb, bs, property, comparator, comparisonValue);
344     }
345 tim 278 }
346    
347 tim 283 return bs;
348 gezelter 507 }
349 tim 278
350 gezelter 1953 SelectionSet SelectionEvaluator::comparatorInstruction(const Token& instruction, int frame) {
351 gezelter 1816 int comparator = instruction.tok;
352     int property = instruction.intValue;
353     float comparisonValue = boost::any_cast<float>(instruction.value);
354 gezelter 1953 SelectionSet bs = createSelectionSets();
355 gezelter 1816 bs.clearAll();
356    
357     SimInfo::MoleculeIterator mi;
358     Molecule* mol;
359     Molecule::AtomIterator ai;
360     Atom* atom;
361     Molecule::RigidBodyIterator rbIter;
362     RigidBody* rb;
363    
364     for (mol = info->beginMolecule(mi); mol != NULL;
365     mol = info->nextMolecule(mi)) {
366    
367     for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
368     compareProperty(atom, bs, property, comparator, comparisonValue, frame);
369     }
370    
371     for (rb = mol->beginRigidBody(rbIter); rb != NULL;
372     rb = mol->nextRigidBody(rbIter)) {
373     compareProperty(rb, bs, property, comparator, comparisonValue, frame);
374     }
375     }
376    
377     return bs;
378     }
379    
380 gezelter 1953 void SelectionEvaluator::compareProperty(StuntDouble* sd, SelectionSet& bs,
381 cli2 1364 int property, int comparator,
382     float comparisonValue) {
383 tim 963 RealType propertyValue = 0.0;
384 gezelter 1879 Vector3d pos;
385 gezelter 1931
386 gezelter 507 switch (property) {
387     case Token::mass:
388     propertyValue = sd->getMass();
389     break;
390     case Token::charge:
391     if (sd->isAtom()){
392     Atom* atom = static_cast<Atom*>(sd);
393     propertyValue = getCharge(atom);
394     } else if (sd->isRigidBody()) {
395     RigidBody* rb = static_cast<RigidBody*>(sd);
396     RigidBody::AtomIterator ai;
397     Atom* atom;
398     for (atom = rb->beginAtom(ai); atom != NULL; atom = rb->nextAtom(ai)) {
399     propertyValue+= getCharge(atom);
400     }
401     }
402     break;
403 cli2 1360 case Token::x:
404     propertyValue = sd->getPos().x();
405     break;
406     case Token::y:
407     propertyValue = sd->getPos().y();
408     break;
409     case Token::z:
410     propertyValue = sd->getPos().z();
411     break;
412 gezelter 1879 case Token::wrappedX:
413     pos = sd->getPos();
414     info->getSnapshotManager()->getCurrentSnapshot()->wrapVector(pos);
415     propertyValue = pos.x();
416     break;
417     case Token::wrappedY:
418     pos = sd->getPos();
419     info->getSnapshotManager()->getCurrentSnapshot()->wrapVector(pos);
420     propertyValue = pos.y();
421     break;
422     case Token::wrappedZ:
423     pos = sd->getPos();
424     info->getSnapshotManager()->getCurrentSnapshot()->wrapVector(pos);
425     propertyValue = pos.z();
426     break;
427 gezelter 1513 case Token::r:
428     propertyValue = sd->getPos().length();
429     break;
430 gezelter 507 default:
431     unrecognizedAtomProperty(property);
432     }
433 tim 283
434 gezelter 507 bool match = false;
435     switch (comparator) {
436     case Token::opLT:
437     match = propertyValue < comparisonValue;
438     break;
439     case Token::opLE:
440     match = propertyValue <= comparisonValue;
441     break;
442     case Token::opGE:
443     match = propertyValue >= comparisonValue;
444     break;
445     case Token::opGT:
446     match = propertyValue > comparisonValue;
447     break;
448     case Token::opEQ:
449     match = propertyValue == comparisonValue;
450     break;
451     case Token::opNE:
452     match = propertyValue != comparisonValue;
453     break;
454     }
455 gezelter 1931
456 gezelter 1816 if (match)
457 gezelter 1953 bs.bitsets_[STUNTDOUBLE].setBitOn(sd->getGlobalIndex());
458 gezelter 1816
459 cli2 1364
460 gezelter 507 }
461 tim 283
462 gezelter 1953 void SelectionEvaluator::compareProperty(StuntDouble* sd, SelectionSet& bs,
463 gezelter 1816 int property, int comparator,
464     float comparisonValue, int frame) {
465     RealType propertyValue = 0.0;
466 gezelter 1879 Vector3d pos;
467 gezelter 1816 switch (property) {
468     case Token::mass:
469     propertyValue = sd->getMass();
470     break;
471     case Token::charge:
472     if (sd->isAtom()){
473     Atom* atom = static_cast<Atom*>(sd);
474     propertyValue = getCharge(atom,frame);
475     } else if (sd->isRigidBody()) {
476     RigidBody* rb = static_cast<RigidBody*>(sd);
477     RigidBody::AtomIterator ai;
478     Atom* atom;
479     for (atom = rb->beginAtom(ai); atom != NULL; atom = rb->nextAtom(ai)) {
480     propertyValue+= getCharge(atom,frame);
481     }
482     }
483     break;
484     case Token::x:
485     propertyValue = sd->getPos(frame).x();
486     break;
487     case Token::y:
488     propertyValue = sd->getPos(frame).y();
489     break;
490     case Token::z:
491     propertyValue = sd->getPos(frame).z();
492     break;
493 gezelter 1879 case Token::wrappedX:
494     pos = sd->getPos(frame);
495     info->getSnapshotManager()->getSnapshot(frame)->wrapVector(pos);
496     propertyValue = pos.x();
497     break;
498     case Token::wrappedY:
499     pos = sd->getPos(frame);
500     info->getSnapshotManager()->getSnapshot(frame)->wrapVector(pos);
501     propertyValue = pos.y();
502     break;
503     case Token::wrappedZ:
504     pos = sd->getPos(frame);
505     info->getSnapshotManager()->getSnapshot(frame)->wrapVector(pos);
506     propertyValue = pos.z();
507     break;
508    
509 gezelter 1816 case Token::r:
510     propertyValue = sd->getPos(frame).length();
511     break;
512     default:
513     unrecognizedAtomProperty(property);
514     }
515    
516     bool match = false;
517     switch (comparator) {
518     case Token::opLT:
519     match = propertyValue < comparisonValue;
520     break;
521     case Token::opLE:
522     match = propertyValue <= comparisonValue;
523     break;
524     case Token::opGE:
525     match = propertyValue >= comparisonValue;
526     break;
527     case Token::opGT:
528     match = propertyValue > comparisonValue;
529     break;
530     case Token::opEQ:
531     match = propertyValue == comparisonValue;
532     break;
533     case Token::opNE:
534     match = propertyValue != comparisonValue;
535     break;
536     }
537     if (match)
538 gezelter 1953 bs.bitsets_[STUNTDOUBLE].setBitOn(sd->getGlobalIndex());
539 gezelter 1816
540    
541     }
542    
543 cli2 1364 void SelectionEvaluator::withinInstruction(const Token& instruction,
544 gezelter 1953 SelectionSet& bs){
545 tim 295
546 tim 281 boost::any withinSpec = instruction.value;
547 tim 295 float distance;
548 tim 282 if (withinSpec.type() == typeid(float)){
549 gezelter 507 distance = boost::any_cast<float>(withinSpec);
550 tim 295 } else if (withinSpec.type() == typeid(int)) {
551 gezelter 507 distance = boost::any_cast<int>(withinSpec);
552 tim 295 } else {
553 gezelter 507 evalError("casting error in withinInstruction");
554     bs.clearAll();
555 tim 278 }
556 tim 282
557 tim 295 bs = distanceFinder.find(bs, distance);
558 gezelter 507 }
559 gezelter 1816
560     void SelectionEvaluator::withinInstruction(const Token& instruction,
561 gezelter 1953 SelectionSet& bs, int frame){
562 gezelter 1816
563     boost::any withinSpec = instruction.value;
564     float distance;
565     if (withinSpec.type() == typeid(float)){
566     distance = boost::any_cast<float>(withinSpec);
567     } else if (withinSpec.type() == typeid(int)) {
568     distance = boost::any_cast<int>(withinSpec);
569     } else {
570     evalError("casting error in withinInstruction");
571     bs.clearAll();
572     }
573    
574     bs = distanceFinder.find(bs, distance, frame);
575     }
576 cli2 1364
577 gezelter 507 void SelectionEvaluator::define() {
578 tim 282 assert(statement.size() >= 3);
579 cli2 1364
580 tim 282 std::string variable = boost::any_cast<std::string>(statement[1].value);
581 cli2 1364
582     variables.insert(VariablesType::value_type(variable,
583     expression(statement, 2)));
584 gezelter 507 }
585 cli2 1364
586 tim 278
587 gezelter 507 /** @todo */
588     void SelectionEvaluator::predefine(const std::string& script) {
589 cli2 1364
590 tim 282 if (compiler.compile("#predefine", script)) {
591 gezelter 507 std::vector<std::vector<Token> > aatoken = compiler.getAatokenCompiled();
592     if (aatoken.size() != 1) {
593     evalError("predefinition does not have exactly 1 command:"
594     + script);
595     return;
596     }
597     std::vector<Token> statement = aatoken[0];
598     if (statement.size() > 2) {
599     int tok = statement[1].tok;
600 cli2 1364 if (tok == Token::identifier ||
601     (tok & Token::predefinedset) == Token::predefinedset) {
602 gezelter 507 std::string variable = boost::any_cast<std::string>(statement[1].value);
603     variables.insert(VariablesType::value_type(variable, statement));
604 cli2 1364
605 gezelter 507 } else {
606     evalError("invalid variable name:" + script);
607     }
608     }else {
609     evalError("bad predefinition length:" + script);
610 cli2 1364 }
611 tim 282
612     } else {
613 gezelter 507 evalError("predefined set compile error:" + script +
614     "\ncompile error:" + compiler.getErrorMessage());
615 tim 282 }
616 gezelter 507 }
617 tim 282
618 gezelter 1953 void SelectionEvaluator::select(SelectionSet& bs){
619 tim 288 bs = expression(statement, 1);
620 gezelter 507 }
621 gezelter 1816
622 gezelter 1953 void SelectionEvaluator::select(SelectionSet& bs, int frame){
623 gezelter 1816 bs = expression(statement, 1, frame);
624     }
625 cli2 1364
626 gezelter 1953 SelectionSet SelectionEvaluator::lookupValue(const std::string& variable){
627 cli2 1364
628 gezelter 1953 SelectionSet bs = createSelectionSets();
629 tim 282 std::map<std::string, boost::any>::iterator i = variables.find(variable);
630 tim 295
631 tim 282 if (i != variables.end()) {
632 gezelter 1953 if (i->second.type() == typeid(SelectionSet)) {
633     return boost::any_cast<SelectionSet>(i->second);
634 gezelter 507 } else if (i->second.type() == typeid(std::vector<Token>)){
635     bs = expression(boost::any_cast<std::vector<Token> >(i->second), 2);
636     i->second = bs; /**@todo fixme */
637     return bs;
638     }
639 tim 283 } else {
640 gezelter 507 unrecognizedIdentifier(variable);
641 tim 282 }
642 cli2 1364
643 tim 295 return bs;
644 gezelter 507 }
645 cli2 1364
646 gezelter 1953 SelectionSet SelectionEvaluator::nameInstruction(const std::string& name){
647 cli2 1364 return nameFinder.match(name);
648 gezelter 507 }
649 tim 283
650 gezelter 507 bool SelectionEvaluator::containDynamicToken(const std::vector<Token>& tokens){
651 tim 288 std::vector<Token>::const_iterator i;
652     for (i = tokens.begin(); i != tokens.end(); ++i) {
653 gezelter 507 if (i->tok & Token::dynamic) {
654     return true;
655     }
656 tim 288 }
657 cli2 1364
658 tim 288 return false;
659 gezelter 507 }
660 tim 288
661 gezelter 507 void SelectionEvaluator::clearDefinitionsAndLoadPredefined() {
662 tim 288 variables.clear();
663     //load predefine
664     //predefine();
665 gezelter 507 }
666 tim 288
667 gezelter 1953 SelectionSet SelectionEvaluator::createSelectionSets() {
668     SelectionSet ss(nObjects);
669     return ss;
670     }
671    
672     SelectionSet SelectionEvaluator::evaluate() {
673     SelectionSet bs = createSelectionSets();
674 tim 288 if (isLoaded_) {
675 gezelter 507 pc = 0;
676     instructionDispatchLoop(bs);
677 tim 288 }
678 gezelter 1816 return bs;
679     }
680 tim 288
681 gezelter 1953 SelectionSet SelectionEvaluator::evaluate(int frame) {
682     SelectionSet bs = createSelectionSets();
683 gezelter 1816 if (isLoaded_) {
684     pc = 0;
685     instructionDispatchLoop(bs, frame);
686     }
687 tim 288 return bs;
688 gezelter 507 }
689 tim 295
690 gezelter 1953 SelectionSet SelectionEvaluator::indexInstruction(const boost::any& value) {
691     SelectionSet bs = createSelectionSets();
692 tim 295
693     if (value.type() == typeid(int)) {
694 gezelter 507 int index = boost::any_cast<int>(value);
695 gezelter 1953 if (index < 0 || index >= bs.bitsets_[STUNTDOUBLE].size()) {
696 gezelter 507 invalidIndex(index);
697     } else {
698     bs = indexFinder.find(index);
699     }
700 tim 295 } else if (value.type() == typeid(std::pair<int, int>)) {
701 gezelter 507 std::pair<int, int> indexRange= boost::any_cast<std::pair<int, int> >(value);
702     assert(indexRange.first <= indexRange.second);
703 gezelter 1953 if (indexRange.first < 0 ||
704     indexRange.second >= bs.bitsets_[STUNTDOUBLE].size()) {
705 gezelter 507 invalidIndexRange(indexRange);
706     }else {
707     bs = indexFinder.find(indexRange.first, indexRange.second);
708     }
709 tim 295 }
710    
711     return bs;
712 gezelter 507 }
713 tim 295
714 gezelter 1953 SelectionSet SelectionEvaluator::allInstruction() {
715     SelectionSet ss = createSelectionSets();
716 tim 432
717 gezelter 1801 SimInfo::MoleculeIterator mi;
718 gezelter 1953 Molecule::AtomIterator ai;
719     Molecule::RigidBodyIterator rbIter;
720     Molecule::BondIterator bondIter;
721     Molecule::BendIterator bendIter;
722     Molecule::TorsionIterator torsionIter;
723     Molecule::InversionIterator inversionIter;
724    
725 gezelter 1801 Molecule* mol;
726     Atom* atom;
727     RigidBody* rb;
728 gezelter 1953 Bond* bond;
729     Bend* bend;
730     Torsion* torsion;
731     Inversion* inversion;
732 gezelter 1801
733     // Doing the loop insures that we're actually on this processor.
734    
735     for (mol = info->beginMolecule(mi); mol != NULL;
736     mol = info->nextMolecule(mi)) {
737     for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
738 gezelter 1953 ss.bitsets_[STUNTDOUBLE].setBitOn(atom->getGlobalIndex());
739     }
740 gezelter 1801 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
741     rb = mol->nextRigidBody(rbIter)) {
742 gezelter 1953 ss.bitsets_[STUNTDOUBLE].setBitOn(rb->getGlobalIndex());
743 gezelter 1801 }
744 gezelter 1953 for (bond = mol->beginBond(bondIter); bond != NULL;
745     bond = mol->nextBond(bondIter)) {
746     ss.bitsets_[BOND].setBitOn(bond->getGlobalIndex());
747     }
748     for (bend = mol->beginBend(bendIter); bend != NULL;
749     bend = mol->nextBend(bendIter)) {
750     ss.bitsets_[BEND].setBitOn(bend->getGlobalIndex());
751     }
752     for (torsion = mol->beginTorsion(torsionIter); torsion != NULL;
753     torsion = mol->nextTorsion(torsionIter)) {
754     ss.bitsets_[TORSION].setBitOn(torsion->getGlobalIndex());
755     }
756     for (inversion = mol->beginInversion(inversionIter); inversion != NULL;
757     inversion = mol->nextInversion(inversionIter)) {
758     ss.bitsets_[INVERSION].setBitOn(inversion->getGlobalIndex());
759     }
760 gezelter 1801 }
761    
762 gezelter 1953 return ss;
763 gezelter 1801 }
764    
765 gezelter 1953 SelectionSet SelectionEvaluator::hull() {
766     SelectionSet bs = createSelectionSets();
767 gezelter 1412
768     bs = hullFinder.findHull();
769 gezelter 1903 surfaceArea_ = hullFinder.getSurfaceArea();
770     hasSurfaceArea_ = true;
771 gezelter 1412 return bs;
772     }
773    
774 gezelter 1816
775 gezelter 1953 SelectionSet SelectionEvaluator::hull(int frame) {
776     SelectionSet bs = createSelectionSets();
777 gezelter 1816
778     bs = hullFinder.findHull(frame);
779 gezelter 1903
780 gezelter 1816 return bs;
781     }
782    
783 tim 963 RealType SelectionEvaluator::getCharge(Atom* atom) {
784 gezelter 1816 RealType charge = 0.0;
785 tim 432 AtomType* atomType = atom->getAtomType();
786    
787 gezelter 1816 FixedChargeAdapter fca = FixedChargeAdapter(atomType);
788     if ( fca.isFixedCharge() ) {
789     charge = fca.getCharge();
790     }
791    
792     FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atomType);
793     if ( fqa.isFluctuatingCharge() ) {
794     charge += atom->getFlucQPos();
795     }
796     return charge;
797     }
798 tim 432
799 gezelter 1816 RealType SelectionEvaluator::getCharge(Atom* atom, int frame) {
800     RealType charge = 0.0;
801     AtomType* atomType = atom->getAtomType();
802    
803     FixedChargeAdapter fca = FixedChargeAdapter(atomType);
804     if ( fca.isFixedCharge() ) {
805     charge = fca.getCharge();
806 tim 432 }
807 gezelter 1816
808     FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atomType);
809     if ( fqa.isFluctuatingCharge() ) {
810     charge += atom->getFlucQPos(frame);
811     }
812 tim 432 return charge;
813 gezelter 507 }
814 tim 432
815     }

Properties

Name Value
svn:keywords Author Id Revision Date