76 class SelectionEvaluator {
78 SelectionEvaluator(
SimInfo* info);
80 bool loadScriptString(
const std::string& script);
81 bool loadScriptFile(
const std::string& filename);
91 bool hadRuntimeError()
const {
return error; }
93 std::string getErrorMessage()
const {
return errorMessage; }
95 int getLinenumber() {
return linenumbers[pc]; }
97 std::string getLine() {
98 std::size_t ichBegin = lineIndices[pc];
100 if ((ichEnd = script.find(
'\r', ichBegin)) == std::string::npos &&
101 (ichEnd = script.find(
'\n', ichBegin)) == std::string::npos) {
102 ichEnd = script.size();
104 return script.substr(ichBegin, ichEnd);
106 bool hasSurfaceArea() {
return hasSurfaceArea_; }
107 RealType getSurfaceArea() {
108 if (hasSurfaceArea_) {
111 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
112 "SelectionEvaluator Error: %s\n",
"No Surface Area For You!");
113 painCave.severity = OPENMD_ERROR;
114 painCave.isFatal = 1;
119 bool hasVolume() {
return hasVolume_; }
120 RealType getVolume() {
124 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
125 "SelectionEvaluator Error: %s\n",
"No Volume For You!");
126 painCave.severity = OPENMD_ERROR;
127 painCave.isFatal = 1;
136 bool loadScript(
const std::string& filename,
const std::string& script);
138 bool loadScriptFileInternal(
const std::string& filename);
140 SelectionSet createSelectionSets();
141 void clearDefinitionsAndLoadPredefined();
144 void select(SelectionSet& bs);
145 void select(SelectionSet& bs,
int frame);
146 void predefine(
const std::string& script);
148 void instructionDispatchLoop(SelectionSet& bs);
149 void instructionDispatchLoop(SelectionSet& bs,
int frame);
151 void withinInstruction(
const Token& instruction, SelectionSet& bs);
152 void withinInstruction(
const Token& instruction, SelectionSet& bs,
155 SelectionSet alphaHullInstruction(
const Token& instruction);
156 SelectionSet alphaHullInstruction(
const Token& instruction,
int frame);
158 SelectionSet allInstruction();
160 SelectionSet comparatorInstruction(
const Token& instruction);
161 SelectionSet comparatorInstruction(
const Token& instruction,
int frame);
162 void compareProperty(StuntDouble* sd, SelectionSet& bs,
int property,
163 int comparator,
float comparisonValue);
164 void compareProperty(StuntDouble* sd, SelectionSet& bs,
int property,
165 int comparator,
float comparisonValue,
int frame);
166 void compareProperty(Molecule* mol, SelectionSet& bs,
int property,
167 int comparator,
float comparisonValue);
168 void compareProperty(Molecule* mol, SelectionSet& bs,
int property,
169 int comparator,
float comparisonValue,
int frame);
170 SelectionSet nameInstruction(
const std::string& name);
171 SelectionSet indexInstruction(
const std::any& value);
172 SelectionSet expression(
const std::vector<Token>& tokens,
int pc);
173 SelectionSet expression(
const std::vector<Token>& tokens,
int pc,
176 SelectionSet lookupValue(
const std::string& variable);
179 SelectionSet hull(
int frame);
181 void evalError(
const std::string& message) {
182 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
183 "SelectionEvaluator Error: %s\n", message.c_str());
184 painCave.severity = OPENMD_ERROR;
185 painCave.isFatal = 1;
189 void unrecognizedCommand(
const Token& token) {
190 evalError(
"unrecognized command:" +
191 std::any_cast<std::string>(token.value));
194 void unrecognizedExpression() { evalError(
"unrecognized expression"); }
196 void unrecognizedAtomProperty(
int) {
197 evalError(
"unrecognized atom property");
200 void unrecognizedMoleculeProperty(
int) {
201 evalError(
"unrecognized molecule property");
204 void unrecognizedIdentifier(
const std::string& identifier) {
205 evalError(
"unrecognized identifier:" + identifier);
208 void invalidIndexRange(std::pair<int, int> range) {
209 evalError(
"invalid index range: [" +
toString(range.first) +
", " +
213 void invalidIndex(
int index) {
214 evalError(
"invalid index : " +
toString(index));
217 bool containDynamicToken(
const std::vector<Token>& tokens);
219 RealType getCharge(Atom* atom);
220 RealType getCharge(Atom* atom,
int frame);
222 SelectionCompiler compiler;
229 std::string filename;
231 std::vector<int> linenumbers;
232 std::vector<int> lineIndices;
233 std::vector<std::vector<Token>> aatoken;
237 std::string errorMessage;
239 std::vector<Token> statement;
242 SimInfo* info {
nullptr};
243 NameFinder nameFinder;
244 DistanceFinder distanceFinder;
245 HullFinder hullFinder;
246 AlphaHullFinder alphaHullFinder;
247 IndexFinder indexFinder;
248 vector<int> nObjects;
250 using VariablesType = std::map<std::string, std::any>;
251 VariablesType variables;
253 bool isDynamic_ {
false};
254 bool isLoaded_ {
false};
255 bool hasSurfaceArea_ {
false};
256 RealType surfaceArea_;
257 bool hasVolume_ {
false};