ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/selection/SelectionEvaluator.cpp
(Generate patch)

Comparing trunk/src/selection/SelectionEvaluator.cpp (file contents):
Revision 413 by tim, Wed Mar 9 17:30:29 2005 UTC vs.
Revision 1931 by gezelter, Mon Aug 19 19:20:32 2013 UTC

# Line 6 | Line 6
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.
# Line 37 | Line 28
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, 234107 (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>
# Line 45 | Line 46
46   #include "primitives/DirectionalAtom.hpp"
47   #include "primitives/RigidBody.hpp"
48   #include "primitives/Molecule.hpp"
49 + #include "io/ifstrstream.hpp"
50 + #include "types/FixedChargeAdapter.hpp"
51 + #include "types/FluctuatingChargeAdapter.hpp"
52  
49 namespace oopse {
53  
54 + namespace OpenMD {
55  
52 SelectionEvaluator::SelectionEvaluator(SimInfo* si)
53    : info(si), nameFinder(info), distanceFinder(info), indexFinder(info), isLoaded_(false){
54    
55    nStuntDouble = info->getNGlobalAtoms() + info->getNRigidBodies();
56 }            
56  
57 < bool SelectionEvaluator::loadScript(const std::string& filename, const std::string& script) {
57 >  SelectionEvaluator::SelectionEvaluator(SimInfo* si)
58 >    : info(si), nameFinder(info), distanceFinder(info), hullFinder(info),
59 >      indexFinder(info), hasSurfaceArea_(false),
60 >      isLoaded_(false){    
61 >      nStuntDouble = info->getNGlobalAtoms() + info->getNGlobalRigidBodies();
62 >    }            
63 >
64 >  bool SelectionEvaluator::loadScript(const std::string& filename,
65 >                                      const std::string& script) {
66      clearDefinitionsAndLoadPredefined();
67      this->filename = filename;
68      this->script = script;
69      if (! compiler.compile(filename, script)) {
70 <        error = true;
71 <        errorMessage = compiler.getErrorMessage();
72 <        std::cerr << "SelectionCompiler Error: " << errorMessage << std::endl;
73 <        return false;
70 >      error = true;
71 >      errorMessage = compiler.getErrorMessage();
72 >
73 >      sprintf( painCave.errMsg,
74 >               "SelectionCompiler Error: %s\n", errorMessage.c_str());
75 >      painCave.severity = OPENMD_ERROR;
76 >      painCave.isFatal = 1;
77 >      simError();
78 >      return false;
79      }
80  
81      pc = 0;
# Line 75 | Line 87 | bool SelectionEvaluator::loadScript(const std::string&
87  
88      isDynamic_ = false;
89      for (i = aatoken.begin(); i != aatoken.end(); ++i) {
90 <        if (containDynamicToken(*i)) {
91 <            isDynamic_ = true;
92 <            break;
93 <        }
90 >      if (containDynamicToken(*i)) {
91 >        isDynamic_ = true;
92 >        break;
93 >      }
94      }
95  
96      isLoaded_ = true;
97      return true;
98 < }
98 >  }
99  
100 < void SelectionEvaluator::clearState() {
89 <    //for (int i = scriptLevelMax; --i >= 0; )
90 <    //    stack[i].clear();
91 <    //scriptLevel = 0;
100 >  void SelectionEvaluator::clearState() {
101      error = false;
102      errorMessage = "";
103 < }
103 >  }
104  
105 < bool SelectionEvaluator::loadScriptString(const std::string& script) {
105 >  bool SelectionEvaluator::loadScriptString(const std::string& script) {
106      clearState();
107      return loadScript("", script);
108 < }
108 >  }
109  
110 < bool SelectionEvaluator::loadScriptFile(const std::string& filename) {
110 >  bool SelectionEvaluator::loadScriptFile(const std::string& filename) {
111      clearState();
112      return loadScriptFileInternal(filename);
113 < }
113 >  }
114  
115 < bool SelectionEvaluator::loadScriptFileInternal(const  std::string & filename) {
116 <  std::ifstream ifs(filename.c_str());
115 >  bool SelectionEvaluator::loadScriptFileInternal(const std::string & filename) {
116 >    ifstrstream ifs(filename.c_str());
117      if (!ifs.is_open()) {
118 <        return false;
118 >      return false;
119      }
120 <
120 >    
121      const int bufferSize = 65535;
122      char buffer[bufferSize];
123      std::string script;
124      while(ifs.getline(buffer, bufferSize)) {
125 <        script += buffer;
125 >      script += buffer;
126      }
127      return loadScript(filename, script);
128 < }
129 <
130 < void SelectionEvaluator::instructionDispatchLoop(BitSet& bs){
128 >  }
129 >  
130 >  void SelectionEvaluator::instructionDispatchLoop(OpenMDBitSet& bs){
131      
132      while ( pc < aatoken.size()) {
133 <        statement = aatoken[pc++];
134 <        statementLength = statement.size();
135 <        Token token = statement[0];
136 <        switch (token.tok) {
137 <            case Token::define:
138 <                define();
139 <            break;
140 <            case Token::select:
141 <                select(bs);
142 <            break;
143 <            default:
144 <                unrecognizedCommand(token);
145 <            return;
146 <        }
133 >      statement = aatoken[pc++];
134 >      statementLength = statement.size();
135 >      Token token = statement[0];
136 >      switch (token.tok) {
137 >      case Token::define:
138 >        define();
139 >        break;
140 >      case Token::select:
141 >        select(bs);
142 >        break;
143 >      default:
144 >        unrecognizedCommand(token);
145 >        return;
146 >      }
147      }
148  
149 < }
149 >  }
150  
151 <  BitSet SelectionEvaluator::expression(const std::vector<Token>& code, int pcStart) {
143 <    BitSet bs;
144 <    std::stack<BitSet> stack;
151 >  void SelectionEvaluator::instructionDispatchLoop(OpenMDBitSet& bs, int frame){
152      
153 <    for (int pc = pcStart; pc < code.size(); ++pc) {
153 >    while ( pc < aatoken.size()) {
154 >      statement = aatoken[pc++];
155 >      statementLength = statement.size();
156 >      Token token = statement[0];
157 >      switch (token.tok) {
158 >      case Token::define:
159 >        define();
160 >        break;
161 >      case Token::select:
162 >        select(bs, frame);
163 >        break;
164 >      default:
165 >        unrecognizedCommand(token);
166 >        return;
167 >      }
168 >    }
169 >
170 >  }
171 >
172 >  OpenMDBitSet SelectionEvaluator::expression(const std::vector<Token>& code,
173 >                                             int pcStart) {
174 >    OpenMDBitSet bs;
175 >    std::stack<OpenMDBitSet> stack;
176 >  
177 >    for (unsigned int pc = pcStart; pc < code.size(); ++pc) {
178        Token instruction = code[pc];
179  
180        switch (instruction.tok) {
# Line 152 | Line 183 | void SelectionEvaluator::instructionDispatchLoop(BitSe
183        case Token::expressionEnd:
184          break;
185        case Token::all:
186 <        bs = BitSet(nStuntDouble);
156 <        bs.setAll();
186 >        bs = allInstruction();
187          stack.push(bs);            
188          break;
189        case Token::none:
190 <        bs = BitSet(nStuntDouble);
190 >        bs = OpenMDBitSet(nStuntDouble);
191          stack.push(bs);            
192          break;
193        case Token::opOr:
# Line 174 | Line 204 | void SelectionEvaluator::instructionDispatchLoop(BitSe
204          stack.top().flip();
205          break;
206        case Token::within:
177
207          withinInstruction(instruction, stack.top());
208          break;
209 <      //case Token::selected:
210 <      //  stack.push(getSelectionSet());
211 <      //  break;
209 >      case Token::hull:
210 >        stack.push(hull());
211 >        break;
212 >        //case Token::selected:
213 >        //  stack.push(getSelectionSet());
214 >        //  break;
215        case Token::name:
216          stack.push(nameInstruction(boost::any_cast<std::string>(instruction.value)));
217          break;
# Line 208 | Line 240 | void SelectionEvaluator::instructionDispatchLoop(BitSe
240    }
241  
242  
243 +  OpenMDBitSet SelectionEvaluator::expression(const std::vector<Token>& code,
244 +                                              int pcStart, int frame) {
245 +    OpenMDBitSet bs;
246 +    std::stack<OpenMDBitSet> stack;
247 +  
248 +    for (unsigned int pc = pcStart; pc < code.size(); ++pc) {
249 +      Token instruction = code[pc];
250  
251 < BitSet SelectionEvaluator::comparatorInstruction(const Token& instruction) {
251 >      switch (instruction.tok) {
252 >      case Token::expressionBegin:
253 >        break;
254 >      case Token::expressionEnd:
255 >        break;
256 >      case Token::all:
257 >        bs = allInstruction();
258 >        stack.push(bs);            
259 >        break;
260 >      case Token::none:
261 >        bs = OpenMDBitSet(nStuntDouble);
262 >        stack.push(bs);            
263 >        break;
264 >      case Token::opOr:
265 >        bs = stack.top();
266 >        stack.pop();
267 >        stack.top() |= bs;
268 >        break;
269 >      case Token::opAnd:
270 >        bs = stack.top();
271 >        stack.pop();
272 >        stack.top() &= bs;
273 >        break;
274 >      case Token::opNot:
275 >        stack.top().flip();
276 >        break;
277 >      case Token::within:
278 >        withinInstruction(instruction, stack.top(), frame);
279 >        break;
280 >      case Token::hull:
281 >        stack.push(hull(frame));
282 >        break;
283 >        //case Token::selected:
284 >        //  stack.push(getSelectionSet());
285 >        //  break;
286 >      case Token::name:
287 >        stack.push(nameInstruction(boost::any_cast<std::string>(instruction.value)));
288 >        break;
289 >      case Token::index:
290 >        stack.push(indexInstruction(instruction.value));
291 >        break;
292 >      case Token::identifier:
293 >        stack.push(lookupValue(boost::any_cast<std::string>(instruction.value)));
294 >        break;
295 >      case Token::opLT:
296 >      case Token::opLE:
297 >      case Token::opGE:
298 >      case Token::opGT:
299 >      case Token::opEQ:
300 >      case Token::opNE:
301 >        stack.push(comparatorInstruction(instruction, frame));
302 >        break;
303 >      default:
304 >        unrecognizedExpression();
305 >      }
306 >    }
307 >    if (stack.size() != 1)
308 >      evalError("atom expression compiler error - stack over/underflow");
309 >          
310 >    return stack.top();
311 >  }
312 >
313 >
314 >
315 >  OpenMDBitSet SelectionEvaluator::comparatorInstruction(const Token& instruction) {
316      int comparator = instruction.tok;
317      int property = instruction.intValue;
318      float comparisonValue = boost::any_cast<float>(instruction.value);
319 <    float propertyValue;
217 <    BitSet bs(nStuntDouble);
319 >    OpenMDBitSet bs(nStuntDouble);
320      bs.clearAll();
321      
322      SimInfo::MoleculeIterator mi;
# Line 223 | Line 325 | BitSet SelectionEvaluator::comparatorInstruction(const
325      Atom* atom;
326      Molecule::RigidBodyIterator rbIter;
327      RigidBody* rb;
328 +
329 +    for (mol = info->beginMolecule(mi); mol != NULL;
330 +         mol = info->nextMolecule(mi)) {
331 +
332 +      for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
333 +        compareProperty(atom, bs, property, comparator, comparisonValue);
334 +      }
335 +    
336 +      for (rb = mol->beginRigidBody(rbIter); rb != NULL;
337 +           rb = mol->nextRigidBody(rbIter)) {
338 +        compareProperty(rb, bs, property, comparator, comparisonValue);
339 +      }
340 +    }
341 +
342 +    return bs;
343 +  }
344 +
345 +  OpenMDBitSet SelectionEvaluator::comparatorInstruction(const Token& instruction, int frame) {
346 +    int comparator = instruction.tok;
347 +    int property = instruction.intValue;
348 +    float comparisonValue = boost::any_cast<float>(instruction.value);
349 +    OpenMDBitSet bs(nStuntDouble);
350 +    bs.clearAll();
351      
352 <    for (mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) {
352 >    SimInfo::MoleculeIterator mi;
353 >    Molecule* mol;
354 >    Molecule::AtomIterator ai;
355 >    Atom* atom;
356 >    Molecule::RigidBodyIterator rbIter;
357 >    RigidBody* rb;
358  
359 <        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
360 <            compareProperty(atom, bs, property, comparator, comparisonValue);
361 <        }
362 <        
363 <        //change the positions of atoms which belong to the rigidbodies
364 <        for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
365 <            compareProperty(rb, bs, property, comparator, comparisonValue);
366 <        }        
359 >    for (mol = info->beginMolecule(mi); mol != NULL;
360 >         mol = info->nextMolecule(mi)) {
361 >
362 >      for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
363 >        compareProperty(atom, bs, property, comparator, comparisonValue, frame);
364 >      }
365 >    
366 >      for (rb = mol->beginRigidBody(rbIter); rb != NULL;
367 >           rb = mol->nextRigidBody(rbIter)) {
368 >        compareProperty(rb, bs, property, comparator, comparisonValue, frame);
369 >      }
370      }
371  
372      return bs;
373 < }
373 >  }
374  
375 < void SelectionEvaluator::compareProperty(StuntDouble* sd, BitSet& bs, int property, int comparator, float comparisonValue) {
376 <        double propertyValue;
377 <        switch (property) {
378 <        case Token::mass:
379 <            propertyValue = sd->getMass();
380 <            break;
381 <        case Token::charge:
382 <            return;
383 <            //break;
384 <        case Token::dipole:
385 <            return;
386 <            //break;
387 <        default:
388 <            unrecognizedAtomProperty(property);
389 <        }
375 >  void SelectionEvaluator::compareProperty(StuntDouble* sd, OpenMDBitSet& bs,
376 >                                           int property, int comparator,
377 >                                           float comparisonValue) {
378 >    RealType propertyValue = 0.0;
379 >    Vector3d pos;
380 >
381 >    switch (property) {
382 >    case Token::mass:
383 >      propertyValue = sd->getMass();
384 >      break;
385 >    case Token::charge:
386 >      if (sd->isAtom()){
387 >        Atom* atom = static_cast<Atom*>(sd);
388 >        propertyValue = getCharge(atom);
389 >      } else if (sd->isRigidBody()) {
390 >        RigidBody* rb = static_cast<RigidBody*>(sd);
391 >        RigidBody::AtomIterator ai;
392 >        Atom* atom;
393 >        for (atom = rb->beginAtom(ai); atom != NULL; atom = rb->nextAtom(ai)) {
394 >          propertyValue+=  getCharge(atom);
395 >        }
396 >      }
397 >      break;
398 >    case Token::x:
399 >      propertyValue = sd->getPos().x();
400 >      break;
401 >    case Token::y:
402 >      propertyValue = sd->getPos().y();
403 >      break;
404 >    case Token::z:
405 >      propertyValue = sd->getPos().z();
406 >      break;
407 >    case Token::wrappedX:    
408 >      pos = sd->getPos();
409 >      info->getSnapshotManager()->getCurrentSnapshot()->wrapVector(pos);
410 >      propertyValue = pos.x();
411 >      break;
412 >    case Token::wrappedY:
413 >      pos = sd->getPos();
414 >      info->getSnapshotManager()->getCurrentSnapshot()->wrapVector(pos);
415 >      propertyValue = pos.y();
416 >      break;
417 >    case Token::wrappedZ:
418 >      pos = sd->getPos();
419 >      info->getSnapshotManager()->getCurrentSnapshot()->wrapVector(pos);
420 >      propertyValue = pos.z();
421 >      break;
422 >    case Token::r:
423 >      propertyValue = sd->getPos().length();
424 >      break;
425 >    default:
426 >      unrecognizedAtomProperty(property);
427 >    }
428          
429 <        bool match = false;
430 <        switch (comparator) {
431 <            case Token::opLT:
432 <                match = propertyValue < comparisonValue;
433 <                break;
434 <            case Token::opLE:
435 <                match = propertyValue <= comparisonValue;
436 <                break;
437 <            case Token::opGE:
438 <                match = propertyValue >= comparisonValue;
439 <                break;
440 <            case Token::opGT:
441 <                match = propertyValue > comparisonValue;
442 <                break;
443 <            case Token::opEQ:
444 <                match = propertyValue == comparisonValue;
445 <                break;
446 <            case Token::opNE:
447 <                match = propertyValue != comparisonValue;
448 <                break;
449 <        }
279 <        if (match)
280 <            bs.setBitOn(sd->getGlobalIndex());
429 >    bool match = false;
430 >    switch (comparator) {
431 >    case Token::opLT:
432 >      match = propertyValue < comparisonValue;
433 >      break;
434 >    case Token::opLE:
435 >      match = propertyValue <= comparisonValue;
436 >      break;
437 >    case Token::opGE:
438 >      match = propertyValue >= comparisonValue;
439 >      break;
440 >    case Token::opGT:
441 >      match = propertyValue > comparisonValue;
442 >      break;
443 >    case Token::opEQ:
444 >      match = propertyValue == comparisonValue;
445 >      break;
446 >    case Token::opNE:
447 >      match = propertyValue != comparisonValue;
448 >      break;
449 >    }
450  
451 < }
451 >    if (match)
452 >      bs.setBitOn(sd->getGlobalIndex());
453 >
454 >    
455 >  }
456  
457 < void SelectionEvaluator::withinInstruction(const Token& instruction, BitSet& bs){
457 >  void SelectionEvaluator::compareProperty(StuntDouble* sd, OpenMDBitSet& bs,
458 >                                           int property, int comparator,
459 >                                           float comparisonValue, int frame) {
460 >    RealType propertyValue = 0.0;
461 >    Vector3d pos;
462 >    switch (property) {
463 >    case Token::mass:
464 >      propertyValue = sd->getMass();
465 >      break;
466 >    case Token::charge:
467 >      if (sd->isAtom()){
468 >        Atom* atom = static_cast<Atom*>(sd);
469 >        propertyValue = getCharge(atom,frame);
470 >      } else if (sd->isRigidBody()) {
471 >        RigidBody* rb = static_cast<RigidBody*>(sd);
472 >        RigidBody::AtomIterator ai;
473 >        Atom* atom;
474 >        for (atom = rb->beginAtom(ai); atom != NULL; atom = rb->nextAtom(ai)) {
475 >          propertyValue+=  getCharge(atom,frame);
476 >        }
477 >      }
478 >      break;
479 >    case Token::x:
480 >      propertyValue = sd->getPos(frame).x();
481 >      break;
482 >    case Token::y:
483 >      propertyValue = sd->getPos(frame).y();
484 >      break;
485 >    case Token::z:
486 >      propertyValue = sd->getPos(frame).z();
487 >      break;
488 >    case Token::wrappedX:    
489 >      pos = sd->getPos(frame);
490 >      info->getSnapshotManager()->getSnapshot(frame)->wrapVector(pos);
491 >      propertyValue = pos.x();
492 >      break;
493 >    case Token::wrappedY:
494 >      pos = sd->getPos(frame);
495 >      info->getSnapshotManager()->getSnapshot(frame)->wrapVector(pos);
496 >      propertyValue = pos.y();
497 >      break;
498 >    case Token::wrappedZ:
499 >      pos = sd->getPos(frame);
500 >      info->getSnapshotManager()->getSnapshot(frame)->wrapVector(pos);
501 >      propertyValue = pos.z();
502 >      break;
503 >
504 >    case Token::r:
505 >      propertyValue = sd->getPos(frame).length();
506 >      break;
507 >    default:
508 >      unrecognizedAtomProperty(property);
509 >    }
510 >        
511 >    bool match = false;
512 >    switch (comparator) {
513 >    case Token::opLT:
514 >      match = propertyValue < comparisonValue;
515 >      break;
516 >    case Token::opLE:
517 >      match = propertyValue <= comparisonValue;
518 >      break;
519 >    case Token::opGE:
520 >      match = propertyValue >= comparisonValue;
521 >      break;
522 >    case Token::opGT:
523 >      match = propertyValue > comparisonValue;
524 >      break;
525 >    case Token::opEQ:
526 >      match = propertyValue == comparisonValue;
527 >      break;
528 >    case Token::opNE:
529 >      match = propertyValue != comparisonValue;
530 >      break;
531 >    }
532 >    if (match)
533 >      bs.setBitOn(sd->getGlobalIndex());
534 >
535      
536 +  }
537 +
538 +  void SelectionEvaluator::withinInstruction(const Token& instruction,
539 +                                             OpenMDBitSet& bs){
540 +    
541      boost::any withinSpec = instruction.value;
542      float distance;
543      if (withinSpec.type() == typeid(float)){
544 <        distance = boost::any_cast<float>(withinSpec);
544 >      distance = boost::any_cast<float>(withinSpec);
545      } else if (withinSpec.type() == typeid(int)) {
546 <        distance = boost::any_cast<int>(withinSpec);    
546 >      distance = boost::any_cast<int>(withinSpec);    
547      } else {
548 <        evalError("casting error in withinInstruction");
549 <        bs.clearAll();
548 >      evalError("casting error in withinInstruction");
549 >      bs.clearAll();
550      }
551      
552      bs = distanceFinder.find(bs, distance);            
553 < }
553 >  }
554  
555 < void SelectionEvaluator::define() {
555 >  void SelectionEvaluator::withinInstruction(const Token& instruction,
556 >                                             OpenMDBitSet& bs, int frame){
557 >    
558 >    boost::any withinSpec = instruction.value;
559 >    float distance;
560 >    if (withinSpec.type() == typeid(float)){
561 >      distance = boost::any_cast<float>(withinSpec);
562 >    } else if (withinSpec.type() == typeid(int)) {
563 >      distance = boost::any_cast<int>(withinSpec);    
564 >    } else {
565 >      evalError("casting error in withinInstruction");
566 >      bs.clearAll();
567 >    }
568 >    
569 >    bs = distanceFinder.find(bs, distance, frame);            
570 >  }
571 >  
572 >  void SelectionEvaluator::define() {
573      assert(statement.size() >= 3);
574 <
574 >    
575      std::string variable = boost::any_cast<std::string>(statement[1].value);
576 +    
577 +    variables.insert(VariablesType::value_type(variable,
578 +                                               expression(statement, 2)));
579 +  }
580 +  
581  
582 <    variables.insert(VariablesType::value_type(variable, expression(statement, 2)));
583 < }
584 <
308 <
309 < /** @todo */
310 < void SelectionEvaluator::predefine(const std::string& script) {
311 <
582 >  /** @todo */
583 >  void SelectionEvaluator::predefine(const std::string& script) {
584 >    
585      if (compiler.compile("#predefine", script)) {
586 <        std::vector<std::vector<Token> > aatoken = compiler.getAatokenCompiled();
587 <        if (aatoken.size() != 1) {
588 <            evalError("predefinition does not have exactly 1 command:"
589 <                + script);
590 <            return;
591 <        }
592 <        std::vector<Token> statement = aatoken[0];
593 <        if (statement.size() > 2) {
594 <            int tok = statement[1].tok;
595 <            if (tok == Token::identifier || (tok & Token::predefinedset) == Token::predefinedset) {
596 <                std::string variable = boost::any_cast<std::string>(statement[1].value);
597 <                variables.insert(VariablesType::value_type(variable, statement));
598 <
599 <            } else {
600 <                evalError("invalid variable name:" + script);
601 <            }
602 <        }else {
603 <            evalError("bad predefinition length:" + script);
604 <        }
605 <
586 >      std::vector<std::vector<Token> > aatoken = compiler.getAatokenCompiled();
587 >      if (aatoken.size() != 1) {
588 >        evalError("predefinition does not have exactly 1 command:"
589 >                  + script);
590 >        return;
591 >      }
592 >      std::vector<Token> statement = aatoken[0];
593 >      if (statement.size() > 2) {
594 >        int tok = statement[1].tok;
595 >        if (tok == Token::identifier ||
596 >            (tok & Token::predefinedset) == Token::predefinedset) {
597 >          std::string variable = boost::any_cast<std::string>(statement[1].value);
598 >          variables.insert(VariablesType::value_type(variable, statement));
599 >          
600 >        } else {
601 >          evalError("invalid variable name:" + script);
602 >        }
603 >      }else {
604 >        evalError("bad predefinition length:" + script);
605 >      }      
606          
607      } else {
608 <        evalError("predefined set compile error:" + script +
609 <          "\ncompile error:" + compiler.getErrorMessage());
608 >      evalError("predefined set compile error:" + script +
609 >                "\ncompile error:" + compiler.getErrorMessage());
610      }
611 +  }
612  
613 < }
340 <
341 < void SelectionEvaluator::select(BitSet& bs){
613 >  void SelectionEvaluator::select(OpenMDBitSet& bs){
614      bs = expression(statement, 1);
615 < }
615 >  }
616  
617 < BitSet SelectionEvaluator::lookupValue(const std::string& variable){
618 <
619 <    BitSet bs(nStuntDouble);
617 >  void SelectionEvaluator::select(OpenMDBitSet& bs, int frame){
618 >    bs = expression(statement, 1, frame);
619 >  }
620 >  
621 >  OpenMDBitSet SelectionEvaluator::lookupValue(const std::string& variable){
622 >    
623 >    OpenMDBitSet bs(nStuntDouble);
624      std::map<std::string, boost::any>::iterator i = variables.find(variable);
625      
626      if (i != variables.end()) {
627 <        if (i->second.type() == typeid(BitSet)) {
628 <            return boost::any_cast<BitSet>(i->second);
629 <        } else if (i->second.type() ==  typeid(std::vector<Token>)){
630 <            bs = expression(boost::any_cast<std::vector<Token> >(i->second), 2);
631 <            i->second =  bs; /**@todo fixme */
632 <            return bs;
633 <        }
627 >      if (i->second.type() == typeid(OpenMDBitSet)) {
628 >        return boost::any_cast<OpenMDBitSet>(i->second);
629 >      } else if (i->second.type() ==  typeid(std::vector<Token>)){
630 >        bs = expression(boost::any_cast<std::vector<Token> >(i->second), 2);
631 >        i->second =  bs; /**@todo fixme */
632 >        return bs;
633 >      }
634      } else {
635 <        unrecognizedIdentifier(variable);
635 >      unrecognizedIdentifier(variable);
636      }
637 <
637 >    
638      return bs;
639 < }
639 >  }
640 >  
641 >  OpenMDBitSet SelectionEvaluator::nameInstruction(const std::string& name){    
642 >    return nameFinder.match(name);    
643 >  }    
644  
645 < BitSet SelectionEvaluator::nameInstruction(const std::string& name){
366 <    
367 <    return nameFinder.match(name);
368 <
369 < }    
370 <
371 < bool SelectionEvaluator::containDynamicToken(const std::vector<Token>& tokens){
645 >  bool SelectionEvaluator::containDynamicToken(const std::vector<Token>& tokens){
646      std::vector<Token>::const_iterator i;
647      for (i = tokens.begin(); i != tokens.end(); ++i) {
648 <        if (i->tok & Token::dynamic) {
649 <            return true;
650 <        }
648 >      if (i->tok & Token::dynamic) {
649 >        return true;
650 >      }
651      }
652 <
652 >    
653      return false;
654 < }    
654 >  }    
655  
656 < void SelectionEvaluator::clearDefinitionsAndLoadPredefined() {
656 >  void SelectionEvaluator::clearDefinitionsAndLoadPredefined() {
657      variables.clear();
658      //load predefine
659      //predefine();
660 < }
660 >  }
661  
662 < BitSet SelectionEvaluator::evaluate() {
663 <    BitSet bs(nStuntDouble);
662 >  OpenMDBitSet SelectionEvaluator::evaluate() {
663 >    OpenMDBitSet bs(nStuntDouble);
664      if (isLoaded_) {
665 <        pc = 0;
666 <        instructionDispatchLoop(bs);
665 >      pc = 0;
666 >      instructionDispatchLoop(bs);
667      }
668 +    return bs;
669 +  }
670  
671 +  OpenMDBitSet SelectionEvaluator::evaluate(int frame) {
672 +    OpenMDBitSet bs(nStuntDouble);
673 +    if (isLoaded_) {
674 +      pc = 0;
675 +      instructionDispatchLoop(bs, frame);
676 +    }
677      return bs;
678 < }
678 >  }
679  
680 < BitSet SelectionEvaluator::indexInstruction(const boost::any& value) {
681 <    BitSet bs(nStuntDouble);
680 >  OpenMDBitSet SelectionEvaluator::indexInstruction(const boost::any& value) {
681 >    OpenMDBitSet bs(nStuntDouble);
682  
683      if (value.type() == typeid(int)) {
684 <        int index = boost::any_cast<int>(value);
685 <        if (index < 0 || index >= bs.size()) {
686 <            invalidIndex(index);
687 <        } else {
688 <            indexFinder.find(index);
689 <        }
684 >      int index = boost::any_cast<int>(value);
685 >      if (index < 0 || index >= bs.size()) {
686 >        invalidIndex(index);
687 >      } else {
688 >        bs = indexFinder.find(index);
689 >      }
690      } else if (value.type() == typeid(std::pair<int, int>)) {
691 <        std::pair<int, int> indexRange= boost::any_cast<std::pair<int, int> >(value);
692 <        assert(indexRange.first <= indexRange.second);
693 <        if (indexRange.first < 0 || indexRange.second >= bs.size()) {
694 <            invalidIndexRange(indexRange);
695 <        }else {
696 <            indexFinder.find(indexRange.first, indexRange.second);
697 <        }
691 >      std::pair<int, int> indexRange= boost::any_cast<std::pair<int, int> >(value);
692 >      assert(indexRange.first <= indexRange.second);
693 >      if (indexRange.first < 0 || indexRange.second >= bs.size()) {
694 >        invalidIndexRange(indexRange);
695 >      }else {
696 >        bs = indexFinder.find(indexRange.first, indexRange.second);
697 >      }
698      }
699  
700      return bs;
701 < }
701 >  }
702  
703 +  OpenMDBitSet SelectionEvaluator::allInstruction() {
704 +    OpenMDBitSet bs(nStuntDouble);
705 +
706 +    SimInfo::MoleculeIterator mi;
707 +    Molecule* mol;
708 +    Molecule::AtomIterator ai;
709 +    Atom* atom;
710 +    Molecule::RigidBodyIterator rbIter;
711 +    RigidBody* rb;
712 +
713 +    // Doing the loop insures that we're actually on this processor.
714 +
715 +    for (mol = info->beginMolecule(mi); mol != NULL;
716 +         mol = info->nextMolecule(mi)) {
717 +
718 +      for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
719 +        bs.setBitOn(atom->getGlobalIndex());
720 +      }
721 +    
722 +      for (rb = mol->beginRigidBody(rbIter); rb != NULL;
723 +           rb = mol->nextRigidBody(rbIter)) {
724 +        bs.setBitOn(rb->getGlobalIndex());
725 +      }
726 +    }
727 +
728 +    return bs;
729 +  }
730 +
731 +  OpenMDBitSet SelectionEvaluator::hull() {
732 +    OpenMDBitSet bs(nStuntDouble);
733 +    
734 +    bs = hullFinder.findHull();
735 +    surfaceArea_ = hullFinder.getSurfaceArea();
736 +    hasSurfaceArea_ = true;
737 +    return bs;
738 +  }
739 +
740 +
741 +  OpenMDBitSet SelectionEvaluator::hull(int frame) {
742 +    OpenMDBitSet bs(nStuntDouble);
743 +    
744 +    bs = hullFinder.findHull(frame);
745 +
746 +    return bs;
747 +  }
748 +
749 +  RealType SelectionEvaluator::getCharge(Atom* atom) {
750 +    RealType charge = 0.0;
751 +    AtomType* atomType = atom->getAtomType();
752 +
753 +    FixedChargeAdapter fca = FixedChargeAdapter(atomType);
754 +    if ( fca.isFixedCharge() ) {
755 +      charge = fca.getCharge();
756 +    }
757 +    
758 +    FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atomType);
759 +    if ( fqa.isFluctuatingCharge() ) {
760 +      charge += atom->getFlucQPos();
761 +    }
762 +    return charge;
763 +  }
764 +
765 +  RealType SelectionEvaluator::getCharge(Atom* atom, int frame) {
766 +    RealType charge = 0.0;
767 +    AtomType* atomType = atom->getAtomType();    
768 +
769 +    FixedChargeAdapter fca = FixedChargeAdapter(atomType);
770 +    if ( fca.isFixedCharge() ) {
771 +      charge = fca.getCharge();
772 +    }
773 +    
774 +    FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atomType);
775 +    if ( fqa.isFluctuatingCharge() ) {
776 +      charge += atom->getFlucQPos(frame);
777 +    }
778 +    return charge;
779 +  }
780 +
781   }

Comparing trunk/src/selection/SelectionEvaluator.cpp (property svn:keywords):
Revision 413 by tim, Wed Mar 9 17:30:29 2005 UTC vs.
Revision 1931 by gezelter, Mon Aug 19 19:20:32 2013 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines