| 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]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010). | 
| 40 | 
+ | 
 * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). | 
| 41 | 
  | 
 */ | 
| 42 | 
  | 
 | 
| 43 | 
  | 
#include <stack> | 
| 46 | 
  | 
#include "primitives/DirectionalAtom.hpp" | 
| 47 | 
  | 
#include "primitives/RigidBody.hpp" | 
| 48 | 
  | 
#include "primitives/Molecule.hpp" | 
| 49 | 
+ | 
#include "io/ifstrstream.hpp" | 
| 50 | 
  | 
 | 
| 51 | 
< | 
namespace oopse { | 
| 51 | 
> | 
namespace OpenMD { | 
| 52 | 
  | 
 | 
| 53 | 
  | 
 | 
| 54 | 
< | 
SelectionEvaluator::SelectionEvaluator(SimInfo* si) : info(si), nameFinder(info), distanceFinder(info), isLoaded_(false){ | 
| 55 | 
< | 
    nStuntDouble = info->getNGlobalAtoms() + info->getNRigidBodies(); | 
| 56 | 
< | 
}             | 
| 54 | 
> | 
  SelectionEvaluator::SelectionEvaluator(SimInfo* si)  | 
| 55 | 
> | 
    : info(si), nameFinder(info), distanceFinder(info), hullFinder(info), | 
| 56 | 
> | 
      indexFinder(info),  | 
| 57 | 
> | 
      isLoaded_(false){     | 
| 58 | 
> | 
      nStuntDouble = info->getNGlobalAtoms() + info->getNGlobalRigidBodies(); | 
| 59 | 
> | 
    }             | 
| 60 | 
  | 
 | 
| 61 | 
< | 
bool SelectionEvaluator::loadScript(const std::string& filename, const std::string& script) { | 
| 61 | 
> | 
  bool SelectionEvaluator::loadScript(const std::string& filename,  | 
| 62 | 
> | 
                                      const std::string& script) { | 
| 63 | 
  | 
    clearDefinitionsAndLoadPredefined(); | 
| 64 | 
  | 
    this->filename = filename; | 
| 65 | 
  | 
    this->script = script; | 
| 66 | 
  | 
    if (! compiler.compile(filename, script)) { | 
| 67 | 
< | 
        error = true; | 
| 68 | 
< | 
        errorMessage = compiler.getErrorMessage(); | 
| 69 | 
< | 
        std::cerr << "SelectionCompiler Error: " << errorMessage << std::endl; | 
| 70 | 
< | 
        return false; | 
| 67 | 
> | 
      error = true; | 
| 68 | 
> | 
      errorMessage = compiler.getErrorMessage(); | 
| 69 | 
> | 
 | 
| 70 | 
> | 
      sprintf( painCave.errMsg, | 
| 71 | 
> | 
               "SelectionCompiler Error: %s\n", errorMessage.c_str()); | 
| 72 | 
> | 
      painCave.severity = OPENMD_ERROR; | 
| 73 | 
> | 
      painCave.isFatal = 1; | 
| 74 | 
> | 
      simError(); | 
| 75 | 
> | 
      return false; | 
| 76 | 
  | 
    } | 
| 77 | 
  | 
 | 
| 78 | 
  | 
    pc = 0; | 
| 84 | 
  | 
 | 
| 85 | 
  | 
    isDynamic_ = false; | 
| 86 | 
  | 
    for (i = aatoken.begin(); i != aatoken.end(); ++i) { | 
| 87 | 
< | 
        if (containDynamicToken(*i)) { | 
| 88 | 
< | 
            isDynamic_ = true; | 
| 89 | 
< | 
            break; | 
| 90 | 
< | 
        } | 
| 87 | 
> | 
      if (containDynamicToken(*i)) { | 
| 88 | 
> | 
        isDynamic_ = true; | 
| 89 | 
> | 
        break; | 
| 90 | 
> | 
      } | 
| 91 | 
  | 
    } | 
| 92 | 
  | 
 | 
| 93 | 
  | 
    isLoaded_ = true; | 
| 94 | 
  | 
    return true; | 
| 95 | 
< | 
} | 
| 95 | 
> | 
  } | 
| 96 | 
  | 
 | 
| 97 | 
< | 
void SelectionEvaluator::clearState() { | 
| 87 | 
< | 
    //for (int i = scriptLevelMax; --i >= 0; ) | 
| 88 | 
< | 
    //    stack[i].clear(); | 
| 89 | 
< | 
    //scriptLevel = 0; | 
| 97 | 
> | 
  void SelectionEvaluator::clearState() { | 
| 98 | 
  | 
    error = false; | 
| 99 | 
  | 
    errorMessage = ""; | 
| 100 | 
< | 
} | 
| 100 | 
> | 
  } | 
| 101 | 
  | 
 | 
| 102 | 
< | 
bool SelectionEvaluator::loadScriptString(const std::string& script) { | 
| 102 | 
> | 
  bool SelectionEvaluator::loadScriptString(const std::string& script) { | 
| 103 | 
  | 
    clearState(); | 
| 104 | 
  | 
    return loadScript("", script); | 
| 105 | 
< | 
} | 
| 105 | 
> | 
  } | 
| 106 | 
  | 
 | 
| 107 | 
< | 
bool SelectionEvaluator::loadScriptFile(const std::string& filename) { | 
| 107 | 
> | 
  bool SelectionEvaluator::loadScriptFile(const std::string& filename) { | 
| 108 | 
  | 
    clearState(); | 
| 109 | 
  | 
    return loadScriptFileInternal(filename); | 
| 110 | 
< | 
} | 
| 110 | 
> | 
  } | 
| 111 | 
  | 
 | 
| 112 | 
< | 
bool SelectionEvaluator::loadScriptFileInternal(const  std::string & filename) { | 
| 113 | 
< | 
  std::ifstream ifs(filename.c_str()); | 
| 112 | 
> | 
  bool SelectionEvaluator::loadScriptFileInternal(const std::string & filename) { | 
| 113 | 
> | 
    ifstrstream ifs(filename.c_str()); | 
| 114 | 
  | 
    if (!ifs.is_open()) { | 
| 115 | 
< | 
        return false; | 
| 115 | 
> | 
      return false; | 
| 116 | 
  | 
    } | 
| 117 | 
< | 
 | 
| 117 | 
> | 
     | 
| 118 | 
  | 
    const int bufferSize = 65535; | 
| 119 | 
  | 
    char buffer[bufferSize]; | 
| 120 | 
  | 
    std::string script; | 
| 121 | 
  | 
    while(ifs.getline(buffer, bufferSize)) { | 
| 122 | 
< | 
        script += buffer; | 
| 122 | 
> | 
      script += buffer; | 
| 123 | 
  | 
    } | 
| 124 | 
  | 
    return loadScript(filename, script); | 
| 125 | 
< | 
} | 
| 126 | 
< | 
 | 
| 127 | 
< | 
void SelectionEvaluator::instructionDispatchLoop(BitSet& bs){ | 
| 125 | 
> | 
  } | 
| 126 | 
> | 
   | 
| 127 | 
> | 
  void SelectionEvaluator::instructionDispatchLoop(OpenMDBitSet& bs){ | 
| 128 | 
  | 
     | 
| 129 | 
  | 
    while ( pc < aatoken.size()) { | 
| 130 | 
< | 
        statement = aatoken[pc++]; | 
| 131 | 
< | 
        statementLength = statement.size(); | 
| 132 | 
< | 
        Token token = statement[0]; | 
| 133 | 
< | 
        switch (token.tok) { | 
| 134 | 
< | 
            case Token::define: | 
| 135 | 
< | 
                define(); | 
| 136 | 
< | 
            break; | 
| 137 | 
< | 
            case Token::select: | 
| 138 | 
< | 
                select(bs); | 
| 139 | 
< | 
            break; | 
| 140 | 
< | 
            default: | 
| 141 | 
< | 
                unrecognizedCommand(token); | 
| 142 | 
< | 
            return; | 
| 143 | 
< | 
        } | 
| 130 | 
> | 
      statement = aatoken[pc++]; | 
| 131 | 
> | 
      statementLength = statement.size(); | 
| 132 | 
> | 
      Token token = statement[0]; | 
| 133 | 
> | 
      switch (token.tok) { | 
| 134 | 
> | 
      case Token::define: | 
| 135 | 
> | 
        define(); | 
| 136 | 
> | 
        break; | 
| 137 | 
> | 
      case Token::select: | 
| 138 | 
> | 
        select(bs); | 
| 139 | 
> | 
        break; | 
| 140 | 
> | 
      default: | 
| 141 | 
> | 
        unrecognizedCommand(token); | 
| 142 | 
> | 
        return; | 
| 143 | 
> | 
      } | 
| 144 | 
  | 
    } | 
| 145 | 
  | 
 | 
| 146 | 
< | 
} | 
| 146 | 
> | 
  } | 
| 147 | 
  | 
 | 
| 148 | 
< | 
  BitSet SelectionEvaluator::expression(const std::vector<Token>& code, int pcStart) { | 
| 149 | 
< | 
    BitSet bs; | 
| 150 | 
< | 
    std::stack<BitSet> stack; | 
| 151 | 
< | 
     | 
| 152 | 
< | 
    for (int pc = pcStart; pc < code.size(); ++pc) { | 
| 148 | 
> | 
  OpenMDBitSet SelectionEvaluator::expression(const std::vector<Token>& code,  | 
| 149 | 
> | 
                                             int pcStart) { | 
| 150 | 
> | 
    OpenMDBitSet bs; | 
| 151 | 
> | 
    std::stack<OpenMDBitSet> stack;  | 
| 152 | 
> | 
    | 
| 153 | 
> | 
    for (unsigned int pc = pcStart; pc < code.size(); ++pc) { | 
| 154 | 
  | 
      Token instruction = code[pc]; | 
| 155 | 
  | 
 | 
| 156 | 
  | 
      switch (instruction.tok) { | 
| 159 | 
  | 
      case Token::expressionEnd: | 
| 160 | 
  | 
        break; | 
| 161 | 
  | 
      case Token::all: | 
| 162 | 
< | 
        bs = BitSet(nStuntDouble); | 
| 154 | 
< | 
        bs.setAll(); | 
| 162 | 
> | 
        bs = allInstruction(); | 
| 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: | 
| 175 | 
– | 
 | 
| 183 | 
  | 
        withinInstruction(instruction, stack.top()); | 
| 184 | 
  | 
        break; | 
| 185 | 
< | 
      //case Token::selected: | 
| 186 | 
< | 
      //  stack.push(getSelectionSet()); | 
| 187 | 
< | 
      //  break; | 
| 185 | 
> | 
      case Token::hull: | 
| 186 | 
> | 
        stack.push(hull()); | 
| 187 | 
> | 
        break; | 
| 188 | 
> | 
        //case Token::selected: | 
| 189 | 
> | 
        //  stack.push(getSelectionSet()); | 
| 190 | 
> | 
        //  break; | 
| 191 | 
  | 
      case Token::name: | 
| 192 | 
  | 
        stack.push(nameInstruction(boost::any_cast<std::string>(instruction.value))); | 
| 193 | 
  | 
        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; | 
| 215 | 
< | 
    BitSet bs(nStuntDouble); | 
| 224 | 
> | 
    OpenMDBitSet bs(nStuntDouble); | 
| 225 | 
  | 
    bs.clearAll(); | 
| 226 | 
  | 
     | 
| 227 | 
  | 
    SimInfo::MoleculeIterator mi; | 
| 230 | 
  | 
    Atom* atom; | 
| 231 | 
  | 
    Molecule::RigidBodyIterator rbIter; | 
| 232 | 
  | 
    RigidBody* rb; | 
| 224 | 
– | 
     | 
| 225 | 
– | 
    for (mol = info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) { | 
| 233 | 
  | 
 | 
| 234 | 
< | 
        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { | 
| 235 | 
< | 
            compareProperty(atom, bs, property, comparator, comparisonValue); | 
| 236 | 
< | 
        } | 
| 237 | 
< | 
         | 
| 238 | 
< | 
        //change the positions of atoms which belong to the rigidbodies | 
| 239 | 
< | 
        for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { | 
| 240 | 
< | 
            compareProperty(rb, bs, property, comparator, comparisonValue); | 
| 241 | 
< | 
        }         | 
| 234 | 
> | 
    for (mol = info->beginMolecule(mi); mol != NULL;  | 
| 235 | 
> | 
         mol = info->nextMolecule(mi)) { | 
| 236 | 
> | 
 | 
| 237 | 
> | 
      for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { | 
| 238 | 
> | 
        compareProperty(atom, bs, property, comparator, comparisonValue); | 
| 239 | 
> | 
      } | 
| 240 | 
> | 
      | 
| 241 | 
> | 
      for (rb = mol->beginRigidBody(rbIter); rb != NULL;  | 
| 242 | 
> | 
           rb = mol->nextRigidBody(rbIter)) { | 
| 243 | 
> | 
        compareProperty(rb, bs, property, comparator, comparisonValue); | 
| 244 | 
> | 
      } | 
| 245 | 
  | 
    } | 
| 246 | 
  | 
 | 
| 247 | 
  | 
    return bs; | 
| 248 | 
< | 
} | 
| 248 | 
> | 
  } | 
| 249 | 
  | 
 | 
| 250 | 
< | 
void SelectionEvaluator::compareProperty(StuntDouble* sd, BitSet& bs, int property, int comparator, float comparisonValue) { | 
| 251 | 
< | 
        double propertyValue; | 
| 252 | 
< | 
        switch (property) { | 
| 253 | 
< | 
        case Token::mass: | 
| 254 | 
< | 
            propertyValue = sd->getMass(); | 
| 255 | 
< | 
            break; | 
| 256 | 
< | 
        case Token::charge: | 
| 257 | 
< | 
            return; | 
| 258 | 
< | 
            //break; | 
| 259 | 
< | 
        case Token::dipole: | 
| 260 | 
< | 
            return; | 
| 261 | 
< | 
            //break;  | 
| 262 | 
< | 
        default: | 
| 263 | 
< | 
            unrecognizedAtomProperty(property); | 
| 264 | 
< | 
        } | 
| 250 | 
> | 
  void SelectionEvaluator::compareProperty(StuntDouble* sd, OpenMDBitSet& bs,  | 
| 251 | 
> | 
                                           int property, int comparator,  | 
| 252 | 
> | 
                                           float comparisonValue) { | 
| 253 | 
> | 
    RealType propertyValue = 0.0; | 
| 254 | 
> | 
    switch (property) { | 
| 255 | 
> | 
    case Token::mass: | 
| 256 | 
> | 
      propertyValue = sd->getMass(); | 
| 257 | 
> | 
      break; | 
| 258 | 
> | 
    case Token::charge: | 
| 259 | 
> | 
      if (sd->isAtom()){ | 
| 260 | 
> | 
        Atom* atom = static_cast<Atom*>(sd); | 
| 261 | 
> | 
        propertyValue = getCharge(atom); | 
| 262 | 
> | 
      } else if (sd->isRigidBody()) { | 
| 263 | 
> | 
        RigidBody* rb = static_cast<RigidBody*>(sd); | 
| 264 | 
> | 
        RigidBody::AtomIterator ai; | 
| 265 | 
> | 
        Atom* atom; | 
| 266 | 
> | 
        for (atom = rb->beginAtom(ai); atom != NULL; atom = rb->nextAtom(ai)) { | 
| 267 | 
> | 
          propertyValue+=  getCharge(atom); | 
| 268 | 
> | 
        } | 
| 269 | 
> | 
      } | 
| 270 | 
> | 
      break; | 
| 271 | 
> | 
    case Token::x: | 
| 272 | 
> | 
      propertyValue = sd->getPos().x(); | 
| 273 | 
> | 
      break; | 
| 274 | 
> | 
    case Token::y: | 
| 275 | 
> | 
      propertyValue = sd->getPos().y(); | 
| 276 | 
> | 
      break; | 
| 277 | 
> | 
    case Token::z: | 
| 278 | 
> | 
      propertyValue = sd->getPos().z(); | 
| 279 | 
> | 
      break; | 
| 280 | 
> | 
    case Token::r: | 
| 281 | 
> | 
      propertyValue = sd->getPos().length(); | 
| 282 | 
> | 
      break; | 
| 283 | 
> | 
    default: | 
| 284 | 
> | 
      unrecognizedAtomProperty(property); | 
| 285 | 
> | 
    } | 
| 286 | 
  | 
         | 
| 287 | 
< | 
        bool match = false; | 
| 288 | 
< | 
        switch (comparator) { | 
| 289 | 
< | 
            case Token::opLT: | 
| 290 | 
< | 
                match = propertyValue < comparisonValue; | 
| 291 | 
< | 
                break; | 
| 292 | 
< | 
            case Token::opLE: | 
| 293 | 
< | 
                match = propertyValue <= comparisonValue; | 
| 294 | 
< | 
                break; | 
| 295 | 
< | 
            case Token::opGE: | 
| 296 | 
< | 
                match = propertyValue >= comparisonValue; | 
| 297 | 
< | 
                break; | 
| 298 | 
< | 
            case Token::opGT: | 
| 299 | 
< | 
                match = propertyValue > comparisonValue; | 
| 300 | 
< | 
                break; | 
| 301 | 
< | 
            case Token::opEQ: | 
| 302 | 
< | 
                match = propertyValue == comparisonValue; | 
| 303 | 
< | 
                break; | 
| 304 | 
< | 
            case Token::opNE: | 
| 305 | 
< | 
                match = propertyValue != comparisonValue; | 
| 306 | 
< | 
                break; | 
| 307 | 
< | 
        } | 
| 308 | 
< | 
        if (match) | 
| 309 | 
< | 
            bs.setBitOn(sd->getGlobalIndex()); | 
| 310 | 
< | 
 | 
| 311 | 
< | 
} | 
| 287 | 
> | 
    bool match = false; | 
| 288 | 
> | 
    switch (comparator) { | 
| 289 | 
> | 
    case Token::opLT: | 
| 290 | 
> | 
      match = propertyValue < comparisonValue; | 
| 291 | 
> | 
      break; | 
| 292 | 
> | 
    case Token::opLE: | 
| 293 | 
> | 
      match = propertyValue <= comparisonValue; | 
| 294 | 
> | 
      break; | 
| 295 | 
> | 
    case Token::opGE: | 
| 296 | 
> | 
      match = propertyValue >= comparisonValue; | 
| 297 | 
> | 
      break; | 
| 298 | 
> | 
    case Token::opGT: | 
| 299 | 
> | 
      match = propertyValue > comparisonValue; | 
| 300 | 
> | 
      break; | 
| 301 | 
> | 
    case Token::opEQ: | 
| 302 | 
> | 
      match = propertyValue == comparisonValue; | 
| 303 | 
> | 
      break; | 
| 304 | 
> | 
    case Token::opNE: | 
| 305 | 
> | 
      match = propertyValue != comparisonValue; | 
| 306 | 
> | 
      break; | 
| 307 | 
> | 
    } | 
| 308 | 
> | 
    if (match) | 
| 309 | 
> | 
      bs.setBitOn(sd->getGlobalIndex()); | 
| 310 | 
> | 
     | 
| 311 | 
> | 
  } | 
| 312 | 
  | 
 | 
| 313 | 
< | 
void SelectionEvaluator::withinInstruction(const Token& instruction, BitSet& bs){ | 
| 313 | 
> | 
  void SelectionEvaluator::withinInstruction(const Token& instruction,  | 
| 314 | 
> | 
                                             OpenMDBitSet& bs){ | 
| 315 | 
  | 
     | 
| 316 | 
  | 
    boost::any withinSpec = instruction.value; | 
| 317 | 
  | 
    float distance; | 
| 318 | 
  | 
    if (withinSpec.type() == typeid(float)){ | 
| 319 | 
< | 
        distance = boost::any_cast<float>(withinSpec); | 
| 319 | 
> | 
      distance = boost::any_cast<float>(withinSpec); | 
| 320 | 
  | 
    } else if (withinSpec.type() == typeid(int)) { | 
| 321 | 
< | 
        distance = boost::any_cast<int>(withinSpec);     | 
| 321 | 
> | 
      distance = boost::any_cast<int>(withinSpec);     | 
| 322 | 
  | 
    } else { | 
| 323 | 
< | 
        evalError("casting error in withinInstruction"); | 
| 324 | 
< | 
        bs.clearAll(); | 
| 323 | 
> | 
      evalError("casting error in withinInstruction"); | 
| 324 | 
> | 
      bs.clearAll(); | 
| 325 | 
  | 
    } | 
| 326 | 
  | 
     | 
| 327 | 
  | 
    bs = distanceFinder.find(bs, distance);             | 
| 328 | 
< | 
} | 
| 329 | 
< | 
 | 
| 330 | 
< | 
void SelectionEvaluator::define() { | 
| 328 | 
> | 
  } | 
| 329 | 
> | 
   | 
| 330 | 
> | 
  void SelectionEvaluator::define() { | 
| 331 | 
  | 
    assert(statement.size() >= 3); | 
| 332 | 
< | 
 | 
| 332 | 
> | 
     | 
| 333 | 
  | 
    std::string variable = boost::any_cast<std::string>(statement[1].value); | 
| 334 | 
+ | 
     | 
| 335 | 
+ | 
    variables.insert(VariablesType::value_type(variable,  | 
| 336 | 
+ | 
                                               expression(statement, 2))); | 
| 337 | 
+ | 
  } | 
| 338 | 
+ | 
   | 
| 339 | 
  | 
 | 
| 340 | 
< | 
    variables.insert(std::make_pair(variable, expression(statement, 2))); | 
| 341 | 
< | 
} | 
| 342 | 
< | 
 | 
| 306 | 
< | 
 | 
| 307 | 
< | 
/** @todo */ | 
| 308 | 
< | 
void SelectionEvaluator::predefine(const std::string& script) { | 
| 309 | 
< | 
 | 
| 340 | 
> | 
  /** @todo */ | 
| 341 | 
> | 
  void SelectionEvaluator::predefine(const std::string& script) { | 
| 342 | 
> | 
     | 
| 343 | 
  | 
    if (compiler.compile("#predefine", script)) { | 
| 344 | 
< | 
        std::vector<std::vector<Token> > aatoken = compiler.getAatokenCompiled(); | 
| 345 | 
< | 
        if (aatoken.size() != 1) { | 
| 346 | 
< | 
            evalError("predefinition does not have exactly 1 command:" | 
| 347 | 
< | 
                + script); | 
| 348 | 
< | 
            return; | 
| 349 | 
< | 
        } | 
| 350 | 
< | 
        std::vector<Token> statement = aatoken[0]; | 
| 351 | 
< | 
        if (statement.size() > 2) { | 
| 352 | 
< | 
            int tok = statement[1].tok; | 
| 353 | 
< | 
            if (tok == Token::identifier || (tok & Token::predefinedset) == Token::predefinedset) { | 
| 354 | 
< | 
                std::string variable = boost::any_cast<std::string>(statement[1].value); | 
| 355 | 
< | 
                variables.insert(VariablesType::value_type(variable, statement)); | 
| 356 | 
< | 
 | 
| 357 | 
< | 
            } else { | 
| 358 | 
< | 
                evalError("invalid variable name:" + script); | 
| 359 | 
< | 
            } | 
| 360 | 
< | 
        }else { | 
| 361 | 
< | 
            evalError("bad predefinition length:" + script); | 
| 362 | 
< | 
        } | 
| 363 | 
< | 
 | 
| 344 | 
> | 
      std::vector<std::vector<Token> > aatoken = compiler.getAatokenCompiled(); | 
| 345 | 
> | 
      if (aatoken.size() != 1) { | 
| 346 | 
> | 
        evalError("predefinition does not have exactly 1 command:" | 
| 347 | 
> | 
                  + script); | 
| 348 | 
> | 
        return; | 
| 349 | 
> | 
      } | 
| 350 | 
> | 
      std::vector<Token> statement = aatoken[0]; | 
| 351 | 
> | 
      if (statement.size() > 2) { | 
| 352 | 
> | 
        int tok = statement[1].tok; | 
| 353 | 
> | 
        if (tok == Token::identifier ||  | 
| 354 | 
> | 
            (tok & Token::predefinedset) == Token::predefinedset) { | 
| 355 | 
> | 
          std::string variable = boost::any_cast<std::string>(statement[1].value); | 
| 356 | 
> | 
          variables.insert(VariablesType::value_type(variable, statement)); | 
| 357 | 
> | 
           | 
| 358 | 
> | 
        } else { | 
| 359 | 
> | 
          evalError("invalid variable name:" + script); | 
| 360 | 
> | 
        } | 
| 361 | 
> | 
      }else { | 
| 362 | 
> | 
        evalError("bad predefinition length:" + script); | 
| 363 | 
> | 
      }       | 
| 364 | 
  | 
         | 
| 365 | 
  | 
    } else { | 
| 366 | 
< | 
        evalError("predefined set compile error:" + script + | 
| 367 | 
< | 
          "\ncompile error:" + compiler.getErrorMessage()); | 
| 366 | 
> | 
      evalError("predefined set compile error:" + script + | 
| 367 | 
> | 
                "\ncompile error:" + compiler.getErrorMessage()); | 
| 368 | 
  | 
    } | 
| 369 | 
+ | 
  } | 
| 370 | 
  | 
 | 
| 371 | 
< | 
} | 
| 338 | 
< | 
 | 
| 339 | 
< | 
void SelectionEvaluator::select(BitSet& bs){ | 
| 371 | 
> | 
  void SelectionEvaluator::select(OpenMDBitSet& bs){ | 
| 372 | 
  | 
    bs = expression(statement, 1); | 
| 373 | 
< | 
} | 
| 374 | 
< | 
 | 
| 375 | 
< | 
BitSet SelectionEvaluator::lookupValue(const std::string& variable){ | 
| 376 | 
< | 
 | 
| 377 | 
< | 
    BitSet bs(nStuntDouble); | 
| 373 | 
> | 
  } | 
| 374 | 
> | 
   | 
| 375 | 
> | 
  OpenMDBitSet SelectionEvaluator::lookupValue(const std::string& variable){ | 
| 376 | 
> | 
     | 
| 377 | 
> | 
    OpenMDBitSet bs(nStuntDouble); | 
| 378 | 
  | 
    std::map<std::string, boost::any>::iterator i = variables.find(variable); | 
| 379 | 
  | 
     | 
| 380 | 
  | 
    if (i != variables.end()) { | 
| 381 | 
< | 
        if (i->second.type() == typeid(BitSet)) { | 
| 382 | 
< | 
            return boost::any_cast<BitSet>(i->second); | 
| 383 | 
< | 
        } else if (i->second.type() ==  typeid(std::vector<Token>)){ | 
| 384 | 
< | 
            bs = expression(boost::any_cast<std::vector<Token> >(i->second), 2); | 
| 385 | 
< | 
            i->second =  bs; /**@todo fixme */ | 
| 386 | 
< | 
            return bs; | 
| 387 | 
< | 
        } | 
| 381 | 
> | 
      if (i->second.type() == typeid(OpenMDBitSet)) { | 
| 382 | 
> | 
        return boost::any_cast<OpenMDBitSet>(i->second); | 
| 383 | 
> | 
      } else if (i->second.type() ==  typeid(std::vector<Token>)){ | 
| 384 | 
> | 
        bs = expression(boost::any_cast<std::vector<Token> >(i->second), 2); | 
| 385 | 
> | 
        i->second =  bs; /**@todo fixme */ | 
| 386 | 
> | 
        return bs; | 
| 387 | 
> | 
      } | 
| 388 | 
  | 
    } else { | 
| 389 | 
< | 
        unrecognizedIdentifier(variable); | 
| 389 | 
> | 
      unrecognizedIdentifier(variable); | 
| 390 | 
  | 
    } | 
| 391 | 
< | 
 | 
| 391 | 
> | 
     | 
| 392 | 
  | 
    return bs; | 
| 393 | 
< | 
} | 
| 393 | 
> | 
  } | 
| 394 | 
> | 
   | 
| 395 | 
> | 
  OpenMDBitSet SelectionEvaluator::nameInstruction(const std::string& name){     | 
| 396 | 
> | 
    return nameFinder.match(name);     | 
| 397 | 
> | 
  }     | 
| 398 | 
  | 
 | 
| 399 | 
< | 
BitSet SelectionEvaluator::nameInstruction(const std::string& name){ | 
| 364 | 
< | 
     | 
| 365 | 
< | 
    return nameFinder.match(name); | 
| 366 | 
< | 
 | 
| 367 | 
< | 
}     | 
| 368 | 
< | 
 | 
| 369 | 
< | 
bool SelectionEvaluator::containDynamicToken(const std::vector<Token>& tokens){ | 
| 399 | 
> | 
  bool SelectionEvaluator::containDynamicToken(const std::vector<Token>& tokens){ | 
| 400 | 
  | 
    std::vector<Token>::const_iterator i; | 
| 401 | 
  | 
    for (i = tokens.begin(); i != tokens.end(); ++i) { | 
| 402 | 
< | 
        if (i->tok & Token::dynamic) { | 
| 403 | 
< | 
            return true; | 
| 404 | 
< | 
        } | 
| 402 | 
> | 
      if (i->tok & Token::dynamic) { | 
| 403 | 
> | 
        return true; | 
| 404 | 
> | 
      } | 
| 405 | 
  | 
    } | 
| 406 | 
< | 
 | 
| 406 | 
> | 
     | 
| 407 | 
  | 
    return false; | 
| 408 | 
< | 
}     | 
| 408 | 
> | 
  }     | 
| 409 | 
  | 
 | 
| 410 | 
< | 
void SelectionEvaluator::clearDefinitionsAndLoadPredefined() { | 
| 410 | 
> | 
  void SelectionEvaluator::clearDefinitionsAndLoadPredefined() { | 
| 411 | 
  | 
    variables.clear(); | 
| 412 | 
  | 
    //load predefine | 
| 413 | 
  | 
    //predefine(); | 
| 414 | 
< | 
} | 
| 414 | 
> | 
  } | 
| 415 | 
  | 
 | 
| 416 | 
< | 
BitSet SelectionEvaluator::evaluate() { | 
| 417 | 
< | 
    BitSet bs(nStuntDouble); | 
| 416 | 
> | 
  OpenMDBitSet SelectionEvaluator::evaluate() { | 
| 417 | 
> | 
    OpenMDBitSet bs(nStuntDouble); | 
| 418 | 
  | 
    if (isLoaded_) { | 
| 419 | 
< | 
        pc = 0; | 
| 420 | 
< | 
        instructionDispatchLoop(bs); | 
| 419 | 
> | 
      pc = 0; | 
| 420 | 
> | 
      instructionDispatchLoop(bs); | 
| 421 | 
  | 
    } | 
| 422 | 
  | 
 | 
| 423 | 
  | 
    return bs; | 
| 424 | 
< | 
} | 
| 424 | 
> | 
  } | 
| 425 | 
  | 
 | 
| 426 | 
< | 
BitSet SelectionEvaluator::indexInstruction(const boost::any& value) { | 
| 427 | 
< | 
    BitSet bs(nStuntDouble); | 
| 426 | 
> | 
  OpenMDBitSet SelectionEvaluator::indexInstruction(const boost::any& value) { | 
| 427 | 
> | 
    OpenMDBitSet bs(nStuntDouble); | 
| 428 | 
  | 
 | 
| 429 | 
  | 
    if (value.type() == typeid(int)) { | 
| 430 | 
< | 
        int index = boost::any_cast<int>(value); | 
| 431 | 
< | 
        if (index < 0 || index >= bs.size()) { | 
| 432 | 
< | 
            invalidIndex(index); | 
| 433 | 
< | 
        } else { | 
| 434 | 
< | 
            bs.setBitOn(index); | 
| 435 | 
< | 
        } | 
| 430 | 
> | 
      int index = boost::any_cast<int>(value); | 
| 431 | 
> | 
      if (index < 0 || index >= bs.size()) { | 
| 432 | 
> | 
        invalidIndex(index); | 
| 433 | 
> | 
      } else { | 
| 434 | 
> | 
        bs = indexFinder.find(index); | 
| 435 | 
> | 
      } | 
| 436 | 
  | 
    } else if (value.type() == typeid(std::pair<int, int>)) { | 
| 437 | 
< | 
        std::pair<int, int> indexRange= boost::any_cast<std::pair<int, int> >(value); | 
| 438 | 
< | 
        assert(indexRange.first <= indexRange.second); | 
| 439 | 
< | 
        if (indexRange.first < 0 || indexRange.second >= bs.size()) { | 
| 440 | 
< | 
            invalidIndexRange(indexRange); | 
| 441 | 
< | 
        }else { | 
| 442 | 
< | 
            bs.setRangeOn(indexRange.first, indexRange.second); | 
| 443 | 
< | 
        } | 
| 437 | 
> | 
      std::pair<int, int> indexRange= boost::any_cast<std::pair<int, int> >(value); | 
| 438 | 
> | 
      assert(indexRange.first <= indexRange.second); | 
| 439 | 
> | 
      if (indexRange.first < 0 || indexRange.second >= bs.size()) { | 
| 440 | 
> | 
        invalidIndexRange(indexRange); | 
| 441 | 
> | 
      }else { | 
| 442 | 
> | 
        bs = indexFinder.find(indexRange.first, indexRange.second); | 
| 443 | 
> | 
      } | 
| 444 | 
  | 
    } | 
| 445 | 
  | 
 | 
| 446 | 
  | 
    return bs; | 
| 447 | 
< | 
} | 
| 447 | 
> | 
  } | 
| 448 | 
  | 
 | 
| 449 | 
< | 
//BitSet SelectionEvaluator::evaluate(int frameNo) { | 
| 450 | 
< | 
// | 
| 421 | 
< | 
//} | 
| 449 | 
> | 
  OpenMDBitSet SelectionEvaluator::allInstruction() { | 
| 450 | 
> | 
    OpenMDBitSet bs(nStuntDouble); | 
| 451 | 
  | 
 | 
| 452 | 
+ | 
    SimInfo::MoleculeIterator mi; | 
| 453 | 
+ | 
    Molecule* mol; | 
| 454 | 
+ | 
    Molecule::AtomIterator ai; | 
| 455 | 
+ | 
    Atom* atom; | 
| 456 | 
+ | 
    Molecule::RigidBodyIterator rbIter; | 
| 457 | 
+ | 
    RigidBody* rb; | 
| 458 | 
+ | 
 | 
| 459 | 
+ | 
    // Doing the loop insures that we're actually on this processor. | 
| 460 | 
+ | 
 | 
| 461 | 
+ | 
    for (mol = info->beginMolecule(mi); mol != NULL;  | 
| 462 | 
+ | 
         mol = info->nextMolecule(mi)) { | 
| 463 | 
+ | 
 | 
| 464 | 
+ | 
      for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { | 
| 465 | 
+ | 
        bs.setBitOn(atom->getGlobalIndex()); | 
| 466 | 
+ | 
      } | 
| 467 | 
+ | 
      | 
| 468 | 
+ | 
      for (rb = mol->beginRigidBody(rbIter); rb != NULL;  | 
| 469 | 
+ | 
           rb = mol->nextRigidBody(rbIter)) { | 
| 470 | 
+ | 
        bs.setBitOn(rb->getGlobalIndex()); | 
| 471 | 
+ | 
      } | 
| 472 | 
+ | 
    } | 
| 473 | 
+ | 
 | 
| 474 | 
+ | 
    return bs; | 
| 475 | 
+ | 
  } | 
| 476 | 
+ | 
 | 
| 477 | 
+ | 
  OpenMDBitSet SelectionEvaluator::hull() { | 
| 478 | 
+ | 
    OpenMDBitSet bs(nStuntDouble); | 
| 479 | 
+ | 
     | 
| 480 | 
+ | 
    bs = hullFinder.findHull(); | 
| 481 | 
+ | 
     | 
| 482 | 
+ | 
    return bs; | 
| 483 | 
+ | 
  } | 
| 484 | 
+ | 
 | 
| 485 | 
+ | 
  RealType SelectionEvaluator::getCharge(Atom* atom) { | 
| 486 | 
+ | 
    RealType charge =0.0; | 
| 487 | 
+ | 
    AtomType* atomType = atom->getAtomType(); | 
| 488 | 
+ | 
    if (atomType->isCharge()) { | 
| 489 | 
+ | 
      GenericData* data = atomType->getPropertyByName("Charge"); | 
| 490 | 
+ | 
      if (data != NULL) { | 
| 491 | 
+ | 
        DoubleGenericData* doubleData= dynamic_cast<DoubleGenericData*>(data); | 
| 492 | 
+ | 
 | 
| 493 | 
+ | 
        if (doubleData != NULL) { | 
| 494 | 
+ | 
          charge = doubleData->getData(); | 
| 495 | 
+ | 
 | 
| 496 | 
+ | 
        } else { | 
| 497 | 
+ | 
          sprintf( painCave.errMsg, | 
| 498 | 
+ | 
                   "Can not cast GenericData to DoubleGenericData\n"); | 
| 499 | 
+ | 
          painCave.severity = OPENMD_ERROR; | 
| 500 | 
+ | 
          painCave.isFatal = 1; | 
| 501 | 
+ | 
          simError();           | 
| 502 | 
+ | 
        } | 
| 503 | 
+ | 
      }  | 
| 504 | 
+ | 
    } | 
| 505 | 
+ | 
 | 
| 506 | 
+ | 
    return charge; | 
| 507 | 
+ | 
  } | 
| 508 | 
+ | 
 | 
| 509 | 
  | 
} |