OpenMM
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
CustomExternalForce.h
1 #ifndef OPENMM_CUSTOMEXTERNALFORCE_H_
2 #define OPENMM_CUSTOMEXTERNALFORCE_H_
3 
4 /* -------------------------------------------------------------------------- *
5  * OpenMM *
6  * -------------------------------------------------------------------------- *
7  * This is part of the OpenMM molecular simulation toolkit originating from *
8  * Simbios, the NIH National Center for Physics-Based Simulation of *
9  * Biological Structures at Stanford, funded under the NIH Roadmap for *
10  * Medical Research, grant U54 GM072970. See https://simtk.org. *
11  * *
12  * Portions copyright (c) 2008-2012 Stanford University and the Authors. *
13  * Authors: Peter Eastman *
14  * Contributors: *
15  * *
16  * Permission is hereby granted, free of charge, to any person obtaining a *
17  * copy of this software and associated documentation files (the "Software"), *
18  * to deal in the Software without restriction, including without limitation *
19  * the rights to use, copy, modify, merge, publish, distribute, sublicense, *
20  * and/or sell copies of the Software, and to permit persons to whom the *
21  * Software is furnished to do so, subject to the following conditions: *
22  * *
23  * The above copyright notice and this permission notice shall be included in *
24  * all copies or substantial portions of the Software. *
25  * *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
27  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
28  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
29  * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
30  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
31  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
32  * USE OR OTHER DEALINGS IN THE SOFTWARE. *
33  * -------------------------------------------------------------------------- */
34 
35 #include "Force.h"
36 #include "Vec3.h"
37 #include <vector>
38 #include "internal/windowsExport.h"
39 
40 namespace OpenMM {
41 
76 class OPENMM_EXPORT CustomExternalForce : public Force {
77 public:
84  explicit CustomExternalForce(const std::string& energy);
88  int getNumParticles() const {
89  return particles.size();
90  }
95  return parameters.size();
96  }
101  return globalParameters.size();
102  }
106  const std::string& getEnergyFunction() const;
110  void setEnergyFunction(const std::string& energy);
117  int addPerParticleParameter(const std::string& name);
124  const std::string& getPerParticleParameterName(int index) const;
131  void setPerParticleParameterName(int index, const std::string& name);
139  int addGlobalParameter(const std::string& name, double defaultValue);
146  const std::string& getGlobalParameterName(int index) const;
153  void setGlobalParameterName(int index, const std::string& name);
160  double getGlobalParameterDefaultValue(int index) const;
167  void setGlobalParameterDefaultValue(int index, double defaultValue);
175  int addParticle(int particle, const std::vector<double>& parameters);
183  void getParticleParameters(int index, int& particle, std::vector<double>& parameters) const;
191  void setParticleParameters(int index, int particle, const std::vector<double>& parameters);
202  void updateParametersInContext(Context& context);
210  return false;
211  }
212 protected:
213  ForceImpl* createImpl() const;
214 private:
215  class ParticleInfo;
216  class ParticleParameterInfo;
217  class GlobalParameterInfo;
218  std::string energyExpression;
219  std::vector<ParticleParameterInfo> parameters;
220  std::vector<GlobalParameterInfo> globalParameters;
221  std::vector<ParticleInfo> particles;
222 };
223 
228 class CustomExternalForce::ParticleInfo {
229 public:
230  int particle;
231  std::vector<double> parameters;
232  ParticleInfo() : particle(-1) {
233  }
234  ParticleInfo(int particle, const std::vector<double>& parameters) : particle(particle), parameters(parameters) {
235  }
236 };
237 
242 class CustomExternalForce::ParticleParameterInfo {
243 public:
244  std::string name;
245  ParticleParameterInfo() {
246  }
247  ParticleParameterInfo(const std::string& name) : name(name) {
248  }
249 };
250 
255 class CustomExternalForce::GlobalParameterInfo {
256 public:
257  std::string name;
258  double defaultValue;
259  GlobalParameterInfo() {
260  }
261  GlobalParameterInfo(const std::string& name, double defaultValue) : name(name), defaultValue(defaultValue) {
262  }
263 };
264 
265 } // namespace OpenMM
266 
267 #endif /*OPENMM_CUSTOMEXTERNALFORCE_H_*/
bool usesPeriodicBoundaryConditions() const
Returns whether or not this force makes use of periodic boundary conditions.
Definition: CustomExternalForce.h:209
A Context stores the complete state of a simulation.
Definition: Context.h:67
This class implements an "external" force on particles.
Definition: CustomExternalForce.h:76
int getNumPerParticleParameters() const
Get the number of per-particle parameters that the force depends on.
Definition: CustomExternalForce.h:94
int getNumParticles() const
Get the number of particles for which force field parameters have been defined.
Definition: CustomExternalForce.h:88
Force objects apply forces to the particles in a System, or alter their behavior in other ways...
Definition: Force.h:65
int getNumGlobalParameters() const
Get the number of global parameters that the force depends on.
Definition: CustomExternalForce.h:100
Definition: AndersenThermostat.h:40