ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/nonbonded/SC.cpp
Revision: 1710
Committed: Fri May 18 21:44:02 2012 UTC (12 years, 11 months ago) by gezelter
File size: 10895 byte(s)
Log Message:
Added an adapter layer between the AtomType and the rest of the code to 
handle the bolt-on capabilities of new types. 

Fixed a long-standing bug in how storageLayout was being set to the maximum
possible value.

Started to add infrastructure for Polarizable and fluc-Q calculations.

File Contents

# User Rev Content
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 gezelter 1665 * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
40     * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41 gezelter 1489 */
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 gezelter 1502 SC::SC() : name_("SC"), initialized_(false), forceField_(NULL),
55     scRcut_(0.0), np_(3000) {}
56 gezelter 1489
57     RealType SC::getM(AtomType* atomType1, AtomType* atomType2) {
58 gezelter 1710 SuttonChenAdapter sca1 = SuttonChenAdapter(atomType1);
59     SuttonChenAdapter sca2 = SuttonChenAdapter(atomType2);
60     RealType m1 = sca1.getM();
61     RealType m2 = sca2.getM();
62 gezelter 1489 return 0.5 * (m1 + m2);
63     }
64    
65     RealType SC::getN(AtomType* atomType1, AtomType* atomType2) {
66 gezelter 1710 SuttonChenAdapter sca1 = SuttonChenAdapter(atomType1);
67     SuttonChenAdapter sca2 = SuttonChenAdapter(atomType2);
68     RealType n1 = sca1.getN();
69     RealType n2 = sca2.getN();
70 gezelter 1489 return 0.5 * (n1 + n2);
71     }
72    
73     RealType SC::getAlpha(AtomType* atomType1, AtomType* atomType2) {
74 gezelter 1710 SuttonChenAdapter sca1 = SuttonChenAdapter(atomType1);
75     SuttonChenAdapter sca2 = SuttonChenAdapter(atomType2);
76     RealType alpha1 = sca1.getAlpha();
77     RealType alpha2 = sca2.getAlpha();
78 gezelter 1489
79     ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
80     std::string DistanceMix = fopts.getDistanceMixingRule();
81     toUpper(DistanceMix);
82    
83     if (DistanceMix == "GEOMETRIC")
84     return sqrt(alpha1 * alpha2);
85     else
86     return 0.5 * (alpha1 + alpha2);
87     }
88    
89 gezelter 1710 RealType SC::getEpsilon(AtomType* atomType1, AtomType* atomType2) {
90     SuttonChenAdapter sca1 = SuttonChenAdapter(atomType1);
91     SuttonChenAdapter sca2 = SuttonChenAdapter(atomType2);
92     RealType epsilon1 = sca1.getEpsilon();
93     RealType epsilon2 = sca2.getEpsilon();
94 gezelter 1489 return sqrt(epsilon1 * epsilon2);
95     }
96    
97     void SC::initialize() {
98     // find all of the SC atom Types:
99     ForceField::AtomTypeContainer* atomTypes = forceField_->getAtomTypes();
100     ForceField::AtomTypeContainer::MapTypeIterator i;
101     AtomType* at;
102    
103     for (at = atomTypes->beginType(i); at != NULL;
104     at = atomTypes->nextType(i)) {
105 gezelter 1710 SuttonChenAdapter sca = SuttonChenAdapter(at);
106     if (sca.isSuttonChen())
107 gezelter 1489 addType(at);
108     }
109     initialized_ = true;
110     }
111    
112    
113    
114     void SC::addType(AtomType* atomType){
115    
116 gezelter 1710 SuttonChenAdapter sca = SuttonChenAdapter(atomType);
117 gezelter 1489 SCAtomData scAtomData;
118    
119 gezelter 1710 scAtomData.c = sca.getC();
120     scAtomData.m = sca.getM();
121     scAtomData.n = sca.getN();
122     scAtomData.alpha = sca.getAlpha();
123     scAtomData.epsilon = sca.getEpsilon();
124 gezelter 1489 scAtomData.rCut = 2.0 * scAtomData.alpha;
125    
126     // add it to the map:
127    
128     pair<map<int,AtomType*>::iterator,bool> ret;
129 gezelter 1710 ret = SClist.insert( pair<int, AtomType*>(atomType->getIdent(), atomType) );
130 gezelter 1489 if (ret.second == false) {
131     sprintf( painCave.errMsg,
132     "SC already had a previous entry with ident %d\n",
133 gezelter 1710 atomType->getIdent() );
134 gezelter 1489 painCave.severity = OPENMD_INFO;
135     painCave.isFatal = 0;
136     simError();
137     }
138    
139     SCMap[atomType] = scAtomData;
140    
141     // Now, iterate over all known types and add to the mixing map:
142    
143     map<AtomType*, SCAtomData>::iterator it;
144     for( it = SCMap.begin(); it != SCMap.end(); ++it) {
145    
146     AtomType* atype2 = (*it).first;
147    
148     SCInteractionData mixer;
149    
150     mixer.alpha = getAlpha(atomType, atype2);
151     mixer.rCut = 2.0 * mixer.alpha;
152     mixer.epsilon = getEpsilon(atomType, atype2);
153     mixer.m = getM(atomType, atype2);
154     mixer.n = getN(atomType, atype2);
155    
156     RealType dr = mixer.rCut / (np_ - 1);
157     vector<RealType> rvals;
158     vector<RealType> vvals;
159     vector<RealType> phivals;
160    
161     rvals.push_back(0.0);
162     vvals.push_back(0.0);
163     phivals.push_back(0.0);
164    
165     for (int k = 1; k < np_; k++) {
166     RealType r = dr * k;
167     rvals.push_back(r);
168     vvals.push_back( mixer.epsilon * pow(mixer.alpha/r, mixer.n) );
169     phivals.push_back( pow(mixer.alpha/r, mixer.m) );
170     }
171    
172     mixer.vCut = mixer.epsilon * pow(mixer.alpha/mixer.rCut, mixer.n);
173    
174     CubicSpline* V = new CubicSpline();
175     V->addPoints(rvals, vvals);
176    
177     CubicSpline* phi = new CubicSpline();
178     phi->addPoints(rvals, phivals);
179    
180     mixer.V = V;
181     mixer.phi = phi;
182    
183     mixer.explicitlySet = false;
184    
185     pair<AtomType*, AtomType*> key1, key2;
186     key1 = make_pair(atomType, atype2);
187     key2 = make_pair(atype2, atomType);
188    
189     MixingMap[key1] = mixer;
190     if (key2 != key1) {
191     MixingMap[key2] = mixer;
192     }
193     }
194     return;
195     }
196    
197     void SC::addExplicitInteraction(AtomType* atype1, AtomType* atype2,
198     RealType epsilon, RealType m, RealType n,
199     RealType alpha) {
200    
201     // in case these weren't already in the map
202     addType(atype1);
203     addType(atype2);
204    
205     SCInteractionData mixer;
206    
207     mixer.epsilon = epsilon;
208     mixer.m = m;
209     mixer.n = n;
210     mixer.alpha = alpha;
211     mixer.rCut = 2.0 * mixer.alpha;
212    
213     RealType dr = mixer.rCut / (np_ - 1);
214     vector<RealType> rvals;
215     vector<RealType> vvals;
216     vector<RealType> phivals;
217    
218     rvals.push_back(0.0);
219     vvals.push_back(0.0);
220     phivals.push_back(0.0);
221    
222     for (int k = 1; k < np_; k++) {
223     RealType r = dr * k;
224     rvals.push_back(r);
225     vvals.push_back( mixer.epsilon * pow(mixer.alpha/r, mixer.n) );
226     phivals.push_back( pow(mixer.alpha/r, mixer.m) );
227     }
228    
229     mixer.vCut = mixer.epsilon * pow(mixer.alpha/mixer.rCut, mixer.n);
230    
231     CubicSpline* V = new CubicSpline();
232     V->addPoints(rvals, vvals);
233    
234     CubicSpline* phi = new CubicSpline();
235     phi->addPoints(rvals, phivals);
236    
237     mixer.V = V;
238     mixer.phi = phi;
239    
240     mixer.explicitlySet = true;
241    
242     pair<AtomType*, AtomType*> key1, key2;
243     key1 = make_pair(atype1, atype2);
244     key2 = make_pair(atype2, atype1);
245    
246     MixingMap[key1] = mixer;
247     if (key2 != key1) {
248     MixingMap[key2] = mixer;
249     }
250     return;
251     }
252    
253 gezelter 1545 void SC::calcDensity(InteractionData &idat) {
254 gezelter 1489
255     if (!initialized_) initialize();
256    
257 gezelter 1571 SCInteractionData mixer = MixingMap[ idat.atypes ];
258 gezelter 1489
259 gezelter 1502 RealType rcij = mixer.rCut;
260 gezelter 1489
261 gezelter 1554 if ( *(idat.rij) < rcij) {
262 gezelter 1575 RealType rho = mixer.phi->getValueAt( *(idat.rij) );
263     *(idat.rho1) += rho;
264     *(idat.rho2) += rho;
265     }
266 gezelter 1554
267 gezelter 1489 return;
268     }
269    
270 gezelter 1545 void SC::calcFunctional(SelfData &sdat) {
271 gezelter 1489
272     if (!initialized_) initialize();
273    
274 gezelter 1545 SCAtomData data1 = SCMap[sdat.atype];
275 gezelter 1575
276     RealType u = - data1.c * data1.epsilon * sqrt( *(sdat.rho) );
277     *(sdat.frho) = u;
278 gezelter 1554 *(sdat.dfrhodrho) = 0.5 * *(sdat.frho) / *(sdat.rho);
279 gezelter 1575
280 gezelter 1583 (*(sdat.pot))[METALLIC_FAMILY] += u;
281 gezelter 1575 *(sdat.particlePot) += u;
282 gezelter 1489
283     return;
284     }
285 gezelter 1502
286 gezelter 1489
287 gezelter 1536 void SC::calcForce(InteractionData &idat) {
288 gezelter 1489
289     if (!initialized_) initialize();
290    
291 gezelter 1571 SCAtomData data1 = SCMap[idat.atypes.first];
292     SCAtomData data2 = SCMap[idat.atypes.second];
293 gezelter 1489
294 gezelter 1571 SCInteractionData mixer = MixingMap[idat.atypes];
295 gezelter 1489
296     RealType rcij = mixer.rCut;
297    
298 gezelter 1554 if ( *(idat.rij) < rcij) {
299 gezelter 1502 RealType vcij = mixer.vCut;
300    
301     pair<RealType, RealType> res;
302    
303 gezelter 1554 res = mixer.phi->getValueAndDerivativeAt( *(idat.rij) );
304 gezelter 1502 RealType rhtmp = res.first;
305     RealType drhodr = res.second;
306    
307 gezelter 1554 res = mixer.V->getValueAndDerivativeAt( *(idat.rij) );
308 gezelter 1502 RealType vptmp = res.first;
309     RealType dvpdr = res.second;
310    
311     RealType pot_temp = vptmp - vcij;
312 gezelter 1554 *(idat.vpair) += pot_temp;
313 gezelter 1502
314 gezelter 1554 RealType dudr = drhodr * ( *(idat.dfrho1) + *(idat.dfrho2) ) + dvpdr;
315 gezelter 1502
316 gezelter 1554 *(idat.f1) += *(idat.d) * dudr / *(idat.rij) ;
317 gezelter 1489
318 gezelter 1575 // particlePot is the difference between the full potential and
319     // the full potential without the presence of a particular
320 gezelter 1502 // particle (atom1).
321     //
322 gezelter 1575 // This reduces the density at other particle locations, so we
323     // need to recompute the density at atom2 assuming atom1 didn't
324     // contribute. This then requires recomputing the density
325     // functional for atom2 as well.
326    
327     *(idat.particlePot1) -= data2.c * data2.epsilon *
328     sqrt( *(idat.rho2) - rhtmp) + *(idat.frho2);
329    
330 gezelter 1586 *(idat.particlePot2) -= data1.c * data1.epsilon *
331 gezelter 1575 sqrt( *(idat.rho1) - rhtmp) + *(idat.frho1);
332 gezelter 1489
333 gezelter 1582 (*(idat.pot))[METALLIC_FAMILY] += pot_temp;
334 gezelter 1502 }
335    
336 gezelter 1489 return;
337     }
338 gezelter 1505
339 gezelter 1545 RealType SC::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
340 gezelter 1505 if (!initialized_) initialize();
341 gezelter 1545
342 gezelter 1505 map<pair<AtomType*, AtomType*>, SCInteractionData>::iterator it;
343 gezelter 1545 it = MixingMap.find(atypes);
344 gezelter 1505 if (it == MixingMap.end())
345     return 0.0;
346     else {
347     SCInteractionData mixer = (*it).second;
348     return mixer.rCut;
349     }
350     }
351 gezelter 1489 }

Properties

Name Value
svn:eol-style native