"openmmapi/src/MonteCarloMembraneBarostat.cpp" did not exist on "6ddebdb28b4a19e9496e86b8e509617407df8e3d"
Commit 29e3fa57 authored by Peter Eastman's avatar Peter Eastman
Browse files

Redesigned the API for specifying exclusions and 1-4 interactions.

parent afd06645
......@@ -58,9 +58,9 @@ void testCoulomb() {
CudaPlatform platform;
System system(2, 0);
LangevinIntegrator integrator(0.0, 0.1, 0.01);
NonbondedForce* forceField = new NonbondedForce(2, 0);
forceField->setParticleParameters(0, 0.5, 1, 0);
forceField->setParticleParameters(1, -1.5, 1, 0);
NonbondedForce* forceField = new NonbondedForce();
forceField->addParticle(0.5, 1, 0);
forceField->addParticle(-1.5, 1, 0);
system.addForce(forceField);
OpenMMContext context(system, integrator, platform);
vector<Vec3> positions(2);
......@@ -79,9 +79,9 @@ void testLJ() {
CudaPlatform platform;
System system(2, 0);
LangevinIntegrator integrator(0.0, 0.1, 0.01);
NonbondedForce* forceField = new NonbondedForce(2, 0);
forceField->setParticleParameters(0, 0, 1.2, 1);
forceField->setParticleParameters(1, 0, 1.4, 2);
NonbondedForce* forceField = new NonbondedForce();
forceField->addParticle(0, 1.2, 1);
forceField->addParticle(0, 1.4, 2);
system.addForce(forceField);
OpenMMContext context(system, integrator, platform);
vector<Vec3> positions(2);
......@@ -102,13 +102,25 @@ void testExclusionsAnd14() {
CudaPlatform platform;
System system(5, 0);
LangevinIntegrator integrator(0.0, 0.1, 0.01);
HarmonicBondForce* bonds = new HarmonicBondForce(4);
bonds->setBondParameters(0, 0, 1, 1, 0);
bonds->setBondParameters(1, 1, 2, 1, 0);
bonds->setBondParameters(2, 2, 3, 1, 0);
bonds->setBondParameters(3, 3, 4, 1, 0);
system.addForce(bonds);
NonbondedForce* nonbonded = new NonbondedForce(5, 2);
NonbondedForce* nonbonded = new NonbondedForce();
for (int i = 0; i < 5; ++i)
nonbonded->addParticle(0, 1.5, 0);
vector<pair<int, int> > bonds;
bonds.push_back(pair<int, int>(0, 1));
bonds.push_back(pair<int, int>(1, 2));
bonds.push_back(pair<int, int>(2, 3));
bonds.push_back(pair<int, int>(3, 4));
nonbonded->createExceptionsFromBonds(bonds, 0.0, 0.0);
int first14, second14;
for (int i = 0; i < nonbonded->getNumExceptions(); i++) {
int particle1, particle2;
double chargeProd, sigma, epsilon;
nonbonded->getExceptionParameters(i, particle1, particle2, chargeProd, sigma, epsilon);
if ((particle1 == 0 && particle2 == 3) || (particle1 == 3 && particle2 == 0))
first14 = i;
if ((particle1 == 1 && particle2 == 4) || (particle1 == 4 && particle2 == 1))
second14 = i;
}
system.addForce(nonbonded);
for (int i = 1; i < 5; ++i) {
......@@ -122,8 +134,8 @@ void testExclusionsAnd14() {
}
nonbonded->setParticleParameters(0, 0, 1.5, 1);
nonbonded->setParticleParameters(i, 0, 1.5, 1);
nonbonded->setNonbonded14Parameters(0, 0, 3, 0, 1.5, i == 3 ? 0.5 : 0.0);
nonbonded->setNonbonded14Parameters(1, 1, 4, 0, 1.5, 0.0);
nonbonded->setExceptionParameters(first14, 0, 3, 0, 1.5, i == 3 ? 0.5 : 0.0);
nonbonded->setExceptionParameters(second14, 1, 4, 0, 1.5, 0.0);
positions[i] = Vec3(r, 0, 0);
OpenMMContext context(system, integrator, platform);
context.setPositions(positions);
......@@ -149,8 +161,8 @@ void testExclusionsAnd14() {
nonbonded->setParticleParameters(0, 2, 1.5, 0);
nonbonded->setParticleParameters(i, 2, 1.5, 0);
nonbonded->setNonbonded14Parameters(0, 0, 3, i == 3 ? 4/1.2 : 0, 1.5, 0);
nonbonded->setNonbonded14Parameters(1, 1, 4, 0, 1.5, 0);
nonbonded->setExceptionParameters(first14, 0, 3, i == 3 ? 4/1.2 : 0, 1.5, 0);
nonbonded->setExceptionParameters(second14, 1, 4, 0, 1.5, 0);
OpenMMContext context2(system, integrator, platform);
context2.setPositions(positions);
state = context2.getState(State::Forces | State::Energy);
......@@ -175,10 +187,10 @@ void testCutoff() {
CudaPlatform platform;
System system(3, 0);
LangevinIntegrator integrator(0.0, 0.1, 0.01);
NonbondedForce* forceField = new NonbondedForce(3, 0);
forceField->setParticleParameters(0, 1.0, 1, 0);
forceField->setParticleParameters(1, 1.0, 1, 0);
forceField->setParticleParameters(2, 1.0, 1, 0);
NonbondedForce* forceField = new NonbondedForce();
forceField->addParticle(1.0, 1, 0);
forceField->addParticle(1.0, 1, 0);
forceField->addParticle(1.0, 1, 0);
forceField->setNonbondedMethod(NonbondedForce::CutoffNonPeriodic);
const double cutoff = 2.9;
forceField->setCutoffDistance(cutoff);
......@@ -208,18 +220,28 @@ void testCutoff14() {
CudaPlatform platform;
System system(5, 0);
LangevinIntegrator integrator(0.0, 0.1, 0.01);
HarmonicBondForce* bonds = new HarmonicBondForce(4);
bonds->setBondParameters(0, 0, 1, 1, 0);
bonds->setBondParameters(1, 1, 2, 1, 0);
bonds->setBondParameters(2, 2, 3, 1, 0);
bonds->setBondParameters(3, 3, 4, 1, 0);
system.addForce(bonds);
NonbondedForce* nonbonded = new NonbondedForce(5, 2);
NonbondedForce* nonbonded = new NonbondedForce();
nonbonded->setNonbondedMethod(NonbondedForce::CutoffNonPeriodic);
nonbonded->setNonbonded14Parameters(0, 0, 3, 0, 1.5, 0.0);
nonbonded->setNonbonded14Parameters(1, 1, 4, 0, 1.5, 0.0);
for (int i = 0; i < 5; ++i)
nonbonded->addParticle(0, 1.5, 0);
const double cutoff = 3.5;
nonbonded->setCutoffDistance(cutoff);
vector<pair<int, int> > bonds;
bonds.push_back(pair<int, int>(0, 1));
bonds.push_back(pair<int, int>(1, 2));
bonds.push_back(pair<int, int>(2, 3));
bonds.push_back(pair<int, int>(3, 4));
nonbonded->createExceptionsFromBonds(bonds, 0.0, 0.0);
int first14, second14;
for (int i = 0; i < nonbonded->getNumExceptions(); i++) {
int particle1, particle2;
double chargeProd, sigma, epsilon;
nonbonded->getExceptionParameters(i, particle1, particle2, chargeProd, sigma, epsilon);
if ((particle1 == 0 && particle2 == 3) || (particle1 == 3 && particle2 == 0))
first14 = i;
if ((particle1 == 1 && particle2 == 4) || (particle1 == 4 && particle2 == 1))
second14 = i;
}
system.addForce(nonbonded);
OpenMMContext context(system, integrator, platform);
vector<Vec3> positions(5);
......@@ -236,8 +258,8 @@ void testCutoff14() {
for (int j = 1; j < 5; ++j)
nonbonded->setParticleParameters(j, 0, 1.5, 0);
nonbonded->setParticleParameters(i, 0, 1.5, 1);
nonbonded->setNonbonded14Parameters(0, 0, 3, 0, 1.5, i == 3 ? 0.5 : 0.0);
nonbonded->setNonbonded14Parameters(1, 1, 4, 0, 1.5, 0.0);
nonbonded->setExceptionParameters(first14, 0, 3, 0, 1.5, i == 3 ? 0.5 : 0.0);
nonbonded->setExceptionParameters(second14, 1, 4, 0, 1.5, 0.0);
context.reinitialize();
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
......@@ -264,8 +286,8 @@ void testCutoff14() {
const double q = 0.7;
nonbonded->setParticleParameters(0, q, 1.5, 0);
nonbonded->setParticleParameters(i, q, 1.5, 0);
nonbonded->setNonbonded14Parameters(0, 0, 3, i == 3 ? q*q/1.2 : 0, 1.5, 0);
nonbonded->setNonbonded14Parameters(1, 1, 4, 0, 1.5, 0);
nonbonded->setExceptionParameters(first14, 0, 3, i == 3 ? q*q/1.2 : 0, 1.5, 0);
nonbonded->setExceptionParameters(second14, 1, 4, 0, 1.5, 0);
context.reinitialize();
context.setPositions(positions);
state = context.getState(State::Forces | State::Energy);
......@@ -293,13 +315,11 @@ void testPeriodic() {
CudaPlatform platform;
System system(3, 0);
LangevinIntegrator integrator(0.0, 0.1, 0.01);
HarmonicBondForce* bonds = new HarmonicBondForce(1);
bonds->setBondParameters(0, 0, 1, 1, 0);
system.addForce(bonds);
NonbondedForce* nonbonded = new NonbondedForce(3, 0);
nonbonded->setParticleParameters(0, 1.0, 1, 0);
nonbonded->setParticleParameters(1, 1.0, 1, 0);
nonbonded->setParticleParameters(2, 1.0, 1, 0);
NonbondedForce* nonbonded = new NonbondedForce();
nonbonded->addParticle(1.0, 1, 0);
nonbonded->addParticle(1.0, 1, 0);
nonbonded->addParticle(1.0, 1, 0);
nonbonded->addException(0, 1, 0.0, 1.0, 0.0);
nonbonded->setNonbondedMethod(NonbondedForce::CutoffPeriodic);
const double cutoff = 2.0;
nonbonded->setCutoffDistance(cutoff);
......@@ -333,19 +353,19 @@ void testLargeSystem() {
ReferencePlatform reference;
System system(numParticles, 0);
VerletIntegrator integrator(0.01);
NonbondedForce* nonbonded = new NonbondedForce(numParticles, 0);
NonbondedForce* nonbonded = new NonbondedForce();
HarmonicBondForce* bonds = new HarmonicBondForce(numMolecules);
vector<Vec3> positions(numParticles);
vector<Vec3> velocities(numParticles);
init_gen_rand(0);
for (int i = 0; i < numMolecules; i++) {
if (i < numMolecules/2) {
nonbonded->setParticleParameters(2*i, 1.0, 0.2, 0.1);
nonbonded->setParticleParameters(2*i+1, 1.0, 0.1, 0.1);
nonbonded->addParticle(1.0, 0.2, 0.1);
nonbonded->addParticle(1.0, 0.1, 0.1);
}
else {
nonbonded->setParticleParameters(2*i, 1.0, 0.2, 0.2);
nonbonded->setParticleParameters(2*i+1, 1.0, 0.1, 0.2);
nonbonded->addParticle(1.0, 0.2, 0.2);
nonbonded->addParticle(1.0, 0.1, 0.2);
}
positions[2*i] = Vec3(boxSize*genrand_real2(), boxSize*genrand_real2(), boxSize*genrand_real2());
positions[2*i+1] = Vec3(positions[2*i][0]+1.0, positions[2*i][1], positions[2*i][2]);
......@@ -405,11 +425,11 @@ void testBlockInteractions(bool periodic) {
CudaPlatform cuda;
System system(numParticles, 0);
VerletIntegrator integrator(0.01);
NonbondedForce* nonbonded = new NonbondedForce(numParticles, 0);
NonbondedForce* nonbonded = new NonbondedForce();
vector<Vec3> positions(numParticles);
init_gen_rand(0);
for (int i = 0; i < numParticles; i++) {
nonbonded->setParticleParameters(i, 1.0, 0.2, 0.2);
nonbonded->addParticle(1.0, 0.2, 0.2);
positions[i] = Vec3(boxSize*(3*genrand_real2()-1), boxSize*(3*genrand_real2()-1), boxSize*(3*genrand_real2()-1));
}
nonbonded->setNonbondedMethod(periodic ? NonbondedForce::CutoffPeriodic : NonbondedForce::CutoffNonPeriodic);
......
......@@ -56,14 +56,14 @@ void testConstraints() {
System system(numParticles, numConstraints);
LangevinIntegrator integrator(temp, 2.0, 0.001);
integrator.setConstraintTolerance(1e-5);
NonbondedForce* forceField = new NonbondedForce(numParticles, 0);
NonbondedForce* forceField = new NonbondedForce();
for (int i = 0; i < numMolecules; ++i) {
system.setParticleMass(i*3, 16.0);
system.setParticleMass(i*3+1, 1.0);
system.setParticleMass(i*3+2, 1.0);
forceField->setParticleParameters(i*3, -0.82, 0.317, 0.65);
forceField->setParticleParameters(i*3+1, 0.41, 1.0, 0.0);
forceField->setParticleParameters(i*3+2, 0.41, 1.0, 0.0);
forceField->addParticle(-0.82, 0.317, 0.65);
forceField->addParticle(0.41, 1.0, 0.0);
forceField->addParticle(0.41, 1.0, 0.0);
system.setConstraintParameters(i*3, i*3, i*3+1, 0.1);
system.setConstraintParameters(i*3+1, i*3, i*3+2, 0.1);
system.setConstraintParameters(i*3+2, i*3+1, i*3+2, 0.163);
......
......@@ -93,10 +93,10 @@ void testConstraints() {
System system(numParticles, numConstraints);
VerletIntegrator integrator(0.001);
integrator.setConstraintTolerance(1e-5);
NonbondedForce* forceField = new NonbondedForce(numParticles, 0);
NonbondedForce* forceField = new NonbondedForce();
for (int i = 0; i < numParticles; ++i) {
system.setParticleMass(i, 10.0);
forceField->setParticleParameters(i, (i%2 == 0 ? 0.2 : -0.2), 0.5, 5.0);
forceField->addParticle((i%2 == 0 ? 0.2 : -0.2), 0.5, 5.0);
}
system.setConstraintParameters(0, 0, 1, 1.0);
system.setConstraintParameters(1, 1, 2, 1.0);
......
......@@ -306,9 +306,26 @@ ReferenceCalcNonbondedForceKernel::~ReferenceCalcNonbondedForceKernel() {
delete neighborList;
}
void ReferenceCalcNonbondedForceKernel::initialize(const System& system, const NonbondedForce& force, const std::vector<std::set<int> >& exclusions) {
void ReferenceCalcNonbondedForceKernel::initialize(const System& system, const NonbondedForce& force) {
// Identify which exceptions are 1-4 interactions.
numParticles = force.getNumParticles();
num14 = force.getNumNonbonded14();
exclusions.resize(numParticles);
vector<int> nb14s;
for (int i = 0; i < force.getNumExceptions(); i++) {
int particle1, particle2;
double chargeProd, sigma, epsilon;
force.getExceptionParameters(i, particle1, particle2, chargeProd, sigma, epsilon);
exclusions[particle1].insert(particle2);
exclusions[particle2].insert(particle1);
if (chargeProd != 0.0 || epsilon != 0.0)
nb14s.push_back(i);
}
// Build the arrays.
num14 = nb14s.size();
bonded14IndexArray = allocateIntArray(num14, 2);
bonded14ParamArray = allocateRealArray(num14, 3);
particleParamArray = allocateRealArray(numParticles, 3);
......@@ -332,7 +349,7 @@ void ReferenceCalcNonbondedForceKernel::initialize(const System& system, const N
for (int i = 0; i < num14; ++i) {
int particle1, particle2;
double charge, radius, depth;
force.getNonbonded14Parameters(i, particle1, particle2, charge, radius, depth);
force.getExceptionParameters(nb14s[i], particle1, particle2, charge, radius, depth);
bonded14IndexArray[i][0] = particle1;
bonded14IndexArray[i][1] = particle2;
bonded14ParamArray[i][0] = static_cast<RealOpenMM>(radius);
......
......@@ -216,11 +216,8 @@ public:
*
* @param system the System this kernel will be applied to
* @param force the NonbondedForce this kernel will be used for
* @param exclusions the i'th element lists the indices of all particles with which the i'th particle should not interact through
* nonbonded forces. Bonded 1-4 pairs are also included in this list, since they should be omitted from
* the standard nonbonded calculation.
*/
void initialize(const System& system, const NonbondedForce& force, const std::vector<std::set<int> >& exclusions);
void initialize(const System& system, const NonbondedForce& force);
/**
* Execute the kernel to calculate the forces.
*
......
......@@ -55,10 +55,10 @@ void testTemperature() {
ReferencePlatform platform;
System system(numParticles, 0);
VerletIntegrator integrator(0.01);
NonbondedForce* forceField = new NonbondedForce(numParticles, 0);
NonbondedForce* forceField = new NonbondedForce();
for (int i = 0; i < numParticles; ++i) {
system.setParticleMass(i, 2.0);
forceField->setParticleParameters(i, (i%2 == 0 ? 1.0 : -1.0), 1.0, 5.0);
forceField->addParticle((i%2 == 0 ? 1.0 : -1.0), 1.0, 5.0);
}
system.addForce(forceField);
AndersenThermostat* thermstat = new AndersenThermostat(temp, collisionFreq);
......@@ -93,10 +93,10 @@ void testRandomSeed() {
ReferencePlatform platform;
System system(numParticles, 0);
VerletIntegrator integrator(0.01);
NonbondedForce* forceField = new NonbondedForce(numParticles, 0);
NonbondedForce* forceField = new NonbondedForce();
for (int i = 0; i < numParticles; ++i) {
system.setParticleMass(i, 2.0);
forceField->setParticleParameters(i, (i%2 == 0 ? 1.0 : -1.0), 1.0, 5.0);
forceField->addParticle((i%2 == 0 ? 1.0 : -1.0), 1.0, 5.0);
}
system.addForce(forceField);
AndersenThermostat* thermostat = new AndersenThermostat(temp, collisionFreq);
......
......@@ -129,10 +129,10 @@ void testConstraints() {
System system(numParticles, numParticles-1);
BrownianIntegrator integrator(temp, 2.0, 0.001);
integrator.setConstraintTolerance(1e-5);
NonbondedForce* forceField = new NonbondedForce(numParticles, 0);
NonbondedForce* forceField = new NonbondedForce();
for (int i = 0; i < numParticles; ++i) {
system.setParticleMass(i, 10.0);
forceField->setParticleParameters(i, (i%2 == 0 ? 0.2 : -0.2), 0.5, 5.0);
forceField->addParticle((i%2 == 0 ? 0.2 : -0.2), 0.5, 5.0);
}
for (int i = 0; i < numParticles-1; ++i)
system.setConstraintParameters(i, i, i+1, 1.0);
......@@ -169,10 +169,10 @@ void testRandomSeed() {
ReferencePlatform platform;
System system(numParticles, 0);
BrownianIntegrator integrator(temp, 2.0, 0.001);
NonbondedForce* forceField = new NonbondedForce(numParticles, 0);
NonbondedForce* forceField = new NonbondedForce();
for (int i = 0; i < numParticles; ++i) {
system.setParticleMass(i, 2.0);
forceField->setParticleParameters(i, (i%2 == 0 ? 1.0 : -1.0), 1.0, 5.0);
forceField->addParticle((i%2 == 0 ? 1.0 : -1.0), 1.0, 5.0);
}
system.addForce(forceField);
vector<Vec3> positions(numParticles);
......
......@@ -69,10 +69,10 @@ void testMotionRemoval() {
HarmonicBondForce* bonds = new HarmonicBondForce(1);
bonds->setBondParameters(0, 2, 3, 2.0, 0.5);
system.addForce(bonds);
NonbondedForce* nonbonded = new NonbondedForce(numParticles, 0);
NonbondedForce* nonbonded = new NonbondedForce();
for (int i = 0; i < numParticles; ++i) {
system.setParticleMass(i, i+1);
nonbonded->setParticleParameters(i, (i%2 == 0 ? 1.0 : -1.0), 1.0, 5.0);
nonbonded->addParticle((i%2 == 0 ? 1.0 : -1.0), 1.0, 5.0);
}
system.addForce(nonbonded);
CMMotionRemover* remover = new CMMotionRemover();
......
......@@ -53,9 +53,9 @@ void testEwald() {
ReferencePlatform platform;
System system(2, 0);
VerletIntegrator integrator(0.01);
NonbondedForce* nonbonded = new NonbondedForce(2, 0);
nonbonded->setParticleParameters(0, 1.0, 1, 0);
nonbonded->setParticleParameters(1, -1.0, 1, 0);
NonbondedForce* nonbonded = new NonbondedForce();
nonbonded->addParticle(1.0, 1, 0);
nonbonded->addParticle(-1.0, 1, 0);
nonbonded->setNonbondedMethod(NonbondedForce::Ewald);
const double cutoff = 2.0;
nonbonded->setCutoffDistance(cutoff);
......
......@@ -76,11 +76,11 @@ void testCutoffAndPeriodic() {
System system(2, 0);
LangevinIntegrator integrator(0, 0.1, 0.01);
GBSAOBCForce* gbsa = new GBSAOBCForce(2);
NonbondedForce* nonbonded = new NonbondedForce(2, 0);
NonbondedForce* nonbonded = new NonbondedForce();
gbsa->setParticleParameters(0, -1, 0.15, 1);
nonbonded->setParticleParameters(0, -1, 1, 0);
nonbonded->addParticle(-1, 1, 0);
gbsa->setParticleParameters(1, 1, 0.15, 1);
nonbonded->setParticleParameters(1, 1, 1, 0);
nonbonded->addParticle(1, 1, 0);
const double cutoffDistance = 3.0;
const double boxSize = 10.0;
nonbonded->setCutoffDistance(cutoffDistance);
......
......@@ -100,10 +100,10 @@ void testTemperature() {
ReferencePlatform platform;
System system(numParticles, 0);
LangevinIntegrator integrator(temp, 2.0, 0.01);
NonbondedForce* forceField = new NonbondedForce(numParticles, 0);
NonbondedForce* forceField = new NonbondedForce();
for (int i = 0; i < numParticles; ++i) {
system.setParticleMass(i, 2.0);
forceField->setParticleParameters(i, (i%2 == 0 ? 1.0 : -1.0), 1.0, 5.0);
forceField->addParticle((i%2 == 0 ? 1.0 : -1.0), 1.0, 5.0);
}
system.addForce(forceField);
OpenMMContext context(system, integrator, platform);
......@@ -136,10 +136,10 @@ void testConstraints() {
System system(numParticles, numParticles-1);
LangevinIntegrator integrator(temp, 2.0, 0.01);
integrator.setConstraintTolerance(1e-5);
NonbondedForce* forceField = new NonbondedForce(numParticles, 0);
NonbondedForce* forceField = new NonbondedForce();
for (int i = 0; i < numParticles; ++i) {
system.setParticleMass(i, 10.0);
forceField->setParticleParameters(i, (i%2 == 0 ? 0.2 : -0.2), 0.5, 5.0);
forceField->addParticle((i%2 == 0 ? 0.2 : -0.2), 0.5, 5.0);
}
for (int i = 0; i < numParticles-1; ++i)
system.setConstraintParameters(i, i, i+1, 1.0);
......@@ -176,10 +176,10 @@ void testRandomSeed() {
ReferencePlatform platform;
System system(numParticles, 0);
LangevinIntegrator integrator(temp, 2.0, 0.01);
NonbondedForce* forceField = new NonbondedForce(numParticles, 0);
NonbondedForce* forceField = new NonbondedForce();
for (int i = 0; i < numParticles; ++i) {
system.setParticleMass(i, 2.0);
forceField->setParticleParameters(i, (i%2 == 0 ? 1.0 : -1.0), 1.0, 5.0);
forceField->addParticle((i%2 == 0 ? 1.0 : -1.0), 1.0, 5.0);
}
system.addForce(forceField);
vector<Vec3> positions(numParticles);
......
......@@ -53,9 +53,9 @@ void testCoulomb() {
ReferencePlatform platform;
System system(2, 0);
VerletIntegrator integrator(0.01);
NonbondedForce* forceField = new NonbondedForce(2, 0);
forceField->setParticleParameters(0, 0.5, 1, 0);
forceField->setParticleParameters(1, -1.5, 1, 0);
NonbondedForce* forceField = new NonbondedForce();
forceField->addParticle(0.5, 1, 0);
forceField->addParticle(-1.5, 1, 0);
system.addForce(forceField);
OpenMMContext context(system, integrator, platform);
vector<Vec3> positions(2);
......@@ -74,9 +74,9 @@ void testLJ() {
ReferencePlatform platform;
System system(2, 0);
VerletIntegrator integrator(0.01);
NonbondedForce* forceField = new NonbondedForce(2, 0);
forceField->setParticleParameters(0, 0, 1.2, 1);
forceField->setParticleParameters(1, 0, 1.4, 2);
NonbondedForce* forceField = new NonbondedForce();
forceField->addParticle(0, 1.2, 1);
forceField->addParticle(0, 1.4, 2);
system.addForce(forceField);
OpenMMContext context(system, integrator, platform);
vector<Vec3> positions(2);
......@@ -97,13 +97,25 @@ void testExclusionsAnd14() {
ReferencePlatform platform;
System system(5, 0);
VerletIntegrator integrator(0.01);
HarmonicBondForce* bonds = new HarmonicBondForce(4);
bonds->setBondParameters(0, 0, 1, 1, 0);
bonds->setBondParameters(1, 1, 2, 1, 0);
bonds->setBondParameters(2, 2, 3, 1, 0);
bonds->setBondParameters(3, 3, 4, 1, 0);
system.addForce(bonds);
NonbondedForce* nonbonded = new NonbondedForce(5, 2);
NonbondedForce* nonbonded = new NonbondedForce();
for (int i = 0; i < 5; i++)
nonbonded->addParticle(0, 1.5, 0);
vector<pair<int, int> > bonds;
bonds.push_back(pair<int, int>(0, 1));
bonds.push_back(pair<int, int>(1, 2));
bonds.push_back(pair<int, int>(2, 3));
bonds.push_back(pair<int, int>(3, 4));
nonbonded->createExceptionsFromBonds(bonds, 0.0, 0.0);
int first14, second14;
for (int i = 0; i < nonbonded->getNumExceptions(); i++) {
int particle1, particle2;
double chargeProd, sigma, epsilon;
nonbonded->getExceptionParameters(i, particle1, particle2, chargeProd, sigma, epsilon);
if ((particle1 == 0 && particle2 == 3) || (particle1 == 3 && particle2 == 0))
first14 = i;
if ((particle1 == 1 && particle2 == 4) || (particle1 == 4 && particle2 == 1))
second14 = i;
}
system.addForce(nonbonded);
OpenMMContext context(system, integrator, platform);
for (int i = 1; i < 5; ++i) {
......@@ -118,8 +130,8 @@ void testExclusionsAnd14() {
}
nonbonded->setParticleParameters(0, 0, 1.5, 1);
nonbonded->setParticleParameters(i, 0, 1.5, 1);
nonbonded->setNonbonded14Parameters(0, 0, 3, 0, 1.5, i == 3 ? 0.5 : 0.0);
nonbonded->setNonbonded14Parameters(1, 1, 4, 0, 1.5, 0.0);
nonbonded->setExceptionParameters(first14, 0, 3, 0, 1.5, i == 3 ? 0.5 : 0.0);
nonbonded->setExceptionParameters(second14, 1, 4, 0, 1.5, 0.0);
positions[i] = Vec3(r, 0, 0);
context.reinitialize();
context.setPositions(positions);
......@@ -145,8 +157,8 @@ void testExclusionsAnd14() {
nonbonded->setParticleParameters(0, 2, 1.5, 0);
nonbonded->setParticleParameters(i, 2, 1.5, 0);
nonbonded->setNonbonded14Parameters(0, 0, 3, i == 3 ? 4/1.2 : 0, 1.5, 0);
nonbonded->setNonbonded14Parameters(1, 1, 4, 0, 1.5, 0);
nonbonded->setExceptionParameters(first14, 0, 3, i == 3 ? 4/1.2 : 0, 1.5, 0);
nonbonded->setExceptionParameters(second14, 1, 4, 0, 1.5, 0);
context.reinitialize();
context.setPositions(positions);
state = context.getState(State::Forces | State::Energy);
......@@ -171,10 +183,10 @@ void testCutoff() {
ReferencePlatform platform;
System system(3, 0);
VerletIntegrator integrator(0.01);
NonbondedForce* forceField = new NonbondedForce(3, 0);
forceField->setParticleParameters(0, 1.0, 1, 0);
forceField->setParticleParameters(1, 1.0, 1, 0);
forceField->setParticleParameters(2, 1.0, 1, 0);
NonbondedForce* forceField = new NonbondedForce();
forceField->addParticle(1.0, 1, 0);
forceField->addParticle(1.0, 1, 0);
forceField->addParticle(1.0, 1, 0);
forceField->setNonbondedMethod(NonbondedForce::CutoffNonPeriodic);
const double cutoff = 2.9;
forceField->setCutoffDistance(cutoff);
......@@ -204,16 +216,28 @@ void testCutoff14() {
ReferencePlatform platform;
System system(5, 0);
VerletIntegrator integrator(0.01);
HarmonicBondForce* bonds = new HarmonicBondForce(4);
bonds->setBondParameters(0, 0, 1, 1, 0);
bonds->setBondParameters(1, 1, 2, 1, 0);
bonds->setBondParameters(2, 2, 3, 1, 0);
bonds->setBondParameters(3, 3, 4, 1, 0);
system.addForce(bonds);
NonbondedForce* nonbonded = new NonbondedForce(5, 2);
NonbondedForce* nonbonded = new NonbondedForce();
for (int i = 0; i < 5; i++)
nonbonded->addParticle(0, 1.5, 0);
nonbonded->setNonbondedMethod(NonbondedForce::CutoffNonPeriodic);
const double cutoff = 3.5;
nonbonded->setCutoffDistance(cutoff);
vector<pair<int, int> > bonds;
bonds.push_back(pair<int, int>(0, 1));
bonds.push_back(pair<int, int>(1, 2));
bonds.push_back(pair<int, int>(2, 3));
bonds.push_back(pair<int, int>(3, 4));
nonbonded->createExceptionsFromBonds(bonds, 0.0, 0.0);
int first14, second14;
for (int i = 0; i < nonbonded->getNumExceptions(); i++) {
int particle1, particle2;
double chargeProd, sigma, epsilon;
nonbonded->getExceptionParameters(i, particle1, particle2, chargeProd, sigma, epsilon);
if ((particle1 == 0 && particle2 == 3) || (particle1 == 3 && particle2 == 0))
first14 = i;
if ((particle1 == 1 && particle2 == 4) || (particle1 == 4 && particle2 == 1))
second14 = i;
}
system.addForce(nonbonded);
OpenMMContext context(system, integrator, platform);
vector<Vec3> positions(5);
......@@ -230,8 +254,8 @@ void testCutoff14() {
for (int j = 1; j < 5; ++j)
nonbonded->setParticleParameters(j, 0, 1.5, 0);
nonbonded->setParticleParameters(i, 0, 1.5, 1);
nonbonded->setNonbonded14Parameters(0, 0, 3, 0, 1.5, i == 3 ? 0.5 : 0.0);
nonbonded->setNonbonded14Parameters(1, 1, 4, 0, 1.5, 0.0);
nonbonded->setExceptionParameters(first14, 0, 3, 0, 1.5, i == 3 ? 0.5 : 0.0);
nonbonded->setExceptionParameters(second14, 1, 4, 0, 1.5, 0.0);
context.reinitialize();
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
......@@ -258,8 +282,8 @@ void testCutoff14() {
const double q = 0.7;
nonbonded->setParticleParameters(0, q, 1.5, 0);
nonbonded->setParticleParameters(i, q, 1.5, 0);
nonbonded->setNonbonded14Parameters(0, 0, 3, i == 3 ? q*q/1.2 : 0, 1.5, 0);
nonbonded->setNonbonded14Parameters(1, 1, 4, 0, 1.5, 0);
nonbonded->setExceptionParameters(first14, 0, 3, i == 3 ? q*q/1.2 : 0, 1.5, 0);
nonbonded->setExceptionParameters(second14, 1, 4, 0, 1.5, 0);
context.reinitialize();
context.setPositions(positions);
state = context.getState(State::Forces | State::Energy);
......@@ -287,13 +311,11 @@ void testPeriodic() {
ReferencePlatform platform;
System system(3, 0);
VerletIntegrator integrator(0.01);
HarmonicBondForce* bonds = new HarmonicBondForce(1);
bonds->setBondParameters(0, 0, 1, 1, 0);
system.addForce(bonds);
NonbondedForce* nonbonded = new NonbondedForce(3, 0);
nonbonded->setParticleParameters(0, 1.0, 1, 0);
nonbonded->setParticleParameters(1, 1.0, 1, 0);
nonbonded->setParticleParameters(2, 1.0, 1, 0);
NonbondedForce* nonbonded = new NonbondedForce();
nonbonded->addParticle(1.0, 1, 0);
nonbonded->addParticle(1.0, 1, 0);
nonbonded->addParticle(1.0, 1, 0);
nonbonded->addException(0, 1, 0.0, 1.0, 0.0);
nonbonded->setNonbondedMethod(NonbondedForce::CutoffPeriodic);
const double cutoff = 2.0;
nonbonded->setCutoffDistance(cutoff);
......
......@@ -92,10 +92,10 @@ void testConstraints() {
System system(numParticles, numParticles-1);
VerletIntegrator integrator(0.002);
integrator.setConstraintTolerance(1e-5);
NonbondedForce* forceField = new NonbondedForce(numParticles, 0);
NonbondedForce* forceField = new NonbondedForce();
for (int i = 0; i < numParticles; ++i) {
system.setParticleMass(i, 10.0);
forceField->setParticleParameters(i, (i%2 == 0 ? 0.2 : -0.2), 0.5, 5.0);
forceField->addParticle((i%2 == 0 ? 0.2 : -0.2), 0.5, 5.0);
}
for (int i = 0; i < numParticles-1; ++i)
system.setConstraintParameters(i, i, i+1, 1.0);
......
......@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008 Stanford University and the Authors. *
* Portions copyright (c) 2008-2009 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -30,7 +30,7 @@
* -------------------------------------------------------------------------- */
/**
* This tests the findExclusions() method of NonbondedForceImpl, which identifies pairs of atoms
* This tests the createExceptionsFromBonds() method of NonbondedForce, which identifies pairs of atoms
* whose nonbonded atoms are either excluded or decreased. The test system is a chain with branches:
*
* 1 3 5 7 9 11 13 15 17 19
......@@ -39,19 +39,8 @@
*/
#include "AssertionUtilities.h"
#include "Kernel.h"
#include "KernelFactory.h"
#include "OpenMMContext.h"
#include "Platform.h"
#include "NonbondedForce.h"
#include "Stream.h"
#include "StreamFactory.h"
#include "System.h"
#include "VerletIntegrator.h"
#include "kernels.h"
#include <algorithm>
#include <iostream>
#include <iterator>
#include <set>
#include <vector>
......@@ -64,207 +53,73 @@ static const int NUM_ATOMS = 20;
* Add a pair of atoms to the list of exclusions.
*/
void addAtomsToExclusions(int atom1, int atom2, vector<set<int> >& exclusions) {
void addAtomsToExclusions(int atom1, int atom2, vector<set<int> >& exclusions, int& totalExclusions) {
if (atom2 < NUM_ATOMS) {
exclusions[atom1].insert(atom2);
exclusions[atom2].insert(atom1);
totalExclusions++;
}
}
/**
* Verify that the exclusions are what we expect.
*/
void verifyExclusions(const vector<set<int> >& exclusions) {
vector<set<int> > expected(NUM_ATOMS);
for (int i = 0; i < NUM_ATOMS; i += 2) {
addAtomsToExclusions(i, i+1, expected);
addAtomsToExclusions(i, i+2, expected);
addAtomsToExclusions(i, i+3, expected);
addAtomsToExclusions(i, i+4, expected);
addAtomsToExclusions(i, i+5, expected);
addAtomsToExclusions(i, i+6, expected);
addAtomsToExclusions(i+1, i+2, expected);
addAtomsToExclusions(i+1, i+3, expected);
addAtomsToExclusions(i+1, i+4, expected);
}
ASSERT_EQUAL(expected.size(), exclusions.size());
for (int i = 0; i < NUM_ATOMS; ++i) {
ASSERT_EQUAL(expected[i].size(), exclusions[i].size());
vector<int> intersection(0);
insert_iterator<vector<int> > inserter(intersection, intersection.begin());
set_intersection(exclusions[i].begin(), exclusions[i].end(), expected[i].begin(), expected[i].end(), inserter);
ASSERT_EQUAL(expected[i].size(), intersection.size());
}
}
/**
* Add a pair of atoms to the list of 1-4 pairs.
*/
void addAtomsTo14List(int atom1, int atom2, set<pair<int, int> >& bonded14Indices) {
if (atom2 < NUM_ATOMS)
bonded14Indices.insert(pair<int, int>(atom1, atom2));
}
/**
* Verify that the 1-4 pairs are what we expect.
*/
void verify14(const vector<vector<int> >& bonded14Indices) {
set<pair<int, int> > expected, found;
for (int i = 0; i < NUM_ATOMS; i += 2) {
addAtomsTo14List(i, i+5, expected);
addAtomsTo14List(i, i+6, expected);
addAtomsTo14List(i+1, i+3, expected);
addAtomsTo14List(i+1, i+4, expected);
}
ASSERT_EQUAL(expected.size(), bonded14Indices.size());
for (size_t i = 0; i < bonded14Indices.size(); ++i) {
int atom1 = bonded14Indices[i][0];
int atom2 = bonded14Indices[i][1];
found.insert(pair<int, int>(min(atom1, atom2), max(atom1, atom2)));
}
vector<pair<int, int> > intersection(0);
insert_iterator<vector<pair<int, int> > > inserter(intersection, intersection.begin());
set_intersection(expected.begin(), expected.end(), found.begin(), found.end(), inserter);
ASSERT_EQUAL(expected.size(), intersection.size());
}
/**
* The following classes define a Platform whose job is to check whether the correct values were passed
* to the initialize() methods.
*/
class DummyBondedKernel : public CalcHarmonicBondForceKernel {
public:
DummyBondedKernel(string name, const Platform& platform) : CalcHarmonicBondForceKernel(name, platform) {
}
void initialize(const System& system, const HarmonicBondForce& force) {
}
void executeForces(OpenMMContextImpl& context) {
}
double executeEnergy(OpenMMContextImpl& context) {
return 0.0;
}
};
class DummyNonbondedKernel : public CalcNonbondedForceKernel {
public:
DummyNonbondedKernel(string name, const Platform& platform) : CalcNonbondedForceKernel(name, platform) {
}
void initialize(const System& system, const NonbondedForce& force, const std::vector<std::set<int> >& exclusions) {
verifyExclusions(exclusions);
// verify14(bonded14Indices);
}
void executeForces(OpenMMContextImpl& context) {
}
double executeEnergy(OpenMMContextImpl& context) {
return 0.0;
}
};
class DummyIntegratorKernel : public IntegrateVerletStepKernel {
public:
DummyIntegratorKernel(string name, const Platform& platform) : IntegrateVerletStepKernel(name, platform) {
}
void initialize(const System& system, const VerletIntegrator& integrator) {
}
void execute(OpenMMContextImpl& context, const VerletIntegrator& integrator) {
}
};
class DummyKEKernel : public CalcKineticEnergyKernel {
public:
DummyKEKernel(string name, const Platform& platform) : CalcKineticEnergyKernel(name, platform) {
}
void initialize(const System& system) {
}
double execute(OpenMMContextImpl& context) {
return 0.0;
}
};
class DummyStreamImpl : public StreamImpl {
public:
DummyStreamImpl(string name, int size, Stream::DataType type, const Platform& platform) : StreamImpl(name, size, type, platform) {
}
void loadFromArray(const void* array) {
}
void saveToArray(void* array) {
}
void fillWithValue(void* value) {
}
};
class DummyKernelFactory : public KernelFactory {
public:
KernelImpl* createKernelImpl(string name, const Platform& platform, OpenMMContextImpl& context) const {
if (name == CalcHarmonicBondForceKernel::Name())
return new DummyBondedKernel(name, platform);
if (name == CalcNonbondedForceKernel::Name())
return new DummyNonbondedKernel(name, platform);
if (name == IntegrateVerletStepKernel::Name())
return new DummyIntegratorKernel(name, platform);
if (name == CalcKineticEnergyKernel::Name())
return new DummyKEKernel(name, platform);
return 0;
}
};
class DummyStreamFactory : public StreamFactory {
public:
StreamImpl* createStreamImpl(string name, int size, Stream::DataType type, const Platform& platform, OpenMMContextImpl& context) const {
return new DummyStreamImpl(name, size, type, platform);
}
};
class DummyPlatform : public Platform {
public:
DummyPlatform() {
registerKernelFactory(CalcHarmonicBondForceKernel::Name(), new DummyKernelFactory());
registerKernelFactory(CalcNonbondedForceKernel::Name(), new DummyKernelFactory());
registerKernelFactory(IntegrateVerletStepKernel::Name(), new DummyKernelFactory());
registerKernelFactory(CalcKineticEnergyKernel::Name(), new DummyKernelFactory());
}
string getName() const {
return "Dummy";
}
double getSpeed() const {
return 1.0;
}
bool supportsDoublePrecision() const {
return true;
}
const StreamFactory& getDefaultStreamFactory() const {
return streamFactory;
}
private:
DummyStreamFactory streamFactory;
};
int main() {
try {
DummyPlatform platform;
System system(NUM_ATOMS, 0);
VerletIntegrator integrator(0.01);
HarmonicBondForce* bonds = new HarmonicBondForce(NUM_ATOMS-1);
NonbondedForce* nonbonded = new NonbondedForce(NUM_ATOMS, 0);
NonbondedForce nonbonded;
vector<pair<int, int> > bonds;
for (int i = 0; i < NUM_ATOMS; i++)
nonbonded.addParticle(1.0, 1.0, 2.0);
// loop over all main-chain atoms (even numbered atoms)
for (int i = 0; i < NUM_ATOMS-1; i += 2)
{
// side-chain bonds
bonds->setBondParameters(i, i, i+1, 1.0, 1.0);
// main-chain bonds
// side-chain bonds
bonds.push_back(pair<int, int>(i, i+1));
// main-chain bonds
if (i < NUM_ATOMS-2) // penultimate atom (NUM_ATOMS-2) has no subsequent main-chain atom
bonds->setBondParameters(i+1, i, i+2, 1.0, 1.0);
bonds.push_back(pair<int, int>(i, i+2));
}
nonbonded.createExceptionsFromBonds(bonds, 0.2, 0.4);
// Build lists of the expected exclusions and 1-4s.
vector<set<int> > expectedExclusions(NUM_ATOMS);
int totalExclusions = 0;
for (int i = 0; i < NUM_ATOMS; i += 2) {
addAtomsToExclusions(i, i+1, expectedExclusions, totalExclusions);
addAtomsToExclusions(i, i+2, expectedExclusions, totalExclusions);
addAtomsToExclusions(i, i+3, expectedExclusions, totalExclusions);
addAtomsToExclusions(i, i+4, expectedExclusions, totalExclusions);
addAtomsToExclusions(i+1, i+2, expectedExclusions, totalExclusions);
}
vector<set<int> > expected14(NUM_ATOMS);
int total14 = 0;
for (int i = 0; i < NUM_ATOMS; i += 2) {
addAtomsToExclusions(i, i+5, expected14, total14);
addAtomsToExclusions(i, i+6, expected14, total14);
addAtomsToExclusions(i+1, i+3, expected14, total14);
addAtomsToExclusions(i+1, i+4, expected14, total14);
}
// Compare them to the exceptions that were generated.
ASSERT_EQUAL(totalExclusions+total14, nonbonded.getNumExceptions());
for (int i = 0; i < nonbonded.getNumExceptions(); i++) {
int particle1, particle2;
double chargeProd, sigma, epsilon;
nonbonded.getExceptionParameters(i, particle1, particle2, chargeProd, sigma, epsilon);
if (chargeProd == 0) {
// This is an exclusion.
ASSERT_EQUAL(0.0, epsilon);
ASSERT(expectedExclusions[particle1].find(particle2) != expectedExclusions[particle2].end());
}
else {
// This is a 1-4.
ASSERT_EQUAL_TOL(0.2, chargeProd, 1e-10);
ASSERT_EQUAL_TOL(1.0, sigma, 1e-10);
ASSERT_EQUAL_TOL(0.8, epsilon, 1e-10);
ASSERT(expected14[particle1].find(particle2) != expected14[particle2].end());
}
}
system.addForce(bonds);
system.addForce(nonbonded);
OpenMMContext context(system, integrator, platform);
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
......
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