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

Fixed several bugs in OpenMM

parent d2638082
...@@ -51,21 +51,35 @@ void NonbondedForceImpl::initialize(OpenMMContextImpl& context) { ...@@ -51,21 +51,35 @@ void NonbondedForceImpl::initialize(OpenMMContextImpl& context) {
System& system = context.getSystem(); System& system = context.getSystem();
vector<set<int> > exclusions(owner.getNumParticles()); vector<set<int> > exclusions(owner.getNumParticles());
vector<vector<int> > bondIndices;
set<pair<int, int> > bonded14set;
for (int i = 0; i < system.getNumForces(); i++) { for (int i = 0; i < system.getNumForces(); i++) {
if (dynamic_cast<HarmonicBondForce*>(&system.getForce(i)) != NULL) { if (dynamic_cast<HarmonicBondForce*>(&system.getForce(i)) != NULL) {
const HarmonicBondForce& force = dynamic_cast<const HarmonicBondForce&>(system.getForce(i)); const HarmonicBondForce& force = dynamic_cast<const HarmonicBondForce&>(system.getForce(i));
vector<vector<int> > bondIndices(force.getNumBonds()); bondIndices.resize(force.getNumBonds());
set<pair<int, int> > bonded14set; for (int j = 0; j < force.getNumBonds(); ++j) {
for (int i = 0; i < force.getNumBonds(); ++i) {
int particle1, particle2; int particle1, particle2;
double length, k; double length, k;
force.getBondParameters(i, particle1, particle2, length, k); force.getBondParameters(j, particle1, particle2, length, k);
bondIndices[i].push_back(particle1); bondIndices[j].push_back(particle1);
bondIndices[i].push_back(particle2); bondIndices[j].push_back(particle2);
}
break;
} }
findExclusions(bondIndices, exclusions, bonded14set);
} }
// Also treat constrained distances as bonds.
int numBonds = bondIndices.size();
bondIndices.resize(numBonds+system.getNumConstraints());
for (int j = 0; j < system.getNumConstraints(); j++) {
int particle1, particle2;
double distance;
system.getConstraintParameters(j, particle1, particle2, distance);
bondIndices[j+numBonds].push_back(particle1);
bondIndices[j+numBonds].push_back(particle2);
} }
findExclusions(bondIndices, exclusions, bonded14set);
dynamic_cast<CalcNonbondedForceKernel&>(kernel.getImpl()).initialize(context.getSystem(), owner, exclusions); dynamic_cast<CalcNonbondedForceKernel&>(kernel.getImpl()).initialize(context.getSystem(), owner, exclusions);
} }
......
...@@ -269,9 +269,8 @@ void CudaCalcNonbondedForceKernel::initialize(const System& system, const Nonbon ...@@ -269,9 +269,8 @@ void CudaCalcNonbondedForceKernel::initialize(const System& system, const Nonbon
force.getNonbonded14Parameters(i, particle1[i], particle2[i], charge, sig, eps); force.getNonbonded14Parameters(i, particle1[i], particle2[i], charge, sig, eps);
c6[i] = (float) (4*eps*pow(sig, 6.0)); c6[i] = (float) (4*eps*pow(sig, 6.0));
c12[i] = (float) (4*eps*pow(sig, 12.0)); c12[i] = (float) (4*eps*pow(sig, 12.0));
float q = (float) std::sqrt(charge); q1[i] = (float) charge;
q1[i] = q; q2[i] = 1.0f;
q2[i] = q;
} }
gpuSetLJ14Parameters(gpu, 138.935485f, 1.0f, particle1, particle2, c6, c12, q1, q2); gpuSetLJ14Parameters(gpu, 138.935485f, 1.0f, particle1, particle2, c6, c12, q1, q2);
} }
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
using namespace OpenMM; using namespace OpenMM;
extern "C" void initOpenMMPlugin() { extern "C" void initOpenMMPlugin() {
if (gpuIsAvailable())
Platform::registerPlatform(new CudaPlatform()); Platform::registerPlatform(new CudaPlatform());
} }
......
...@@ -378,8 +378,8 @@ double ReferenceCalcNonbondedForceKernel::executeEnergy(OpenMMContextImpl& conte ...@@ -378,8 +378,8 @@ double ReferenceCalcNonbondedForceKernel::executeEnergy(OpenMMContextImpl& conte
ReferenceLJCoulomb14 nonbonded14; ReferenceLJCoulomb14 nonbonded14;
if (nonbondedMethod != NoCutoff) if (nonbondedMethod != NoCutoff)
nonbonded14.setUseCutoff(nonbondedCutoff, 78.3f); nonbonded14.setUseCutoff(nonbondedCutoff, 78.3f);
RealOpenMM* energyArray = new RealOpenMM[numParticles]; RealOpenMM* energyArray = new RealOpenMM[num14];
for (int i = 0; i < numParticles; ++i) for (int i = 0; i < num14; ++i)
energyArray[i] = 0; energyArray[i] = 0;
refBondForce.calculateForce(num14, bonded14IndexArray, posData, bonded14ParamArray, forceData, energyArray, 0, &energy, nonbonded14); refBondForce.calculateForce(num14, bonded14IndexArray, posData, bonded14ParamArray, forceData, energyArray, 0, &energy, nonbonded14);
disposeRealArray(forceData, numParticles); disposeRealArray(forceData, numParticles);
......
...@@ -243,7 +243,7 @@ int ReferenceLJCoulombIxn::calculatePairIxn( int numberOfAtoms, RealOpenMM** ato ...@@ -243,7 +243,7 @@ int ReferenceLJCoulombIxn::calculatePairIxn( int numberOfAtoms, RealOpenMM** ato
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
int ReferenceLJCoulombIxn::calculateOneIxn( int ii, int jj, RealOpenMM** atomCoordinates, int ReferenceLJCoulombIxn::calculateOneIxn( int ii, int jj, RealOpenMM** atomCoordinates,
RealOpenMM** atomParameters, RealOpenMM** forces, RealOpenMM** atomParameters, RealOpenMM** forces,
RealOpenMM* energyByAtom, RealOpenMM* totalEnergy ) const { RealOpenMM* energyByAtom, RealOpenMM* totalEnergy ) const {
......
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