Simpatico  v1.10
LJPair.h
1 #ifndef SIMP_LJ_PAIR_H
2 #define SIMP_LJ_PAIR_H
3 
4 /*
5 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include <util/param/ParamComposite.h>
12 #include <util/global.h>
13 
14 #include <math.h>
15 
16 namespace Simp
17 {
18 
19  using namespace Util;
20 
33  class LJPair : public ParamComposite
34  {
35 
36  public:
37 
41  LJPair();
42 
48  LJPair(const LJPair& other);
49 
55  LJPair& operator = (const LJPair& other);
56 
58 
59 
65  void setNAtomType(int nAtomType);
66 
74  void readParameters(std::istream &in);
75 
81  virtual void loadParameters(Serializable::IArchive &ar);
82 
88  virtual void save(Serializable::OArchive &ar);
89 
97  void setEpsilon(int i, int j, double epsilon);
98 
106  void setSigma(int i, int j, double sigma);
107 
116  void set(std::string name, int i, int j, double value);
117 
119 
121 
130  double energy(double rsq, int i, int j) const;
131 
154  double forceOverR(double rsq, int i, int j) const;
155 
163  double cutoffSq(int i, int j) const;
164 
168  double maxPairCutoff() const;
169 
177  double epsilon(int i, int j) const;
178 
186  double sigma(int i, int j) const;
187 
195  double get(std::string name, int i, int j) const;
196 
198 
199  protected:
200 
202  static const int MaxAtomType = 4;
203 
204  // Lennard-Jones parameters for different types of atom pairs
212 
219 
224 
229 
230  };
231 
232  // Inline methods
233 
234  /*
235  * Calculate interaction energy for a pair, as function of squared distance.
236  */
237  inline double LJPair::energy(double rsq, int i, int j) const
238  {
239  double r6i;
240  if (rsq < cutoffSq_[i][j]) {
241  if (rsq < 0.6*sigmaSq_[i][j]) {
242  rsq = 0.6*sigmaSq_[i][j];
243  }
244  r6i = sigmaSq_[i][j]/rsq;
245  r6i = r6i*r6i*r6i;
246  return 4.0*epsilon_[i][j]*(r6i*r6i - r6i) + ljShift_[i][j];
247  } else {
248  return 0.0;
249  }
250  }
251 
252  /*
253  * Calculate force/distance for a pair as function of squared distance.
254  */
255  inline double LJPair::forceOverR(double rsq, int i, int j) const
256  {
257  double r2i, r6i;
258  r2i = 1.0/rsq;
259  r6i = sigmaSq_[i][j]*r2i;
260  r6i = r6i*r6i*r6i;
261  return eps48_[i][j]*(r6i - 0.5)*r6i*r2i;
262  }
263 
264  /*
265  * Return cutoff parameter for a specific atom type pair.
266  */
267  inline double LJPair::cutoffSq(int i, int j) const
268  { return cutoffSq_[i][j]; }
269 
270 }
271 #endif
double sigmaSq_[MaxAtomType][MaxAtomType]
square of sigma[][].
Definition: LJPair.h:207
LJPair()
Default constructor.
Definition: LJPair.cpp:24
double epsilon_[MaxAtomType][MaxAtomType]
LJ interaction energies.
Definition: LJPair.h:205
double ljShift_[MaxAtomType][MaxAtomType]
shift in LJ potential.
Definition: LJPair.h:210
void setEpsilon(int i, int j, double epsilon)
Set LJ interaction energy for a specific pair of Atom types.
Definition: LJPair.cpp:92
double eps48_[MaxAtomType][MaxAtomType]
48*epsilon
Definition: LJPair.h:211
double cutoffSq(int i, int j) const
Get square of cutoff distance for specific type pair.
Definition: LJPair.h:267
File containing preprocessor macros for error handling.
int nAtomType_
Total number of atom types.
Definition: LJPair.h:223
Classes used by all simpatico molecular simulations.
double sigma(int i, int j) const
Get LJ range for a specific pair of Atom types.
Definition: LJPair.cpp:260
double forceOverR(double rsq, int i, int j) const
Returns ratio of scalar pair interaction force to pair separation.
Definition: LJPair.h:255
Saving / output archive for binary ostream.
double epsilon(int i, int j) const
Get LJ interaction energy for a specific pair of Atom types.
Definition: LJPair.cpp:250
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
Definition: LJPair.cpp:229
Utility classes for scientific computation.
Definition: accumulators.mod:1
double sigma_[MaxAtomType][MaxAtomType]
LJ range parameters.
Definition: LJPair.h:206
double cutoff_[MaxAtomType][MaxAtomType]
LJ cutoff distance.
Definition: LJPair.h:208
double maxPairCutoff() const
Get maximum of pair cutoff distance, for all atom type pairs.
Definition: LJPair.cpp:244
double cutoffSq_[MaxAtomType][MaxAtomType]
square of cutoff[][].
Definition: LJPair.h:209
void setSigma(int i, int j, double sigma)
Get LJ range for a specific pair of Atom types.
Definition: LJPair.cpp:125
Saving archive for binary istream.
bool isInitialized_
Was this object initialized by calling (read|load)Parameters ?
Definition: LJPair.h:228
A cutoff, shifted Lennard-Jones nonbonded pair interaction.
Definition: LJPair.h:33
static const int MaxAtomType
Maximum allowed value for nAtomType (# of atom types)
Definition: LJPair.h:202
double maxPairCutoff_
Maximum pair potential cutoff radius, for all monomer type pairs.
Definition: LJPair.h:218
LJPair & operator=(const LJPair &other)
Assignment.
Definition: LJPair.cpp:55
void setNAtomType(int nAtomType)
Set nAtomType value.
Definition: LJPair.cpp:78
void readParameters(std::istream &in)
Read epsilon, sigma, and cutoff, and initialize other variables.
Definition: LJPair.cpp:159
An object that can read multiple parameters from file.
double energy(double rsq, int i, int j) const
Returns interaction energy for a single pair of atoms.
Definition: LJPair.h:237
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
Definition: LJPair.cpp:196