-
Notifications
You must be signed in to change notification settings - Fork 0
/
FFSwitchMartini.h
259 lines (218 loc) · 8.42 KB
/
FFSwitchMartini.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/*******************************************************************************
GPU OPTIMIZED MONTE CARLO (GOMC) 2.31
Copyright (C) 2018 GOMC Group
A copy of the GNU General Public License can be found in the COPYRIGHT.txt
along with this program, also can be found at <http://www.gnu.org/licenses/>.
********************************************************************************/
#ifndef FF_SWITCH_MARTINI_H
#define FF_SWITCH_MARTINI_H
#include "EnsemblePreprocessor.h" //For "MIE_INT_ONLY" preprocessor.
#include "FFConst.h" //constants related to particles.
#include "BasicTypes.h" //for uint
#include "NumLib.h" //For Cb, Sq
#include "FFParticle.h"
///////////////////////////////////////////////////////////////////////
////////////////////////// LJ Switch Martini Style ////////////////////////////
///////////////////////////////////////////////////////////////////////
// LJ potential calculation:
// Eij = cn * eps_ij * ( sig_ij^n * (1/rij^n + phi(n)) -
// sig_ij^6 * (1/rij^6 + phi(6)))
// cn = n/(n-6) * ((n/6)^(6/(n-6)))
//
// Eelec = qi*qj*(1/rij + phi(1))
// Welec = qi*qj*(1/rij^3 + phiW(1)/r)
//
// phi(x) = -Cx , if r < rswitch
// phi(x) = -Ax *(r - rswitch)^3/3 - Bx * (r - rswitch)^4 / 4 - Cx ,if r>rswitch
//
// Ax = x * ((x + 1) * rswitch - (x + 4) * rcut) /
// (rcut^(x + 2)) * (rcut - rswitch)^2)
// Bx = x * ((x + 1) * rswitch - (x + 3) * rcut) /
// (rcut^(x + 2)) * (rcut - rswitch)^3)
// Cx = 1/rcut^x - Ax * (rcut - rswitch)^3 / 3 - Bx * (rcut - rswitch)^4 / 4
//
// Virial Calculation
//
// Wij = cn * eps_ij * ( sig_ij^n * (n/rij^(n+2) + phiW(n)/rij) -
// sig_ij^6 * (6/rij^(6+2) + phiW(6)/r))
//
// phiW(x) = 0 , if r < rswitch
// phiW(x) = Ax *(r - rswitch)^2 + Bx * (r - rswitch)^3 ,if r > rswitch
//
//
struct FF_SWITCH_MARTINI : public FFParticle {
public:
virtual double CalcEn(const double distSq,
const uint kind1, const uint kind2) const;
virtual double CalcVir(const double distSq,
const uint kind1, const uint kind2) const;
virtual void CalcAdd_1_4(double& en, const double distSq,
const uint kind1, const uint kind2) const;
// coulomb interaction functions
virtual double CalcCoulomb(const double distSq,
const double qi_qj_Fact) const;
virtual double CalcCoulombEn(const double distSq,
const double qi_qj_Fact) const;
virtual double CalcCoulombVir(const double distSq,
const double qi_qj) const;
virtual void CalcCoulombAdd_1_4(double& en, const double distSq,
const double qi_qj_Fact,
const bool NB) const;
//!Returns Ezero, no energy correction
virtual double EnergyLRC(const uint kind1, const uint kind2) const
{
return 0.0;
}
//!!Returns Ezero, no virial correction
virtual double VirialLRC(const uint kind1, const uint kind2) const
{
return 0.0;
}
};
inline void FF_SWITCH_MARTINI::CalcAdd_1_4(double& en, const double distSq,
const uint kind1,
const uint kind2) const
{
uint index = FlatIndex(kind1, kind2);
double r_2 = 1.0 / distSq;
double r_4 = r_2 * r_2;
double r_6 = r_4 * r_2;
#ifdef MIE_INT_ONLY
uint n_ij = n_1_4[index];
double r_n = num::POW(r_2, r_4, attract, n_ij);
#else
double n_ij = n_1_4[index];
double r_n = pow(sqrt(r_2), n_ij);
#endif
double rij_ron = sqrt(distSq) - rOn;
double rij_ron_2 = rij_ron * rij_ron;
double rij_ron_3 = rij_ron_2 * rij_ron;
double rij_ron_4 = rij_ron_2 * rij_ron_2;
double shifttempRep = -(An_1_4[index] / 3.0) * rij_ron_3 -
(Bn_1_4[index] / 4.0) * rij_ron_4 - Cn_1_4[index];
double shifttempAtt = -(A6 / 3.0) * rij_ron_3 - (B6 / 4.0) * rij_ron_4 - C6;
const double shiftRep = ( distSq > rOnSq ? shifttempRep : -Cn_1_4[index]);
const double shiftAtt = ( distSq > rOnSq ? shifttempAtt : -C6);
en += epsilon_cn_1_4[index] * (sign_1_4[index] * (r_n + shiftRep) -
sig6_1_4[index] * (r_6 + shiftAtt));
}
inline void FF_SWITCH_MARTINI::CalcCoulombAdd_1_4(double& en,
const double distSq,
const double qi_qj_Fact,
const bool NB) const
{
double dist = sqrt(distSq);
if(NB)
en += qi_qj_Fact / dist;
else
en += qi_qj_Fact * scaling_14 / dist;
}
//mie potential
inline double FF_SWITCH_MARTINI::CalcEn(const double distSq,
const uint kind1,
const uint kind2) const
{
uint index = FlatIndex(kind1, kind2);
double r_2 = 1.0 / distSq;
double r_4 = r_2 * r_2;
double r_6 = r_4 * r_2;
#ifdef MIE_INT_ONLY
uint n_ij = n[index];
double r_n = num::POW(r_2, r_4, attract, n_ij);
#else
double n_ij = n[index];
double r_n = pow(sqrt(r_2), n_ij);
#endif
double rij_ron = sqrt(distSq) - rOn;
double rij_ron_2 = rij_ron * rij_ron;
double rij_ron_3 = rij_ron_2 * rij_ron;
double rij_ron_4 = rij_ron_2 * rij_ron_2;
double shifttempRep = -(An[index] / 3.0) * rij_ron_3 -
(Bn[index] / 4.0) * rij_ron_4 - Cn[index];
double shifttempAtt = -(A6 / 3.0) * rij_ron_3 - (B6 / 4.0) * rij_ron_4 - C6;
const double shiftRep = ( distSq > rOnSq ? shifttempRep : -Cn[index]);
const double shiftAtt = ( distSq > rOnSq ? shifttempAtt : -C6);
double Eij = epsilon_cn[index] * (sign[index] * (r_n + shiftRep) -
sig6[index] * (r_6 + shiftAtt));
return Eij;
}
inline double FF_SWITCH_MARTINI::CalcCoulomb(const double distSq,
const double qi_qj_Fact) const
{
if(ewald) {
double dist = sqrt(distSq);
double val = alpha * dist;
return qi_qj_Fact * erfc(val) / dist;
} else {
// in Martini, the Coulomb switching distance is zero, so we will have
// sqrt(distSq) - rOnCoul = sqrt(distSq)
double dist = sqrt(distSq);
double rij_ronCoul_3 = dist * distSq;
double rij_ronCoul_4 = distSq * distSq;
double coul = -(A1 / 3.0) * rij_ronCoul_3 - (B1 / 4.0) * rij_ronCoul_4 - C1;
return qi_qj_Fact * diElectric_1 * (1.0 / dist + coul);
}
}
//will be used in energy calculation after each move
inline double FF_SWITCH_MARTINI::CalcCoulombEn(const double distSq,
const double qi_qj_Fact) const
{
if(distSq <= rCutLowSq)
return num::BIGNUM;
if(ewald) {
double dist = sqrt(distSq);
double val = alpha * dist;
return qi_qj_Fact * erfc(val) / dist;
} else {
// in Martini, the Coulomb switching distance is zero, so we will have
// sqrt(distSq) - rOnCoul = sqrt(distSq)
double dist = sqrt(distSq);
double rij_ronCoul_3 = dist * distSq;
double rij_ronCoul_4 = distSq * distSq;
double coul = -(A1 / 3.0) * rij_ronCoul_3 - (B1 / 4.0) * rij_ronCoul_4 - C1;
return qi_qj_Fact * diElectric_1 * (1.0 / dist + coul);
}
}
//mie potential
inline double FF_SWITCH_MARTINI::CalcVir(const double distSq,
const uint kind1,
const uint kind2) const
{
uint index = FlatIndex(kind1, kind2);
double n_ij = n[index];
double r_1 = 1.0 / sqrt(distSq);
double r_8 = pow(r_1, 8);
double r_n2 = pow(r_1, n_ij + 2);
double rij_ron = sqrt(distSq) - rOn;
double rij_ron_2 = rij_ron * rij_ron;
double rij_ron_3 = rij_ron_2 * rij_ron;
double dshifttempRep = An[index] * rij_ron_2 + Bn[index] * rij_ron_3;
double dshifttempAtt = A6 * rij_ron_2 + B6 * rij_ron_3;
const double dshiftRep = ( distSq > rOnSq ? dshifttempRep * r_1 : 0);
const double dshiftAtt = ( distSq > rOnSq ? dshifttempAtt * r_1 : 0);
double Wij = epsilon_cn[index] * (sign[index] *
(n_ij * r_n2 + dshiftRep) -
sig6[index] * (6.0 * r_8 + dshiftAtt));
return Wij;
}
inline double FF_SWITCH_MARTINI::CalcCoulombVir(const double distSq,
const double qi_qj) const
{
if(ewald) {
double dist = sqrt(distSq);
double constValue = 2.0 * alpha / sqrt(M_PI);
double expConstValue = exp(-1.0 * alpha * alpha * distSq);
double temp = erfc(alpha * dist);
return qi_qj * (temp / dist + constValue * expConstValue) / distSq;
} else {
// in Martini, the Coulomb switching distance is zero, so we will have
// sqrt(distSq) - rOnCoul = sqrt(distSq)
double dist = sqrt(distSq);
double rij_ronCoul_2 = distSq;
double rij_ronCoul_3 = dist * distSq;
double rij_ronCoul_4 = distSq * distSq;
double virCoul = A1 / rij_ronCoul_2 + B1 / rij_ronCoul_3;
return qi_qj * diElectric_1 * ( 1.0 / (dist * distSq) + virCoul / dist);
}
}
#endif /*FF_SWITCH_MARTINI_H*/