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-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 "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 
70 class OPENMM_EXPORT NonbondedForce : public Force {
71 public:
80  NoCutoff = 0,
85  CutoffNonPeriodic = 1,
91  CutoffPeriodic = 2,
96  Ewald = 3,
101  PME = 4
102  };
106  NonbondedForce();
110  int getNumParticles() const {
111  return particles.size();
112  }
116  int getNumExceptions() const {
117  return exceptions.size();
118  }
122  NonbondedMethod getNonbondedMethod() const;
126  void setNonbondedMethod(NonbondedMethod method);
133  double getCutoffDistance() const;
140  void setCutoffDistance(double distance);
144  double getReactionFieldDielectric() const;
148  void setReactionFieldDielectric(double dielectric);
155  double getEwaldErrorTolerance() const;
162  void setEwaldErrorTolerance(double tol);
175  int addParticle(double charge, double sigma, double epsilon);
184  void getParticleParameters(int index, double& charge, double& sigma, double& epsilon) const;
195  void setParticleParameters(int index, double charge, double sigma, double epsilon);
212  int addException(int particle1, int particle2, double chargeProd, double sigma, double epsilon, bool replace = false);
223  void getExceptionParameters(int index, int& particle1, int& particle2, double& chargeProd, double& sigma, double& epsilon) const;
236  void setExceptionParameters(int index, int particle1, int particle2, double chargeProd, double sigma, double epsilon);
249  void createExceptionsFromBonds(const std::vector<std::pair<int, int> >& bonds, double coulomb14Scale, double lj14Scale);
257  return useDispersionCorrection;
258  }
265  void setUseDispersionCorrection(bool useCorrection) {
266  useDispersionCorrection = useCorrection;
267  }
274  int getReciprocalSpaceForceGroup() const;
284  void setReciprocalSpaceForceGroup(int group);
297  void updateParametersInContext(Context& context);
298 protected:
299  ForceImpl* createImpl() const;
300 private:
301  class ParticleInfo;
302  class ExceptionInfo;
303  NonbondedMethod nonbondedMethod;
304  double cutoffDistance, rfDielectric, ewaldErrorTol;
305  bool useDispersionCorrection;
306  int recipForceGroup;
307  void addExclusionsToSet(const std::vector<std::set<int> >& bonded12, std::set<int>& exclusions, int baseParticle, int fromParticle, int currentLevel) const;
308  std::vector<ParticleInfo> particles;
309  std::vector<ExceptionInfo> exceptions;
310  std::map<std::pair<int, int>, int> exceptionMap;
311 };
312 
317 class NonbondedForce::ParticleInfo {
318 public:
319  double charge, sigma, epsilon;
320  ParticleInfo() {
321  charge = sigma = epsilon = 0.0;
322  }
323  ParticleInfo(double charge, double sigma, double epsilon) :
324  charge(charge), sigma(sigma), epsilon(epsilon) {
325  }
326 };
327 
332 class NonbondedForce::ExceptionInfo {
333 public:
334  int particle1, particle2;
335  double chargeProd, sigma, epsilon;
336  ExceptionInfo() {
337  particle1 = particle2 = -1;
338  chargeProd = sigma = epsilon = 0.0;
339  }
340  ExceptionInfo(int particle1, int particle2, double chargeProd, double sigma, double epsilon) :
341  particle1(particle1), particle2(particle2), chargeProd(chargeProd), sigma(sigma), epsilon(epsilon) {
342  }
343 };
344 
345 } // namespace OpenMM
346 
347 #endif /*OPENMM_NONBONDEDFORCE_H_*/