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 1953 by gezelter, Thu Dec 5 18:19:26 2013 UTC vs.
Revision 2055 by gezelter, Fri Feb 6 18:49:27 2015 UTC

# Line 63 | Line 63 | namespace OpenMD {
63      nObjects.push_back(info->getNGlobalBends());
64      nObjects.push_back(info->getNGlobalTorsions());
65      nObjects.push_back(info->getNGlobalInversions());
66 +    nObjects.push_back(info->getNGlobalMolecules());    
67    }
68    
69    bool SelectionEvaluator::loadScript(const std::string& filename,
# Line 334 | Line 335 | namespace OpenMD {
335      for (mol = info->beginMolecule(mi); mol != NULL;
336           mol = info->nextMolecule(mi)) {
337  
338 +      compareProperty(mol, bs, property, comparator, comparisonValue);
339 +
340        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
341          compareProperty(atom, bs, property, comparator, comparisonValue);
342        }
# Line 363 | Line 366 | namespace OpenMD {
366  
367      for (mol = info->beginMolecule(mi); mol != NULL;
368           mol = info->nextMolecule(mi)) {
369 +
370 +      compareProperty(mol, bs, property, comparator, comparisonValue, frame);
371  
372        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
373          compareProperty(atom, bs, property, comparator, comparisonValue, frame);
# Line 458 | Line 463 | namespace OpenMD {
463  
464      
465    }
466 +
467 +  void SelectionEvaluator::compareProperty(Molecule* mol, SelectionSet& bs,
468 +                                           int property, int comparator,
469 +                                           float comparisonValue) {
470 +    RealType propertyValue = 0.0;
471 +    Vector3d pos;
472  
473 +    switch (property) {
474 +    case Token::mass:
475 +      propertyValue = mol->getMass();
476 +      break;
477 +    case Token::charge:
478 +      {
479 +        Molecule::AtomIterator ai;
480 +        Atom* atom;
481 +        for (atom = mol->beginAtom(ai); atom != NULL;
482 +             atom = mol->nextAtom(ai)) {
483 +          propertyValue+=  getCharge(atom);
484 +        }
485 +      }
486 +      break;
487 +    case Token::x:
488 +      propertyValue = mol->getCom().x();
489 +      break;
490 +    case Token::y:
491 +      propertyValue = mol->getCom().y();
492 +      break;
493 +    case Token::z:
494 +      propertyValue = mol->getCom().z();
495 +      break;
496 +    case Token::wrappedX:    
497 +      pos = mol->getCom();
498 +      info->getSnapshotManager()->getCurrentSnapshot()->wrapVector(pos);
499 +      propertyValue = pos.x();
500 +      break;
501 +    case Token::wrappedY:
502 +      pos = mol->getCom();
503 +      info->getSnapshotManager()->getCurrentSnapshot()->wrapVector(pos);
504 +      propertyValue = pos.y();
505 +      break;
506 +    case Token::wrappedZ:
507 +      pos = mol->getCom();
508 +      info->getSnapshotManager()->getCurrentSnapshot()->wrapVector(pos);
509 +      propertyValue = pos.z();
510 +      break;
511 +    case Token::r:
512 +      propertyValue = mol->getCom().length();
513 +      break;
514 +    default:
515 +      unrecognizedMoleculeProperty(property);
516 +    }
517 +    
518 +    bool match = false;
519 +    switch (comparator) {
520 +    case Token::opLT:
521 +      match = propertyValue < comparisonValue;
522 +      break;
523 +    case Token::opLE:
524 +      match = propertyValue <= comparisonValue;
525 +      break;
526 +    case Token::opGE:
527 +      match = propertyValue >= comparisonValue;
528 +      break;
529 +    case Token::opGT:
530 +      match = propertyValue > comparisonValue;
531 +      break;
532 +    case Token::opEQ:
533 +      match = propertyValue == comparisonValue;
534 +      break;
535 +    case Token::opNE:
536 +      match = propertyValue != comparisonValue;
537 +      break;
538 +    }
539 +    
540 +    if (match)
541 +      bs.bitsets_[MOLECULE].setBitOn(mol->getGlobalIndex());    
542 +  }
543 +
544 +  void SelectionEvaluator::compareProperty(Molecule* mol, SelectionSet& bs,
545 +                                           int property, int comparator,
546 +                                           float comparisonValue, int frame) {
547 +    RealType propertyValue = 0.0;
548 +    Vector3d pos;
549 +    switch (property) {
550 +    case Token::mass:
551 +      propertyValue = mol->getMass();
552 +      break;
553 +    case Token::charge:
554 +      {
555 +        Molecule::AtomIterator ai;
556 +        Atom* atom;
557 +        for (atom = mol->beginAtom(ai); atom != NULL;
558 +             atom = mol->nextAtom(ai)) {
559 +          propertyValue+=  getCharge(atom,frame);
560 +        }
561 +      }      
562 +      break;
563 +    case Token::x:
564 +      propertyValue = mol->getCom(frame).x();
565 +      break;
566 +    case Token::y:
567 +      propertyValue = mol->getCom(frame).y();
568 +      break;
569 +    case Token::z:
570 +      propertyValue = mol->getCom(frame).z();
571 +      break;
572 +    case Token::wrappedX:    
573 +      pos = mol->getCom(frame);
574 +      info->getSnapshotManager()->getSnapshot(frame)->wrapVector(pos);
575 +      propertyValue = pos.x();
576 +      break;
577 +    case Token::wrappedY:
578 +      pos = mol->getCom(frame);
579 +      info->getSnapshotManager()->getSnapshot(frame)->wrapVector(pos);
580 +      propertyValue = pos.y();
581 +      break;
582 +    case Token::wrappedZ:
583 +      pos = mol->getCom(frame);
584 +      info->getSnapshotManager()->getSnapshot(frame)->wrapVector(pos);
585 +      propertyValue = pos.z();
586 +      break;
587 +
588 +    case Token::r:
589 +      propertyValue = mol->getCom(frame).length();
590 +      break;
591 +    default:
592 +      unrecognizedMoleculeProperty(property);
593 +    }
594 +        
595 +    bool match = false;
596 +    switch (comparator) {
597 +    case Token::opLT:
598 +      match = propertyValue < comparisonValue;
599 +      break;
600 +    case Token::opLE:
601 +      match = propertyValue <= comparisonValue;
602 +      break;
603 +    case Token::opGE:
604 +      match = propertyValue >= comparisonValue;
605 +      break;
606 +    case Token::opGT:
607 +      match = propertyValue > comparisonValue;
608 +      break;
609 +    case Token::opEQ:
610 +      match = propertyValue == comparisonValue;
611 +      break;
612 +    case Token::opNE:
613 +      match = propertyValue != comparisonValue;
614 +      break;
615 +    }
616 +    if (match)
617 +      bs.bitsets_[MOLECULE].setBitOn(mol->getGlobalIndex());
618 +    
619 +    
620 +  }
621    void SelectionEvaluator::compareProperty(StuntDouble* sd, SelectionSet& bs,
622                                             int property, int comparator,
623                                             float comparisonValue, int frame) {
# Line 540 | Line 699 | namespace OpenMD {
699      
700    }
701  
702 +  
703    void SelectionEvaluator::withinInstruction(const Token& instruction,
704                                               SelectionSet& bs){
705      
# Line 756 | Line 916 | namespace OpenMD {
916        for (inversion = mol->beginInversion(inversionIter); inversion != NULL;
917             inversion = mol->nextInversion(inversionIter)) {
918          ss.bitsets_[INVERSION].setBitOn(inversion->getGlobalIndex());
919 <      }  
919 >      }
920 >      ss.bitsets_[MOLECULE].setBitOn(mol->getGlobalIndex());
921      }
922  
923      return ss;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines