Commit 0a2439ce authored by Rafal P. Wiewiora's avatar Rafal P. Wiewiora
Browse files

Merge branch 'master' of https://github.com/rafwiewiora/openmm

parents c29de611 6ed5bc4e
...@@ -105,8 +105,8 @@ extern "C" __global__ void computeDonorForces(unsigned long long* __restrict__ f ...@@ -105,8 +105,8 @@ extern "C" __global__ void computeDonorForces(unsigned long long* __restrict__ f
__syncthreads(); __syncthreads();
if (donorIndex < NUM_DONORS) { if (donorIndex < NUM_DONORS) {
for (int index = 0; index < blockSize; index++) { for (int index = 0; index < blockSize; index++) {
#ifdef USE_EXCLUSIONS
int acceptorIndex = acceptorStart+index; int acceptorIndex = acceptorStart+index;
#ifdef USE_EXCLUSIONS
if (acceptorIndex == exclusionIndices.x || acceptorIndex == exclusionIndices.y || acceptorIndex == exclusionIndices.z || acceptorIndex == exclusionIndices.w) if (acceptorIndex == exclusionIndices.x || acceptorIndex == exclusionIndices.y || acceptorIndex == exclusionIndices.z || acceptorIndex == exclusionIndices.w)
continue; continue;
#endif #endif
...@@ -193,8 +193,8 @@ extern "C" __global__ void computeAcceptorForces(unsigned long long* __restrict_ ...@@ -193,8 +193,8 @@ extern "C" __global__ void computeAcceptorForces(unsigned long long* __restrict_
__syncthreads(); __syncthreads();
if (acceptorIndex < NUM_ACCEPTORS) { if (acceptorIndex < NUM_ACCEPTORS) {
for (int index = 0; index < blockSize; index++) { for (int index = 0; index < blockSize; index++) {
#ifdef USE_EXCLUSIONS
int donorIndex = donorStart+index; int donorIndex = donorStart+index;
#ifdef USE_EXCLUSIONS
if (donorIndex == exclusionIndices.x || donorIndex == exclusionIndices.y || donorIndex == exclusionIndices.z || donorIndex == exclusionIndices.w) if (donorIndex == exclusionIndices.x || donorIndex == exclusionIndices.y || donorIndex == exclusionIndices.z || donorIndex == exclusionIndices.w)
continue; continue;
#endif #endif
......
...@@ -184,8 +184,7 @@ void OpenCLBondedUtilities::initialize(const System& system) { ...@@ -184,8 +184,7 @@ void OpenCLBondedUtilities::initialize(const System& system) {
// Create the kernels. // Create the kernels.
for (vector<vector<int> >::const_iterator iter = forceSets.begin(); iter != forceSets.end(); ++iter) { for (auto& set : forceSets) {
const vector<int>& set = *iter;
int setSize = set.size(); int setSize = set.size();
stringstream s; stringstream s;
s<<"#ifdef SUPPORTS_64_BIT_ATOMICS\n"; s<<"#ifdef SUPPORTS_64_BIT_ATOMICS\n";
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for * * Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2009-2016 Stanford University and the Authors. * * Portions copyright (c) 2009-2017 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -318,8 +318,8 @@ OpenCLContext::OpenCLContext(const System& system, int platformIndex, int device ...@@ -318,8 +318,8 @@ OpenCLContext::OpenCLContext(const System& system, int platformIndex, int device
OpenCLArray valuesArray(*this, 20, sizeof(mm_float8), "values"); OpenCLArray valuesArray(*this, 20, sizeof(mm_float8), "values");
vector<mm_float8> values(valuesArray.getSize()); vector<mm_float8> values(valuesArray.getSize());
float nextValue = 1e-4f; float nextValue = 1e-4f;
for (int i = 0; i < (int) values.size(); ++i) { for (auto& val : values) {
values[i].s0 = nextValue; val.s0 = nextValue;
nextValue *= (float) M_PI; nextValue *= (float) M_PI;
} }
valuesArray.upload(values); valuesArray.upload(values);
...@@ -328,14 +328,14 @@ OpenCLContext::OpenCLContext(const System& system, int platformIndex, int device ...@@ -328,14 +328,14 @@ OpenCLContext::OpenCLContext(const System& system, int platformIndex, int device
executeKernel(accuracyKernel, values.size()); executeKernel(accuracyKernel, values.size());
valuesArray.download(values); valuesArray.download(values);
double maxSqrtError = 0.0, maxRsqrtError = 0.0, maxRecipError = 0.0, maxExpError = 0.0, maxLogError = 0.0; double maxSqrtError = 0.0, maxRsqrtError = 0.0, maxRecipError = 0.0, maxExpError = 0.0, maxLogError = 0.0;
for (int i = 0; i < (int) values.size(); ++i) { for (auto& val : values) {
double v = values[i].s0; double v = val.s0;
double correctSqrt = sqrt(v); double correctSqrt = sqrt(v);
maxSqrtError = max(maxSqrtError, fabs(correctSqrt-values[i].s1)/correctSqrt); maxSqrtError = max(maxSqrtError, fabs(correctSqrt-val.s1)/correctSqrt);
maxRsqrtError = max(maxRsqrtError, fabs(1.0/correctSqrt-values[i].s2)*correctSqrt); maxRsqrtError = max(maxRsqrtError, fabs(1.0/correctSqrt-val.s2)*correctSqrt);
maxRecipError = max(maxRecipError, fabs(1.0/v-values[i].s3)/values[i].s3); maxRecipError = max(maxRecipError, fabs(1.0/v-val.s3)/val.s3);
maxExpError = max(maxExpError, fabs(exp(v)-values[i].s4)/values[i].s4); maxExpError = max(maxExpError, fabs(exp(v)-val.s4)/val.s4);
maxLogError = max(maxLogError, fabs(log(v)-values[i].s5)/values[i].s5); maxLogError = max(maxLogError, fabs(log(v)-val.s5)/val.s5);
} }
compilationDefines["SQRT"] = (maxSqrtError < 1e-6) ? "native_sqrt" : "sqrt"; compilationDefines["SQRT"] = (maxSqrtError < 1e-6) ? "native_sqrt" : "sqrt";
compilationDefines["RSQRT"] = (maxRsqrtError < 1e-6) ? "native_rsqrt" : "rsqrt"; compilationDefines["RSQRT"] = (maxRsqrtError < 1e-6) ? "native_rsqrt" : "rsqrt";
...@@ -412,14 +412,14 @@ OpenCLContext::OpenCLContext(const System& system, int platformIndex, int device ...@@ -412,14 +412,14 @@ OpenCLContext::OpenCLContext(const System& system, int platformIndex, int device
} }
OpenCLContext::~OpenCLContext() { OpenCLContext::~OpenCLContext() {
for (int i = 0; i < (int) forces.size(); i++) for (auto force : forces)
delete forces[i]; delete force;
for (int i = 0; i < (int) reorderListeners.size(); i++) for (auto listener : reorderListeners)
delete reorderListeners[i]; delete listener;
for (int i = 0; i < (int) preComputations.size(); i++) for (auto computation : preComputations)
delete preComputations[i]; delete computation;
for (int i = 0; i < (int) postComputations.size(); i++) for (auto computation : postComputations)
delete postComputations[i]; delete computation;
if (pinnedBuffer != NULL) if (pinnedBuffer != NULL)
delete pinnedBuffer; delete pinnedBuffer;
if (posq != NULL) if (posq != NULL)
...@@ -458,8 +458,8 @@ void OpenCLContext::initialize() { ...@@ -458,8 +458,8 @@ void OpenCLContext::initialize() {
bonded->initialize(system); bonded->initialize(system);
numForceBuffers = platformData.contexts.size(); numForceBuffers = platformData.contexts.size();
numForceBuffers = std::max(numForceBuffers, bonded->getNumForceBuffers()); numForceBuffers = std::max(numForceBuffers, bonded->getNumForceBuffers());
for (int i = 0; i < (int) forces.size(); i++) for (auto force : forces)
numForceBuffers = std::max(numForceBuffers, forces[i]->getRequiredForceBuffers()); numForceBuffers = std::max(numForceBuffers, force->getRequiredForceBuffers());
int energyBufferSize = max(numThreadBlocks*ThreadBlockSize, nonbonded->getNumEnergyBuffers()); int energyBufferSize = max(numThreadBlocks*ThreadBlockSize, nonbonded->getNumEnergyBuffers());
if (useDoublePrecision) { if (useDoublePrecision) {
forceBuffers = OpenCLArray::create<mm_double4>(*this, paddedNumAtoms*numForceBuffers, "forceBuffers"); forceBuffers = OpenCLArray::create<mm_double4>(*this, paddedNumAtoms*numForceBuffers, "forceBuffers");
...@@ -525,17 +525,17 @@ string OpenCLContext::replaceStrings(const string& input, const std::map<std::st ...@@ -525,17 +525,17 @@ string OpenCLContext::replaceStrings(const string& input, const std::map<std::st
symbolChars.insert(c); symbolChars.insert(c);
} }
string result = input; string result = input;
for (map<string, string>::const_iterator iter = replacements.begin(); iter != replacements.end(); iter++) { for (auto& pair : replacements) {
int index = 0; int index = 0;
int size = iter->first.size(); int size = pair.first.size();
do { do {
index = result.find(iter->first, index); index = result.find(pair.first, index);
if (index != result.npos) { if (index != result.npos) {
if ((index == 0 || symbolChars.find(result[index-1]) == symbolChars.end()) && (index == result.size()-size || symbolChars.find(result[index+size]) == symbolChars.end())) { if ((index == 0 || symbolChars.find(result[index-1]) == symbolChars.end()) && (index == result.size()-size || symbolChars.find(result[index+size]) == symbolChars.end())) {
// We have found a complete symbol, not part of a longer symbol. // We have found a complete symbol, not part of a longer symbol.
result.replace(index, size, iter->second); result.replace(index, size, pair.second);
index += iter->second.size(); index += pair.second.size();
} }
else else
index++; index++;
...@@ -554,10 +554,10 @@ cl::Program OpenCLContext::createProgram(const string source, const map<string, ...@@ -554,10 +554,10 @@ cl::Program OpenCLContext::createProgram(const string source, const map<string,
stringstream src; stringstream src;
if (!options.empty()) if (!options.empty())
src << "// Compilation Options: " << options << endl << endl; src << "// Compilation Options: " << options << endl << endl;
for (map<string, string>::const_iterator iter = compilationDefines.begin(); iter != compilationDefines.end(); ++iter) { for (auto& pair : compilationDefines) {
src << "#define " << iter->first; src << "#define " << pair.first;
if (!iter->second.empty()) if (!pair.second.empty())
src << " " << iter->second; src << " " << pair.second;
src << endl; src << endl;
} }
if (!compilationDefines.empty()) if (!compilationDefines.empty())
...@@ -588,10 +588,10 @@ cl::Program OpenCLContext::createProgram(const string source, const map<string, ...@@ -588,10 +588,10 @@ cl::Program OpenCLContext::createProgram(const string source, const map<string,
src << "typedef float3 mixed3;\n"; src << "typedef float3 mixed3;\n";
src << "typedef float4 mixed4;\n"; src << "typedef float4 mixed4;\n";
} }
for (map<string, string>::const_iterator iter = defines.begin(); iter != defines.end(); ++iter) { for (auto& pair : defines) {
src << "#define " << iter->first; src << "#define " << pair.first;
if (!iter->second.empty()) if (!pair.second.empty())
src << " " << iter->second; src << " " << pair.second;
src << endl; src << endl;
} }
if (!defines.empty()) if (!defines.empty())
...@@ -856,10 +856,10 @@ void OpenCLContext::findMoleculeGroups() { ...@@ -856,10 +856,10 @@ void OpenCLContext::findMoleculeGroups() {
atomBonds[particle1].push_back(particle2); atomBonds[particle1].push_back(particle2);
atomBonds[particle2].push_back(particle1); atomBonds[particle2].push_back(particle1);
} }
for (int i = 0; i < (int) forces.size(); i++) { for (auto force : forces) {
for (int j = 0; j < forces[i]->getNumParticleGroups(); j++) { for (int j = 0; j < force->getNumParticleGroups(); j++) {
vector<int> particles; vector<int> particles;
forces[i]->getParticlesInGroup(j, particles); force->getParticlesInGroup(j, particles);
for (int k = 0; k < (int) particles.size(); k++) for (int k = 0; k < (int) particles.size(); k++)
for (int m = 0; m < (int) particles.size(); m++) for (int m = 0; m < (int) particles.size(); m++)
if (k != m) if (k != m)
...@@ -1076,8 +1076,8 @@ bool OpenCLContext::invalidateMolecules(OpenCLForceInfo* force) { ...@@ -1076,8 +1076,8 @@ bool OpenCLContext::invalidateMolecules(OpenCLForceInfo* force) {
} }
atomIndexDevice->upload(atomIndex); atomIndexDevice->upload(atomIndex);
findMoleculeGroups(); findMoleculeGroups();
for (int i = 0; i < (int) reorderListeners.size(); i++) for (auto listener : reorderListeners)
reorderListeners[i]->execute(); listener->execute();
reorderAtoms(); reorderAtoms();
return true; return true;
} }
...@@ -1138,10 +1138,9 @@ void OpenCLContext::reorderAtomsImpl() { ...@@ -1138,10 +1138,9 @@ void OpenCLContext::reorderAtomsImpl() {
vector<Real4> newPosqCorrection(paddedNumAtoms, Real4(0,0,0,0)); vector<Real4> newPosqCorrection(paddedNumAtoms, Real4(0,0,0,0));
vector<Mixed4> newVelm(paddedNumAtoms, Mixed4(0,0,0,0)); vector<Mixed4> newVelm(paddedNumAtoms, Mixed4(0,0,0,0));
vector<mm_int4> newCellOffsets(numAtoms); vector<mm_int4> newCellOffsets(numAtoms);
for (int group = 0; group < (int) moleculeGroups.size(); group++) { for (auto& mol : moleculeGroups) {
// Find the center of each molecule. // Find the center of each molecule.
MoleculeGroup& mol = moleculeGroups[group];
int numMolecules = mol.offsets.size(); int numMolecules = mol.offsets.size();
vector<int>& atoms = mol.atoms; vector<int>& atoms = mol.atoms;
vector<Real4> molPos(numMolecules); vector<Real4> molPos(numMolecules);
...@@ -1235,9 +1234,9 @@ void OpenCLContext::reorderAtomsImpl() { ...@@ -1235,9 +1234,9 @@ void OpenCLContext::reorderAtomsImpl() {
// Reorder the atoms. // Reorder the atoms.
for (int i = 0; i < numMolecules; i++) { for (int i = 0; i < numMolecules; i++) {
for (int j = 0; j < (int)atoms.size(); j++) { for (int atom : atoms) {
int oldIndex = mol.offsets[molBins[i].second]+atoms[j]; int oldIndex = mol.offsets[molBins[i].second]+atom;
int newIndex = mol.offsets[i]+atoms[j]; int newIndex = mol.offsets[i]+atom;
originalIndex[newIndex] = atomIndex[oldIndex]; originalIndex[newIndex] = atomIndex[oldIndex];
newPosq[newIndex] = oldPosq[oldIndex]; newPosq[newIndex] = oldPosq[oldIndex];
if (useMixedPrecision) if (useMixedPrecision)
...@@ -1259,8 +1258,8 @@ void OpenCLContext::reorderAtomsImpl() { ...@@ -1259,8 +1258,8 @@ void OpenCLContext::reorderAtomsImpl() {
posqCorrection->upload(newPosqCorrection); posqCorrection->upload(newPosqCorrection);
velm->upload(newVelm); velm->upload(newVelm);
atomIndexDevice->upload(atomIndex); atomIndexDevice->upload(atomIndex);
for (int i = 0; i < (int) reorderListeners.size(); i++) for (auto listener : reorderListeners)
reorderListeners[i]->execute(); listener->execute();
} }
void OpenCLContext::addReorderListener(ReorderListener* listener) { void OpenCLContext::addReorderListener(ReorderListener* listener) {
......
...@@ -448,12 +448,12 @@ void OpenCLExpressionUtilities::processExpression(stringstream& out, const Expre ...@@ -448,12 +448,12 @@ void OpenCLExpressionUtilities::processExpression(stringstream& out, const Expre
vector<bool> hasAssigned(powers.size(), false); vector<bool> hasAssigned(powers.size(), false);
exponents.push_back((int) fabs(exponent)); exponents.push_back((int) fabs(exponent));
names.push_back(name); names.push_back(name);
for (map<int, const ExpressionTreeNode*>::const_iterator iter = powers.begin(); iter != powers.end(); ++iter) { for (auto& power : powers) {
if (iter->first != exponent) { if (power.first != exponent) {
exponents.push_back(iter->first >= 0 ? iter->first : -iter->first); exponents.push_back(power.first >= 0 ? power.first : -power.first);
string name2 = prefix+context.intToString(temps.size()); string name2 = prefix+context.intToString(temps.size());
names.push_back(name2); names.push_back(name2);
temps.push_back(make_pair(*iter->second, name2)); temps.push_back(make_pair(*power.second, name2));
out << tempType << " " << name2 << " = 0.0f;\n"; out << tempType << " " << name2 << " = 0.0f;\n";
} }
} }
......
This diff is collapsed.
...@@ -91,8 +91,8 @@ __kernel void computeDonorForces(__global real4* restrict forceBuffers, __global ...@@ -91,8 +91,8 @@ __kernel void computeDonorForces(__global real4* restrict forceBuffers, __global
barrier(CLK_LOCAL_MEM_FENCE); barrier(CLK_LOCAL_MEM_FENCE);
if (donorIndex < NUM_DONORS) { if (donorIndex < NUM_DONORS) {
for (int index = 0; index < blockSize; index++) { for (int index = 0; index < blockSize; index++) {
#ifdef USE_EXCLUSIONS
int acceptorIndex = acceptorStart+index; int acceptorIndex = acceptorStart+index;
#ifdef USE_EXCLUSIONS
if (acceptorIndex == exclusionIndices.x || acceptorIndex == exclusionIndices.y || acceptorIndex == exclusionIndices.z || acceptorIndex == exclusionIndices.w) if (acceptorIndex == exclusionIndices.x || acceptorIndex == exclusionIndices.y || acceptorIndex == exclusionIndices.z || acceptorIndex == exclusionIndices.w)
continue; continue;
#endif #endif
...@@ -179,8 +179,8 @@ __kernel void computeAcceptorForces(__global real4* restrict forceBuffers, __glo ...@@ -179,8 +179,8 @@ __kernel void computeAcceptorForces(__global real4* restrict forceBuffers, __glo
barrier(CLK_LOCAL_MEM_FENCE); barrier(CLK_LOCAL_MEM_FENCE);
if (acceptorIndex < NUM_ACCEPTORS) { if (acceptorIndex < NUM_ACCEPTORS) {
for (int index = 0; index < blockSize; index++) { for (int index = 0; index < blockSize; index++) {
#ifdef USE_EXCLUSIONS
int donorIndex = donorStart+index; int donorIndex = donorStart+index;
#ifdef USE_EXCLUSIONS
if (donorIndex == exclusionIndices.x || donorIndex == exclusionIndices.y || donorIndex == exclusionIndices.z || donorIndex == exclusionIndices.w) if (donorIndex == exclusionIndices.x || donorIndex == exclusionIndices.y || donorIndex == exclusionIndices.z || donorIndex == exclusionIndices.w)
continue; continue;
#endif #endif
......
...@@ -159,8 +159,8 @@ static void validateVariables(const Lepton::ExpressionTreeNode& node, const set< ...@@ -159,8 +159,8 @@ static void validateVariables(const Lepton::ExpressionTreeNode& node, const set<
const Lepton::Operation& op = node.getOperation(); const Lepton::Operation& op = node.getOperation();
if (op.getId() == Lepton::Operation::VARIABLE && variables.find(op.getName()) == variables.end()) if (op.getId() == Lepton::Operation::VARIABLE && variables.find(op.getName()) == variables.end())
throw OpenMMException("Unknown variable in expression: "+op.getName()); throw OpenMMException("Unknown variable in expression: "+op.getName());
for (int i = 0; i < (int) node.getChildren().size(); i++) for (auto& child : node.getChildren())
validateVariables(node.getChildren()[i], variables); validateVariables(child, variables);
} }
/** /**
...@@ -214,8 +214,8 @@ void ReferenceCalcForcesAndEnergyKernel::beginComputation(ContextImpl& context, ...@@ -214,8 +214,8 @@ void ReferenceCalcForcesAndEnergyKernel::beginComputation(ContextImpl& context,
} }
else else
savedForces = forceData; savedForces = forceData;
for (map<string, double>::const_iterator iter = context.getParameters().begin(); iter != context.getParameters().end(); ++iter) for (auto& param : context.getParameters())
extractEnergyParameterDerivatives(context)[iter->first] = 0; extractEnergyParameterDerivatives(context)[param.first] = 0;
} }
double ReferenceCalcForcesAndEnergyKernel::finishComputation(ContextImpl& context, bool includeForces, bool includeEnergy, int groups, bool& valid) { double ReferenceCalcForcesAndEnergyKernel::finishComputation(ContextImpl& context, bool includeForces, bool includeEnergy, int groups, bool& valid) {
...@@ -466,8 +466,8 @@ double ReferenceCalcCustomBondForceKernel::execute(ContextImpl& context, bool in ...@@ -466,8 +466,8 @@ double ReferenceCalcCustomBondForceKernel::execute(ContextImpl& context, bool in
vector<Vec3>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
double energy = 0; double energy = 0;
map<string, double> globalParameters; map<string, double> globalParameters;
for (int i = 0; i < (int) globalParameterNames.size(); i++) for (auto& name : globalParameterNames)
globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]); globalParameters[name] = context.getParameter(name);
ReferenceCustomBondIxn bond(energyExpression, forceExpression, parameterNames, globalParameters, energyParamDerivExpressions); ReferenceCustomBondIxn bond(energyExpression, forceExpression, parameterNames, globalParameters, energyParamDerivExpressions);
if (usePeriodic) if (usePeriodic)
bond.setPeriodic(extractBoxVectors(context)); bond.setPeriodic(extractBoxVectors(context));
...@@ -600,8 +600,8 @@ double ReferenceCalcCustomAngleForceKernel::execute(ContextImpl& context, bool i ...@@ -600,8 +600,8 @@ double ReferenceCalcCustomAngleForceKernel::execute(ContextImpl& context, bool i
vector<Vec3>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
double energy = 0; double energy = 0;
map<string, double> globalParameters; map<string, double> globalParameters;
for (int i = 0; i < (int) globalParameterNames.size(); i++) for (auto& name : globalParameterNames)
globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]); globalParameters[name] = context.getParameter(name);
ReferenceCustomAngleIxn customAngle(energyExpression, forceExpression, parameterNames, globalParameters, energyParamDerivExpressions); ReferenceCustomAngleIxn customAngle(energyExpression, forceExpression, parameterNames, globalParameters, energyParamDerivExpressions);
if (usePeriodic) if (usePeriodic)
customAngle.setPeriodic(extractBoxVectors(context)); customAngle.setPeriodic(extractBoxVectors(context));
...@@ -870,8 +870,8 @@ double ReferenceCalcCustomTorsionForceKernel::execute(ContextImpl& context, bool ...@@ -870,8 +870,8 @@ double ReferenceCalcCustomTorsionForceKernel::execute(ContextImpl& context, bool
vector<Vec3>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
double energy = 0; double energy = 0;
map<string, double> globalParameters; map<string, double> globalParameters;
for (int i = 0; i < (int) globalParameterNames.size(); i++) for (auto& name : globalParameterNames)
globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]); globalParameters[name] = context.getParameter(name);
ReferenceCustomTorsionIxn customTorsion(energyExpression, forceExpression, parameterNames, globalParameters, energyParamDerivExpressions); ReferenceCustomTorsionIxn customTorsion(energyExpression, forceExpression, parameterNames, globalParameters, energyParamDerivExpressions);
if (usePeriodic) if (usePeriodic)
customTorsion.setPeriodic(extractBoxVectors(context)); customTorsion.setPeriodic(extractBoxVectors(context));
...@@ -1165,8 +1165,8 @@ void ReferenceCalcCustomNonbondedForceKernel::initialize(const System& system, c ...@@ -1165,8 +1165,8 @@ void ReferenceCalcCustomNonbondedForceKernel::initialize(const System& system, c
// Delete the custom functions. // Delete the custom functions.
for (map<string, Lepton::CustomFunction*>::iterator iter = functions.begin(); iter != functions.end(); iter++) for (auto& function : functions)
delete iter->second; delete function.second;
// Record information for the long range correction. // Record information for the long range correction.
...@@ -1208,11 +1208,11 @@ double ReferenceCalcCustomNonbondedForceKernel::execute(ContextImpl& context, bo ...@@ -1208,11 +1208,11 @@ double ReferenceCalcCustomNonbondedForceKernel::execute(ContextImpl& context, bo
if (interactionGroups.size() > 0) if (interactionGroups.size() > 0)
ixn.setInteractionGroups(interactionGroups); ixn.setInteractionGroups(interactionGroups);
bool globalParamsChanged = false; bool globalParamsChanged = false;
for (int i = 0; i < (int) globalParameterNames.size(); i++) { for (auto& name : globalParameterNames) {
double value = context.getParameter(globalParameterNames[i]); double value = context.getParameter(name);
if (globalParamValues[globalParameterNames[i]] != value) if (globalParamValues[name] != value)
globalParamsChanged = true; globalParamsChanged = true;
globalParamValues[globalParameterNames[i]] = value; globalParamValues[name] = value;
} }
if (useSwitchingFunction) if (useSwitchingFunction)
ixn.setUseSwitchingFunction(switchingDistance); ixn.setUseSwitchingFunction(switchingDistance);
...@@ -1459,8 +1459,8 @@ void ReferenceCalcCustomGBForceKernel::initialize(const System& system, const Cu ...@@ -1459,8 +1459,8 @@ void ReferenceCalcCustomGBForceKernel::initialize(const System& system, const Cu
// Delete the custom functions. // Delete the custom functions.
for (map<string, Lepton::CustomFunction*>::iterator iter = functions.begin(); iter != functions.end(); iter++) for (auto& function : functions)
delete iter->second; delete function.second;
} }
double ReferenceCalcCustomGBForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) { double ReferenceCalcCustomGBForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
...@@ -1477,8 +1477,8 @@ double ReferenceCalcCustomGBForceKernel::execute(ContextImpl& context, bool incl ...@@ -1477,8 +1477,8 @@ double ReferenceCalcCustomGBForceKernel::execute(ContextImpl& context, bool incl
ixn.setUseCutoff(nonbondedCutoff, *neighborList); ixn.setUseCutoff(nonbondedCutoff, *neighborList);
} }
map<string, double> globalParameters; map<string, double> globalParameters;
for (int i = 0; i < (int) globalParameterNames.size(); i++) for (auto& name : globalParameterNames)
globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]); globalParameters[name] = context.getParameter(name);
vector<double> energyParamDerivValues(energyParamDerivNames.size()+1, 0.0); vector<double> energyParamDerivValues(energyParamDerivNames.size()+1, 0.0);
ixn.calculateIxn(numParticles, posData, particleParamArray, exclusions, globalParameters, forceData, includeEnergy ? &energy : NULL, &energyParamDerivValues[0]); ixn.calculateIxn(numParticles, posData, particleParamArray, exclusions, globalParameters, forceData, includeEnergy ? &energy : NULL, &energyParamDerivValues[0]);
map<string, double>& energyParamDerivs = extractEnergyParameterDerivatives(context); map<string, double>& energyParamDerivs = extractEnergyParameterDerivatives(context);
...@@ -1593,8 +1593,8 @@ double ReferenceCalcCustomExternalForceKernel::execute(ContextImpl& context, boo ...@@ -1593,8 +1593,8 @@ double ReferenceCalcCustomExternalForceKernel::execute(ContextImpl& context, boo
boxVectors = extractBoxVectors(context); boxVectors = extractBoxVectors(context);
double energy = 0; double energy = 0;
map<string, double> globalParameters; map<string, double> globalParameters;
for (int i = 0; i < (int) globalParameterNames.size(); i++) for (auto& name : globalParameterNames)
globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]); globalParameters[name] = context.getParameter(name);
ReferenceCustomExternalIxn force(energyExpression, forceExpressionX, forceExpressionY, forceExpressionZ, parameterNames, globalParameters); ReferenceCustomExternalIxn force(energyExpression, forceExpressionX, forceExpressionY, forceExpressionZ, parameterNames, globalParameters);
for (int i = 0; i < numParticles; ++i) for (int i = 0; i < numParticles; ++i)
force.calculateForce(particles[i], posData, particleParamArray[i], forceData, includeEnergy ? &energy : NULL); force.calculateForce(particles[i], posData, particleParamArray[i], forceData, includeEnergy ? &energy : NULL);
...@@ -1699,8 +1699,8 @@ void ReferenceCalcCustomHbondForceKernel::initialize(const System& system, const ...@@ -1699,8 +1699,8 @@ void ReferenceCalcCustomHbondForceKernel::initialize(const System& system, const
// Delete the custom functions. // Delete the custom functions.
for (map<string, Lepton::CustomFunction*>::iterator iter = functions.begin(); iter != functions.end(); iter++) for (auto& function : functions)
delete iter->second; delete function.second;
} }
double ReferenceCalcCustomHbondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) { double ReferenceCalcCustomHbondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
...@@ -1710,8 +1710,8 @@ double ReferenceCalcCustomHbondForceKernel::execute(ContextImpl& context, bool i ...@@ -1710,8 +1710,8 @@ double ReferenceCalcCustomHbondForceKernel::execute(ContextImpl& context, bool i
ixn->setPeriodic(extractBoxVectors(context)); ixn->setPeriodic(extractBoxVectors(context));
double energy = 0; double energy = 0;
map<string, double> globalParameters; map<string, double> globalParameters;
for (int i = 0; i < (int) globalParameterNames.size(); i++) for (auto& name : globalParameterNames)
globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]); globalParameters[name] = context.getParameter(name);
ixn->calculatePairIxn(posData, donorParamArray, acceptorParamArray, exclusions, globalParameters, forceData, includeEnergy ? &energy : NULL); ixn->calculatePairIxn(posData, donorParamArray, acceptorParamArray, exclusions, globalParameters, forceData, includeEnergy ? &energy : NULL);
return energy; return energy;
} }
...@@ -1803,8 +1803,8 @@ void ReferenceCalcCustomCentroidBondForceKernel::initialize(const System& system ...@@ -1803,8 +1803,8 @@ void ReferenceCalcCustomCentroidBondForceKernel::initialize(const System& system
// Delete the custom functions. // Delete the custom functions.
for (map<string, Lepton::CustomFunction*>::iterator iter = functions.begin(); iter != functions.end(); iter++) for (auto& function : functions)
delete iter->second; delete function.second;
} }
double ReferenceCalcCustomCentroidBondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) { double ReferenceCalcCustomCentroidBondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
...@@ -1812,8 +1812,8 @@ double ReferenceCalcCustomCentroidBondForceKernel::execute(ContextImpl& context, ...@@ -1812,8 +1812,8 @@ double ReferenceCalcCustomCentroidBondForceKernel::execute(ContextImpl& context,
vector<Vec3>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
double energy = 0; double energy = 0;
map<string, double> globalParameters; map<string, double> globalParameters;
for (int i = 0; i < (int) globalParameterNames.size(); i++) for (auto& name : globalParameterNames)
globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]); globalParameters[name] = context.getParameter(name);
if (usePeriodic) if (usePeriodic)
ixn->setPeriodic(extractBoxVectors(context)); ixn->setPeriodic(extractBoxVectors(context));
vector<double> energyParamDerivValues(energyParamDerivNames.size()+1, 0.0); vector<double> energyParamDerivValues(energyParamDerivNames.size()+1, 0.0);
...@@ -1893,8 +1893,8 @@ void ReferenceCalcCustomCompoundBondForceKernel::initialize(const System& system ...@@ -1893,8 +1893,8 @@ void ReferenceCalcCustomCompoundBondForceKernel::initialize(const System& system
// Delete the custom functions. // Delete the custom functions.
for (map<string, Lepton::CustomFunction*>::iterator iter = functions.begin(); iter != functions.end(); iter++) for (auto& function : functions)
delete iter->second; delete function.second;
} }
double ReferenceCalcCustomCompoundBondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) { double ReferenceCalcCustomCompoundBondForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
...@@ -1902,8 +1902,8 @@ double ReferenceCalcCustomCompoundBondForceKernel::execute(ContextImpl& context, ...@@ -1902,8 +1902,8 @@ double ReferenceCalcCustomCompoundBondForceKernel::execute(ContextImpl& context,
vector<Vec3>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
double energy = 0; double energy = 0;
map<string, double> globalParameters; map<string, double> globalParameters;
for (int i = 0; i < (int) globalParameterNames.size(); i++) for (auto& name : globalParameterNames)
globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]); globalParameters[name] = context.getParameter(name);
if (usePeriodic) if (usePeriodic)
ixn->setPeriodic(extractBoxVectors(context)); ixn->setPeriodic(extractBoxVectors(context));
vector<double> energyParamDerivValues(energyParamDerivNames.size()+1, 0.0); vector<double> energyParamDerivValues(energyParamDerivNames.size()+1, 0.0);
...@@ -1966,8 +1966,8 @@ double ReferenceCalcCustomManyParticleForceKernel::execute(ContextImpl& context, ...@@ -1966,8 +1966,8 @@ double ReferenceCalcCustomManyParticleForceKernel::execute(ContextImpl& context,
vector<Vec3>& forceData = extractForces(context); vector<Vec3>& forceData = extractForces(context);
double energy = 0; double energy = 0;
map<string, double> globalParameters; map<string, double> globalParameters;
for (int i = 0; i < (int) globalParameterNames.size(); i++) for (auto& name : globalParameterNames)
globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]); globalParameters[name] = context.getParameter(name);
if (nonbondedMethod == CutoffPeriodic) { if (nonbondedMethod == CutoffPeriodic) {
Vec3* boxVectors = extractBoxVectors(context); Vec3* boxVectors = extractBoxVectors(context);
double minAllowedSize = 2*cutoffDistance; double minAllowedSize = 2*cutoffDistance;
...@@ -2232,8 +2232,8 @@ void ReferenceIntegrateCustomStepKernel::initialize(const System& system, const ...@@ -2232,8 +2232,8 @@ void ReferenceIntegrateCustomStepKernel::initialize(const System& system, const
for (int i = 0; i < numParticles; ++i) for (int i = 0; i < numParticles; ++i)
masses[i] = system.getParticleMass(i); masses[i] = system.getParticleMass(i);
perDofValues.resize(integrator.getNumPerDofVariables()); perDofValues.resize(integrator.getNumPerDofVariables());
for (int i = 0; i < (int) perDofValues.size(); i++) for (auto& values : perDofValues)
perDofValues[i].resize(numParticles); values.resize(numParticles);
// Create the computation objects. // Create the computation objects.
......
...@@ -66,13 +66,12 @@ using namespace OpenMM; ...@@ -66,13 +66,12 @@ using namespace OpenMM;
double temperature, double collisionFrequency, double stepSize) const { double temperature, double collisionFrequency, double stepSize) const {
const double collisionProbability = 1.0f - exp(-collisionFrequency*stepSize); const double collisionProbability = 1.0f - exp(-collisionFrequency*stepSize);
for (int i = 0; i < (int) atomGroups.size(); ++i) { for (auto& group : atomGroups) {
if (SimTKOpenMMUtilities::getUniformlyDistributedRandomNumber() < collisionProbability) { if (SimTKOpenMMUtilities::getUniformlyDistributedRandomNumber() < collisionProbability) {
// A collision occurred, so set the velocities to new values chosen from a Boltzmann distribution. // A collision occurred, so set the velocities to new values chosen from a Boltzmann distribution.
for (int j = 0; j < (int) atomGroups[i].size(); j++) { for (int atom : group) {
int atom = atomGroups[i][j];
if (atomMasses[atom] != 0) { if (atomMasses[atom] != 0) {
const double velocityScale = static_cast<double>(sqrt(BOLTZ*temperature/atomMasses[atom])); const double velocityScale = static_cast<double>(sqrt(BOLTZ*temperature/atomMasses[atom]));
atomVelocities[atom][0] = velocityScale*SimTKOpenMMUtilities::getNormallyDistributedRandomNumber(); atomVelocities[atom][0] = velocityScale*SimTKOpenMMUtilities::getNormallyDistributedRandomNumber();
......
...@@ -127,8 +127,8 @@ ReferenceCCMAAlgorithm::ReferenceCCMAAlgorithm(int numberOfAtoms, ...@@ -127,8 +127,8 @@ ReferenceCCMAAlgorithm::ReferenceCCMAAlgorithm(int numberOfAtoms,
// We didn't find one, so look for an angle force field term. // We didn't find one, so look for an angle force field term.
const vector<int>& angleCandidates = atomAngles[atomb]; const vector<int>& angleCandidates = atomAngles[atomb];
for (vector<int>::const_iterator iter = angleCandidates.begin(); iter != angleCandidates.end(); iter++) { for (int candidate : angleCandidates) {
const AngleInfo& angle = angles[*iter]; const AngleInfo& angle = angles[candidate];
if ((angle.atom1 == atoma && angle.atom3 == atomc) || (angle.atom3 == atoma && angle.atom1 == atomc)) { if ((angle.atom1 == atoma && angle.atom3 == atomc) || (angle.atom3 == atoma && angle.atom1 == atomc)) {
matrix[j].push_back(pair<int, double>(k, scale*cos(angle.angle))); matrix[j].push_back(pair<int, double>(k, scale*cos(angle.angle)));
break; break;
...@@ -145,8 +145,7 @@ ReferenceCCMAAlgorithm::ReferenceCCMAAlgorithm(int numberOfAtoms, ...@@ -145,8 +145,7 @@ ReferenceCCMAAlgorithm::ReferenceCCMAAlgorithm(int numberOfAtoms,
vector<double> matrixValue; vector<double> matrixValue;
for (int i = 0; i < numberOfConstraints; i++) { for (int i = 0; i < numberOfConstraints; i++) {
matrixRowStart.push_back(matrixValue.size()); matrixRowStart.push_back(matrixValue.size());
for (int j = 0; j < (int) matrix[i].size(); j++) { for (auto& element : matrix[i]) {
pair<int, double> element = matrix[i][j];
matrixColIndex.push_back(element.first); matrixColIndex.push_back(element.first);
matrixValue.push_back(element.second); matrixValue.push_back(element.second);
} }
...@@ -292,10 +291,8 @@ void ReferenceCCMAAlgorithm::applyConstraints(vector<Vec3>& atomCoordinates, ...@@ -292,10 +291,8 @@ void ReferenceCCMAAlgorithm::applyConstraints(vector<Vec3>& atomCoordinates,
if (_matrix.size() > 0) { if (_matrix.size() > 0) {
for (int i = 0; i < _numberOfConstraints; i++) { for (int i = 0; i < _numberOfConstraints; i++) {
double sum = 0.0; double sum = 0.0;
for (int j = 0; j < (int) _matrix[i].size(); j++) { for (auto& element : _matrix[i])
pair<int, double> element = _matrix[i][j];
sum += element.second*constraintDelta[element.first]; sum += element.second*constraintDelta[element.first];
}
tempDelta[i] = sum; tempDelta[i] = sum;
} }
constraintDelta = tempDelta; constraintDelta = tempDelta;
......
...@@ -47,10 +47,10 @@ ReferenceCustomAngleIxn::ReferenceCustomAngleIxn(const Lepton::CompiledExpressio ...@@ -47,10 +47,10 @@ ReferenceCustomAngleIxn::ReferenceCustomAngleIxn(const Lepton::CompiledExpressio
expressionSet.registerExpression(this->energyParamDerivExpressions[i]); expressionSet.registerExpression(this->energyParamDerivExpressions[i]);
thetaIndex = expressionSet.getVariableIndex("theta"); thetaIndex = expressionSet.getVariableIndex("theta");
numParameters = parameterNames.size(); numParameters = parameterNames.size();
for (int i = 0; i < (int) numParameters; i++) for (auto& param : parameterNames)
angleParamIndex.push_back(expressionSet.getVariableIndex(parameterNames[i])); angleParamIndex.push_back(expressionSet.getVariableIndex(param));
for (map<string, double>::const_iterator iter = globalParameters.begin(); iter != globalParameters.end(); ++iter) for (auto& param : globalParameters)
expressionSet.setVariable(expressionSet.getVariableIndex(iter->first), iter->second); expressionSet.setVariable(expressionSet.getVariableIndex(param.first), param.second);
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
......
...@@ -48,10 +48,10 @@ ReferenceCustomBondIxn::ReferenceCustomBondIxn(const Lepton::CompiledExpression& ...@@ -48,10 +48,10 @@ ReferenceCustomBondIxn::ReferenceCustomBondIxn(const Lepton::CompiledExpression&
expressionSet.registerExpression(this->energyParamDerivExpressions[i]); expressionSet.registerExpression(this->energyParamDerivExpressions[i]);
rIndex = expressionSet.getVariableIndex("r"); rIndex = expressionSet.getVariableIndex("r");
numParameters = parameterNames.size(); numParameters = parameterNames.size();
for (int i = 0; i < (int) numParameters; i++) for (auto& param : parameterNames)
bondParamIndex.push_back(expressionSet.getVariableIndex(parameterNames[i])); bondParamIndex.push_back(expressionSet.getVariableIndex(param));
for (map<string, double>::const_iterator iter = globalParameters.begin(); iter != globalParameters.end(); ++iter) for (auto& param : globalParameters)
expressionSet.setVariable(expressionSet.getVariableIndex(iter->first), iter->second); expressionSet.setVariable(expressionSet.getVariableIndex(param.first), param.second);
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
......
...@@ -56,12 +56,12 @@ ReferenceCustomCentroidBondIxn::ReferenceCustomCentroidBondIxn(int numGroupsPerB ...@@ -56,12 +56,12 @@ ReferenceCustomCentroidBondIxn::ReferenceCustomCentroidBondIxn(int numGroupsPerB
positionTerms.push_back(ReferenceCustomCentroidBondIxn::PositionTermInfo(yname.str(), i, 1, energyExpression.differentiate(yname.str()).createCompiledExpression())); positionTerms.push_back(ReferenceCustomCentroidBondIxn::PositionTermInfo(yname.str(), i, 1, energyExpression.differentiate(yname.str()).createCompiledExpression()));
positionTerms.push_back(ReferenceCustomCentroidBondIxn::PositionTermInfo(zname.str(), i, 2, energyExpression.differentiate(zname.str()).createCompiledExpression())); positionTerms.push_back(ReferenceCustomCentroidBondIxn::PositionTermInfo(zname.str(), i, 2, energyExpression.differentiate(zname.str()).createCompiledExpression()));
} }
for (map<string, vector<int> >::const_iterator iter = distances.begin(); iter != distances.end(); ++iter) for (auto& term : distances)
distanceTerms.push_back(ReferenceCustomCentroidBondIxn::DistanceTermInfo(iter->first, iter->second, energyExpression.differentiate(iter->first).createCompiledExpression())); distanceTerms.push_back(ReferenceCustomCentroidBondIxn::DistanceTermInfo(term.first, term.second, energyExpression.differentiate(term.first).createCompiledExpression()));
for (map<string, vector<int> >::const_iterator iter = angles.begin(); iter != angles.end(); ++iter) for (auto& term : angles)
angleTerms.push_back(ReferenceCustomCentroidBondIxn::AngleTermInfo(iter->first, iter->second, energyExpression.differentiate(iter->first).createCompiledExpression())); angleTerms.push_back(ReferenceCustomCentroidBondIxn::AngleTermInfo(term.first, term.second, energyExpression.differentiate(term.first).createCompiledExpression()));
for (map<string, vector<int> >::const_iterator iter = dihedrals.begin(); iter != dihedrals.end(); ++iter) for (auto& term : dihedrals)
dihedralTerms.push_back(ReferenceCustomCentroidBondIxn::DihedralTermInfo(iter->first, iter->second, energyExpression.differentiate(iter->first).createCompiledExpression())); dihedralTerms.push_back(ReferenceCustomCentroidBondIxn::DihedralTermInfo(term.first, term.second, energyExpression.differentiate(term.first).createCompiledExpression()));
for (int i = 0; i < positionTerms.size(); i++) { for (int i = 0; i < positionTerms.size(); i++) {
expressionSet.registerExpression(positionTerms[i].forceExpression); expressionSet.registerExpression(positionTerms[i].forceExpression);
positionTerms[i].index = expressionSet.getVariableIndex(positionTerms[i].name); positionTerms[i].index = expressionSet.getVariableIndex(positionTerms[i].name);
...@@ -108,8 +108,8 @@ void ReferenceCustomCentroidBondIxn::calculatePairIxn(vector<Vec3>& atomCoordina ...@@ -108,8 +108,8 @@ void ReferenceCustomCentroidBondIxn::calculatePairIxn(vector<Vec3>& atomCoordina
// Compute the forces on groups. // Compute the forces on groups.
for (map<string, double>::const_iterator iter = globalParameters.begin(); iter != globalParameters.end(); ++iter) for (auto& param : globalParameters)
expressionSet.setVariable(expressionSet.getVariableIndex(iter->first), iter->second); expressionSet.setVariable(expressionSet.getVariableIndex(param.first), param.second);
vector<Vec3> groupForces(numGroups); vector<Vec3> groupForces(numGroups);
int numBonds = bondGroups.size(); int numBonds = bondGroups.size();
for (int bond = 0; bond < numBonds; bond++) { for (int bond = 0; bond < numBonds; bond++) {
...@@ -131,23 +131,18 @@ void ReferenceCustomCentroidBondIxn::calculateOneIxn(int bond, vector<Vec3>& gro ...@@ -131,23 +131,18 @@ void ReferenceCustomCentroidBondIxn::calculateOneIxn(int bond, vector<Vec3>& gro
// Compute all of the variables the energy can depend on. // Compute all of the variables the energy can depend on.
const vector<int>& groups = bondGroups[bond]; const vector<int>& groups = bondGroups[bond];
for (int i = 0; i < (int) positionTerms.size(); i++) { for (auto& term : positionTerms)
const PositionTermInfo& term = positionTerms[i];
expressionSet.setVariable(term.index, groupCenters[groups[term.group]][term.component]); expressionSet.setVariable(term.index, groupCenters[groups[term.group]][term.component]);
} for (auto& term : distanceTerms) {
for (int i = 0; i < (int) distanceTerms.size(); i++) {
const DistanceTermInfo& term = distanceTerms[i];
computeDelta(groups[term.g1], groups[term.g2], term.delta, groupCenters); computeDelta(groups[term.g1], groups[term.g2], term.delta, groupCenters);
expressionSet.setVariable(term.index, term.delta[ReferenceForce::RIndex]); expressionSet.setVariable(term.index, term.delta[ReferenceForce::RIndex]);
} }
for (int i = 0; i < (int) angleTerms.size(); i++) { for (auto& term : angleTerms) {
const AngleTermInfo& term = angleTerms[i];
computeDelta(groups[term.g1], groups[term.g2], term.delta1, groupCenters); computeDelta(groups[term.g1], groups[term.g2], term.delta1, groupCenters);
computeDelta(groups[term.g3], groups[term.g2], term.delta2, groupCenters); computeDelta(groups[term.g3], groups[term.g2], term.delta2, groupCenters);
expressionSet.setVariable(term.index, computeAngle(term.delta1, term.delta2)); expressionSet.setVariable(term.index, computeAngle(term.delta1, term.delta2));
} }
for (int i = 0; i < (int) dihedralTerms.size(); i++) { for (auto& term : dihedralTerms) {
const DihedralTermInfo& term = dihedralTerms[i];
computeDelta(groups[term.g2], groups[term.g1], term.delta1, groupCenters); computeDelta(groups[term.g2], groups[term.g1], term.delta1, groupCenters);
computeDelta(groups[term.g2], groups[term.g3], term.delta2, groupCenters); computeDelta(groups[term.g2], groups[term.g3], term.delta2, groupCenters);
computeDelta(groups[term.g4], groups[term.g3], term.delta3, groupCenters); computeDelta(groups[term.g4], groups[term.g3], term.delta3, groupCenters);
...@@ -158,15 +153,12 @@ void ReferenceCustomCentroidBondIxn::calculateOneIxn(int bond, vector<Vec3>& gro ...@@ -158,15 +153,12 @@ void ReferenceCustomCentroidBondIxn::calculateOneIxn(int bond, vector<Vec3>& gro
// Apply forces based on individual particle coordinates. // Apply forces based on individual particle coordinates.
for (int i = 0; i < (int) positionTerms.size(); i++) { for (auto& term : positionTerms)
const PositionTermInfo& term = positionTerms[i];
forces[groups[term.group]][term.component] -= term.forceExpression.evaluate(); forces[groups[term.group]][term.component] -= term.forceExpression.evaluate();
}
// Apply forces based on distances. // Apply forces based on distances.
for (int i = 0; i < (int) distanceTerms.size(); i++) { for (auto& term : distanceTerms) {
const DistanceTermInfo& term = distanceTerms[i];
double dEdR = term.forceExpression.evaluate()/(term.delta[ReferenceForce::RIndex]); double dEdR = term.forceExpression.evaluate()/(term.delta[ReferenceForce::RIndex]);
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
double force = -dEdR*term.delta[i]; double force = -dEdR*term.delta[i];
...@@ -177,8 +169,7 @@ void ReferenceCustomCentroidBondIxn::calculateOneIxn(int bond, vector<Vec3>& gro ...@@ -177,8 +169,7 @@ void ReferenceCustomCentroidBondIxn::calculateOneIxn(int bond, vector<Vec3>& gro
// Apply forces based on angles. // Apply forces based on angles.
for (int i = 0; i < (int) angleTerms.size(); i++) { for (auto& term : angleTerms) {
const AngleTermInfo& term = angleTerms[i];
double dEdTheta = term.forceExpression.evaluate(); double dEdTheta = term.forceExpression.evaluate();
double thetaCross[ReferenceForce::LastDeltaRIndex]; double thetaCross[ReferenceForce::LastDeltaRIndex];
SimTKOpenMMUtilities::crossProductVector3(term.delta1, term.delta2, thetaCross); SimTKOpenMMUtilities::crossProductVector3(term.delta1, term.delta2, thetaCross);
...@@ -204,8 +195,7 @@ void ReferenceCustomCentroidBondIxn::calculateOneIxn(int bond, vector<Vec3>& gro ...@@ -204,8 +195,7 @@ void ReferenceCustomCentroidBondIxn::calculateOneIxn(int bond, vector<Vec3>& gro
// Apply forces based on dihedrals. // Apply forces based on dihedrals.
for (int i = 0; i < (int) dihedralTerms.size(); i++) { for (auto& term : dihedralTerms) {
const DihedralTermInfo& term = dihedralTerms[i];
double dEdTheta = term.forceExpression.evaluate(); double dEdTheta = term.forceExpression.evaluate();
double internalF[4][3]; double internalF[4][3];
double forceFactors[4]; double forceFactors[4];
......
...@@ -61,12 +61,12 @@ ReferenceCustomCompoundBondIxn::ReferenceCustomCompoundBondIxn(int numParticlesP ...@@ -61,12 +61,12 @@ ReferenceCustomCompoundBondIxn::ReferenceCustomCompoundBondIxn(int numParticlesP
particleTerms.push_back(ReferenceCustomCompoundBondIxn::ParticleTermInfo(yname.str(), i, 1, energyExpression.differentiate(yname.str()).createCompiledExpression())); particleTerms.push_back(ReferenceCustomCompoundBondIxn::ParticleTermInfo(yname.str(), i, 1, energyExpression.differentiate(yname.str()).createCompiledExpression()));
particleTerms.push_back(ReferenceCustomCompoundBondIxn::ParticleTermInfo(zname.str(), i, 2, energyExpression.differentiate(zname.str()).createCompiledExpression())); particleTerms.push_back(ReferenceCustomCompoundBondIxn::ParticleTermInfo(zname.str(), i, 2, energyExpression.differentiate(zname.str()).createCompiledExpression()));
} }
for (map<string, vector<int> >::const_iterator iter = distances.begin(); iter != distances.end(); ++iter) for (auto& term : distances)
distanceTerms.push_back(ReferenceCustomCompoundBondIxn::DistanceTermInfo(iter->first, iter->second, energyExpression.differentiate(iter->first).createCompiledExpression())); distanceTerms.push_back(ReferenceCustomCompoundBondIxn::DistanceTermInfo(term.first, term.second, energyExpression.differentiate(term.first).createCompiledExpression()));
for (map<string, vector<int> >::const_iterator iter = angles.begin(); iter != angles.end(); ++iter) for (auto& term : angles)
angleTerms.push_back(ReferenceCustomCompoundBondIxn::AngleTermInfo(iter->first, iter->second, energyExpression.differentiate(iter->first).createCompiledExpression())); angleTerms.push_back(ReferenceCustomCompoundBondIxn::AngleTermInfo(term.first, term.second, energyExpression.differentiate(term.first).createCompiledExpression()));
for (map<string, vector<int> >::const_iterator iter = dihedrals.begin(); iter != dihedrals.end(); ++iter) for (auto& term : dihedrals)
dihedralTerms.push_back(ReferenceCustomCompoundBondIxn::DihedralTermInfo(iter->first, iter->second, energyExpression.differentiate(iter->first).createCompiledExpression())); dihedralTerms.push_back(ReferenceCustomCompoundBondIxn::DihedralTermInfo(term.first, term.second, energyExpression.differentiate(term.first).createCompiledExpression()));
for (int i = 0; i < particleTerms.size(); i++) { for (int i = 0; i < particleTerms.size(); i++) {
expressionSet.registerExpression(particleTerms[i].forceExpression); expressionSet.registerExpression(particleTerms[i].forceExpression);
particleTerms[i].index = expressionSet.getVariableIndex(particleTerms[i].name); particleTerms[i].index = expressionSet.getVariableIndex(particleTerms[i].name);
...@@ -119,8 +119,8 @@ void ReferenceCustomCompoundBondIxn::setPeriodic(OpenMM::Vec3* vectors) { ...@@ -119,8 +119,8 @@ void ReferenceCustomCompoundBondIxn::setPeriodic(OpenMM::Vec3* vectors) {
void ReferenceCustomCompoundBondIxn::calculatePairIxn(vector<Vec3>& atomCoordinates, double** bondParameters, void ReferenceCustomCompoundBondIxn::calculatePairIxn(vector<Vec3>& atomCoordinates, double** bondParameters,
const map<string, double>& globalParameters, vector<Vec3>& forces, const map<string, double>& globalParameters, vector<Vec3>& forces,
double* totalEnergy, double* energyParamDerivs) { double* totalEnergy, double* energyParamDerivs) {
for (map<string, double>::const_iterator iter = globalParameters.begin(); iter != globalParameters.end(); ++iter) for (auto& param : globalParameters)
expressionSet.setVariable(expressionSet.getVariableIndex(iter->first), iter->second); expressionSet.setVariable(expressionSet.getVariableIndex(param.first), param.second);
int numBonds = bondAtoms.size(); int numBonds = bondAtoms.size();
for (int bond = 0; bond < numBonds; bond++) { for (int bond = 0; bond < numBonds; bond++) {
for (int i = 0; i < numParameters; i++) for (int i = 0; i < numParameters; i++)
...@@ -146,23 +146,18 @@ void ReferenceCustomCompoundBondIxn::calculateOneIxn(int bond, vector<Vec3>& ato ...@@ -146,23 +146,18 @@ void ReferenceCustomCompoundBondIxn::calculateOneIxn(int bond, vector<Vec3>& ato
// Compute all of the variables the energy can depend on. // Compute all of the variables the energy can depend on.
const vector<int>& atoms = bondAtoms[bond]; const vector<int>& atoms = bondAtoms[bond];
for (int i = 0; i < (int) particleTerms.size(); i++) { for (auto& term : particleTerms)
const ParticleTermInfo& term = particleTerms[i];
expressionSet.setVariable(term.index, atomCoordinates[atoms[term.atom]][term.component]); expressionSet.setVariable(term.index, atomCoordinates[atoms[term.atom]][term.component]);
} for (auto& term : distanceTerms) {
for (int i = 0; i < (int) distanceTerms.size(); i++) {
const DistanceTermInfo& term = distanceTerms[i];
computeDelta(atoms[term.p1], atoms[term.p2], term.delta, atomCoordinates); computeDelta(atoms[term.p1], atoms[term.p2], term.delta, atomCoordinates);
expressionSet.setVariable(term.index, term.delta[ReferenceForce::RIndex]); expressionSet.setVariable(term.index, term.delta[ReferenceForce::RIndex]);
} }
for (int i = 0; i < (int) angleTerms.size(); i++) { for (auto& term : angleTerms) {
const AngleTermInfo& term = angleTerms[i];
computeDelta(atoms[term.p1], atoms[term.p2], term.delta1, atomCoordinates); computeDelta(atoms[term.p1], atoms[term.p2], term.delta1, atomCoordinates);
computeDelta(atoms[term.p3], atoms[term.p2], term.delta2, atomCoordinates); computeDelta(atoms[term.p3], atoms[term.p2], term.delta2, atomCoordinates);
expressionSet.setVariable(term.index, computeAngle(term.delta1, term.delta2)); expressionSet.setVariable(term.index, computeAngle(term.delta1, term.delta2));
} }
for (int i = 0; i < (int) dihedralTerms.size(); i++) { for (auto& term : dihedralTerms) {
const DihedralTermInfo& term = dihedralTerms[i];
computeDelta(atoms[term.p2], atoms[term.p1], term.delta1, atomCoordinates); computeDelta(atoms[term.p2], atoms[term.p1], term.delta1, atomCoordinates);
computeDelta(atoms[term.p2], atoms[term.p3], term.delta2, atomCoordinates); computeDelta(atoms[term.p2], atoms[term.p3], term.delta2, atomCoordinates);
computeDelta(atoms[term.p4], atoms[term.p3], term.delta3, atomCoordinates); computeDelta(atoms[term.p4], atoms[term.p3], term.delta3, atomCoordinates);
...@@ -173,15 +168,12 @@ void ReferenceCustomCompoundBondIxn::calculateOneIxn(int bond, vector<Vec3>& ato ...@@ -173,15 +168,12 @@ void ReferenceCustomCompoundBondIxn::calculateOneIxn(int bond, vector<Vec3>& ato
// Apply forces based on individual particle coordinates. // Apply forces based on individual particle coordinates.
for (int i = 0; i < (int) particleTerms.size(); i++) { for (auto& term : particleTerms)
const ParticleTermInfo& term = particleTerms[i];
forces[atoms[term.atom]][term.component] -= term.forceExpression.evaluate(); forces[atoms[term.atom]][term.component] -= term.forceExpression.evaluate();
}
// Apply forces based on distances. // Apply forces based on distances.
for (int i = 0; i < (int) distanceTerms.size(); i++) { for (auto& term : distanceTerms) {
const DistanceTermInfo& term = distanceTerms[i];
double dEdR = term.forceExpression.evaluate()/(term.delta[ReferenceForce::RIndex]); double dEdR = term.forceExpression.evaluate()/(term.delta[ReferenceForce::RIndex]);
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
double force = -dEdR*term.delta[i]; double force = -dEdR*term.delta[i];
...@@ -192,8 +184,7 @@ void ReferenceCustomCompoundBondIxn::calculateOneIxn(int bond, vector<Vec3>& ato ...@@ -192,8 +184,7 @@ void ReferenceCustomCompoundBondIxn::calculateOneIxn(int bond, vector<Vec3>& ato
// Apply forces based on angles. // Apply forces based on angles.
for (int i = 0; i < (int) angleTerms.size(); i++) { for (auto& term : angleTerms) {
const AngleTermInfo& term = angleTerms[i];
double dEdTheta = term.forceExpression.evaluate(); double dEdTheta = term.forceExpression.evaluate();
double thetaCross[ReferenceForce::LastDeltaRIndex]; double thetaCross[ReferenceForce::LastDeltaRIndex];
SimTKOpenMMUtilities::crossProductVector3(term.delta1, term.delta2, thetaCross); SimTKOpenMMUtilities::crossProductVector3(term.delta1, term.delta2, thetaCross);
...@@ -219,8 +210,7 @@ void ReferenceCustomCompoundBondIxn::calculateOneIxn(int bond, vector<Vec3>& ato ...@@ -219,8 +210,7 @@ void ReferenceCustomCompoundBondIxn::calculateOneIxn(int bond, vector<Vec3>& ato
// Apply forces based on dihedrals. // Apply forces based on dihedrals.
for (int i = 0; i < (int) dihedralTerms.size(); i++) { for (auto& term : dihedralTerms) {
const DihedralTermInfo& term = dihedralTerms[i];
double dEdTheta = term.forceExpression.evaluate(); double dEdTheta = term.forceExpression.evaluate();
double internalF[4][3]; double internalF[4][3];
double forceFactors[4]; double forceFactors[4];
......
...@@ -175,8 +175,8 @@ ExpressionTreeNode ReferenceCustomDynamics::replaceDerivFunctions(const Expressi ...@@ -175,8 +175,8 @@ ExpressionTreeNode ReferenceCustomDynamics::replaceDerivFunctions(const Expressi
} }
else { else {
vector<ExpressionTreeNode> children; vector<ExpressionTreeNode> children;
for (int i = 0; i < (int) node.getChildren().size(); i++) for (auto& child : node.getChildren())
children.push_back(replaceDerivFunctions(node.getChildren()[i], context)); children.push_back(replaceDerivFunctions(child, context));
return ExpressionTreeNode(op.clone(), children); return ExpressionTreeNode(op.clone(), children);
} }
} }
...@@ -204,8 +204,8 @@ void ReferenceCustomDynamics::update(ContextImpl& context, int numberOfAtoms, ve ...@@ -204,8 +204,8 @@ void ReferenceCustomDynamics::update(ContextImpl& context, int numberOfAtoms, ve
initialize(context, masses, globals); initialize(context, masses, globals);
int numSteps = stepType.size(); int numSteps = stepType.size();
globals.insert(context.getParameters().begin(), context.getParameters().end()); globals.insert(context.getParameters().begin(), context.getParameters().end());
for (map<string, double>::const_iterator iter = globals.begin(); iter != globals.end(); ++iter) for (auto& global : globals)
expressionSet.setVariable(expressionSet.getVariableIndex(iter->first), iter->second); expressionSet.setVariable(expressionSet.getVariableIndex(global.first), global.second);
oldPos = atomCoordinates; oldPos = atomCoordinates;
// Loop over steps and execute them. // Loop over steps and execute them.
...@@ -276,8 +276,8 @@ void ReferenceCustomDynamics::update(ContextImpl& context, int numberOfAtoms, ve ...@@ -276,8 +276,8 @@ void ReferenceCustomDynamics::update(ContextImpl& context, int numberOfAtoms, ve
recordChangedParameters(context, globals); recordChangedParameters(context, globals);
context.updateContextState(); context.updateContextState();
globals.insert(context.getParameters().begin(), context.getParameters().end()); globals.insert(context.getParameters().begin(), context.getParameters().end());
for (map<string, double>::const_iterator iter = globals.begin(); iter != globals.end(); ++iter) for (auto& global : globals)
expressionSet.setVariable(expressionSet.getVariableIndex(iter->first), iter->second); expressionSet.setVariable(expressionSet.getVariableIndex(global.first), global.second);
break; break;
} }
case CustomIntegrator::IfBlockStart: { case CustomIntegrator::IfBlockStart: {
...@@ -355,10 +355,10 @@ bool ReferenceCustomDynamics::evaluateCondition(int step) { ...@@ -355,10 +355,10 @@ bool ReferenceCustomDynamics::evaluateCondition(int step) {
* Check which context parameters have changed and register them with the context. * Check which context parameters have changed and register them with the context.
*/ */
void ReferenceCustomDynamics::recordChangedParameters(OpenMM::ContextImpl& context, std::map<std::string, double>& globals) { void ReferenceCustomDynamics::recordChangedParameters(OpenMM::ContextImpl& context, std::map<std::string, double>& globals) {
for (map<string, double>::const_iterator iter = context.getParameters().begin(); iter != context.getParameters().end(); ++iter) { for (auto& param : context.getParameters()) {
string name = iter->first; string name = param.first;
double value = globals[name]; double value = globals[name];
if (value != iter->second) if (value != param.second)
context.setParameter(name, globals[name]); context.setParameter(name, globals[name]);
} }
} }
...@@ -385,8 +385,8 @@ double ReferenceCustomDynamics::computeKineticEnergy(OpenMM::ContextImpl& contex ...@@ -385,8 +385,8 @@ double ReferenceCustomDynamics::computeKineticEnergy(OpenMM::ContextImpl& contex
if (invalidatesForces.size() == 0) if (invalidatesForces.size() == 0)
initialize(context, masses, globals); initialize(context, masses, globals);
globals.insert(context.getParameters().begin(), context.getParameters().end()); globals.insert(context.getParameters().begin(), context.getParameters().end());
for (map<string, double>::const_iterator iter = globals.begin(); iter != globals.end(); ++iter) for (auto& global : globals)
expressionSet.setVariable(expressionSet.getVariableIndex(iter->first), iter->second); expressionSet.setVariable(expressionSet.getVariableIndex(global.first), global.second);
if (kineticEnergyNeedsForce) { if (kineticEnergyNeedsForce) {
energy = context.calcForcesAndEnergy(true, true, -1); energy = context.calcForcesAndEnergy(true, true, -1);
forcesAreValid = true; forcesAreValid = true;
......
...@@ -57,17 +57,17 @@ ReferenceCustomExternalIxn::ReferenceCustomExternalIxn(const Lepton::CompiledExp ...@@ -57,17 +57,17 @@ ReferenceCustomExternalIxn::ReferenceCustomExternalIxn(const Lepton::CompiledExp
forceZY = ReferenceForce::getVariablePointer(this->forceExpressionZ, "y"); forceZY = ReferenceForce::getVariablePointer(this->forceExpressionZ, "y");
forceZZ = ReferenceForce::getVariablePointer(this->forceExpressionZ, "z"); forceZZ = ReferenceForce::getVariablePointer(this->forceExpressionZ, "z");
numParameters = parameterNames.size(); numParameters = parameterNames.size();
for (int i = 0; i < (int) numParameters; i++) { for (auto& param : parameterNames) {
energyParams.push_back(ReferenceForce::getVariablePointer(this->energyExpression, parameterNames[i])); energyParams.push_back(ReferenceForce::getVariablePointer(this->energyExpression, param));
forceXParams.push_back(ReferenceForce::getVariablePointer(this->forceExpressionX, parameterNames[i])); forceXParams.push_back(ReferenceForce::getVariablePointer(this->forceExpressionX, param));
forceYParams.push_back(ReferenceForce::getVariablePointer(this->forceExpressionY, parameterNames[i])); forceYParams.push_back(ReferenceForce::getVariablePointer(this->forceExpressionY, param));
forceZParams.push_back(ReferenceForce::getVariablePointer(this->forceExpressionZ, parameterNames[i])); forceZParams.push_back(ReferenceForce::getVariablePointer(this->forceExpressionZ, param));
} }
for (map<string, double>::const_iterator iter = globalParameters.begin(); iter != globalParameters.end(); ++iter) { for (auto& param : globalParameters) {
ReferenceForce::setVariable(ReferenceForce::getVariablePointer(this->energyExpression, iter->first), iter->second); ReferenceForce::setVariable(ReferenceForce::getVariablePointer(this->energyExpression, param.first), param.second);
ReferenceForce::setVariable(ReferenceForce::getVariablePointer(this->forceExpressionX, iter->first), iter->second); ReferenceForce::setVariable(ReferenceForce::getVariablePointer(this->forceExpressionX, param.first), param.second);
ReferenceForce::setVariable(ReferenceForce::getVariablePointer(this->forceExpressionY, iter->first), iter->second); ReferenceForce::setVariable(ReferenceForce::getVariablePointer(this->forceExpressionY, param.first), param.second);
ReferenceForce::setVariable(ReferenceForce::getVariablePointer(this->forceExpressionZ, iter->first), iter->second); ReferenceForce::setVariable(ReferenceForce::getVariablePointer(this->forceExpressionZ, param.first), param.second);
} }
} }
......
...@@ -84,19 +84,19 @@ ReferenceCustomGBIxn::ReferenceCustomGBIxn(const vector<Lepton::CompiledExpressi ...@@ -84,19 +84,19 @@ ReferenceCustomGBIxn::ReferenceCustomGBIxn(const vector<Lepton::CompiledExpressi
xIndex = expressionSet.getVariableIndex("x"); xIndex = expressionSet.getVariableIndex("x");
yIndex = expressionSet.getVariableIndex("y"); yIndex = expressionSet.getVariableIndex("y");
zIndex = expressionSet.getVariableIndex("z"); zIndex = expressionSet.getVariableIndex("z");
for (int i = 0; i < (int) parameterNames.size(); i++) { for (auto& param : parameterNames) {
paramIndex.push_back(expressionSet.getVariableIndex(parameterNames[i])); paramIndex.push_back(expressionSet.getVariableIndex(param));
for (int j = 1; j < 3; j++) { for (int j = 1; j < 3; j++) {
stringstream name; stringstream name;
name << parameterNames[i] << j; name << param << j;
particleParamIndex.push_back(expressionSet.getVariableIndex(name.str())); particleParamIndex.push_back(expressionSet.getVariableIndex(name.str()));
} }
} }
for (int i = 0; i < (int) valueNames.size(); i++) { for (auto& value : valueNames) {
valueIndex.push_back(expressionSet.getVariableIndex(valueNames[i])); valueIndex.push_back(expressionSet.getVariableIndex(value));
for (int j = 1; j < 3; j++) { for (int j = 1; j < 3; j++) {
stringstream name; stringstream name;
name << valueNames[i] << j; name << value << j;
particleValueIndex.push_back(expressionSet.getVariableIndex(name.str())); particleValueIndex.push_back(expressionSet.getVariableIndex(name.str()));
} }
} }
...@@ -153,8 +153,8 @@ ReferenceCustomGBIxn::~ReferenceCustomGBIxn() { ...@@ -153,8 +153,8 @@ ReferenceCustomGBIxn::~ReferenceCustomGBIxn() {
void ReferenceCustomGBIxn::calculateIxn(int numberOfAtoms, vector<Vec3>& atomCoordinates, double** atomParameters, void ReferenceCustomGBIxn::calculateIxn(int numberOfAtoms, vector<Vec3>& atomCoordinates, double** atomParameters,
const vector<set<int> >& exclusions, map<string, double>& globalParameters, vector<Vec3>& forces, const vector<set<int> >& exclusions, map<string, double>& globalParameters, vector<Vec3>& forces,
double* totalEnergy, double* energyParamDerivs) { double* totalEnergy, double* energyParamDerivs) {
for (map<string, double>::const_iterator iter = globalParameters.begin(); iter != globalParameters.end(); ++iter) for (auto& param : globalParameters)
expressionSet.setVariable(expressionSet.getVariableIndex(iter->first), iter->second); expressionSet.setVariable(expressionSet.getVariableIndex(param.first), param.second);
// Initialize arrays for storing values. // Initialize arrays for storing values.
...@@ -225,8 +225,7 @@ void ReferenceCustomGBIxn::calculateParticlePairValue(int index, int numAtoms, v ...@@ -225,8 +225,7 @@ void ReferenceCustomGBIxn::calculateParticlePairValue(int index, int numAtoms, v
if (cutoff) { if (cutoff) {
// Loop over all pairs in the neighbor list. // Loop over all pairs in the neighbor list.
for (int i = 0; i < (int) neighborList->size(); i++) { for (auto& pair : *neighborList) {
OpenMM::AtomPair pair = (*neighborList)[i];
if (useExclusions && exclusions[pair.first].find(pair.second) != exclusions[pair.first].end()) if (useExclusions && exclusions[pair.first].find(pair.second) != exclusions[pair.first].end())
continue; continue;
calculateOnePairValue(index, pair.first, pair.second, atomCoordinates, atomParameters); calculateOnePairValue(index, pair.first, pair.second, atomCoordinates, atomParameters);
...@@ -306,8 +305,7 @@ void ReferenceCustomGBIxn::calculateParticlePairEnergyTerm(int index, int numAto ...@@ -306,8 +305,7 @@ void ReferenceCustomGBIxn::calculateParticlePairEnergyTerm(int index, int numAto
if (cutoff) { if (cutoff) {
// Loop over all pairs in the neighbor list. // Loop over all pairs in the neighbor list.
for (int i = 0; i < (int) neighborList->size(); i++) { for (auto& pair : *neighborList) {
OpenMM::AtomPair pair = (*neighborList)[i];
if (useExclusions && exclusions[pair.first].find(pair.second) != exclusions[pair.first].end()) if (useExclusions && exclusions[pair.first].find(pair.second) != exclusions[pair.first].end())
continue; continue;
calculateOnePairEnergyTerm(index, pair.first, pair.second, atomCoordinates, atomParameters, forces, totalEnergy, energyParamDerivs); calculateOnePairEnergyTerm(index, pair.first, pair.second, atomCoordinates, atomParameters, forces, totalEnergy, energyParamDerivs);
...@@ -377,8 +375,7 @@ void ReferenceCustomGBIxn::calculateChainRuleForces(int numAtoms, vector<Vec3>& ...@@ -377,8 +375,7 @@ void ReferenceCustomGBIxn::calculateChainRuleForces(int numAtoms, vector<Vec3>&
if (cutoff) { if (cutoff) {
// Loop over all pairs in the neighbor list. // Loop over all pairs in the neighbor list.
for (int i = 0; i < (int) neighborList->size(); i++) { for (auto& pair : *neighborList) {
OpenMM::AtomPair pair = (*neighborList)[i];
bool isExcluded = (exclusions[pair.first].find(pair.second) != exclusions[pair.first].end()); bool isExcluded = (exclusions[pair.first].find(pair.second) != exclusions[pair.first].end());
calculateOnePairChainRule(pair.first, pair.second, atomCoordinates, atomParameters, forces, isExcluded); calculateOnePairChainRule(pair.first, pair.second, atomCoordinates, atomParameters, forces, isExcluded);
calculateOnePairChainRule(pair.second, pair.first, atomCoordinates, atomParameters, forces, isExcluded); calculateOnePairChainRule(pair.second, pair.first, atomCoordinates, atomParameters, forces, isExcluded);
......
...@@ -49,12 +49,12 @@ ReferenceCustomHbondIxn::ReferenceCustomHbondIxn(const vector<vector<int> >& don ...@@ -49,12 +49,12 @@ ReferenceCustomHbondIxn::ReferenceCustomHbondIxn(const vector<vector<int> >& don
const map<string, vector<int> >& distances, const map<string, vector<int> >& angles, const map<string, vector<int> >& dihedrals) : const map<string, vector<int> >& distances, const map<string, vector<int> >& angles, const map<string, vector<int> >& dihedrals) :
cutoff(false), periodic(false), donorAtoms(donorAtoms), acceptorAtoms(acceptorAtoms), energyExpression(energyExpression.createProgram()), cutoff(false), periodic(false), donorAtoms(donorAtoms), acceptorAtoms(acceptorAtoms), energyExpression(energyExpression.createProgram()),
donorParamNames(donorParameterNames), acceptorParamNames(acceptorParameterNames) { donorParamNames(donorParameterNames), acceptorParamNames(acceptorParameterNames) {
for (map<string, vector<int> >::const_iterator iter = distances.begin(); iter != distances.end(); ++iter) for (auto& term : distances)
distanceTerms.push_back(ReferenceCustomHbondIxn::DistanceTermInfo(iter->first, iter->second, energyExpression.differentiate(iter->first).optimize().createProgram())); distanceTerms.push_back(ReferenceCustomHbondIxn::DistanceTermInfo(term.first, term.second, energyExpression.differentiate(term.first).optimize().createProgram()));
for (map<string, vector<int> >::const_iterator iter = angles.begin(); iter != angles.end(); ++iter) for (auto& term : angles)
angleTerms.push_back(ReferenceCustomHbondIxn::AngleTermInfo(iter->first, iter->second, energyExpression.differentiate(iter->first).optimize().createProgram())); angleTerms.push_back(ReferenceCustomHbondIxn::AngleTermInfo(term.first, term.second, energyExpression.differentiate(term.first).optimize().createProgram()));
for (map<string, vector<int> >::const_iterator iter = dihedrals.begin(); iter != dihedrals.end(); ++iter) for (auto& term : dihedrals)
dihedralTerms.push_back(ReferenceCustomHbondIxn::DihedralTermInfo(iter->first, iter->second, energyExpression.differentiate(iter->first).optimize().createProgram())); dihedralTerms.push_back(ReferenceCustomHbondIxn::DihedralTermInfo(term.first, term.second, energyExpression.differentiate(term.first).optimize().createProgram()));
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
......
...@@ -60,8 +60,8 @@ ReferenceCustomManyParticleIxn::ReferenceCustomManyParticleIxn(const CustomManyP ...@@ -60,8 +60,8 @@ ReferenceCustomManyParticleIxn::ReferenceCustomManyParticleIxn(const CustomManyP
// Delete the custom functions. // Delete the custom functions.
for (map<string, Lepton::CustomFunction*>::iterator iter = functions.begin(); iter != functions.end(); iter++) for (auto& function : functions)
delete iter->second; delete function.second;
// Differentiate the energy to get expressions for the force. // Differentiate the energy to get expressions for the force.
...@@ -80,12 +80,12 @@ ReferenceCustomManyParticleIxn::ReferenceCustomManyParticleIxn(const CustomManyP ...@@ -80,12 +80,12 @@ ReferenceCustomManyParticleIxn::ReferenceCustomManyParticleIxn(const CustomManyP
particleParamNames[i].push_back(paramname.str()); particleParamNames[i].push_back(paramname.str());
} }
} }
for (map<string, vector<int> >::const_iterator iter = distances.begin(); iter != distances.end(); ++iter) for (auto& term : distances)
distanceTerms.push_back(ReferenceCustomManyParticleIxn::DistanceTermInfo(iter->first, iter->second, energyExpr.differentiate(iter->first).optimize().createProgram())); distanceTerms.push_back(ReferenceCustomManyParticleIxn::DistanceTermInfo(term.first, term.second, energyExpr.differentiate(term.first).optimize().createProgram()));
for (map<string, vector<int> >::const_iterator iter = angles.begin(); iter != angles.end(); ++iter) for (auto& term : angles)
angleTerms.push_back(ReferenceCustomManyParticleIxn::AngleTermInfo(iter->first, iter->second, energyExpr.differentiate(iter->first).optimize().createProgram())); angleTerms.push_back(ReferenceCustomManyParticleIxn::AngleTermInfo(term.first, term.second, energyExpr.differentiate(term.first).optimize().createProgram()));
for (map<string, vector<int> >::const_iterator iter = dihedrals.begin(); iter != dihedrals.end(); ++iter) for (auto& term : dihedrals)
dihedralTerms.push_back(ReferenceCustomManyParticleIxn::DihedralTermInfo(iter->first, iter->second, energyExpr.differentiate(iter->first).optimize().createProgram())); dihedralTerms.push_back(ReferenceCustomManyParticleIxn::DihedralTermInfo(term.first, term.second, energyExpr.differentiate(term.first).optimize().createProgram()));
// Record exclusions. // Record exclusions.
...@@ -192,23 +192,18 @@ void ReferenceCustomManyParticleIxn::calculateOneIxn(const vector<int>& particle ...@@ -192,23 +192,18 @@ void ReferenceCustomManyParticleIxn::calculateOneIxn(const vector<int>& particle
// Compute all of the variables the energy can depend on. // Compute all of the variables the energy can depend on.
for (int i = 0; i < (int) particleTerms.size(); i++) { for (auto& term : particleTerms)
const ParticleTermInfo& term = particleTerms[i];
variables[term.name] = atomCoordinates[permutedParticles[term.atom]][term.component]; variables[term.name] = atomCoordinates[permutedParticles[term.atom]][term.component];
} for (auto& term : distanceTerms) {
for (int i = 0; i < (int) distanceTerms.size(); i++) {
const DistanceTermInfo& term = distanceTerms[i];
computeDelta(permutedParticles[term.p1], permutedParticles[term.p2], term.delta, atomCoordinates); computeDelta(permutedParticles[term.p1], permutedParticles[term.p2], term.delta, atomCoordinates);
variables[term.name] = term.delta[ReferenceForce::RIndex]; variables[term.name] = term.delta[ReferenceForce::RIndex];
} }
for (int i = 0; i < (int) angleTerms.size(); i++) { for (auto& term : angleTerms) {
const AngleTermInfo& term = angleTerms[i];
computeDelta(permutedParticles[term.p1], permutedParticles[term.p2], term.delta1, atomCoordinates); computeDelta(permutedParticles[term.p1], permutedParticles[term.p2], term.delta1, atomCoordinates);
computeDelta(permutedParticles[term.p3], permutedParticles[term.p2], term.delta2, atomCoordinates); computeDelta(permutedParticles[term.p3], permutedParticles[term.p2], term.delta2, atomCoordinates);
variables[term.name] = computeAngle(term.delta1, term.delta2); variables[term.name] = computeAngle(term.delta1, term.delta2);
} }
for (int i = 0; i < (int) dihedralTerms.size(); i++) { for (auto& term : dihedralTerms) {
const DihedralTermInfo& term = dihedralTerms[i];
computeDelta(permutedParticles[term.p2], permutedParticles[term.p1], term.delta1, atomCoordinates); computeDelta(permutedParticles[term.p2], permutedParticles[term.p1], term.delta1, atomCoordinates);
computeDelta(permutedParticles[term.p2], permutedParticles[term.p3], term.delta2, atomCoordinates); computeDelta(permutedParticles[term.p2], permutedParticles[term.p3], term.delta2, atomCoordinates);
computeDelta(permutedParticles[term.p4], permutedParticles[term.p3], term.delta3, atomCoordinates); computeDelta(permutedParticles[term.p4], permutedParticles[term.p3], term.delta3, atomCoordinates);
...@@ -219,15 +214,12 @@ void ReferenceCustomManyParticleIxn::calculateOneIxn(const vector<int>& particle ...@@ -219,15 +214,12 @@ void ReferenceCustomManyParticleIxn::calculateOneIxn(const vector<int>& particle
// Apply forces based on individual particle coordinates. // Apply forces based on individual particle coordinates.
for (int i = 0; i < (int) particleTerms.size(); i++) { for (auto& term : particleTerms)
const ParticleTermInfo& term = particleTerms[i];
forces[permutedParticles[term.atom]][term.component] -= term.forceExpression.evaluate(variables); forces[permutedParticles[term.atom]][term.component] -= term.forceExpression.evaluate(variables);
}
// Apply forces based on distances. // Apply forces based on distances.
for (int i = 0; i < (int) distanceTerms.size(); i++) { for (auto& term : distanceTerms) {
const DistanceTermInfo& term = distanceTerms[i];
double dEdR = term.forceExpression.evaluate(variables)/(term.delta[ReferenceForce::RIndex]); double dEdR = term.forceExpression.evaluate(variables)/(term.delta[ReferenceForce::RIndex]);
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
double force = -dEdR*term.delta[i]; double force = -dEdR*term.delta[i];
...@@ -238,8 +230,7 @@ void ReferenceCustomManyParticleIxn::calculateOneIxn(const vector<int>& particle ...@@ -238,8 +230,7 @@ void ReferenceCustomManyParticleIxn::calculateOneIxn(const vector<int>& particle
// Apply forces based on angles. // Apply forces based on angles.
for (int i = 0; i < (int) angleTerms.size(); i++) { for (auto& term : angleTerms) {
const AngleTermInfo& term = angleTerms[i];
double dEdTheta = term.forceExpression.evaluate(variables); double dEdTheta = term.forceExpression.evaluate(variables);
double thetaCross[ReferenceForce::LastDeltaRIndex]; double thetaCross[ReferenceForce::LastDeltaRIndex];
SimTKOpenMMUtilities::crossProductVector3(term.delta1, term.delta2, thetaCross); SimTKOpenMMUtilities::crossProductVector3(term.delta1, term.delta2, thetaCross);
...@@ -265,8 +256,7 @@ void ReferenceCustomManyParticleIxn::calculateOneIxn(const vector<int>& particle ...@@ -265,8 +256,7 @@ void ReferenceCustomManyParticleIxn::calculateOneIxn(const vector<int>& particle
// Apply forces based on dihedrals. // Apply forces based on dihedrals.
for (int i = 0; i < (int) dihedralTerms.size(); i++) { for (auto& term : dihedralTerms) {
const DihedralTermInfo& term = dihedralTerms[i];
double dEdTheta = term.forceExpression.evaluate(variables); double dEdTheta = term.forceExpression.evaluate(variables);
double internalF[4][3]; double internalF[4][3];
double forceFactors[4]; double forceFactors[4];
......
...@@ -53,10 +53,10 @@ ReferenceCustomNonbondedIxn::ReferenceCustomNonbondedIxn(const Lepton::CompiledE ...@@ -53,10 +53,10 @@ ReferenceCustomNonbondedIxn::ReferenceCustomNonbondedIxn(const Lepton::CompiledE
for (int i = 0; i < this->energyParamDerivExpressions.size(); i++) for (int i = 0; i < this->energyParamDerivExpressions.size(); i++)
expressionSet.registerExpression(this->energyParamDerivExpressions[i]); expressionSet.registerExpression(this->energyParamDerivExpressions[i]);
rIndex = expressionSet.getVariableIndex("r"); rIndex = expressionSet.getVariableIndex("r");
for (int i = 0; i < (int) paramNames.size(); i++) { for (auto& param : paramNames) {
for (int j = 1; j < 3; j++) { for (int j = 1; j < 3; j++) {
stringstream name; stringstream name;
name << paramNames[i] << j; name << param << j;
particleParamIndex.push_back(expressionSet.getVariableIndex(name.str())); particleParamIndex.push_back(expressionSet.getVariableIndex(name.str()));
} }
} }
...@@ -159,14 +159,14 @@ void ReferenceCustomNonbondedIxn::calculatePairIxn(int numberOfAtoms, vector<Vec ...@@ -159,14 +159,14 @@ void ReferenceCustomNonbondedIxn::calculatePairIxn(int numberOfAtoms, vector<Vec
double* fixedParameters, const map<string, double>& globalParameters, vector<Vec3>& forces, double* fixedParameters, const map<string, double>& globalParameters, vector<Vec3>& forces,
double* energyByAtom, double* totalEnergy, double* energyParamDerivs) { double* energyByAtom, double* totalEnergy, double* energyParamDerivs) {
for (map<string, double>::const_iterator iter = globalParameters.begin(); iter != globalParameters.end(); ++iter) for (auto& param : globalParameters)
expressionSet.setVariable(expressionSet.getVariableIndex(iter->first), iter->second); expressionSet.setVariable(expressionSet.getVariableIndex(param.first), param.second);
if (interactionGroups.size() > 0) { if (interactionGroups.size() > 0) {
// The user has specified interaction groups, so compute only the requested interactions. // The user has specified interaction groups, so compute only the requested interactions.
for (int group = 0; group < (int) interactionGroups.size(); group++) { for (auto& group : interactionGroups) {
const set<int>& set1 = interactionGroups[group].first; const set<int>& set1 = group.first;
const set<int>& set2 = interactionGroups[group].second; const set<int>& set2 = group.second;
for (set<int>::const_iterator atom1 = set1.begin(); atom1 != set1.end(); ++atom1) { for (set<int>::const_iterator atom1 = set1.begin(); atom1 != set1.end(); ++atom1) {
for (set<int>::const_iterator atom2 = set2.begin(); atom2 != set2.end(); ++atom2) { for (set<int>::const_iterator atom2 = set2.begin(); atom2 != set2.end(); ++atom2) {
if (*atom1 == *atom2 || exclusions[*atom1].find(*atom2) != exclusions[*atom1].end()) if (*atom1 == *atom2 || exclusions[*atom1].find(*atom2) != exclusions[*atom1].end())
...@@ -185,8 +185,7 @@ void ReferenceCustomNonbondedIxn::calculatePairIxn(int numberOfAtoms, vector<Vec ...@@ -185,8 +185,7 @@ void ReferenceCustomNonbondedIxn::calculatePairIxn(int numberOfAtoms, vector<Vec
else if (cutoff) { else if (cutoff) {
// We are using a cutoff, so get the interactions from the neighbor list. // We are using a cutoff, so get the interactions from the neighbor list.
for (int i = 0; i < (int) neighborList->size(); i++) { for (auto& pair : *neighborList) {
OpenMM::AtomPair pair = (*neighborList)[i];
for (int j = 0; j < (int) paramNames.size(); j++) { for (int j = 0; j < (int) paramNames.size(); j++) {
expressionSet.setVariable(particleParamIndex[j*2], atomParameters[pair.first][j]); expressionSet.setVariable(particleParamIndex[j*2], atomParameters[pair.first][j]);
expressionSet.setVariable(particleParamIndex[j*2+1], atomParameters[pair.second][j]); expressionSet.setVariable(particleParamIndex[j*2+1], atomParameters[pair.second][j]);
......
...@@ -47,10 +47,10 @@ ReferenceCustomTorsionIxn::ReferenceCustomTorsionIxn(const Lepton::CompiledExpre ...@@ -47,10 +47,10 @@ ReferenceCustomTorsionIxn::ReferenceCustomTorsionIxn(const Lepton::CompiledExpre
expressionSet.registerExpression(this->energyParamDerivExpressions[i]); expressionSet.registerExpression(this->energyParamDerivExpressions[i]);
thetaIndex = expressionSet.getVariableIndex("theta"); thetaIndex = expressionSet.getVariableIndex("theta");
numParameters = parameterNames.size(); numParameters = parameterNames.size();
for (int i = 0; i < (int) numParameters; i++) for (auto& param : parameterNames)
torsionParamIndex.push_back(expressionSet.getVariableIndex(parameterNames[i])); torsionParamIndex.push_back(expressionSet.getVariableIndex(param));
for (map<string, double>::const_iterator iter = globalParameters.begin(); iter != globalParameters.end(); ++iter) for (auto& param : globalParameters)
expressionSet.setVariable(expressionSet.getVariableIndex(iter->first), iter->second); expressionSet.setVariable(expressionSet.getVariableIndex(param.first), param.second);
} }
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment