OpenMM
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
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-2014 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 "TabulatedFunction.h"
36 #include "Force.h"
37 #include "Vec3.h"
38 #include <map>
39 #include <set>
40 #include <utility>
41 #include <vector>
42 #include "internal/windowsExport.h"
43 
44 namespace OpenMM {
45 
132 class OPENMM_EXPORT CustomNonbondedForce : public Force {
133 public:
142  NoCutoff = 0,
146  CutoffNonPeriodic = 1,
151  CutoffPeriodic = 2,
152  };
159  explicit CustomNonbondedForce(const std::string& energy);
160  CustomNonbondedForce(const CustomNonbondedForce& rhs); // copy constructor
165  int getNumParticles() const {
166  return particles.size();
167  }
171  int getNumExclusions() const {
172  return exclusions.size();
173  }
178  return parameters.size();
179  }
184  return globalParameters.size();
185  }
190  return functions.size();
191  }
197  int getNumFunctions() const {
198  return functions.size();
199  }
204  return interactionGroups.size();
205  }
209  const std::string& getEnergyFunction() const;
213  void setEnergyFunction(const std::string& energy);
217  NonbondedMethod getNonbondedMethod() const;
221  void setNonbondedMethod(NonbondedMethod method);
228  double getCutoffDistance() const;
235  void setCutoffDistance(double distance);
240  bool getUseSwitchingFunction() const;
245  void setUseSwitchingFunction(bool use);
250  double getSwitchingDistance() const;
255  void setSwitchingDistance(double distance);
260  bool getUseLongRangeCorrection() const;
265  void setUseLongRangeCorrection(bool use);
272  int addPerParticleParameter(const std::string& name);
279  const std::string& getPerParticleParameterName(int index) const;
286  void setPerParticleParameterName(int index, const std::string& name);
294  int addGlobalParameter(const std::string& name, double defaultValue);
301  const std::string& getGlobalParameterName(int index) const;
308  void setGlobalParameterName(int index, const std::string& name);
315  double getGlobalParameterDefaultValue(int index) const;
322  void setGlobalParameterDefaultValue(int index, double defaultValue);
330  int addParticle(const std::vector<double>& parameters);
337  void getParticleParameters(int index, std::vector<double>& parameters) const;
344  void setParticleParameters(int index, const std::vector<double>& parameters);
354  int addExclusion(int particle1, int particle2);
362  void getExclusionParticles(int index, int& particle1, int& particle2) const;
370  void setExclusionParticles(int index, int particle1, int particle2);
379  void createExclusionsFromBonds(const std::vector<std::pair<int, int> >& bonds, int bondCutoff);
389  int addTabulatedFunction(const std::string& name, TabulatedFunction* function);
396  const TabulatedFunction& getTabulatedFunction(int index) const;
403  TabulatedFunction& getTabulatedFunction(int index);
410  const std::string& getTabulatedFunctionName(int index) const;
416  int addFunction(const std::string& name, const std::vector<double>& values, double min, double max);
423  void getFunctionParameters(int index, std::string& name, std::vector<double>& values, double& min, double& max) const;
430  void setFunctionParameters(int index, const std::string& name, const std::vector<double>& values, double min, double max);
438  int addInteractionGroup(const std::set<int>& set1, const std::set<int>& set2);
446  void getInteractionGroupParameters(int index, std::set<int>& set1, std::set<int>& set2) const;
454  void setInteractionGroupParameters(int index, const std::set<int>& set1, const std::set<int>& set2);
466  void updateParametersInContext(Context& context);
467 protected:
468  ForceImpl* createImpl() const;
469 private:
470  // REMEMBER TO UPDATE THE COPY CONSTRUCTOR IF YOU ADD ANY NEW FIELDS !!
471  class ParticleInfo;
472  class PerParticleParameterInfo;
473  class GlobalParameterInfo;
474  class ExclusionInfo;
475  class FunctionInfo;
476  class InteractionGroupInfo;
477  NonbondedMethod nonbondedMethod;
478  double cutoffDistance, switchingDistance;
479  bool useSwitchingFunction, useLongRangeCorrection;
480  std::string energyExpression;
481  std::vector<PerParticleParameterInfo> parameters;
482  std::vector<GlobalParameterInfo> globalParameters;
483  std::vector<ParticleInfo> particles;
484  std::vector<ExclusionInfo> exclusions;
485  std::vector<FunctionInfo> functions;
486  std::vector<InteractionGroupInfo> interactionGroups;
487 };
488 
493 class CustomNonbondedForce::ParticleInfo {
494 public:
495  std::vector<double> parameters;
496  ParticleInfo() {
497  }
498  ParticleInfo(const std::vector<double>& parameters) : parameters(parameters) {
499  }
500 };
501 
506 class CustomNonbondedForce::PerParticleParameterInfo {
507 public:
508  std::string name;
509  PerParticleParameterInfo() {
510  }
511  PerParticleParameterInfo(const std::string& name) : name(name) {
512  }
513 };
514 
519 class CustomNonbondedForce::GlobalParameterInfo {
520 public:
521  std::string name;
522  double defaultValue;
523  GlobalParameterInfo() {
524  }
525  GlobalParameterInfo(const std::string& name, double defaultValue) : name(name), defaultValue(defaultValue) {
526  }
527 };
528 
533 class CustomNonbondedForce::ExclusionInfo {
534 public:
535  int particle1, particle2;
536  ExclusionInfo() {
537  particle1 = particle2 = -1;
538  }
539  ExclusionInfo(int particle1, int particle2) :
540  particle1(particle1), particle2(particle2) {
541  }
542 };
543 
548 class CustomNonbondedForce::FunctionInfo {
549 public:
550  std::string name;
551  TabulatedFunction* function;
552  FunctionInfo() {
553  }
554  FunctionInfo(const std::string& name, TabulatedFunction* function) : name(name), function(function) {
555  }
556 };
557 
562 class CustomNonbondedForce::InteractionGroupInfo {
563 public:
564  std::set<int> set1, set2;
565  InteractionGroupInfo() {
566  }
567  InteractionGroupInfo(const std::set<int>& set1, const std::set<int>& set2) :
568  set1(set1), set2(set2) {
569  }
570 };
571 
572 } // namespace OpenMM
573 
574 #endif /*OPENMM_CUSTOMNONBONDEDFORCE_H_*/
int getNumGlobalParameters() const
Get the number of global parameters that the interaction depends on.
Definition: CustomNonbondedForce.h:183
A TabulatedFunction uses a set of tabulated values to define a mathematical function.
Definition: TabulatedFunction.h:58
int getNumFunctions() const
Get the number of tabulated functions that have been defined.
Definition: CustomNonbondedForce.h:197
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:171
int getNumPerParticleParameters() const
Get the number of per-particle parameters that the interaction depends on.
Definition: CustomNonbondedForce.h:177
Force objects apply forces to the particles in a System, or alter their behavior in other ways...
Definition: Force.h:65
int getNumTabulatedFunctions() const
Get the number of tabulated functions that have been defined.
Definition: CustomNonbondedForce.h:189
int getNumInteractionGroups() const
Get the number of interaction groups that have been defined.
Definition: CustomNonbondedForce.h:203
int getNumParticles() const
Get the number of particles for which force field parameters have been defined.
Definition: CustomNonbondedForce.h:165
NonbondedMethod
This is an enumeration of the different methods that may be used for handling long range nonbonded fo...
Definition: CustomNonbondedForce.h:137
A ForceImpl provides the internal implementation of a Force.
Definition: ForceImpl.h:57
This class implements nonbonded interactions between particles.
Definition: CustomNonbondedForce.h:132