"vscode:/vscode.git/clone" did not exist on "6802dca5d640b277aa84009b857074e3d86bd994"
Commit d1793e5a authored by Peter Eastman's avatar Peter Eastman
Browse files

Eliminated nested classes, since SWIG didn't handle them well

parent f728d2f6
...@@ -65,6 +65,7 @@ ...@@ -65,6 +65,7 @@
#include "openmm/VariableVerletIntegrator.h" #include "openmm/VariableVerletIntegrator.h"
#include "openmm/Vec3.h" #include "openmm/Vec3.h"
#include "openmm/VerletIntegrator.h" #include "openmm/VerletIntegrator.h"
#include "openmm/VirtualSite.h"
#include "openmm/Platform.h" #include "openmm/Platform.h"
#endif /*OPENMM_H_*/ #endif /*OPENMM_H_*/
...@@ -46,9 +46,6 @@ namespace OpenMM { ...@@ -46,9 +46,6 @@ namespace OpenMM {
class OPENMM_EXPORT VirtualSite { class OPENMM_EXPORT VirtualSite {
public: public:
class TwoParticleAverage;
class ThreeParticleAverage;
class OutOfPlane;
virtual ~VirtualSite() { virtual ~VirtualSite() {
} }
/** /**
...@@ -75,10 +72,10 @@ private: ...@@ -75,10 +72,10 @@ private:
* of two other particle's locations. Assuming the weights add up to 1, this means * of two other particle's locations. Assuming the weights add up to 1, this means
* the virtual site is on the line passing through the two particles. * the virtual site is on the line passing through the two particles.
*/ */
class VirtualSite::TwoParticleAverage : public VirtualSite { class TwoParticleAverageSite : public VirtualSite {
public: public:
/** /**
* Create a new TwoParticleAverage virtual site. Normally weight1 and weight2 * Create a new TwoParticleAverageSite virtual site. Normally weight1 and weight2
* should add up to 1, although this is not strictly required. * should add up to 1, although this is not strictly required.
* *
* @param particle1 the index of the first particle * @param particle1 the index of the first particle
...@@ -86,7 +83,7 @@ public: ...@@ -86,7 +83,7 @@ public:
* @param weight1 the weight factor (between 0 and 1) for the first particle * @param weight1 the weight factor (between 0 and 1) for the first particle
* @param weight2 the weight factor (between 0 and 1) for the second particle * @param weight2 the weight factor (between 0 and 1) for the second particle
*/ */
TwoParticleAverage(int particle1, int particle2, double weight1, double weight2); TwoParticleAverageSite(int particle1, int particle2, double weight1, double weight2);
/** /**
* Get the weight factor used for a particle this virtual site depends on. * Get the weight factor used for a particle this virtual site depends on.
* *
...@@ -103,10 +100,10 @@ private: ...@@ -103,10 +100,10 @@ private:
* of three other particle's locations. Assuming the weights add up to 1, this means * of three other particle's locations. Assuming the weights add up to 1, this means
* the virtual site is in the plane of the three particles. * the virtual site is in the plane of the three particles.
*/ */
class VirtualSite::ThreeParticleAverage : public VirtualSite { class ThreeParticleAverageSite : public VirtualSite {
public: public:
/** /**
* Create a new ThreeParticleAverage virtual site. Normally the weights * Create a new ThreeParticleAverageSite virtual site. Normally the weights
* should add up to 1, although this is not strictly required. * should add up to 1, although this is not strictly required.
* *
* @param particle1 the index of the first particle * @param particle1 the index of the first particle
...@@ -116,7 +113,7 @@ public: ...@@ -116,7 +113,7 @@ public:
* @param weight2 the weight factor (between 0 and 1) for the second particle * @param weight2 the weight factor (between 0 and 1) for the second particle
* @param weight2 the weight factor (between 0 and 1) for the third particle * @param weight2 the weight factor (between 0 and 1) for the third particle
*/ */
ThreeParticleAverage(int particle1, int particle2, int particle3, double weight1, double weight2, double weight3); ThreeParticleAverageSite(int particle1, int particle2, int particle3, double weight1, double weight2, double weight3);
/** /**
* Get the weight factor used for a particle this virtual site depends on. * Get the weight factor used for a particle this virtual site depends on.
* *
...@@ -140,10 +137,10 @@ private: ...@@ -140,10 +137,10 @@ private:
* The three weight factors are user-specified. This allows the virtual site location * The three weight factors are user-specified. This allows the virtual site location
* to be out of the plane of the three particles. * to be out of the plane of the three particles.
*/ */
class VirtualSite::OutOfPlane : public VirtualSite { class OutOfPlaneSite : public VirtualSite {
public: public:
/** /**
* Create a new OutOfPlane virtual site. * Create a new OutOfPlaneSite virtual site.
* *
* @param particle1 the index of the first particle * @param particle1 the index of the first particle
* @param particle2 the index of the second particle * @param particle2 the index of the second particle
...@@ -152,7 +149,7 @@ public: ...@@ -152,7 +149,7 @@ public:
* @param weight13 the weight factor for the vector from particle1 to particle3 * @param weight13 the weight factor for the vector from particle1 to particle3
* @param weightCross the weight factor for the cross product * @param weightCross the weight factor for the cross product
*/ */
OutOfPlane(int particle1, int particle2, int particle3, double weight12, double weight13, double weightCross); OutOfPlaneSite(int particle1, int particle2, int particle3, double weight12, double weight13, double weightCross);
/** /**
* Get the weight factor for the vector from particle1 to particle2. * Get the weight factor for the vector from particle1 to particle2.
*/ */
......
...@@ -48,7 +48,7 @@ int VirtualSite::getParticle(int particle) const { ...@@ -48,7 +48,7 @@ int VirtualSite::getParticle(int particle) const {
return particles[particle]; return particles[particle];
} }
VirtualSite::TwoParticleAverage::TwoParticleAverage(int particle1, int particle2, double weight1, double weight2) : TwoParticleAverageSite::TwoParticleAverageSite(int particle1, int particle2, double weight1, double weight2) :
weight1(weight1), weight2(weight2) { weight1(weight1), weight2(weight2) {
vector<int> particles(2); vector<int> particles(2);
particles[0] = particle1; particles[0] = particle1;
...@@ -56,7 +56,7 @@ VirtualSite::TwoParticleAverage::TwoParticleAverage(int particle1, int particle2 ...@@ -56,7 +56,7 @@ VirtualSite::TwoParticleAverage::TwoParticleAverage(int particle1, int particle2
setParticles(particles); setParticles(particles);
} }
double VirtualSite::TwoParticleAverage::getWeight(int particle) const { double TwoParticleAverageSite::getWeight(int particle) const {
if (particle == 0) if (particle == 0)
return weight1; return weight1;
if (particle == 1) if (particle == 1)
...@@ -64,7 +64,7 @@ double VirtualSite::TwoParticleAverage::getWeight(int particle) const { ...@@ -64,7 +64,7 @@ double VirtualSite::TwoParticleAverage::getWeight(int particle) const {
throw OpenMMException("Illegal index for particle"); throw OpenMMException("Illegal index for particle");
} }
VirtualSite::ThreeParticleAverage::ThreeParticleAverage(int particle1, int particle2, int particle3, double weight1, double weight2, double weight3) : ThreeParticleAverageSite::ThreeParticleAverageSite(int particle1, int particle2, int particle3, double weight1, double weight2, double weight3) :
weight1(weight1), weight2(weight2), weight3(weight3) { weight1(weight1), weight2(weight2), weight3(weight3) {
vector<int> particles(3); vector<int> particles(3);
particles[0] = particle1; particles[0] = particle1;
...@@ -73,7 +73,7 @@ VirtualSite::ThreeParticleAverage::ThreeParticleAverage(int particle1, int parti ...@@ -73,7 +73,7 @@ VirtualSite::ThreeParticleAverage::ThreeParticleAverage(int particle1, int parti
setParticles(particles); setParticles(particles);
} }
double VirtualSite::ThreeParticleAverage::getWeight(int particle) const { double ThreeParticleAverageSite::getWeight(int particle) const {
if (particle == 0) if (particle == 0)
return weight1; return weight1;
if (particle == 1) if (particle == 1)
...@@ -83,7 +83,7 @@ double VirtualSite::ThreeParticleAverage::getWeight(int particle) const { ...@@ -83,7 +83,7 @@ double VirtualSite::ThreeParticleAverage::getWeight(int particle) const {
throw OpenMMException("Illegal index for particle"); throw OpenMMException("Illegal index for particle");
} }
VirtualSite::OutOfPlane::OutOfPlane(int particle1, int particle2, int particle3, double weight12, double weight13, double weightCross) : OutOfPlaneSite::OutOfPlaneSite(int particle1, int particle2, int particle3, double weight12, double weight13, double weightCross) :
weight12(weight12), weight13(weight13), weightCross(weightCross) { weight12(weight12), weight13(weight13), weightCross(weightCross) {
vector<int> particles(3); vector<int> particles(3);
particles[0] = particle1; particles[0] = particle1;
...@@ -92,14 +92,14 @@ VirtualSite::OutOfPlane::OutOfPlane(int particle1, int particle2, int particle3, ...@@ -92,14 +92,14 @@ VirtualSite::OutOfPlane::OutOfPlane(int particle1, int particle2, int particle3,
setParticles(particles); setParticles(particles);
} }
double VirtualSite::OutOfPlane::getWeight12() const { double OutOfPlaneSite::getWeight12() const {
return weight12; return weight12;
} }
double VirtualSite::OutOfPlane::getWeight13() const { double OutOfPlaneSite::getWeight13() const {
return weight13; return weight13;
} }
double VirtualSite::OutOfPlane::getWeightCross() const { double OutOfPlaneSite::getWeightCross() const {
return weightCross; return weightCross;
} }
...@@ -38,26 +38,26 @@ using namespace std; ...@@ -38,26 +38,26 @@ using namespace std;
void ReferenceVirtualSites::computePositions(const OpenMM::System& system, vector<OpenMM::RealVec>& atomCoordinates) { void ReferenceVirtualSites::computePositions(const OpenMM::System& system, vector<OpenMM::RealVec>& atomCoordinates) {
for (int i = 0; i < system.getNumParticles(); i++) for (int i = 0; i < system.getNumParticles(); i++)
if (system.isVirtualSite(i)) { if (system.isVirtualSite(i)) {
if (dynamic_cast<const VirtualSite::TwoParticleAverage*>(&system.getVirtualSite(i)) != NULL) { if (dynamic_cast<const TwoParticleAverageSite*>(&system.getVirtualSite(i)) != NULL) {
// A two particle average. // A two particle average.
const VirtualSite::TwoParticleAverage& site = dynamic_cast<const VirtualSite::TwoParticleAverage&>(system.getVirtualSite(i)); const TwoParticleAverageSite& site = dynamic_cast<const TwoParticleAverageSite&>(system.getVirtualSite(i));
int p1 = site.getParticle(0), p2 = site.getParticle(1); int p1 = site.getParticle(0), p2 = site.getParticle(1);
RealOpenMM w1 = site.getWeight(0), w2 = site.getWeight(1); RealOpenMM w1 = site.getWeight(0), w2 = site.getWeight(1);
atomCoordinates[i] = atomCoordinates[p1]*w1 + atomCoordinates[p2]*w2; atomCoordinates[i] = atomCoordinates[p1]*w1 + atomCoordinates[p2]*w2;
} }
else if (dynamic_cast<const VirtualSite::ThreeParticleAverage*>(&system.getVirtualSite(i)) != NULL) { else if (dynamic_cast<const ThreeParticleAverageSite*>(&system.getVirtualSite(i)) != NULL) {
// A three particle average. // A three particle average.
const VirtualSite::ThreeParticleAverage& site = dynamic_cast<const VirtualSite::ThreeParticleAverage&>(system.getVirtualSite(i)); const ThreeParticleAverageSite& site = dynamic_cast<const ThreeParticleAverageSite&>(system.getVirtualSite(i));
int p1 = site.getParticle(0), p2 = site.getParticle(1), p3 = site.getParticle(2); int p1 = site.getParticle(0), p2 = site.getParticle(1), p3 = site.getParticle(2);
RealOpenMM w1 = site.getWeight(0), w2 = site.getWeight(1), w3 = site.getWeight(2); RealOpenMM w1 = site.getWeight(0), w2 = site.getWeight(1), w3 = site.getWeight(2);
atomCoordinates[i] = atomCoordinates[p1]*w1 + atomCoordinates[p2]*w2 + atomCoordinates[p3]*w3; atomCoordinates[i] = atomCoordinates[p1]*w1 + atomCoordinates[p2]*w2 + atomCoordinates[p3]*w3;
} }
else if (dynamic_cast<const VirtualSite::OutOfPlane*>(&system.getVirtualSite(i)) != NULL) { else if (dynamic_cast<const OutOfPlaneSite*>(&system.getVirtualSite(i)) != NULL) {
// An out of plane site. // An out of plane site.
const VirtualSite::OutOfPlane& site = dynamic_cast<const VirtualSite::OutOfPlane&>(system.getVirtualSite(i)); const OutOfPlaneSite& site = dynamic_cast<const OutOfPlaneSite&>(system.getVirtualSite(i));
int p1 = site.getParticle(0), p2 = site.getParticle(1), p3 = site.getParticle(2); int p1 = site.getParticle(0), p2 = site.getParticle(1), p3 = site.getParticle(2);
RealOpenMM w12 = site.getWeight12(), w13 = site.getWeight13(), wcross = site.getWeightCross(); RealOpenMM w12 = site.getWeight12(), w13 = site.getWeight13(), wcross = site.getWeightCross();
RealVec v12 = atomCoordinates[p2]-atomCoordinates[p1]; RealVec v12 = atomCoordinates[p2]-atomCoordinates[p1];
...@@ -73,29 +73,29 @@ void ReferenceVirtualSites::distributeForces(const OpenMM::System& system, const ...@@ -73,29 +73,29 @@ void ReferenceVirtualSites::distributeForces(const OpenMM::System& system, const
for (int i = 0; i < system.getNumParticles(); i++) for (int i = 0; i < system.getNumParticles(); i++)
if (system.isVirtualSite(i)) { if (system.isVirtualSite(i)) {
RealVec f = forces[i]; RealVec f = forces[i];
if (dynamic_cast<const VirtualSite::TwoParticleAverage*>(&system.getVirtualSite(i)) != NULL) { if (dynamic_cast<const TwoParticleAverageSite*>(&system.getVirtualSite(i)) != NULL) {
// A two particle average. // A two particle average.
const VirtualSite::TwoParticleAverage& site = dynamic_cast<const VirtualSite::TwoParticleAverage&>(system.getVirtualSite(i)); const TwoParticleAverageSite& site = dynamic_cast<const TwoParticleAverageSite&>(system.getVirtualSite(i));
int p1 = site.getParticle(0), p2 = site.getParticle(1); int p1 = site.getParticle(0), p2 = site.getParticle(1);
RealOpenMM w1 = site.getWeight(0), w2 = site.getWeight(1); RealOpenMM w1 = site.getWeight(0), w2 = site.getWeight(1);
forces[p1] += f*w1; forces[p1] += f*w1;
forces[p2] += f*w2; forces[p2] += f*w2;
} }
else if (dynamic_cast<const VirtualSite::ThreeParticleAverage*>(&system.getVirtualSite(i)) != NULL) { else if (dynamic_cast<const ThreeParticleAverageSite*>(&system.getVirtualSite(i)) != NULL) {
// A three particle average. // A three particle average.
const VirtualSite::ThreeParticleAverage& site = dynamic_cast<const VirtualSite::ThreeParticleAverage&>(system.getVirtualSite(i)); const ThreeParticleAverageSite& site = dynamic_cast<const ThreeParticleAverageSite&>(system.getVirtualSite(i));
int p1 = site.getParticle(0), p2 = site.getParticle(1), p3 = site.getParticle(2); int p1 = site.getParticle(0), p2 = site.getParticle(1), p3 = site.getParticle(2);
RealOpenMM w1 = site.getWeight(0), w2 = site.getWeight(1), w3 = site.getWeight(2); RealOpenMM w1 = site.getWeight(0), w2 = site.getWeight(1), w3 = site.getWeight(2);
forces[p1] += f*w1; forces[p1] += f*w1;
forces[p2] += f*w2; forces[p2] += f*w2;
forces[p3] += f*w3; forces[p3] += f*w3;
} }
else if (dynamic_cast<const VirtualSite::OutOfPlane*>(&system.getVirtualSite(i)) != NULL) { else if (dynamic_cast<const OutOfPlaneSite*>(&system.getVirtualSite(i)) != NULL) {
// An out of plane site. // An out of plane site.
const VirtualSite::OutOfPlane& site = dynamic_cast<const VirtualSite::OutOfPlane&>(system.getVirtualSite(i)); const OutOfPlaneSite& site = dynamic_cast<const OutOfPlaneSite&>(system.getVirtualSite(i));
int p1 = site.getParticle(0), p2 = site.getParticle(1), p3 = site.getParticle(2); int p1 = site.getParticle(0), p2 = site.getParticle(1), p3 = site.getParticle(2);
RealOpenMM w12 = site.getWeight12(), w13 = site.getWeight13(), wcross = site.getWeightCross(); RealOpenMM w12 = site.getWeight12(), w13 = site.getWeight13(), wcross = site.getWeightCross();
RealVec v12 = atomCoordinates[p2]-atomCoordinates[p1]; RealVec v12 = atomCoordinates[p2]-atomCoordinates[p1];
......
...@@ -88,7 +88,7 @@ void testMasslessParticle() { ...@@ -88,7 +88,7 @@ void testMasslessParticle() {
} }
/** /**
* Test a TwoParticleAverage virtual site. * Test a TwoParticleAverageSite virtual site.
*/ */
void testTwoParticleAverage() { void testTwoParticleAverage() {
ReferencePlatform platform; ReferencePlatform platform;
...@@ -96,7 +96,7 @@ void testTwoParticleAverage() { ...@@ -96,7 +96,7 @@ void testTwoParticleAverage() {
system.addParticle(1.0); system.addParticle(1.0);
system.addParticle(1.0); system.addParticle(1.0);
system.addParticle(0.0); system.addParticle(0.0);
system.setVirtualSite(2, new VirtualSite::TwoParticleAverage(0, 1, 0.8, 0.2)); system.setVirtualSite(2, new TwoParticleAverageSite(0, 1, 0.8, 0.2));
CustomExternalForce* forceField = new CustomExternalForce("-a*x"); CustomExternalForce* forceField = new CustomExternalForce("-a*x");
system.addForce(forceField); system.addForce(forceField);
forceField->addPerParticleParameter("a"); forceField->addPerParticleParameter("a");
...@@ -124,7 +124,7 @@ void testTwoParticleAverage() { ...@@ -124,7 +124,7 @@ void testTwoParticleAverage() {
} }
/** /**
* Test a ThreeParticleAverage virtual site. * Test a ThreeParticleAverageSite virtual site.
*/ */
void testThreeParticleAverage() { void testThreeParticleAverage() {
ReferencePlatform platform; ReferencePlatform platform;
...@@ -133,7 +133,7 @@ void testThreeParticleAverage() { ...@@ -133,7 +133,7 @@ void testThreeParticleAverage() {
system.addParticle(1.0); system.addParticle(1.0);
system.addParticle(1.0); system.addParticle(1.0);
system.addParticle(0.0); system.addParticle(0.0);
system.setVirtualSite(3, new VirtualSite::ThreeParticleAverage(0, 1, 2, 0.2, 0.3, 0.5)); system.setVirtualSite(3, new ThreeParticleAverageSite(0, 1, 2, 0.2, 0.3, 0.5));
CustomExternalForce* forceField = new CustomExternalForce("-a*x"); CustomExternalForce* forceField = new CustomExternalForce("-a*x");
system.addForce(forceField); system.addForce(forceField);
forceField->addPerParticleParameter("a"); forceField->addPerParticleParameter("a");
...@@ -165,7 +165,7 @@ void testThreeParticleAverage() { ...@@ -165,7 +165,7 @@ void testThreeParticleAverage() {
} }
/** /**
* Test an OutOfPlane virtual site. * Test an OutOfPlaneSite virtual site.
*/ */
void testOutOfPlane() { void testOutOfPlane() {
ReferencePlatform platform; ReferencePlatform platform;
...@@ -174,7 +174,7 @@ void testOutOfPlane() { ...@@ -174,7 +174,7 @@ void testOutOfPlane() {
system.addParticle(1.0); system.addParticle(1.0);
system.addParticle(1.0); system.addParticle(1.0);
system.addParticle(0.0); system.addParticle(0.0);
system.setVirtualSite(3, new VirtualSite::OutOfPlane(0, 1, 2, 0.3, 0.4, 0.5)); system.setVirtualSite(3, new OutOfPlaneSite(0, 1, 2, 0.3, 0.4, 0.5));
CustomExternalForce* forceField = new CustomExternalForce("-a*x"); CustomExternalForce* forceField = new CustomExternalForce("-a*x");
system.addForce(forceField); system.addForce(forceField);
forceField->addPerParticleParameter("a"); forceField->addPerParticleParameter("a");
...@@ -228,7 +228,7 @@ void testConservationLaws() { ...@@ -228,7 +228,7 @@ void testConservationLaws() {
system.addParticle(1.0); system.addParticle(1.0);
system.addParticle(1.0); system.addParticle(1.0);
system.addParticle(0.0); system.addParticle(0.0);
system.setVirtualSite(2, new VirtualSite::TwoParticleAverage(0, 1, 0.4, 0.6)); system.setVirtualSite(2, new TwoParticleAverageSite(0, 1, 0.4, 0.6));
system.addConstraint(0, 1, 2.0); system.addConstraint(0, 1, 2.0);
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
forceField->addParticle(0, 1, 10); forceField->addParticle(0, 1, 10);
...@@ -245,7 +245,7 @@ void testConservationLaws() { ...@@ -245,7 +245,7 @@ void testConservationLaws() {
system.addParticle(1.0); system.addParticle(1.0);
system.addParticle(1.0); system.addParticle(1.0);
system.addParticle(0.0); system.addParticle(0.0);
system.setVirtualSite(6, new VirtualSite::ThreeParticleAverage(3, 4, 5, 0.3, 0.5, 0.2)); system.setVirtualSite(6, new ThreeParticleAverageSite(3, 4, 5, 0.3, 0.5, 0.2));
system.addConstraint(3, 4, 1.0); system.addConstraint(3, 4, 1.0);
system.addConstraint(3, 5, 1.0); system.addConstraint(3, 5, 1.0);
system.addConstraint(4, 5, sqrt(2.0)); system.addConstraint(4, 5, sqrt(2.0));
...@@ -265,7 +265,7 @@ void testConservationLaws() { ...@@ -265,7 +265,7 @@ void testConservationLaws() {
system.addParticle(1.0); system.addParticle(1.0);
system.addParticle(1.0); system.addParticle(1.0);
system.addParticle(0.0); system.addParticle(0.0);
system.setVirtualSite(10, new VirtualSite::OutOfPlane(7, 8, 9, 0.3, 0.5, 0.2)); system.setVirtualSite(10, new OutOfPlaneSite(7, 8, 9, 0.3, 0.5, 0.2));
system.addConstraint(7, 8, 1.0); system.addConstraint(7, 8, 1.0);
system.addConstraint(7, 9, 1.0); system.addConstraint(7, 9, 1.0);
system.addConstraint(8, 9, sqrt(2.0)); system.addConstraint(8, 9, sqrt(2.0));
...@@ -294,9 +294,9 @@ void testConservationLaws() { ...@@ -294,9 +294,9 @@ void testConservationLaws() {
const vector<Vec3>& vel = state.getVelocities(); const vector<Vec3>& vel = state.getVelocities();
const vector<Vec3>& f = state.getForces(); const vector<Vec3>& f = state.getForces();
double energy = state.getPotentialEnergy(); double energy = state.getPotentialEnergy();
for (int i = 0; i < numParticles; i++) { for (int j = 0; j < numParticles; j++) {
Vec3 v = vel[i] + f[i]*0.5*integrator.getStepSize(); Vec3 v = vel[j] + f[j]*0.5*integrator.getStepSize();
energy += 0.5*system.getParticleMass(i)*v.dot(v); energy += 0.5*system.getParticleMass(j)*v.dot(v);
} }
if (i == 0) if (i == 0)
initialEnergy = energy; initialEnergy = energy;
......
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