--- trunk/src/selection/SelectionEvaluator.cpp 2005/02/07 19:13:18 295 +++ trunk/src/selection/SelectionEvaluator.cpp 2005/03/11 15:00:20 432 @@ -49,7 +49,9 @@ namespace oopse { namespace oopse { -SelectionEvaluator::SelectionEvaluator(SimInfo* si) : info(si), nameFinder(info), distanceFinder(info), isLoaded_(false){ +SelectionEvaluator::SelectionEvaluator(SimInfo* si) + : info(si), nameFinder(info), distanceFinder(info), indexFinder(info), isLoaded_(false){ + nStuntDouble = info->getNGlobalAtoms() + info->getNRigidBodies(); } @@ -84,9 +86,6 @@ void SelectionEvaluator::clearState() { } void SelectionEvaluator::clearState() { - //for (int i = scriptLevelMax; --i >= 0; ) - // stack[i].clear(); - //scriptLevel = 0; error = false; errorMessage = ""; } @@ -102,7 +101,7 @@ bool SelectionEvaluator::loadScriptFileInternal(const } bool SelectionEvaluator::loadScriptFileInternal(const std::string & filename) { - ifstream ifs(filename.c_str()); + std::ifstream ifs(filename.c_str()); if (!ifs.is_open()) { return false; } @@ -228,7 +227,6 @@ BitSet SelectionEvaluator::comparatorInstruction(const compareProperty(atom, bs, property, comparator, comparisonValue); } - //change the positions of atoms which belong to the rigidbodies for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { compareProperty(rb, bs, property, comparator, comparisonValue); } @@ -238,17 +236,24 @@ void SelectionEvaluator::compareProperty(StuntDouble* } void SelectionEvaluator::compareProperty(StuntDouble* sd, BitSet& bs, int property, int comparator, float comparisonValue) { - double propertyValue; + double propertyValue = 0.0; switch (property) { case Token::mass: propertyValue = sd->getMass(); break; case Token::charge: - return; - //break; - case Token::dipole: - return; - //break; + if (sd->isAtom()){ + Atom* atom = static_cast(sd); + propertyValue = getCharge(atom); + } else if (sd->isRigidBody()) { + RigidBody* rb = static_cast(sd); + RigidBody::AtomIterator ai; + Atom* atom; + for (atom = rb->beginAtom(ai); atom != NULL; atom = rb->nextAtom(ai)) { + propertyValue+= getCharge(atom); + } + } + break; default: unrecognizedAtomProperty(property); } @@ -300,7 +305,7 @@ void SelectionEvaluator::define() { std::string variable = boost::any_cast(statement[1].value); - variables.insert(std::make_pair(variable, expression(statement, 2))); + variables.insert(VariablesType::value_type(variable, expression(statement, 2))); } @@ -319,7 +324,7 @@ void SelectionEvaluator::predefine(const std::string& int tok = statement[1].tok; if (tok == Token::identifier || (tok & Token::predefinedset) == Token::predefinedset) { std::string variable = boost::any_cast(statement[1].value); - variables.insert(std::make_pair(variable, statement)); + variables.insert(VariablesType::value_type(variable, statement)); } else { evalError("invalid variable name:" + script); @@ -386,6 +391,7 @@ BitSet SelectionEvaluator::evaluate() { BitSet SelectionEvaluator::evaluate() { BitSet bs(nStuntDouble); if (isLoaded_) { + pc = 0; instructionDispatchLoop(bs); } @@ -400,7 +406,7 @@ BitSet SelectionEvaluator::indexInstruction(const boos if (index < 0 || index >= bs.size()) { invalidIndex(index); } else { - bs.setBitOn(index); + bs = indexFinder.find(index); } } else if (value.type() == typeid(std::pair)) { std::pair indexRange= boost::any_cast >(value); @@ -408,15 +414,36 @@ BitSet SelectionEvaluator::indexInstruction(const boos if (indexRange.first < 0 || indexRange.second >= bs.size()) { invalidIndexRange(indexRange); }else { - bs.setRangeOn(indexRange.first, indexRange.second); + bs = indexFinder.find(indexRange.first, indexRange.second); } } return bs; } -//BitSet SelectionEvaluator::evaluate(int frameNo) { -// -//} +double SelectionEvaluator::getCharge(Atom* atom) { + double charge =0.0; + AtomType* atomType = atom->getAtomType(); + if (atomType->isCharge()) { + GenericData* data = atomType->getPropertyByName("Charge"); + if (data != NULL) { + DoubleGenericData* doubleData= dynamic_cast(data); + + if (doubleData != NULL) { + charge = doubleData->getData(); + + } else { + sprintf( painCave.errMsg, + "Can not cast GenericData to DoubleGenericData\n"); + painCave.severity = OOPSE_ERROR; + painCave.isFatal = 1; + simError(); + } + } + } + + return charge; } + +}