Commit a37f4b76 authored by Peter Eastman's avatar Peter Eastman
Browse files

Throw an exception if the cutoff distance is greater than half the box size (bug 1023)

parent 82554f15
......@@ -95,6 +95,13 @@ void CustomGBForceImpl::initialize(ContextImpl& context) {
exclusions[particle1].insert(particle2);
exclusions[particle2].insert(particle1);
}
if (owner.getNonbondedMethod() == CustomGBForce::CutoffPeriodic) {
Vec3 boxVectors[3];
system.getPeriodicBoxVectors(boxVectors[0], boxVectors[1], boxVectors[2]);
double cutoff = owner.getCutoffDistance();
if (cutoff > 0.5*boxVectors[0][0] || cutoff > 0.5*boxVectors[1][1] || cutoff > 0.5*boxVectors[2][2])
throw OpenMMException("CustomGBForce: The cutoff distance cannot be greater than half the periodic box size.");
}
dynamic_cast<CalcCustomGBForceKernel&>(kernel.getImpl()).initialize(context.getSystem(), owner);
}
......
......@@ -95,6 +95,13 @@ void CustomNonbondedForceImpl::initialize(ContextImpl& context) {
exclusions[particle1].insert(particle2);
exclusions[particle2].insert(particle1);
}
if (owner.getNonbondedMethod() == CustomNonbondedForce::CutoffPeriodic) {
Vec3 boxVectors[3];
system.getPeriodicBoxVectors(boxVectors[0], boxVectors[1], boxVectors[2]);
double cutoff = owner.getCutoffDistance();
if (cutoff > 0.5*boxVectors[0][0] || cutoff > 0.5*boxVectors[1][1] || cutoff > 0.5*boxVectors[2][2])
throw OpenMMException("CustomNonbondedForce: The cutoff distance cannot be greater than half the periodic box size.");
}
dynamic_cast<CalcCustomNonbondedForceKernel&>(kernel.getImpl()).initialize(context.getSystem(), owner);
}
......
......@@ -45,6 +45,13 @@ void GBSAOBCForceImpl::initialize(ContextImpl& context) {
kernel = context.getPlatform().createKernel(CalcGBSAOBCForceKernel::Name(), context);
if (owner.getNumParticles() != context.getSystem().getNumParticles())
throw OpenMMException("GBSAOBCForce must have exactly as many particles as the System it belongs to.");
if (owner.getNonbondedMethod() == GBSAOBCForce::CutoffPeriodic) {
Vec3 boxVectors[3];
context.getSystem().getPeriodicBoxVectors(boxVectors[0], boxVectors[1], boxVectors[2]);
double cutoff = owner.getCutoffDistance();
if (cutoff > 0.5*boxVectors[0][0] || cutoff > 0.5*boxVectors[1][1] || cutoff > 0.5*boxVectors[2][2])
throw OpenMMException("GBSAOBCForce: The cutoff distance cannot be greater than half the periodic box size.");
}
dynamic_cast<CalcGBSAOBCForceKernel&>(kernel.getImpl()).initialize(context.getSystem(), owner);
}
......
......@@ -94,6 +94,13 @@ void GBVIForceImpl::initialize(ContextImpl& context) {
bondIndices[i].push_back( particle2 );
bondLengths[i] = bondLength;
}
if (owner.getNonbondedMethod() == GBVIForce::CutoffPeriodic) {
Vec3 boxVectors[3];
system.getPeriodicBoxVectors(boxVectors[0], boxVectors[1], boxVectors[2]);
double cutoff = owner.getCutoffDistance();
if (cutoff > 0.5*boxVectors[0][0] || cutoff > 0.5*boxVectors[1][1] || cutoff > 0.5*boxVectors[2][2])
throw OpenMMException("GBVIForce: The cutoff distance cannot be greater than half the periodic box size.");
}
vector<double> scaledRadii;
scaledRadii.resize(numberOfParticles);
......
......@@ -85,6 +85,15 @@ void NonbondedForceImpl::initialize(ContextImpl& context) {
exceptions[particle1].insert(particle2);
exceptions[particle2].insert(particle1);
}
if (owner.getNonbondedMethod() == NonbondedForce::CutoffPeriodic ||
owner.getNonbondedMethod() == NonbondedForce::Ewald ||
owner.getNonbondedMethod() == NonbondedForce::PME) {
Vec3 boxVectors[3];
system.getPeriodicBoxVectors(boxVectors[0], boxVectors[1], boxVectors[2]);
double cutoff = owner.getCutoffDistance();
if (cutoff > 0.5*boxVectors[0][0] || cutoff > 0.5*boxVectors[1][1] || cutoff > 0.5*boxVectors[2][2])
throw OpenMMException("NonbondedForce: The cutoff distance cannot be greater than half the periodic box size.");
}
dynamic_cast<CalcNonbondedForceKernel&>(kernel.getImpl()).initialize(context.getSystem(), owner);
}
......
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