Simpatico  v1.10
WcaPair.cpp
1 /*
2 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
3 *
4 * Copyright 2010 - 2017, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include "WcaPair.h"
9 
10 #include <iostream>
11 #include <cstring>
12 
13 namespace Simp
14 {
15 
16  using namespace Util;
17 
18  /*
19  * Read potential parameters from file.
20  */
21  void WcaPair::readParameters(std::istream& in)
22  {
23  if (nAtomType_ <= 0) {
24  UTIL_THROW( "nAtomType must be set before readParam");
25  }
26 
27  // Read parameters epsilon and sigma
28  readCArray2D<double>(in, "epsilon", epsilon_[0],
30  readCArray2D<double>(in, "sigma", sigma_[0],
32 
33  // Initialize all other parameters
34  double r6i;
35  int i, j;
36  maxPairCutoff_ = 0.0;
37  for (i = 0; i < nAtomType_; ++i) {
38  for (j = 0; j < nAtomType_; ++j) {
39 
40  cutoff_[i][j] = sigma_[i][j]*pow(2.0, 1.0/6.0);
41 
42  sigmaSq_[i][j] = sigma_[i][j]*sigma_[i][j];
43  cutoffSq_[i][j] = cutoff_[i][j]*cutoff_[i][j];
44  if (cutoff_[i][j] > maxPairCutoff_ ) {
45  maxPairCutoff_ = cutoff_[i][j];
46  }
47 
48  r6i = sigmaSq_[i][j]/cutoffSq_[i][j];
49  r6i = r6i*r6i*r6i;
50  ljShift_[i][j] = -4.0*epsilon_[i][j]*(r6i*r6i - r6i);
51 
52  eps48_[i][j] = 48.0*epsilon_[i][j];
53  }
54  }
55  isInitialized_ = true;
56  }
57 
58  /*
59  * Modify a parameter, identified by a string.
60  */
61  void WcaPair::set(std::string name, int i, int j, double value)
62  {
63  if (name == "epsilon") {
64  epsilon_[i][j] = value;
65  eps48_[i][j] = 48.0*value;
66  if (j != i) {
67  epsilon_[j][i] = value;
68  eps48_[j][i] = eps48_[i][j];
69  }
70  } else {
71  UTIL_THROW("Unrecognized parameter name");
72  }
73 
74  // Recalculate shift
75  double r6i = sigmaSq_[i][j]/cutoffSq_[i][j];
76  r6i = r6i*r6i*r6i;
77  ljShift_[i][j] = -4.0*epsilon_[i][j]*(r6i*r6i - r6i);
78  if (j != i) {
79  ljShift_[j][i] = ljShift_[j][i];
80  }
81 
82  }
83 
84 }
double sigmaSq_[MaxAtomType][MaxAtomType]
square of sigma[][].
Definition: LJPair.h:207
void set(std::string name, int i, int j, double value)
Modify a parameter, identified by a string.
Definition: WcaPair.cpp:61
double epsilon_[MaxAtomType][MaxAtomType]
LJ interaction energies.
Definition: LJPair.h:205
double ljShift_[MaxAtomType][MaxAtomType]
shift in LJ potential.
Definition: LJPair.h:210
double eps48_[MaxAtomType][MaxAtomType]
48*epsilon
Definition: LJPair.h:211
int nAtomType_
Total number of atom types.
Definition: LJPair.h:223
Classes used by all simpatico molecular simulations.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
void readParameters(std::istream &in)
Read epsilon and sigma, initialize other variables.
Definition: WcaPair.cpp:21
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 cutoffSq_[MaxAtomType][MaxAtomType]
square of cutoff[][].
Definition: LJPair.h:209
bool isInitialized_
Was this object initialized by calling (read|load)Parameters ?
Definition: LJPair.h:228
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