"openmmapi/vscode:/vscode.git/clone" did not exist on "1902a1373a7072fb72e7ca3bdb8def4eae592fa3"
Commit 18295108 authored by peastman's avatar peastman
Browse files

Merge changes from main branch

parents e6101f68 8d7234e5
...@@ -49,7 +49,7 @@ public: ...@@ -49,7 +49,7 @@ public:
const CMMotionRemover& getOwner() const { const CMMotionRemover& getOwner() const {
return owner; return owner;
} }
void updateContextState(ContextImpl& context); void updateContextState(ContextImpl& context, bool& forcesInvalid);
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups) { double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups) {
// This force doesn't apply forces to particles. // This force doesn't apply forces to particles.
return 0.0; return 0.0;
......
...@@ -55,7 +55,8 @@ public: ...@@ -55,7 +55,8 @@ public:
/** /**
* Create an ContextImpl for a Context; * 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(); ~ContextImpl();
/** /**
* Get the Context for which this is the implementation. * Get the Context for which this is the implementation.
...@@ -197,8 +198,11 @@ public: ...@@ -197,8 +198,11 @@ public:
double calcForcesAndEnergy(bool includeForces, bool includeEnergy, int groups=0xFFFFFFFF); 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(). * 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). * Calculate the kinetic energy of the system (in kJ/mol).
*/ */
...@@ -206,8 +210,11 @@ public: ...@@ -206,8 +210,11 @@ public:
/** /**
* This should be called at the start of each time step. It calls updateContextState() on each * 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. * 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. * Get the list of ForceImpls belonging to this ContextImpl.
*/ */
...@@ -261,8 +268,18 @@ public: ...@@ -261,8 +268,18 @@ public:
* you should never call it. It is exposed here because the same logic is useful to other classes too. * 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); 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: private:
friend class Context; friend class Context;
void initialize();
Context& owner; Context& owner;
const System& system; const System& system;
Integrator& integrator; Integrator& integrator;
......
...@@ -53,7 +53,7 @@ public: ...@@ -53,7 +53,7 @@ public:
const CustomAngleForce& getOwner() const { const CustomAngleForce& getOwner() const {
return owner; return owner;
} }
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......
...@@ -53,7 +53,7 @@ public: ...@@ -53,7 +53,7 @@ public:
const CustomBondForce& getOwner() const { const CustomBondForce& getOwner() const {
return owner; return owner;
} }
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups); 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: ...@@ -58,7 +58,7 @@ public:
const CustomCentroidBondForce& getOwner() const { const CustomCentroidBondForce& getOwner() const {
return owner; return owner;
} }
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......
...@@ -57,7 +57,7 @@ public: ...@@ -57,7 +57,7 @@ public:
const CustomCompoundBondForce& getOwner() const { const CustomCompoundBondForce& getOwner() const {
return owner; return owner;
} }
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......
...@@ -53,7 +53,7 @@ public: ...@@ -53,7 +53,7 @@ public:
const CustomExternalForce& getOwner() const { const CustomExternalForce& getOwner() const {
return owner; return owner;
} }
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......
...@@ -53,7 +53,7 @@ public: ...@@ -53,7 +53,7 @@ public:
const CustomGBForce& getOwner() const { const CustomGBForce& getOwner() const {
return owner; return owner;
} }
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......
...@@ -57,7 +57,7 @@ public: ...@@ -57,7 +57,7 @@ public:
const CustomHbondForce& getOwner() const { const CustomHbondForce& getOwner() const {
return owner; return owner;
} }
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......
...@@ -73,7 +73,7 @@ public: ...@@ -73,7 +73,7 @@ public:
*/ */
static void analyzeComputations(const ContextImpl& context, const CustomIntegrator& integrator, std::vector<std::vector<Lepton::ParsedExpression> >& expressions, 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<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. * Determine whether an expression involves a particular variable.
*/ */
......
...@@ -57,7 +57,7 @@ public: ...@@ -57,7 +57,7 @@ public:
const CustomManyParticleForce& getOwner() const { const CustomManyParticleForce& getOwner() const {
return owner; return owner;
} }
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......
...@@ -54,7 +54,7 @@ public: ...@@ -54,7 +54,7 @@ public:
const CustomNonbondedForce& getOwner() const { const CustomNonbondedForce& getOwner() const {
return owner; return owner;
} }
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
...@@ -69,7 +69,7 @@ public: ...@@ -69,7 +69,7 @@ public:
static void calcLongRangeCorrection(const CustomNonbondedForce& force, const Context& context, double& coefficient, std::vector<double>& derivatives); static void calcLongRangeCorrection(const CustomNonbondedForce& force, const Context& context, double& coefficient, std::vector<double>& derivatives);
private: private:
static double integrateInteraction(Lepton::CompiledExpression& expression, const std::vector<double>& params1, const std::vector<double>& params2, 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; const CustomNonbondedForce& owner;
Kernel kernel; Kernel kernel;
}; };
......
...@@ -53,7 +53,7 @@ public: ...@@ -53,7 +53,7 @@ public:
const CustomTorsionForce& getOwner() const { const CustomTorsionForce& getOwner() const {
return owner; return owner;
} }
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE. * * USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "openmm/Context.h"
#include "openmm/internal/windowsExport.h" #include "openmm/internal/windowsExport.h"
#include <map> #include <map>
#include <string> #include <string>
...@@ -72,9 +73,16 @@ public: ...@@ -72,9 +73,16 @@ public:
* to modify the state variables (positions, velocities, and parameters) stored in the * to modify the state variables (positions, velocities, and parameters) stored in the
* Context in arbitrary ways before integration is performed. * 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 * Calculate the force on each particle generated by this ForceImpl and/or this ForceImpl's
* contribution to the potential energy of the system. * contribution to the potential energy of the system.
...@@ -104,6 +112,13 @@ public: ...@@ -104,6 +112,13 @@ public:
virtual std::vector<std::pair<int, int> > getBondedParticles() const { virtual std::vector<std::pair<int, int> > getBondedParticles() const {
return std::vector<std::pair<int, int> >(0); 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 } // namespace OpenMM
......
...@@ -50,7 +50,7 @@ public: ...@@ -50,7 +50,7 @@ public:
const GBSAOBCForce& getOwner() const { const GBSAOBCForce& getOwner() const {
return owner; return owner;
} }
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......
...@@ -53,7 +53,7 @@ public: ...@@ -53,7 +53,7 @@ public:
const HarmonicAngleForce& getOwner() const { const HarmonicAngleForce& getOwner() const {
return owner; return owner;
} }
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......
...@@ -53,7 +53,7 @@ public: ...@@ -53,7 +53,7 @@ public:
const HarmonicBondForce& getOwner() const { const HarmonicBondForce& getOwner() const {
return owner; return owner;
} }
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
......
...@@ -51,7 +51,7 @@ public: ...@@ -51,7 +51,7 @@ public:
const MonteCarloBarostat& getOwner() const { const MonteCarloBarostat& getOwner() const {
return owner; return owner;
} }
void updateContextState(ContextImpl& context); void updateContextState(ContextImpl& context, bool& forcesInvalid);
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups) { double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups) {
// This force doesn't apply forces to particles. // This force doesn't apply forces to particles.
return 0.0; return 0.0;
......
...@@ -55,7 +55,7 @@ public: ...@@ -55,7 +55,7 @@ public:
const NonbondedForce& getOwner() const { const NonbondedForce& getOwner() const {
return owner; return owner;
} }
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups); 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