OpenMM
 All Classes Namespaces Functions Variables Enumerations Enumerator Friends
CustomNonbondedForce.h
1 #ifndef OPENMM_CUSTOMNONBONDEDFORCE_H_
2 #define OPENMM_CUSTOMNONBONDEDFORCE_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 <map>
38 #include <set>
39 #include <utility>
40 #include <vector>
41 #include "internal/windowsExport.h"
42 
43 namespace OpenMM {
44 
93 class OPENMM_EXPORT CustomNonbondedForce : public Force {
94 public:
103  NoCutoff = 0,
107  CutoffNonPeriodic = 1,
112  CutoffPeriodic = 2,
113  };
120  explicit CustomNonbondedForce(const std::string& energy);
124  int getNumParticles() const {
125  return particles.size();
126  }
130  int getNumExclusions() const {
131  return exclusions.size();
132  }
137  return parameters.size();
138  }
143  return globalParameters.size();
144  }
148  int getNumFunctions() const {
149  return functions.size();
150  }
154  const std::string& getEnergyFunction() const;
158  void setEnergyFunction(const std::string& energy);
162  NonbondedMethod getNonbondedMethod() const;
166  void setNonbondedMethod(NonbondedMethod method);
173  double getCutoffDistance() const;
180  void setCutoffDistance(double distance);
187  int addPerParticleParameter(const std::string& name);
194  const std::string& getPerParticleParameterName(int index) const;
201  void setPerParticleParameterName(int index, const std::string& name);
209  int addGlobalParameter(const std::string& name, double defaultValue);
216  const std::string& getGlobalParameterName(int index) const;
223  void setGlobalParameterName(int index, const std::string& name);
230  double getGlobalParameterDefaultValue(int index) const;
237  void setGlobalParameterDefaultValue(int index, double defaultValue);
245  int addParticle(const std::vector<double>& parameters);
252  void getParticleParameters(int index, std::vector<double>& parameters) const;
259  void setParticleParameters(int index, const std::vector<double>& parameters);
267  int addExclusion(int particle1, int particle2);
275  void getExclusionParticles(int index, int& particle1, int& particle2) const;
283  void setExclusionParticles(int index, int particle1, int particle2);
294  int addFunction(const std::string& name, const std::vector<double>& values, double min, double max);
305  void getFunctionParameters(int index, std::string& name, std::vector<double>& values, double& min, double& max) const;
316  void setFunctionParameters(int index, const std::string& name, const std::vector<double>& values, double min, double max);
328  void updateParametersInContext(Context& context);
329 protected:
330  ForceImpl* createImpl();
331 private:
332  class ParticleInfo;
333  class PerParticleParameterInfo;
334  class GlobalParameterInfo;
335  class ExclusionInfo;
336  class FunctionInfo;
337  NonbondedMethod nonbondedMethod;
338  double cutoffDistance;
339  std::string energyExpression;
340  std::vector<PerParticleParameterInfo> parameters;
341  std::vector<GlobalParameterInfo> globalParameters;
342  std::vector<ParticleInfo> particles;
343  std::vector<ExclusionInfo> exclusions;
344  std::vector<FunctionInfo> functions;
345 };
346 
351 class CustomNonbondedForce::ParticleInfo {
352 public:
353  std::vector<double> parameters;
354  ParticleInfo() {
355  }
356  ParticleInfo(const std::vector<double>& parameters) : parameters(parameters) {
357  }
358 };
359 
364 class CustomNonbondedForce::PerParticleParameterInfo {
365 public:
366  std::string name;
367  PerParticleParameterInfo() {
368  }
369  PerParticleParameterInfo(const std::string& name) : name(name) {
370  }
371 };
372 
377 class CustomNonbondedForce::GlobalParameterInfo {
378 public:
379  std::string name;
380  double defaultValue;
381  GlobalParameterInfo() {
382  }
383  GlobalParameterInfo(const std::string& name, double defaultValue) : name(name), defaultValue(defaultValue) {
384  }
385 };
386 
391 class CustomNonbondedForce::ExclusionInfo {
392 public:
393  int particle1, particle2;
394  ExclusionInfo() {
395  particle1 = particle2 = -1;
396  }
397  ExclusionInfo(int particle1, int particle2) :
398  particle1(particle1), particle2(particle2) {
399  }
400 };
401 
406 class CustomNonbondedForce::FunctionInfo {
407 public:
408  std::string name;
409  std::vector<double> values;
410  double min, max;
411  FunctionInfo() {
412  }
413  FunctionInfo(const std::string& name, const std::vector<double>& values, double min, double max) :
414  name(name), values(values), min(min), max(max) {
415  }
416 };
417 
418 } // namespace OpenMM
419 
420 #endif /*OPENMM_CUSTOMNONBONDEDFORCE_H_*/