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 2052 by gezelter, Fri Jan 9 19:06:35 2015 UTC vs.
Revision 2071 by gezelter, Sat Mar 7 21:41:51 2015 UTC

# Line 53 | Line 53 | namespace OpenMD {
53  
54   namespace OpenMD {
55  
56
56    SelectionEvaluator::SelectionEvaluator(SimInfo* si)
57      : info(si), nameFinder(info), distanceFinder(info), hullFinder(info),
58 <      indexFinder(info), hasSurfaceArea_(false),
60 <      isLoaded_(false){    
58 >      indexFinder(info), isLoaded_(false), hasSurfaceArea_(false) {
59      nObjects.push_back(info->getNGlobalAtoms() + info->getNGlobalRigidBodies());
60      nObjects.push_back(info->getNGlobalBonds());
61      nObjects.push_back(info->getNGlobalBends());
# Line 334 | Line 332 | namespace OpenMD {
332  
333      for (mol = info->beginMolecule(mi); mol != NULL;
334           mol = info->nextMolecule(mi)) {
335 +
336 +      compareProperty(mol, bs, property, comparator, comparisonValue);
337  
338        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
339          compareProperty(atom, bs, property, comparator, comparisonValue);
# Line 365 | Line 365 | namespace OpenMD {
365      for (mol = info->beginMolecule(mi); mol != NULL;
366           mol = info->nextMolecule(mi)) {
367  
368 +      compareProperty(mol, bs, property, comparator, comparisonValue, frame);
369 +
370        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
371          compareProperty(atom, bs, property, comparator, comparisonValue, frame);
372        }
# Line 460 | Line 462 | namespace OpenMD {
462      
463    }
464  
465 +  void SelectionEvaluator::compareProperty(Molecule* mol, SelectionSet& bs,
466 +                                           int property, int comparator,
467 +                                           float comparisonValue) {
468 +    RealType propertyValue = 0.0;
469 +    Vector3d pos;
470 +
471 +    switch (property) {
472 +    case Token::mass:
473 +      propertyValue = mol->getMass();
474 +      break;
475 +    case Token::charge:
476 +      {
477 +        Molecule::AtomIterator ai;
478 +        Atom* atom;
479 +        for (atom = mol->beginAtom(ai); atom != NULL;
480 +             atom = mol->nextAtom(ai)) {
481 +          propertyValue+=  getCharge(atom);
482 +        }
483 +      }
484 +      break;
485 +    case Token::x:
486 +      propertyValue = mol->getCom().x();
487 +      break;
488 +    case Token::y:
489 +      propertyValue = mol->getCom().y();
490 +      break;
491 +    case Token::z:
492 +      propertyValue = mol->getCom().z();
493 +      break;
494 +    case Token::wrappedX:    
495 +      pos = mol->getCom();
496 +      info->getSnapshotManager()->getCurrentSnapshot()->wrapVector(pos);
497 +      propertyValue = pos.x();
498 +      break;
499 +    case Token::wrappedY:
500 +      pos = mol->getCom();
501 +      info->getSnapshotManager()->getCurrentSnapshot()->wrapVector(pos);
502 +      propertyValue = pos.y();
503 +      break;
504 +    case Token::wrappedZ:
505 +      pos = mol->getCom();
506 +      info->getSnapshotManager()->getCurrentSnapshot()->wrapVector(pos);
507 +      propertyValue = pos.z();
508 +      break;
509 +    case Token::r:
510 +      propertyValue = mol->getCom().length();
511 +      break;
512 +    default:
513 +      unrecognizedMoleculeProperty(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 +    
538 +    if (match)
539 +      bs.bitsets_[MOLECULE].setBitOn(mol->getGlobalIndex());    
540 +  }
541 +
542 +  void SelectionEvaluator::compareProperty(Molecule* mol, SelectionSet& bs,
543 +                                           int property, int comparator,
544 +                                           float comparisonValue, int frame) {
545 +    RealType propertyValue = 0.0;
546 +    Vector3d pos;
547 +    switch (property) {
548 +    case Token::mass:
549 +      propertyValue = mol->getMass();
550 +      break;
551 +    case Token::charge:
552 +      {
553 +        Molecule::AtomIterator ai;
554 +        Atom* atom;
555 +        for (atom = mol->beginAtom(ai); atom != NULL;
556 +             atom = mol->nextAtom(ai)) {
557 +          propertyValue+=  getCharge(atom,frame);
558 +        }
559 +      }      
560 +      break;
561 +    case Token::x:
562 +      propertyValue = mol->getCom(frame).x();
563 +      break;
564 +    case Token::y:
565 +      propertyValue = mol->getCom(frame).y();
566 +      break;
567 +    case Token::z:
568 +      propertyValue = mol->getCom(frame).z();
569 +      break;
570 +    case Token::wrappedX:    
571 +      pos = mol->getCom(frame);
572 +      info->getSnapshotManager()->getSnapshot(frame)->wrapVector(pos);
573 +      propertyValue = pos.x();
574 +      break;
575 +    case Token::wrappedY:
576 +      pos = mol->getCom(frame);
577 +      info->getSnapshotManager()->getSnapshot(frame)->wrapVector(pos);
578 +      propertyValue = pos.y();
579 +      break;
580 +    case Token::wrappedZ:
581 +      pos = mol->getCom(frame);
582 +      info->getSnapshotManager()->getSnapshot(frame)->wrapVector(pos);
583 +      propertyValue = pos.z();
584 +      break;
585 +
586 +    case Token::r:
587 +      propertyValue = mol->getCom(frame).length();
588 +      break;
589 +    default:
590 +      unrecognizedMoleculeProperty(property);
591 +    }
592 +        
593 +    bool match = false;
594 +    switch (comparator) {
595 +    case Token::opLT:
596 +      match = propertyValue < comparisonValue;
597 +      break;
598 +    case Token::opLE:
599 +      match = propertyValue <= comparisonValue;
600 +      break;
601 +    case Token::opGE:
602 +      match = propertyValue >= comparisonValue;
603 +      break;
604 +    case Token::opGT:
605 +      match = propertyValue > comparisonValue;
606 +      break;
607 +    case Token::opEQ:
608 +      match = propertyValue == comparisonValue;
609 +      break;
610 +    case Token::opNE:
611 +      match = propertyValue != comparisonValue;
612 +      break;
613 +    }
614 +    if (match)
615 +      bs.bitsets_[MOLECULE].setBitOn(mol->getGlobalIndex());
616 +    
617 +    
618 +  }
619    void SelectionEvaluator::compareProperty(StuntDouble* sd, SelectionSet& bs,
620                                             int property, int comparator,
621                                             float comparisonValue, int frame) {
# Line 536 | Line 692 | namespace OpenMD {
692        break;
693      }
694      if (match)
695 <      bs.bitsets_[STUNTDOUBLE].setBitOn(sd->getGlobalIndex());
540 <
541 <    
695 >      bs.bitsets_[STUNTDOUBLE].setBitOn(sd->getGlobalIndex());    
696    }
697 <
697 >  
698 >  
699    void SelectionEvaluator::withinInstruction(const Token& instruction,
700                                               SelectionSet& bs){
701      

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines