Commit 54d474a6 authored by peastman's avatar peastman
Browse files

Merge pull request #762 from swails/is_periodic

Implements `usesPeriodicBoundaryConditions` on `Force`s and `System`
parents 19ccd0f8 1f15a914
......@@ -59,6 +59,8 @@ void testBonds() {
forceField->addBond(0, 1, 1.5, 0.8);
forceField->addBond(1, 2, 1.2, 0.7);
system.addForce(forceField);
ASSERT(!forceField->usesPeriodicBoundaryConditions());
ASSERT(!system.usesPeriodicBoundaryConditions());
Context context(system, integrator, platform);
vector<Vec3> positions(3);
positions[0] = Vec3(0, 2, 0);
......
......@@ -75,6 +75,8 @@ void testIdealGas() {
}
MonteCarloAnisotropicBarostat* barostat = new MonteCarloAnisotropicBarostat(Vec3(pressure, pressure, pressure), temp[0], true, true, true, frequency);
system.addForce(barostat);
ASSERT(barostat->usesPeriodicBoundaryConditions());
ASSERT(system.usesPeriodicBoundaryConditions());
// Test it for three different temperatures.
......@@ -134,6 +136,8 @@ void testIdealGasAxis(int axis) {
}
MonteCarloAnisotropicBarostat* barostat = new MonteCarloAnisotropicBarostat(Vec3(pressure, pressure, pressure), temp[0], scaleX, scaleY, scaleZ, frequency);
system.addForce(barostat);
ASSERT(barostat->usesPeriodicBoundaryConditions());
ASSERT(system.usesPeriodicBoundaryConditions());
// Test it for three different temperatures.
......@@ -191,6 +195,8 @@ void testRandomSeed() {
system.addForce(forceField);
MonteCarloAnisotropicBarostat* barostat = new MonteCarloAnisotropicBarostat(Vec3(pressure, pressure, pressure), temp, true, true, true, 1);
system.addForce(barostat);
ASSERT(barostat->usesPeriodicBoundaryConditions());
ASSERT(system.usesPeriodicBoundaryConditions());
vector<Vec3> positions(numParticles);
vector<Vec3> velocities(numParticles);
for (int i = 0; i < numParticles; ++i) {
......
......@@ -112,6 +112,8 @@ void testIdealGas() {
}
MonteCarloBarostat* barostat = new MonteCarloBarostat(pressure, temp[0], frequency);
system.addForce(barostat);
ASSERT(barostat->usesPeriodicBoundaryConditions());
ASSERT(system.usesPeriodicBoundaryConditions());
// Test it for three different temperatures.
......@@ -159,6 +161,8 @@ void testRandomSeed() {
system.addForce(forceField);
MonteCarloBarostat* barostat = new MonteCarloBarostat(pressure, temp, 1);
system.addForce(barostat);
ASSERT(barostat->usesPeriodicBoundaryConditions());
ASSERT(system.usesPeriodicBoundaryConditions());
vector<Vec3> positions(numParticles);
vector<Vec3> velocities(numParticles);
for (int i = 0; i < numParticles; ++i) {
......
......@@ -75,6 +75,8 @@ void testIdealGas(MonteCarloMembraneBarostat::XYMode xymode, MonteCarloMembraneB
}
MonteCarloMembraneBarostat* barostat = new MonteCarloMembraneBarostat(pressure, tension, temp[0], xymode, zmode, frequency);
system.addForce(barostat);
ASSERT(barostat->usesPeriodicBoundaryConditions());
ASSERT(system.usesPeriodicBoundaryConditions());
// Test it for three different temperatures.
......@@ -132,6 +134,8 @@ void testRandomSeed() {
system.addForce(forceField);
MonteCarloMembraneBarostat* barostat = new MonteCarloMembraneBarostat(pressure, tension, temp, MonteCarloMembraneBarostat::XYAnisotropic, MonteCarloMembraneBarostat::ZFree, 1);
system.addForce(barostat);
ASSERT(barostat->usesPeriodicBoundaryConditions());
ASSERT(system.usesPeriodicBoundaryConditions());
vector<Vec3> positions(numParticles);
vector<Vec3> velocities(numParticles);
for (int i = 0; i < numParticles; ++i) {
......
......@@ -59,6 +59,8 @@ void testCoulomb() {
forceField->addParticle(0.5, 1, 0);
forceField->addParticle(-1.5, 1, 0);
system.addForce(forceField);
ASSERT(!forceField->usesPeriodicBoundaryConditions());
ASSERT(!system.usesPeriodicBoundaryConditions());
Context context(system, integrator, platform);
vector<Vec3> positions(2);
positions[0] = Vec3(0, 0, 0);
......@@ -82,6 +84,8 @@ void testLJ() {
forceField->addParticle(0, 1.2, 1);
forceField->addParticle(0, 1.4, 2);
system.addForce(forceField);
ASSERT(!forceField->usesPeriodicBoundaryConditions());
ASSERT(!system.usesPeriodicBoundaryConditions());
Context context(system, integrator, platform);
vector<Vec3> positions(2);
positions[0] = Vec3(0, 0, 0);
......@@ -201,6 +205,8 @@ void testCutoff() {
const double eps = 50.0;
forceField->setReactionFieldDielectric(eps);
system.addForce(forceField);
ASSERT(!forceField->usesPeriodicBoundaryConditions());
ASSERT(!system.usesPeriodicBoundaryConditions());
Context context(system, integrator, platform);
vector<Vec3> positions(3);
positions[0] = Vec3(0, 0, 0);
......@@ -252,6 +258,8 @@ void testCutoff14() {
second14 = i;
}
system.addForce(nonbonded);
ASSERT(!nonbonded->usesPeriodicBoundaryConditions());
ASSERT(!system.usesPeriodicBoundaryConditions());
Context context(system, integrator, platform);
vector<Vec3> positions(5);
positions[0] = Vec3(0, 0, 0);
......@@ -333,6 +341,8 @@ void testPeriodic() {
nonbonded->setCutoffDistance(cutoff);
system.setDefaultPeriodicBoxVectors(Vec3(4, 0, 0), Vec3(0, 4, 0), Vec3(0, 0, 4));
system.addForce(nonbonded);
ASSERT(nonbonded->usesPeriodicBoundaryConditions());
ASSERT(system.usesPeriodicBoundaryConditions());
Context context(system, integrator, platform);
vector<Vec3> positions(3);
positions[0] = Vec3(0, 0, 0);
......@@ -376,6 +386,8 @@ void testDispersionCorrection() {
nonbonded->setCutoffDistance(cutoff);
system.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize));
system.addForce(nonbonded);
ASSERT(nonbonded->usesPeriodicBoundaryConditions());
ASSERT(system.usesPeriodicBoundaryConditions());
// See if the correction has the correct value.
......@@ -435,6 +447,14 @@ void testSwitchingFunction(NonbondedForce::NonbondedMethod method) {
nonbonded->setSwitchingDistance(1.5);
nonbonded->setUseDispersionCorrection(false);
system.addForce(nonbonded);
if (method == NonbondedForce::PME) {
ASSERT(nonbonded->usesPeriodicBoundaryConditions());
ASSERT(system.usesPeriodicBoundaryConditions());
}
else {
ASSERT(!nonbonded->usesPeriodicBoundaryConditions());
ASSERT(!system.usesPeriodicBoundaryConditions());
}
Context context(system, integrator, platform);
vector<Vec3> positions(2);
positions[0] = Vec3(0, 0, 0);
......
......@@ -59,6 +59,8 @@ void testPeriodicTorsions() {
PeriodicTorsionForce* forceField = new PeriodicTorsionForce();
forceField->addTorsion(0, 1, 2, 3, 2, PI_M/3, 1.1);
system.addForce(forceField);
ASSERT(!forceField->usesPeriodicBoundaryConditions());
ASSERT(!system.usesPeriodicBoundaryConditions());
Context context(system, integrator, platform);
vector<Vec3> positions(4);
positions[0] = Vec3(0, 1, 0);
......
......@@ -59,6 +59,8 @@ void testRBTorsions() {
RBTorsionForce* forceField = new RBTorsionForce();
forceField->addTorsion(0, 1, 2, 3, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6);
system.addForce(forceField);
ASSERT(!forceField->usesPeriodicBoundaryConditions());
ASSERT(!system.usesPeriodicBoundaryConditions());
Context context(system, integrator, platform);
vector<Vec3> positions(4);
positions[0] = Vec3(0, 1, 0);
......
......@@ -166,7 +166,15 @@ public:
* in an angle cannot be changed, nor can new angles be added.
*/
void updateParametersInContext(Context& context);
/**
* Returns whether or not this force makes use of periodic boundary
* conditions.
*
* @returns true if nonbondedMethod uses PBC and false otherwise
*/
bool usesPeriodicBoundaryConditions() const {
return false;
}
protected:
ForceImpl* createImpl() const;
double _globalCubicK, _globalQuarticK, _globalPenticK, _globalSexticK;
......
......@@ -138,7 +138,15 @@ public:
* in a bond cannot be changed, nor can new bonds be added.
*/
void updateParametersInContext(Context& context);
/**
* Returns whether or not this force makes use of periodic boundary
* conditions.
*
* @returns true if nonbondedMethod uses PBC and false otherwise
*/
bool usesPeriodicBoundaryConditions() const {
return false;
}
protected:
double _globalQuarticK, _globalCubicK;
ForceImpl* createImpl() const;
......
......@@ -163,7 +163,15 @@ public:
* (the probe radius, the surface area factor, etc.) are unaffected and can only be changed by reinitializing the Context.
*/
void updateParametersInContext(Context& context);
/**
* Returns whether or not this force makes use of periodic boundary
* conditions.
*
* @returns true if nonbondedMethod uses PBC and false otherwise
*/
bool usesPeriodicBoundaryConditions() const {
return false;
}
protected:
ForceImpl* createImpl() const;
private:
......
......@@ -171,7 +171,15 @@ public:
* in an angle cannot be changed, nor can new angles be added.
*/
void updateParametersInContext(Context& context);
/**
* Returns whether or not this force makes use of periodic boundary
* conditions.
*
* @returns true if nonbondedMethod uses PBC and false otherwise
*/
bool usesPeriodicBoundaryConditions() const {
return false;
}
protected:
ForceImpl* createImpl() const;
double _globalCubicK, _globalQuarticK, _globalPenticK, _globalSexticK;
......
......@@ -349,7 +349,15 @@ public:
* only to change the parameters of existing ones.
*/
void updateParametersInContext(Context& context);
/**
* Returns whether or not this force makes use of periodic boundary
* conditions.
*
* @returns true if nonbondedMethod uses PBC and false otherwise
*/
bool usesPeriodicBoundaryConditions() const {
return nonbondedMethod == AmoebaMultipoleForce::PME;
}
protected:
ForceImpl* createImpl() const;
private:
......
......@@ -163,7 +163,15 @@ public:
* in a term cannot be changed, nor can new terms be added.
*/
void updateParametersInContext(Context& context);
/**
* Returns whether or not this force makes use of periodic boundary
* conditions.
*
* @returns true if nonbondedMethod uses PBC and false otherwise
*/
bool usesPeriodicBoundaryConditions() const {
return false;
}
protected:
ForceImpl* createImpl() const;
double _globalCubicK, _globalQuarticK, _globalPenticK, _globalSexticK;
......
......@@ -113,7 +113,15 @@ public:
* in a torsion cannot be changed, nor can new torsions be added.
*/
void updateParametersInContext(Context& context);
/**
* Returns whether or not this force makes use of periodic boundary
* conditions.
*
* @returns true if nonbondedMethod uses PBC and false otherwise
*/
bool usesPeriodicBoundaryConditions() const {
return false;
}
protected:
ForceImpl* createImpl() const;
private:
......
......@@ -116,7 +116,15 @@ public:
* in a term cannot be changed, nor can new terms be added.
*/
void updateParametersInContext(Context& context);
/**
* Returns whether or not this force makes use of periodic boundary
* conditions.
*
* @returns true if nonbondedMethod uses PBC and false otherwise
*/
bool usesPeriodicBoundaryConditions() const {
return false;
}
protected:
ForceImpl* createImpl() const;
private:
......
......@@ -137,7 +137,15 @@ public:
* grid[x][y][5] = dEd(xy) value
*/
void setTorsionTorsionGrid(int index, const std::vector<std::vector<std::vector<double> > >& grid);
/**
* Returns whether or not this force makes use of periodic boundary
* conditions.
*
* @returns true if nonbondedMethod uses PBC and false otherwise
*/
bool usesPeriodicBoundaryConditions() const {
return false;
}
protected:
ForceImpl* createImpl() const;
private:
......
......@@ -212,7 +212,15 @@ public:
* (the nonbonded method, the cutoff distance, etc.) are unaffected and can only be changed by reinitializing the Context.
*/
void updateParametersInContext(Context& context);
/**
* Returns whether or not this force makes use of periodic boundary
* conditions.
*
* @returns true if nonbondedMethod uses PBC and false otherwise
*/
bool usesPeriodicBoundaryConditions() const {
return nonbondedMethod == AmoebaVdwForce::CutoffPeriodic;
}
protected:
ForceImpl* createImpl() const;
private:
......
......@@ -121,7 +121,15 @@ public:
void setShctd(double inputValue);
void setDispoff(double inputValue);
void setSlevy(double inputValue);
/**
* Returns whether or not this force makes use of periodic boundary
* conditions.
*
* @returns true if nonbondedMethod uses PBC and false otherwise
*/
bool usesPeriodicBoundaryConditions() const {
return false;
}
protected:
ForceImpl* createImpl() const;
private:
......
......@@ -82,9 +82,11 @@ static void getPrefactorsGivenAngleCosine( double cosine, double idealAngle, dou
double angle;
if( cosine >= 1.0 ){
angle = 0.0f;
} else if( cosine <= -1.0 ){
}
else if( cosine <= -1.0 ){
angle = RADIAN*PI_M;
} else {
}
else {
angle = RADIAN*acos(cosine);
}
#ifdef AMOEBA_DEBUG
......@@ -286,6 +288,8 @@ void testOneAngle( FILE* log ) {
amoebaAngleForce->setAmoebaGlobalAngleSextic(sexticK);
system.addForce(amoebaAngleForce);
ASSERT(!amoebaAngleForce->usesPeriodicBoundaryConditions());
ASSERT(!system.usesPeriodicBoundaryConditions());
Context context(system, integrator, Platform::getPlatformByName( "Reference"));
std::vector<Vec3> positions(numberOfParticles);
......
......@@ -193,6 +193,8 @@ void testTwoBond( FILE* log ) {
amoebaBondForce->addBond(1, 2, bondLength, quadraticK);
system.addForce(amoebaBondForce);
ASSERT(!amoebaBondForce->usesPeriodicBoundaryConditions());
ASSERT(!system.usesPeriodicBoundaryConditions());
Context context(system, integrator, Platform::getPlatformByName( "Reference"));
std::vector<Vec3> positions(3);
......
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