1 |
gezelter |
1489 |
/* |
2 |
|
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
|
|
* |
4 |
|
|
* The University of Notre Dame grants you ("Licensee") a |
5 |
|
|
* non-exclusive, royalty free, license to use, modify and |
6 |
|
|
* redistribute this software in source and binary code form, provided |
7 |
|
|
* that the following conditions are met: |
8 |
|
|
* |
9 |
|
|
* 1. Redistributions of source code must retain the above copyright |
10 |
|
|
* notice, this list of conditions and the following disclaimer. |
11 |
|
|
* |
12 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
|
|
* notice, this list of conditions and the following disclaimer in the |
14 |
|
|
* documentation and/or other materials provided with the |
15 |
|
|
* distribution. |
16 |
|
|
* |
17 |
|
|
* This software is provided "AS IS," without a warranty of any |
18 |
|
|
* kind. All express or implied conditions, representations and |
19 |
|
|
* warranties, including any implied warranty of merchantability, |
20 |
|
|
* fitness for a particular purpose or non-infringement, are hereby |
21 |
|
|
* excluded. The University of Notre Dame and its licensors shall not |
22 |
|
|
* be liable for any damages suffered by licensee as a result of |
23 |
|
|
* using, modifying or distributing the software or its |
24 |
|
|
* derivatives. In no event will the University of Notre Dame or its |
25 |
|
|
* licensors be liable for any lost revenue, profit or data, or for |
26 |
|
|
* direct, indirect, special, consequential, incidental or punitive |
27 |
|
|
* damages, however caused and regardless of the theory of liability, |
28 |
|
|
* arising out of the use of or inability to use software, even if the |
29 |
|
|
* University of Notre Dame has been advised of the possibility of |
30 |
|
|
* such damages. |
31 |
|
|
* |
32 |
|
|
* SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your |
33 |
|
|
* research, please cite the appropriate papers when you publish your |
34 |
|
|
* work. Good starting points are: |
35 |
|
|
* |
36 |
|
|
* [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |
37 |
|
|
* [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |
38 |
|
|
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). |
39 |
|
|
* [4] Vardeman & Gezelter, in progress (2009). |
40 |
|
|
*/ |
41 |
|
|
|
42 |
|
|
#include <stdio.h> |
43 |
|
|
#include <string.h> |
44 |
|
|
|
45 |
|
|
#include <cmath> |
46 |
|
|
#include "nonbonded/SC.hpp" |
47 |
|
|
#include "utils/simError.h" |
48 |
|
|
#include "types/NonBondedInteractionType.hpp" |
49 |
|
|
|
50 |
|
|
namespace OpenMD { |
51 |
|
|
|
52 |
|
|
|
53 |
gezelter |
1502 |
SC::SC() : name_("SC"), initialized_(false), forceField_(NULL), |
54 |
|
|
scRcut_(0.0), np_(3000) {} |
55 |
gezelter |
1489 |
|
56 |
|
|
SCParam SC::getSCParam(AtomType* atomType) { |
57 |
|
|
|
58 |
|
|
// Do sanity checking on the AtomType we were passed before |
59 |
|
|
// building any data structures: |
60 |
|
|
if (!atomType->isSC()) { |
61 |
|
|
sprintf( painCave.errMsg, |
62 |
|
|
"SC::getSCParam was passed an atomType (%s) that does not\n" |
63 |
|
|
"\tappear to be a Sutton-Chen (SC) atom.\n", |
64 |
|
|
atomType->getName().c_str()); |
65 |
|
|
painCave.severity = OPENMD_ERROR; |
66 |
|
|
painCave.isFatal = 1; |
67 |
|
|
simError(); |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
GenericData* data = atomType->getPropertyByName("SC"); |
71 |
|
|
if (data == NULL) { |
72 |
|
|
sprintf( painCave.errMsg, "SC::getSCParam could not find SC\n" |
73 |
|
|
"\tparameters for atomType %s.\n", |
74 |
|
|
atomType->getName().c_str()); |
75 |
|
|
painCave.severity = OPENMD_ERROR; |
76 |
|
|
painCave.isFatal = 1; |
77 |
|
|
simError(); |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
SCParamGenericData* scData = dynamic_cast<SCParamGenericData*>(data); |
81 |
|
|
if (scData == NULL) { |
82 |
|
|
sprintf( painCave.errMsg, |
83 |
|
|
"SC::getSCParam could not convert GenericData to SCParamGenericData\n" |
84 |
|
|
"\tfor atom type %s\n", atomType->getName().c_str()); |
85 |
|
|
painCave.severity = OPENMD_ERROR; |
86 |
|
|
painCave.isFatal = 1; |
87 |
|
|
simError(); |
88 |
|
|
} |
89 |
|
|
|
90 |
|
|
return scData->getData(); |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
RealType SC::getC(AtomType* atomType) { |
94 |
|
|
SCParam scParam = getSCParam(atomType); |
95 |
|
|
return scParam.c; |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
RealType SC::getM(AtomType* atomType) { |
99 |
|
|
SCParam scParam = getSCParam(atomType); |
100 |
|
|
return scParam.m; |
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
RealType SC::getM(AtomType* atomType1, AtomType* atomType2) { |
104 |
|
|
RealType m1 = getM(atomType1); |
105 |
|
|
RealType m2 = getM(atomType2); |
106 |
|
|
return 0.5 * (m1 + m2); |
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
RealType SC::getN(AtomType* atomType) { |
110 |
|
|
SCParam scParam = getSCParam(atomType); |
111 |
|
|
return scParam.n; |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
RealType SC::getN(AtomType* atomType1, AtomType* atomType2) { |
115 |
|
|
RealType n1 = getN(atomType1); |
116 |
|
|
RealType n2 = getN(atomType2); |
117 |
|
|
return 0.5 * (n1 + n2); |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
RealType SC::getAlpha(AtomType* atomType) { |
121 |
|
|
SCParam scParam = getSCParam(atomType); |
122 |
|
|
return scParam.alpha; |
123 |
|
|
} |
124 |
|
|
|
125 |
|
|
RealType SC::getAlpha(AtomType* atomType1, AtomType* atomType2) { |
126 |
|
|
RealType alpha1 = getAlpha(atomType1); |
127 |
|
|
RealType alpha2 = getAlpha(atomType2); |
128 |
|
|
|
129 |
|
|
ForceFieldOptions& fopts = forceField_->getForceFieldOptions(); |
130 |
|
|
std::string DistanceMix = fopts.getDistanceMixingRule(); |
131 |
|
|
toUpper(DistanceMix); |
132 |
|
|
|
133 |
|
|
if (DistanceMix == "GEOMETRIC") |
134 |
|
|
return sqrt(alpha1 * alpha2); |
135 |
|
|
else |
136 |
|
|
return 0.5 * (alpha1 + alpha2); |
137 |
|
|
} |
138 |
|
|
|
139 |
|
|
RealType SC::getEpsilon(AtomType* atomType) { |
140 |
|
|
SCParam scParam = getSCParam(atomType); |
141 |
|
|
return scParam.epsilon; |
142 |
|
|
} |
143 |
|
|
|
144 |
|
|
RealType SC::getEpsilon(AtomType* atomType1, AtomType* atomType2) { |
145 |
|
|
RealType epsilon1 = getEpsilon(atomType1); |
146 |
|
|
RealType epsilon2 = getEpsilon(atomType2); |
147 |
|
|
return sqrt(epsilon1 * epsilon2); |
148 |
|
|
} |
149 |
|
|
|
150 |
|
|
void SC::initialize() { |
151 |
|
|
// find all of the SC atom Types: |
152 |
|
|
ForceField::AtomTypeContainer* atomTypes = forceField_->getAtomTypes(); |
153 |
|
|
ForceField::AtomTypeContainer::MapTypeIterator i; |
154 |
|
|
AtomType* at; |
155 |
|
|
|
156 |
|
|
for (at = atomTypes->beginType(i); at != NULL; |
157 |
|
|
at = atomTypes->nextType(i)) { |
158 |
|
|
if (at->isSC()) |
159 |
|
|
addType(at); |
160 |
|
|
} |
161 |
|
|
initialized_ = true; |
162 |
|
|
} |
163 |
|
|
|
164 |
|
|
|
165 |
|
|
|
166 |
|
|
void SC::addType(AtomType* atomType){ |
167 |
|
|
|
168 |
|
|
SCAtomData scAtomData; |
169 |
|
|
|
170 |
|
|
scAtomData.c = getC(atomType); |
171 |
|
|
scAtomData.m = getM(atomType); |
172 |
|
|
scAtomData.n = getN(atomType); |
173 |
|
|
scAtomData.alpha = getAlpha(atomType); |
174 |
|
|
scAtomData.epsilon = getEpsilon(atomType); |
175 |
|
|
scAtomData.rCut = 2.0 * scAtomData.alpha; |
176 |
|
|
|
177 |
|
|
// add it to the map: |
178 |
|
|
AtomTypeProperties atp = atomType->getATP(); |
179 |
|
|
|
180 |
|
|
pair<map<int,AtomType*>::iterator,bool> ret; |
181 |
|
|
ret = SClist.insert( pair<int, AtomType*>(atp.ident, atomType) ); |
182 |
|
|
if (ret.second == false) { |
183 |
|
|
sprintf( painCave.errMsg, |
184 |
|
|
"SC already had a previous entry with ident %d\n", |
185 |
|
|
atp.ident); |
186 |
|
|
painCave.severity = OPENMD_INFO; |
187 |
|
|
painCave.isFatal = 0; |
188 |
|
|
simError(); |
189 |
|
|
} |
190 |
|
|
|
191 |
|
|
SCMap[atomType] = scAtomData; |
192 |
|
|
|
193 |
|
|
// Now, iterate over all known types and add to the mixing map: |
194 |
|
|
|
195 |
|
|
map<AtomType*, SCAtomData>::iterator it; |
196 |
|
|
for( it = SCMap.begin(); it != SCMap.end(); ++it) { |
197 |
|
|
|
198 |
|
|
AtomType* atype2 = (*it).first; |
199 |
|
|
|
200 |
|
|
SCInteractionData mixer; |
201 |
|
|
|
202 |
|
|
mixer.alpha = getAlpha(atomType, atype2); |
203 |
|
|
mixer.rCut = 2.0 * mixer.alpha; |
204 |
|
|
mixer.epsilon = getEpsilon(atomType, atype2); |
205 |
|
|
mixer.m = getM(atomType, atype2); |
206 |
|
|
mixer.n = getN(atomType, atype2); |
207 |
|
|
|
208 |
|
|
RealType dr = mixer.rCut / (np_ - 1); |
209 |
|
|
vector<RealType> rvals; |
210 |
|
|
vector<RealType> vvals; |
211 |
|
|
vector<RealType> phivals; |
212 |
|
|
|
213 |
|
|
rvals.push_back(0.0); |
214 |
|
|
vvals.push_back(0.0); |
215 |
|
|
phivals.push_back(0.0); |
216 |
|
|
|
217 |
|
|
for (int k = 1; k < np_; k++) { |
218 |
|
|
RealType r = dr * k; |
219 |
|
|
rvals.push_back(r); |
220 |
|
|
vvals.push_back( mixer.epsilon * pow(mixer.alpha/r, mixer.n) ); |
221 |
|
|
phivals.push_back( pow(mixer.alpha/r, mixer.m) ); |
222 |
|
|
} |
223 |
|
|
|
224 |
|
|
mixer.vCut = mixer.epsilon * pow(mixer.alpha/mixer.rCut, mixer.n); |
225 |
|
|
|
226 |
|
|
CubicSpline* V = new CubicSpline(); |
227 |
|
|
V->addPoints(rvals, vvals); |
228 |
|
|
|
229 |
|
|
CubicSpline* phi = new CubicSpline(); |
230 |
|
|
phi->addPoints(rvals, phivals); |
231 |
|
|
|
232 |
|
|
mixer.V = V; |
233 |
|
|
mixer.phi = phi; |
234 |
|
|
|
235 |
|
|
mixer.explicitlySet = false; |
236 |
|
|
|
237 |
|
|
pair<AtomType*, AtomType*> key1, key2; |
238 |
|
|
key1 = make_pair(atomType, atype2); |
239 |
|
|
key2 = make_pair(atype2, atomType); |
240 |
|
|
|
241 |
|
|
MixingMap[key1] = mixer; |
242 |
|
|
if (key2 != key1) { |
243 |
|
|
MixingMap[key2] = mixer; |
244 |
|
|
} |
245 |
|
|
} |
246 |
|
|
return; |
247 |
|
|
} |
248 |
|
|
|
249 |
|
|
void SC::addExplicitInteraction(AtomType* atype1, AtomType* atype2, |
250 |
|
|
RealType epsilon, RealType m, RealType n, |
251 |
|
|
RealType alpha) { |
252 |
|
|
|
253 |
|
|
// in case these weren't already in the map |
254 |
|
|
addType(atype1); |
255 |
|
|
addType(atype2); |
256 |
|
|
|
257 |
|
|
SCInteractionData mixer; |
258 |
|
|
|
259 |
|
|
mixer.epsilon = epsilon; |
260 |
|
|
mixer.m = m; |
261 |
|
|
mixer.n = n; |
262 |
|
|
mixer.alpha = alpha; |
263 |
|
|
mixer.rCut = 2.0 * mixer.alpha; |
264 |
|
|
|
265 |
|
|
RealType dr = mixer.rCut / (np_ - 1); |
266 |
|
|
vector<RealType> rvals; |
267 |
|
|
vector<RealType> vvals; |
268 |
|
|
vector<RealType> phivals; |
269 |
|
|
|
270 |
|
|
rvals.push_back(0.0); |
271 |
|
|
vvals.push_back(0.0); |
272 |
|
|
phivals.push_back(0.0); |
273 |
|
|
|
274 |
|
|
for (int k = 1; k < np_; k++) { |
275 |
|
|
RealType r = dr * k; |
276 |
|
|
rvals.push_back(r); |
277 |
|
|
vvals.push_back( mixer.epsilon * pow(mixer.alpha/r, mixer.n) ); |
278 |
|
|
phivals.push_back( pow(mixer.alpha/r, mixer.m) ); |
279 |
|
|
} |
280 |
|
|
|
281 |
|
|
mixer.vCut = mixer.epsilon * pow(mixer.alpha/mixer.rCut, mixer.n); |
282 |
|
|
|
283 |
|
|
CubicSpline* V = new CubicSpline(); |
284 |
|
|
V->addPoints(rvals, vvals); |
285 |
|
|
|
286 |
|
|
CubicSpline* phi = new CubicSpline(); |
287 |
|
|
phi->addPoints(rvals, phivals); |
288 |
|
|
|
289 |
|
|
mixer.V = V; |
290 |
|
|
mixer.phi = phi; |
291 |
|
|
|
292 |
|
|
mixer.explicitlySet = true; |
293 |
|
|
|
294 |
|
|
pair<AtomType*, AtomType*> key1, key2; |
295 |
|
|
key1 = make_pair(atype1, atype2); |
296 |
|
|
key2 = make_pair(atype2, atype1); |
297 |
|
|
|
298 |
|
|
MixingMap[key1] = mixer; |
299 |
|
|
if (key2 != key1) { |
300 |
|
|
MixingMap[key2] = mixer; |
301 |
|
|
} |
302 |
|
|
return; |
303 |
|
|
} |
304 |
|
|
|
305 |
gezelter |
1502 |
void SC::calcDensity(DensityData ddat) { |
306 |
gezelter |
1489 |
|
307 |
|
|
if (!initialized_) initialize(); |
308 |
|
|
|
309 |
gezelter |
1502 |
SCInteractionData mixer = MixingMap[make_pair(ddat.atype1, ddat.atype2)]; |
310 |
gezelter |
1489 |
|
311 |
gezelter |
1502 |
RealType rcij = mixer.rCut; |
312 |
gezelter |
1489 |
|
313 |
gezelter |
1502 |
if (ddat.rij < rcij) { |
314 |
|
|
ddat.rho_i_at_j = mixer.phi->getValueAt(ddat.rij); |
315 |
|
|
ddat.rho_j_at_i = ddat.rho_i_at_j; |
316 |
|
|
} else { |
317 |
|
|
ddat.rho_i_at_j = 0.0; |
318 |
|
|
ddat.rho_j_at_i = 0.0; |
319 |
|
|
} |
320 |
|
|
|
321 |
gezelter |
1489 |
return; |
322 |
|
|
} |
323 |
|
|
|
324 |
gezelter |
1502 |
void SC::calcFunctional(FunctionalData fdat) { |
325 |
gezelter |
1489 |
|
326 |
|
|
if (!initialized_) initialize(); |
327 |
|
|
|
328 |
gezelter |
1502 |
SCAtomData data1 = SCMap[fdat.atype]; |
329 |
gezelter |
1489 |
|
330 |
gezelter |
1502 |
fdat.frho = - data1.c * data1.epsilon * sqrt(fdat.rho); |
331 |
|
|
fdat.dfrhodrho = 0.5 * fdat.frho / fdat.rho; |
332 |
gezelter |
1489 |
|
333 |
|
|
return; |
334 |
|
|
} |
335 |
gezelter |
1502 |
|
336 |
gezelter |
1489 |
|
337 |
gezelter |
1502 |
void SC::calcForce(InteractionData idat) { |
338 |
gezelter |
1489 |
|
339 |
|
|
if (!initialized_) initialize(); |
340 |
|
|
|
341 |
gezelter |
1502 |
SCAtomData data1 = SCMap[idat.atype1]; |
342 |
|
|
SCAtomData data2 = SCMap[idat.atype2]; |
343 |
gezelter |
1489 |
|
344 |
gezelter |
1502 |
SCInteractionData mixer = MixingMap[make_pair(idat.atype1, idat.atype2)]; |
345 |
gezelter |
1489 |
|
346 |
|
|
RealType rcij = mixer.rCut; |
347 |
|
|
|
348 |
gezelter |
1502 |
if (idat.rij < rcij) { |
349 |
|
|
RealType vcij = mixer.vCut; |
350 |
|
|
|
351 |
|
|
pair<RealType, RealType> res; |
352 |
|
|
|
353 |
|
|
res = mixer.phi->getValueAndDerivativeAt(idat.rij); |
354 |
|
|
RealType rhtmp = res.first; |
355 |
|
|
RealType drhodr = res.second; |
356 |
|
|
|
357 |
|
|
res = mixer.V->getValueAndDerivativeAt(idat.rij); |
358 |
|
|
RealType vptmp = res.first; |
359 |
|
|
RealType dvpdr = res.second; |
360 |
|
|
|
361 |
|
|
RealType pot_temp = vptmp - vcij; |
362 |
|
|
idat.vpair += pot_temp; |
363 |
|
|
|
364 |
|
|
RealType dudr = drhodr * (idat.dfrho1 + idat.dfrho2) + dvpdr; |
365 |
|
|
|
366 |
|
|
idat.f1 += idat.d * dudr / idat.rij; |
367 |
gezelter |
1489 |
|
368 |
gezelter |
1502 |
// particle_pot is the difference between the full potential |
369 |
|
|
// and the full potential without the presence of a particular |
370 |
|
|
// particle (atom1). |
371 |
|
|
// |
372 |
|
|
// This reduces the density at other particle locations, so |
373 |
|
|
// we need to recompute the density at atom2 assuming atom1 |
374 |
|
|
// didn't contribute. This then requires recomputing the |
375 |
|
|
// density functional for atom2 as well. |
376 |
|
|
// |
377 |
|
|
// Most of the particle_pot heavy lifting comes from the |
378 |
|
|
// pair interaction, and will be handled by vpair. |
379 |
gezelter |
1489 |
|
380 |
gezelter |
1502 |
idat.fshift1 = - data1.c * data1.epsilon * sqrt(idat.rho1 - rhtmp); |
381 |
|
|
idat.fshift2 = - data2.c * data2.epsilon * sqrt(idat.rho2 - rhtmp); |
382 |
|
|
|
383 |
|
|
idat.pot += pot_temp; |
384 |
|
|
} |
385 |
|
|
|
386 |
gezelter |
1489 |
return; |
387 |
|
|
} |
388 |
gezelter |
1505 |
|
389 |
|
|
RealType SC::getSuggestedCutoffRadius(AtomType* at1, AtomType* at2) { |
390 |
|
|
if (!initialized_) initialize(); |
391 |
|
|
pair<AtomType*, AtomType*> key = make_pair(at1, at2); |
392 |
|
|
map<pair<AtomType*, AtomType*>, SCInteractionData>::iterator it; |
393 |
|
|
it = MixingMap.find(key); |
394 |
|
|
if (it == MixingMap.end()) |
395 |
|
|
return 0.0; |
396 |
|
|
else { |
397 |
|
|
SCInteractionData mixer = (*it).second; |
398 |
|
|
return mixer.rCut; |
399 |
|
|
} |
400 |
|
|
} |
401 |
gezelter |
1489 |
} |