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

Comparing:
trunk/src/selection/SelectionEvaluator.cpp (file contents), Revision 1360 by cli2, Mon Sep 7 16:31:51 2009 UTC vs.
branches/development/src/selection/SelectionEvaluator.cpp (file contents), Revision 1665 by gezelter, Tue Nov 22 20:38:56 2011 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(OOPSEBitSet& 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 <  OOPSEBitSet SelectionEvaluator::expression(const std::vector<Token>& code, int pcStart) {
149 <    OOPSEBitSet bs;
150 <    std::stack<OOPSEBitSet> stack;
151 <    
148 >  OpenMDBitSet SelectionEvaluator::expression(const std::vector<Token>& code,
149 >                                             int pcStart) {
150 >    OpenMDBitSet bs;
151 >    std::stack<OpenMDBitSet> stack;
152 >  
153      for (int pc = pcStart; pc < code.size(); ++pc) {
154        Token instruction = code[pc];
155  
# Line 149 | Line 159 | namespace oopse {
159        case Token::expressionEnd:
160          break;
161        case Token::all:
162 <        bs = OOPSEBitSet(nStuntDouble);
162 >        bs = OpenMDBitSet(nStuntDouble);
163          bs.setAll();
164          stack.push(bs);            
165          break;
166        case Token::none:
167 <        bs = OOPSEBitSet(nStuntDouble);
167 >        bs = OpenMDBitSet(nStuntDouble);
168          stack.push(bs);            
169          break;
170        case Token::opOr:
# Line 171 | Line 181 | namespace oopse {
181          stack.top().flip();
182          break;
183        case Token::within:
174
184          withinInstruction(instruction, stack.top());
185          break;
186 +      case Token::hull:
187 +        stack.push(hull());
188 +        break;
189          //case Token::selected:
190          //  stack.push(getSelectionSet());
191          //  break;
# Line 206 | Line 218 | namespace oopse {
218  
219  
220  
221 <  OOPSEBitSet SelectionEvaluator::comparatorInstruction(const Token& instruction) {
221 >  OpenMDBitSet SelectionEvaluator::comparatorInstruction(const Token& instruction) {
222      int comparator = instruction.tok;
223      int property = instruction.intValue;
224      float comparisonValue = boost::any_cast<float>(instruction.value);
225      float propertyValue;
226 <    OOPSEBitSet bs(nStuntDouble);
226 >    OpenMDBitSet bs(nStuntDouble);
227      bs.clearAll();
228      
229      SimInfo::MoleculeIterator mi;
# Line 220 | Line 232 | namespace oopse {
232      Atom* atom;
233      Molecule::RigidBodyIterator rbIter;
234      RigidBody* rb;
223    
224    for (mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) {
235  
236 +    for (mol = info->beginMolecule(mi); mol != NULL;
237 +         mol = info->nextMolecule(mi)) {
238 +
239        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
240          compareProperty(atom, bs, property, comparator, comparisonValue);
241        }
242 <        
243 <      for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
244 <        compareProperty(rb, bs, property, comparator, comparisonValue);
245 <      }        
242 >    
243 >      for (rb = mol->beginRigidBody(rbIter); rb != NULL;
244 >           rb = mol->nextRigidBody(rbIter)) {
245 >        compareProperty(rb, bs, property, comparator, comparisonValue);
246 >      }
247      }
248  
249      return bs;
250    }
251  
252 <  void SelectionEvaluator::compareProperty(StuntDouble* sd, OOPSEBitSet& bs, int property, int comparator, float comparisonValue) {
252 >  void SelectionEvaluator::compareProperty(StuntDouble* sd, OpenMDBitSet& bs,
253 >                                           int property, int comparator,
254 >                                           float comparisonValue) {
255      RealType propertyValue = 0.0;
256      switch (property) {
257      case Token::mass:
# Line 263 | Line 279 | namespace oopse {
279      case Token::z:
280        propertyValue = sd->getPos().z();
281        break;
282 +    case Token::r:
283 +      propertyValue = sd->getPos().length();
284 +      break;
285      default:
286        unrecognizedAtomProperty(property);
287      }
# Line 290 | Line 309 | namespace oopse {
309      }
310      if (match)
311        bs.setBitOn(sd->getGlobalIndex());
312 <
312 >    
313    }
314  
315 <  void SelectionEvaluator::withinInstruction(const Token& instruction, OOPSEBitSet& bs){
315 >  void SelectionEvaluator::withinInstruction(const Token& instruction,
316 >                                             OpenMDBitSet& bs){
317      
318      boost::any withinSpec = instruction.value;
319      float distance;
# Line 308 | Line 328 | namespace oopse {
328      
329      bs = distanceFinder.find(bs, distance);            
330    }
331 <
331 >  
332    void SelectionEvaluator::define() {
333      assert(statement.size() >= 3);
334 <
334 >    
335      std::string variable = boost::any_cast<std::string>(statement[1].value);
336 <
337 <    variables.insert(VariablesType::value_type(variable, expression(statement, 2)));
336 >    
337 >    variables.insert(VariablesType::value_type(variable,
338 >                                               expression(statement, 2)));
339    }
340 +  
341  
320
342    /** @todo */
343    void SelectionEvaluator::predefine(const std::string& script) {
344 <
344 >    
345      if (compiler.compile("#predefine", script)) {
346        std::vector<std::vector<Token> > aatoken = compiler.getAatokenCompiled();
347        if (aatoken.size() != 1) {
# Line 331 | Line 352 | namespace oopse {
352        std::vector<Token> statement = aatoken[0];
353        if (statement.size() > 2) {
354          int tok = statement[1].tok;
355 <        if (tok == Token::identifier || (tok & Token::predefinedset) == Token::predefinedset) {
355 >        if (tok == Token::identifier ||
356 >            (tok & Token::predefinedset) == Token::predefinedset) {
357            std::string variable = boost::any_cast<std::string>(statement[1].value);
358            variables.insert(VariablesType::value_type(variable, statement));
359 <
359 >          
360          } else {
361            evalError("invalid variable name:" + script);
362          }
363        }else {
364          evalError("bad predefinition length:" + script);
365 <      }
344 <
365 >      }      
366          
367      } else {
368        evalError("predefined set compile error:" + script +
369                  "\ncompile error:" + compiler.getErrorMessage());
370      }
350
371    }
372  
373 <  void SelectionEvaluator::select(OOPSEBitSet& bs){
373 >  void SelectionEvaluator::select(OpenMDBitSet& bs){
374      bs = expression(statement, 1);
375    }
376 <
377 <  OOPSEBitSet SelectionEvaluator::lookupValue(const std::string& variable){
378 <
379 <    OOPSEBitSet bs(nStuntDouble);
376 >  
377 >  OpenMDBitSet SelectionEvaluator::lookupValue(const std::string& variable){
378 >    
379 >    OpenMDBitSet bs(nStuntDouble);
380      std::map<std::string, boost::any>::iterator i = variables.find(variable);
381      
382      if (i != variables.end()) {
383 <      if (i->second.type() == typeid(OOPSEBitSet)) {
384 <        return boost::any_cast<OOPSEBitSet>(i->second);
383 >      if (i->second.type() == typeid(OpenMDBitSet)) {
384 >        return boost::any_cast<OpenMDBitSet>(i->second);
385        } else if (i->second.type() ==  typeid(std::vector<Token>)){
386          bs = expression(boost::any_cast<std::vector<Token> >(i->second), 2);
387          i->second =  bs; /**@todo fixme */
# Line 370 | Line 390 | namespace oopse {
390      } else {
391        unrecognizedIdentifier(variable);
392      }
393 <
393 >    
394      return bs;
395    }
396 <
397 <  OOPSEBitSet SelectionEvaluator::nameInstruction(const std::string& name){
398 <    
379 <    return nameFinder.match(name);
380 <
396 >  
397 >  OpenMDBitSet SelectionEvaluator::nameInstruction(const std::string& name){    
398 >    return nameFinder.match(name);    
399    }    
400  
401    bool SelectionEvaluator::containDynamicToken(const std::vector<Token>& tokens){
# Line 387 | Line 405 | namespace oopse {
405          return true;
406        }
407      }
408 <
408 >    
409      return false;
410    }    
411  
# Line 397 | Line 415 | namespace oopse {
415      //predefine();
416    }
417  
418 <  OOPSEBitSet SelectionEvaluator::evaluate() {
419 <    OOPSEBitSet bs(nStuntDouble);
418 >  OpenMDBitSet SelectionEvaluator::evaluate() {
419 >    OpenMDBitSet bs(nStuntDouble);
420      if (isLoaded_) {
421        pc = 0;
422        instructionDispatchLoop(bs);
# Line 407 | Line 425 | namespace oopse {
425      return bs;
426    }
427  
428 <  OOPSEBitSet SelectionEvaluator::indexInstruction(const boost::any& value) {
429 <    OOPSEBitSet bs(nStuntDouble);
428 >  OpenMDBitSet SelectionEvaluator::indexInstruction(const boost::any& value) {
429 >    OpenMDBitSet bs(nStuntDouble);
430  
431      if (value.type() == typeid(int)) {
432        int index = boost::any_cast<int>(value);
# Line 431 | Line 449 | namespace oopse {
449    }
450  
451  
452 +  OpenMDBitSet SelectionEvaluator::hull() {
453 +    OpenMDBitSet bs(nStuntDouble);
454 +    
455 +    bs = hullFinder.findHull();
456 +    
457 +    return bs;
458 +  }
459 +
460 +
461 +
462    RealType SelectionEvaluator::getCharge(Atom* atom) {
463      RealType charge =0.0;
464      AtomType* atomType = atom->getAtomType();
# Line 445 | Line 473 | namespace oopse {
473          } else {
474            sprintf( painCave.errMsg,
475                     "Can not cast GenericData to DoubleGenericData\n");
476 <          painCave.severity = OOPSE_ERROR;
476 >          painCave.severity = OPENMD_ERROR;
477            painCave.isFatal = 1;
478            simError();          
479          }

Comparing:
trunk/src/selection/SelectionEvaluator.cpp (property svn:keywords), Revision 1360 by cli2, Mon Sep 7 16:31:51 2009 UTC vs.
branches/development/src/selection/SelectionEvaluator.cpp (property svn:keywords), Revision 1665 by gezelter, Tue Nov 22 20:38:56 2011 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines