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

Fixed bug when CustomGBForce was told to use exclusions, but didn't have any...

Fixed bug when CustomGBForce was told to use exclusions, but didn't have any exclusions.  (See bug 1519.)
parent 6ab42996
......@@ -2136,15 +2136,14 @@ void OpenCLCalcCustomGBForceKernel::initialize(const System& system, const Custo
for (int i = 0; i < force.getNumGlobalParameters(); i++)
variables[force.getGlobalParameterName(i)] = "globals["+intToString(i)+"]";
stringstream n2EnergySource;
bool anyExclusions = false;
bool anyExclusions = (force.getNumExclusions() > 0);
for (int i = 0; i < force.getNumEnergyTerms(); i++) {
string expression;
CustomGBForce::ComputationType type;
force.getEnergyTermParameters(i, expression, type);
if (type == CustomGBForce::SingleParticle)
continue;
bool exclude = (type == CustomGBForce::ParticlePair);
anyExclusions |= exclude;
bool exclude = (anyExclusions && type == CustomGBForce::ParticlePair);
map<string, Lepton::ParsedExpression> n2EnergyExpressions;
n2EnergyExpressions["tempEnergy += "] = Lepton::Parser::parse(expression, functions).optimize();
n2EnergyExpressions["dEdR += "] = Lepton::Parser::parse(expression, functions).differentiate("r").optimize();
......
......@@ -35,7 +35,7 @@
using namespace OpenMM;
using namespace std;
OpenCLNonbondedUtilities::OpenCLNonbondedUtilities(OpenCLContext& context) : context(context), cutoff(-1.0), useCutoff(false),
OpenCLNonbondedUtilities::OpenCLNonbondedUtilities(OpenCLContext& context) : context(context), cutoff(-1.0), useCutoff(false), anyExclusions(false),
numForceBuffers(0), exclusionIndices(NULL), exclusionRowIndices(NULL), exclusions(NULL), interactingTiles(NULL), interactionFlags(NULL),
interactionCount(NULL), blockCenter(NULL), blockBoundingBox(NULL) {
// Decide how many thread blocks and force buffers to use.
......@@ -93,7 +93,7 @@ void OpenCLNonbondedUtilities::addInteraction(bool usesCutoff, bool usesPeriodic
if (cutoffDistance != cutoff)
throw OpenMMException("All Forces must use the same cutoff distance");
}
if (usesExclusions && atomExclusions.size() != 0) {
if (usesExclusions && anyExclusions) {
bool sameExclusions = (exclusionList.size() == atomExclusions.size());
for (int i = 0; i < (int) exclusionList.size() && sameExclusions; i++) {
if (exclusionList[i].size() != atomExclusions[i].size())
......@@ -109,8 +109,10 @@ void OpenCLNonbondedUtilities::addInteraction(bool usesCutoff, bool usesPeriodic
usePeriodic = usesPeriodic;
cutoff = cutoffDistance;
kernelSource += kernel+"\n";
if (usesExclusions)
if (usesExclusions && !anyExclusions) {
atomExclusions = exclusionList;
anyExclusions = true;
}
}
void OpenCLNonbondedUtilities::addParameter(const ParameterInfo& parameter) {
......
......@@ -245,7 +245,7 @@ private:
std::string kernelSource;
std::map<std::string, std::string> kernelDefines;
double cutoff;
bool useCutoff, usePeriodic, forceBufferPerAtomBlock, deviceIsCpu;
bool useCutoff, usePeriodic, forceBufferPerAtomBlock, deviceIsCpu, anyExclusions;
int numForceBuffers, startTileIndex, numTiles, numForceThreadBlocks, forceThreadBlockSize;
};
......
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