Unverified Commit 6786cc75 authored by peastman's avatar peastman Committed by GitHub
Browse files

Merge pull request #2561 from peastman/middle

Converted BAOABLangevinIntegrator to LangevinMiddleIntegrator
parents 3fdc297c cc59da1a
/* Portions copyright (c) 2013-2019 Stanford University and Simbios. /* Portions copyright (c) 2013-2020 Stanford University and Simbios.
* Authors: Peter Eastman * Authors: Peter Eastman
* Contributors: * Contributors:
* *
...@@ -23,17 +23,17 @@ ...@@ -23,17 +23,17 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#ifndef __CPU_BAOAB_DYNAMICS_H__ #ifndef __CPU_LANGEVIN_MIDDLE_DYNAMICS_H__
#define __CPU_BAOAB_DYNAMICS_H__ #define __CPU_LANGEVIN_MIDDLE_DYNAMICS_H__
#include "ReferenceBAOABDynamics.h" #include "ReferenceLangevinMiddleDynamics.h"
#include "CpuRandom.h" #include "CpuRandom.h"
#include "openmm/internal/ThreadPool.h" #include "openmm/internal/ThreadPool.h"
#include "sfmt/SFMT.h" #include "sfmt/SFMT.h"
namespace OpenMM { namespace OpenMM {
class CpuBAOABDynamics : public ReferenceBAOABDynamics { class CpuLangevinMiddleDynamics : public ReferenceLangevinMiddleDynamics {
public: public:
/** /**
* Constructor. * Constructor.
...@@ -45,25 +45,22 @@ public: ...@@ -45,25 +45,22 @@ public:
* @param threads thread pool for parallelizing computation * @param threads thread pool for parallelizing computation
* @param random random number generator * @param random random number generator
*/ */
CpuBAOABDynamics(int numberOfAtoms, double deltaT, double friction, double temperature, OpenMM::ThreadPool& threads, OpenMM::CpuRandom& random); CpuLangevinMiddleDynamics(int numberOfAtoms, double deltaT, double friction, double temperature, OpenMM::ThreadPool& threads, OpenMM::CpuRandom& random);
/** /**
* Destructor. * Destructor.
*/ */
~CpuBAOABDynamics(); ~CpuLangevinMiddleDynamics();
/** /**
* First update step. * First update step.
* *
* @param numberOfAtoms number of atoms * @param numberOfAtoms number of atoms
* @param atomCoordinates atom coordinates
* @param velocities velocities * @param velocities velocities
* @param forces forces * @param forces forces
* @param inverseMasses inverse atom masses * @param inverseMasses inverse atom masses
* @param xPrime xPrime
*/ */
void updatePart1(int numberOfAtoms, std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<OpenMM::Vec3>& velocities, void updatePart1(int numberOfAtoms, std::vector<OpenMM::Vec3>& velocities, std::vector<OpenMM::Vec3>& forces, std::vector<double>& inverseMasses);
std::vector<OpenMM::Vec3>& forces, std::vector<double>& inverseMasses, std::vector<OpenMM::Vec3>& xPrime);
/** /**
* Second update step. * Second update step.
...@@ -94,7 +91,6 @@ private: ...@@ -94,7 +91,6 @@ private:
void threadUpdate1(int threadIndex); void threadUpdate1(int threadIndex);
void threadUpdate2(int threadIndex); void threadUpdate2(int threadIndex);
void threadUpdate3(int threadIndex); void threadUpdate3(int threadIndex);
void threadUpdate4(int threadIndex);
OpenMM::ThreadPool& threads; OpenMM::ThreadPool& threads;
OpenMM::CpuRandom& random; OpenMM::CpuRandom& random;
std::vector<OpenMM_SFMT::SFMT> threadRandom; std::vector<OpenMM_SFMT::SFMT> threadRandom;
...@@ -109,4 +105,4 @@ private: ...@@ -109,4 +105,4 @@ private:
} // namespace OpenMM } // namespace OpenMM
#endif // __CPU_BAOAB_DYNAMICS_H__ #endif // __CPU_LANGEVIN_MIDDLE_DYNAMICS_H__
...@@ -61,7 +61,7 @@ KernelImpl* CpuKernelFactory::createKernelImpl(std::string name, const Platform& ...@@ -61,7 +61,7 @@ KernelImpl* CpuKernelFactory::createKernelImpl(std::string name, const Platform&
return new CpuCalcGayBerneForceKernel(name, platform, data); return new CpuCalcGayBerneForceKernel(name, platform, data);
if (name == IntegrateLangevinStepKernel::Name()) if (name == IntegrateLangevinStepKernel::Name())
return new CpuIntegrateLangevinStepKernel(name, platform, data); return new CpuIntegrateLangevinStepKernel(name, platform, data);
if (name == IntegrateBAOABStepKernel::Name()) if (name == IntegrateLangevinMiddleStepKernel::Name())
return new CpuIntegrateBAOABStepKernel(name, platform, data); return new CpuIntegrateLangevinMiddleStepKernel(name, platform, data);
throw OpenMMException((std::string("Tried to create kernel with illegal kernel name '") + name + "'").c_str()); throw OpenMMException((std::string("Tried to create kernel with illegal kernel name '") + name + "'").c_str());
} }
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,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) 2013-2019 Stanford University and the Authors. * * Portions copyright (c) 2013-2020 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -1361,12 +1361,12 @@ double CpuIntegrateLangevinStepKernel::computeKineticEnergy(ContextImpl& context ...@@ -1361,12 +1361,12 @@ double CpuIntegrateLangevinStepKernel::computeKineticEnergy(ContextImpl& context
return computeShiftedKineticEnergy(context, masses, 0.5*integrator.getStepSize()); return computeShiftedKineticEnergy(context, masses, 0.5*integrator.getStepSize());
} }
CpuIntegrateBAOABStepKernel::~CpuIntegrateBAOABStepKernel() { CpuIntegrateLangevinMiddleStepKernel::~CpuIntegrateLangevinMiddleStepKernel() {
if (dynamics) if (dynamics)
delete dynamics; delete dynamics;
} }
void CpuIntegrateBAOABStepKernel::initialize(const System& system, const BAOABLangevinIntegrator& integrator) { void CpuIntegrateLangevinMiddleStepKernel::initialize(const System& system, const LangevinMiddleIntegrator& integrator) {
int numParticles = system.getNumParticles(); int numParticles = system.getNumParticles();
masses.resize(numParticles); masses.resize(numParticles);
for (int i = 0; i < numParticles; ++i) for (int i = 0; i < numParticles; ++i)
...@@ -1374,7 +1374,7 @@ void CpuIntegrateBAOABStepKernel::initialize(const System& system, const BAOABLa ...@@ -1374,7 +1374,7 @@ void CpuIntegrateBAOABStepKernel::initialize(const System& system, const BAOABLa
data.random.initialize(integrator.getRandomNumberSeed(), data.threads.getNumThreads()); data.random.initialize(integrator.getRandomNumberSeed(), data.threads.getNumThreads());
} }
void CpuIntegrateBAOABStepKernel::execute(ContextImpl& context, const BAOABLangevinIntegrator& integrator, bool& forcesAreValid) { void CpuIntegrateLangevinMiddleStepKernel::execute(ContextImpl& context, const LangevinMiddleIntegrator& integrator) {
double temperature = integrator.getTemperature(); double temperature = integrator.getTemperature();
double friction = integrator.getFriction(); double friction = integrator.getFriction();
double stepSize = integrator.getStepSize(); double stepSize = integrator.getStepSize();
...@@ -1385,18 +1385,18 @@ void CpuIntegrateBAOABStepKernel::execute(ContextImpl& context, const BAOABLange ...@@ -1385,18 +1385,18 @@ void CpuIntegrateBAOABStepKernel::execute(ContextImpl& context, const BAOABLange
if (dynamics) if (dynamics)
delete dynamics; delete dynamics;
dynamics = new CpuBAOABDynamics(context.getSystem().getNumParticles(), stepSize, friction, temperature, data.threads, data.random); dynamics = new CpuLangevinMiddleDynamics(context.getSystem().getNumParticles(), stepSize, friction, temperature, data.threads, data.random);
dynamics->setReferenceConstraintAlgorithm(&extractConstraints(context)); dynamics->setReferenceConstraintAlgorithm(&extractConstraints(context));
prevTemp = temperature; prevTemp = temperature;
prevFriction = friction; prevFriction = friction;
prevStepSize = stepSize; prevStepSize = stepSize;
} }
dynamics->update(context, posData, velData, masses, forcesAreValid, integrator.getConstraintTolerance()); dynamics->update(context, posData, velData, masses, integrator.getConstraintTolerance());
ReferencePlatform::PlatformData* refData = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData()); ReferencePlatform::PlatformData* refData = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
refData->time += stepSize; refData->time += stepSize;
refData->stepCount++; refData->stepCount++;
} }
double CpuIntegrateBAOABStepKernel::computeKineticEnergy(ContextImpl& context, const BAOABLangevinIntegrator& integrator) { double CpuIntegrateLangevinMiddleStepKernel::computeKineticEnergy(ContextImpl& context, const LangevinMiddleIntegrator& integrator) {
return computeShiftedKineticEnergy(context, masses, 0.0); return computeShiftedKineticEnergy(context, masses, 0.0);
} }
/* Portions copyright (c) 2006-2020 Stanford University and Simbios.
/* Portions copyright (c) 2006-2019 Stanford University and Simbios.
* Authors: Peter Eastman * Authors: Peter Eastman
* Contributors: * Contributors:
* *
...@@ -24,28 +23,25 @@ ...@@ -24,28 +23,25 @@
*/ */
#include "SimTKOpenMMUtilities.h" #include "SimTKOpenMMUtilities.h"
#include "CpuBAOABDynamics.h" #include "CpuLangevinMiddleDynamics.h"
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
CpuBAOABDynamics::CpuBAOABDynamics(int numberOfAtoms, double deltaT, double friction, double temperature, ThreadPool& threads, CpuRandom& random) : CpuLangevinMiddleDynamics::CpuLangevinMiddleDynamics(int numberOfAtoms, double deltaT, double friction, double temperature, ThreadPool& threads, CpuRandom& random) :
ReferenceBAOABDynamics(numberOfAtoms, deltaT, friction, temperature), threads(threads), random(random) { ReferenceLangevinMiddleDynamics(numberOfAtoms, deltaT, friction, temperature), threads(threads), random(random) {
} }
CpuBAOABDynamics::~CpuBAOABDynamics() { CpuLangevinMiddleDynamics::~CpuLangevinMiddleDynamics() {
} }
void CpuBAOABDynamics::updatePart1(int numberOfAtoms, vector<Vec3>& atomCoordinates, vector<Vec3>& velocities, void CpuLangevinMiddleDynamics::updatePart1(int numberOfAtoms, vector<Vec3>& velocities, vector<Vec3>& forces, vector<double>& inverseMasses) {
vector<Vec3>& forces, vector<double>& inverseMasses, vector<Vec3>& xPrime) {
// Record the parameters for the threads. // Record the parameters for the threads.
this->numberOfAtoms = numberOfAtoms; this->numberOfAtoms = numberOfAtoms;
this->atomCoordinates = &atomCoordinates[0];
this->velocities = &velocities[0]; this->velocities = &velocities[0];
this->forces = &forces[0]; this->forces = &forces[0];
this->inverseMasses = &inverseMasses[0]; this->inverseMasses = &inverseMasses[0];
this->xPrime = &xPrime[0];
// Signal the threads to start running and wait for them to finish. // Signal the threads to start running and wait for them to finish.
...@@ -53,7 +49,7 @@ void CpuBAOABDynamics::updatePart1(int numberOfAtoms, vector<Vec3>& atomCoordina ...@@ -53,7 +49,7 @@ void CpuBAOABDynamics::updatePart1(int numberOfAtoms, vector<Vec3>& atomCoordina
threads.waitForThreads(); threads.waitForThreads();
} }
void CpuBAOABDynamics::updatePart2(int numberOfAtoms, vector<Vec3>& atomCoordinates, vector<Vec3>& velocities, void CpuLangevinMiddleDynamics::updatePart2(int numberOfAtoms, vector<Vec3>& atomCoordinates, vector<Vec3>& velocities,
vector<double>& inverseMasses, vector<Vec3>& xPrime) { vector<double>& inverseMasses, vector<Vec3>& xPrime) {
// Record the parameters for the threads. // Record the parameters for the threads.
...@@ -69,7 +65,7 @@ void CpuBAOABDynamics::updatePart2(int numberOfAtoms, vector<Vec3>& atomCoordina ...@@ -69,7 +65,7 @@ void CpuBAOABDynamics::updatePart2(int numberOfAtoms, vector<Vec3>& atomCoordina
threads.waitForThreads(); threads.waitForThreads();
} }
void CpuBAOABDynamics::updatePart3(ContextImpl& context, int numberOfAtoms, vector<Vec3>& atomCoordinates, vector<Vec3>& velocities, void CpuLangevinMiddleDynamics::updatePart3(ContextImpl& context, int numberOfAtoms, vector<Vec3>& atomCoordinates, vector<Vec3>& velocities,
vector<double>& inverseMasses, vector<Vec3>& xPrime) { vector<double>& inverseMasses, vector<Vec3>& xPrime) {
// Record the parameters for the threads. // Record the parameters for the threads.
...@@ -83,26 +79,18 @@ void CpuBAOABDynamics::updatePart3(ContextImpl& context, int numberOfAtoms, vect ...@@ -83,26 +79,18 @@ void CpuBAOABDynamics::updatePart3(ContextImpl& context, int numberOfAtoms, vect
threads.execute([&] (ThreadPool& threads, int threadIndex) { threadUpdate3(threadIndex); }); threads.execute([&] (ThreadPool& threads, int threadIndex) { threadUpdate3(threadIndex); });
threads.waitForThreads(); threads.waitForThreads();
context.calcForcesAndEnergy(true, false);
threads.execute([&] (ThreadPool& threads, int threadIndex) { threadUpdate4(threadIndex); });
threads.waitForThreads();
} }
void CpuBAOABDynamics::threadUpdate1(int threadIndex) { void CpuLangevinMiddleDynamics::threadUpdate1(int threadIndex) {
const double halfdt = 0.5*getDeltaT();
int start = threadIndex*numberOfAtoms/threads.getNumThreads(); int start = threadIndex*numberOfAtoms/threads.getNumThreads();
int end = (threadIndex+1)*numberOfAtoms/threads.getNumThreads(); int end = (threadIndex+1)*numberOfAtoms/threads.getNumThreads();
for (int i = start; i < end; i++) { for (int i = start; i < end; i++)
if (inverseMasses[i] != 0.0) { if (inverseMasses[i] != 0.0)
velocities[i] += (halfdt*inverseMasses[i])*forces[i]; velocities[i] += (getDeltaT()*inverseMasses[i])*forces[i];
xPrime[i] = atomCoordinates[i] + velocities[i]*halfdt;
oldx[i] = xPrime[i];
}
}
} }
void CpuBAOABDynamics::threadUpdate2(int threadIndex) { void CpuLangevinMiddleDynamics::threadUpdate2(int threadIndex) {
const double halfdt = 0.5*getDeltaT(); const double halfdt = 0.5*getDeltaT();
const double kT = BOLTZ*getTemperature(); const double kT = BOLTZ*getTemperature();
const double friction = getFriction(); const double friction = getFriction();
...@@ -113,34 +101,22 @@ void CpuBAOABDynamics::threadUpdate2(int threadIndex) { ...@@ -113,34 +101,22 @@ void CpuBAOABDynamics::threadUpdate2(int threadIndex) {
for (int i = start; i < end; i++) { for (int i = start; i < end; i++) {
if (inverseMasses[i] != 0.0) { if (inverseMasses[i] != 0.0) {
velocities[i] += (xPrime[i]-oldx[i])/halfdt; xPrime[i] = atomCoordinates[i] + velocities[i]*halfdt;
Vec3 noise(random.getGaussianRandom(threadIndex), random.getGaussianRandom(threadIndex), random.getGaussianRandom(threadIndex)); Vec3 noise(random.getGaussianRandom(threadIndex), random.getGaussianRandom(threadIndex), random.getGaussianRandom(threadIndex));
velocities[i] = vscale*velocities[i] + noisescale*sqrt(kT*inverseMasses[i])*noise; velocities[i] = vscale*velocities[i] + noisescale*sqrt(kT*inverseMasses[i])*noise;
atomCoordinates[i] = xPrime[i]; xPrime[i] = xPrime[i] + velocities[i]*halfdt;
xPrime[i] = atomCoordinates[i] + velocities[i]*halfdt;
oldx[i] = xPrime[i]; oldx[i] = xPrime[i];
} }
} }
} }
void CpuBAOABDynamics::threadUpdate3(int threadIndex) { void CpuLangevinMiddleDynamics::threadUpdate3(int threadIndex) {
const double halfdt = 0.5*getDeltaT();
int start = threadIndex*numberOfAtoms/threads.getNumThreads(); int start = threadIndex*numberOfAtoms/threads.getNumThreads();
int end = (threadIndex+1)*numberOfAtoms/threads.getNumThreads(); int end = (threadIndex+1)*numberOfAtoms/threads.getNumThreads();
for (int i = start; i < end; ++i) for (int i = start; i < end; ++i)
if (inverseMasses[i] != 0.0) { if (inverseMasses[i] != 0.0) {
velocities[i] += (xPrime[i]-oldx[i])/halfdt; velocities[i] += (xPrime[i]-oldx[i])/getDeltaT();
atomCoordinates[i] = xPrime[i]; atomCoordinates[i] = xPrime[i];
} }
} }
void CpuBAOABDynamics::threadUpdate4(int threadIndex) {
const double halfdt = 0.5*getDeltaT();
int start = threadIndex*numberOfAtoms/threads.getNumThreads();
int end = (threadIndex+1)*numberOfAtoms/threads.getNumThreads();
for (int i = start; i < end; ++i)
if (inverseMasses[i] != 0.0)
velocities[i] += (halfdt*inverseMasses[i])*forces[i];
}
...@@ -74,7 +74,7 @@ CpuPlatform::CpuPlatform() { ...@@ -74,7 +74,7 @@ CpuPlatform::CpuPlatform() {
registerKernelFactory(CalcCustomGBForceKernel::Name(), factory); registerKernelFactory(CalcCustomGBForceKernel::Name(), factory);
registerKernelFactory(CalcGayBerneForceKernel::Name(), factory); registerKernelFactory(CalcGayBerneForceKernel::Name(), factory);
registerKernelFactory(IntegrateLangevinStepKernel::Name(), factory); registerKernelFactory(IntegrateLangevinStepKernel::Name(), factory);
registerKernelFactory(IntegrateBAOABStepKernel::Name(), factory); registerKernelFactory(IntegrateLangevinMiddleStepKernel::Name(), factory);
platformProperties.push_back(CpuThreads()); platformProperties.push_back(CpuThreads());
platformProperties.push_back(CpuDeterministicForces()); platformProperties.push_back(CpuDeterministicForces());
int threads = getNumProcessors(); int threads = getNumProcessors();
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "CpuTests.h" #include "CpuTests.h"
#include "TestBAOABLangevinIntegrator.h" #include "TestLangevinMiddleIntegrator.h"
void runPlatformTests() { void runPlatformTests() {
} }
...@@ -121,8 +121,8 @@ KernelImpl* CudaKernelFactory::createKernelImpl(std::string name, const Platform ...@@ -121,8 +121,8 @@ KernelImpl* CudaKernelFactory::createKernelImpl(std::string name, const Platform
return new CommonIntegrateVerletStepKernel(name, platform, cu); return new CommonIntegrateVerletStepKernel(name, platform, cu);
if (name == IntegrateLangevinStepKernel::Name()) if (name == IntegrateLangevinStepKernel::Name())
return new CommonIntegrateLangevinStepKernel(name, platform, cu); return new CommonIntegrateLangevinStepKernel(name, platform, cu);
if (name == IntegrateBAOABStepKernel::Name()) if (name == IntegrateLangevinMiddleStepKernel::Name())
return new CommonIntegrateBAOABStepKernel(name, platform, cu); return new CommonIntegrateLangevinMiddleStepKernel(name, platform, cu);
if (name == IntegrateBrownianStepKernel::Name()) if (name == IntegrateBrownianStepKernel::Name())
return new CommonIntegrateBrownianStepKernel(name, platform, cu); return new CommonIntegrateBrownianStepKernel(name, platform, cu);
if (name == IntegrateVariableVerletStepKernel::Name()) if (name == IntegrateVariableVerletStepKernel::Name())
......
...@@ -98,7 +98,7 @@ CudaPlatform::CudaPlatform() { ...@@ -98,7 +98,7 @@ CudaPlatform::CudaPlatform() {
registerKernelFactory(IntegrateVerletStepKernel::Name(), factory); registerKernelFactory(IntegrateVerletStepKernel::Name(), factory);
registerKernelFactory(IntegrateVelocityVerletStepKernel::Name(), factory); registerKernelFactory(IntegrateVelocityVerletStepKernel::Name(), factory);
registerKernelFactory(IntegrateLangevinStepKernel::Name(), factory); registerKernelFactory(IntegrateLangevinStepKernel::Name(), factory);
registerKernelFactory(IntegrateBAOABStepKernel::Name(), factory); registerKernelFactory(IntegrateLangevinMiddleStepKernel::Name(), factory);
registerKernelFactory(IntegrateBrownianStepKernel::Name(), factory); registerKernelFactory(IntegrateBrownianStepKernel::Name(), factory);
registerKernelFactory(IntegrateVariableVerletStepKernel::Name(), factory); registerKernelFactory(IntegrateVariableVerletStepKernel::Name(), factory);
registerKernelFactory(IntegrateVariableLangevinStepKernel::Name(), factory); registerKernelFactory(IntegrateVariableLangevinStepKernel::Name(), factory);
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "CudaTests.h" #include "CudaTests.h"
#include "TestBAOABLangevinIntegrator.h" #include "TestLangevinMiddleIntegrator.h"
void runPlatformTests() { void runPlatformTests() {
} }
...@@ -119,8 +119,8 @@ KernelImpl* OpenCLKernelFactory::createKernelImpl(std::string name, const Platfo ...@@ -119,8 +119,8 @@ KernelImpl* OpenCLKernelFactory::createKernelImpl(std::string name, const Platfo
return new CommonIntegrateVerletStepKernel(name, platform, cl); return new CommonIntegrateVerletStepKernel(name, platform, cl);
if (name == IntegrateLangevinStepKernel::Name()) if (name == IntegrateLangevinStepKernel::Name())
return new CommonIntegrateLangevinStepKernel(name, platform, cl); return new CommonIntegrateLangevinStepKernel(name, platform, cl);
if (name == IntegrateBAOABStepKernel::Name()) if (name == IntegrateLangevinMiddleStepKernel::Name())
return new CommonIntegrateBAOABStepKernel(name, platform, cl); return new CommonIntegrateLangevinMiddleStepKernel(name, platform, cl);
if (name == IntegrateBrownianStepKernel::Name()) if (name == IntegrateBrownianStepKernel::Name())
return new CommonIntegrateBrownianStepKernel(name, platform, cl); return new CommonIntegrateBrownianStepKernel(name, platform, cl);
if (name == IntegrateVariableVerletStepKernel::Name()) if (name == IntegrateVariableVerletStepKernel::Name())
......
...@@ -89,7 +89,7 @@ OpenCLPlatform::OpenCLPlatform() { ...@@ -89,7 +89,7 @@ OpenCLPlatform::OpenCLPlatform() {
registerKernelFactory(IntegrateVerletStepKernel::Name(), factory); registerKernelFactory(IntegrateVerletStepKernel::Name(), factory);
registerKernelFactory(IntegrateVelocityVerletStepKernel::Name(), factory); registerKernelFactory(IntegrateVelocityVerletStepKernel::Name(), factory);
registerKernelFactory(IntegrateLangevinStepKernel::Name(), factory); registerKernelFactory(IntegrateLangevinStepKernel::Name(), factory);
registerKernelFactory(IntegrateBAOABStepKernel::Name(), factory); registerKernelFactory(IntegrateLangevinMiddleStepKernel::Name(), factory);
registerKernelFactory(IntegrateBrownianStepKernel::Name(), factory); registerKernelFactory(IntegrateBrownianStepKernel::Name(), factory);
registerKernelFactory(IntegrateVariableVerletStepKernel::Name(), factory); registerKernelFactory(IntegrateVariableVerletStepKernel::Name(), factory);
registerKernelFactory(IntegrateVariableLangevinStepKernel::Name(), factory); registerKernelFactory(IntegrateVariableLangevinStepKernel::Name(), factory);
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "OpenCLTests.h" #include "OpenCLTests.h"
#include "TestBAOABLangevinIntegrator.h" #include "TestLangevinMiddleIntegrator.h"
void runPlatformTests() { void runPlatformTests() {
} }
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,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) 2008-2019 Stanford University and the Authors. * * Portions copyright (c) 2008-2020 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -45,7 +45,7 @@ namespace OpenMM { ...@@ -45,7 +45,7 @@ namespace OpenMM {
class ReferenceObc; class ReferenceObc;
class ReferenceAndersenThermostat; class ReferenceAndersenThermostat;
class ReferenceBAOABDynamics; class ReferenceLangevinMiddleDynamics;
class ReferenceCustomBondIxn; class ReferenceCustomBondIxn;
class ReferenceCustomAngleIxn; class ReferenceCustomAngleIxn;
class ReferenceCustomTorsionIxn; class ReferenceCustomTorsionIxn;
...@@ -1213,42 +1213,38 @@ private: ...@@ -1213,42 +1213,38 @@ private:
}; };
/** /**
* This kernel is invoked by BAOABLangevinIntegrator to take one time step. * This kernel is invoked by LangevinMiddleIntegrator to take one time step.
*/ */
class ReferenceIntegrateBAOABStepKernel : public IntegrateBAOABStepKernel { class ReferenceIntegrateLangevinMiddleStepKernel : public IntegrateLangevinMiddleStepKernel {
public: public:
ReferenceIntegrateBAOABStepKernel(std::string name, const Platform& platform, ReferencePlatform::PlatformData& data) : IntegrateBAOABStepKernel(name, platform), ReferenceIntegrateLangevinMiddleStepKernel(std::string name, const Platform& platform, ReferencePlatform::PlatformData& data) : IntegrateLangevinMiddleStepKernel(name, platform),
data(data), dynamics(0) { data(data), dynamics(0) {
} }
~ReferenceIntegrateBAOABStepKernel(); ~ReferenceIntegrateLangevinMiddleStepKernel();
/** /**
* Initialize the kernel, setting up the particle masses. * Initialize the kernel, setting up the particle masses.
* *
* @param system the System this kernel will be applied to * @param system the System this kernel will be applied to
* @param integrator the BAOABLangevinIntegrator this kernel will be used for * @param integrator the LangevinMiddleIntegrator this kernel will be used for
*/ */
void initialize(const System& system, const BAOABLangevinIntegrator& integrator); void initialize(const System& system, const LangevinMiddleIntegrator& integrator);
/** /**
* Execute the kernel. * Execute the kernel.
* *
* @param context the context in which to execute this kernel * @param context the context in which to execute this kernel
* @param integrator the BAOABLangevinIntegrator this kernel is being used for * @param integrator the LangevinMiddleIntegrator this kernel is being used for
* @param forcesAreValid if the context has been modified since the last time step, this will be
* false to show that cached forces are invalid and must be recalculated.
* On exit, this should specify whether the cached forces are valid at the
* end of the step.
*/ */
void execute(ContextImpl& context, const BAOABLangevinIntegrator& integrator, bool& forcesAreValid); void execute(ContextImpl& context, const LangevinMiddleIntegrator& integrator);
/** /**
* Compute the kinetic energy. * Compute the kinetic energy.
* *
* @param context the context in which to execute this kernel * @param context the context in which to execute this kernel
* @param integrator the BAOABLangevinIntegrator this kernel is being used for * @param integrator the LangevinMiddleIntegrator this kernel is being used for
*/ */
double computeKineticEnergy(ContextImpl& context, const BAOABLangevinIntegrator& integrator); double computeKineticEnergy(ContextImpl& context, const LangevinMiddleIntegrator& integrator);
private: private:
ReferencePlatform::PlatformData& data; ReferencePlatform::PlatformData& data;
ReferenceBAOABDynamics* dynamics; ReferenceLangevinMiddleDynamics* dynamics;
std::vector<double> masses; std::vector<double> masses;
double prevTemp, prevFriction, prevStepSize; double prevTemp, prevFriction, prevStepSize;
}; };
......
/* Portions copyright (c) 2006-2019 Stanford University and Simbios. /* Portions copyright (c) 2006-2020 Stanford University and Simbios.
* Contributors: Pande Group * Contributors: Pande Group
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#ifndef __ReferenceBAOABDynamics_H__ #ifndef __ReferenceLangevinMiddleDynamics_H__
#define __ReferenceBAOABDynamics_H__ #define __ReferenceLangevinMiddleDynamics_H__
#include "ReferenceDynamics.h" #include "ReferenceDynamics.h"
#include "openmm/internal/ContextImpl.h" #include "openmm/internal/ContextImpl.h"
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
namespace OpenMM { namespace OpenMM {
class OPENMM_EXPORT ReferenceBAOABDynamics : public ReferenceDynamics { class OPENMM_EXPORT ReferenceLangevinMiddleDynamics : public ReferenceDynamics {
protected: protected:
...@@ -52,7 +52,7 @@ class OPENMM_EXPORT ReferenceBAOABDynamics : public ReferenceDynamics { ...@@ -52,7 +52,7 @@ class OPENMM_EXPORT ReferenceBAOABDynamics : public ReferenceDynamics {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
ReferenceBAOABDynamics(int numberOfAtoms, double deltaT, double friction, double temperature); ReferenceLangevinMiddleDynamics(int numberOfAtoms, double deltaT, double friction, double temperature);
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -60,7 +60,7 @@ class OPENMM_EXPORT ReferenceBAOABDynamics : public ReferenceDynamics { ...@@ -60,7 +60,7 @@ class OPENMM_EXPORT ReferenceBAOABDynamics : public ReferenceDynamics {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
~ReferenceBAOABDynamics(); ~ReferenceLangevinMiddleDynamics();
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -79,29 +79,25 @@ class OPENMM_EXPORT ReferenceBAOABDynamics : public ReferenceDynamics { ...@@ -79,29 +79,25 @@ class OPENMM_EXPORT ReferenceBAOABDynamics : public ReferenceDynamics {
@param atomCoordinates atom coordinates @param atomCoordinates atom coordinates
@param velocities velocities @param velocities velocities
@param masses atom masses @param masses atom masses
@param forcesAreValid whether the current forces are valid or need to be recomputed
@param tolerance the constraint tolerance @param tolerance the constraint tolerance
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
void update(OpenMM::ContextImpl& context, std::vector<OpenMM::Vec3>& atomCoordinates, void update(OpenMM::ContextImpl& context, std::vector<OpenMM::Vec3>& atomCoordinates,
std::vector<OpenMM::Vec3>& velocities, std::vector<double>& masses, bool& forcesAreValid, double tolerance); std::vector<OpenMM::Vec3>& velocities, std::vector<double>& masses, double tolerance);
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
First update; based on code in update.c do_update_sd() Gromacs 3.1.4 First update; based on code in update.c do_update_sd() Gromacs 3.1.4
@param numberOfAtoms number of atoms @param numberOfAtoms number of atoms
@param atomCoordinates atom coordinates
@param velocities velocities @param velocities velocities
@param forces forces @param forces forces
@param inverseMasses inverse atom masses @param inverseMasses inverse atom masses
@param xPrime xPrime
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
virtual void updatePart1(int numberOfAtoms, std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<OpenMM::Vec3>& velocities, virtual void updatePart1(int numberOfAtoms, std::vector<OpenMM::Vec3>& velocities, std::vector<OpenMM::Vec3>& forces, std::vector<double>& inverseMasses);
std::vector<OpenMM::Vec3>& forces, std::vector<double>& inverseMasses, std::vector<OpenMM::Vec3>& xPrime);
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -116,7 +112,7 @@ class OPENMM_EXPORT ReferenceBAOABDynamics : public ReferenceDynamics { ...@@ -116,7 +112,7 @@ class OPENMM_EXPORT ReferenceBAOABDynamics : public ReferenceDynamics {
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
virtual void updatePart2(int numberOfAtoms, std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<OpenMM::Vec3>& velocities, virtual void updatePart2(int numberOfAtoms, std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<OpenMM::Vec3>& velocities,
std::vector<double>& inverseMasses, std::vector<OpenMM::Vec3>& xPrime); std::vector<double>& inverseMasses, std::vector<OpenMM::Vec3>& xPrime);
/**--------------------------------------------------------------------------------------- /**---------------------------------------------------------------------------------------
...@@ -126,16 +122,15 @@ class OPENMM_EXPORT ReferenceBAOABDynamics : public ReferenceDynamics { ...@@ -126,16 +122,15 @@ class OPENMM_EXPORT ReferenceBAOABDynamics : public ReferenceDynamics {
@param numberOfAtoms number of atoms @param numberOfAtoms number of atoms
@param atomCoordinates atom coordinates @param atomCoordinates atom coordinates
@param velocities velocities @param velocities velocities
@param forces forces
@param inverseMasses inverse atom masses @param inverseMasses inverse atom masses
@param xPrime xPrime @param xPrime xPrime
--------------------------------------------------------------------------------------- */ --------------------------------------------------------------------------------------- */
virtual void updatePart3(OpenMM::ContextImpl& context, int numberOfAtoms, std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<OpenMM::Vec3>& velocities, virtual void updatePart3(OpenMM::ContextImpl& context, int numberOfAtoms, std::vector<OpenMM::Vec3>& atomCoordinates, std::vector<OpenMM::Vec3>& velocities,
std::vector<OpenMM::Vec3>& forces, std::vector<double>& inverseMasses, std::vector<OpenMM::Vec3>& xPrime); std::vector<double>& inverseMasses, std::vector<OpenMM::Vec3>& xPrime);
}; };
} // namespace OpenMM } // namespace OpenMM
#endif // __ReferenceBAOABDynamics_H__ #endif // __ReferenceLangevinMiddleDynamics_H__
...@@ -94,8 +94,8 @@ KernelImpl* ReferenceKernelFactory::createKernelImpl(std::string name, const Pla ...@@ -94,8 +94,8 @@ KernelImpl* ReferenceKernelFactory::createKernelImpl(std::string name, const Pla
return new ReferenceNoseHooverChainKernel(name, platform); return new ReferenceNoseHooverChainKernel(name, platform);
if (name == IntegrateLangevinStepKernel::Name()) if (name == IntegrateLangevinStepKernel::Name())
return new ReferenceIntegrateLangevinStepKernel(name, platform, data); return new ReferenceIntegrateLangevinStepKernel(name, platform, data);
if (name == IntegrateBAOABStepKernel::Name()) if (name == IntegrateLangevinMiddleStepKernel::Name())
return new ReferenceIntegrateBAOABStepKernel(name, platform, data); return new ReferenceIntegrateLangevinMiddleStepKernel(name, platform, data);
if (name == IntegrateBrownianStepKernel::Name()) if (name == IntegrateBrownianStepKernel::Name())
return new ReferenceIntegrateBrownianStepKernel(name, platform, data); return new ReferenceIntegrateBrownianStepKernel(name, platform, data);
if (name == IntegrateVariableLangevinStepKernel::Name()) if (name == IntegrateVariableLangevinStepKernel::Name())
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,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) 2008-2019 Stanford University and the Authors. * * Portions copyright (c) 2008-2020 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#include "ReferenceObc.h" #include "ReferenceObc.h"
#include "ReferenceAndersenThermostat.h" #include "ReferenceAndersenThermostat.h"
#include "ReferenceAngleBondIxn.h" #include "ReferenceAngleBondIxn.h"
#include "ReferenceBAOABDynamics.h"
#include "ReferenceBondForce.h" #include "ReferenceBondForce.h"
#include "ReferenceBrownianDynamics.h" #include "ReferenceBrownianDynamics.h"
#include "ReferenceCCMAAlgorithm.h" #include "ReferenceCCMAAlgorithm.h"
...@@ -53,6 +52,7 @@ ...@@ -53,6 +52,7 @@
#include "ReferenceCustomTorsionIxn.h" #include "ReferenceCustomTorsionIxn.h"
#include "ReferenceGayBerneForce.h" #include "ReferenceGayBerneForce.h"
#include "ReferenceHarmonicBondIxn.h" #include "ReferenceHarmonicBondIxn.h"
#include "ReferenceLangevinMiddleDynamics.h"
#include "ReferenceLJCoulomb14.h" #include "ReferenceLJCoulomb14.h"
#include "ReferenceLJCoulombIxn.h" #include "ReferenceLJCoulombIxn.h"
#include "ReferenceMonteCarloBarostat.h" #include "ReferenceMonteCarloBarostat.h"
...@@ -2233,12 +2233,12 @@ double ReferenceIntegrateLangevinStepKernel::computeKineticEnergy(ContextImpl& c ...@@ -2233,12 +2233,12 @@ double ReferenceIntegrateLangevinStepKernel::computeKineticEnergy(ContextImpl& c
return computeShiftedKineticEnergy(context, masses, 0.5*integrator.getStepSize()); return computeShiftedKineticEnergy(context, masses, 0.5*integrator.getStepSize());
} }
ReferenceIntegrateBAOABStepKernel::~ReferenceIntegrateBAOABStepKernel() { ReferenceIntegrateLangevinMiddleStepKernel::~ReferenceIntegrateLangevinMiddleStepKernel() {
if (dynamics) if (dynamics)
delete dynamics; delete dynamics;
} }
void ReferenceIntegrateBAOABStepKernel::initialize(const System& system, const BAOABLangevinIntegrator& integrator) { void ReferenceIntegrateLangevinMiddleStepKernel::initialize(const System& system, const LangevinMiddleIntegrator& integrator) {
int numParticles = system.getNumParticles(); int numParticles = system.getNumParticles();
masses.resize(numParticles); masses.resize(numParticles);
for (int i = 0; i < numParticles; ++i) for (int i = 0; i < numParticles; ++i)
...@@ -2246,7 +2246,7 @@ void ReferenceIntegrateBAOABStepKernel::initialize(const System& system, const B ...@@ -2246,7 +2246,7 @@ void ReferenceIntegrateBAOABStepKernel::initialize(const System& system, const B
SimTKOpenMMUtilities::setRandomNumberSeed((unsigned int) integrator.getRandomNumberSeed()); SimTKOpenMMUtilities::setRandomNumberSeed((unsigned int) integrator.getRandomNumberSeed());
} }
void ReferenceIntegrateBAOABStepKernel::execute(ContextImpl& context, const BAOABLangevinIntegrator& integrator, bool& forcesAreValid) { void ReferenceIntegrateLangevinMiddleStepKernel::execute(ContextImpl& context, const LangevinMiddleIntegrator& integrator) {
double temperature = integrator.getTemperature(); double temperature = integrator.getTemperature();
double friction = integrator.getFriction(); double friction = integrator.getFriction();
double stepSize = integrator.getStepSize(); double stepSize = integrator.getStepSize();
...@@ -2257,7 +2257,7 @@ void ReferenceIntegrateBAOABStepKernel::execute(ContextImpl& context, const BAOA ...@@ -2257,7 +2257,7 @@ void ReferenceIntegrateBAOABStepKernel::execute(ContextImpl& context, const BAOA
if (dynamics) if (dynamics)
delete dynamics; delete dynamics;
dynamics = new ReferenceBAOABDynamics( dynamics = new ReferenceLangevinMiddleDynamics(
context.getSystem().getNumParticles(), context.getSystem().getNumParticles(),
stepSize, stepSize,
friction, friction,
...@@ -2267,12 +2267,12 @@ void ReferenceIntegrateBAOABStepKernel::execute(ContextImpl& context, const BAOA ...@@ -2267,12 +2267,12 @@ void ReferenceIntegrateBAOABStepKernel::execute(ContextImpl& context, const BAOA
prevFriction = friction; prevFriction = friction;
prevStepSize = stepSize; prevStepSize = stepSize;
} }
dynamics->update(context, posData, velData, masses, forcesAreValid, integrator.getConstraintTolerance()); dynamics->update(context, posData, velData, masses, integrator.getConstraintTolerance());
data.time += stepSize; data.time += stepSize;
data.stepCount++; data.stepCount++;
} }
double ReferenceIntegrateBAOABStepKernel::computeKineticEnergy(ContextImpl& context, const BAOABLangevinIntegrator& integrator) { double ReferenceIntegrateLangevinMiddleStepKernel::computeKineticEnergy(ContextImpl& context, const LangevinMiddleIntegrator& integrator) {
return computeShiftedKineticEnergy(context, masses, 0.0); return computeShiftedKineticEnergy(context, masses, 0.0);
} }
......
...@@ -69,7 +69,7 @@ ReferencePlatform::ReferencePlatform() { ...@@ -69,7 +69,7 @@ ReferencePlatform::ReferencePlatform() {
registerKernelFactory(IntegrateVelocityVerletStepKernel::Name(), factory); registerKernelFactory(IntegrateVelocityVerletStepKernel::Name(), factory);
registerKernelFactory(NoseHooverChainKernel::Name(), factory); registerKernelFactory(NoseHooverChainKernel::Name(), factory);
registerKernelFactory(IntegrateLangevinStepKernel::Name(), factory); registerKernelFactory(IntegrateLangevinStepKernel::Name(), factory);
registerKernelFactory(IntegrateBAOABStepKernel::Name(), factory); registerKernelFactory(IntegrateLangevinMiddleStepKernel::Name(), factory);
registerKernelFactory(IntegrateBrownianStepKernel::Name(), factory); registerKernelFactory(IntegrateBrownianStepKernel::Name(), factory);
registerKernelFactory(IntegrateVariableLangevinStepKernel::Name(), factory); registerKernelFactory(IntegrateVariableLangevinStepKernel::Name(), factory);
registerKernelFactory(IntegrateVariableVerletStepKernel::Name(), factory); registerKernelFactory(IntegrateVariableVerletStepKernel::Name(), factory);
......
/* Portions copyright (c) 2006-2019 Stanford University and Simbios. /* Portions copyright (c) 2006-2020 Stanford University and Simbios.
* Contributors: Pande Group * Contributors: Pande Group
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include <sstream> #include <sstream>
#include "SimTKOpenMMUtilities.h" #include "SimTKOpenMMUtilities.h"
#include "ReferenceBAOABDynamics.h" #include "ReferenceLangevinMiddleDynamics.h"
#include "ReferencePlatform.h" #include "ReferencePlatform.h"
#include "ReferenceVirtualSites.h" #include "ReferenceVirtualSites.h"
#include "openmm/OpenMMException.h" #include "openmm/OpenMMException.h"
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
using std::vector; using std::vector;
using namespace OpenMM; using namespace OpenMM;
ReferenceBAOABDynamics::ReferenceBAOABDynamics(int numberOfAtoms, ReferenceLangevinMiddleDynamics::ReferenceLangevinMiddleDynamics(int numberOfAtoms,
double deltaT, double friction, double deltaT, double friction,
double temperature) : double temperature) :
ReferenceDynamics(numberOfAtoms, deltaT, temperature), friction(friction) { ReferenceDynamics(numberOfAtoms, deltaT, temperature), friction(friction) {
...@@ -44,29 +44,22 @@ ReferenceBAOABDynamics::ReferenceBAOABDynamics(int numberOfAtoms, ...@@ -44,29 +44,22 @@ ReferenceBAOABDynamics::ReferenceBAOABDynamics(int numberOfAtoms,
inverseMasses.resize(numberOfAtoms); inverseMasses.resize(numberOfAtoms);
} }
ReferenceBAOABDynamics::~ReferenceBAOABDynamics() { ReferenceLangevinMiddleDynamics::~ReferenceLangevinMiddleDynamics() {
} }
double ReferenceBAOABDynamics::getFriction() const { double ReferenceLangevinMiddleDynamics::getFriction() const {
return friction; return friction;
} }
void ReferenceBAOABDynamics::updatePart1(int numberOfAtoms, vector<Vec3>& atomCoordinates, void ReferenceLangevinMiddleDynamics::updatePart1(int numberOfAtoms, vector<Vec3>& velocities, vector<Vec3>& forces, vector<double>& inverseMasses) {
vector<Vec3>& velocities, vector<Vec3>& forces, vector<double>& inverseMasses, for (int i = 0; i < numberOfAtoms; i++)
vector<Vec3>& xPrime) { if (inverseMasses[i] != 0.0)
const double halfdt = 0.5*getDeltaT(); velocities[i] += (getDeltaT()*inverseMasses[i])*forces[i];
for (int i = 0; i < numberOfAtoms; i++) {
if (inverseMasses[i] != 0.0) {
velocities[i] += (halfdt*inverseMasses[i])*forces[i];
xPrime[i] = atomCoordinates[i] + velocities[i]*halfdt;
oldx[i] = xPrime[i];
}
}
} }
void ReferenceBAOABDynamics::updatePart2(int numberOfAtoms, vector<Vec3>& atomCoordinates, void ReferenceLangevinMiddleDynamics::updatePart2(int numberOfAtoms, vector<Vec3>& atomCoordinates,
vector<Vec3>& velocities, vector<double>& inverseMasses, vector<Vec3>& velocities, vector<double>& inverseMasses,
vector<Vec3>& xPrime) { vector<Vec3>& xPrime) {
const double halfdt = 0.5*getDeltaT(); const double halfdt = 0.5*getDeltaT();
const double kT = BOLTZ*getTemperature(); const double kT = BOLTZ*getTemperature();
const double friction = getFriction(); const double friction = getFriction();
...@@ -75,37 +68,29 @@ void ReferenceBAOABDynamics::updatePart2(int numberOfAtoms, vector<Vec3>& atomCo ...@@ -75,37 +68,29 @@ void ReferenceBAOABDynamics::updatePart2(int numberOfAtoms, vector<Vec3>& atomCo
for (int i = 0; i < numberOfAtoms; i++) { for (int i = 0; i < numberOfAtoms; i++) {
if (inverseMasses[i] != 0.0) { if (inverseMasses[i] != 0.0) {
velocities[i] += (xPrime[i]-oldx[i])/halfdt; xPrime[i] = atomCoordinates[i] + velocities[i]*halfdt;
velocities[i] = vscale*velocities[i] + noisescale*sqrt(kT*inverseMasses[i])*Vec3( velocities[i] = vscale*velocities[i] + noisescale*sqrt(kT*inverseMasses[i])*Vec3(
SimTKOpenMMUtilities::getNormallyDistributedRandomNumber(), SimTKOpenMMUtilities::getNormallyDistributedRandomNumber(),
SimTKOpenMMUtilities::getNormallyDistributedRandomNumber(), SimTKOpenMMUtilities::getNormallyDistributedRandomNumber(),
SimTKOpenMMUtilities::getNormallyDistributedRandomNumber()); SimTKOpenMMUtilities::getNormallyDistributedRandomNumber());
atomCoordinates[i] = xPrime[i]; xPrime[i] = xPrime[i] + velocities[i]*halfdt;
xPrime[i] = atomCoordinates[i] + velocities[i]*halfdt;
oldx[i] = xPrime[i]; oldx[i] = xPrime[i];
} }
} }
} }
void ReferenceBAOABDynamics::updatePart3(OpenMM::ContextImpl& context, int numberOfAtoms, vector<Vec3>& atomCoordinates, void ReferenceLangevinMiddleDynamics::updatePart3(OpenMM::ContextImpl& context, int numberOfAtoms, vector<Vec3>& atomCoordinates,
vector<Vec3>& velocities, vector<Vec3>& forces, vector<double>& inverseMasses, vector<Vec3>& velocities, vector<double>& inverseMasses, vector<Vec3>& xPrime) {
vector<Vec3>& xPrime) {
const double halfdt = 0.5*getDeltaT();
for (int i = 0; i < numberOfAtoms; i++) { for (int i = 0; i < numberOfAtoms; i++) {
if (inverseMasses[i] != 0.0) { if (inverseMasses[i] != 0.0) {
velocities[i] += (xPrime[i]-oldx[i])/halfdt; velocities[i] += (xPrime[i]-oldx[i])/getDeltaT();
atomCoordinates[i] = xPrime[i]; atomCoordinates[i] = xPrime[i];
} }
} }
context.calcForcesAndEnergy(true, false);
for (int i = 0; i < numberOfAtoms; i++) {
if (inverseMasses[i] != 0.0)
velocities[i] += (halfdt*inverseMasses[i])*forces[i];
}
} }
void ReferenceBAOABDynamics::update(ContextImpl& context, vector<Vec3>& atomCoordinates, void ReferenceLangevinMiddleDynamics::update(ContextImpl& context, vector<Vec3>& atomCoordinates,
vector<Vec3>& velocities, vector<double>& masses, bool& forcesAreValid, double tolerance) { vector<Vec3>& velocities, vector<double>& masses, double tolerance) {
int numberOfAtoms = context.getSystem().getNumParticles(); int numberOfAtoms = context.getSystem().getNumParticles();
ReferenceConstraintAlgorithm* referenceConstraintAlgorithm = getReferenceConstraintAlgorithm(); ReferenceConstraintAlgorithm* referenceConstraintAlgorithm = getReferenceConstraintAlgorithm();
if (getTimeStep() == 0) { if (getTimeStep() == 0) {
...@@ -118,18 +103,14 @@ void ReferenceBAOABDynamics::update(ContextImpl& context, vector<Vec3>& atomCoor ...@@ -118,18 +103,14 @@ void ReferenceBAOABDynamics::update(ContextImpl& context, vector<Vec3>& atomCoor
inverseMasses[ii] = 1.0/masses[ii]; inverseMasses[ii] = 1.0/masses[ii];
} }
} }
if (!forcesAreValid) {
context.calcForcesAndEnergy(true, false);
forcesAreValid = true;
}
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData()); ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
vector<Vec3>& forces = *data->forces; vector<Vec3>& forces = *data->forces;
// 1st update // 1st update
updatePart1(numberOfAtoms, atomCoordinates, velocities, forces, inverseMasses, xPrime); updatePart1(numberOfAtoms, velocities, forces, inverseMasses);
if (referenceConstraintAlgorithm) if (referenceConstraintAlgorithm)
referenceConstraintAlgorithm->apply(atomCoordinates, xPrime, inverseMasses, tolerance); referenceConstraintAlgorithm->applyToVelocities(atomCoordinates, velocities, inverseMasses, tolerance);
// 2nd update // 2nd update
...@@ -139,9 +120,7 @@ void ReferenceBAOABDynamics::update(ContextImpl& context, vector<Vec3>& atomCoor ...@@ -139,9 +120,7 @@ void ReferenceBAOABDynamics::update(ContextImpl& context, vector<Vec3>& atomCoor
// 3rd update // 3rd update
updatePart3(context, numberOfAtoms, atomCoordinates, velocities, forces, inverseMasses, xPrime); updatePart3(context, numberOfAtoms, atomCoordinates, velocities, inverseMasses, xPrime);
if (referenceConstraintAlgorithm)
referenceConstraintAlgorithm->applyToVelocities(atomCoordinates, velocities, inverseMasses, tolerance);
ReferenceVirtualSites::computePositions(context.getSystem(), atomCoordinates); ReferenceVirtualSites::computePositions(context.getSystem(), atomCoordinates);
incrementTimeStep(); incrementTimeStep();
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "ReferenceTests.h" #include "ReferenceTests.h"
#include "TestBAOABLangevinIntegrator.h" #include "TestLangevinMiddleIntegrator.h"
void runPlatformTests() { void runPlatformTests() {
} }
#ifndef OPENMM_BAOAB_LANGEVIN_INTEGRATOR_PROXY_H_ #ifndef OPENMM_LANGEVIN_MIDDLE_INTEGRATOR_PROXY_H_
#define OPENMM_BAOAB_LANGEVIN_INTEGRATOR_PROXY_H_ #define OPENMM_LANGEVIN_MIDDLE_INTEGRATOR_PROXY_H_
#include "openmm/serialization/XmlSerializer.h" #include "openmm/serialization/XmlSerializer.h"
namespace OpenMM { namespace OpenMM {
class BAOABLangevinIntegratorProxy : public SerializationProxy { class LangevinMiddleIntegratorProxy : public SerializationProxy {
public: public:
BAOABLangevinIntegratorProxy(); LangevinMiddleIntegratorProxy();
void serialize(const void* object, SerializationNode& node) const; void serialize(const void* object, SerializationNode& node) const;
void* deserialize(const SerializationNode& node) const; void* deserialize(const SerializationNode& node) const;
}; };
} }
#endif /*OPENMM_BAOAB_LANGEVIN_INTEGRATOR_PROXY_H_*/ #endif /*OPENMM_LANGEVIN_MIDDLE_INTEGRATOR_PROXY_H_*/
\ No newline at end of file \ No newline at end of file
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