OpenMM
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
NonbondedForce.h
1 #ifndef OPENMM_NONBONDEDFORCE_H_
2 #define OPENMM_NONBONDEDFORCE_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 "Context.h"
36 #include "Force.h"
37 #include <map>
38 #include <set>
39 #include <utility>
40 #include <vector>
41 #include "internal/windowsExport.h"
42 
43 namespace OpenMM {
44 
81 class OPENMM_EXPORT NonbondedForce : public Force {
82 public:
91  NoCutoff = 0,
96  CutoffNonPeriodic = 1,
102  CutoffPeriodic = 2,
107  Ewald = 3,
112  PME = 4
113  };
117  NonbondedForce();
121  int getNumParticles() const {
122  return particles.size();
123  }
127  int getNumExceptions() const {
128  return exceptions.size();
129  }
133  NonbondedMethod getNonbondedMethod() const;
137  void setNonbondedMethod(NonbondedMethod method);
144  double getCutoffDistance() const;
151  void setCutoffDistance(double distance);
156  bool getUseSwitchingFunction() const;
161  void setUseSwitchingFunction(bool use);
166  double getSwitchingDistance() const;
171  void setSwitchingDistance(double distance);
175  double getReactionFieldDielectric() const;
179  void setReactionFieldDielectric(double dielectric);
189  double getEwaldErrorTolerance() const;
199  void setEwaldErrorTolerance(double tol);
209  void getPMEParameters(double& alpha, int& nx, int& ny, int& nz) const;
219  void setPMEParameters(double alpha, int nx, int ny, int nz);
232  int addParticle(double charge, double sigma, double epsilon);
241  void getParticleParameters(int index, double& charge, double& sigma, double& epsilon) const;
252  void setParticleParameters(int index, double charge, double sigma, double epsilon);
269  int addException(int particle1, int particle2, double chargeProd, double sigma, double epsilon, bool replace = false);
280  void getExceptionParameters(int index, int& particle1, int& particle2, double& chargeProd, double& sigma, double& epsilon) const;
293  void setExceptionParameters(int index, int particle1, int particle2, double chargeProd, double sigma, double epsilon);
306  void createExceptionsFromBonds(const std::vector<std::pair<int, int> >& bonds, double coulomb14Scale, double lj14Scale);
314  return useDispersionCorrection;
315  }
322  void setUseDispersionCorrection(bool useCorrection) {
323  useDispersionCorrection = useCorrection;
324  }
331  int getReciprocalSpaceForceGroup() const;
341  void setReciprocalSpaceForceGroup(int group);
354  void updateParametersInContext(Context& context);
362  return nonbondedMethod == NonbondedForce::CutoffPeriodic ||
363  nonbondedMethod == NonbondedForce::Ewald ||
364  nonbondedMethod == NonbondedForce::PME;
365  }
366 protected:
367  ForceImpl* createImpl() const;
368 private:
369  class ParticleInfo;
370  class ExceptionInfo;
371  NonbondedMethod nonbondedMethod;
372  double cutoffDistance, switchingDistance, rfDielectric, ewaldErrorTol, alpha;
373  bool useSwitchingFunction, useDispersionCorrection;
374  int recipForceGroup, nx, ny, nz;
375  void addExclusionsToSet(const std::vector<std::set<int> >& bonded12, std::set<int>& exclusions, int baseParticle, int fromParticle, int currentLevel) const;
376  std::vector<ParticleInfo> particles;
377  std::vector<ExceptionInfo> exceptions;
378  std::map<std::pair<int, int>, int> exceptionMap;
379 };
380 
385 class NonbondedForce::ParticleInfo {
386 public:
387  double charge, sigma, epsilon;
388  ParticleInfo() {
389  charge = sigma = epsilon = 0.0;
390  }
391  ParticleInfo(double charge, double sigma, double epsilon) :
392  charge(charge), sigma(sigma), epsilon(epsilon) {
393  }
394 };
395 
400 class NonbondedForce::ExceptionInfo {
401 public:
402  int particle1, particle2;
403  double chargeProd, sigma, epsilon;
404  ExceptionInfo() {
405  particle1 = particle2 = -1;
406  chargeProd = sigma = epsilon = 0.0;
407  }
408  ExceptionInfo(int particle1, int particle2, double chargeProd, double sigma, double epsilon) :
409  particle1(particle1), particle2(particle2), chargeProd(chargeProd), sigma(sigma), epsilon(epsilon) {
410  }
411 };
412 
413 } // namespace OpenMM
414 
415 #endif /*OPENMM_NONBONDEDFORCE_H_*/
A Context stores the complete state of a simulation.
Definition: Context.h:67
Periodic boundary conditions are used, so that each particle interacts only with the nearest periodic...
Definition: NonbondedForce.h:102
Periodic boundary conditions are used, and Ewald summation is used to compute the interaction of each...
Definition: NonbondedForce.h:107
Periodic boundary conditions are used, and Particle-Mesh Ewald (PME) summation is used to compute the...
Definition: NonbondedForce.h:112
bool getUseDispersionCorrection() const
Get whether to add a contribution to the energy that approximately represents the effect of Lennard-J...
Definition: NonbondedForce.h:313
Force objects apply forces to the particles in a System, or alter their behavior in other ways...
Definition: Force.h:65
void setUseDispersionCorrection(bool useCorrection)
Set whether to add a contribution to the energy that approximately represents the effect of Lennard-J...
Definition: NonbondedForce.h:322
int getNumExceptions() const
Get the number of special interactions that should be calculated differently from other interactions...
Definition: NonbondedForce.h:127
int getNumParticles() const
Get the number of particles for which force field parameters have been defined.
Definition: NonbondedForce.h:121
bool usesPeriodicBoundaryConditions() const
Returns whether or not this force makes use of periodic boundary conditions.
Definition: NonbondedForce.h:361
NonbondedMethod
This is an enumeration of the different methods that may be used for handling long range nonbonded fo...
Definition: NonbondedForce.h:86
This class implements nonbonded interactions between particles, including a Coulomb force to represen...
Definition: NonbondedForce.h:81
Definition: AndersenThermostat.h:40