| 1 |
tim |
277 |
/* |
| 2 |
|
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
| 3 |
|
|
* |
| 4 |
|
|
* The University of Notre Dame grants you ("Licensee") a |
| 5 |
|
|
* non-exclusive, royalty free, license to use, modify and |
| 6 |
|
|
* redistribute this software in source and binary code form, provided |
| 7 |
|
|
* that the following conditions are met: |
| 8 |
|
|
* |
| 9 |
gezelter |
1390 |
* 1. Redistributions of source code must retain the above copyright |
| 10 |
tim |
277 |
* notice, this list of conditions and the following disclaimer. |
| 11 |
|
|
* |
| 12 |
gezelter |
1390 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 13 |
tim |
277 |
* notice, this list of conditions and the following disclaimer in the |
| 14 |
|
|
* documentation and/or other materials provided with the |
| 15 |
|
|
* distribution. |
| 16 |
|
|
* |
| 17 |
|
|
* This software is provided "AS IS," without a warranty of any |
| 18 |
|
|
* kind. All express or implied conditions, representations and |
| 19 |
|
|
* warranties, including any implied warranty of merchantability, |
| 20 |
|
|
* fitness for a particular purpose or non-infringement, are hereby |
| 21 |
|
|
* excluded. The University of Notre Dame and its licensors shall not |
| 22 |
|
|
* be liable for any damages suffered by licensee as a result of |
| 23 |
|
|
* using, modifying or distributing the software or its |
| 24 |
|
|
* derivatives. In no event will the University of Notre Dame or its |
| 25 |
|
|
* licensors be liable for any lost revenue, profit or data, or for |
| 26 |
|
|
* direct, indirect, special, consequential, incidental or punitive |
| 27 |
|
|
* damages, however caused and regardless of the theory of liability, |
| 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 |
gezelter |
1390 |
* |
| 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 |
gezelter |
1879 |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). |
| 39 |
gezelter |
1782 |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
| 40 |
|
|
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
| 41 |
tim |
277 |
*/ |
| 42 |
|
|
|
| 43 |
tim |
283 |
#include <stack> |
| 44 |
tim |
277 |
#include "selection/SelectionEvaluator.hpp" |
| 45 |
tim |
283 |
#include "primitives/Atom.hpp" |
| 46 |
|
|
#include "primitives/DirectionalAtom.hpp" |
| 47 |
|
|
#include "primitives/RigidBody.hpp" |
| 48 |
|
|
#include "primitives/Molecule.hpp" |
| 49 |
gezelter |
1782 |
#include "io/ifstrstream.hpp" |
| 50 |
gezelter |
1816 |
#include "types/FixedChargeAdapter.hpp" |
| 51 |
|
|
#include "types/FluctuatingChargeAdapter.hpp" |
| 52 |
tim |
283 |
|
| 53 |
gezelter |
1816 |
|
| 54 |
gezelter |
1390 |
namespace OpenMD { |
| 55 |
tim |
277 |
|
| 56 |
gezelter |
507 |
SelectionEvaluator::SelectionEvaluator(SimInfo* si) |
| 57 |
gezelter |
1412 |
: info(si), nameFinder(info), distanceFinder(info), hullFinder(info), |
| 58 |
gezelter |
2071 |
indexFinder(info), isLoaded_(false), hasSurfaceArea_(false) { |
| 59 |
gezelter |
1953 |
nObjects.push_back(info->getNGlobalAtoms() + info->getNGlobalRigidBodies()); |
| 60 |
|
|
nObjects.push_back(info->getNGlobalBonds()); |
| 61 |
|
|
nObjects.push_back(info->getNGlobalBends()); |
| 62 |
|
|
nObjects.push_back(info->getNGlobalTorsions()); |
| 63 |
|
|
nObjects.push_back(info->getNGlobalInversions()); |
| 64 |
gezelter |
2052 |
nObjects.push_back(info->getNGlobalMolecules()); |
| 65 |
gezelter |
1953 |
} |
| 66 |
|
|
|
| 67 |
cli2 |
1364 |
bool SelectionEvaluator::loadScript(const std::string& filename, |
| 68 |
|
|
const std::string& script) { |
| 69 |
tim |
288 |
clearDefinitionsAndLoadPredefined(); |
| 70 |
tim |
278 |
this->filename = filename; |
| 71 |
|
|
this->script = script; |
| 72 |
|
|
if (! compiler.compile(filename, script)) { |
| 73 |
gezelter |
507 |
error = true; |
| 74 |
|
|
errorMessage = compiler.getErrorMessage(); |
| 75 |
cli2 |
1364 |
|
| 76 |
|
|
sprintf( painCave.errMsg, |
| 77 |
|
|
"SelectionCompiler Error: %s\n", errorMessage.c_str()); |
| 78 |
gezelter |
1390 |
painCave.severity = OPENMD_ERROR; |
| 79 |
cli2 |
1364 |
painCave.isFatal = 1; |
| 80 |
|
|
simError(); |
| 81 |
gezelter |
507 |
return false; |
| 82 |
tim |
278 |
} |
| 83 |
|
|
|
| 84 |
|
|
pc = 0; |
| 85 |
|
|
aatoken = compiler.getAatokenCompiled(); |
| 86 |
|
|
linenumbers = compiler.getLineNumbers(); |
| 87 |
|
|
lineIndices = compiler.getLineIndices(); |
| 88 |
tim |
288 |
|
| 89 |
|
|
std::vector<std::vector<Token> >::const_iterator i; |
| 90 |
|
|
|
| 91 |
|
|
isDynamic_ = false; |
| 92 |
|
|
for (i = aatoken.begin(); i != aatoken.end(); ++i) { |
| 93 |
gezelter |
507 |
if (containDynamicToken(*i)) { |
| 94 |
|
|
isDynamic_ = true; |
| 95 |
|
|
break; |
| 96 |
|
|
} |
| 97 |
tim |
288 |
} |
| 98 |
|
|
|
| 99 |
|
|
isLoaded_ = true; |
| 100 |
tim |
278 |
return true; |
| 101 |
gezelter |
507 |
} |
| 102 |
tim |
278 |
|
| 103 |
gezelter |
507 |
void SelectionEvaluator::clearState() { |
| 104 |
tim |
278 |
error = false; |
| 105 |
tim |
281 |
errorMessage = ""; |
| 106 |
gezelter |
507 |
} |
| 107 |
tim |
278 |
|
| 108 |
gezelter |
507 |
bool SelectionEvaluator::loadScriptString(const std::string& script) { |
| 109 |
tim |
278 |
clearState(); |
| 110 |
tim |
281 |
return loadScript("", script); |
| 111 |
gezelter |
507 |
} |
| 112 |
tim |
278 |
|
| 113 |
gezelter |
507 |
bool SelectionEvaluator::loadScriptFile(const std::string& filename) { |
| 114 |
tim |
278 |
clearState(); |
| 115 |
|
|
return loadScriptFileInternal(filename); |
| 116 |
gezelter |
507 |
} |
| 117 |
tim |
278 |
|
| 118 |
cli2 |
1364 |
bool SelectionEvaluator::loadScriptFileInternal(const std::string & filename) { |
| 119 |
|
|
ifstrstream ifs(filename.c_str()); |
| 120 |
tim |
288 |
if (!ifs.is_open()) { |
| 121 |
gezelter |
507 |
return false; |
| 122 |
tim |
288 |
} |
| 123 |
cli2 |
1364 |
|
| 124 |
tim |
288 |
const int bufferSize = 65535; |
| 125 |
|
|
char buffer[bufferSize]; |
| 126 |
|
|
std::string script; |
| 127 |
|
|
while(ifs.getline(buffer, bufferSize)) { |
| 128 |
gezelter |
507 |
script += buffer; |
| 129 |
tim |
288 |
} |
| 130 |
|
|
return loadScript(filename, script); |
| 131 |
gezelter |
507 |
} |
| 132 |
cli2 |
1364 |
|
| 133 |
gezelter |
1953 |
void SelectionEvaluator::instructionDispatchLoop(SelectionSet& bs){ |
| 134 |
tim |
288 |
|
| 135 |
tim |
281 |
while ( pc < aatoken.size()) { |
| 136 |
gezelter |
507 |
statement = aatoken[pc++]; |
| 137 |
|
|
statementLength = statement.size(); |
| 138 |
|
|
Token token = statement[0]; |
| 139 |
|
|
switch (token.tok) { |
| 140 |
|
|
case Token::define: |
| 141 |
|
|
define(); |
| 142 |
|
|
break; |
| 143 |
|
|
case Token::select: |
| 144 |
|
|
select(bs); |
| 145 |
|
|
break; |
| 146 |
|
|
default: |
| 147 |
|
|
unrecognizedCommand(token); |
| 148 |
|
|
return; |
| 149 |
|
|
} |
| 150 |
tim |
278 |
} |
| 151 |
tim |
288 |
|
| 152 |
gezelter |
507 |
} |
| 153 |
tim |
278 |
|
| 154 |
gezelter |
1953 |
void SelectionEvaluator::instructionDispatchLoop(SelectionSet& bs, int frame){ |
| 155 |
gezelter |
1816 |
|
| 156 |
|
|
while ( pc < aatoken.size()) { |
| 157 |
|
|
statement = aatoken[pc++]; |
| 158 |
|
|
statementLength = statement.size(); |
| 159 |
|
|
Token token = statement[0]; |
| 160 |
|
|
switch (token.tok) { |
| 161 |
|
|
case Token::define: |
| 162 |
|
|
define(); |
| 163 |
|
|
break; |
| 164 |
|
|
case Token::select: |
| 165 |
|
|
select(bs, frame); |
| 166 |
|
|
break; |
| 167 |
|
|
default: |
| 168 |
|
|
unrecognizedCommand(token); |
| 169 |
|
|
return; |
| 170 |
|
|
} |
| 171 |
|
|
} |
| 172 |
|
|
|
| 173 |
|
|
} |
| 174 |
|
|
|
| 175 |
gezelter |
1953 |
SelectionSet SelectionEvaluator::expression(const std::vector<Token>& code, |
| 176 |
cli2 |
1364 |
int pcStart) { |
| 177 |
gezelter |
1953 |
SelectionSet bs = createSelectionSets(); |
| 178 |
|
|
std::stack<SelectionSet> stack; |
| 179 |
|
|
vector<int> bsSize = bs.size(); |
| 180 |
cli2 |
1364 |
|
| 181 |
gezelter |
1782 |
for (unsigned int pc = pcStart; pc < code.size(); ++pc) { |
| 182 |
tim |
278 |
Token instruction = code[pc]; |
| 183 |
tim |
282 |
|
| 184 |
tim |
278 |
switch (instruction.tok) { |
| 185 |
tim |
281 |
case Token::expressionBegin: |
| 186 |
tim |
278 |
break; |
| 187 |
tim |
281 |
case Token::expressionEnd: |
| 188 |
tim |
282 |
break; |
| 189 |
tim |
281 |
case Token::all: |
| 190 |
gezelter |
1801 |
bs = allInstruction(); |
| 191 |
gezelter |
1953 |
stack.push(bs); |
| 192 |
tim |
278 |
break; |
| 193 |
tim |
281 |
case Token::none: |
| 194 |
gezelter |
1953 |
bs = createSelectionSets(); |
| 195 |
|
|
stack.push(bs); |
| 196 |
tim |
278 |
break; |
| 197 |
tim |
281 |
case Token::opOr: |
| 198 |
gezelter |
1953 |
bs= stack.top(); |
| 199 |
|
|
stack.pop(); |
| 200 |
|
|
stack.top() |= bs; |
| 201 |
tim |
278 |
break; |
| 202 |
tim |
281 |
case Token::opAnd: |
| 203 |
gezelter |
1953 |
bs = stack.top(); |
| 204 |
|
|
stack.pop(); |
| 205 |
|
|
stack.top() &= bs; |
| 206 |
tim |
278 |
break; |
| 207 |
tim |
281 |
case Token::opNot: |
| 208 |
gezelter |
1953 |
stack.top().flip(); |
| 209 |
tim |
278 |
break; |
| 210 |
tim |
281 |
case Token::within: |
| 211 |
tim |
283 |
withinInstruction(instruction, stack.top()); |
| 212 |
tim |
278 |
break; |
| 213 |
gezelter |
1412 |
case Token::hull: |
| 214 |
gezelter |
1953 |
stack.push(hull()); |
| 215 |
gezelter |
1412 |
break; |
| 216 |
gezelter |
507 |
//case Token::selected: |
| 217 |
|
|
// stack.push(getSelectionSet()); |
| 218 |
|
|
// break; |
| 219 |
tim |
281 |
case Token::name: |
| 220 |
gezelter |
1953 |
stack.push(nameInstruction(boost::any_cast<std::string>(instruction.value))); |
| 221 |
tim |
278 |
break; |
| 222 |
tim |
295 |
case Token::index: |
| 223 |
gezelter |
1953 |
stack.push(indexInstruction(instruction.value)); |
| 224 |
tim |
281 |
break; |
| 225 |
|
|
case Token::identifier: |
| 226 |
gezelter |
1953 |
stack.push(lookupValue(boost::any_cast<std::string>(instruction.value))); |
| 227 |
tim |
281 |
break; |
| 228 |
|
|
case Token::opLT: |
| 229 |
|
|
case Token::opLE: |
| 230 |
|
|
case Token::opGE: |
| 231 |
|
|
case Token::opGT: |
| 232 |
|
|
case Token::opEQ: |
| 233 |
|
|
case Token::opNE: |
| 234 |
tim |
283 |
stack.push(comparatorInstruction(instruction)); |
| 235 |
tim |
278 |
break; |
| 236 |
|
|
default: |
| 237 |
|
|
unrecognizedExpression(); |
| 238 |
|
|
} |
| 239 |
|
|
} |
| 240 |
tim |
283 |
if (stack.size() != 1) |
| 241 |
tim |
278 |
evalError("atom expression compiler error - stack over/underflow"); |
| 242 |
tim |
283 |
|
| 243 |
|
|
return stack.top(); |
| 244 |
tim |
278 |
} |
| 245 |
|
|
|
| 246 |
|
|
|
| 247 |
gezelter |
1953 |
SelectionSet SelectionEvaluator::expression(const std::vector<Token>& code, |
| 248 |
gezelter |
1816 |
int pcStart, int frame) { |
| 249 |
gezelter |
1953 |
SelectionSet bs = createSelectionSets(); |
| 250 |
|
|
std::stack<SelectionSet> stack; |
| 251 |
gezelter |
1816 |
|
| 252 |
|
|
for (unsigned int pc = pcStart; pc < code.size(); ++pc) { |
| 253 |
|
|
Token instruction = code[pc]; |
| 254 |
tim |
278 |
|
| 255 |
gezelter |
1816 |
switch (instruction.tok) { |
| 256 |
|
|
case Token::expressionBegin: |
| 257 |
|
|
break; |
| 258 |
|
|
case Token::expressionEnd: |
| 259 |
|
|
break; |
| 260 |
|
|
case Token::all: |
| 261 |
|
|
bs = allInstruction(); |
| 262 |
|
|
stack.push(bs); |
| 263 |
|
|
break; |
| 264 |
|
|
case Token::none: |
| 265 |
gezelter |
1953 |
bs = SelectionSet(nObjects); |
| 266 |
gezelter |
1816 |
stack.push(bs); |
| 267 |
|
|
break; |
| 268 |
|
|
case Token::opOr: |
| 269 |
|
|
bs = stack.top(); |
| 270 |
|
|
stack.pop(); |
| 271 |
|
|
stack.top() |= bs; |
| 272 |
|
|
break; |
| 273 |
|
|
case Token::opAnd: |
| 274 |
|
|
bs = stack.top(); |
| 275 |
|
|
stack.pop(); |
| 276 |
|
|
stack.top() &= bs; |
| 277 |
|
|
break; |
| 278 |
|
|
case Token::opNot: |
| 279 |
|
|
stack.top().flip(); |
| 280 |
|
|
break; |
| 281 |
|
|
case Token::within: |
| 282 |
|
|
withinInstruction(instruction, stack.top(), frame); |
| 283 |
|
|
break; |
| 284 |
|
|
case Token::hull: |
| 285 |
|
|
stack.push(hull(frame)); |
| 286 |
|
|
break; |
| 287 |
|
|
//case Token::selected: |
| 288 |
|
|
// stack.push(getSelectionSet()); |
| 289 |
|
|
// break; |
| 290 |
|
|
case Token::name: |
| 291 |
|
|
stack.push(nameInstruction(boost::any_cast<std::string>(instruction.value))); |
| 292 |
|
|
break; |
| 293 |
|
|
case Token::index: |
| 294 |
|
|
stack.push(indexInstruction(instruction.value)); |
| 295 |
|
|
break; |
| 296 |
|
|
case Token::identifier: |
| 297 |
|
|
stack.push(lookupValue(boost::any_cast<std::string>(instruction.value))); |
| 298 |
|
|
break; |
| 299 |
|
|
case Token::opLT: |
| 300 |
|
|
case Token::opLE: |
| 301 |
|
|
case Token::opGE: |
| 302 |
|
|
case Token::opGT: |
| 303 |
|
|
case Token::opEQ: |
| 304 |
|
|
case Token::opNE: |
| 305 |
|
|
stack.push(comparatorInstruction(instruction, frame)); |
| 306 |
|
|
break; |
| 307 |
|
|
default: |
| 308 |
|
|
unrecognizedExpression(); |
| 309 |
|
|
} |
| 310 |
|
|
} |
| 311 |
|
|
if (stack.size() != 1) |
| 312 |
|
|
evalError("atom expression compiler error - stack over/underflow"); |
| 313 |
|
|
|
| 314 |
|
|
return stack.top(); |
| 315 |
|
|
} |
| 316 |
|
|
|
| 317 |
|
|
|
| 318 |
|
|
|
| 319 |
gezelter |
1953 |
SelectionSet SelectionEvaluator::comparatorInstruction(const Token& instruction) { |
| 320 |
tim |
278 |
int comparator = instruction.tok; |
| 321 |
|
|
int property = instruction.intValue; |
| 322 |
tim |
283 |
float comparisonValue = boost::any_cast<float>(instruction.value); |
| 323 |
gezelter |
1953 |
SelectionSet bs = createSelectionSets(); |
| 324 |
tim |
295 |
bs.clearAll(); |
| 325 |
tim |
283 |
|
| 326 |
|
|
SimInfo::MoleculeIterator mi; |
| 327 |
|
|
Molecule* mol; |
| 328 |
|
|
Molecule::AtomIterator ai; |
| 329 |
|
|
Atom* atom; |
| 330 |
|
|
Molecule::RigidBodyIterator rbIter; |
| 331 |
|
|
RigidBody* rb; |
| 332 |
tim |
281 |
|
| 333 |
cli2 |
1364 |
for (mol = info->beginMolecule(mi); mol != NULL; |
| 334 |
|
|
mol = info->nextMolecule(mi)) { |
| 335 |
|
|
|
| 336 |
gezelter |
2055 |
compareProperty(mol, bs, property, comparator, comparisonValue); |
| 337 |
|
|
|
| 338 |
gezelter |
507 |
for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
| 339 |
|
|
compareProperty(atom, bs, property, comparator, comparisonValue); |
| 340 |
|
|
} |
| 341 |
cli2 |
1364 |
|
| 342 |
|
|
for (rb = mol->beginRigidBody(rbIter); rb != NULL; |
| 343 |
|
|
rb = mol->nextRigidBody(rbIter)) { |
| 344 |
|
|
compareProperty(rb, bs, property, comparator, comparisonValue); |
| 345 |
|
|
} |
| 346 |
tim |
278 |
} |
| 347 |
|
|
|
| 348 |
tim |
283 |
return bs; |
| 349 |
gezelter |
507 |
} |
| 350 |
tim |
278 |
|
| 351 |
gezelter |
1953 |
SelectionSet SelectionEvaluator::comparatorInstruction(const Token& instruction, int frame) { |
| 352 |
gezelter |
1816 |
int comparator = instruction.tok; |
| 353 |
|
|
int property = instruction.intValue; |
| 354 |
|
|
float comparisonValue = boost::any_cast<float>(instruction.value); |
| 355 |
gezelter |
1953 |
SelectionSet bs = createSelectionSets(); |
| 356 |
gezelter |
1816 |
bs.clearAll(); |
| 357 |
|
|
|
| 358 |
|
|
SimInfo::MoleculeIterator mi; |
| 359 |
|
|
Molecule* mol; |
| 360 |
|
|
Molecule::AtomIterator ai; |
| 361 |
|
|
Atom* atom; |
| 362 |
|
|
Molecule::RigidBodyIterator rbIter; |
| 363 |
|
|
RigidBody* rb; |
| 364 |
|
|
|
| 365 |
|
|
for (mol = info->beginMolecule(mi); mol != NULL; |
| 366 |
|
|
mol = info->nextMolecule(mi)) { |
| 367 |
|
|
|
| 368 |
gezelter |
2055 |
compareProperty(mol, bs, property, comparator, comparisonValue, frame); |
| 369 |
|
|
|
| 370 |
gezelter |
1816 |
for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
| 371 |
|
|
compareProperty(atom, bs, property, comparator, comparisonValue, frame); |
| 372 |
|
|
} |
| 373 |
|
|
|
| 374 |
|
|
for (rb = mol->beginRigidBody(rbIter); rb != NULL; |
| 375 |
|
|
rb = mol->nextRigidBody(rbIter)) { |
| 376 |
|
|
compareProperty(rb, bs, property, comparator, comparisonValue, frame); |
| 377 |
|
|
} |
| 378 |
|
|
} |
| 379 |
|
|
|
| 380 |
|
|
return bs; |
| 381 |
|
|
} |
| 382 |
|
|
|
| 383 |
gezelter |
1953 |
void SelectionEvaluator::compareProperty(StuntDouble* sd, SelectionSet& bs, |
| 384 |
cli2 |
1364 |
int property, int comparator, |
| 385 |
|
|
float comparisonValue) { |
| 386 |
tim |
963 |
RealType propertyValue = 0.0; |
| 387 |
gezelter |
1879 |
Vector3d pos; |
| 388 |
gezelter |
1931 |
|
| 389 |
gezelter |
507 |
switch (property) { |
| 390 |
|
|
case Token::mass: |
| 391 |
|
|
propertyValue = sd->getMass(); |
| 392 |
|
|
break; |
| 393 |
|
|
case Token::charge: |
| 394 |
|
|
if (sd->isAtom()){ |
| 395 |
|
|
Atom* atom = static_cast<Atom*>(sd); |
| 396 |
|
|
propertyValue = getCharge(atom); |
| 397 |
|
|
} else if (sd->isRigidBody()) { |
| 398 |
|
|
RigidBody* rb = static_cast<RigidBody*>(sd); |
| 399 |
|
|
RigidBody::AtomIterator ai; |
| 400 |
|
|
Atom* atom; |
| 401 |
|
|
for (atom = rb->beginAtom(ai); atom != NULL; atom = rb->nextAtom(ai)) { |
| 402 |
|
|
propertyValue+= getCharge(atom); |
| 403 |
|
|
} |
| 404 |
|
|
} |
| 405 |
|
|
break; |
| 406 |
cli2 |
1360 |
case Token::x: |
| 407 |
|
|
propertyValue = sd->getPos().x(); |
| 408 |
|
|
break; |
| 409 |
|
|
case Token::y: |
| 410 |
|
|
propertyValue = sd->getPos().y(); |
| 411 |
|
|
break; |
| 412 |
|
|
case Token::z: |
| 413 |
|
|
propertyValue = sd->getPos().z(); |
| 414 |
|
|
break; |
| 415 |
gezelter |
1879 |
case Token::wrappedX: |
| 416 |
|
|
pos = sd->getPos(); |
| 417 |
|
|
info->getSnapshotManager()->getCurrentSnapshot()->wrapVector(pos); |
| 418 |
|
|
propertyValue = pos.x(); |
| 419 |
|
|
break; |
| 420 |
|
|
case Token::wrappedY: |
| 421 |
|
|
pos = sd->getPos(); |
| 422 |
|
|
info->getSnapshotManager()->getCurrentSnapshot()->wrapVector(pos); |
| 423 |
|
|
propertyValue = pos.y(); |
| 424 |
|
|
break; |
| 425 |
|
|
case Token::wrappedZ: |
| 426 |
|
|
pos = sd->getPos(); |
| 427 |
|
|
info->getSnapshotManager()->getCurrentSnapshot()->wrapVector(pos); |
| 428 |
|
|
propertyValue = pos.z(); |
| 429 |
|
|
break; |
| 430 |
gezelter |
1513 |
case Token::r: |
| 431 |
|
|
propertyValue = sd->getPos().length(); |
| 432 |
|
|
break; |
| 433 |
gezelter |
507 |
default: |
| 434 |
|
|
unrecognizedAtomProperty(property); |
| 435 |
|
|
} |
| 436 |
tim |
283 |
|
| 437 |
gezelter |
507 |
bool match = false; |
| 438 |
|
|
switch (comparator) { |
| 439 |
|
|
case Token::opLT: |
| 440 |
|
|
match = propertyValue < comparisonValue; |
| 441 |
|
|
break; |
| 442 |
|
|
case Token::opLE: |
| 443 |
|
|
match = propertyValue <= comparisonValue; |
| 444 |
|
|
break; |
| 445 |
|
|
case Token::opGE: |
| 446 |
|
|
match = propertyValue >= comparisonValue; |
| 447 |
|
|
break; |
| 448 |
|
|
case Token::opGT: |
| 449 |
|
|
match = propertyValue > comparisonValue; |
| 450 |
|
|
break; |
| 451 |
|
|
case Token::opEQ: |
| 452 |
|
|
match = propertyValue == comparisonValue; |
| 453 |
|
|
break; |
| 454 |
|
|
case Token::opNE: |
| 455 |
|
|
match = propertyValue != comparisonValue; |
| 456 |
|
|
break; |
| 457 |
|
|
} |
| 458 |
gezelter |
1931 |
|
| 459 |
gezelter |
1816 |
if (match) |
| 460 |
gezelter |
1953 |
bs.bitsets_[STUNTDOUBLE].setBitOn(sd->getGlobalIndex()); |
| 461 |
gezelter |
1816 |
|
| 462 |
cli2 |
1364 |
|
| 463 |
gezelter |
507 |
} |
| 464 |
tim |
283 |
|
| 465 |
gezelter |
2055 |
void SelectionEvaluator::compareProperty(Molecule* mol, SelectionSet& bs, |
| 466 |
|
|
int property, int comparator, |
| 467 |
|
|
float comparisonValue) { |
| 468 |
|
|
RealType propertyValue = 0.0; |
| 469 |
|
|
Vector3d pos; |
| 470 |
|
|
|
| 471 |
|
|
switch (property) { |
| 472 |
|
|
case Token::mass: |
| 473 |
|
|
propertyValue = mol->getMass(); |
| 474 |
|
|
break; |
| 475 |
|
|
case Token::charge: |
| 476 |
|
|
{ |
| 477 |
|
|
Molecule::AtomIterator ai; |
| 478 |
|
|
Atom* atom; |
| 479 |
|
|
for (atom = mol->beginAtom(ai); atom != NULL; |
| 480 |
|
|
atom = mol->nextAtom(ai)) { |
| 481 |
|
|
propertyValue+= getCharge(atom); |
| 482 |
|
|
} |
| 483 |
|
|
} |
| 484 |
|
|
break; |
| 485 |
|
|
case Token::x: |
| 486 |
|
|
propertyValue = mol->getCom().x(); |
| 487 |
|
|
break; |
| 488 |
|
|
case Token::y: |
| 489 |
|
|
propertyValue = mol->getCom().y(); |
| 490 |
|
|
break; |
| 491 |
|
|
case Token::z: |
| 492 |
|
|
propertyValue = mol->getCom().z(); |
| 493 |
|
|
break; |
| 494 |
|
|
case Token::wrappedX: |
| 495 |
|
|
pos = mol->getCom(); |
| 496 |
|
|
info->getSnapshotManager()->getCurrentSnapshot()->wrapVector(pos); |
| 497 |
|
|
propertyValue = pos.x(); |
| 498 |
|
|
break; |
| 499 |
|
|
case Token::wrappedY: |
| 500 |
|
|
pos = mol->getCom(); |
| 501 |
|
|
info->getSnapshotManager()->getCurrentSnapshot()->wrapVector(pos); |
| 502 |
|
|
propertyValue = pos.y(); |
| 503 |
|
|
break; |
| 504 |
|
|
case Token::wrappedZ: |
| 505 |
|
|
pos = mol->getCom(); |
| 506 |
|
|
info->getSnapshotManager()->getCurrentSnapshot()->wrapVector(pos); |
| 507 |
|
|
propertyValue = pos.z(); |
| 508 |
|
|
break; |
| 509 |
|
|
case Token::r: |
| 510 |
|
|
propertyValue = mol->getCom().length(); |
| 511 |
|
|
break; |
| 512 |
|
|
default: |
| 513 |
|
|
unrecognizedMoleculeProperty(property); |
| 514 |
|
|
} |
| 515 |
|
|
|
| 516 |
|
|
bool match = false; |
| 517 |
|
|
switch (comparator) { |
| 518 |
|
|
case Token::opLT: |
| 519 |
|
|
match = propertyValue < comparisonValue; |
| 520 |
|
|
break; |
| 521 |
|
|
case Token::opLE: |
| 522 |
|
|
match = propertyValue <= comparisonValue; |
| 523 |
|
|
break; |
| 524 |
|
|
case Token::opGE: |
| 525 |
|
|
match = propertyValue >= comparisonValue; |
| 526 |
|
|
break; |
| 527 |
|
|
case Token::opGT: |
| 528 |
|
|
match = propertyValue > comparisonValue; |
| 529 |
|
|
break; |
| 530 |
|
|
case Token::opEQ: |
| 531 |
|
|
match = propertyValue == comparisonValue; |
| 532 |
|
|
break; |
| 533 |
|
|
case Token::opNE: |
| 534 |
|
|
match = propertyValue != comparisonValue; |
| 535 |
|
|
break; |
| 536 |
|
|
} |
| 537 |
|
|
|
| 538 |
|
|
if (match) |
| 539 |
|
|
bs.bitsets_[MOLECULE].setBitOn(mol->getGlobalIndex()); |
| 540 |
|
|
} |
| 541 |
|
|
|
| 542 |
|
|
void SelectionEvaluator::compareProperty(Molecule* mol, SelectionSet& bs, |
| 543 |
|
|
int property, int comparator, |
| 544 |
|
|
float comparisonValue, int frame) { |
| 545 |
|
|
RealType propertyValue = 0.0; |
| 546 |
|
|
Vector3d pos; |
| 547 |
|
|
switch (property) { |
| 548 |
|
|
case Token::mass: |
| 549 |
|
|
propertyValue = mol->getMass(); |
| 550 |
|
|
break; |
| 551 |
|
|
case Token::charge: |
| 552 |
|
|
{ |
| 553 |
|
|
Molecule::AtomIterator ai; |
| 554 |
|
|
Atom* atom; |
| 555 |
|
|
for (atom = mol->beginAtom(ai); atom != NULL; |
| 556 |
|
|
atom = mol->nextAtom(ai)) { |
| 557 |
|
|
propertyValue+= getCharge(atom,frame); |
| 558 |
|
|
} |
| 559 |
|
|
} |
| 560 |
|
|
break; |
| 561 |
|
|
case Token::x: |
| 562 |
|
|
propertyValue = mol->getCom(frame).x(); |
| 563 |
|
|
break; |
| 564 |
|
|
case Token::y: |
| 565 |
|
|
propertyValue = mol->getCom(frame).y(); |
| 566 |
|
|
break; |
| 567 |
|
|
case Token::z: |
| 568 |
|
|
propertyValue = mol->getCom(frame).z(); |
| 569 |
|
|
break; |
| 570 |
|
|
case Token::wrappedX: |
| 571 |
|
|
pos = mol->getCom(frame); |
| 572 |
|
|
info->getSnapshotManager()->getSnapshot(frame)->wrapVector(pos); |
| 573 |
|
|
propertyValue = pos.x(); |
| 574 |
|
|
break; |
| 575 |
|
|
case Token::wrappedY: |
| 576 |
|
|
pos = mol->getCom(frame); |
| 577 |
|
|
info->getSnapshotManager()->getSnapshot(frame)->wrapVector(pos); |
| 578 |
|
|
propertyValue = pos.y(); |
| 579 |
|
|
break; |
| 580 |
|
|
case Token::wrappedZ: |
| 581 |
|
|
pos = mol->getCom(frame); |
| 582 |
|
|
info->getSnapshotManager()->getSnapshot(frame)->wrapVector(pos); |
| 583 |
|
|
propertyValue = pos.z(); |
| 584 |
|
|
break; |
| 585 |
|
|
|
| 586 |
|
|
case Token::r: |
| 587 |
|
|
propertyValue = mol->getCom(frame).length(); |
| 588 |
|
|
break; |
| 589 |
|
|
default: |
| 590 |
|
|
unrecognizedMoleculeProperty(property); |
| 591 |
|
|
} |
| 592 |
|
|
|
| 593 |
|
|
bool match = false; |
| 594 |
|
|
switch (comparator) { |
| 595 |
|
|
case Token::opLT: |
| 596 |
|
|
match = propertyValue < comparisonValue; |
| 597 |
|
|
break; |
| 598 |
|
|
case Token::opLE: |
| 599 |
|
|
match = propertyValue <= comparisonValue; |
| 600 |
|
|
break; |
| 601 |
|
|
case Token::opGE: |
| 602 |
|
|
match = propertyValue >= comparisonValue; |
| 603 |
|
|
break; |
| 604 |
|
|
case Token::opGT: |
| 605 |
|
|
match = propertyValue > comparisonValue; |
| 606 |
|
|
break; |
| 607 |
|
|
case Token::opEQ: |
| 608 |
|
|
match = propertyValue == comparisonValue; |
| 609 |
|
|
break; |
| 610 |
|
|
case Token::opNE: |
| 611 |
|
|
match = propertyValue != comparisonValue; |
| 612 |
|
|
break; |
| 613 |
|
|
} |
| 614 |
|
|
if (match) |
| 615 |
|
|
bs.bitsets_[MOLECULE].setBitOn(mol->getGlobalIndex()); |
| 616 |
|
|
|
| 617 |
|
|
|
| 618 |
|
|
} |
| 619 |
gezelter |
1953 |
void SelectionEvaluator::compareProperty(StuntDouble* sd, SelectionSet& bs, |
| 620 |
gezelter |
1816 |
int property, int comparator, |
| 621 |
|
|
float comparisonValue, int frame) { |
| 622 |
|
|
RealType propertyValue = 0.0; |
| 623 |
gezelter |
1879 |
Vector3d pos; |
| 624 |
gezelter |
1816 |
switch (property) { |
| 625 |
|
|
case Token::mass: |
| 626 |
|
|
propertyValue = sd->getMass(); |
| 627 |
|
|
break; |
| 628 |
|
|
case Token::charge: |
| 629 |
|
|
if (sd->isAtom()){ |
| 630 |
|
|
Atom* atom = static_cast<Atom*>(sd); |
| 631 |
|
|
propertyValue = getCharge(atom,frame); |
| 632 |
|
|
} else if (sd->isRigidBody()) { |
| 633 |
|
|
RigidBody* rb = static_cast<RigidBody*>(sd); |
| 634 |
|
|
RigidBody::AtomIterator ai; |
| 635 |
|
|
Atom* atom; |
| 636 |
|
|
for (atom = rb->beginAtom(ai); atom != NULL; atom = rb->nextAtom(ai)) { |
| 637 |
|
|
propertyValue+= getCharge(atom,frame); |
| 638 |
|
|
} |
| 639 |
|
|
} |
| 640 |
|
|
break; |
| 641 |
|
|
case Token::x: |
| 642 |
|
|
propertyValue = sd->getPos(frame).x(); |
| 643 |
|
|
break; |
| 644 |
|
|
case Token::y: |
| 645 |
|
|
propertyValue = sd->getPos(frame).y(); |
| 646 |
|
|
break; |
| 647 |
|
|
case Token::z: |
| 648 |
|
|
propertyValue = sd->getPos(frame).z(); |
| 649 |
|
|
break; |
| 650 |
gezelter |
1879 |
case Token::wrappedX: |
| 651 |
|
|
pos = sd->getPos(frame); |
| 652 |
|
|
info->getSnapshotManager()->getSnapshot(frame)->wrapVector(pos); |
| 653 |
|
|
propertyValue = pos.x(); |
| 654 |
|
|
break; |
| 655 |
|
|
case Token::wrappedY: |
| 656 |
|
|
pos = sd->getPos(frame); |
| 657 |
|
|
info->getSnapshotManager()->getSnapshot(frame)->wrapVector(pos); |
| 658 |
|
|
propertyValue = pos.y(); |
| 659 |
|
|
break; |
| 660 |
|
|
case Token::wrappedZ: |
| 661 |
|
|
pos = sd->getPos(frame); |
| 662 |
|
|
info->getSnapshotManager()->getSnapshot(frame)->wrapVector(pos); |
| 663 |
|
|
propertyValue = pos.z(); |
| 664 |
|
|
break; |
| 665 |
|
|
|
| 666 |
gezelter |
1816 |
case Token::r: |
| 667 |
|
|
propertyValue = sd->getPos(frame).length(); |
| 668 |
|
|
break; |
| 669 |
|
|
default: |
| 670 |
|
|
unrecognizedAtomProperty(property); |
| 671 |
|
|
} |
| 672 |
|
|
|
| 673 |
|
|
bool match = false; |
| 674 |
|
|
switch (comparator) { |
| 675 |
|
|
case Token::opLT: |
| 676 |
|
|
match = propertyValue < comparisonValue; |
| 677 |
|
|
break; |
| 678 |
|
|
case Token::opLE: |
| 679 |
|
|
match = propertyValue <= comparisonValue; |
| 680 |
|
|
break; |
| 681 |
|
|
case Token::opGE: |
| 682 |
|
|
match = propertyValue >= comparisonValue; |
| 683 |
|
|
break; |
| 684 |
|
|
case Token::opGT: |
| 685 |
|
|
match = propertyValue > comparisonValue; |
| 686 |
|
|
break; |
| 687 |
|
|
case Token::opEQ: |
| 688 |
|
|
match = propertyValue == comparisonValue; |
| 689 |
|
|
break; |
| 690 |
|
|
case Token::opNE: |
| 691 |
|
|
match = propertyValue != comparisonValue; |
| 692 |
|
|
break; |
| 693 |
|
|
} |
| 694 |
|
|
if (match) |
| 695 |
gezelter |
2071 |
bs.bitsets_[STUNTDOUBLE].setBitOn(sd->getGlobalIndex()); |
| 696 |
gezelter |
1816 |
} |
| 697 |
gezelter |
2055 |
|
| 698 |
gezelter |
2071 |
|
| 699 |
cli2 |
1364 |
void SelectionEvaluator::withinInstruction(const Token& instruction, |
| 700 |
gezelter |
1953 |
SelectionSet& bs){ |
| 701 |
tim |
295 |
|
| 702 |
tim |
281 |
boost::any withinSpec = instruction.value; |
| 703 |
tim |
295 |
float distance; |
| 704 |
tim |
282 |
if (withinSpec.type() == typeid(float)){ |
| 705 |
gezelter |
507 |
distance = boost::any_cast<float>(withinSpec); |
| 706 |
tim |
295 |
} else if (withinSpec.type() == typeid(int)) { |
| 707 |
gezelter |
507 |
distance = boost::any_cast<int>(withinSpec); |
| 708 |
tim |
295 |
} else { |
| 709 |
gezelter |
507 |
evalError("casting error in withinInstruction"); |
| 710 |
|
|
bs.clearAll(); |
| 711 |
tim |
278 |
} |
| 712 |
tim |
282 |
|
| 713 |
tim |
295 |
bs = distanceFinder.find(bs, distance); |
| 714 |
gezelter |
507 |
} |
| 715 |
gezelter |
1816 |
|
| 716 |
|
|
void SelectionEvaluator::withinInstruction(const Token& instruction, |
| 717 |
gezelter |
1953 |
SelectionSet& bs, int frame){ |
| 718 |
gezelter |
1816 |
|
| 719 |
|
|
boost::any withinSpec = instruction.value; |
| 720 |
|
|
float distance; |
| 721 |
|
|
if (withinSpec.type() == typeid(float)){ |
| 722 |
|
|
distance = boost::any_cast<float>(withinSpec); |
| 723 |
|
|
} else if (withinSpec.type() == typeid(int)) { |
| 724 |
|
|
distance = boost::any_cast<int>(withinSpec); |
| 725 |
|
|
} else { |
| 726 |
|
|
evalError("casting error in withinInstruction"); |
| 727 |
|
|
bs.clearAll(); |
| 728 |
|
|
} |
| 729 |
|
|
|
| 730 |
|
|
bs = distanceFinder.find(bs, distance, frame); |
| 731 |
|
|
} |
| 732 |
cli2 |
1364 |
|
| 733 |
gezelter |
507 |
void SelectionEvaluator::define() { |
| 734 |
tim |
282 |
assert(statement.size() >= 3); |
| 735 |
cli2 |
1364 |
|
| 736 |
tim |
282 |
std::string variable = boost::any_cast<std::string>(statement[1].value); |
| 737 |
cli2 |
1364 |
|
| 738 |
|
|
variables.insert(VariablesType::value_type(variable, |
| 739 |
|
|
expression(statement, 2))); |
| 740 |
gezelter |
507 |
} |
| 741 |
cli2 |
1364 |
|
| 742 |
tim |
278 |
|
| 743 |
gezelter |
507 |
/** @todo */ |
| 744 |
|
|
void SelectionEvaluator::predefine(const std::string& script) { |
| 745 |
cli2 |
1364 |
|
| 746 |
tim |
282 |
if (compiler.compile("#predefine", script)) { |
| 747 |
gezelter |
507 |
std::vector<std::vector<Token> > aatoken = compiler.getAatokenCompiled(); |
| 748 |
|
|
if (aatoken.size() != 1) { |
| 749 |
|
|
evalError("predefinition does not have exactly 1 command:" |
| 750 |
|
|
+ script); |
| 751 |
|
|
return; |
| 752 |
|
|
} |
| 753 |
|
|
std::vector<Token> statement = aatoken[0]; |
| 754 |
|
|
if (statement.size() > 2) { |
| 755 |
|
|
int tok = statement[1].tok; |
| 756 |
cli2 |
1364 |
if (tok == Token::identifier || |
| 757 |
|
|
(tok & Token::predefinedset) == Token::predefinedset) { |
| 758 |
gezelter |
507 |
std::string variable = boost::any_cast<std::string>(statement[1].value); |
| 759 |
|
|
variables.insert(VariablesType::value_type(variable, statement)); |
| 760 |
cli2 |
1364 |
|
| 761 |
gezelter |
507 |
} else { |
| 762 |
|
|
evalError("invalid variable name:" + script); |
| 763 |
|
|
} |
| 764 |
|
|
}else { |
| 765 |
|
|
evalError("bad predefinition length:" + script); |
| 766 |
cli2 |
1364 |
} |
| 767 |
tim |
282 |
|
| 768 |
|
|
} else { |
| 769 |
gezelter |
507 |
evalError("predefined set compile error:" + script + |
| 770 |
|
|
"\ncompile error:" + compiler.getErrorMessage()); |
| 771 |
tim |
282 |
} |
| 772 |
gezelter |
507 |
} |
| 773 |
tim |
282 |
|
| 774 |
gezelter |
1953 |
void SelectionEvaluator::select(SelectionSet& bs){ |
| 775 |
tim |
288 |
bs = expression(statement, 1); |
| 776 |
gezelter |
507 |
} |
| 777 |
gezelter |
1816 |
|
| 778 |
gezelter |
1953 |
void SelectionEvaluator::select(SelectionSet& bs, int frame){ |
| 779 |
gezelter |
1816 |
bs = expression(statement, 1, frame); |
| 780 |
|
|
} |
| 781 |
cli2 |
1364 |
|
| 782 |
gezelter |
1953 |
SelectionSet SelectionEvaluator::lookupValue(const std::string& variable){ |
| 783 |
cli2 |
1364 |
|
| 784 |
gezelter |
1953 |
SelectionSet bs = createSelectionSets(); |
| 785 |
tim |
282 |
std::map<std::string, boost::any>::iterator i = variables.find(variable); |
| 786 |
tim |
295 |
|
| 787 |
tim |
282 |
if (i != variables.end()) { |
| 788 |
gezelter |
1953 |
if (i->second.type() == typeid(SelectionSet)) { |
| 789 |
|
|
return boost::any_cast<SelectionSet>(i->second); |
| 790 |
gezelter |
507 |
} else if (i->second.type() == typeid(std::vector<Token>)){ |
| 791 |
|
|
bs = expression(boost::any_cast<std::vector<Token> >(i->second), 2); |
| 792 |
|
|
i->second = bs; /**@todo fixme */ |
| 793 |
|
|
return bs; |
| 794 |
|
|
} |
| 795 |
tim |
283 |
} else { |
| 796 |
gezelter |
507 |
unrecognizedIdentifier(variable); |
| 797 |
tim |
282 |
} |
| 798 |
cli2 |
1364 |
|
| 799 |
tim |
295 |
return bs; |
| 800 |
gezelter |
507 |
} |
| 801 |
cli2 |
1364 |
|
| 802 |
gezelter |
1953 |
SelectionSet SelectionEvaluator::nameInstruction(const std::string& name){ |
| 803 |
cli2 |
1364 |
return nameFinder.match(name); |
| 804 |
gezelter |
507 |
} |
| 805 |
tim |
283 |
|
| 806 |
gezelter |
507 |
bool SelectionEvaluator::containDynamicToken(const std::vector<Token>& tokens){ |
| 807 |
tim |
288 |
std::vector<Token>::const_iterator i; |
| 808 |
|
|
for (i = tokens.begin(); i != tokens.end(); ++i) { |
| 809 |
gezelter |
507 |
if (i->tok & Token::dynamic) { |
| 810 |
|
|
return true; |
| 811 |
|
|
} |
| 812 |
tim |
288 |
} |
| 813 |
cli2 |
1364 |
|
| 814 |
tim |
288 |
return false; |
| 815 |
gezelter |
507 |
} |
| 816 |
tim |
288 |
|
| 817 |
gezelter |
507 |
void SelectionEvaluator::clearDefinitionsAndLoadPredefined() { |
| 818 |
tim |
288 |
variables.clear(); |
| 819 |
|
|
//load predefine |
| 820 |
|
|
//predefine(); |
| 821 |
gezelter |
507 |
} |
| 822 |
tim |
288 |
|
| 823 |
gezelter |
1953 |
SelectionSet SelectionEvaluator::createSelectionSets() { |
| 824 |
|
|
SelectionSet ss(nObjects); |
| 825 |
|
|
return ss; |
| 826 |
|
|
} |
| 827 |
|
|
|
| 828 |
|
|
SelectionSet SelectionEvaluator::evaluate() { |
| 829 |
|
|
SelectionSet bs = createSelectionSets(); |
| 830 |
tim |
288 |
if (isLoaded_) { |
| 831 |
gezelter |
507 |
pc = 0; |
| 832 |
|
|
instructionDispatchLoop(bs); |
| 833 |
tim |
288 |
} |
| 834 |
gezelter |
1816 |
return bs; |
| 835 |
|
|
} |
| 836 |
tim |
288 |
|
| 837 |
gezelter |
1953 |
SelectionSet SelectionEvaluator::evaluate(int frame) { |
| 838 |
|
|
SelectionSet bs = createSelectionSets(); |
| 839 |
gezelter |
1816 |
if (isLoaded_) { |
| 840 |
|
|
pc = 0; |
| 841 |
|
|
instructionDispatchLoop(bs, frame); |
| 842 |
|
|
} |
| 843 |
tim |
288 |
return bs; |
| 844 |
gezelter |
507 |
} |
| 845 |
tim |
295 |
|
| 846 |
gezelter |
1953 |
SelectionSet SelectionEvaluator::indexInstruction(const boost::any& value) { |
| 847 |
|
|
SelectionSet bs = createSelectionSets(); |
| 848 |
tim |
295 |
|
| 849 |
|
|
if (value.type() == typeid(int)) { |
| 850 |
gezelter |
507 |
int index = boost::any_cast<int>(value); |
| 851 |
gezelter |
1953 |
if (index < 0 || index >= bs.bitsets_[STUNTDOUBLE].size()) { |
| 852 |
gezelter |
507 |
invalidIndex(index); |
| 853 |
|
|
} else { |
| 854 |
|
|
bs = indexFinder.find(index); |
| 855 |
|
|
} |
| 856 |
tim |
295 |
} else if (value.type() == typeid(std::pair<int, int>)) { |
| 857 |
gezelter |
507 |
std::pair<int, int> indexRange= boost::any_cast<std::pair<int, int> >(value); |
| 858 |
|
|
assert(indexRange.first <= indexRange.second); |
| 859 |
gezelter |
1953 |
if (indexRange.first < 0 || |
| 860 |
|
|
indexRange.second >= bs.bitsets_[STUNTDOUBLE].size()) { |
| 861 |
gezelter |
507 |
invalidIndexRange(indexRange); |
| 862 |
|
|
}else { |
| 863 |
|
|
bs = indexFinder.find(indexRange.first, indexRange.second); |
| 864 |
|
|
} |
| 865 |
tim |
295 |
} |
| 866 |
|
|
|
| 867 |
|
|
return bs; |
| 868 |
gezelter |
507 |
} |
| 869 |
tim |
295 |
|
| 870 |
gezelter |
1953 |
SelectionSet SelectionEvaluator::allInstruction() { |
| 871 |
|
|
SelectionSet ss = createSelectionSets(); |
| 872 |
tim |
432 |
|
| 873 |
gezelter |
1801 |
SimInfo::MoleculeIterator mi; |
| 874 |
gezelter |
1953 |
Molecule::AtomIterator ai; |
| 875 |
|
|
Molecule::RigidBodyIterator rbIter; |
| 876 |
|
|
Molecule::BondIterator bondIter; |
| 877 |
|
|
Molecule::BendIterator bendIter; |
| 878 |
|
|
Molecule::TorsionIterator torsionIter; |
| 879 |
|
|
Molecule::InversionIterator inversionIter; |
| 880 |
|
|
|
| 881 |
gezelter |
1801 |
Molecule* mol; |
| 882 |
|
|
Atom* atom; |
| 883 |
|
|
RigidBody* rb; |
| 884 |
gezelter |
1953 |
Bond* bond; |
| 885 |
|
|
Bend* bend; |
| 886 |
|
|
Torsion* torsion; |
| 887 |
|
|
Inversion* inversion; |
| 888 |
gezelter |
1801 |
|
| 889 |
|
|
// Doing the loop insures that we're actually on this processor. |
| 890 |
|
|
|
| 891 |
|
|
for (mol = info->beginMolecule(mi); mol != NULL; |
| 892 |
|
|
mol = info->nextMolecule(mi)) { |
| 893 |
|
|
for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
| 894 |
gezelter |
1953 |
ss.bitsets_[STUNTDOUBLE].setBitOn(atom->getGlobalIndex()); |
| 895 |
|
|
} |
| 896 |
gezelter |
1801 |
for (rb = mol->beginRigidBody(rbIter); rb != NULL; |
| 897 |
|
|
rb = mol->nextRigidBody(rbIter)) { |
| 898 |
gezelter |
1953 |
ss.bitsets_[STUNTDOUBLE].setBitOn(rb->getGlobalIndex()); |
| 899 |
gezelter |
1801 |
} |
| 900 |
gezelter |
1953 |
for (bond = mol->beginBond(bondIter); bond != NULL; |
| 901 |
|
|
bond = mol->nextBond(bondIter)) { |
| 902 |
|
|
ss.bitsets_[BOND].setBitOn(bond->getGlobalIndex()); |
| 903 |
|
|
} |
| 904 |
|
|
for (bend = mol->beginBend(bendIter); bend != NULL; |
| 905 |
|
|
bend = mol->nextBend(bendIter)) { |
| 906 |
|
|
ss.bitsets_[BEND].setBitOn(bend->getGlobalIndex()); |
| 907 |
|
|
} |
| 908 |
|
|
for (torsion = mol->beginTorsion(torsionIter); torsion != NULL; |
| 909 |
|
|
torsion = mol->nextTorsion(torsionIter)) { |
| 910 |
|
|
ss.bitsets_[TORSION].setBitOn(torsion->getGlobalIndex()); |
| 911 |
|
|
} |
| 912 |
|
|
for (inversion = mol->beginInversion(inversionIter); inversion != NULL; |
| 913 |
|
|
inversion = mol->nextInversion(inversionIter)) { |
| 914 |
|
|
ss.bitsets_[INVERSION].setBitOn(inversion->getGlobalIndex()); |
| 915 |
gezelter |
2052 |
} |
| 916 |
|
|
ss.bitsets_[MOLECULE].setBitOn(mol->getGlobalIndex()); |
| 917 |
gezelter |
1801 |
} |
| 918 |
|
|
|
| 919 |
gezelter |
1953 |
return ss; |
| 920 |
gezelter |
1801 |
} |
| 921 |
|
|
|
| 922 |
gezelter |
1953 |
SelectionSet SelectionEvaluator::hull() { |
| 923 |
|
|
SelectionSet bs = createSelectionSets(); |
| 924 |
gezelter |
1412 |
|
| 925 |
|
|
bs = hullFinder.findHull(); |
| 926 |
gezelter |
1903 |
surfaceArea_ = hullFinder.getSurfaceArea(); |
| 927 |
|
|
hasSurfaceArea_ = true; |
| 928 |
gezelter |
1412 |
return bs; |
| 929 |
|
|
} |
| 930 |
|
|
|
| 931 |
gezelter |
1816 |
|
| 932 |
gezelter |
1953 |
SelectionSet SelectionEvaluator::hull(int frame) { |
| 933 |
|
|
SelectionSet bs = createSelectionSets(); |
| 934 |
gezelter |
1816 |
|
| 935 |
|
|
bs = hullFinder.findHull(frame); |
| 936 |
gezelter |
1903 |
|
| 937 |
gezelter |
1816 |
return bs; |
| 938 |
|
|
} |
| 939 |
|
|
|
| 940 |
tim |
963 |
RealType SelectionEvaluator::getCharge(Atom* atom) { |
| 941 |
gezelter |
1816 |
RealType charge = 0.0; |
| 942 |
tim |
432 |
AtomType* atomType = atom->getAtomType(); |
| 943 |
|
|
|
| 944 |
gezelter |
1816 |
FixedChargeAdapter fca = FixedChargeAdapter(atomType); |
| 945 |
|
|
if ( fca.isFixedCharge() ) { |
| 946 |
|
|
charge = fca.getCharge(); |
| 947 |
|
|
} |
| 948 |
|
|
|
| 949 |
|
|
FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atomType); |
| 950 |
|
|
if ( fqa.isFluctuatingCharge() ) { |
| 951 |
|
|
charge += atom->getFlucQPos(); |
| 952 |
|
|
} |
| 953 |
|
|
return charge; |
| 954 |
|
|
} |
| 955 |
tim |
432 |
|
| 956 |
gezelter |
1816 |
RealType SelectionEvaluator::getCharge(Atom* atom, int frame) { |
| 957 |
|
|
RealType charge = 0.0; |
| 958 |
|
|
AtomType* atomType = atom->getAtomType(); |
| 959 |
|
|
|
| 960 |
|
|
FixedChargeAdapter fca = FixedChargeAdapter(atomType); |
| 961 |
|
|
if ( fca.isFixedCharge() ) { |
| 962 |
|
|
charge = fca.getCharge(); |
| 963 |
tim |
432 |
} |
| 964 |
gezelter |
1816 |
|
| 965 |
|
|
FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atomType); |
| 966 |
|
|
if ( fqa.isFluctuatingCharge() ) { |
| 967 |
|
|
charge += atom->getFlucQPos(frame); |
| 968 |
|
|
} |
| 969 |
tim |
432 |
return charge; |
| 970 |
gezelter |
507 |
} |
| 971 |
tim |
432 |
|
| 972 |
|
|
} |