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
......@@ -197,8 +197,8 @@ ExpressionTreeNode CustomManyParticleForceImpl::replaceFunctions(const Expressio
// This is not an angle or dihedral, so process its children.
vector<ExpressionTreeNode> children;
for (int i = 0; i < (int) node.getChildren().size(); i++)
children.push_back(replaceFunctions(node.getChildren()[i], atoms, distances, angles, dihedrals, variables));
for (auto& child : node.getChildren())
children.push_back(replaceFunctions(child, atoms, distances, angles, dihedrals, variables));
return ExpressionTreeNode(op.clone(), children);
}
const Operation::Custom& custom = static_cast<const Operation::Custom&>(op);
......@@ -280,9 +280,9 @@ void CustomManyParticleForceImpl::buildFilterArrays(const CustomManyParticleForc
for (int j = 0; j < numTypes; j++)
allowedTypes[i].insert(j);
else {
for (set<int>::const_iterator iter = types.begin(); iter != types.end(); ++iter)
if (typeMap.find(*iter) != typeMap.end())
allowedTypes[i].insert(typeMap[*iter]);
for (int type : types)
if (typeMap.find(type) != typeMap.end())
allowedTypes[i].insert(typeMap[type]);
if (allowedTypes[i].size() < numTypes)
anyFilters = true;
}
......
......@@ -70,8 +70,8 @@ CustomNonbondedForce::CustomNonbondedForce(const CustomNonbondedForce& rhs) {
}
CustomNonbondedForce::~CustomNonbondedForce() {
for (int i = 0; i < (int) functions.size(); i++)
delete functions[i].function;
for (auto function : functions)
delete function.function;
}
const string& CustomNonbondedForce::getEnergyFunction() const {
......@@ -87,6 +87,8 @@ CustomNonbondedForce::NonbondedMethod CustomNonbondedForce::getNonbondedMethod()
}
void CustomNonbondedForce::setNonbondedMethod(NonbondedMethod method) {
if (method < 0 || method > 2)
throw OpenMMException("CustomNonbondedForce: Illegal value for nonbonded method");
nonbondedMethod = method;
}
......@@ -210,14 +212,14 @@ void CustomNonbondedForce::setExclusionParticles(int index, int particle1, int p
void CustomNonbondedForce::createExclusionsFromBonds(const vector<pair<int, int> >& bonds, int bondCutoff) {
if (bondCutoff < 1)
return;
for (int i = 0; i < (int) bonds.size(); ++i)
if (bonds[i].first < 0 || bonds[i].second < 0 || bonds[i].first >= particles.size() || bonds[i].second >= particles.size())
for (auto& bond : bonds)
if (bond.first < 0 || bond.second < 0 || bond.first >= particles.size() || bond.second >= particles.size())
throw OpenMMException("createExclusionsFromBonds: Illegal particle index in list of bonds");
vector<set<int> > exclusions(particles.size());
vector<set<int> > bonded12(exclusions.size());
for (int i = 0; i < (int) bonds.size(); ++i) {
int p1 = bonds[i].first;
int p2 = bonds[i].second;
for (auto& bond : bonds) {
int p1 = bond.first;
int p2 = bond.second;
exclusions[p1].insert(p2);
exclusions[p2].insert(p1);
bonded12[p1].insert(p2);
......@@ -225,15 +227,14 @@ void CustomNonbondedForce::createExclusionsFromBonds(const vector<pair<int, int>
}
for (int level = 0; level < bondCutoff-1; level++) {
vector<set<int> > currentExclusions = exclusions;
for (int i = 0; i < (int) particles.size(); i++) {
for (set<int>::const_iterator iter = currentExclusions[i].begin(); iter != currentExclusions[i].end(); ++iter)
exclusions[*iter].insert(bonded12[i].begin(), bonded12[i].end());
}
for (int i = 0; i < (int) particles.size(); i++)
for (int j : currentExclusions[i])
exclusions[j].insert(bonded12[i].begin(), bonded12[i].end());
}
for (int i = 0; i < (int) exclusions.size(); ++i)
for (set<int>::const_iterator iter = exclusions[i].begin(); iter != exclusions[i].end(); ++iter)
if (*iter < i)
addExclusion(*iter, i);
for (int j : exclusions[i])
if (j < i)
addExclusion(j, i);
}
int CustomNonbondedForce::addTabulatedFunction(const std::string& name, TabulatedFunction* function) {
......
......@@ -54,18 +54,16 @@ bool Force::usesPeriodicBoundaryConditions() const {
}
ForceImpl& Force::getImplInContext(Context& context) {
const vector<ForceImpl*>& impls = context.getImpl().getForceImpls();
for (int i = 0; i < (int) impls.size(); i++)
if (&impls[i]->getOwner() == this)
return *impls[i];
for (auto impl : context.getImpl().getForceImpls())
if (&impl->getOwner() == this)
return *impl;
throw OpenMMException("getImplInContext: This Force is not present in the Context");
}
const ForceImpl& Force::getImplInContext(const Context& context) const {
const vector<ForceImpl*>& impls = context.getImpl().getForceImpls();
for (int i = 0; i < (int) impls.size(); i++)
if (&impls[i]->getOwner() == this)
return *impls[i];
for (auto impl : context.getImpl().getForceImpls())
if (&impl->getOwner() == this)
return *impl;
throw OpenMMException("getImplInContext: This Force is not present in the Context");
}
......
......@@ -64,6 +64,8 @@ GBSAOBCForce::NonbondedMethod GBSAOBCForce::getNonbondedMethod() const {
}
void GBSAOBCForce::setNonbondedMethod(NonbondedMethod method) {
if (method < 0 || method > 2)
throw OpenMMException("GBSAOBCForce: Illegal value for nonbonded method");
nonbondedMethod = method;
}
......
......@@ -55,6 +55,8 @@ GayBerneForce::NonbondedMethod GayBerneForce::getNonbondedMethod() const {
}
void GayBerneForce::setNonbondedMethod(NonbondedMethod method) {
if (method < 0 || method > 2)
throw OpenMMException("GayBerneForce: Illegal value for nonbonded method");
nonbondedMethod = method;
}
......
......@@ -57,6 +57,8 @@ NonbondedForce::NonbondedMethod NonbondedForce::getNonbondedMethod() const {
}
void NonbondedForce::setNonbondedMethod(NonbondedMethod method) {
if (method < 0 || method > 5)
throw OpenMMException("NonbondedForce: Illegal value for nonbonded method");
nonbondedMethod = method;
}
......@@ -203,17 +205,17 @@ ForceImpl* NonbondedForce::createImpl() const {
}
void NonbondedForce::createExceptionsFromBonds(const vector<pair<int, int> >& bonds, double coulomb14Scale, double lj14Scale) {
for (int i = 0; i < (int) bonds.size(); ++i)
if (bonds[i].first < 0 || bonds[i].second < 0 || bonds[i].first >= particles.size() || bonds[i].second >= particles.size())
for (auto& bond : bonds)
if (bond.first < 0 || bond.second < 0 || bond.first >= particles.size() || bond.second >= particles.size())
throw OpenMMException("createExceptionsFromBonds: Illegal particle index in list of bonds");
// Find particles separated by 1, 2, or 3 bonds.
vector<set<int> > exclusions(particles.size());
vector<set<int> > bonded12(exclusions.size());
for (int i = 0; i < (int) bonds.size(); ++i) {
bonded12[bonds[i].first].insert(bonds[i].second);
bonded12[bonds[i].second].insert(bonds[i].first);
for (auto& bond : bonds) {
bonded12[bond.first].insert(bond.second);
bonded12[bond.second].insert(bond.first);
}
for (int i = 0; i < (int) exclusions.size(); ++i)
addExclusionsToSet(bonded12, exclusions[i], i, i, 2);
......@@ -223,33 +225,34 @@ void NonbondedForce::createExceptionsFromBonds(const vector<pair<int, int> >& bo
for (int i = 0; i < (int) exclusions.size(); ++i) {
set<int> bonded13;
addExclusionsToSet(bonded12, bonded13, i, i, 1);
for (set<int>::const_iterator iter = exclusions[i].begin(); iter != exclusions[i].end(); ++iter)
if (*iter < i) {
if (bonded13.find(*iter) == bonded13.end()) {
for (int j : exclusions[i]) {
if (j < i) {
if (bonded13.find(j) == bonded13.end()) {
// This is a 1-4 interaction.
const ParticleInfo& particle1 = particles[*iter];
const ParticleInfo& particle1 = particles[j];
const ParticleInfo& particle2 = particles[i];
const double chargeProd = coulomb14Scale*particle1.charge*particle2.charge;
const double sigma = 0.5*(particle1.sigma+particle2.sigma);
const double epsilon = lj14Scale*std::sqrt(particle1.epsilon*particle2.epsilon);
addException(*iter, i, chargeProd, sigma, epsilon);
addException(j, i, chargeProd, sigma, epsilon);
}
else {
// This interaction should be completely excluded.
addException(*iter, i, 0.0, 1.0, 0.0);
addException(j, i, 0.0, 1.0, 0.0);
}
}
}
}
}
void NonbondedForce::addExclusionsToSet(const vector<set<int> >& bonded12, set<int>& exclusions, int baseParticle, int fromParticle, int currentLevel) const {
for (set<int>::const_iterator iter = bonded12[fromParticle].begin(); iter != bonded12[fromParticle].end(); ++iter) {
if (*iter != baseParticle)
exclusions.insert(*iter);
for (int i : bonded12[fromParticle]) {
if (i != baseParticle)
exclusions.insert(i);
if (currentLevel > 0)
addExclusionsToSet(bonded12, exclusions, baseParticle, *iter, currentLevel-1);
addExclusionsToSet(bonded12, exclusions, baseParticle, i, currentLevel-1);
}
}
......
......@@ -45,10 +45,10 @@ System::System() {
}
System::~System() {
for (int i = 0; i < (int) forces.size(); ++i)
delete forces[i];
for (int i = 0; i < (int) virtualSites.size(); ++i)
delete virtualSites[i];
for (auto force : forces)
delete force;
for (auto site : virtualSites)
delete site;
}
double System::getParticleMass(int index) const {
......
......@@ -89,13 +89,13 @@ ThreadPool::ThreadPool(int numThreads) : currentTask(NULL) {
}
ThreadPool::~ThreadPool() {
for (int i = 0; i < (int) threadData.size(); i++)
threadData[i]->isDeleted = true;
for (auto data : threadData)
data->isDeleted = true;
pthread_mutex_lock(&lock);
pthread_cond_broadcast(&startCondition);
pthread_mutex_unlock(&lock);
for (int i = 0; i < (int) thread.size(); i++)
pthread_join(thread[i], NULL);
for (auto t : thread)
pthread_join(t, NULL);
pthread_mutex_destroy(&lock);
pthread_cond_destroy(&startCondition);
pthread_cond_destroy(&endCondition);
......
......@@ -159,8 +159,8 @@ void CpuBondForce::assignBond(int bond, int thread, vector<int>& atomThread, vec
if (atom != -1)
throw OpenMMException("CpuBondForce: Internal error: atoms assigned to threads incorrectly");
atom = thread;
for (set<int>::const_iterator iter = atomBonds[atom].begin(); iter != atomBonds[atom].end(); ++iter)
candidateBonds.push_back(*iter);
for (int bond : atomBonds[atom])
candidateBonds.push_back(bond);
}
}
......
......@@ -74,48 +74,48 @@ CpuCustomGBForce::ThreadData::ThreadData(int numAtoms, int numThreads, int threa
variableLocations[name.str()] = &particleValue[2*i+j];
}
}
for (int i = 0; i < (int) valueExpressions.size(); i++) {
this->valueExpressions[i].setVariableLocations(variableLocations);
expressionSet.registerExpression(this->valueExpressions[i]);
for (auto& expression : this->valueExpressions) {
expression.setVariableLocations(variableLocations);
expressionSet.registerExpression(expression);
}
for (int i = 0; i < (int) valueDerivExpressions.size(); i++)
for (int j = 0; j < (int) valueDerivExpressions[i].size(); j++) {
this->valueDerivExpressions[i][j].setVariableLocations(variableLocations);
expressionSet.registerExpression(this->valueDerivExpressions[i][j]);
for (auto& expressions : this->valueDerivExpressions)
for (auto& expression : expressions) {
expression.setVariableLocations(variableLocations);
expressionSet.registerExpression(expression);
}
for (int i = 0; i < (int) valueGradientExpressions.size(); i++)
for (int j = 0; j < (int) valueGradientExpressions[i].size(); j++) {
this->valueGradientExpressions[i][j].setVariableLocations(variableLocations);
expressionSet.registerExpression(this->valueGradientExpressions[i][j]);
for (auto& expressions : this->valueGradientExpressions)
for (auto& expression : expressions) {
expression.setVariableLocations(variableLocations);
expressionSet.registerExpression(expression);
}
for (int i = 0; i < (int) valueParamDerivExpressions.size(); i++)
for (int j = 0; j < (int) valueParamDerivExpressions[i].size(); j++) {
this->valueParamDerivExpressions[i][j].setVariableLocations(variableLocations);
expressionSet.registerExpression(this->valueParamDerivExpressions[i][j]);
for (auto& expressions : this->valueParamDerivExpressions)
for (auto& expression : expressions) {
expression.setVariableLocations(variableLocations);
expressionSet.registerExpression(expression);
}
for (int i = 0; i < (int) energyExpressions.size(); i++) {
this->energyExpressions[i].setVariableLocations(variableLocations);
expressionSet.registerExpression(this->energyExpressions[i]);
for (auto& expression : this->energyExpressions) {
expression.setVariableLocations(variableLocations);
expressionSet.registerExpression(expression);
}
for (int i = 0; i < (int) energyDerivExpressions.size(); i++)
for (int j = 0; j < (int) energyDerivExpressions[i].size(); j++) {
this->energyDerivExpressions[i][j].setVariableLocations(variableLocations);
expressionSet.registerExpression(this->energyDerivExpressions[i][j]);
for (auto& expressions : this->energyDerivExpressions)
for (auto& expression : expressions) {
expression.setVariableLocations(variableLocations);
expressionSet.registerExpression(expression);
}
for (int i = 0; i < (int) energyGradientExpressions.size(); i++)
for (int j = 0; j < (int) energyGradientExpressions[i].size(); j++) {
this->energyGradientExpressions[i][j].setVariableLocations(variableLocations);
expressionSet.registerExpression(this->energyGradientExpressions[i][j]);
for (auto& expressions : this->energyGradientExpressions)
for (auto& expression : expressions) {
expression.setVariableLocations(variableLocations);
expressionSet.registerExpression(expression);
}
for (int i = 0; i < (int) energyParamDerivExpressions.size(); i++)
for (int j = 0; j < (int) energyParamDerivExpressions[i].size(); j++) {
this->energyParamDerivExpressions[i][j].setVariableLocations(variableLocations);
expressionSet.registerExpression(this->energyParamDerivExpressions[i][j]);
for (auto& expressions : this->energyParamDerivExpressions)
for (auto& expression : expressions) {
expression.setVariableLocations(variableLocations);
expressionSet.registerExpression(expression);
}
value0.resize(numAtoms);
dEdV.resize(valueNames.size());
for (int i = 0; i < (int) dEdV.size(); i++)
dEdV[i].resize(numAtoms);
for (auto& v : dEdV)
v.resize(numAtoms);
dVdX.resize(valueDerivExpressions.size());
dVdY.resize(valueDerivExpressions.size());
dVdZ.resize(valueDerivExpressions.size());
......@@ -155,8 +155,8 @@ CpuCustomGBForce::CpuCustomGBForce(int numAtoms, const std::vector<std::set<int>
}
CpuCustomGBForce::~CpuCustomGBForce() {
for (int i = 0; i < (int) threadData.size(); i++)
delete threadData[i];
for (auto data : threadData)
delete data;
}
void CpuCustomGBForce::setUseCutoff(float distance, const CpuNeighborList& neighbors) {
......@@ -256,16 +256,16 @@ void CpuCustomGBForce::threadComputeForce(ThreadPool& threads, int threadIndex)
ThreadData& data = *threadData[threadIndex];
fvec4 boxSize(periodicBoxSize[0], periodicBoxSize[1], periodicBoxSize[2], 0);
fvec4 invBoxSize((1/periodicBoxSize[0]), (1/periodicBoxSize[1]), (1/periodicBoxSize[2]), 0);
for (map<string, double>::const_iterator iter = globalParameters->begin(); iter != globalParameters->end(); ++iter)
data.expressionSet.setVariable(data.expressionSet.getVariableIndex(iter->first), iter->second);
for (auto& param : *globalParameters)
data.expressionSet.setVariable(data.expressionSet.getVariableIndex(param.first), param.second);
// Calculate the first computed value.
for (int i = 0; i < (int) data.value0.size(); i++)
data.value0[i] = 0.0f;
for (int i = 0; i < (int) data.dValue0dParam.size(); i++)
for (int j = 0; j < (int) data.dValue0dParam[i].size(); j++)
data.dValue0dParam[i][j] = 0.0;
for (auto& v : data.value0)
v = 0.0f;
for (auto& vals : data.dValue0dParam)
for (auto& v : vals)
v = 0.0f;
if (valueTypes[0] == CustomGBForce::ParticlePair)
calculateParticlePairValue(0, data, numberOfAtoms, posq, atomParameters, true, boxSize, invBoxSize);
else
......@@ -291,8 +291,8 @@ void CpuCustomGBForce::threadComputeForce(ThreadPool& threads, int threadIndex)
int numValues = valueTypes.size();
for (int atom = data.firstAtom; atom < data.lastAtom; atom++) {
float sum = 0.0f;
for (int j = 0; j < (int) threadData.size(); j++)
sum += threadData[j]->value0[atom];
for (auto& data : threadData)
sum += data->value0[atom];
values[0][atom] = sum;
data.x = posq[4*atom];
data.y = posq[4*atom+1];
......@@ -320,11 +320,11 @@ void CpuCustomGBForce::threadComputeForce(ThreadPool& threads, int threadIndex)
// Now calculate the energy and its derivatives.
for (int i = 0; i < (int) data.dEdV.size(); i++)
for (int j = 0; j < (int) data.dEdV[i].size(); j++)
data.dEdV[i][j] = 0.0f;
for (int i = 0; i < (int) data.energyParamDerivs.size(); i++)
data.energyParamDerivs[i] = 0.0f;
for (auto& vals : data.dEdV)
for (auto& v : vals)
v = 0.0f;
for (auto& v : data.energyParamDerivs)
v = 0.0f;
for (int termIndex = 0; termIndex < (int) data.energyExpressions.size(); termIndex++) {
if (energyTypes[termIndex] == CustomGBForce::SingleParticle)
calculateSingleParticleEnergyTerm(termIndex, data, numberOfAtoms, posq, atomParameters, forces, energy);
......@@ -340,8 +340,8 @@ void CpuCustomGBForce::threadComputeForce(ThreadPool& threads, int threadIndex)
for (int atom = data.firstAtom; atom < data.lastAtom; atom++) {
for (int i = 0; i < (int) dEdV.size(); i++) {
float sum = 0.0f;
for (int j = 0; j < (int) threadData.size(); j++)
sum += threadData[j]->dEdV[i][atom];
for (auto& data : threadData)
sum += data->dEdV[i][atom];
dEdV[i][atom] = sum;
}
}
......
......@@ -63,8 +63,8 @@ CpuCustomManyParticleForce::CpuCustomManyParticleForce(const CustomManyParticleF
// Delete the custom functions.
for (map<string, Lepton::CustomFunction*>::iterator iter = functions.begin(); iter != functions.end(); iter++)
delete iter->second;
for (auto& function : functions)
delete function.second;
// Record exclusions.
......@@ -84,8 +84,8 @@ CpuCustomManyParticleForce::CpuCustomManyParticleForce(const CustomManyParticleF
CpuCustomManyParticleForce::~CpuCustomManyParticleForce() {
if (neighborList != NULL)
delete neighborList;
for (int i = 0; i < (int) threadData.size(); i++)
delete threadData[i];
for (auto data : threadData)
delete data;
}
void CpuCustomManyParticleForce::calculateIxn(AlignedArray<float>& posq, double** particleParameters,
......@@ -150,8 +150,8 @@ void CpuCustomManyParticleForce::threadComputeForce(ThreadPool& threads, int thr
float* forces = &(*threadForce)[threadIndex][0];
ThreadData& data = *threadData[threadIndex];
data.energy = 0;
for (map<string, double>::const_iterator iter = globalParameters->begin(); iter != globalParameters->end(); ++iter)
data.expressionSet.setVariable(data.expressionSet.getVariableIndex(iter->first), iter->second);
for (auto& param : *globalParameters)
data.expressionSet.setVariable(data.expressionSet.getVariableIndex(param.first), param.second);
if (useCutoff) {
// Loop over interactions from the neighbor list.
......@@ -287,18 +287,12 @@ void CpuCustomManyParticleForce::calculateOneIxn(vector<int>& particleSet, doubl
// Compute all of the variables the energy can depend on.
for (int i = 0; i < (int) data.particleTerms.size(); i++) {
const ParticleTermInfo& term = data.particleTerms[i];
for (auto& term : data.particleTerms)
expressionSet.setVariable(term.variableIndex, posq[4*permutedParticles[term.atom]+term.component]);
}
for (int i = 0; i < (int) data.distanceTerms.size(); i++) {
const DistanceTermInfo& term = data.distanceTerms[i];
for (auto& term : data.distanceTerms)
expressionSet.setVariable(term.variableIndex, normDelta[term.delta]);
}
for (int i = 0; i < (int) data.angleTerms.size(); i++) {
const AngleTermInfo& term = data.angleTerms[i];
for (auto& term : data.angleTerms)
expressionSet.setVariable(term.variableIndex, computeAngle(delta[term.delta1], delta[term.delta2], norm2Delta[term.delta1], norm2Delta[term.delta2], term.delta1Sign*term.delta2Sign));
}
for (int i = 0; i < (int) data.dihedralTerms.size(); i++) {
const DihedralTermInfo& term = data.dihedralTerms[i];
expressionSet.setVariable(term.variableIndex, getDihedralAngleBetweenThreeVectors(delta[term.delta1], delta[term.delta2], delta[term.delta3], cross1[i], cross2[i], delta[term.delta1]));
......@@ -310,8 +304,7 @@ void CpuCustomManyParticleForce::calculateOneIxn(vector<int>& particleSet, doubl
AlignedArray<fvec4>& f = data.f;
for (int i = 0; i < numParticlesPerSet; i++)
f[i] = fvec4(0.0f);
for (int i = 0; i < (int) data.particleTerms.size(); i++) {
const ParticleTermInfo& term = data.particleTerms[i];
for (auto& term : data.particleTerms) {
float temp[4];
f[term.atom].store(temp);
temp[term.component] -= term.forceExpression.evaluate();
......@@ -320,8 +313,7 @@ void CpuCustomManyParticleForce::calculateOneIxn(vector<int>& particleSet, doubl
// Apply forces based on distances.
for (int i = 0; i < (int) data.distanceTerms.size(); i++) {
const DistanceTermInfo& term = data.distanceTerms[i];
for (auto& term : data.distanceTerms) {
float dEdR = (float) (term.forceExpression.evaluate()*term.deltaSign/(normDelta[term.delta]));
fvec4 force = -dEdR*delta[term.delta];
f[term.p1] -= force;
......@@ -330,8 +322,7 @@ void CpuCustomManyParticleForce::calculateOneIxn(vector<int>& particleSet, doubl
// Apply forces based on angles.
for (int i = 0; i < (int) data.angleTerms.size(); i++) {
const AngleTermInfo& term = data.angleTerms[i];
for (auto& term : data.angleTerms) {
float dEdTheta = (float) term.forceExpression.evaluate();
fvec4 thetaCross = cross(delta[term.delta1], delta[term.delta2]);
float lengthThetaCross = sqrtf(dot3(thetaCross, thetaCross));
......@@ -482,20 +473,20 @@ CpuCustomManyParticleForce::ThreadData::ThreadData(const CustomManyParticleForce
particleParamIndices[i].push_back(expressionSet.getVariableIndex(paramname.str()));
}
}
for (map<string, vector<int> >::const_iterator iter = dihedrals.begin(); iter != dihedrals.end(); ++iter)
dihedralTerms.push_back(CpuCustomManyParticleForce::DihedralTermInfo(iter->first, iter->second, energyExpr.differentiate(iter->first).optimize().createCompiledExpression(), *this));
for (map<string, vector<int> >::const_iterator iter = distances.begin(); iter != distances.end(); ++iter)
distanceTerms.push_back(CpuCustomManyParticleForce::DistanceTermInfo(iter->first, iter->second, energyExpr.differentiate(iter->first).optimize().createCompiledExpression(), *this));
for (map<string, vector<int> >::const_iterator iter = angles.begin(); iter != angles.end(); ++iter)
angleTerms.push_back(CpuCustomManyParticleForce::AngleTermInfo(iter->first, iter->second, energyExpr.differentiate(iter->first).optimize().createCompiledExpression(), *this));
for (int i = 0; i < particleTerms.size(); i++)
expressionSet.registerExpression(particleTerms[i].forceExpression);
for (int i = 0; i < distanceTerms.size(); i++)
expressionSet.registerExpression(distanceTerms[i].forceExpression);
for (int i = 0; i < angleTerms.size(); i++)
expressionSet.registerExpression(angleTerms[i].forceExpression);
for (int i = 0; i < dihedralTerms.size(); i++)
expressionSet.registerExpression(dihedralTerms[i].forceExpression);
for (auto& term : dihedrals)
dihedralTerms.push_back(CpuCustomManyParticleForce::DihedralTermInfo(term.first, term.second, energyExpr.differentiate(term.first).optimize().createCompiledExpression(), *this));
for (auto& term : distances)
distanceTerms.push_back(CpuCustomManyParticleForce::DistanceTermInfo(term.first, term.second, energyExpr.differentiate(term.first).optimize().createCompiledExpression(), *this));
for (auto& term : angles)
angleTerms.push_back(CpuCustomManyParticleForce::AngleTermInfo(term.first, term.second, energyExpr.differentiate(term.first).optimize().createCompiledExpression(), *this));
for (auto& term : particleTerms)
expressionSet.registerExpression(term.forceExpression);
for (auto& term : distanceTerms)
expressionSet.registerExpression(term.forceExpression);
for (auto& term : angleTerms)
expressionSet.registerExpression(term.forceExpression);
for (auto& term : dihedralTerms)
expressionSet.registerExpression(term.forceExpression);
int numDeltas = deltaPairs.size();
delta.resize(numDeltas);
normDelta.resize(numDeltas);
......
......@@ -51,9 +51,9 @@ CpuCustomNonbondedForce::ThreadData::ThreadData(const Lepton::CompiledExpression
this->forceExpression.setVariableLocations(variableLocations);
expressionSet.registerExpression(this->energyExpression);
expressionSet.registerExpression(this->forceExpression);
for (int i = 0; i < this->energyParamDerivExpressions.size(); i++) {
this->energyParamDerivExpressions[i].setVariableLocations(variableLocations);
expressionSet.registerExpression(this->energyParamDerivExpressions[i]);
for (auto& expression : this->energyParamDerivExpressions) {
expression.setVariableLocations(variableLocations);
expressionSet.registerExpression(expression);
}
}
......@@ -66,8 +66,8 @@ CpuCustomNonbondedForce::CpuCustomNonbondedForce(const Lepton::CompiledExpressio
}
CpuCustomNonbondedForce::~CpuCustomNonbondedForce() {
for (int i = 0; i < (int) threadData.size(); i++)
delete threadData[i];
for (auto data : threadData)
delete data;
}
void CpuCustomNonbondedForce::setUseCutoff(double distance, const CpuNeighborList& neighbors) {
......@@ -78,9 +78,9 @@ void CpuCustomNonbondedForce::setUseCutoff(double distance, const CpuNeighborLis
void CpuCustomNonbondedForce::setInteractionGroups(const vector<pair<set<int>, set<int> > >& groups) {
useInteractionGroups = true;
for (int group = 0; group < (int) groups.size(); group++) {
const set<int>& set1 = groups[group].first;
const set<int>& set2 = groups[group].second;
for (auto& group : groups) {
const set<int>& set1 = group.first;
const set<int>& set2 = group.second;
for (set<int>::const_iterator atom1 = set1.begin(); atom1 != set1.end(); ++atom1) {
for (set<int>::const_iterator atom2 = set2.begin(); atom2 != set2.end(); ++atom2) {
if (*atom1 == *atom2 || exclusions[*atom1].find(*atom2) != exclusions[*atom1].end())
......@@ -167,10 +167,10 @@ void CpuCustomNonbondedForce::threadComputeForce(ThreadPool& threads, int thread
double& energy = threadEnergy[threadIndex];
float* forces = &(*threadForce)[threadIndex][0];
ThreadData& data = *threadData[threadIndex];
for (map<string, double>::const_iterator iter = globalParameters->begin(); iter != globalParameters->end(); ++iter)
data.expressionSet.setVariable(data.expressionSet.getVariableIndex(iter->first), iter->second);
for (int i = 0; i < data.energyParamDerivs.size(); i++)
data.energyParamDerivs[i] = 0.0;
for (auto& param : *globalParameters)
data.expressionSet.setVariable(data.expressionSet.getVariableIndex(param.first), param.second);
for (auto& deriv : data.energyParamDerivs)
deriv = 0.0;
fvec4 boxSize(periodicBoxVectors[0][0], periodicBoxVectors[1][1], periodicBoxVectors[2][2], 0);
fvec4 invBoxSize(recipBoxSize[0], recipBoxSize[1], recipBoxSize[2], 0);
if (useInteractionGroups) {
......
......@@ -98,8 +98,8 @@ static void validateVariables(const Lepton::ExpressionTreeNode& node, const set<
const Lepton::Operation& op = node.getOperation();
if (op.getId() == Lepton::Operation::VARIABLE && variables.find(op.getName()) == variables.end())
throw OpenMMException("Unknown variable in expression: "+op.getName());
for (int i = 0; i < (int) node.getChildren().size(); i++)
validateVariables(node.getChildren()[i], variables);
for (auto& child : node.getChildren())
validateVariables(child, variables);
}
/**
......@@ -867,8 +867,8 @@ void CpuCalcCustomNonbondedForceKernel::initialize(const System& system, const C
// Delete the custom functions.
for (map<string, Lepton::CustomFunction*>::iterator iter = functions.begin(); iter != functions.end(); iter++)
delete iter->second;
for (auto& function : functions)
delete function.second;
// Record information for the long range correction.
......@@ -909,11 +909,11 @@ double CpuCalcCustomNonbondedForceKernel::execute(ContextImpl& context, bool inc
nonbonded->setPeriodic(boxVectors);
}
bool globalParamsChanged = false;
for (int i = 0; i < (int) globalParameterNames.size(); i++) {
double value = context.getParameter(globalParameterNames[i]);
if (globalParamValues[globalParameterNames[i]] != value)
for (auto& name : globalParameterNames) {
double value = context.getParameter(name);
if (globalParamValues[name] != value)
globalParamsChanged = true;
globalParamValues[globalParameterNames[i]] = value;
globalParamValues[name] = value;
}
if (useSwitchingFunction)
nonbonded->setUseSwitchingFunction(switchingDistance);
......@@ -1155,8 +1155,8 @@ void CpuCalcCustomGBForceKernel::initialize(const System& system, const CustomGB
// Delete the custom functions.
for (map<string, Lepton::CustomFunction*>::iterator iter = functions.begin(); iter != functions.end(); iter++)
delete iter->second;
for (auto& function : functions)
delete function.second;
ixn = new CpuCustomGBForce(numParticles, exclusions, valueExpressions, valueDerivExpressions, valueGradientExpressions, valueParamDerivExpressions,
valueNames, valueTypes, energyExpressions, energyDerivExpressions, energyGradientExpressions, energyParamDerivExpressions, energyTypes,
particleParameterNames, data.threads);
......@@ -1174,8 +1174,8 @@ double CpuCalcCustomGBForceKernel::execute(ContextImpl& context, bool includeFor
ixn->setUseCutoff(nonbondedCutoff, *data.neighborList);
}
map<string, double> globalParameters;
for (int i = 0; i < (int) globalParameterNames.size(); i++)
globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]);
for (auto& name : globalParameterNames)
globalParameters[name] = context.getParameter(name);
vector<double> energyParamDerivValues(energyParamDerivNames.size()+1, 0.0);
ixn->calculateIxn(numParticles, &data.posq[0], particleParamArray, globalParameters, data.threadForce, includeForces, includeEnergy, energy, &energyParamDerivValues[0]);
map<string, double>& energyParamDerivs = extractEnergyParameterDerivatives(context);
......@@ -1236,8 +1236,8 @@ void CpuCalcCustomManyParticleForceKernel::initialize(const System& system, cons
double CpuCalcCustomManyParticleForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
map<string, double> globalParameters;
for (int i = 0; i < (int) globalParameterNames.size(); i++)
globalParameters[globalParameterNames[i]] = context.getParameter(globalParameterNames[i]);
for (auto& name : globalParameterNames)
globalParameters[name] = context.getParameter(name);
if (nonbondedMethod == CutoffPeriodic) {
Vec3* boxVectors = extractBoxVectors(context);
double minAllowedSize = 2*cutoffDistance;
......
......@@ -577,10 +577,10 @@ void CpuNeighborList::threadComputeNeighborList(ThreadPool& threads, int threadI
for (int j = 0; j < atomsInBlock; j++) {
const set<int>& atomExclusions = (*exclusions)[sortedAtoms[firstIndex+j]];
char mask = 1<<j;
for (set<int>::const_iterator iter = atomExclusions.begin(); iter != atomExclusions.end(); ++iter) {
map<int, char>::iterator thisAtomFlags = atomFlags.find(*iter);
for (int exclusion : atomExclusions) {
map<int, char>::iterator thisAtomFlags = atomFlags.find(exclusion);
if (thisAtomFlags == atomFlags.end())
atomFlags[*iter] = mask;
atomFlags[exclusion] = mask;
else
thisAtomFlags->second |= mask;
}
......
......@@ -447,9 +447,9 @@ void CpuNonbondedForce::threadComputeDirect(ThreadPool& threads, int threadIndex
for (int i = start; i < end; i++) {
fvec4 posI((float) atomCoordinates[i][0], (float) atomCoordinates[i][1], (float) atomCoordinates[i][2], 0.0f);
float scaledChargeI = (float) (ONE_4PI_EPS0*posq[4*i+3]);
for (set<int>::const_iterator iter = exclusions[i].begin(); iter != exclusions[i].end(); ++iter) {
if (*iter > i) {
int j = *iter;
for (int excluded : exclusions[i]) {
if (excluded > i) {
int j = excluded;
fvec4 deltaR;
fvec4 posJ((float) atomCoordinates[j][0], (float) atomCoordinates[j][1], (float) atomCoordinates[j][2], 0.0f);
float r2;
......
......@@ -34,8 +34,8 @@ CpuRandom::CpuRandom() : hasInitialized(false) {
}
CpuRandom::~CpuRandom() {
for (int i = 0; i < (int) threadRandom.size(); i++)
delete threadRandom[i];
for (auto random : threadRandom)
delete random;
}
void CpuRandom::initialize(int seed, int numThreads) {
......
......@@ -56,8 +56,8 @@ CpuSETTLE::CpuSETTLE(const System& system, const ReferenceSETTLEAlgorithm& settl
}
CpuSETTLE::~CpuSETTLE() {
for (int i = 0; i < (int) threadSettle.size(); i++)
delete threadSettle[i];
for (auto settle : threadSettle)
delete settle;
}
void CpuSETTLE::apply(vector<OpenMM::Vec3>& atomCoordinates, vector<OpenMM::Vec3>& atomCoordinatesP, vector<double>& inverseMasses, double tolerance) {
......
......@@ -385,14 +385,14 @@ CudaContext::CudaContext(const System& system, int deviceIndex, bool useBlocking
CudaContext::~CudaContext() {
setAsCurrent();
for (int i = 0; i < (int) forces.size(); i++)
delete forces[i];
for (int i = 0; i < (int) reorderListeners.size(); i++)
delete reorderListeners[i];
for (int i = 0; i < (int) preComputations.size(); i++)
delete preComputations[i];
for (int i = 0; i < (int) postComputations.size(); i++)
delete postComputations[i];
for (auto force : forces)
delete force;
for (auto listener : reorderListeners)
delete listener;
for (auto computation : preComputations)
delete computation;
for (auto computation : postComputations)
delete computation;
if (pinnedBuffer != NULL)
cuMemFreeHost(pinnedBuffer);
if (posq != NULL)
......@@ -498,17 +498,17 @@ string CudaContext::replaceStrings(const string& input, const std::map<std::stri
symbolChars.insert(c);
}
string result = input;
for (map<string, string>::const_iterator iter = replacements.begin(); iter != replacements.end(); iter++) {
for (auto& pair : replacements) {
int index = 0;
int size = iter->first.size();
int size = pair.first.size();
do {
index = result.find(iter->first, index);
index = result.find(pair.first, index);
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())) {
// We have found a complete symbol, not part of a longer symbol.
result.replace(index, size, iter->second);
index += iter->second.size();
result.replace(index, size, pair.second);
index += pair.second.size();
}
else
index++;
......@@ -528,10 +528,10 @@ CUmodule CudaContext::createModule(const string source, const map<string, string
stringstream src;
if (!options.empty())
src << "// Compilation Options: " << options << endl << endl;
for (map<string, string>::const_iterator iter = compilationDefines.begin(); iter != compilationDefines.end(); ++iter) {
src << "#define " << iter->first;
if (!iter->second.empty())
src << " " << iter->second;
for (auto& pair : compilationDefines) {
src << "#define " << pair.first;
if (!pair.second.empty())
src << " " << pair.second;
src << endl;
}
if (!compilationDefines.empty())
......@@ -561,10 +561,10 @@ CUmodule CudaContext::createModule(const string source, const map<string, string
src << "typedef float4 mixed4;\n";
}
src << "typedef unsigned int tileflags;\n";
for (map<string, string>::const_iterator iter = defines.begin(); iter != defines.end(); ++iter) {
src << "#define " << iter->first;
if (!iter->second.empty())
src << " " << iter->second;
for (auto& pair : defines) {
src << "#define " << pair.first;
if (!pair.second.empty())
src << " " << pair.second;
src << endl;
}
if (!defines.empty())
......@@ -966,10 +966,10 @@ void CudaContext::findMoleculeGroups() {
atomBonds[particle1].push_back(particle2);
atomBonds[particle2].push_back(particle1);
}
for (int i = 0; i < (int) forces.size(); i++) {
for (int j = 0; j < forces[i]->getNumParticleGroups(); j++) {
for (auto force : forces) {
for (int j = 0; j < force->getNumParticleGroups(); j++) {
vector<int> particles;
forces[i]->getParticlesInGroup(j, particles);
force->getParticlesInGroup(j, particles);
for (int k = 0; k < (int) particles.size(); k++)
for (int m = 0; m < (int) particles.size(); m++)
if (k != m)
......@@ -1187,8 +1187,8 @@ bool CudaContext::invalidateMolecules(CudaForceInfo* force) {
}
atomIndexDevice->upload(atomIndex);
findMoleculeGroups();
for (int i = 0; i < (int) reorderListeners.size(); i++)
reorderListeners[i]->execute();
for (auto listener : reorderListeners)
listener->execute();
reorderAtoms();
return true;
}
......@@ -1250,10 +1250,9 @@ void CudaContext::reorderAtomsImpl() {
vector<Real4> newPosqCorrection(paddedNumAtoms);
vector<Mixed4> newVelm(paddedNumAtoms);
vector<int4> newCellOffsets(numAtoms);
for (int group = 0; group < (int) moleculeGroups.size(); group++) {
for (auto& mol : moleculeGroups) {
// Find the center of each molecule.
MoleculeGroup& mol = moleculeGroups[group];
int numMolecules = mol.offsets.size();
vector<int>& atoms = mol.atoms;
vector<Real4> molPos(numMolecules);
......@@ -1347,9 +1346,9 @@ void CudaContext::reorderAtomsImpl() {
// Reorder the atoms.
for (int i = 0; i < numMolecules; i++) {
for (int j = 0; j < (int)atoms.size(); j++) {
int oldIndex = mol.offsets[molBins[i].second]+atoms[j];
int newIndex = mol.offsets[i]+atoms[j];
for (int atom : atoms) {
int oldIndex = mol.offsets[molBins[i].second]+atom;
int newIndex = mol.offsets[i]+atom;
originalIndex[newIndex] = atomIndex[oldIndex];
newPosq[newIndex] = oldPosq[oldIndex];
if (useMixedPrecision)
......@@ -1371,8 +1370,8 @@ void CudaContext::reorderAtomsImpl() {
posqCorrection->upload(newPosqCorrection);
velm->upload(newVelm);
atomIndexDevice->upload(atomIndex);
for (int i = 0; i < (int) reorderListeners.size(); i++)
reorderListeners[i]->execute();
for (auto listener : reorderListeners)
listener->execute();
}
void CudaContext::addReorderListener(ReorderListener* listener) {
......
......@@ -456,12 +456,12 @@ void CudaExpressionUtilities::processExpression(stringstream& out, const Express
vector<bool> hasAssigned(powers.size(), false);
exponents.push_back((int) fabs(exponent));
names.push_back(name);
for (map<int, const ExpressionTreeNode*>::const_iterator iter = powers.begin(); iter != powers.end(); ++iter) {
if (iter->first != exponent) {
exponents.push_back(iter->first >= 0 ? iter->first : -iter->first);
for (auto& power : powers) {
if (power.first != exponent) {
exponents.push_back(power.first >= 0 ? power.first : -power.first);
string name2 = prefix+context.intToString(temps.size());
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";
}
}
......
This diff is collapsed.
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