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 1816 by gezelter, Fri Dec 7 18:33:33 2012 UTC vs.
Revision 1953 by gezelter, Thu Dec 5 18:19:26 2013 UTC

# Line 35 | Line 35
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).          
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   */
# Line 56 | Line 56 | namespace OpenMD {
56  
57    SelectionEvaluator::SelectionEvaluator(SimInfo* si)
58      : info(si), nameFinder(info), distanceFinder(info), hullFinder(info),
59 <      indexFinder(info),
59 >      indexFinder(info), hasSurfaceArea_(false),
60        isLoaded_(false){    
61 <      nStuntDouble = info->getNGlobalAtoms() + info->getNGlobalRigidBodies();
62 <    }            
63 <
61 >    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    bool SelectionEvaluator::loadScript(const std::string& filename,
69                                        const std::string& script) {
70      clearDefinitionsAndLoadPredefined();
# Line 127 | Line 131 | namespace OpenMD {
131      return loadScript(filename, script);
132    }
133    
134 <  void SelectionEvaluator::instructionDispatchLoop(OpenMDBitSet& bs){
134 >  void SelectionEvaluator::instructionDispatchLoop(SelectionSet& bs){
135      
136      while ( pc < aatoken.size()) {
137        statement = aatoken[pc++];
# Line 148 | Line 152 | namespace OpenMD {
152  
153    }
154  
155 <  void SelectionEvaluator::instructionDispatchLoop(OpenMDBitSet& bs, int frame){
155 >  void SelectionEvaluator::instructionDispatchLoop(SelectionSet& bs, int frame){
156      
157      while ( pc < aatoken.size()) {
158        statement = aatoken[pc++];
# Line 169 | Line 173 | namespace OpenMD {
173  
174    }
175  
176 <  OpenMDBitSet SelectionEvaluator::expression(const std::vector<Token>& code,
176 >  SelectionSet SelectionEvaluator::expression(const std::vector<Token>& code,
177                                               int pcStart) {
178 <    OpenMDBitSet bs;
179 <    std::stack<OpenMDBitSet> stack;
178 >    SelectionSet bs = createSelectionSets();
179 >    std::stack<SelectionSet> stack;
180 >    vector<int> bsSize = bs.size();
181    
182      for (unsigned int pc = pcStart; pc < code.size(); ++pc) {
183        Token instruction = code[pc];
# Line 184 | Line 189 | namespace OpenMD {
189          break;
190        case Token::all:
191          bs = allInstruction();
192 <        stack.push(bs);            
192 >        stack.push(bs);
193          break;
194        case Token::none:
195 <        bs = OpenMDBitSet(nStuntDouble);
196 <        stack.push(bs);            
195 >        bs = createSelectionSets();
196 >        stack.push(bs);
197          break;
198        case Token::opOr:
199 <        bs = stack.top();
200 <        stack.pop();
201 <        stack.top() |= bs;
199 >          bs= stack.top();
200 >          stack.pop();
201 >          stack.top() |= bs;
202          break;
203        case Token::opAnd:
204 <        bs = stack.top();
205 <        stack.pop();
206 <        stack.top() &= bs;
204 >          bs = stack.top();
205 >          stack.pop();
206 >          stack.top() &= bs;
207          break;
208        case Token::opNot:
209 <        stack.top().flip();
209 >          stack.top().flip();
210          break;
211        case Token::within:
212          withinInstruction(instruction, stack.top());
213          break;
214        case Token::hull:
215 <        stack.push(hull());
215 >          stack.push(hull());
216          break;
217          //case Token::selected:
218          //  stack.push(getSelectionSet());
219          //  break;
220        case Token::name:
221 <        stack.push(nameInstruction(boost::any_cast<std::string>(instruction.value)));
221 >          stack.push(nameInstruction(boost::any_cast<std::string>(instruction.value)));
222          break;
223        case Token::index:
224 <        stack.push(indexInstruction(instruction.value));
224 >          stack.push(indexInstruction(instruction.value));
225          break;
226        case Token::identifier:
227 <        stack.push(lookupValue(boost::any_cast<std::string>(instruction.value)));
227 >          stack.push(lookupValue(boost::any_cast<std::string>(instruction.value)));
228          break;
229        case Token::opLT:
230        case Token::opLE:
# Line 240 | Line 245 | namespace OpenMD {
245    }
246  
247  
248 <  OpenMDBitSet SelectionEvaluator::expression(const std::vector<Token>& code,
248 >  SelectionSet SelectionEvaluator::expression(const std::vector<Token>& code,
249                                                int pcStart, int frame) {
250 <    OpenMDBitSet bs;
251 <    std::stack<OpenMDBitSet> stack;
250 >    SelectionSet bs = createSelectionSets();
251 >    std::stack<SelectionSet> stack;
252    
253      for (unsigned int pc = pcStart; pc < code.size(); ++pc) {
254        Token instruction = code[pc];
# Line 258 | Line 263 | namespace OpenMD {
263          stack.push(bs);            
264          break;
265        case Token::none:
266 <        bs = OpenMDBitSet(nStuntDouble);
266 >        bs = SelectionSet(nObjects);
267          stack.push(bs);            
268          break;
269        case Token::opOr:
# Line 312 | Line 317 | namespace OpenMD {
317  
318  
319  
320 <  OpenMDBitSet SelectionEvaluator::comparatorInstruction(const Token& instruction) {
320 >  SelectionSet SelectionEvaluator::comparatorInstruction(const Token& instruction) {
321      int comparator = instruction.tok;
322      int property = instruction.intValue;
323      float comparisonValue = boost::any_cast<float>(instruction.value);
324 <    OpenMDBitSet bs(nStuntDouble);
324 >    SelectionSet bs = createSelectionSets();
325      bs.clearAll();
326      
327      SimInfo::MoleculeIterator mi;
# Line 342 | Line 347 | namespace OpenMD {
347      return bs;
348    }
349  
350 <  OpenMDBitSet SelectionEvaluator::comparatorInstruction(const Token& instruction, int frame) {
350 >  SelectionSet SelectionEvaluator::comparatorInstruction(const Token& instruction, int frame) {
351      int comparator = instruction.tok;
352      int property = instruction.intValue;
353      float comparisonValue = boost::any_cast<float>(instruction.value);
354 <    OpenMDBitSet bs(nStuntDouble);
354 >    SelectionSet bs = createSelectionSets();
355      bs.clearAll();
356      
357      SimInfo::MoleculeIterator mi;
# Line 372 | Line 377 | namespace OpenMD {
377      return bs;
378    }
379  
380 <  void SelectionEvaluator::compareProperty(StuntDouble* sd, OpenMDBitSet& bs,
380 >  void SelectionEvaluator::compareProperty(StuntDouble* sd, SelectionSet& bs,
381                                             int property, int comparator,
382                                             float comparisonValue) {
383      RealType propertyValue = 0.0;
384 +    Vector3d pos;
385 +
386      switch (property) {
387      case Token::mass:
388        propertyValue = sd->getMass();
# Line 402 | Line 409 | namespace OpenMD {
409      case Token::z:
410        propertyValue = sd->getPos().z();
411        break;
412 +    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      case Token::r:
428        propertyValue = sd->getPos().length();
429        break;
# Line 430 | Line 452 | namespace OpenMD {
452        match = propertyValue != comparisonValue;
453        break;
454      }
455 +
456      if (match)
457 <      bs.setBitOn(sd->getGlobalIndex());
457 >      bs.bitsets_[STUNTDOUBLE].setBitOn(sd->getGlobalIndex());
458  
459      
460    }
461  
462 <  void SelectionEvaluator::compareProperty(StuntDouble* sd, OpenMDBitSet& bs,
462 >  void SelectionEvaluator::compareProperty(StuntDouble* sd, SelectionSet& bs,
463                                             int property, int comparator,
464                                             float comparisonValue, int frame) {
465      RealType propertyValue = 0.0;
466 +    Vector3d pos;
467      switch (property) {
468      case Token::mass:
469        propertyValue = sd->getMass();
# Line 465 | Line 489 | namespace OpenMD {
489        break;
490      case Token::z:
491        propertyValue = sd->getPos(frame).z();
492 +      break;
493 +    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      case Token::r:
510        propertyValue = sd->getPos(frame).length();
511        break;
# Line 495 | Line 535 | namespace OpenMD {
535        break;
536      }
537      if (match)
538 <      bs.setBitOn(sd->getGlobalIndex());
538 >      bs.bitsets_[STUNTDOUBLE].setBitOn(sd->getGlobalIndex());
539  
540      
541    }
542  
543    void SelectionEvaluator::withinInstruction(const Token& instruction,
544 <                                             OpenMDBitSet& bs){
544 >                                             SelectionSet& bs){
545      
546      boost::any withinSpec = instruction.value;
547      float distance;
# Line 518 | Line 558 | namespace OpenMD {
558    }
559  
560    void SelectionEvaluator::withinInstruction(const Token& instruction,
561 <                                             OpenMDBitSet& bs, int frame){
561 >                                             SelectionSet& bs, int frame){
562      
563      boost::any withinSpec = instruction.value;
564      float distance;
# Line 575 | Line 615 | namespace OpenMD {
615      }
616    }
617  
618 <  void SelectionEvaluator::select(OpenMDBitSet& bs){
618 >  void SelectionEvaluator::select(SelectionSet& bs){
619      bs = expression(statement, 1);
620    }
621  
622 <  void SelectionEvaluator::select(OpenMDBitSet& bs, int frame){
622 >  void SelectionEvaluator::select(SelectionSet& bs, int frame){
623      bs = expression(statement, 1, frame);
624    }
625    
626 <  OpenMDBitSet SelectionEvaluator::lookupValue(const std::string& variable){
626 >  SelectionSet SelectionEvaluator::lookupValue(const std::string& variable){
627      
628 <    OpenMDBitSet bs(nStuntDouble);
628 >    SelectionSet bs = createSelectionSets();
629      std::map<std::string, boost::any>::iterator i = variables.find(variable);
630      
631      if (i != variables.end()) {
632 <      if (i->second.type() == typeid(OpenMDBitSet)) {
633 <        return boost::any_cast<OpenMDBitSet>(i->second);
632 >      if (i->second.type() == typeid(SelectionSet)) {
633 >        return boost::any_cast<SelectionSet>(i->second);
634        } 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 */
# Line 603 | Line 643 | namespace OpenMD {
643      return bs;
644    }
645    
646 <  OpenMDBitSet SelectionEvaluator::nameInstruction(const std::string& name){    
646 >  SelectionSet SelectionEvaluator::nameInstruction(const std::string& name){    
647      return nameFinder.match(name);    
648    }    
649  
# Line 624 | Line 664 | namespace OpenMD {
664      //predefine();
665    }
666  
667 <  OpenMDBitSet SelectionEvaluator::evaluate() {
668 <    OpenMDBitSet bs(nStuntDouble);
667 >  SelectionSet SelectionEvaluator::createSelectionSets() {
668 >    SelectionSet ss(nObjects);
669 >    return ss;
670 >  }
671 >
672 >  SelectionSet SelectionEvaluator::evaluate() {
673 >    SelectionSet bs = createSelectionSets();
674      if (isLoaded_) {
675        pc = 0;
676        instructionDispatchLoop(bs);
# Line 633 | Line 678 | namespace OpenMD {
678      return bs;
679    }
680  
681 <  OpenMDBitSet SelectionEvaluator::evaluate(int frame) {
682 <    OpenMDBitSet bs(nStuntDouble);
681 >  SelectionSet SelectionEvaluator::evaluate(int frame) {
682 >    SelectionSet bs = createSelectionSets();
683      if (isLoaded_) {
684        pc = 0;
685        instructionDispatchLoop(bs, frame);
# Line 642 | Line 687 | namespace OpenMD {
687      return bs;
688    }
689  
690 <  OpenMDBitSet SelectionEvaluator::indexInstruction(const boost::any& value) {
691 <    OpenMDBitSet bs(nStuntDouble);
690 >  SelectionSet SelectionEvaluator::indexInstruction(const boost::any& value) {
691 >    SelectionSet bs = createSelectionSets();
692  
693      if (value.type() == typeid(int)) {
694        int index = boost::any_cast<int>(value);
695 <      if (index < 0 || index >= bs.size()) {
695 >      if (index < 0 || index >= bs.bitsets_[STUNTDOUBLE].size()) {
696          invalidIndex(index);
697        } else {
698          bs = indexFinder.find(index);
# Line 655 | Line 700 | namespace OpenMD {
700      } else if (value.type() == typeid(std::pair<int, int>)) {
701        std::pair<int, int> indexRange= boost::any_cast<std::pair<int, int> >(value);
702        assert(indexRange.first <= indexRange.second);
703 <      if (indexRange.first < 0 || indexRange.second >= bs.size()) {
703 >      if (indexRange.first < 0 ||
704 >          indexRange.second >= bs.bitsets_[STUNTDOUBLE].size()) {
705          invalidIndexRange(indexRange);
706        }else {
707          bs = indexFinder.find(indexRange.first, indexRange.second);
# Line 665 | Line 711 | namespace OpenMD {
711      return bs;
712    }
713  
714 <  OpenMDBitSet SelectionEvaluator::allInstruction() {
715 <    OpenMDBitSet bs(nStuntDouble);
714 >  SelectionSet SelectionEvaluator::allInstruction() {
715 >    SelectionSet ss = createSelectionSets();
716  
717      SimInfo::MoleculeIterator mi;
672    Molecule* mol;
718      Molecule::AtomIterator ai;
674    Atom* atom;
719      Molecule::RigidBodyIterator rbIter;
720 +    Molecule::BondIterator bondIter;
721 +    Molecule::BendIterator bendIter;
722 +    Molecule::TorsionIterator torsionIter;
723 +    Molecule::InversionIterator inversionIter;
724 +
725 +    Molecule* mol;
726 +    Atom* atom;
727      RigidBody* rb;
728 +    Bond* bond;
729 +    Bend* bend;
730 +    Torsion* torsion;
731 +    Inversion* inversion;    
732  
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)) {
682
737        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
738 <        bs.setBitOn(atom->getGlobalIndex());
739 <      }
686 <    
738 >        ss.bitsets_[STUNTDOUBLE].setBitOn(atom->getGlobalIndex());
739 >      }    
740        for (rb = mol->beginRigidBody(rbIter); rb != NULL;
741             rb = mol->nextRigidBody(rbIter)) {
742 <        bs.setBitOn(rb->getGlobalIndex());
742 >        ss.bitsets_[STUNTDOUBLE].setBitOn(rb->getGlobalIndex());
743        }
744 +      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      }
761  
762 <    return bs;
762 >    return ss;
763    }
764  
765 <  OpenMDBitSet SelectionEvaluator::hull() {
766 <    OpenMDBitSet bs(nStuntDouble);
765 >  SelectionSet SelectionEvaluator::hull() {
766 >    SelectionSet bs = createSelectionSets();
767      
768      bs = hullFinder.findHull();
769 <    
769 >    surfaceArea_ = hullFinder.getSurfaceArea();
770 >    hasSurfaceArea_ = true;
771      return bs;
772    }
773  
774  
775 <  OpenMDBitSet SelectionEvaluator::hull(int frame) {
776 <    OpenMDBitSet bs(nStuntDouble);
775 >  SelectionSet SelectionEvaluator::hull(int frame) {
776 >    SelectionSet bs = createSelectionSets();
777      
778      bs = hullFinder.findHull(frame);
779 <    
779 >
780      return bs;
781    }
782  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines