OpenMM
 All Classes Namespaces Functions Variables Typedefs 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-2013 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 
131 class OPENMM_EXPORT CustomNonbondedForce : public Force {
132 public:
141  NoCutoff = 0,
145  CutoffNonPeriodic = 1,
150  CutoffPeriodic = 2,
151  };
158  explicit CustomNonbondedForce(const std::string& energy);
162  int getNumParticles() const {
163  return particles.size();
164  }
168  int getNumExclusions() const {
169  return exclusions.size();
170  }
175  return parameters.size();
176  }
181  return globalParameters.size();
182  }
186  int getNumFunctions() const {
187  return functions.size();
188  }
193  return interactionGroups.size();
194  }
198  const std::string& getEnergyFunction() const;
202  void setEnergyFunction(const std::string& energy);
206  NonbondedMethod getNonbondedMethod() const;
210  void setNonbondedMethod(NonbondedMethod method);
217  double getCutoffDistance() const;
224  void setCutoffDistance(double distance);
229  bool getUseSwitchingFunction() const;
234  void setUseSwitchingFunction(bool use);
239  double getSwitchingDistance() const;
244  void setSwitchingDistance(double distance);
249  bool getUseLongRangeCorrection() const;
254  void setUseLongRangeCorrection(bool use);
261  int addPerParticleParameter(const std::string& name);
268  const std::string& getPerParticleParameterName(int index) const;
275  void setPerParticleParameterName(int index, const std::string& name);
283  int addGlobalParameter(const std::string& name, double defaultValue);
290  const std::string& getGlobalParameterName(int index) const;
297  void setGlobalParameterName(int index, const std::string& name);
304  double getGlobalParameterDefaultValue(int index) const;
311  void setGlobalParameterDefaultValue(int index, double defaultValue);
319  int addParticle(const std::vector<double>& parameters);
326  void getParticleParameters(int index, std::vector<double>& parameters) const;
333  void setParticleParameters(int index, const std::vector<double>& parameters);
341  int addExclusion(int particle1, int particle2);
349  void getExclusionParticles(int index, int& particle1, int& particle2) const;
357  void setExclusionParticles(int index, int particle1, int particle2);
368  int addFunction(const std::string& name, const std::vector<double>& values, double min, double max);
379  void getFunctionParameters(int index, std::string& name, std::vector<double>& values, double& min, double& max) const;
390  void setFunctionParameters(int index, const std::string& name, const std::vector<double>& values, double min, double max);
398  int addInteractionGroup(const std::set<int>& set1, const std::set<int>& set2);
406  void getInteractionGroupParameters(int index, std::set<int>& set1, std::set<int>& set2) const;
414  void setInteractionGroupParameters(int index, const std::set<int>& set1, const std::set<int>& set2);
426  void updateParametersInContext(Context& context);
427 protected:
428  ForceImpl* createImpl() const;
429 private:
430  class ParticleInfo;
431  class PerParticleParameterInfo;
432  class GlobalParameterInfo;
433  class ExclusionInfo;
434  class FunctionInfo;
435  class InteractionGroupInfo;
436  NonbondedMethod nonbondedMethod;
437  double cutoffDistance, switchingDistance;
438  bool useSwitchingFunction, useLongRangeCorrection;
439  std::string energyExpression;
440  std::vector<PerParticleParameterInfo> parameters;
441  std::vector<GlobalParameterInfo> globalParameters;
442  std::vector<ParticleInfo> particles;
443  std::vector<ExclusionInfo> exclusions;
444  std::vector<FunctionInfo> functions;
445  std::vector<InteractionGroupInfo> interactionGroups;
446 };
447 
452 class CustomNonbondedForce::ParticleInfo {
453 public:
454  std::vector<double> parameters;
455  ParticleInfo() {
456  }
457  ParticleInfo(const std::vector<double>& parameters) : parameters(parameters) {
458  }
459 };
460 
465 class CustomNonbondedForce::PerParticleParameterInfo {
466 public:
467  std::string name;
468  PerParticleParameterInfo() {
469  }
470  PerParticleParameterInfo(const std::string& name) : name(name) {
471  }
472 };
473 
478 class CustomNonbondedForce::GlobalParameterInfo {
479 public:
480  std::string name;
481  double defaultValue;
482  GlobalParameterInfo() {
483  }
484  GlobalParameterInfo(const std::string& name, double defaultValue) : name(name), defaultValue(defaultValue) {
485  }
486 };
487 
492 class CustomNonbondedForce::ExclusionInfo {
493 public:
494  int particle1, particle2;
495  ExclusionInfo() {
496  particle1 = particle2 = -1;
497  }
498  ExclusionInfo(int particle1, int particle2) :
499  particle1(particle1), particle2(particle2) {
500  }
501 };
502 
507 class CustomNonbondedForce::FunctionInfo {
508 public:
509  std::string name;
510  std::vector<double> values;
511  double min, max;
512  FunctionInfo() {
513  }
514  FunctionInfo(const std::string& name, const std::vector<double>& values, double min, double max) :
515  name(name), values(values), min(min), max(max) {
516  }
517 };
518 
523 class CustomNonbondedForce::InteractionGroupInfo {
524 public:
525  std::set<int> set1, set2;
526  InteractionGroupInfo() {
527  }
528  InteractionGroupInfo(const std::set<int>& set1, const std::set<int>& set2) :
529  set1(set1), set2(set2) {
530  }
531 };
532 
533 } // namespace OpenMM
534 
535 #endif /*OPENMM_CUSTOMNONBONDEDFORCE_H_*/
int getNumGlobalParameters() const
Get the number of global parameters that the interaction depends on.
Definition: CustomNonbondedForce.h:180
int getNumFunctions() const
Get the number of tabulated functions that have been defined.
Definition: CustomNonbondedForce.h:186
A Context stores the complete state of a simulation.
Definition: Context.h:67
int getNumExclusions() const
Get the number of particle pairs whose interactions should be excluded.
Definition: CustomNonbondedForce.h:168
int getNumPerParticleParameters() const
Get the number of per-particle parameters that the interaction depends on.
Definition: CustomNonbondedForce.h:174
Force objects apply forces to the particles in a System, or alter their behavior in other ways...
Definition: Force.h:65
int getNumInteractionGroups() const
Get the number of interaction groups that have been defined.
Definition: CustomNonbondedForce.h:192
int getNumParticles() const
Get the number of particles for which force field parameters have been defined.
Definition: CustomNonbondedForce.h:162
NonbondedMethod
This is an enumeration of the different methods that may be used for handling long range nonbonded fo...
Definition: CustomNonbondedForce.h:136
A ForceImpl provides the internal implementation of a Force.
Definition: ForceImpl.h:57
This class implements nonbonded interactions between particles.
Definition: CustomNonbondedForce.h:131