double ReferenceCustomDynamics::computeKineticEnergy(OpenMM::ContextImpl& context, int numberOfAtoms, std::vector<OpenMM::RealVec>& atomCoordinates, std::vector<OpenMM::RealVec>& velocities, std::vector<OpenMM::RealVec>& forces, std::vector<RealOpenMM>& masses, std::map<std::string, RealOpenMM>& globals, std::vector<std::vector<OpenMM::RealVec> >& perDof, bool& forcesAreValid) { globals.insert(context.getParameters().begin(), context.getParameters().end()); if (kineticEnergyNeedsForce) { energy = context.calcForcesAndEnergy(true, true, -1); forcesAreValid = true; } computePerDof(numberOfAtoms, sumBuffer, atomCoordinates, velocities, forces, masses, globals, perDof, kineticEnergyExpression, "f"); RealOpenMM sum = 0.0; for (int j = 0; j < numberOfAtoms; j++) if (masses[j] != 0.0) sum += sumBuffer[j][0]+sumBuffer[j][1]+sumBuffer[j][2]; return sum; }
/** * Check which context parameters have changed and register them with the context. */ void ReferenceCustomDynamics::recordChangedParameters(OpenMM::ContextImpl& context, std::map<std::string, RealOpenMM>& globals) { for (map<string, double>::const_iterator iter = context.getParameters().begin(); iter != context.getParameters().end(); ++iter) { string name = iter->first; double value = globals[name]; if (value != iter->second) context.setParameter(name, globals[name]); } }
double ReferenceCustomDynamics::computeKineticEnergy(OpenMM::ContextImpl& context, int numberOfAtoms, std::vector<OpenMM::RealVec>& atomCoordinates, std::vector<OpenMM::RealVec>& velocities, std::vector<OpenMM::RealVec>& forces, std::vector<RealOpenMM>& masses, std::map<std::string, RealOpenMM>& globals, std::vector<std::vector<OpenMM::RealVec> >& perDof, bool& forcesAreValid) { if (invalidatesForces.size() == 0) initialize(context, masses, globals); globals.insert(context.getParameters().begin(), context.getParameters().end()); for (map<string, RealOpenMM>::const_iterator iter = globals.begin(); iter != globals.end(); ++iter) expressionSet.setVariable(expressionSet.getVariableIndex(iter->first), iter->second); if (kineticEnergyNeedsForce) { energy = context.calcForcesAndEnergy(true, true, -1); forcesAreValid = true; } computePerDof(numberOfAtoms, sumBuffer, atomCoordinates, velocities, forces, masses, perDof, kineticEnergyExpression); RealOpenMM sum = 0.0; for (int j = 0; j < numberOfAtoms; j++) if (masses[j] != 0.0) sum += sumBuffer[j][0]+sumBuffer[j][1]+sumBuffer[j][2]; return sum; }