--- trunk/src/restraints/RestraintForceManager.cpp 2009/09/07 16:31:51 1360 +++ trunk/src/restraints/RestraintForceManager.cpp 2009/10/16 20:42:29 1366 @@ -78,8 +78,8 @@ namespace oopse { restTime_ = simParam->getStatusTime(); } else { sprintf(painCave.errMsg, - "Restraint warning: If you use restraints without setting\n", - "\tstatusTime, no restraint data will be written to the rest\n", + "Restraint warning: If you use restraints without setting\n" + "\tstatusTime, no restraint data will be written to the rest\n" "\tfile.\n"); painCave.isFatal = 0; simError(); @@ -109,15 +109,44 @@ namespace oopse { molIndex = stamp[i]->getMolIndex(); } - Molecule* mol = info_->getMoleculeByGlobalIndex(molIndex); - - if (mol == NULL) { + if (molIndex < 0) { sprintf(painCave.errMsg, - "Restraint Error: A molecular restraint was specified, but\n" - "\tno molecule was found with global index %d.\n", - molIndex); + "Restraint Error: A molecular restraint was specified\n" + "\twith a molIndex that was less than 0\n"); painCave.isFatal = 1; simError(); + } + if (molIndex >= info_->getNGlobalMolecules()) { + sprintf(painCave.errMsg, + "Restraint Error: A molecular restraint was specified with\n" + "\ta molIndex that was greater than the total number of molecules\n"); + painCave.isFatal = 1; + simError(); + } + + Molecule* mol = info_->getMoleculeByGlobalIndex(molIndex); + + if (mol == NULL) { +#ifdef IS_MPI + // getMoleculeByGlobalIndex returns a NULL in parallel if + // this proc doesn't have the molecule. Do a quick check to + // make sure another processor is supposed to have it. + + int myrank = MPI::COMM_WORLD.Get_rank(); + if (info_->getMolToProc(molIndex) == myrank) { + // If we were supposed to have it but got a null, then freak out. +#endif + + sprintf(painCave.errMsg, + "Restraint Error: A molecular restraint was specified, but\n" + "\tno molecule was found with global index %d.\n", + molIndex); + painCave.isFatal = 1; + simError(); + +#ifdef IS_MPI + } +#endif } MolecularRestraint* rest = new MolecularRestraint(); @@ -148,6 +177,9 @@ namespace oopse { if (stamp[i]->haveRestrainedSwingXAngle()) { rest->setRestrainedSwingXAngle(stamp[i]->getRestrainedSwingXAngle() * M_PI/180.0); } + if (stamp[i]->havePrint()) { + rest->setPrintRestraint(stamp[i]->getPrint()); + } restraints_.push_back(rest); mol->addProperty(new RestraintData("Restraint", rest)); @@ -170,7 +202,7 @@ namespace oopse { SelectionEvaluator evaluator(info); SelectionManager seleMan(info); - + evaluator.loadScriptString(objectSelection); seleMan.setSelectionSet(evaluator.evaluate()); int selectionCount = seleMan.getSelectionCount(); @@ -211,7 +243,11 @@ namespace oopse { } if (stamp[i]->haveRestrainedSwingYAngle()) { rest->setRestrainedSwingYAngle(stamp[i]->getRestrainedSwingYAngle()); - } + } + if (stamp[i]->havePrint()) { + rest->setPrintRestraint(stamp[i]->getPrint()); + } + restraints_.push_back(rest); sd->addProperty(new RestraintData("Restraint", rest)); restrainedObjs_.push_back(sd); @@ -357,7 +393,10 @@ namespace oopse { unscaledPotential_ += mRest->getUnscaledPotential(); restInfo = mRest->getRestraintInfo(); - restInfo_.push_back(restInfo); + + // only collect data on restraints that we're going to print: + if (mRest->getPrintRestraint()) + restInfo_.push_back(restInfo); } for(ro=restrainedObjs_.begin(); ro != restrainedObjs_.end(); ++ro){ @@ -418,7 +457,10 @@ namespace oopse { unscaledPotential_ += oRest->getUnscaledPotential(); restInfo = oRest->getRestraintInfo(); - restInfo_.push_back(restInfo); + + // only collect data on restraints that we're going to print: + if (oRest->getPrintRestraint()) + restInfo_.push_back(restInfo); } return unscaledPotential_ * scalingFactor;