| 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. | 
| 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]  Vardeman & Gezelter, in progress (2009). | 
| 40 |  | */ | 
| 41 |  |  | 
| 42 |  | #include <stack> | 
| 45 |  | #include "primitives/DirectionalAtom.hpp" | 
| 46 |  | #include "primitives/RigidBody.hpp" | 
| 47 |  | #include "primitives/Molecule.hpp" | 
| 48 | + | #include "io/basic_ifstrstream.hpp" | 
| 49 |  |  | 
| 50 | < | namespace oopse { | 
| 50 | > | namespace OpenMD { | 
| 51 |  |  | 
| 52 |  |  | 
| 53 |  | SelectionEvaluator::SelectionEvaluator(SimInfo* si) | 
| 54 | < | : info(si), nameFinder(info), distanceFinder(info), indexFinder(info), isLoaded_(false){ | 
| 55 | < |  | 
| 56 | < | nStuntDouble = info->getNGlobalAtoms() + info->getNRigidBodies(); | 
| 54 | > | : info(si), nameFinder(info), distanceFinder(info), hullFinder(info), | 
| 55 | > | indexFinder(info), | 
| 56 | > | isLoaded_(false){ | 
| 57 | > | nStuntDouble = info->getNGlobalAtoms() + info->getNGlobalRigidBodies(); | 
| 58 |  | } | 
| 59 |  |  | 
| 60 | < | bool SelectionEvaluator::loadScript(const std::string& filename, const std::string& script) { | 
| 60 | > | bool SelectionEvaluator::loadScript(const std::string& filename, | 
| 61 | > | const std::string& script) { | 
| 62 |  | clearDefinitionsAndLoadPredefined(); | 
| 63 |  | this->filename = filename; | 
| 64 |  | this->script = script; | 
| 65 |  | if (! compiler.compile(filename, script)) { | 
| 66 |  | error = true; | 
| 67 |  | errorMessage = compiler.getErrorMessage(); | 
| 68 | < | std::cerr << "SelectionCompiler Error: " << errorMessage << std::endl; | 
| 68 | > |  | 
| 69 | > | sprintf( painCave.errMsg, | 
| 70 | > | "SelectionCompiler Error: %s\n", errorMessage.c_str()); | 
| 71 | > | painCave.severity = OPENMD_ERROR; | 
| 72 | > | painCave.isFatal = 1; | 
| 73 | > | simError(); | 
| 74 |  | return false; | 
| 75 |  | } | 
| 76 |  |  | 
| 108 |  | return loadScriptFileInternal(filename); | 
| 109 |  | } | 
| 110 |  |  | 
| 111 | < | bool SelectionEvaluator::loadScriptFileInternal(const  std::string & filename) { | 
| 112 | < | std::ifstream ifs(filename.c_str()); | 
| 111 | > | bool SelectionEvaluator::loadScriptFileInternal(const std::string & filename) { | 
| 112 | > | ifstrstream ifs(filename.c_str()); | 
| 113 |  | if (!ifs.is_open()) { | 
| 114 |  | return false; | 
| 115 |  | } | 
| 116 | < |  | 
| 116 | > |  | 
| 117 |  | const int bufferSize = 65535; | 
| 118 |  | char buffer[bufferSize]; | 
| 119 |  | std::string script; | 
| 122 |  | } | 
| 123 |  | return loadScript(filename, script); | 
| 124 |  | } | 
| 125 | < |  | 
| 126 | < | void SelectionEvaluator::instructionDispatchLoop(BitSet& bs){ | 
| 125 | > |  | 
| 126 | > | void SelectionEvaluator::instructionDispatchLoop(OpenMDBitSet& bs){ | 
| 127 |  |  | 
| 128 |  | while ( pc < aatoken.size()) { | 
| 129 |  | statement = aatoken[pc++]; | 
| 144 |  |  | 
| 145 |  | } | 
| 146 |  |  | 
| 147 | < | BitSet SelectionEvaluator::expression(const std::vector<Token>& code, int pcStart) { | 
| 148 | < | BitSet bs; | 
| 149 | < | std::stack<BitSet> stack; | 
| 150 | < |  | 
| 147 | > | OpenMDBitSet SelectionEvaluator::expression(const std::vector<Token>& code, | 
| 148 | > | int pcStart) { | 
| 149 | > | OpenMDBitSet bs; | 
| 150 | > | std::stack<OpenMDBitSet> stack; | 
| 151 | > |  | 
| 152 |  | for (int pc = pcStart; pc < code.size(); ++pc) { | 
| 153 |  | Token instruction = code[pc]; | 
| 154 |  |  | 
| 158 |  | case Token::expressionEnd: | 
| 159 |  | break; | 
| 160 |  | case Token::all: | 
| 161 | < | bs = BitSet(nStuntDouble); | 
| 161 | > | bs = OpenMDBitSet(nStuntDouble); | 
| 162 |  | bs.setAll(); | 
| 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: | 
| 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; | 
| 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; | 
| 225 | < | BitSet bs(nStuntDouble); | 
| 225 | > | OpenMDBitSet bs(nStuntDouble); | 
| 226 |  | bs.clearAll(); | 
| 227 |  |  | 
| 228 |  | SimInfo::MoleculeIterator mi; | 
| 231 |  | Atom* atom; | 
| 232 |  | Molecule::RigidBodyIterator rbIter; | 
| 233 |  | RigidBody* rb; | 
| 223 | – |  | 
| 224 | – | for (mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) { | 
| 234 |  |  | 
| 235 | + | for (mol = info->beginMolecule(mi); mol != NULL; | 
| 236 | + | mol = info->nextMolecule(mi)) { | 
| 237 | + |  | 
| 238 |  | for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { | 
| 239 |  | compareProperty(atom, bs, property, comparator, comparisonValue); | 
| 240 |  | } | 
| 241 | < |  | 
| 242 | < | for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { | 
| 243 | < | compareProperty(rb, bs, property, comparator, comparisonValue); | 
| 244 | < | } | 
| 241 | > |  | 
| 242 | > | for (rb = mol->beginRigidBody(rbIter); rb != NULL; | 
| 243 | > | rb = mol->nextRigidBody(rbIter)) { | 
| 244 | > | compareProperty(rb, bs, property, comparator, comparisonValue); | 
| 245 | > | } | 
| 246 |  | } | 
| 247 |  |  | 
| 248 |  | return bs; | 
| 249 |  | } | 
| 250 |  |  | 
| 251 | < | void SelectionEvaluator::compareProperty(StuntDouble* sd, BitSet& bs, int property, int comparator, float comparisonValue) { | 
| 252 | < | double propertyValue = 0.0; | 
| 251 | > | void SelectionEvaluator::compareProperty(StuntDouble* sd, OpenMDBitSet& bs, | 
| 252 | > | int property, int comparator, | 
| 253 | > | float comparisonValue) { | 
| 254 | > | RealType propertyValue = 0.0; | 
| 255 |  | switch (property) { | 
| 256 |  | case Token::mass: | 
| 257 |  | propertyValue = sd->getMass(); | 
| 269 |  | } | 
| 270 |  | } | 
| 271 |  | break; | 
| 272 | + | case Token::x: | 
| 273 | + | propertyValue = sd->getPos().x(); | 
| 274 | + | break; | 
| 275 | + | case Token::y: | 
| 276 | + | propertyValue = sd->getPos().y(); | 
| 277 | + | break; | 
| 278 | + | case Token::z: | 
| 279 | + | propertyValue = sd->getPos().z(); | 
| 280 | + | break; | 
| 281 |  | default: | 
| 282 |  | unrecognizedAtomProperty(property); | 
| 283 |  | } | 
| 305 |  | } | 
| 306 |  | if (match) | 
| 307 |  | bs.setBitOn(sd->getGlobalIndex()); | 
| 308 | < |  | 
| 308 | > |  | 
| 309 |  | } | 
| 310 |  |  | 
| 311 | < | void SelectionEvaluator::withinInstruction(const Token& instruction, BitSet& bs){ | 
| 311 | > | void SelectionEvaluator::withinInstruction(const Token& instruction, | 
| 312 | > | OpenMDBitSet& bs){ | 
| 313 |  |  | 
| 314 |  | boost::any withinSpec = instruction.value; | 
| 315 |  | float distance; | 
| 324 |  |  | 
| 325 |  | bs = distanceFinder.find(bs, distance); | 
| 326 |  | } | 
| 327 | < |  | 
| 327 | > |  | 
| 328 |  | void SelectionEvaluator::define() { | 
| 329 |  | assert(statement.size() >= 3); | 
| 330 | < |  | 
| 330 | > |  | 
| 331 |  | std::string variable = boost::any_cast<std::string>(statement[1].value); | 
| 332 | < |  | 
| 333 | < | variables.insert(VariablesType::value_type(variable, expression(statement, 2))); | 
| 332 | > |  | 
| 333 | > | variables.insert(VariablesType::value_type(variable, | 
| 334 | > | expression(statement, 2))); | 
| 335 |  | } | 
| 336 | + |  | 
| 337 |  |  | 
| 311 | – |  | 
| 338 |  | /** @todo */ | 
| 339 |  | void SelectionEvaluator::predefine(const std::string& script) { | 
| 340 | < |  | 
| 340 | > |  | 
| 341 |  | if (compiler.compile("#predefine", script)) { | 
| 342 |  | std::vector<std::vector<Token> > aatoken = compiler.getAatokenCompiled(); | 
| 343 |  | if (aatoken.size() != 1) { | 
| 348 |  | std::vector<Token> statement = aatoken[0]; | 
| 349 |  | if (statement.size() > 2) { | 
| 350 |  | int tok = statement[1].tok; | 
| 351 | < | if (tok == Token::identifier || (tok & Token::predefinedset) == Token::predefinedset) { | 
| 351 | > | if (tok == Token::identifier || | 
| 352 | > | (tok & Token::predefinedset) == Token::predefinedset) { | 
| 353 |  | std::string variable = boost::any_cast<std::string>(statement[1].value); | 
| 354 |  | variables.insert(VariablesType::value_type(variable, statement)); | 
| 355 | < |  | 
| 355 | > |  | 
| 356 |  | } else { | 
| 357 |  | evalError("invalid variable name:" + script); | 
| 358 |  | } | 
| 359 |  | }else { | 
| 360 |  | evalError("bad predefinition length:" + script); | 
| 361 | < | } | 
| 335 | < |  | 
| 361 | > | } | 
| 362 |  |  | 
| 363 |  | } else { | 
| 364 |  | evalError("predefined set compile error:" + script + | 
| 365 |  | "\ncompile error:" + compiler.getErrorMessage()); | 
| 366 |  | } | 
| 341 | – |  | 
| 367 |  | } | 
| 368 |  |  | 
| 369 | < | void SelectionEvaluator::select(BitSet& bs){ | 
| 369 | > | void SelectionEvaluator::select(OpenMDBitSet& bs){ | 
| 370 |  | bs = expression(statement, 1); | 
| 371 |  | } | 
| 372 | < |  | 
| 373 | < | BitSet SelectionEvaluator::lookupValue(const std::string& variable){ | 
| 374 | < |  | 
| 375 | < | BitSet bs(nStuntDouble); | 
| 372 | > |  | 
| 373 | > | OpenMDBitSet SelectionEvaluator::lookupValue(const std::string& variable){ | 
| 374 | > |  | 
| 375 | > | OpenMDBitSet bs(nStuntDouble); | 
| 376 |  | std::map<std::string, boost::any>::iterator i = variables.find(variable); | 
| 377 |  |  | 
| 378 |  | if (i != variables.end()) { | 
| 379 | < | if (i->second.type() == typeid(BitSet)) { | 
| 380 | < | return boost::any_cast<BitSet>(i->second); | 
| 379 | > | if (i->second.type() == typeid(OpenMDBitSet)) { | 
| 380 | > | return boost::any_cast<OpenMDBitSet>(i->second); | 
| 381 |  | } else if (i->second.type() ==  typeid(std::vector<Token>)){ | 
| 382 |  | bs = expression(boost::any_cast<std::vector<Token> >(i->second), 2); | 
| 383 |  | i->second =  bs; /**@todo fixme */ | 
| 386 |  | } else { | 
| 387 |  | unrecognizedIdentifier(variable); | 
| 388 |  | } | 
| 389 | < |  | 
| 389 | > |  | 
| 390 |  | return bs; | 
| 391 |  | } | 
| 392 | < |  | 
| 393 | < | BitSet SelectionEvaluator::nameInstruction(const std::string& name){ | 
| 394 | < |  | 
| 370 | < | return nameFinder.match(name); | 
| 371 | < |  | 
| 392 | > |  | 
| 393 | > | OpenMDBitSet SelectionEvaluator::nameInstruction(const std::string& name){ | 
| 394 | > | return nameFinder.match(name); | 
| 395 |  | } | 
| 396 |  |  | 
| 397 |  | bool SelectionEvaluator::containDynamicToken(const std::vector<Token>& tokens){ | 
| 401 |  | return true; | 
| 402 |  | } | 
| 403 |  | } | 
| 404 | < |  | 
| 404 | > |  | 
| 405 |  | return false; | 
| 406 |  | } | 
| 407 |  |  | 
| 411 |  | //predefine(); | 
| 412 |  | } | 
| 413 |  |  | 
| 414 | < | BitSet SelectionEvaluator::evaluate() { | 
| 415 | < | BitSet bs(nStuntDouble); | 
| 414 | > | OpenMDBitSet SelectionEvaluator::evaluate() { | 
| 415 | > | OpenMDBitSet bs(nStuntDouble); | 
| 416 |  | if (isLoaded_) { | 
| 417 |  | pc = 0; | 
| 418 |  | instructionDispatchLoop(bs); | 
| 421 |  | return bs; | 
| 422 |  | } | 
| 423 |  |  | 
| 424 | < | BitSet SelectionEvaluator::indexInstruction(const boost::any& value) { | 
| 425 | < | BitSet bs(nStuntDouble); | 
| 424 | > | OpenMDBitSet SelectionEvaluator::indexInstruction(const boost::any& value) { | 
| 425 | > | OpenMDBitSet bs(nStuntDouble); | 
| 426 |  |  | 
| 427 |  | if (value.type() == typeid(int)) { | 
| 428 |  | int index = boost::any_cast<int>(value); | 
| 445 |  | } | 
| 446 |  |  | 
| 447 |  |  | 
| 448 | < | double SelectionEvaluator::getCharge(Atom* atom) { | 
| 449 | < | double charge =0.0; | 
| 448 | > | OpenMDBitSet SelectionEvaluator::hull() { | 
| 449 | > | OpenMDBitSet bs(nStuntDouble); | 
| 450 | > |  | 
| 451 | > | bs = hullFinder.findHull(); | 
| 452 | > |  | 
| 453 | > | return bs; | 
| 454 | > | } | 
| 455 | > |  | 
| 456 | > |  | 
| 457 | > |  | 
| 458 | > | RealType SelectionEvaluator::getCharge(Atom* atom) { | 
| 459 | > | RealType charge =0.0; | 
| 460 |  | AtomType* atomType = atom->getAtomType(); | 
| 461 |  | if (atomType->isCharge()) { | 
| 462 |  | GenericData* data = atomType->getPropertyByName("Charge"); | 
| 469 |  | } else { | 
| 470 |  | sprintf( painCave.errMsg, | 
| 471 |  | "Can not cast GenericData to DoubleGenericData\n"); | 
| 472 | < | painCave.severity = OOPSE_ERROR; | 
| 472 | > | painCave.severity = OPENMD_ERROR; | 
| 473 |  | painCave.isFatal = 1; | 
| 474 |  | simError(); | 
| 475 |  | } |