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

Removed duplicate kernels, slightly modified API for Python compatibility.

parent 8d956093
......@@ -1107,46 +1107,7 @@ public:
* @param system the System this kernel will be applied to
* @param barostat the MonteCarloBarostat this kernel will be used for
*/
virtual void initialize(const System& system, const MonteCarloBarostat& barostat) = 0;
/**
* Attempt a Monte Carlo step, scaling particle positions (or cluster centers) by a specified value.
* This version scales the x, y, and z positions independently.
* This is called BEFORE the periodic box size is modified. It should begin by translating each particle
* or cluster into the first periodic box, so that coordinates will still be correct after the box size
* is changed.
*
* @param context the context in which to execute this kernel
* @param scaleX the scale factor by which to multiply particle x-coordinate
* @param scaleY the scale factor by which to multiply particle y-coordinate
* @param scaleZ the scale factor by which to multiply particle z-coordinate
*/
virtual void scaleCoordinates(ContextImpl& context, double scaleX, double scaleY, double scaleZ) = 0;
/**
* Reject the most recent Monte Carlo step, restoring the particle positions to where they were before
* scaleCoordinates() was last called.
*
* @param context the context in which to execute this kernel
*/
virtual void restoreCoordinates(ContextImpl& context) = 0;
};
/**
* This kernel is invoked by MonteCarloAnisotropicBarostat to adjust the periodic box volume
*/
class ApplyMonteCarloAnisotropicBarostatKernel : public KernelImpl {
public:
static std::string Name() {
return "ApplyMonteCarloAnisotropicBarostat";
}
ApplyMonteCarloAnisotropicBarostatKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
}
/**
* Initialize the kernel.
*
* @param system the System this kernel will be applied to
* @param barostat the MonteCarloAnisotropicBarostat this kernel will be used for
*/
virtual void initialize(const System& system, const MonteCarloAnisotropicBarostat& barostat) = 0;
virtual void initialize(const System& system, const Force& barostat) = 0;
/**
* Attempt a Monte Carlo step, scaling particle positions (or cluster centers) by a specified value.
* This version scales the x, y, and z positions independently.
......
......@@ -35,7 +35,6 @@
#include "Force.h"
#include <string>
#include "internal/windowsExport.h"
#include "Vec3.h"
namespace OpenMM {
......@@ -176,21 +175,23 @@ public:
/**
* Create a MonteCarloAnisotropicBarostat.
*
* @param defaultPressure 3-element vector specifying the default pressure acting on each axis (in bar)
* @param defaultPressureX The default pressure acting on the X-axis (in bar)
* @param defaultPressureY The default pressure acting on the Y-axis (in bar)
* @param defaultPressureZ The default pressure acting on the Z-axis (in bar)
* @param temperature the temperature at which the system is being maintained (in Kelvin)
* @param frequency the frequency at which Monte Carlo pressure changes should be attempted (in time steps)
* @param scaleX on/off switch for whether to scale the X axis
* @param scaleY on/off switch for whether to scale the Y axis
* @param scaleZ on/off switch for whether to scale the Z axis
*/
MonteCarloAnisotropicBarostat(Vec3 defaultPressure, double temperature, int frequency = 25, bool scaleX = 1, bool scaleY = 1, bool scaleZ = 1);
MonteCarloAnisotropicBarostat(double defaultPressureX, double defaultPressureY, double defaultPressureZ, double temperature, int frequency = 25, bool scaleX = 1, bool scaleY = 1, bool scaleZ = 1);
/**
* Get the default pressure acting on the X-axis (in bar).
*
* @return the default pressure acting on the system, measured in bar.
*/
double getDefaultPressureX() const {
return defaultPressure[0];
return defaultPressureX;
}
/**
* Get the default pressure acting on the Y-axis (in bar).
......@@ -198,7 +199,7 @@ public:
* @return the default pressure acting on the system, measured in bar.
*/
double getDefaultPressureY() const {
return defaultPressure[1];
return defaultPressureY;
}
/**
* Get the default pressure acting on the Z-axis (in bar).
......@@ -206,7 +207,7 @@ public:
* @return the default pressure acting on the system, measured in bar.
*/
double getDefaultPressureZ() const {
return defaultPressure[2];
return defaultPressureZ;
}
/**
* Get the true/false flag for scaling the X-axis.
......@@ -279,7 +280,7 @@ public:
protected:
ForceImpl* createImpl() const;
private:
Vec3 defaultPressure;
double defaultPressureX, defaultPressureY, defaultPressureZ;
double temperature;
bool scaleX, scaleY, scaleZ;
int frequency, randomNumberSeed;
......
......@@ -35,7 +35,6 @@
#include "ForceImpl.h"
#include "openmm/MonteCarloBarostat.h"
#include "openmm/Kernel.h"
#include "openmm/Vec3.h"
#include "sfmt/SFMT.h"
#include <string>
......
......@@ -44,8 +44,8 @@ ForceImpl* MonteCarloBarostat::createImpl() const {
return new MonteCarloBarostatImpl(*this);
}
MonteCarloAnisotropicBarostat::MonteCarloAnisotropicBarostat(Vec3 defaultPressure, double temperature, int frequency, bool scaleX, bool scaleY, bool scaleZ) :
defaultPressure(defaultPressure), temperature(temperature), frequency(frequency), scaleX(scaleX), scaleY(scaleY), scaleZ(scaleZ) {
MonteCarloAnisotropicBarostat::MonteCarloAnisotropicBarostat(double defaultPressureX, double defaultPressureY, double defaultPressureZ, double temperature, int frequency, bool scaleX, bool scaleY, bool scaleZ) :
defaultPressureX(defaultPressureX), defaultPressureY(defaultPressureY), defaultPressureZ(defaultPressureZ), temperature(temperature), frequency(frequency), scaleX(scaleX), scaleY(scaleY), scaleZ(scaleZ) {
setRandomNumberSeed((int) time(NULL));
}
......
......@@ -126,8 +126,8 @@ MonteCarloAnisotropicBarostatImpl::MonteCarloAnisotropicBarostatImpl(const Monte
}
void MonteCarloAnisotropicBarostatImpl::initialize(ContextImpl& context) {
kernel = context.getPlatform().createKernel(ApplyMonteCarloAnisotropicBarostatKernel::Name(), context);
kernel.getAs<ApplyMonteCarloAnisotropicBarostatKernel>().initialize(context.getSystem(), owner);
kernel = context.getPlatform().createKernel(ApplyMonteCarloBarostatKernel::Name(), context);
kernel.getAs<ApplyMonteCarloBarostatKernel>().initialize(context.getSystem(), owner);
Vec3 box[3];
context.getPeriodicBoxVectors(box[0], box[1], box[2]);
double volume = box[0][0]*box[1][1]*box[2][2];
......@@ -181,7 +181,7 @@ void MonteCarloAnisotropicBarostatImpl::updateContextState(ContextImpl& context)
for (int i=0; i<3; i++)
lengthScale[i] = 1.0;
lengthScale[axis] = newVolume/volume;
kernel.getAs<ApplyMonteCarloAnisotropicBarostatKernel>().scaleCoordinates(context, lengthScale[0], lengthScale[1], lengthScale[2]);
kernel.getAs<ApplyMonteCarloBarostatKernel>().scaleCoordinates(context, lengthScale[0], lengthScale[1], lengthScale[2]);
context.getOwner().setPeriodicBoxVectors(box[0]*lengthScale[0], box[1]*lengthScale[1], box[2]*lengthScale[2]);
// Compute the energy of the modified system.
......@@ -192,7 +192,7 @@ void MonteCarloAnisotropicBarostatImpl::updateContextState(ContextImpl& context)
if (w > 0 && genrand_real2(random) > std::exp(-w/kT)) {
// Reject the step.
kernel.getAs<ApplyMonteCarloAnisotropicBarostatKernel>().restoreCoordinates(context);
kernel.getAs<ApplyMonteCarloBarostatKernel>().restoreCoordinates(context);
context.getOwner().setPeriodicBoxVectors(box[0], box[1], box[2]);
volume = newVolume;
}
......@@ -223,7 +223,7 @@ std::map<std::string, double> MonteCarloAnisotropicBarostatImpl::getDefaultParam
std::vector<std::string> MonteCarloAnisotropicBarostatImpl::getKernelNames() {
std::vector<std::string> names;
names.push_back(ApplyMonteCarloAnisotropicBarostatKernel::Name());
names.push_back(ApplyMonteCarloBarostatKernel::Name());
return names;
}
......@@ -5310,7 +5310,7 @@ CudaApplyMonteCarloBarostatKernel::~CudaApplyMonteCarloBarostatKernel() {
delete moleculeStartIndex;
}
void CudaApplyMonteCarloBarostatKernel::initialize(const System& system, const MonteCarloBarostat& thermostat) {
void CudaApplyMonteCarloBarostatKernel::initialize(const System& system, const Force& thermostat) {
cu.setAsCurrent();
savedPositions = new CudaArray(cu, cu.getPaddedNumAtoms(), cu.getUseDoublePrecision() ? sizeof(double4) : sizeof(float4), "savedPositions");
CUmodule module = cu.createModule(CudaKernelSources::monteCarloBarostat);
......@@ -5372,13 +5372,6 @@ void CudaApplyMonteCarloBarostatKernel::restoreCoordinates(ContextImpl& context)
}
}
void CudaApplyMonteCarloAnisotropicBarostatKernel::initialize(const System& system, const MonteCarloAnisotropicBarostat& thermostat) {
cu.setAsCurrent();
savedPositions = new CudaArray(cu, cu.getPaddedNumAtoms(), cu.getUseDoublePrecision() ? sizeof(double4) : sizeof(float4), "savedPositions");
CUmodule module = cu.createModule(CudaKernelSources::monteCarloBarostat);
kernel = cu.getKernel(module, "scalePositions");
}
CudaRemoveCMMotionKernel::~CudaRemoveCMMotionKernel() {
cu.setAsCurrent();
if (cmMomentum != NULL)
......
......@@ -1254,7 +1254,7 @@ public:
* @param system the System this kernel will be applied to
* @param barostat the MonteCarloBarostat this kernel will be used for
*/
void initialize(const System& system, const MonteCarloBarostat& barostat);
void initialize(const System& system, const Force& barostat);
/**
* Attempt a Monte Carlo step, scaling particle positions (or cluster centers) by a specified value.
* This version scales the x, y, and z positions independently.
......@@ -1286,29 +1286,6 @@ private:
std::vector<int> lastAtomOrder;
};
/**
* This kernel is invoked by MonteCarloAnisotropicBarostat to adjust the periodic box volume
*/
class CudaApplyMonteCarloAnisotropicBarostatKernel : public CudaApplyMonteCarloBarostatKernel {
public:
/**
* Initialize the kernel.
*
* @param system the System this kernel will be applied to
* @param barostat the MonteCarloAnisotropicBarostat this kernel will be used for
*/
void initialize(const System& system, const MonteCarloAnisotropicBarostat& barostat);
private:
CudaContext& cu;
bool hasInitializedKernels;
int numMolecules;
CudaArray* savedPositions;
CudaArray* moleculeAtoms;
CudaArray* moleculeStartIndex;
CUfunction kernel;
std::vector<int> lastAtomOrder;
};
/**
* This kernel is invoked to remove center of mass motion from the system.
*/
......
......@@ -112,7 +112,7 @@ void testIdealGas(int aniso) {
}
MonteCarloBarostat* barostat = new MonteCarloBarostat(pressure, temp[0], frequency);
if (aniso)
MonteCarloAnisotropicBarostat* barostat = new MonteCarloAnisotropicBarostat(Vec3(pressure, pressure, pressure), temp[0], frequency);
MonteCarloAnisotropicBarostat* barostat = new MonteCarloAnisotropicBarostat(pressure, pressure, pressure, temp[0], frequency);
system.addForce(barostat);
// Test it for three different temperatures.
......@@ -256,7 +256,7 @@ void testWater(int aniso) {
system.addForce(nonbonded);
MonteCarloBarostat* barostat = new MonteCarloBarostat(pressure, temp, frequency);
if (aniso)
MonteCarloAnisotropicBarostat* barostat = new MonteCarloAnisotropicBarostat(Vec3(pressure, pressure, pressure), temp, frequency);
MonteCarloAnisotropicBarostat* barostat = new MonteCarloAnisotropicBarostat(pressure, pressure, pressure, temp, frequency);
system.addForce(barostat);
// Simulate it and see if the density matches the expected value (1 g/mL).
......
......@@ -5536,7 +5536,7 @@ OpenCLApplyMonteCarloBarostatKernel::~OpenCLApplyMonteCarloBarostatKernel() {
delete moleculeStartIndex;
}
void OpenCLApplyMonteCarloBarostatKernel::initialize(const System& system, const MonteCarloBarostat& thermostat) {
void OpenCLApplyMonteCarloBarostatKernel::initialize(const System& system, const Force& thermostat) {
savedPositions = OpenCLArray::create<mm_float4>(cl, cl.getPaddedNumAtoms(), "savedPositions");
cl::Program program = cl.createProgram(OpenCLKernelSources::monteCarloBarostat);
kernel = cl::Kernel(program, "scalePositions");
......
......@@ -1268,7 +1268,7 @@ public:
* @param system the System this kernel will be applied to
* @param barostat the MonteCarloBarostat this kernel will be used for
*/
void initialize(const System& system, const MonteCarloBarostat& barostat);
void initialize(const System& system, const Force& barostat);
/**
* Attempt a Monte Carlo step, scaling particle positions (or cluster centers) by a specified value.
* This version scales the x, y, and z positions independently.
......@@ -1300,29 +1300,6 @@ private:
std::vector<int> lastAtomOrder;
};
/**
* This kernel is invoked by MonteCarloAnisotropicBarostat to adjust the periodic box volume
*/
class OpenCLApplyMonteCarloAnisotropicBarostatKernel : public OpenCLApplyMonteCarloBarostatKernel {
public:
/**
* Initialize the kernel.
*
* @param system the System this kernel will be applied to
* @param barostat the MonteCarloAnisotropicBarostat this kernel will be used for
*/
void initialize(const System& system, const MonteCarloAnisotropicBarostat& barostat);
private:
OpenCLContext& cl;
bool hasInitializedKernels;
int numMolecules;
OpenCLArray* savedPositions;
OpenCLArray* moleculeAtoms;
OpenCLArray* moleculeStartIndex;
cl::Kernel kernel;
std::vector<int> lastAtomOrder;
};
/**
* This kernel is invoked to remove center of mass motion from the system.
*/
......
......@@ -112,7 +112,7 @@ void testIdealGas(int aniso) {
}
MonteCarloBarostat* barostat = new MonteCarloBarostat(pressure, temp[0], frequency);
if (aniso)
MonteCarloAnisotropicBarostat* barostat = new MonteCarloAnisotropicBarostat(Vec3(pressure, pressure, pressure), temp[0], frequency);
MonteCarloAnisotropicBarostat* barostat = new MonteCarloAnisotropicBarostat(pressure, pressure, pressure, temp[0], frequency);
system.addForce(barostat);
// Test it for three different temperatures.
......@@ -259,7 +259,7 @@ void testWater(int aniso) {
system.addForce(nonbonded);
MonteCarloBarostat* barostat = new MonteCarloBarostat(pressure, temp, frequency);
if (aniso)
MonteCarloAnisotropicBarostat* barostat = new MonteCarloAnisotropicBarostat(Vec3(pressure, pressure, pressure), temp, frequency);
MonteCarloAnisotropicBarostat* barostat = new MonteCarloAnisotropicBarostat(pressure, pressure, pressure, temp, frequency);
system.addForce(barostat);
// Simulate it and see if the density matches the expected value (1 g/mL).
......
......@@ -2140,7 +2140,7 @@ ReferenceApplyMonteCarloBarostatKernel::~ReferenceApplyMonteCarloBarostatKernel(
delete barostat;
}
void ReferenceApplyMonteCarloBarostatKernel::initialize(const System& system, const MonteCarloBarostat& barostat) {
void ReferenceApplyMonteCarloBarostatKernel::initialize(const System& system, const Force& barostat) {
}
void ReferenceApplyMonteCarloBarostatKernel::scaleCoordinates(ContextImpl& context, double scaleX, double scaleY, double scaleZ) {
......@@ -2156,9 +2156,6 @@ void ReferenceApplyMonteCarloBarostatKernel::restoreCoordinates(ContextImpl& con
barostat->restorePositions(posData);
}
void ReferenceApplyMonteCarloAnisotropicBarostatKernel::initialize(const System& system, const MonteCarloAnisotropicBarostat& barostat) {
}
void ReferenceRemoveCMMotionKernel::initialize(const System& system, const CMMotionRemover& force) {
frequency = force.getFrequency();
masses.resize(system.getNumParticles());
......
......@@ -1182,7 +1182,7 @@ public:
* @param system the System this kernel will be applied to
* @param barostat the MonteCarloBarostat this kernel will be used for
*/
void initialize(const System& system, const MonteCarloBarostat& barostat);
void initialize(const System& system, const Force& barostat);
/**
* Attempt a Monte Carlo step, scaling particle positions (or cluster centers) by a specified value.
* This version scales the x, y, and z positions independently.
......@@ -1207,22 +1207,6 @@ private:
ReferenceMonteCarloBarostat* barostat;
};
/**
* This kernel is invoked by MonteCarloAnisotropicBarostat to adjust the periodic box volume
*/
class ReferenceApplyMonteCarloAnisotropicBarostatKernel : public ReferenceApplyMonteCarloBarostatKernel{
public:
/**
* Initialize the kernel.
*
* @param system the System this kernel will be applied to
* @param barostat the MonteCarloAnisotropicBarostat this kernel will be used for
*/
void initialize(const System& system, const MonteCarloAnisotropicBarostat& barostat);
private:
ReferenceMonteCarloBarostat* barostat;
};
/**
* This kernel is invoked to remove center of mass motion from the system.
*/
......
......@@ -112,7 +112,7 @@ void testIdealGas(int aniso) {
}
MonteCarloBarostat* barostat = new MonteCarloBarostat(pressure, temp[0], frequency);
if (aniso)
MonteCarloAnisotropicBarostat* barostat = new MonteCarloAnisotropicBarostat(Vec3(pressure, pressure, pressure), temp[0], frequency);
MonteCarloAnisotropicBarostat* barostat = new MonteCarloAnisotropicBarostat(pressure, pressure, pressure, temp[0], frequency);
system.addForce(barostat);
// Test it for three different temperatures.
......
......@@ -32,7 +32,6 @@ SKIP_METHODS = [('State',),
('ApplyAndersenThermostatKernel',),
('ApplyConstraintsKernel',),
('ApplyMonteCarloBarostatKernel',),
('ApplyMonteCarloAnisotropicBarostatKernel',),
('BondInfo',),
('BondParameterInfo',),
('CalcAmoebaGeneralizedKirkwoodForceKernel',),
......
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