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 507 by gezelter, Fri Apr 15 22:04:00 2005 UTC vs.
Revision 1801 by gezelter, Mon Oct 1 18:21:15 2012 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, 24107 (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  
51 < namespace oopse {
51 > namespace OpenMD {
52  
53  
54    SelectionEvaluator::SelectionEvaluator(SimInfo* si)
55 <    : info(si), nameFinder(info), distanceFinder(info), indexFinder(info), isLoaded_(false){
56 <    
57 <      nStuntDouble = info->getNGlobalAtoms() + info->getNRigidBodies();
55 >    : info(si), nameFinder(info), distanceFinder(info), hullFinder(info),
56 >      indexFinder(info),
57 >      isLoaded_(false){    
58 >      nStuntDouble = info->getNGlobalAtoms() + info->getNGlobalRigidBodies();
59      }            
60  
61 <  bool SelectionEvaluator::loadScript(const std::string& filename, const std::string& script) {
61 >  bool SelectionEvaluator::loadScript(const std::string& filename,
62 >                                      const std::string& script) {
63      clearDefinitionsAndLoadPredefined();
64      this->filename = filename;
65      this->script = script;
66      if (! compiler.compile(filename, script)) {
67        error = true;
68        errorMessage = compiler.getErrorMessage();
69 <      std::cerr << "SelectionCompiler Error: " << errorMessage << std::endl;
69 >
70 >      sprintf( painCave.errMsg,
71 >               "SelectionCompiler Error: %s\n", errorMessage.c_str());
72 >      painCave.severity = OPENMD_ERROR;
73 >      painCave.isFatal = 1;
74 >      simError();
75        return false;
76      }
77  
# Line 100 | Line 109 | namespace oopse {
109      return loadScriptFileInternal(filename);
110    }
111  
112 <  bool SelectionEvaluator::loadScriptFileInternal(const  std::string & filename) {
113 <    std::ifstream ifs(filename.c_str());
112 >  bool SelectionEvaluator::loadScriptFileInternal(const std::string & filename) {
113 >    ifstrstream ifs(filename.c_str());
114      if (!ifs.is_open()) {
115        return false;
116      }
117 <
117 >    
118      const int bufferSize = 65535;
119      char buffer[bufferSize];
120      std::string script;
# Line 114 | Line 123 | namespace oopse {
123      }
124      return loadScript(filename, script);
125    }
126 <
127 <  void SelectionEvaluator::instructionDispatchLoop(BitSet& bs){
126 >  
127 >  void SelectionEvaluator::instructionDispatchLoop(OpenMDBitSet& bs){
128      
129      while ( pc < aatoken.size()) {
130        statement = aatoken[pc++];
# Line 136 | Line 145 | namespace oopse {
145  
146    }
147  
148 <  BitSet SelectionEvaluator::expression(const std::vector<Token>& code, int pcStart) {
149 <    BitSet bs;
150 <    std::stack<BitSet> stack;
151 <    
152 <    for (int pc = pcStart; pc < code.size(); ++pc) {
148 >  OpenMDBitSet SelectionEvaluator::expression(const std::vector<Token>& code,
149 >                                             int pcStart) {
150 >    OpenMDBitSet bs;
151 >    std::stack<OpenMDBitSet> stack;
152 >  
153 >    for (unsigned int pc = pcStart; pc < code.size(); ++pc) {
154        Token instruction = code[pc];
155  
156        switch (instruction.tok) {
# Line 149 | Line 159 | namespace oopse {
159        case Token::expressionEnd:
160          break;
161        case Token::all:
162 <        bs = BitSet(nStuntDouble);
153 <        bs.setAll();
162 >        bs = allInstruction();
163          stack.push(bs);            
164          break;
165        case Token::none:
166 <        bs = BitSet(nStuntDouble);
166 >        bs = OpenMDBitSet(nStuntDouble);
167          stack.push(bs);            
168          break;
169        case Token::opOr:
# Line 171 | Line 180 | namespace oopse {
180          stack.top().flip();
181          break;
182        case Token::within:
174
183          withinInstruction(instruction, stack.top());
184          break;
185 +      case Token::hull:
186 +        stack.push(hull());
187 +        break;
188          //case Token::selected:
189          //  stack.push(getSelectionSet());
190          //  break;
# Line 206 | Line 217 | namespace oopse {
217  
218  
219  
220 <  BitSet SelectionEvaluator::comparatorInstruction(const Token& instruction) {
220 >  OpenMDBitSet SelectionEvaluator::comparatorInstruction(const Token& instruction) {
221      int comparator = instruction.tok;
222      int property = instruction.intValue;
223      float comparisonValue = boost::any_cast<float>(instruction.value);
224 <    float propertyValue;
214 <    BitSet bs(nStuntDouble);
224 >    OpenMDBitSet bs(nStuntDouble);
225      bs.clearAll();
226      
227      SimInfo::MoleculeIterator mi;
# Line 220 | Line 230 | namespace oopse {
230      Atom* atom;
231      Molecule::RigidBodyIterator rbIter;
232      RigidBody* rb;
223    
224    for (mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) {
233  
234 +    for (mol = info->beginMolecule(mi); mol != NULL;
235 +         mol = info->nextMolecule(mi)) {
236 +
237        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
238          compareProperty(atom, bs, property, comparator, comparisonValue);
239        }
240 <        
241 <      for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
242 <        compareProperty(rb, bs, property, comparator, comparisonValue);
243 <      }        
240 >    
241 >      for (rb = mol->beginRigidBody(rbIter); rb != NULL;
242 >           rb = mol->nextRigidBody(rbIter)) {
243 >        compareProperty(rb, bs, property, comparator, comparisonValue);
244 >      }
245      }
246  
247      return bs;
248    }
249  
250 <  void SelectionEvaluator::compareProperty(StuntDouble* sd, BitSet& bs, int property, int comparator, float comparisonValue) {
251 <    double propertyValue = 0.0;
250 >  void SelectionEvaluator::compareProperty(StuntDouble* sd, OpenMDBitSet& bs,
251 >                                           int property, int comparator,
252 >                                           float comparisonValue) {
253 >    RealType propertyValue = 0.0;
254      switch (property) {
255      case Token::mass:
256        propertyValue = sd->getMass();
# Line 253 | Line 267 | namespace oopse {
267            propertyValue+=  getCharge(atom);
268          }
269        }
270 +      break;
271 +    case Token::x:
272 +      propertyValue = sd->getPos().x();
273 +      break;
274 +    case Token::y:
275 +      propertyValue = sd->getPos().y();
276 +      break;
277 +    case Token::z:
278 +      propertyValue = sd->getPos().z();
279 +      break;
280 +    case Token::r:
281 +      propertyValue = sd->getPos().length();
282        break;
283      default:
284        unrecognizedAtomProperty(property);
# Line 281 | Line 307 | namespace oopse {
307      }
308      if (match)
309        bs.setBitOn(sd->getGlobalIndex());
310 <
310 >    
311    }
312  
313 <  void SelectionEvaluator::withinInstruction(const Token& instruction, BitSet& bs){
313 >  void SelectionEvaluator::withinInstruction(const Token& instruction,
314 >                                             OpenMDBitSet& bs){
315      
316      boost::any withinSpec = instruction.value;
317      float distance;
# Line 299 | Line 326 | namespace oopse {
326      
327      bs = distanceFinder.find(bs, distance);            
328    }
329 <
329 >  
330    void SelectionEvaluator::define() {
331      assert(statement.size() >= 3);
332 <
332 >    
333      std::string variable = boost::any_cast<std::string>(statement[1].value);
334 <
335 <    variables.insert(VariablesType::value_type(variable, expression(statement, 2)));
334 >    
335 >    variables.insert(VariablesType::value_type(variable,
336 >                                               expression(statement, 2)));
337    }
338 +  
339  
311
340    /** @todo */
341    void SelectionEvaluator::predefine(const std::string& script) {
342 <
342 >    
343      if (compiler.compile("#predefine", script)) {
344        std::vector<std::vector<Token> > aatoken = compiler.getAatokenCompiled();
345        if (aatoken.size() != 1) {
# Line 322 | Line 350 | namespace oopse {
350        std::vector<Token> statement = aatoken[0];
351        if (statement.size() > 2) {
352          int tok = statement[1].tok;
353 <        if (tok == Token::identifier || (tok & Token::predefinedset) == Token::predefinedset) {
353 >        if (tok == Token::identifier ||
354 >            (tok & Token::predefinedset) == Token::predefinedset) {
355            std::string variable = boost::any_cast<std::string>(statement[1].value);
356            variables.insert(VariablesType::value_type(variable, statement));
357 <
357 >          
358          } else {
359            evalError("invalid variable name:" + script);
360          }
361        }else {
362          evalError("bad predefinition length:" + script);
363 <      }
335 <
363 >      }      
364          
365      } else {
366        evalError("predefined set compile error:" + script +
367                  "\ncompile error:" + compiler.getErrorMessage());
368      }
341
369    }
370  
371 <  void SelectionEvaluator::select(BitSet& bs){
371 >  void SelectionEvaluator::select(OpenMDBitSet& bs){
372      bs = expression(statement, 1);
373    }
374 <
375 <  BitSet SelectionEvaluator::lookupValue(const std::string& variable){
376 <
377 <    BitSet bs(nStuntDouble);
374 >  
375 >  OpenMDBitSet SelectionEvaluator::lookupValue(const std::string& variable){
376 >    
377 >    OpenMDBitSet bs(nStuntDouble);
378      std::map<std::string, boost::any>::iterator i = variables.find(variable);
379      
380      if (i != variables.end()) {
381 <      if (i->second.type() == typeid(BitSet)) {
382 <        return boost::any_cast<BitSet>(i->second);
381 >      if (i->second.type() == typeid(OpenMDBitSet)) {
382 >        return boost::any_cast<OpenMDBitSet>(i->second);
383        } else if (i->second.type() ==  typeid(std::vector<Token>)){
384          bs = expression(boost::any_cast<std::vector<Token> >(i->second), 2);
385          i->second =  bs; /**@todo fixme */
# Line 361 | Line 388 | namespace oopse {
388      } else {
389        unrecognizedIdentifier(variable);
390      }
391 <
391 >    
392      return bs;
393    }
394 <
395 <  BitSet SelectionEvaluator::nameInstruction(const std::string& name){
396 <    
370 <    return nameFinder.match(name);
371 <
394 >  
395 >  OpenMDBitSet SelectionEvaluator::nameInstruction(const std::string& name){    
396 >    return nameFinder.match(name);    
397    }    
398  
399    bool SelectionEvaluator::containDynamicToken(const std::vector<Token>& tokens){
# Line 378 | Line 403 | namespace oopse {
403          return true;
404        }
405      }
406 <
406 >    
407      return false;
408    }    
409  
# Line 388 | Line 413 | namespace oopse {
413      //predefine();
414    }
415  
416 <  BitSet SelectionEvaluator::evaluate() {
417 <    BitSet bs(nStuntDouble);
416 >  OpenMDBitSet SelectionEvaluator::evaluate() {
417 >    OpenMDBitSet bs(nStuntDouble);
418      if (isLoaded_) {
419        pc = 0;
420        instructionDispatchLoop(bs);
# Line 398 | Line 423 | namespace oopse {
423      return bs;
424    }
425  
426 <  BitSet SelectionEvaluator::indexInstruction(const boost::any& value) {
427 <    BitSet bs(nStuntDouble);
426 >  OpenMDBitSet SelectionEvaluator::indexInstruction(const boost::any& value) {
427 >    OpenMDBitSet bs(nStuntDouble);
428  
429      if (value.type() == typeid(int)) {
430        int index = boost::any_cast<int>(value);
# Line 421 | Line 446 | namespace oopse {
446      return bs;
447    }
448  
449 +  OpenMDBitSet SelectionEvaluator::allInstruction() {
450 +    OpenMDBitSet bs(nStuntDouble);
451  
452 <  double SelectionEvaluator::getCharge(Atom* atom) {
453 <    double charge =0.0;
452 >    SimInfo::MoleculeIterator mi;
453 >    Molecule* mol;
454 >    Molecule::AtomIterator ai;
455 >    Atom* atom;
456 >    Molecule::RigidBodyIterator rbIter;
457 >    RigidBody* rb;
458 >
459 >    // Doing the loop insures that we're actually on this processor.
460 >
461 >    for (mol = info->beginMolecule(mi); mol != NULL;
462 >         mol = info->nextMolecule(mi)) {
463 >
464 >      for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
465 >        bs.setBitOn(atom->getGlobalIndex());
466 >      }
467 >    
468 >      for (rb = mol->beginRigidBody(rbIter); rb != NULL;
469 >           rb = mol->nextRigidBody(rbIter)) {
470 >        bs.setBitOn(rb->getGlobalIndex());
471 >      }
472 >    }
473 >
474 >    return bs;
475 >  }
476 >
477 >  OpenMDBitSet SelectionEvaluator::hull() {
478 >    OpenMDBitSet bs(nStuntDouble);
479 >    
480 >    bs = hullFinder.findHull();
481 >    
482 >    return bs;
483 >  }
484 >
485 >  RealType SelectionEvaluator::getCharge(Atom* atom) {
486 >    RealType charge =0.0;
487      AtomType* atomType = atom->getAtomType();
488      if (atomType->isCharge()) {
489        GenericData* data = atomType->getPropertyByName("Charge");
# Line 436 | Line 496 | namespace oopse {
496          } else {
497            sprintf( painCave.errMsg,
498                     "Can not cast GenericData to DoubleGenericData\n");
499 <          painCave.severity = OOPSE_ERROR;
499 >          painCave.severity = OPENMD_ERROR;
500            painCave.isFatal = 1;
501            simError();          
502          }

Comparing trunk/src/selection/SelectionEvaluator.cpp (property svn:keywords):
Revision 507 by gezelter, Fri Apr 15 22:04:00 2005 UTC vs.
Revision 1801 by gezelter, Mon Oct 1 18:21:15 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines