Commit 3b6925ae authored by Andy Simmonett's avatar Andy Simmonett Committed by GitHub
Browse files

Merge pull request #1 from peastman/ljpme

Cleanup to LJ PME code
parents 5a8a8aa9 f7a102fb
...@@ -208,4 +208,5 @@ ExpressionTreeNode CustomCompoundBondForceImpl::replaceFunctions(const Expressio ...@@ -208,4 +208,5 @@ ExpressionTreeNode CustomCompoundBondForceImpl::replaceFunctions(const Expressio
void CustomCompoundBondForceImpl::updateParametersInContext(ContextImpl& context) { void CustomCompoundBondForceImpl::updateParametersInContext(ContextImpl& context) {
kernel.getAs<CalcCustomCompoundBondForceKernel>().copyParametersToContext(context, owner); kernel.getAs<CalcCustomCompoundBondForceKernel>().copyParametersToContext(context, owner);
context.systemChanged();
} }
...@@ -97,4 +97,5 @@ map<string, double> CustomExternalForceImpl::getDefaultParameters() { ...@@ -97,4 +97,5 @@ map<string, double> CustomExternalForceImpl::getDefaultParameters() {
void CustomExternalForceImpl::updateParametersInContext(ContextImpl& context) { void CustomExternalForceImpl::updateParametersInContext(ContextImpl& context) {
kernel.getAs<CalcCustomExternalForceKernel>().copyParametersToContext(context, owner); kernel.getAs<CalcCustomExternalForceKernel>().copyParametersToContext(context, owner);
context.systemChanged();
} }
...@@ -126,4 +126,5 @@ map<string, double> CustomGBForceImpl::getDefaultParameters() { ...@@ -126,4 +126,5 @@ map<string, double> CustomGBForceImpl::getDefaultParameters() {
void CustomGBForceImpl::updateParametersInContext(ContextImpl& context) { void CustomGBForceImpl::updateParametersInContext(ContextImpl& context) {
kernel.getAs<CalcCustomGBForceKernel>().copyParametersToContext(context, owner); kernel.getAs<CalcCustomGBForceKernel>().copyParametersToContext(context, owner);
context.systemChanged();
} }
...@@ -278,4 +278,5 @@ ExpressionTreeNode CustomHbondForceImpl::replaceFunctions(const ExpressionTreeNo ...@@ -278,4 +278,5 @@ ExpressionTreeNode CustomHbondForceImpl::replaceFunctions(const ExpressionTreeNo
void CustomHbondForceImpl::updateParametersInContext(ContextImpl& context) { void CustomHbondForceImpl::updateParametersInContext(ContextImpl& context) {
kernel.getAs<CalcCustomHbondForceKernel>().copyParametersToContext(context, owner); kernel.getAs<CalcCustomHbondForceKernel>().copyParametersToContext(context, owner);
context.systemChanged();
} }
...@@ -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) 2011-2014 Stanford University and the Authors. * * Portions copyright (c) 2011-2016 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -63,6 +63,15 @@ void CustomIntegrator::initialize(ContextImpl& contextRef) { ...@@ -63,6 +63,15 @@ void CustomIntegrator::initialize(ContextImpl& contextRef) {
if (contextRef.getParameters().find(name) != contextRef.getParameters().end()) if (contextRef.getParameters().find(name) != contextRef.getParameters().end())
throw OpenMMException("The Integrator defines a variable with the same name as a Context parameter: "+name); throw OpenMMException("The Integrator defines a variable with the same name as a Context parameter: "+name);
} }
set<std::string> globalTargets;
globalTargets.insert(globalNames.begin(), globalNames.end());
globalTargets.insert("dt");
for (map<string, double>::const_iterator iter = contextRef.getParameters().begin(); iter != contextRef.getParameters().end(); ++iter)
globalTargets.insert(iter->first);
for (int i = 0; i < computations.size(); i++) {
if (computations[i].type == ComputeGlobal && globalTargets.find(computations[i].variable) == globalTargets.end())
throw OpenMMException("Unknown global variable: "+computations[i].variable);
}
context = &contextRef; context = &contextRef;
owner = &contextRef.getOwner(); owner = &contextRef.getOwner();
kernel = context->getPlatform().createKernel(IntegrateCustomStepKernel::Name(), contextRef); kernel = context->getPlatform().createKernel(IntegrateCustomStepKernel::Name(), contextRef);
......
...@@ -240,6 +240,7 @@ ExpressionTreeNode CustomManyParticleForceImpl::replaceFunctions(const Expressio ...@@ -240,6 +240,7 @@ ExpressionTreeNode CustomManyParticleForceImpl::replaceFunctions(const Expressio
void CustomManyParticleForceImpl::updateParametersInContext(ContextImpl& context) { void CustomManyParticleForceImpl::updateParametersInContext(ContextImpl& context) {
kernel.getAs<CalcCustomManyParticleForceKernel>().copyParametersToContext(context, owner); kernel.getAs<CalcCustomManyParticleForceKernel>().copyParametersToContext(context, owner);
context.systemChanged();
} }
void CustomManyParticleForceImpl::buildFilterArrays(const CustomManyParticleForce& force, int& numTypes, vector<int>& particleTypes, vector<int>& orderIndex, vector<vector<int> >& particleOrder) { void CustomManyParticleForceImpl::buildFilterArrays(const CustomManyParticleForce& force, int& numTypes, vector<int>& particleTypes, vector<int>& orderIndex, vector<vector<int> >& particleOrder) {
......
...@@ -155,6 +155,7 @@ map<string, double> CustomNonbondedForceImpl::getDefaultParameters() { ...@@ -155,6 +155,7 @@ map<string, double> CustomNonbondedForceImpl::getDefaultParameters() {
void CustomNonbondedForceImpl::updateParametersInContext(ContextImpl& context) { void CustomNonbondedForceImpl::updateParametersInContext(ContextImpl& context) {
kernel.getAs<CalcCustomNonbondedForceKernel>().copyParametersToContext(context, owner); kernel.getAs<CalcCustomNonbondedForceKernel>().copyParametersToContext(context, owner);
context.systemChanged();
} }
void CustomNonbondedForceImpl::calcLongRangeCorrection(const CustomNonbondedForce& force, const Context& context, double& coefficient, vector<double>& derivatives) { void CustomNonbondedForceImpl::calcLongRangeCorrection(const CustomNonbondedForce& force, const Context& context, double& coefficient, vector<double>& derivatives) {
......
...@@ -115,4 +115,5 @@ map<string, double> CustomTorsionForceImpl::getDefaultParameters() { ...@@ -115,4 +115,5 @@ map<string, double> CustomTorsionForceImpl::getDefaultParameters() {
void CustomTorsionForceImpl::updateParametersInContext(ContextImpl& context) { void CustomTorsionForceImpl::updateParametersInContext(ContextImpl& context) {
kernel.getAs<CalcCustomTorsionForceKernel>().copyParametersToContext(context, owner); kernel.getAs<CalcCustomTorsionForceKernel>().copyParametersToContext(context, owner);
context.systemChanged();
} }
...@@ -69,4 +69,5 @@ std::vector<std::string> GBSAOBCForceImpl::getKernelNames() { ...@@ -69,4 +69,5 @@ std::vector<std::string> GBSAOBCForceImpl::getKernelNames() {
void GBSAOBCForceImpl::updateParametersInContext(ContextImpl& context) { void GBSAOBCForceImpl::updateParametersInContext(ContextImpl& context) {
kernel.getAs<CalcGBSAOBCForceKernel>().copyParametersToContext(context, owner); kernel.getAs<CalcGBSAOBCForceKernel>().copyParametersToContext(context, owner);
context.systemChanged();
} }
...@@ -126,4 +126,5 @@ std::vector<std::string> GayBerneForceImpl::getKernelNames() { ...@@ -126,4 +126,5 @@ std::vector<std::string> GayBerneForceImpl::getKernelNames() {
void GayBerneForceImpl::updateParametersInContext(ContextImpl& context) { void GayBerneForceImpl::updateParametersInContext(ContextImpl& context) {
kernel.getAs<CalcGayBerneForceKernel>().copyParametersToContext(context, owner); kernel.getAs<CalcGayBerneForceKernel>().copyParametersToContext(context, owner);
context.systemChanged();
} }
...@@ -63,4 +63,5 @@ std::vector<std::string> HarmonicAngleForceImpl::getKernelNames() { ...@@ -63,4 +63,5 @@ std::vector<std::string> HarmonicAngleForceImpl::getKernelNames() {
void HarmonicAngleForceImpl::updateParametersInContext(ContextImpl& context) { void HarmonicAngleForceImpl::updateParametersInContext(ContextImpl& context) {
kernel.getAs<CalcHarmonicAngleForceKernel>().copyParametersToContext(context, owner); kernel.getAs<CalcHarmonicAngleForceKernel>().copyParametersToContext(context, owner);
context.systemChanged();
} }
...@@ -73,4 +73,5 @@ vector<pair<int, int> > HarmonicBondForceImpl::getBondedParticles() const { ...@@ -73,4 +73,5 @@ vector<pair<int, int> > HarmonicBondForceImpl::getBondedParticles() const {
void HarmonicBondForceImpl::updateParametersInContext(ContextImpl& context) { void HarmonicBondForceImpl::updateParametersInContext(ContextImpl& context) {
kernel.getAs<CalcHarmonicBondForceKernel>().copyParametersToContext(context, owner); kernel.getAs<CalcHarmonicBondForceKernel>().copyParametersToContext(context, owner);
context.systemChanged();
} }
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "openmm/internal/OSRngSeed.h" #include "openmm/internal/OSRngSeed.h"
#include "openmm/Context.h" #include "openmm/Context.h"
#include "openmm/kernels.h" #include "openmm/kernels.h"
#include "openmm/OpenMMException.h"
#include <cmath> #include <cmath>
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
...@@ -51,6 +52,8 @@ MonteCarloAnisotropicBarostatImpl::MonteCarloAnisotropicBarostatImpl(const Monte ...@@ -51,6 +52,8 @@ MonteCarloAnisotropicBarostatImpl::MonteCarloAnisotropicBarostatImpl(const Monte
} }
void MonteCarloAnisotropicBarostatImpl::initialize(ContextImpl& context) { void MonteCarloAnisotropicBarostatImpl::initialize(ContextImpl& context) {
if (!context.getSystem().usesPeriodicBoundaryConditions())
throw OpenMMException("A barostat cannot be used with a non-periodic system");
kernel = context.getPlatform().createKernel(ApplyMonteCarloBarostatKernel::Name(), context); kernel = context.getPlatform().createKernel(ApplyMonteCarloBarostatKernel::Name(), context);
kernel.getAs<ApplyMonteCarloBarostatKernel>().initialize(context.getSystem(), owner); kernel.getAs<ApplyMonteCarloBarostatKernel>().initialize(context.getSystem(), owner);
Vec3 box[3]; Vec3 box[3];
......
...@@ -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) 2010 Stanford University and the Authors. * * Portions copyright (c) 2010-2016 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "openmm/internal/OSRngSeed.h" #include "openmm/internal/OSRngSeed.h"
#include "openmm/Context.h" #include "openmm/Context.h"
#include "openmm/kernels.h" #include "openmm/kernels.h"
#include "openmm/OpenMMException.h"
#include <cmath> #include <cmath>
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
...@@ -51,6 +52,8 @@ MonteCarloBarostatImpl::MonteCarloBarostatImpl(const MonteCarloBarostat& owner) ...@@ -51,6 +52,8 @@ MonteCarloBarostatImpl::MonteCarloBarostatImpl(const MonteCarloBarostat& owner)
} }
void MonteCarloBarostatImpl::initialize(ContextImpl& context) { void MonteCarloBarostatImpl::initialize(ContextImpl& context) {
if (!context.getSystem().usesPeriodicBoundaryConditions())
throw OpenMMException("A barostat cannot be used with a non-periodic system");
kernel = context.getPlatform().createKernel(ApplyMonteCarloBarostatKernel::Name(), context); kernel = context.getPlatform().createKernel(ApplyMonteCarloBarostatKernel::Name(), context);
kernel.getAs<ApplyMonteCarloBarostatKernel>().initialize(context.getSystem(), owner); kernel.getAs<ApplyMonteCarloBarostatKernel>().initialize(context.getSystem(), owner);
Vec3 box[3]; Vec3 box[3];
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "openmm/internal/OSRngSeed.h" #include "openmm/internal/OSRngSeed.h"
#include "openmm/Context.h" #include "openmm/Context.h"
#include "openmm/kernels.h" #include "openmm/kernels.h"
#include "openmm/OpenMMException.h"
#include <cmath> #include <cmath>
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
...@@ -51,6 +52,8 @@ MonteCarloMembraneBarostatImpl::MonteCarloMembraneBarostatImpl(const MonteCarloM ...@@ -51,6 +52,8 @@ MonteCarloMembraneBarostatImpl::MonteCarloMembraneBarostatImpl(const MonteCarloM
} }
void MonteCarloMembraneBarostatImpl::initialize(ContextImpl& context) { void MonteCarloMembraneBarostatImpl::initialize(ContextImpl& context) {
if (!context.getSystem().usesPeriodicBoundaryConditions())
throw OpenMMException("A barostat cannot be used with a non-periodic system");
kernel = context.getPlatform().createKernel(ApplyMonteCarloBarostatKernel::Name(), context); kernel = context.getPlatform().createKernel(ApplyMonteCarloBarostatKernel::Name(), context);
kernel.getAs<ApplyMonteCarloBarostatKernel>().initialize(context.getSystem(), owner); kernel.getAs<ApplyMonteCarloBarostatKernel>().initialize(context.getSystem(), owner);
Vec3 box[3]; Vec3 box[3];
......
...@@ -106,6 +106,13 @@ void NonbondedForce::getPMEParameters(double& alpha, int& nx, int& ny, int& nz) ...@@ -106,6 +106,13 @@ void NonbondedForce::getPMEParameters(double& alpha, int& nx, int& ny, int& nz)
nz = this->nz; nz = this->nz;
} }
void NonbondedForce::getLJPMEParameters(double& alpha, int& nx, int& ny, int& nz) const {
alpha = this->dalpha;
nx = this->dnx;
ny = this->dny;
nz = this->dnz;
}
void NonbondedForce::setPMEParameters(double alpha, int nx, int ny, int nz) { void NonbondedForce::setPMEParameters(double alpha, int nx, int ny, int nz) {
this->alpha = alpha; this->alpha = alpha;
this->nx = nx; this->nx = nx;
...@@ -113,10 +120,21 @@ void NonbondedForce::setPMEParameters(double alpha, int nx, int ny, int nz) { ...@@ -113,10 +120,21 @@ void NonbondedForce::setPMEParameters(double alpha, int nx, int ny, int nz) {
this->nz = nz; this->nz = nz;
} }
void NonbondedForce::setLJPMEParameters(double alpha, int nx, int ny, int nz) {
this->dalpha = alpha;
this->dnx = nx;
this->dny = ny;
this->dnz = nz;
}
void NonbondedForce::getPMEParametersInContext(const Context& context, double& alpha, int& nx, int& ny, int& nz) const { void NonbondedForce::getPMEParametersInContext(const Context& context, double& alpha, int& nx, int& ny, int& nz) const {
dynamic_cast<const NonbondedForceImpl&>(getImplInContext(context)).getPMEParameters(alpha, nx, ny, nz); dynamic_cast<const NonbondedForceImpl&>(getImplInContext(context)).getPMEParameters(alpha, nx, ny, nz);
} }
void NonbondedForce::getLJPMEParametersInContext(const Context& context, double& alpha, int& nx, int& ny, int& nz) const {
dynamic_cast<const NonbondedForceImpl&>(getImplInContext(context)).getLJPMEParameters(alpha, nx, ny, nz);
}
int NonbondedForce::addParticle(double charge, double sigma, double epsilon) { int NonbondedForce::addParticle(double charge, double sigma, double epsilon) {
particles.push_back(ParticleInfo(charge, sigma, epsilon)); particles.push_back(ParticleInfo(charge, sigma, epsilon));
return particles.size()-1; return particles.size()-1;
......
...@@ -151,7 +151,10 @@ void NonbondedForceImpl::calcEwaldParameters(const System& system, const Nonbond ...@@ -151,7 +151,10 @@ void NonbondedForceImpl::calcEwaldParameters(const System& system, const Nonbond
kmaxz++; kmaxz++;
} }
void NonbondedForceImpl::calcPMEParameters(const System& system, const NonbondedForce& force, double& alpha, int& xsize, int& ysize, int& zsize) { void NonbondedForceImpl::calcPMEParameters(const System& system, const NonbondedForce& force, double& alpha, int& xsize, int& ysize, int& zsize, bool lj) {
if (lj)
force.getLJPMEParameters(alpha, xsize, ysize, zsize);
else
force.getPMEParameters(alpha, xsize, ysize, zsize); force.getPMEParameters(alpha, xsize, ysize, zsize);
if (alpha == 0.0) { if (alpha == 0.0) {
Vec3 boxVectors[3]; Vec3 boxVectors[3];
...@@ -277,8 +280,13 @@ double NonbondedForceImpl::calcDispersionCorrection(const System& system, const ...@@ -277,8 +280,13 @@ double NonbondedForceImpl::calcDispersionCorrection(const System& system, const
void NonbondedForceImpl::updateParametersInContext(ContextImpl& context) { void NonbondedForceImpl::updateParametersInContext(ContextImpl& context) {
kernel.getAs<CalcNonbondedForceKernel>().copyParametersToContext(context, owner); kernel.getAs<CalcNonbondedForceKernel>().copyParametersToContext(context, owner);
context.systemChanged();
} }
void NonbondedForceImpl::getPMEParameters(double& alpha, int& nx, int& ny, int& nz) const { void NonbondedForceImpl::getPMEParameters(double& alpha, int& nx, int& ny, int& nz) const {
kernel.getAs<CalcNonbondedForceKernel>().getPMEParameters(alpha, nx, ny, nz); kernel.getAs<CalcNonbondedForceKernel>().getPMEParameters(alpha, nx, ny, nz);
} }
void NonbondedForceImpl::getLJPMEParameters(double& alpha, int& nx, int& ny, int& nz) const {
kernel.getAs<CalcNonbondedForceKernel>().getLJPMEParameters(alpha, nx, ny, nz);
}
...@@ -63,4 +63,5 @@ std::vector<std::string> PeriodicTorsionForceImpl::getKernelNames() { ...@@ -63,4 +63,5 @@ std::vector<std::string> PeriodicTorsionForceImpl::getKernelNames() {
void PeriodicTorsionForceImpl::updateParametersInContext(ContextImpl& context) { void PeriodicTorsionForceImpl::updateParametersInContext(ContextImpl& context) {
kernel.getAs<CalcPeriodicTorsionForceKernel>().copyParametersToContext(context, owner); kernel.getAs<CalcPeriodicTorsionForceKernel>().copyParametersToContext(context, owner);
context.systemChanged();
} }
...@@ -63,4 +63,5 @@ std::vector<std::string> RBTorsionForceImpl::getKernelNames() { ...@@ -63,4 +63,5 @@ std::vector<std::string> RBTorsionForceImpl::getKernelNames() {
void RBTorsionForceImpl::updateParametersInContext(ContextImpl& context) { void RBTorsionForceImpl::updateParametersInContext(ContextImpl& context) {
kernel.getAs<CalcRBTorsionForceKernel>().copyParametersToContext(context, owner); kernel.getAs<CalcRBTorsionForceKernel>().copyParametersToContext(context, owner);
context.systemChanged();
} }
/* Portions copyright (c) 2009-2014 Stanford University and Simbios. /* Portions copyright (c) 2009-2016 Stanford University and Simbios.
* Contributors: Peter Eastman * Contributors: Peter Eastman
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
...@@ -254,15 +254,15 @@ public: ...@@ -254,15 +254,15 @@ public:
std::vector<std::vector<Lepton::CompiledExpression> > valueDerivExpressions; std::vector<std::vector<Lepton::CompiledExpression> > valueDerivExpressions;
std::vector<std::vector<Lepton::CompiledExpression> > valueGradientExpressions; std::vector<std::vector<Lepton::CompiledExpression> > valueGradientExpressions;
std::vector<std::vector<Lepton::CompiledExpression> > valueParamDerivExpressions; std::vector<std::vector<Lepton::CompiledExpression> > valueParamDerivExpressions;
std::vector<int> valueIndex; std::vector<double> value;
std::vector<Lepton::CompiledExpression> energyExpressions; std::vector<Lepton::CompiledExpression> energyExpressions;
std::vector<std::vector<Lepton::CompiledExpression> > energyDerivExpressions; std::vector<std::vector<Lepton::CompiledExpression> > energyDerivExpressions;
std::vector<std::vector<Lepton::CompiledExpression> > energyGradientExpressions; std::vector<std::vector<Lepton::CompiledExpression> > energyGradientExpressions;
std::vector<std::vector<Lepton::CompiledExpression> > energyParamDerivExpressions; std::vector<std::vector<Lepton::CompiledExpression> > energyParamDerivExpressions;
std::vector<int> paramIndex; std::vector<double> param;
std::vector<int> particleParamIndex; std::vector<double> particleParam;
std::vector<int> particleValueIndex; std::vector<double> particleValue;
int xindex, yindex, zindex, rindex; double x, y, z, r;
int firstAtom, lastAtom; int firstAtom, lastAtom;
// Workspace vectors // Workspace vectors
std::vector<float> value0, dVdR1, dVdR2, dVdX, dVdY, dVdZ; std::vector<float> value0, dVdR1, dVdR2, dVdX, dVdY, dVdZ;
......
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