Commit 6a14b5b1 authored by Peter Eastman's avatar Peter Eastman
Browse files

Avoid errors in updateParametersInContext() when a force contains no bonds.

parent 38071b45
...@@ -477,6 +477,8 @@ void CudaCalcHarmonicBondForceKernel::copyParametersToContext(ContextImpl& conte ...@@ -477,6 +477,8 @@ void CudaCalcHarmonicBondForceKernel::copyParametersToContext(ContextImpl& conte
int endIndex = (cu.getContextIndex()+1)*force.getNumBonds()/numContexts; int endIndex = (cu.getContextIndex()+1)*force.getNumBonds()/numContexts;
if (numBonds != endIndex-startIndex) if (numBonds != endIndex-startIndex)
throw OpenMMException("updateParametersInContext: The number of bonds has changed"); throw OpenMMException("updateParametersInContext: The number of bonds has changed");
if (numBonds == 0)
return;
// Record the per-bond parameters. // Record the per-bond parameters.
...@@ -619,6 +621,8 @@ void CudaCalcCustomBondForceKernel::copyParametersToContext(ContextImpl& context ...@@ -619,6 +621,8 @@ void CudaCalcCustomBondForceKernel::copyParametersToContext(ContextImpl& context
int endIndex = (cu.getContextIndex()+1)*force.getNumBonds()/numContexts; int endIndex = (cu.getContextIndex()+1)*force.getNumBonds()/numContexts;
if (numBonds != endIndex-startIndex) if (numBonds != endIndex-startIndex)
throw OpenMMException("updateParametersInContext: The number of bonds has changed"); throw OpenMMException("updateParametersInContext: The number of bonds has changed");
if (numBonds == 0)
return;
// Record the per-bond parameters. // Record the per-bond parameters.
...@@ -707,6 +711,8 @@ void CudaCalcHarmonicAngleForceKernel::copyParametersToContext(ContextImpl& cont ...@@ -707,6 +711,8 @@ void CudaCalcHarmonicAngleForceKernel::copyParametersToContext(ContextImpl& cont
int endIndex = (cu.getContextIndex()+1)*force.getNumAngles()/numContexts; int endIndex = (cu.getContextIndex()+1)*force.getNumAngles()/numContexts;
if (numAngles != endIndex-startIndex) if (numAngles != endIndex-startIndex)
throw OpenMMException("updateParametersInContext: The number of angles has changed"); throw OpenMMException("updateParametersInContext: The number of angles has changed");
if (numAngles == 0)
return;
// Record the per-angle parameters. // Record the per-angle parameters.
...@@ -850,6 +856,8 @@ void CudaCalcCustomAngleForceKernel::copyParametersToContext(ContextImpl& contex ...@@ -850,6 +856,8 @@ void CudaCalcCustomAngleForceKernel::copyParametersToContext(ContextImpl& contex
int endIndex = (cu.getContextIndex()+1)*force.getNumAngles()/numContexts; int endIndex = (cu.getContextIndex()+1)*force.getNumAngles()/numContexts;
if (numAngles != endIndex-startIndex) if (numAngles != endIndex-startIndex)
throw OpenMMException("updateParametersInContext: The number of angles has changed"); throw OpenMMException("updateParametersInContext: The number of angles has changed");
if (numAngles == 0)
return;
// Record the per-angle parameters. // Record the per-angle parameters.
...@@ -939,6 +947,8 @@ void CudaCalcPeriodicTorsionForceKernel::copyParametersToContext(ContextImpl& co ...@@ -939,6 +947,8 @@ void CudaCalcPeriodicTorsionForceKernel::copyParametersToContext(ContextImpl& co
int endIndex = (cu.getContextIndex()+1)*force.getNumTorsions()/numContexts; int endIndex = (cu.getContextIndex()+1)*force.getNumTorsions()/numContexts;
if (numTorsions != endIndex-startIndex) if (numTorsions != endIndex-startIndex)
throw OpenMMException("updateParametersInContext: The number of torsions has changed"); throw OpenMMException("updateParametersInContext: The number of torsions has changed");
if (numTorsions == 0)
return;
// Record the per-torsion parameters. // Record the per-torsion parameters.
...@@ -1033,6 +1043,8 @@ void CudaCalcRBTorsionForceKernel::copyParametersToContext(ContextImpl& context, ...@@ -1033,6 +1043,8 @@ void CudaCalcRBTorsionForceKernel::copyParametersToContext(ContextImpl& context,
int endIndex = (cu.getContextIndex()+1)*force.getNumTorsions()/numContexts; int endIndex = (cu.getContextIndex()+1)*force.getNumTorsions()/numContexts;
if (numTorsions != endIndex-startIndex) if (numTorsions != endIndex-startIndex)
throw OpenMMException("updateParametersInContext: The number of torsions has changed"); throw OpenMMException("updateParametersInContext: The number of torsions has changed");
if (numTorsions == 0)
return;
// Record the per-torsion parameters. // Record the per-torsion parameters.
...@@ -1267,6 +1279,8 @@ void CudaCalcCustomTorsionForceKernel::copyParametersToContext(ContextImpl& cont ...@@ -1267,6 +1279,8 @@ void CudaCalcCustomTorsionForceKernel::copyParametersToContext(ContextImpl& cont
int endIndex = (cu.getContextIndex()+1)*force.getNumTorsions()/numContexts; int endIndex = (cu.getContextIndex()+1)*force.getNumTorsions()/numContexts;
if (numTorsions != endIndex-startIndex) if (numTorsions != endIndex-startIndex)
throw OpenMMException("updateParametersInContext: The number of torsions has changed"); throw OpenMMException("updateParametersInContext: The number of torsions has changed");
if (numTorsions == 0)
return;
// Record the per-torsion parameters. // Record the per-torsion parameters.
...@@ -3112,6 +3126,8 @@ void CudaCalcCustomExternalForceKernel::copyParametersToContext(ContextImpl& con ...@@ -3112,6 +3126,8 @@ void CudaCalcCustomExternalForceKernel::copyParametersToContext(ContextImpl& con
int endIndex = (cu.getContextIndex()+1)*force.getNumParticles()/numContexts; int endIndex = (cu.getContextIndex()+1)*force.getNumParticles()/numContexts;
if (numParticles != endIndex-startIndex) if (numParticles != endIndex-startIndex)
throw OpenMMException("updateParametersInContext: The number of particles has changed"); throw OpenMMException("updateParametersInContext: The number of particles has changed");
if (numParticles == 0)
return;
// Record the per-particle parameters. // Record the per-particle parameters.
...@@ -3622,28 +3638,33 @@ void CudaCalcCustomHbondForceKernel::copyParametersToContext(ContextImpl& contex ...@@ -3622,28 +3638,33 @@ void CudaCalcCustomHbondForceKernel::copyParametersToContext(ContextImpl& contex
// Record the per-donor parameters. // Record the per-donor parameters.
vector<vector<float> > donorParamVector(numDonors); if (numDonors > 0) {
vector<double> parameters; vector<vector<float> > donorParamVector(numDonors);
for (int i = 0; i < numDonors; i++) { vector<double> parameters;
int d1, d2, d3; for (int i = 0; i < numDonors; i++) {
force.getDonorParameters(startIndex+i, d1, d2, d3, parameters); int d1, d2, d3;
donorParamVector[i].resize(parameters.size()); force.getDonorParameters(startIndex+i, d1, d2, d3, parameters);
for (int j = 0; j < (int) parameters.size(); j++) donorParamVector[i].resize(parameters.size());
donorParamVector[i][j] = (float) parameters[j]; for (int j = 0; j < (int) parameters.size(); j++)
donorParamVector[i][j] = (float) parameters[j];
}
donorParams->setParameterValues(donorParamVector);
} }
donorParams->setParameterValues(donorParamVector);
// Record the per-acceptor parameters. // Record the per-acceptor parameters.
vector<vector<float> > acceptorParamVector(numAcceptors); if (numAcceptors > 0) {
for (int i = 0; i < numAcceptors; i++) { vector<vector<float> > acceptorParamVector(numAcceptors);
int a1, a2, a3; vector<double> parameters;
force.getAcceptorParameters(i, a1, a2, a3, parameters); for (int i = 0; i < numAcceptors; i++) {
acceptorParamVector[i].resize(parameters.size()); int a1, a2, a3;
for (int j = 0; j < (int) parameters.size(); j++) force.getAcceptorParameters(i, a1, a2, a3, parameters);
acceptorParamVector[i][j] = (float) parameters[j]; acceptorParamVector[i].resize(parameters.size());
for (int j = 0; j < (int) parameters.size(); j++)
acceptorParamVector[i][j] = (float) parameters[j];
}
acceptorParams->setParameterValues(acceptorParamVector);
} }
acceptorParams->setParameterValues(acceptorParamVector);
// Mark that the current reordering may be invalid. // Mark that the current reordering may be invalid.
...@@ -3951,6 +3972,8 @@ void CudaCalcCustomCompoundBondForceKernel::copyParametersToContext(ContextImpl& ...@@ -3951,6 +3972,8 @@ void CudaCalcCustomCompoundBondForceKernel::copyParametersToContext(ContextImpl&
int endIndex = (cu.getContextIndex()+1)*force.getNumBonds()/numContexts; int endIndex = (cu.getContextIndex()+1)*force.getNumBonds()/numContexts;
if (numBonds != endIndex-startIndex) if (numBonds != endIndex-startIndex)
throw OpenMMException("updateParametersInContext: The number of bonds has changed"); throw OpenMMException("updateParametersInContext: The number of bonds has changed");
if (numBonds == 0)
return;
// Record the per-bond parameters. // Record the per-bond parameters.
......
...@@ -499,6 +499,8 @@ void OpenCLCalcHarmonicBondForceKernel::copyParametersToContext(ContextImpl& con ...@@ -499,6 +499,8 @@ void OpenCLCalcHarmonicBondForceKernel::copyParametersToContext(ContextImpl& con
int endIndex = (cl.getContextIndex()+1)*force.getNumBonds()/numContexts; int endIndex = (cl.getContextIndex()+1)*force.getNumBonds()/numContexts;
if (numBonds != endIndex-startIndex) if (numBonds != endIndex-startIndex)
throw OpenMMException("updateParametersInContext: The number of bonds has changed"); throw OpenMMException("updateParametersInContext: The number of bonds has changed");
if (numBonds == 0)
return;
// Record the per-bond parameters. // Record the per-bond parameters.
...@@ -638,6 +640,8 @@ void OpenCLCalcCustomBondForceKernel::copyParametersToContext(ContextImpl& conte ...@@ -638,6 +640,8 @@ void OpenCLCalcCustomBondForceKernel::copyParametersToContext(ContextImpl& conte
int endIndex = (cl.getContextIndex()+1)*force.getNumBonds()/numContexts; int endIndex = (cl.getContextIndex()+1)*force.getNumBonds()/numContexts;
if (numBonds != endIndex-startIndex) if (numBonds != endIndex-startIndex)
throw OpenMMException("updateParametersInContext: The number of bonds has changed"); throw OpenMMException("updateParametersInContext: The number of bonds has changed");
if (numBonds == 0)
return;
// Record the per-bond parameters. // Record the per-bond parameters.
...@@ -723,6 +727,8 @@ void OpenCLCalcHarmonicAngleForceKernel::copyParametersToContext(ContextImpl& co ...@@ -723,6 +727,8 @@ void OpenCLCalcHarmonicAngleForceKernel::copyParametersToContext(ContextImpl& co
int endIndex = (cl.getContextIndex()+1)*force.getNumAngles()/numContexts; int endIndex = (cl.getContextIndex()+1)*force.getNumAngles()/numContexts;
if (numAngles != endIndex-startIndex) if (numAngles != endIndex-startIndex)
throw OpenMMException("updateParametersInContext: The number of angles has changed"); throw OpenMMException("updateParametersInContext: The number of angles has changed");
if (numAngles == 0)
return;
// Record the per-angle parameters. // Record the per-angle parameters.
...@@ -863,6 +869,8 @@ void OpenCLCalcCustomAngleForceKernel::copyParametersToContext(ContextImpl& cont ...@@ -863,6 +869,8 @@ void OpenCLCalcCustomAngleForceKernel::copyParametersToContext(ContextImpl& cont
int endIndex = (cl.getContextIndex()+1)*force.getNumAngles()/numContexts; int endIndex = (cl.getContextIndex()+1)*force.getNumAngles()/numContexts;
if (numAngles != endIndex-startIndex) if (numAngles != endIndex-startIndex)
throw OpenMMException("updateParametersInContext: The number of angles has changed"); throw OpenMMException("updateParametersInContext: The number of angles has changed");
if (numAngles == 0)
return;
// Record the per-angle parameters. // Record the per-angle parameters.
...@@ -949,6 +957,8 @@ void OpenCLCalcPeriodicTorsionForceKernel::copyParametersToContext(ContextImpl& ...@@ -949,6 +957,8 @@ void OpenCLCalcPeriodicTorsionForceKernel::copyParametersToContext(ContextImpl&
int endIndex = (cl.getContextIndex()+1)*force.getNumTorsions()/numContexts; int endIndex = (cl.getContextIndex()+1)*force.getNumTorsions()/numContexts;
if (numTorsions != endIndex-startIndex) if (numTorsions != endIndex-startIndex)
throw OpenMMException("updateParametersInContext: The number of torsions has changed"); throw OpenMMException("updateParametersInContext: The number of torsions has changed");
if (numTorsions == 0)
return;
// Record the per-torsion parameters. // Record the per-torsion parameters.
...@@ -1033,6 +1043,8 @@ void OpenCLCalcRBTorsionForceKernel::copyParametersToContext(ContextImpl& contex ...@@ -1033,6 +1043,8 @@ void OpenCLCalcRBTorsionForceKernel::copyParametersToContext(ContextImpl& contex
int endIndex = (cl.getContextIndex()+1)*force.getNumTorsions()/numContexts; int endIndex = (cl.getContextIndex()+1)*force.getNumTorsions()/numContexts;
if (numTorsions != endIndex-startIndex) if (numTorsions != endIndex-startIndex)
throw OpenMMException("updateParametersInContext: The number of torsions has changed"); throw OpenMMException("updateParametersInContext: The number of torsions has changed");
if (numTorsions == 0)
return;
// Record the per-torsion parameters. // Record the per-torsion parameters.
...@@ -1261,6 +1273,8 @@ void OpenCLCalcCustomTorsionForceKernel::copyParametersToContext(ContextImpl& co ...@@ -1261,6 +1273,8 @@ void OpenCLCalcCustomTorsionForceKernel::copyParametersToContext(ContextImpl& co
int endIndex = (cl.getContextIndex()+1)*force.getNumTorsions()/numContexts; int endIndex = (cl.getContextIndex()+1)*force.getNumTorsions()/numContexts;
if (numTorsions != endIndex-startIndex) if (numTorsions != endIndex-startIndex)
throw OpenMMException("updateParametersInContext: The number of torsions has changed"); throw OpenMMException("updateParametersInContext: The number of torsions has changed");
if (numTorsions == 0)
return;
// Record the per-torsion parameters. // Record the per-torsion parameters.
...@@ -3272,6 +3286,8 @@ void OpenCLCalcCustomExternalForceKernel::copyParametersToContext(ContextImpl& c ...@@ -3272,6 +3286,8 @@ void OpenCLCalcCustomExternalForceKernel::copyParametersToContext(ContextImpl& c
int endIndex = (cl.getContextIndex()+1)*force.getNumParticles()/numContexts; int endIndex = (cl.getContextIndex()+1)*force.getNumParticles()/numContexts;
if (numParticles != endIndex-startIndex) if (numParticles != endIndex-startIndex)
throw OpenMMException("updateParametersInContext: The number of particles has changed"); throw OpenMMException("updateParametersInContext: The number of particles has changed");
if (numParticles == 0)
return;
// Record the per-particle parameters. // Record the per-particle parameters.
...@@ -3812,28 +3828,33 @@ void OpenCLCalcCustomHbondForceKernel::copyParametersToContext(ContextImpl& cont ...@@ -3812,28 +3828,33 @@ void OpenCLCalcCustomHbondForceKernel::copyParametersToContext(ContextImpl& cont
// Record the per-donor parameters. // Record the per-donor parameters.
vector<vector<cl_float> > donorParamVector(numDonors); if (numDonors > 0) {
vector<double> parameters; vector<vector<cl_float> > donorParamVector(numDonors);
for (int i = 0; i < numDonors; i++) { vector<double> parameters;
int d1, d2, d3; for (int i = 0; i < numDonors; i++) {
force.getDonorParameters(startIndex+i, d1, d2, d3, parameters); int d1, d2, d3;
donorParamVector[i].resize(parameters.size()); force.getDonorParameters(startIndex+i, d1, d2, d3, parameters);
for (int j = 0; j < (int) parameters.size(); j++) donorParamVector[i].resize(parameters.size());
donorParamVector[i][j] = (cl_float) parameters[j]; for (int j = 0; j < (int) parameters.size(); j++)
donorParamVector[i][j] = (cl_float) parameters[j];
}
donorParams->setParameterValues(donorParamVector);
} }
donorParams->setParameterValues(donorParamVector);
// Record the per-acceptor parameters. // Record the per-acceptor parameters.
vector<vector<cl_float> > acceptorParamVector(numAcceptors); if (numAcceptors > 0) {
for (int i = 0; i < numAcceptors; i++) { vector<vector<cl_float> > acceptorParamVector(numAcceptors);
int a1, a2, a3; vector<double> parameters;
force.getAcceptorParameters(i, a1, a2, a3, parameters); for (int i = 0; i < numAcceptors; i++) {
acceptorParamVector[i].resize(parameters.size()); int a1, a2, a3;
for (int j = 0; j < (int) parameters.size(); j++) force.getAcceptorParameters(i, a1, a2, a3, parameters);
acceptorParamVector[i][j] = (cl_float) parameters[j]; acceptorParamVector[i].resize(parameters.size());
for (int j = 0; j < (int) parameters.size(); j++)
acceptorParamVector[i][j] = (cl_float) parameters[j];
}
acceptorParams->setParameterValues(acceptorParamVector);
} }
acceptorParams->setParameterValues(acceptorParamVector);
// Mark that the current reordering may be invalid. // Mark that the current reordering may be invalid.
...@@ -4138,6 +4159,8 @@ void OpenCLCalcCustomCompoundBondForceKernel::copyParametersToContext(ContextImp ...@@ -4138,6 +4159,8 @@ void OpenCLCalcCustomCompoundBondForceKernel::copyParametersToContext(ContextImp
int endIndex = (cl.getContextIndex()+1)*force.getNumBonds()/numContexts; int endIndex = (cl.getContextIndex()+1)*force.getNumBonds()/numContexts;
if (numBonds != endIndex-startIndex) if (numBonds != endIndex-startIndex)
throw OpenMMException("updateParametersInContext: The number of bonds has changed"); throw OpenMMException("updateParametersInContext: The number of bonds has changed");
if (numBonds == 0)
return;
// Record the per-bond parameters. // Record the per-bond parameters.
......
...@@ -130,6 +130,8 @@ void CudaCalcAmoebaBondForceKernel::copyParametersToContext(ContextImpl& context ...@@ -130,6 +130,8 @@ void CudaCalcAmoebaBondForceKernel::copyParametersToContext(ContextImpl& context
int endIndex = (cu.getContextIndex()+1)*force.getNumBonds()/numContexts; int endIndex = (cu.getContextIndex()+1)*force.getNumBonds()/numContexts;
if (numBonds != endIndex-startIndex) if (numBonds != endIndex-startIndex)
throw OpenMMException("updateParametersInContext: The number of bonds has changed"); throw OpenMMException("updateParametersInContext: The number of bonds has changed");
if (numBonds == 0)
return;
// Record the per-bond parameters. // Record the per-bond parameters.
...@@ -228,6 +230,8 @@ void CudaCalcAmoebaAngleForceKernel::copyParametersToContext(ContextImpl& contex ...@@ -228,6 +230,8 @@ void CudaCalcAmoebaAngleForceKernel::copyParametersToContext(ContextImpl& contex
int endIndex = (cu.getContextIndex()+1)*force.getNumAngles()/numContexts; int endIndex = (cu.getContextIndex()+1)*force.getNumAngles()/numContexts;
if (numAngles != endIndex-startIndex) if (numAngles != endIndex-startIndex)
throw OpenMMException("updateParametersInContext: The number of angles has changed"); throw OpenMMException("updateParametersInContext: The number of angles has changed");
if (numAngles == 0)
return;
// Record the per-angle parameters. // Record the per-angle parameters.
...@@ -326,6 +330,8 @@ void CudaCalcAmoebaInPlaneAngleForceKernel::copyParametersToContext(ContextImpl& ...@@ -326,6 +330,8 @@ void CudaCalcAmoebaInPlaneAngleForceKernel::copyParametersToContext(ContextImpl&
int endIndex = (cu.getContextIndex()+1)*force.getNumAngles()/numContexts; int endIndex = (cu.getContextIndex()+1)*force.getNumAngles()/numContexts;
if (numAngles != endIndex-startIndex) if (numAngles != endIndex-startIndex)
throw OpenMMException("updateParametersInContext: The number of in-plane angles has changed"); throw OpenMMException("updateParametersInContext: The number of in-plane angles has changed");
if (numAngles == 0)
return;
// Record the per-angle parameters. // Record the per-angle parameters.
...@@ -421,6 +427,8 @@ void CudaCalcAmoebaPiTorsionForceKernel::copyParametersToContext(ContextImpl& co ...@@ -421,6 +427,8 @@ void CudaCalcAmoebaPiTorsionForceKernel::copyParametersToContext(ContextImpl& co
int endIndex = (cu.getContextIndex()+1)*force.getNumPiTorsions()/numContexts; int endIndex = (cu.getContextIndex()+1)*force.getNumPiTorsions()/numContexts;
if (numPiTorsions != endIndex-startIndex) if (numPiTorsions != endIndex-startIndex)
throw OpenMMException("updateParametersInContext: The number of torsions has changed"); throw OpenMMException("updateParametersInContext: The number of torsions has changed");
if (numPiTorsions == 0)
return;
// Record the per-torsion parameters. // Record the per-torsion parameters.
...@@ -514,6 +522,8 @@ void CudaCalcAmoebaStretchBendForceKernel::copyParametersToContext(ContextImpl& ...@@ -514,6 +522,8 @@ void CudaCalcAmoebaStretchBendForceKernel::copyParametersToContext(ContextImpl&
int endIndex = (cu.getContextIndex()+1)*force.getNumStretchBends()/numContexts; int endIndex = (cu.getContextIndex()+1)*force.getNumStretchBends()/numContexts;
if (numStretchBends != endIndex-startIndex) if (numStretchBends != endIndex-startIndex)
throw OpenMMException("updateParametersInContext: The number of bend-stretch terms has changed"); throw OpenMMException("updateParametersInContext: The number of bend-stretch terms has changed");
if (numStretchBends == 0)
return;
// Record the per-stretch-bend parameters. // Record the per-stretch-bend parameters.
...@@ -612,6 +622,8 @@ void CudaCalcAmoebaOutOfPlaneBendForceKernel::copyParametersToContext(ContextImp ...@@ -612,6 +622,8 @@ void CudaCalcAmoebaOutOfPlaneBendForceKernel::copyParametersToContext(ContextImp
int endIndex = (cu.getContextIndex()+1)*force.getNumOutOfPlaneBends()/numContexts; int endIndex = (cu.getContextIndex()+1)*force.getNumOutOfPlaneBends()/numContexts;
if (numOutOfPlaneBends != endIndex-startIndex) if (numOutOfPlaneBends != endIndex-startIndex)
throw OpenMMException("updateParametersInContext: The number of out-of-plane bends has changed"); throw OpenMMException("updateParametersInContext: The number of out-of-plane bends has changed");
if (numOutOfPlaneBends == 0)
return;
// Record the per-bend parameters. // Record the per-bend parameters.
......
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