--- trunk/src/selection/SelectionEvaluator.cpp 2005/12/02 15:38:03 770 +++ trunk/src/selection/SelectionEvaluator.cpp 2009/11/25 20:02:06 1390 @@ -6,19 +6,10 @@ * redistribute this software in source and binary code form, provided * that the following conditions are met: * - * 1. Acknowledgement of the program authors must be made in any - * publication of scientific results based in part on use of the - * program. An acceptable form of acknowledgement is citation of - * the article in which the program was described (Matthew - * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher - * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented - * Parallel Simulation Engine for Molecular Dynamics," - * J. Comput. Chem. 26, pp. 252-271 (2005)) - * - * 2. Redistributions of source code must retain the above copyright + * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - * 3. Redistributions in binary form must reproduce the above copyright + * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. @@ -37,6 +28,15 @@ * arising out of the use of or inability to use software, even if the * University of Notre Dame has been advised of the possibility of * such damages. + * + * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your + * research, please cite the appropriate papers when you publish your + * work. Good starting points are: + * + * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). + * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). + * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). + * [4] Vardeman & Gezelter, in progress (2009). */ #include @@ -45,24 +45,31 @@ #include "primitives/DirectionalAtom.hpp" #include "primitives/RigidBody.hpp" #include "primitives/Molecule.hpp" +#include "io/basic_ifstrstream.hpp" -namespace oopse { +namespace OpenMD { SelectionEvaluator::SelectionEvaluator(SimInfo* si) - : info(si), nameFinder(info), distanceFinder(info), indexFinder(info), isLoaded_(false){ - - nStuntDouble = info->getNGlobalAtoms() + info->getNRigidBodies(); + : info(si), nameFinder(info), distanceFinder(info), indexFinder(info), + isLoaded_(false){ + nStuntDouble = info->getNGlobalAtoms() + info->getNGlobalRigidBodies(); } - bool SelectionEvaluator::loadScript(const std::string& filename, const std::string& script) { + bool SelectionEvaluator::loadScript(const std::string& filename, + const std::string& script) { clearDefinitionsAndLoadPredefined(); this->filename = filename; this->script = script; if (! compiler.compile(filename, script)) { error = true; errorMessage = compiler.getErrorMessage(); - std::cerr << "SelectionCompiler Error: " << errorMessage << std::endl; + + sprintf( painCave.errMsg, + "SelectionCompiler Error: %s\n", errorMessage.c_str()); + painCave.severity = OPENMD_ERROR; + painCave.isFatal = 1; + simError(); return false; } @@ -100,12 +107,12 @@ namespace oopse { return loadScriptFileInternal(filename); } - bool SelectionEvaluator::loadScriptFileInternal(const std::string & filename) { - std::ifstream ifs(filename.c_str()); + bool SelectionEvaluator::loadScriptFileInternal(const std::string & filename) { + ifstrstream ifs(filename.c_str()); if (!ifs.is_open()) { return false; } - + const int bufferSize = 65535; char buffer[bufferSize]; std::string script; @@ -114,8 +121,8 @@ namespace oopse { } return loadScript(filename, script); } - - void SelectionEvaluator::instructionDispatchLoop(OOPSEBitSet& bs){ + + void SelectionEvaluator::instructionDispatchLoop(OpenMDBitSet& bs){ while ( pc < aatoken.size()) { statement = aatoken[pc++]; @@ -136,10 +143,11 @@ namespace oopse { } - OOPSEBitSet SelectionEvaluator::expression(const std::vector& code, int pcStart) { - OOPSEBitSet bs; - std::stack stack; - + OpenMDBitSet SelectionEvaluator::expression(const std::vector& code, + int pcStart) { + OpenMDBitSet bs; + std::stack stack; + for (int pc = pcStart; pc < code.size(); ++pc) { Token instruction = code[pc]; @@ -149,12 +157,12 @@ namespace oopse { case Token::expressionEnd: break; case Token::all: - bs = OOPSEBitSet(nStuntDouble); + bs = OpenMDBitSet(nStuntDouble); bs.setAll(); stack.push(bs); break; case Token::none: - bs = OOPSEBitSet(nStuntDouble); + bs = OpenMDBitSet(nStuntDouble); stack.push(bs); break; case Token::opOr: @@ -171,7 +179,6 @@ namespace oopse { stack.top().flip(); break; case Token::within: - withinInstruction(instruction, stack.top()); break; //case Token::selected: @@ -206,12 +213,12 @@ namespace oopse { - OOPSEBitSet SelectionEvaluator::comparatorInstruction(const Token& instruction) { + OpenMDBitSet SelectionEvaluator::comparatorInstruction(const Token& instruction) { int comparator = instruction.tok; int property = instruction.intValue; float comparisonValue = boost::any_cast(instruction.value); float propertyValue; - OOPSEBitSet bs(nStuntDouble); + OpenMDBitSet bs(nStuntDouble); bs.clearAll(); SimInfo::MoleculeIterator mi; @@ -220,23 +227,27 @@ namespace oopse { Atom* atom; Molecule::RigidBodyIterator rbIter; RigidBody* rb; - - for (mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) { + for (mol = info->beginMolecule(mi); mol != NULL; + mol = info->nextMolecule(mi)) { + for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { compareProperty(atom, bs, property, comparator, comparisonValue); } - - for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { - compareProperty(rb, bs, property, comparator, comparisonValue); - } + + for (rb = mol->beginRigidBody(rbIter); rb != NULL; + rb = mol->nextRigidBody(rbIter)) { + compareProperty(rb, bs, property, comparator, comparisonValue); + } } return bs; } - void SelectionEvaluator::compareProperty(StuntDouble* sd, OOPSEBitSet& bs, int property, int comparator, float comparisonValue) { - double propertyValue = 0.0; + void SelectionEvaluator::compareProperty(StuntDouble* sd, OpenMDBitSet& bs, + int property, int comparator, + float comparisonValue) { + RealType propertyValue = 0.0; switch (property) { case Token::mass: propertyValue = sd->getMass(); @@ -254,6 +265,15 @@ namespace oopse { } } break; + case Token::x: + propertyValue = sd->getPos().x(); + break; + case Token::y: + propertyValue = sd->getPos().y(); + break; + case Token::z: + propertyValue = sd->getPos().z(); + break; default: unrecognizedAtomProperty(property); } @@ -281,10 +301,11 @@ namespace oopse { } if (match) bs.setBitOn(sd->getGlobalIndex()); - + } - void SelectionEvaluator::withinInstruction(const Token& instruction, OOPSEBitSet& bs){ + void SelectionEvaluator::withinInstruction(const Token& instruction, + OpenMDBitSet& bs){ boost::any withinSpec = instruction.value; float distance; @@ -299,19 +320,20 @@ namespace oopse { bs = distanceFinder.find(bs, distance); } - + void SelectionEvaluator::define() { assert(statement.size() >= 3); - + std::string variable = boost::any_cast(statement[1].value); - - variables.insert(VariablesType::value_type(variable, expression(statement, 2))); + + variables.insert(VariablesType::value_type(variable, + expression(statement, 2))); } + - /** @todo */ void SelectionEvaluator::predefine(const std::string& script) { - + if (compiler.compile("#predefine", script)) { std::vector > aatoken = compiler.getAatokenCompiled(); if (aatoken.size() != 1) { @@ -322,37 +344,36 @@ namespace oopse { std::vector statement = aatoken[0]; if (statement.size() > 2) { int tok = statement[1].tok; - if (tok == Token::identifier || (tok & Token::predefinedset) == Token::predefinedset) { + if (tok == Token::identifier || + (tok & Token::predefinedset) == Token::predefinedset) { std::string variable = boost::any_cast(statement[1].value); variables.insert(VariablesType::value_type(variable, statement)); - + } else { evalError("invalid variable name:" + script); } }else { evalError("bad predefinition length:" + script); - } - + } } else { evalError("predefined set compile error:" + script + "\ncompile error:" + compiler.getErrorMessage()); } - } - void SelectionEvaluator::select(OOPSEBitSet& bs){ + void SelectionEvaluator::select(OpenMDBitSet& bs){ bs = expression(statement, 1); } - - OOPSEBitSet SelectionEvaluator::lookupValue(const std::string& variable){ - - OOPSEBitSet bs(nStuntDouble); + + OpenMDBitSet SelectionEvaluator::lookupValue(const std::string& variable){ + + OpenMDBitSet bs(nStuntDouble); std::map::iterator i = variables.find(variable); if (i != variables.end()) { - if (i->second.type() == typeid(OOPSEBitSet)) { - return boost::any_cast(i->second); + if (i->second.type() == typeid(OpenMDBitSet)) { + return boost::any_cast(i->second); } else if (i->second.type() == typeid(std::vector)){ bs = expression(boost::any_cast >(i->second), 2); i->second = bs; /**@todo fixme */ @@ -361,14 +382,12 @@ namespace oopse { } else { unrecognizedIdentifier(variable); } - + return bs; } - - OOPSEBitSet SelectionEvaluator::nameInstruction(const std::string& name){ - - return nameFinder.match(name); - + + OpenMDBitSet SelectionEvaluator::nameInstruction(const std::string& name){ + return nameFinder.match(name); } bool SelectionEvaluator::containDynamicToken(const std::vector& tokens){ @@ -378,7 +397,7 @@ namespace oopse { return true; } } - + return false; } @@ -388,8 +407,8 @@ namespace oopse { //predefine(); } - OOPSEBitSet SelectionEvaluator::evaluate() { - OOPSEBitSet bs(nStuntDouble); + OpenMDBitSet SelectionEvaluator::evaluate() { + OpenMDBitSet bs(nStuntDouble); if (isLoaded_) { pc = 0; instructionDispatchLoop(bs); @@ -398,8 +417,8 @@ namespace oopse { return bs; } - OOPSEBitSet SelectionEvaluator::indexInstruction(const boost::any& value) { - OOPSEBitSet bs(nStuntDouble); + OpenMDBitSet SelectionEvaluator::indexInstruction(const boost::any& value) { + OpenMDBitSet bs(nStuntDouble); if (value.type() == typeid(int)) { int index = boost::any_cast(value); @@ -422,8 +441,8 @@ namespace oopse { } - double SelectionEvaluator::getCharge(Atom* atom) { - double charge =0.0; + RealType SelectionEvaluator::getCharge(Atom* atom) { + RealType charge =0.0; AtomType* atomType = atom->getAtomType(); if (atomType->isCharge()) { GenericData* data = atomType->getPropertyByName("Charge"); @@ -436,7 +455,7 @@ namespace oopse { } else { sprintf( painCave.errMsg, "Can not cast GenericData to DoubleGenericData\n"); - painCave.severity = OOPSE_ERROR; + painCave.severity = OPENMD_ERROR; painCave.isFatal = 1; simError(); }