OpenMM
 All Classes Namespaces Functions Variables Enumerations Enumerator Friends
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-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 "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);
186  double getEwaldErrorTolerance() const;
193  void setEwaldErrorTolerance(double tol);
206  int addParticle(double charge, double sigma, double epsilon);
215  void getParticleParameters(int index, double& charge, double& sigma, double& epsilon) const;
226  void setParticleParameters(int index, double charge, double sigma, double epsilon);
243  int addException(int particle1, int particle2, double chargeProd, double sigma, double epsilon, bool replace = false);
254  void getExceptionParameters(int index, int& particle1, int& particle2, double& chargeProd, double& sigma, double& epsilon) const;
267  void setExceptionParameters(int index, int particle1, int particle2, double chargeProd, double sigma, double epsilon);
280  void createExceptionsFromBonds(const std::vector<std::pair<int, int> >& bonds, double coulomb14Scale, double lj14Scale);
288  return useDispersionCorrection;
289  }
296  void setUseDispersionCorrection(bool useCorrection) {
297  useDispersionCorrection = useCorrection;
298  }
305  int getReciprocalSpaceForceGroup() const;
315  void setReciprocalSpaceForceGroup(int group);
328  void updateParametersInContext(Context& context);
329 protected:
330  ForceImpl* createImpl() const;
331 private:
332  class ParticleInfo;
333  class ExceptionInfo;
334  NonbondedMethod nonbondedMethod;
335  double cutoffDistance, switchingDistance, rfDielectric, ewaldErrorTol;
336  bool useSwitchingFunction, useDispersionCorrection;
337  int recipForceGroup;
338  void addExclusionsToSet(const std::vector<std::set<int> >& bonded12, std::set<int>& exclusions, int baseParticle, int fromParticle, int currentLevel) const;
339  std::vector<ParticleInfo> particles;
340  std::vector<ExceptionInfo> exceptions;
341  std::map<std::pair<int, int>, int> exceptionMap;
342 };
343 
348 class NonbondedForce::ParticleInfo {
349 public:
350  double charge, sigma, epsilon;
351  ParticleInfo() {
352  charge = sigma = epsilon = 0.0;
353  }
354  ParticleInfo(double charge, double sigma, double epsilon) :
355  charge(charge), sigma(sigma), epsilon(epsilon) {
356  }
357 };
358 
363 class NonbondedForce::ExceptionInfo {
364 public:
365  int particle1, particle2;
366  double chargeProd, sigma, epsilon;
367  ExceptionInfo() {
368  particle1 = particle2 = -1;
369  chargeProd = sigma = epsilon = 0.0;
370  }
371  ExceptionInfo(int particle1, int particle2, double chargeProd, double sigma, double epsilon) :
372  particle1(particle1), particle2(particle2), chargeProd(chargeProd), sigma(sigma), epsilon(epsilon) {
373  }
374 };
375 
376 } // namespace OpenMM
377 
378 #endif /*OPENMM_NONBONDEDFORCE_H_*/