OpenMM
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
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 
75 class OPENMM_EXPORT CustomExternalForce : public Force {
76 public:
83  explicit CustomExternalForce(const std::string& energy);
87  int getNumParticles() const {
88  return particles.size();
89  }
94  return parameters.size();
95  }
99  int getNumGlobalParameters() const {
100  return globalParameters.size();
101  }
105  const std::string& getEnergyFunction() const;
109  void setEnergyFunction(const std::string& energy);
116  int addPerParticleParameter(const std::string& name);
123  const std::string& getPerParticleParameterName(int index) const;
130  void setPerParticleParameterName(int index, const std::string& name);
138  int addGlobalParameter(const std::string& name, double defaultValue);
145  const std::string& getGlobalParameterName(int index) const;
152  void setGlobalParameterName(int index, const std::string& name);
159  double getGlobalParameterDefaultValue(int index) const;
166  void setGlobalParameterDefaultValue(int index, double defaultValue);
174  int addParticle(int particle, const std::vector<double>& parameters);
182  void getParticleParameters(int index, int& particle, std::vector<double>& parameters) const;
190  void setParticleParameters(int index, int particle, const std::vector<double>& parameters);
201  void updateParametersInContext(Context& context);
202 protected:
203  ForceImpl* createImpl() const;
204 private:
205  class ParticleInfo;
206  class ParticleParameterInfo;
207  class GlobalParameterInfo;
208  std::string energyExpression;
209  std::vector<ParticleParameterInfo> parameters;
210  std::vector<GlobalParameterInfo> globalParameters;
211  std::vector<ParticleInfo> particles;
212 };
213 
218 class CustomExternalForce::ParticleInfo {
219 public:
220  int particle;
221  std::vector<double> parameters;
222  ParticleInfo() : particle(-1) {
223  }
224  ParticleInfo(int particle, const std::vector<double>& parameters) : particle(particle), parameters(parameters) {
225  }
226 };
227 
232 class CustomExternalForce::ParticleParameterInfo {
233 public:
234  std::string name;
235  ParticleParameterInfo() {
236  }
237  ParticleParameterInfo(const std::string& name) : name(name) {
238  }
239 };
240 
245 class CustomExternalForce::GlobalParameterInfo {
246 public:
247  std::string name;
248  double defaultValue;
249  GlobalParameterInfo() {
250  }
251  GlobalParameterInfo(const std::string& name, double defaultValue) : name(name), defaultValue(defaultValue) {
252  }
253 };
254 
255 } // namespace OpenMM
256 
257 #endif /*OPENMM_CUSTOMEXTERNALFORCE_H_*/
A Context stores the complete state of a simulation.
Definition: Context.h:67
This class implements an &quot;external&quot; force on particles.
Definition: CustomExternalForce.h:75
int getNumPerParticleParameters() const
Get the number of per-particle parameters that the force depends on.
Definition: CustomExternalForce.h:93
int getNumParticles() const
Get the number of particles for which force field parameters have been defined.
Definition: CustomExternalForce.h:87
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:99
A ForceImpl provides the internal implementation of a Force.
Definition: ForceImpl.h:57