--- trunk/src/selection/SelectionEvaluator.hpp 2005/03/09 17:30:29 413 +++ trunk/src/selection/SelectionEvaluator.hpp 2012/10/01 18:21:15 1801 @@ -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,16 @@ * 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] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). + * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). */ #ifndef SELECTION_SELECTIONEVALUATOR_HPP @@ -48,153 +49,163 @@ #include #include "brains/SimInfo.hpp" -#include "selection/Token.hpp" +#include "selection/SelectionToken.hpp" #include "selection/SelectionCompiler.hpp" #include "selection/NameFinder.hpp" #include "selection/DistanceFinder.hpp" +#include "selection/HullFinder.hpp" #include "selection/IndexFinder.hpp" -#include "utils/BitSet.hpp" +#include "utils/OpenMDBitSet.hpp" #include "primitives/StuntDouble.hpp" #include "utils/StringUtils.hpp" -namespace oopse { +namespace OpenMD { -/** - * @class SelectionEvaluator SelectionEvaluator.hpp "selection/SelectionEvaluator" - * @brief Evalute the tokens compiled by SelectionCompiler and return a BitSet - */ -class SelectionEvaluator{ - public: + /** + * @class SelectionEvaluator SelectionEvaluator.hpp "selection/SelectionEvaluator" + * @brief Evalute the tokens compiled by SelectionCompiler and return a OpenMDBitSet + */ + class SelectionEvaluator{ + public: - SelectionEvaluator(SimInfo* info); + SelectionEvaluator(SimInfo* info); - - bool loadScriptString(const std::string& script); - bool loadScriptFile(const std::string& filename); + bool loadScriptString(const std::string& script); + bool loadScriptFile(const std::string& filename); - BitSet evaluate(); + OpenMDBitSet evaluate(); - /** - * Tests if the result from evaluation of script is dynamic. - */ - bool isDynamic() { - return isDynamic_; - } + /** + * Tests if the result from evaluation of script is dynamic. + */ + bool isDynamic() { + return isDynamic_; + } - bool hadRuntimeError() const{ - return error; - } + bool hadRuntimeError() const{ + return error; + } - std::string getErrorMessage() const { - return errorMessage; - } + std::string getErrorMessage() const { + return errorMessage; + } - int getLinenumber() { - return linenumbers[pc]; - } + int getLinenumber() { + return linenumbers[pc]; + } - std::string getLine() { - int ichBegin = lineIndices[pc]; - int ichEnd; - if ((ichEnd = script.find('\r', ichBegin)) == std::string::npos && - (ichEnd = script.find('\n', ichBegin)) == std::string::npos) { - ichEnd = script.size(); - } - return script.substr(ichBegin, ichEnd); - } + std::string getLine() { + int ichBegin = lineIndices[pc]; + int ichEnd; + if ((ichEnd = script.find('\r', ichBegin)) == std::string::npos && + (ichEnd = script.find('\n', ichBegin)) == std::string::npos) { + ichEnd = script.size(); + } + return script.substr(ichBegin, ichEnd); + } - private: + private: - void clearState(); + void clearState(); - bool loadScript(const std::string& filename, const std::string& script); + bool loadScript(const std::string& filename, const std::string& script); - bool loadScriptFileInternal(const std::string& filename); + bool loadScriptFileInternal(const std::string& filename); - void clearDefinitionsAndLoadPredefined(); + void clearDefinitionsAndLoadPredefined(); - void define(); - void select(BitSet& bs); - void predefine(const std::string& script); + void define(); + void select(OpenMDBitSet& bs); + void predefine(const std::string& script); - void instructionDispatchLoop(BitSet& bs); + void instructionDispatchLoop(OpenMDBitSet& bs); - void withinInstruction(const Token& instruction, BitSet& bs); + void withinInstruction(const Token& instruction, OpenMDBitSet& bs); + OpenMDBitSet allInstruction(); - BitSet comparatorInstruction(const Token& instruction); - void compareProperty(StuntDouble* sd, BitSet& bs, int property, int comparator, float comparisonValue); - BitSet nameInstruction(const std::string& name); - BitSet indexInstruction(const boost::any& value); - BitSet expression(const std::vector& tokens, int pc); + OpenMDBitSet comparatorInstruction(const Token& instruction); + void compareProperty(StuntDouble* sd, OpenMDBitSet& bs, int property, int comparator, float comparisonValue); + OpenMDBitSet nameInstruction(const std::string& name); + OpenMDBitSet indexInstruction(const boost::any& value); + OpenMDBitSet expression(const std::vector& tokens, int pc); - BitSet lookupValue(const std::string& variable); + OpenMDBitSet lookupValue(const std::string& variable); + + OpenMDBitSet hull(); - void evalError(const std::string& message) { - std::cerr << "SelectionEvaulator Error: " << message << std::endl; - } + void evalError(const std::string& message) { + sprintf( painCave.errMsg, + "SelectionEvaluator Error: %s\n", message.c_str()); + painCave.severity = OPENMD_ERROR; + painCave.isFatal = 1; + simError(); + } - void unrecognizedCommand(const Token& token) { - evalError("unrecognized command:" + boost::any_cast(token.value)); - } + void unrecognizedCommand(const Token& token) { + evalError("unrecognized command:" + boost::any_cast(token.value)); + } - void unrecognizedExpression() { - evalError("unrecognized expression"); - } + void unrecognizedExpression() { + evalError("unrecognized expression"); + } - void unrecognizedAtomProperty(int property){ - evalError("unrecognized atom property"); - } + void unrecognizedAtomProperty(int property){ + evalError("unrecognized atom property"); + } - void unrecognizedIdentifier(const std::string& identifier) { - evalError("unrecognized identifier:" + identifier); - } + void unrecognizedIdentifier(const std::string& identifier) { + evalError("unrecognized identifier:" + identifier); + } - void invalidIndexRange(std::pair range) { - evalError("invalid index range: [" + toString(range.first) + ", " + toString(range.second) + ")"); - } + void invalidIndexRange(std::pair range) { + evalError("invalid index range: [" + toString(range.first) + ", " + toString(range.second) + ")"); + } - void invalidIndex(int index) { - evalError("invalid index : " + toString(index) ); - } + void invalidIndex(int index) { + evalError("invalid index : " + toString(index) ); + } - bool containDynamicToken(const std::vector& tokens); + bool containDynamicToken(const std::vector& tokens); + + RealType getCharge(Atom* atom); - SelectionCompiler compiler; + SelectionCompiler compiler; - //const static int scriptLevelMax = 10; - //int scriptLevel; + //const static int scriptLevelMax = 10; + //int scriptLevel; - //Context stack[scriptLevelMax]; + //Context stack[scriptLevelMax]; - std::string filename; - std::string script; - std::vector linenumbers; - std::vector lineIndices; - std::vector > aatoken; - int pc; // program counter + std::string filename; + std::string script; + std::vector linenumbers; + std::vector lineIndices; + std::vector > aatoken; + unsigned int pc; // program counter - bool error; - std::string errorMessage; + bool error; + std::string errorMessage; - std::vector statement; - int statementLength; + std::vector statement; + int statementLength; - SimInfo* info; - NameFinder nameFinder; - DistanceFinder distanceFinder; - IndexFinder indexFinder; - int nStuntDouble; //natoms + nrigidbodies + SimInfo* info; + NameFinder nameFinder; + DistanceFinder distanceFinder; + HullFinder hullFinder; + IndexFinder indexFinder; + int nStuntDouble; //nGLOBALatoms + nGLOBALrigidbodies - typedef std::map VariablesType; - VariablesType variables; + typedef std::map VariablesType; + VariablesType variables; - bool isDynamic_; - bool isLoaded_; + bool isDynamic_; + bool isLoaded_; -}; + }; } #endif