ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/nonbonded/SC.cpp
Revision: 1665
Committed: Tue Nov 22 20:38:56 2011 UTC (13 years, 5 months ago) by gezelter
File size: 12260 byte(s)
Log Message:
updated copyright notices

File Contents

# Content
1 /*
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] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
40 * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41 */
42
43 #include <stdio.h>
44 #include <string.h>
45
46 #include <cmath>
47 #include "nonbonded/SC.hpp"
48 #include "utils/simError.h"
49 #include "types/NonBondedInteractionType.hpp"
50
51 namespace OpenMD {
52
53
54 SC::SC() : name_("SC"), initialized_(false), forceField_(NULL),
55 scRcut_(0.0), np_(3000) {}
56
57 SCParam SC::getSCParam(AtomType* atomType) {
58
59 // Do sanity checking on the AtomType we were passed before
60 // building any data structures:
61 if (!atomType->isSC()) {
62 sprintf( painCave.errMsg,
63 "SC::getSCParam was passed an atomType (%s) that does not\n"
64 "\tappear to be a Sutton-Chen (SC) atom.\n",
65 atomType->getName().c_str());
66 painCave.severity = OPENMD_ERROR;
67 painCave.isFatal = 1;
68 simError();
69 }
70
71 GenericData* data = atomType->getPropertyByName("SC");
72 if (data == NULL) {
73 sprintf( painCave.errMsg, "SC::getSCParam could not find SC\n"
74 "\tparameters for atomType %s.\n",
75 atomType->getName().c_str());
76 painCave.severity = OPENMD_ERROR;
77 painCave.isFatal = 1;
78 simError();
79 }
80
81 SCParamGenericData* scData = dynamic_cast<SCParamGenericData*>(data);
82 if (scData == NULL) {
83 sprintf( painCave.errMsg,
84 "SC::getSCParam could not convert GenericData to SCParamGenericData\n"
85 "\tfor atom type %s\n", atomType->getName().c_str());
86 painCave.severity = OPENMD_ERROR;
87 painCave.isFatal = 1;
88 simError();
89 }
90
91 return scData->getData();
92 }
93
94 RealType SC::getC(AtomType* atomType) {
95 SCParam scParam = getSCParam(atomType);
96 return scParam.c;
97 }
98
99 RealType SC::getM(AtomType* atomType) {
100 SCParam scParam = getSCParam(atomType);
101 return scParam.m;
102 }
103
104 RealType SC::getM(AtomType* atomType1, AtomType* atomType2) {
105 RealType m1 = getM(atomType1);
106 RealType m2 = getM(atomType2);
107 return 0.5 * (m1 + m2);
108 }
109
110 RealType SC::getN(AtomType* atomType) {
111 SCParam scParam = getSCParam(atomType);
112 return scParam.n;
113 }
114
115 RealType SC::getN(AtomType* atomType1, AtomType* atomType2) {
116 RealType n1 = getN(atomType1);
117 RealType n2 = getN(atomType2);
118 return 0.5 * (n1 + n2);
119 }
120
121 RealType SC::getAlpha(AtomType* atomType) {
122 SCParam scParam = getSCParam(atomType);
123 return scParam.alpha;
124 }
125
126 RealType SC::getAlpha(AtomType* atomType1, AtomType* atomType2) {
127 RealType alpha1 = getAlpha(atomType1);
128 RealType alpha2 = getAlpha(atomType2);
129
130 ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
131 std::string DistanceMix = fopts.getDistanceMixingRule();
132 toUpper(DistanceMix);
133
134 if (DistanceMix == "GEOMETRIC")
135 return sqrt(alpha1 * alpha2);
136 else
137 return 0.5 * (alpha1 + alpha2);
138 }
139
140 RealType SC::getEpsilon(AtomType* atomType) {
141 SCParam scParam = getSCParam(atomType);
142 return scParam.epsilon;
143 }
144
145 RealType SC::getEpsilon(AtomType* atomType1, AtomType* atomType2) {
146 RealType epsilon1 = getEpsilon(atomType1);
147 RealType epsilon2 = getEpsilon(atomType2);
148 return sqrt(epsilon1 * epsilon2);
149 }
150
151 void SC::initialize() {
152 // find all of the SC atom Types:
153 ForceField::AtomTypeContainer* atomTypes = forceField_->getAtomTypes();
154 ForceField::AtomTypeContainer::MapTypeIterator i;
155 AtomType* at;
156
157 for (at = atomTypes->beginType(i); at != NULL;
158 at = atomTypes->nextType(i)) {
159 if (at->isSC())
160 addType(at);
161 }
162 initialized_ = true;
163 }
164
165
166
167 void SC::addType(AtomType* atomType){
168
169 SCAtomData scAtomData;
170
171 scAtomData.c = getC(atomType);
172 scAtomData.m = getM(atomType);
173 scAtomData.n = getN(atomType);
174 scAtomData.alpha = getAlpha(atomType);
175 scAtomData.epsilon = getEpsilon(atomType);
176 scAtomData.rCut = 2.0 * scAtomData.alpha;
177
178 // add it to the map:
179 AtomTypeProperties atp = atomType->getATP();
180
181 pair<map<int,AtomType*>::iterator,bool> ret;
182 ret = SClist.insert( pair<int, AtomType*>(atp.ident, atomType) );
183 if (ret.second == false) {
184 sprintf( painCave.errMsg,
185 "SC already had a previous entry with ident %d\n",
186 atp.ident);
187 painCave.severity = OPENMD_INFO;
188 painCave.isFatal = 0;
189 simError();
190 }
191
192 SCMap[atomType] = scAtomData;
193
194 // Now, iterate over all known types and add to the mixing map:
195
196 map<AtomType*, SCAtomData>::iterator it;
197 for( it = SCMap.begin(); it != SCMap.end(); ++it) {
198
199 AtomType* atype2 = (*it).first;
200
201 SCInteractionData mixer;
202
203 mixer.alpha = getAlpha(atomType, atype2);
204 mixer.rCut = 2.0 * mixer.alpha;
205 mixer.epsilon = getEpsilon(atomType, atype2);
206 mixer.m = getM(atomType, atype2);
207 mixer.n = getN(atomType, atype2);
208
209 RealType dr = mixer.rCut / (np_ - 1);
210 vector<RealType> rvals;
211 vector<RealType> vvals;
212 vector<RealType> phivals;
213
214 rvals.push_back(0.0);
215 vvals.push_back(0.0);
216 phivals.push_back(0.0);
217
218 for (int k = 1; k < np_; k++) {
219 RealType r = dr * k;
220 rvals.push_back(r);
221 vvals.push_back( mixer.epsilon * pow(mixer.alpha/r, mixer.n) );
222 phivals.push_back( pow(mixer.alpha/r, mixer.m) );
223 }
224
225 mixer.vCut = mixer.epsilon * pow(mixer.alpha/mixer.rCut, mixer.n);
226
227 CubicSpline* V = new CubicSpline();
228 V->addPoints(rvals, vvals);
229
230 CubicSpline* phi = new CubicSpline();
231 phi->addPoints(rvals, phivals);
232
233 mixer.V = V;
234 mixer.phi = phi;
235
236 mixer.explicitlySet = false;
237
238 pair<AtomType*, AtomType*> key1, key2;
239 key1 = make_pair(atomType, atype2);
240 key2 = make_pair(atype2, atomType);
241
242 MixingMap[key1] = mixer;
243 if (key2 != key1) {
244 MixingMap[key2] = mixer;
245 }
246 }
247 return;
248 }
249
250 void SC::addExplicitInteraction(AtomType* atype1, AtomType* atype2,
251 RealType epsilon, RealType m, RealType n,
252 RealType alpha) {
253
254 // in case these weren't already in the map
255 addType(atype1);
256 addType(atype2);
257
258 SCInteractionData mixer;
259
260 mixer.epsilon = epsilon;
261 mixer.m = m;
262 mixer.n = n;
263 mixer.alpha = alpha;
264 mixer.rCut = 2.0 * mixer.alpha;
265
266 RealType dr = mixer.rCut / (np_ - 1);
267 vector<RealType> rvals;
268 vector<RealType> vvals;
269 vector<RealType> phivals;
270
271 rvals.push_back(0.0);
272 vvals.push_back(0.0);
273 phivals.push_back(0.0);
274
275 for (int k = 1; k < np_; k++) {
276 RealType r = dr * k;
277 rvals.push_back(r);
278 vvals.push_back( mixer.epsilon * pow(mixer.alpha/r, mixer.n) );
279 phivals.push_back( pow(mixer.alpha/r, mixer.m) );
280 }
281
282 mixer.vCut = mixer.epsilon * pow(mixer.alpha/mixer.rCut, mixer.n);
283
284 CubicSpline* V = new CubicSpline();
285 V->addPoints(rvals, vvals);
286
287 CubicSpline* phi = new CubicSpline();
288 phi->addPoints(rvals, phivals);
289
290 mixer.V = V;
291 mixer.phi = phi;
292
293 mixer.explicitlySet = true;
294
295 pair<AtomType*, AtomType*> key1, key2;
296 key1 = make_pair(atype1, atype2);
297 key2 = make_pair(atype2, atype1);
298
299 MixingMap[key1] = mixer;
300 if (key2 != key1) {
301 MixingMap[key2] = mixer;
302 }
303 return;
304 }
305
306 void SC::calcDensity(InteractionData &idat) {
307
308 if (!initialized_) initialize();
309
310 SCInteractionData mixer = MixingMap[ idat.atypes ];
311
312 RealType rcij = mixer.rCut;
313
314 if ( *(idat.rij) < rcij) {
315 RealType rho = mixer.phi->getValueAt( *(idat.rij) );
316 *(idat.rho1) += rho;
317 *(idat.rho2) += rho;
318 }
319
320 return;
321 }
322
323 void SC::calcFunctional(SelfData &sdat) {
324
325 if (!initialized_) initialize();
326
327 SCAtomData data1 = SCMap[sdat.atype];
328
329 RealType u = - data1.c * data1.epsilon * sqrt( *(sdat.rho) );
330 *(sdat.frho) = u;
331 *(sdat.dfrhodrho) = 0.5 * *(sdat.frho) / *(sdat.rho);
332
333 (*(sdat.pot))[METALLIC_FAMILY] += u;
334 *(sdat.particlePot) += u;
335
336 return;
337 }
338
339
340 void SC::calcForce(InteractionData &idat) {
341
342 if (!initialized_) initialize();
343
344 SCAtomData data1 = SCMap[idat.atypes.first];
345 SCAtomData data2 = SCMap[idat.atypes.second];
346
347 SCInteractionData mixer = MixingMap[idat.atypes];
348
349 RealType rcij = mixer.rCut;
350
351 if ( *(idat.rij) < rcij) {
352 RealType vcij = mixer.vCut;
353
354 pair<RealType, RealType> res;
355
356 res = mixer.phi->getValueAndDerivativeAt( *(idat.rij) );
357 RealType rhtmp = res.first;
358 RealType drhodr = res.second;
359
360 res = mixer.V->getValueAndDerivativeAt( *(idat.rij) );
361 RealType vptmp = res.first;
362 RealType dvpdr = res.second;
363
364 RealType pot_temp = vptmp - vcij;
365 *(idat.vpair) += pot_temp;
366
367 RealType dudr = drhodr * ( *(idat.dfrho1) + *(idat.dfrho2) ) + dvpdr;
368
369 *(idat.f1) += *(idat.d) * dudr / *(idat.rij) ;
370
371 // particlePot is the difference between the full potential and
372 // the full potential without the presence of a particular
373 // particle (atom1).
374 //
375 // This reduces the density at other particle locations, so we
376 // need to recompute the density at atom2 assuming atom1 didn't
377 // contribute. This then requires recomputing the density
378 // functional for atom2 as well.
379
380 *(idat.particlePot1) -= data2.c * data2.epsilon *
381 sqrt( *(idat.rho2) - rhtmp) + *(idat.frho2);
382
383 *(idat.particlePot2) -= data1.c * data1.epsilon *
384 sqrt( *(idat.rho1) - rhtmp) + *(idat.frho1);
385
386 (*(idat.pot))[METALLIC_FAMILY] += pot_temp;
387 }
388
389 return;
390 }
391
392 RealType SC::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
393 if (!initialized_) initialize();
394
395 map<pair<AtomType*, AtomType*>, SCInteractionData>::iterator it;
396 it = MixingMap.find(atypes);
397 if (it == MixingMap.end())
398 return 0.0;
399 else {
400 SCInteractionData mixer = (*it).second;
401 return mixer.rCut;
402 }
403 }
404 }

Properties

Name Value
svn:eol-style native