Commit c83f44dd authored by Lee-Ping's avatar Lee-Ping
Browse files

Merge branch 'master' of github.com:SimTk/openmm

parents e9021971 9202aec4
...@@ -552,7 +552,7 @@ ForceValidationResult* ValidateOpenMMForces::compareForce(Context& context, std: ...@@ -552,7 +552,7 @@ ForceValidationResult* ValidateOpenMMForces::compareForce(Context& context, std:
if( forceName.compare( "NA" ) == 0 ){ if( forceName.compare( "NA" ) == 0 ){
std::stringstream message; std::stringstream message;
message << "Force at index=" << ii << " not found -- aborting!"; message << "Force at index=" << ii << " not found -- aborting!";
std::cerr << message << std::endl; std::cerr << message.str() << std::endl;
throw OpenMM::OpenMMException(message.str()); throw OpenMM::OpenMMException(message.str());
} }
systemForceNameMap[forceName] = ii; systemForceNameMap[forceName] = ii;
......
...@@ -9,7 +9,9 @@ ...@@ -9,7 +9,9 @@
*/ */
#if defined(_MSC_VER) #if defined(_MSC_VER)
#ifndef M_PI
#define M_PI 3.14159265358979323846264338327950288 #define M_PI 3.14159265358979323846264338327950288
#endif
#if _MSC_VER <= 1700 // 1700 is VC11, 1800 is VC12 #if _MSC_VER <= 1700 // 1700 is VC11, 1800 is VC12
/*************************** /***************************
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include <cmath> #include <cmath>
#include <sstream> #include <sstream>
#include <utility> #include <utility>
#include <algorithm>
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "openmm/kernels.h" #include "openmm/kernels.h"
#include <cmath> #include <cmath>
#include <vector> #include <vector>
#include <algorithm>
using namespace OpenMM; using namespace OpenMM;
using namespace OpenMM_SFMT; using namespace OpenMM_SFMT;
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "openmm/kernels.h" #include "openmm/kernels.h"
#include <cmath> #include <cmath>
#include <vector> #include <vector>
#include <algorithm>
using namespace OpenMM; using namespace OpenMM;
using namespace OpenMM_SFMT; using namespace OpenMM_SFMT;
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <cmath> #include <cmath>
#include <map> #include <map>
#include <sstream> #include <sstream>
#include <algorithm>
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include <set> #include <set>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include <algorithm>
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
......
...@@ -1520,7 +1520,7 @@ void CudaCalcNonbondedForceKernel::initialize(const System& system, const Nonbon ...@@ -1520,7 +1520,7 @@ void CudaCalcNonbondedForceKernel::initialize(const System& system, const Nonbon
else else
dispersionCoefficient = 0.0; dispersionCoefficient = 0.0;
alpha = 0; alpha = 0;
if (force.getNonbondedMethod() == NonbondedForce::Ewald && cu.getContextIndex() == 0) { if (force.getNonbondedMethod() == NonbondedForce::Ewald) {
// Compute the Ewald parameters. // Compute the Ewald parameters.
int kmaxx, kmaxy, kmaxz; int kmaxx, kmaxy, kmaxz;
...@@ -1528,6 +1528,7 @@ void CudaCalcNonbondedForceKernel::initialize(const System& system, const Nonbon ...@@ -1528,6 +1528,7 @@ void CudaCalcNonbondedForceKernel::initialize(const System& system, const Nonbon
defines["EWALD_ALPHA"] = cu.doubleToString(alpha); defines["EWALD_ALPHA"] = cu.doubleToString(alpha);
defines["TWO_OVER_SQRT_PI"] = cu.doubleToString(2.0/sqrt(M_PI)); defines["TWO_OVER_SQRT_PI"] = cu.doubleToString(2.0/sqrt(M_PI));
defines["USE_EWALD"] = "1"; defines["USE_EWALD"] = "1";
if (cu.getContextIndex() == 0) {
ewaldSelfEnergy = -ONE_4PI_EPS0*alpha*sumSquaredCharges/sqrt(M_PI); ewaldSelfEnergy = -ONE_4PI_EPS0*alpha*sumSquaredCharges/sqrt(M_PI);
// Create the reciprocal space kernels. // Create the reciprocal space kernels.
...@@ -1547,7 +1548,8 @@ void CudaCalcNonbondedForceKernel::initialize(const System& system, const Nonbon ...@@ -1547,7 +1548,8 @@ void CudaCalcNonbondedForceKernel::initialize(const System& system, const Nonbon
int elementSize = (cu.getUseDoublePrecision() ? sizeof(double2) : sizeof(float2)); int elementSize = (cu.getUseDoublePrecision() ? sizeof(double2) : sizeof(float2));
cosSinSums = new CudaArray(cu, (2*kmaxx-1)*(2*kmaxy-1)*(2*kmaxz-1), elementSize, "cosSinSums"); cosSinSums = new CudaArray(cu, (2*kmaxx-1)*(2*kmaxy-1)*(2*kmaxz-1), elementSize, "cosSinSums");
} }
else if (force.getNonbondedMethod() == NonbondedForce::PME && cu.getContextIndex() == 0) { }
else if (force.getNonbondedMethod() == NonbondedForce::PME) {
// Compute the PME parameters. // Compute the PME parameters.
int gridSizeX, gridSizeY, gridSizeZ; int gridSizeX, gridSizeY, gridSizeZ;
...@@ -1560,6 +1562,7 @@ void CudaCalcNonbondedForceKernel::initialize(const System& system, const Nonbon ...@@ -1560,6 +1562,7 @@ void CudaCalcNonbondedForceKernel::initialize(const System& system, const Nonbon
defines["EWALD_ALPHA"] = cu.doubleToString(alpha); defines["EWALD_ALPHA"] = cu.doubleToString(alpha);
defines["TWO_OVER_SQRT_PI"] = cu.doubleToString(2.0/sqrt(M_PI)); defines["TWO_OVER_SQRT_PI"] = cu.doubleToString(2.0/sqrt(M_PI));
defines["USE_EWALD"] = "1"; defines["USE_EWALD"] = "1";
if (cu.getContextIndex() == 0) {
ewaldSelfEnergy = -ONE_4PI_EPS0*alpha*sumSquaredCharges/sqrt(M_PI); ewaldSelfEnergy = -ONE_4PI_EPS0*alpha*sumSquaredCharges/sqrt(M_PI);
pmeDefines["PME_ORDER"] = cu.intToString(PmeOrder); pmeDefines["PME_ORDER"] = cu.intToString(PmeOrder);
pmeDefines["NUM_ATOMS"] = cu.intToString(numParticles); pmeDefines["NUM_ATOMS"] = cu.intToString(numParticles);
...@@ -1698,6 +1701,7 @@ void CudaCalcNonbondedForceKernel::initialize(const System& system, const Nonbon ...@@ -1698,6 +1701,7 @@ void CudaCalcNonbondedForceKernel::initialize(const System& system, const Nonbon
} }
} }
} }
}
else else
ewaldSelfEnergy = 0.0; ewaldSelfEnergy = 0.0;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for * * Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2010-2012 Stanford University and the Authors. * * Portions copyright (c) 2010-2014 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -170,6 +170,7 @@ void testVirtualSites() { ...@@ -170,6 +170,7 @@ void testVirtualSites() {
VerletIntegrator integrator(0.01); VerletIntegrator integrator(0.01);
Context context(system, integrator, platform); Context context(system, integrator, platform);
context.setPositions(positions); context.setPositions(positions);
context.applyConstraints(1e-5);
State initialState = context.getState(State::Forces | State::Energy); State initialState = context.getState(State::Forces | State::Energy);
LocalEnergyMinimizer::minimize(context, tolerance); LocalEnergyMinimizer::minimize(context, tolerance);
State finalState = context.getState(State::Forces | State::Energy | State::Positions); State finalState = context.getState(State::Forces | State::Energy | State::Positions);
......
...@@ -748,7 +748,7 @@ void testChangingParameters() { ...@@ -748,7 +748,7 @@ void testChangingParameters() {
ASSERT_EQUAL_TOL(cuState.getPotentialEnergy(), referenceState.getPotentialEnergy(), tol); ASSERT_EQUAL_TOL(cuState.getPotentialEnergy(), referenceState.getPotentialEnergy(), tol);
} }
void testParallelComputation(bool useCutoff) { void testParallelComputation(NonbondedForce::NonbondedMethod method) {
System system; System system;
const int numParticles = 200; const int numParticles = 200;
for (int i = 0; i < numParticles; i++) for (int i = 0; i < numParticles; i++)
...@@ -756,9 +756,9 @@ void testParallelComputation(bool useCutoff) { ...@@ -756,9 +756,9 @@ void testParallelComputation(bool useCutoff) {
NonbondedForce* force = new NonbondedForce(); NonbondedForce* force = new NonbondedForce();
for (int i = 0; i < numParticles; i++) for (int i = 0; i < numParticles; i++)
force->addParticle(i%2-0.5, 0.5, 1.0); force->addParticle(i%2-0.5, 0.5, 1.0);
if (useCutoff) force->setNonbondedMethod(method);
force->setNonbondedMethod(NonbondedForce::CutoffNonPeriodic);
system.addForce(force); system.addForce(force);
system.setDefaultPeriodicBoxVectors(Vec3(5,0,0), Vec3(0,5,0), Vec3(0,0,5));
OpenMM_SFMT::SFMT sfmt; OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt); init_gen_rand(0, sfmt);
vector<Vec3> positions(numParticles); vector<Vec3> positions(numParticles);
...@@ -877,8 +877,9 @@ int main(int argc, char* argv[]) { ...@@ -877,8 +877,9 @@ int main(int argc, char* argv[]) {
//testBlockInteractions(true); //testBlockInteractions(true);
testDispersionCorrection(); testDispersionCorrection();
testChangingParameters(); testChangingParameters();
testParallelComputation(false); testParallelComputation(NonbondedForce::NoCutoff);
testParallelComputation(true); testParallelComputation(NonbondedForce::Ewald);
testParallelComputation(NonbondedForce::PME);
testSwitchingFunction(NonbondedForce::CutoffNonPeriodic); testSwitchingFunction(NonbondedForce::CutoffNonPeriodic);
testSwitchingFunction(NonbondedForce::PME); testSwitchingFunction(NonbondedForce::PME);
} }
......
...@@ -1492,7 +1492,7 @@ void OpenCLCalcNonbondedForceKernel::initialize(const System& system, const Nonb ...@@ -1492,7 +1492,7 @@ void OpenCLCalcNonbondedForceKernel::initialize(const System& system, const Nonb
else else
dispersionCoefficient = 0.0; dispersionCoefficient = 0.0;
alpha = 0; alpha = 0;
if (force.getNonbondedMethod() == NonbondedForce::Ewald && cl.getContextIndex() == 0) { if (force.getNonbondedMethod() == NonbondedForce::Ewald) {
// Compute the Ewald parameters. // Compute the Ewald parameters.
int kmaxx, kmaxy, kmaxz; int kmaxx, kmaxy, kmaxz;
...@@ -1500,6 +1500,7 @@ void OpenCLCalcNonbondedForceKernel::initialize(const System& system, const Nonb ...@@ -1500,6 +1500,7 @@ void OpenCLCalcNonbondedForceKernel::initialize(const System& system, const Nonb
defines["EWALD_ALPHA"] = cl.doubleToString(alpha); defines["EWALD_ALPHA"] = cl.doubleToString(alpha);
defines["TWO_OVER_SQRT_PI"] = cl.doubleToString(2.0/sqrt(M_PI)); defines["TWO_OVER_SQRT_PI"] = cl.doubleToString(2.0/sqrt(M_PI));
defines["USE_EWALD"] = "1"; defines["USE_EWALD"] = "1";
if (cl.getContextIndex() == 0) {
ewaldSelfEnergy = -ONE_4PI_EPS0*alpha*sumSquaredCharges/sqrt(M_PI); ewaldSelfEnergy = -ONE_4PI_EPS0*alpha*sumSquaredCharges/sqrt(M_PI);
// Create the reciprocal space kernels. // Create the reciprocal space kernels.
...@@ -1516,7 +1517,8 @@ void OpenCLCalcNonbondedForceKernel::initialize(const System& system, const Nonb ...@@ -1516,7 +1517,8 @@ void OpenCLCalcNonbondedForceKernel::initialize(const System& system, const Nonb
int elementSize = (cl.getUseDoublePrecision() ? sizeof(mm_double2) : sizeof(mm_float2)); int elementSize = (cl.getUseDoublePrecision() ? sizeof(mm_double2) : sizeof(mm_float2));
cosSinSums = new OpenCLArray(cl, (2*kmaxx-1)*(2*kmaxy-1)*(2*kmaxz-1), elementSize, "cosSinSums"); cosSinSums = new OpenCLArray(cl, (2*kmaxx-1)*(2*kmaxy-1)*(2*kmaxz-1), elementSize, "cosSinSums");
} }
else if (force.getNonbondedMethod() == NonbondedForce::PME && cl.getContextIndex() == 0) { }
else if (force.getNonbondedMethod() == NonbondedForce::PME) {
// Compute the PME parameters. // Compute the PME parameters.
int gridSizeX, gridSizeY, gridSizeZ; int gridSizeX, gridSizeY, gridSizeZ;
...@@ -1527,6 +1529,7 @@ void OpenCLCalcNonbondedForceKernel::initialize(const System& system, const Nonb ...@@ -1527,6 +1529,7 @@ void OpenCLCalcNonbondedForceKernel::initialize(const System& system, const Nonb
defines["EWALD_ALPHA"] = cl.doubleToString(alpha); defines["EWALD_ALPHA"] = cl.doubleToString(alpha);
defines["TWO_OVER_SQRT_PI"] = cl.doubleToString(2.0/sqrt(M_PI)); defines["TWO_OVER_SQRT_PI"] = cl.doubleToString(2.0/sqrt(M_PI));
defines["USE_EWALD"] = "1"; defines["USE_EWALD"] = "1";
if (cl.getContextIndex() == 0) {
ewaldSelfEnergy = -ONE_4PI_EPS0*alpha*sumSquaredCharges/sqrt(M_PI); ewaldSelfEnergy = -ONE_4PI_EPS0*alpha*sumSquaredCharges/sqrt(M_PI);
pmeDefines["PME_ORDER"] = cl.intToString(PmeOrder); pmeDefines["PME_ORDER"] = cl.intToString(PmeOrder);
pmeDefines["NUM_ATOMS"] = cl.intToString(numParticles); pmeDefines["NUM_ATOMS"] = cl.intToString(numParticles);
...@@ -1644,6 +1647,7 @@ void OpenCLCalcNonbondedForceKernel::initialize(const System& system, const Nonb ...@@ -1644,6 +1647,7 @@ void OpenCLCalcNonbondedForceKernel::initialize(const System& system, const Nonb
} }
} }
} }
}
else else
ewaldSelfEnergy = 0.0; ewaldSelfEnergy = 0.0;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for * * Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2010 Stanford University and the Authors. * * Portions copyright (c) 2010-2014 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -170,6 +170,7 @@ void testVirtualSites() { ...@@ -170,6 +170,7 @@ void testVirtualSites() {
VerletIntegrator integrator(0.01); VerletIntegrator integrator(0.01);
Context context(system, integrator, platform); Context context(system, integrator, platform);
context.setPositions(positions); context.setPositions(positions);
context.applyConstraints(1e-5);
State initialState = context.getState(State::Forces | State::Energy); State initialState = context.getState(State::Forces | State::Energy);
LocalEnergyMinimizer::minimize(context, tolerance); LocalEnergyMinimizer::minimize(context, tolerance);
State finalState = context.getState(State::Forces | State::Energy | State::Positions); State finalState = context.getState(State::Forces | State::Energy | State::Positions);
......
...@@ -751,7 +751,7 @@ void testChangingParameters() { ...@@ -751,7 +751,7 @@ void testChangingParameters() {
ASSERT_EQUAL_TOL(clState.getPotentialEnergy(), referenceState.getPotentialEnergy(), tol); ASSERT_EQUAL_TOL(clState.getPotentialEnergy(), referenceState.getPotentialEnergy(), tol);
} }
void testParallelComputation(bool useCutoff) { void testParallelComputation(NonbondedForce::NonbondedMethod method) {
System system; System system;
const int numParticles = 200; const int numParticles = 200;
for (int i = 0; i < numParticles; i++) for (int i = 0; i < numParticles; i++)
...@@ -759,9 +759,9 @@ void testParallelComputation(bool useCutoff) { ...@@ -759,9 +759,9 @@ void testParallelComputation(bool useCutoff) {
NonbondedForce* force = new NonbondedForce(); NonbondedForce* force = new NonbondedForce();
for (int i = 0; i < numParticles; i++) for (int i = 0; i < numParticles; i++)
force->addParticle(i%2-0.5, 0.5, 1.0); force->addParticle(i%2-0.5, 0.5, 1.0);
if (useCutoff) force->setNonbondedMethod(method);
force->setNonbondedMethod(NonbondedForce::CutoffNonPeriodic);
system.addForce(force); system.addForce(force);
system.setDefaultPeriodicBoxVectors(Vec3(5,0,0), Vec3(0,5,0), Vec3(0,0,5));
OpenMM_SFMT::SFMT sfmt; OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt); init_gen_rand(0, sfmt);
vector<Vec3> positions(numParticles); vector<Vec3> positions(numParticles);
...@@ -880,8 +880,9 @@ int main(int argc, char* argv[]) { ...@@ -880,8 +880,9 @@ int main(int argc, char* argv[]) {
// testBlockInteractions(true); // testBlockInteractions(true);
testDispersionCorrection(); testDispersionCorrection();
testChangingParameters(); testChangingParameters();
testParallelComputation(false); testParallelComputation(NonbondedForce::NoCutoff);
testParallelComputation(true); testParallelComputation(NonbondedForce::Ewald);
testParallelComputation(NonbondedForce::PME);
testSwitchingFunction(NonbondedForce::CutoffNonPeriodic); testSwitchingFunction(NonbondedForce::CutoffNonPeriodic);
testSwitchingFunction(NonbondedForce::PME); testSwitchingFunction(NonbondedForce::PME);
} }
......
...@@ -34,12 +34,19 @@ ...@@ -34,12 +34,19 @@
#include "openmm/internal/SplineFitter.h" #include "openmm/internal/SplineFitter.h"
#ifdef _MSC_VER #ifdef _MSC_VER
#if _MSC_VER < 1800
/** /**
* We need to define this ourselves, since Visual Studio is missing round() from cmath. * We need to define this ourselves, since Visual Studio is missing round() from cmath.
*/ */
static int round(double x) { static int round(double x) {
return (int) (x+0.5); return (int) (x+0.5);
} }
#else
#include <cmath>
#endif // MSC_VER < 1800
#else #else
#include <cmath> #include <cmath>
#endif #endif
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <string.h> #include <string.h>
#include <sstream> #include <sstream>
#include <complex> #include <complex>
#include <algorithm>
#include "SimTKOpenMMCommon.h" #include "SimTKOpenMMCommon.h"
#include "SimTKOpenMMLog.h" #include "SimTKOpenMMLog.h"
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <cmath> #include <cmath>
#include <iostream> #include <iostream>
#include <cassert> #include <cassert>
#include <algorithm>
using namespace std; using namespace std;
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <cstring> #include <cstring>
#include <sstream> #include <sstream>
#include <algorithm>
#include "SimTKOpenMMCommon.h" #include "SimTKOpenMMCommon.h"
#include "SimTKOpenMMLog.h" #include "SimTKOpenMMLog.h"
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <string.h> #include <string.h>
#include <sstream> #include <sstream>
#include <algorithm>
#include "SimTKOpenMMCommon.h" #include "SimTKOpenMMCommon.h"
#include "SimTKOpenMMLog.h" #include "SimTKOpenMMLog.h"
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for * * Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2010 Stanford University and the Authors. * * Portions copyright (c) 2010-2014 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -171,6 +171,7 @@ void testVirtualSites() { ...@@ -171,6 +171,7 @@ void testVirtualSites() {
VerletIntegrator integrator(0.01); VerletIntegrator integrator(0.01);
Context context(system, integrator, platform); Context context(system, integrator, platform);
context.setPositions(positions); context.setPositions(positions);
context.applyConstraints(1e-5);
State initialState = context.getState(State::Forces | State::Energy); State initialState = context.getState(State::Forces | State::Energy);
LocalEnergyMinimizer::minimize(context, tolerance); LocalEnergyMinimizer::minimize(context, tolerance);
State finalState = context.getState(State::Forces | State::Energy | State::Positions); State finalState = context.getState(State::Forces | State::Energy | State::Positions);
......
...@@ -141,6 +141,7 @@ void DrudeForceImpl::initialize(ContextImpl& context) { ...@@ -141,6 +141,7 @@ void DrudeForceImpl::initialize(ContextImpl& context) {
} }
double DrudeForceImpl::calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups) { double DrudeForceImpl::calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups) {
if ((groups&(1<<owner.getForceGroup())) != 0)
return kernel.getAs<CalcDrudeForceKernel>().execute(context, includeForces, includeEnergy); return kernel.getAs<CalcDrudeForceKernel>().execute(context, includeForces, includeEnergy);
} }
......
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