Commit ddbd992b authored by Jason Swails's avatar Jason Swails
Browse files

Add a usesPeriodicBoundaryConditions() method to all of the Force classes and

the System. The System inspects all of its forces and calls
usePeriodicBoundaryConditions -- it reports 'true' if at least one of its Forces
returns 'true' for usesPeriodicBoundaryConditions.

The default Force implementation is to raise an exception (NotImplementedError).
The System implementation will return true if at least one of its Forces returns
'true' for usesPeriodicBoundaryConditions, _regardless_ of whether or not one or
more of the forces does not implement the method. If at least one of the forces
does not implement usesPeriodicBoundaryConditions and all forces return false,
an OpenMMException is thrown.
parent 67ad6557
......@@ -224,6 +224,15 @@ public:
* @param c the vector defining the third edge of the periodic box
*/
void setDefaultPeriodicBoxVectors(const Vec3& a, const Vec3& b, const Vec3& c);
/**
* Returns whether or not any forces in this System use periodic boundaries.
*
* If a force in this System does not implement usesPeriodicBoundaryConditions
* a NotImplementedError is thrown
*
* @return true of at least one force uses PBC and false otherwise
*/
bool usesPeriodicBoundaryConditions();
private:
class ConstraintInfo;
Vec3 periodicBoxVectors[3];
......
......@@ -49,6 +49,10 @@ void Force::setForceGroup(int group) {
forceGroup = group;
}
bool Force::usesPeriodicBoundaryConditions() const {
throw NotImplementedError("usesPeriodicBoundaryConditions is not implemented");
}
ForceImpl& Force::getImplInContext(Context& context) {
const vector<ForceImpl*>& impls = context.getImpl().getForceImpls();
for (int i = 0; i < (int) impls.size(); i++)
......
......@@ -119,3 +119,24 @@ void System::setDefaultPeriodicBoxVectors(const Vec3& a, const Vec3& b, const Ve
periodicBoxVectors[1] = b;
periodicBoxVectors[2] = c;
}
bool System::usesPeriodicBoundaryConditions() {
bool uses_pbc = false;
bool all_forces_implement = true;
for (std::vector<Force*>::const_iterator it = forces.begin();
it != forces.end(); it++) {
try {
if ((*it)->usesPeriodicBoundaryConditions())
uses_pbc = true;
} catch (NotImplementedError &e) {
all_forces_implement = false;
}
}
if (!all_forces_implement && !uses_pbc) {
throw OpenMMException("not all forces implement usesPeriodicBoundaryConditions");
}
return uses_pbc;
}
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