--- trunk/src/selection/SelectionEvaluator.cpp 2005/03/09 17:30:29 413 +++ trunk/src/selection/SelectionEvaluator.cpp 2005/03/11 15:00:20 432 @@ -86,9 +86,6 @@ void SelectionEvaluator::clearState() { } void SelectionEvaluator::clearState() { - //for (int i = scriptLevelMax; --i >= 0; ) - // stack[i].clear(); - //scriptLevel = 0; error = false; errorMessage = ""; } @@ -230,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); } @@ -240,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); } @@ -403,7 +406,7 @@ BitSet SelectionEvaluator::indexInstruction(const boos if (index < 0 || index >= bs.size()) { invalidIndex(index); } else { - indexFinder.find(index); + bs = indexFinder.find(index); } } else if (value.type() == typeid(std::pair)) { std::pair indexRange= boost::any_cast >(value); @@ -411,11 +414,36 @@ BitSet SelectionEvaluator::indexInstruction(const boos if (indexRange.first < 0 || indexRange.second >= bs.size()) { invalidIndexRange(indexRange); }else { - indexFinder.find(indexRange.first, indexRange.second); + bs = indexFinder.find(indexRange.first, indexRange.second); } } return bs; } + +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; } + +}