Commit 18295108 authored by peastman's avatar peastman
Browse files

Merge changes from main branch

parents e6101f68 8d7234e5
......@@ -49,7 +49,7 @@ public:
const CMMotionRemover& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context);
void updateContextState(ContextImpl& context, bool& forcesInvalid);
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups) {
// This force doesn't apply forces to particles.
return 0.0;
......
......@@ -55,7 +55,8 @@ public:
/**
* Create an ContextImpl for a Context;
*/
ContextImpl(Context& owner, const System& system, Integrator& integrator, Platform* platform, const std::map<std::string, std::string>& properties);
ContextImpl(Context& owner, const System& system, Integrator& integrator, Platform* platform, const std::map<std::string, std::string>& properties,
ContextImpl* originalContext=NULL);
~ContextImpl();
/**
* Get the Context for which this is the implementation.
......@@ -197,8 +198,11 @@ public:
double calcForcesAndEnergy(bool includeForces, bool includeEnergy, int groups=0xFFFFFFFF);
/**
* Get the set of force group flags that were passed to the most recent call to calcForcesAndEnergy().
*
* Note that this returns a reference, so it's possible to modify it. Be very very cautious about
* doing that! Only do it if you're also modifying forces stored inside the context.
*/
int getLastForceGroups() const;
int& getLastForceGroups();
/**
* Calculate the kinetic energy of the system (in kJ/mol).
*/
......@@ -206,8 +210,11 @@ public:
/**
* This should be called at the start of each time step. It calls updateContextState() on each
* ForceImpl in the system, allowing them to modify the values of state variables.
*
* @return true if the state was modified in any way that would cause the forces on particles
* to change, false otherwise
*/
void updateContextState();
bool updateContextState();
/**
* Get the list of ForceImpls belonging to this ContextImpl.
*/
......@@ -261,8 +268,18 @@ public:
* you should never call it. It is exposed here because the same logic is useful to other classes too.
*/
static std::vector<std::vector<int> > findMolecules(int numParticles, std::vector<std::vector<int> >& particleBonds);
/**
* Create a new Context based on this one. The new context will use the same Platform, device, and property
* values as this one. With the CUDA and OpenCL platforms, it also shares the same GPU context, allowing data
* to be transferred between them without leaving the GPU.
*
* This method exists for very specialized purposes. If you aren't certain whether you should use it, that probably
* means you shouldn't.
*/
Context* createLinkedContext(const System& system, Integrator& integrator);
private:
friend class Context;
void initialize();
Context& owner;
const System& system;
Integrator& integrator;
......
......@@ -53,7 +53,7 @@ public:
const CustomAngleForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly.
}
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......
......@@ -53,7 +53,7 @@ public:
const CustomBondForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly.
}
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......
#ifndef OPENMM_CUSTOMCVFORCEIMPL_H_
#define OPENMM_CUSTOMCVFORCEIMPL_H_
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2017 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "ForceImpl.h"
#include "openmm/Context.h"
#include "openmm/CustomCVForce.h"
#include "openmm/Kernel.h"
#include "openmm/System.h"
#include "openmm/VerletIntegrator.h"
#include <map>
#include <string>
#include <vector>
namespace OpenMM {
/**
* This is the internal implementation of CustomCVForce.
*/
class OPENMM_EXPORT CustomCVForceImpl : public ForceImpl {
public:
CustomCVForceImpl(const CustomCVForce& owner);
~CustomCVForceImpl();
void initialize(ContextImpl& context);
const CustomCVForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly.
}
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
std::map<std::string, double> getDefaultParameters();
std::vector<std::string> getKernelNames();
void getCollectiveVariableValues(ContextImpl& context, std::vector<double>& values);
Context& getInnerContext();
private:
const CustomCVForce& owner;
Kernel kernel;
System innerSystem;
VerletIntegrator innerIntegrator;
Context* innerContext;
};
} // namespace OpenMM
#endif /*OPENMM_CUSTOMCVFORCEIMPL_H_*/
......@@ -58,7 +58,7 @@ public:
const CustomCentroidBondForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly.
}
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......
......@@ -57,7 +57,7 @@ public:
const CustomCompoundBondForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly.
}
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......
......@@ -53,7 +53,7 @@ public:
const CustomExternalForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly.
}
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......
......@@ -53,7 +53,7 @@ public:
const CustomGBForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly.
}
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......
......@@ -57,7 +57,7 @@ public:
const CustomHbondForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly.
}
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......
......@@ -73,7 +73,7 @@ public:
*/
static void analyzeComputations(const ContextImpl& context, const CustomIntegrator& integrator, std::vector<std::vector<Lepton::ParsedExpression> >& expressions,
std::vector<Comparison>& comparisons, std::vector<int>& blockEnd, std::vector<bool>& invalidatesForces, std::vector<bool>& needsForces,
std::vector<bool>& needsEnergy, std::vector<bool>& computeBoth, std::vector<int>& forceGroup);
std::vector<bool>& needsEnergy, std::vector<bool>& computeBoth, std::vector<int>& forceGroup, const std::map<std::string, Lepton::CustomFunction*>& functions);
/**
* Determine whether an expression involves a particular variable.
*/
......
......@@ -57,7 +57,7 @@ public:
const CustomManyParticleForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly.
}
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......
......@@ -54,7 +54,7 @@ public:
const CustomNonbondedForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly.
}
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......@@ -69,7 +69,7 @@ public:
static void calcLongRangeCorrection(const CustomNonbondedForce& force, const Context& context, double& coefficient, std::vector<double>& derivatives);
private:
static double integrateInteraction(Lepton::CompiledExpression& expression, const std::vector<double>& params1, const std::vector<double>& params2,
const CustomNonbondedForce& force, const Context& context);
const CustomNonbondedForce& force, const Context& context, const std::vector<std::string>& paramNames);
const CustomNonbondedForce& owner;
Kernel kernel;
};
......
......@@ -53,7 +53,7 @@ public:
const CustomTorsionForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly.
}
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......
......@@ -32,6 +32,7 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/Context.h"
#include "openmm/internal/windowsExport.h"
#include <map>
#include <string>
......@@ -72,9 +73,16 @@ public:
* to modify the state variables (positions, velocities, and parameters) stored in the
* Context in arbitrary ways before integration is performed.
*
* @param context the context in which the system is being simulated
* @param context the context in which the system is being simulated
* @param forcesInvalid if the state was modified in any way that might cause previously
* calculated forces to no longer be valid (such as modifying
* positions or parameters), the method should set this to true.
*/
virtual void updateContextState(ContextImpl& context, bool& forcesInvalid);
/**
* @deprecated This version exists for backward compatibility. Subclasses should implement the other version instead.
*/
virtual void updateContextState(ContextImpl& context) = 0;
virtual void updateContextState(ContextImpl& context);
/**
* Calculate the force on each particle generated by this ForceImpl and/or this ForceImpl's
* contribution to the potential energy of the system.
......@@ -104,6 +112,13 @@ public:
virtual std::vector<std::pair<int, int> > getBondedParticles() const {
return std::vector<std::pair<int, int> >(0);
}
protected:
/**
* Get the ContextImpl corresponding to a Context.
*/
ContextImpl& getContextImpl(Context& context) {
return context.getImpl();
}
};
} // namespace OpenMM
......
......@@ -50,7 +50,7 @@ public:
const GBSAOBCForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly.
}
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......
......@@ -53,7 +53,7 @@ public:
const HarmonicAngleForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly.
}
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......
......@@ -53,7 +53,7 @@ public:
const HarmonicBondForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly.
}
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......
......@@ -51,7 +51,7 @@ public:
const MonteCarloBarostat& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context);
void updateContextState(ContextImpl& context, bool& forcesInvalid);
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups) {
// This force doesn't apply forces to particles.
return 0.0;
......
......@@ -55,7 +55,7 @@ public:
const NonbondedForce& getOwner() const {
return owner;
}
void updateContextState(ContextImpl& context) {
void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly.
}
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......
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