OpenMD 3.2
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
SC.cpp
1/*
2 * Copyright (c) 2004-present, The University of Notre Dame. All rights
3 * reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
32 * research, please cite the following paper when you publish your work:
33 *
34 * [1] Drisko et al., J. Open Source Softw. 9, 7004 (2024).
35 *
36 * Good starting points for code and simulation methodology are:
37 *
38 * [2] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
39 * [3] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
40 * [4] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
41 * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
42 * [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
43 * [7] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
44 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
45 * [9] Drisko & Gezelter, J. Chem. Theory Comput. 20, 4986-4997 (2024).
46 */
47
48#include "nonbonded/SC.hpp"
49
50#include <cmath>
51#include <cstdio>
52#include <cstring>
53
55#include "utils/simError.h"
56
57namespace OpenMD {
58
59 SC::SC() : name_("SC"), initialized_(false), forceField_(NULL), np_(3000) {}
60
61 SC::~SC() {
62 initialized_ = false;
63
64 MixingMap.clear();
65 SCtypes.clear();
66 SCdata.clear();
67 SCtids.clear();
68 }
69
70 RealType SC::getM(AtomType* atomType1, AtomType* atomType2) {
71 SuttonChenAdapter sca1 = SuttonChenAdapter(atomType1);
72 SuttonChenAdapter sca2 = SuttonChenAdapter(atomType2);
73 RealType m1 = sca1.getM();
74 RealType m2 = sca2.getM();
75 return 0.5 * (m1 + m2);
76 }
77
78 RealType SC::getN(AtomType* atomType1, AtomType* atomType2) {
79 SuttonChenAdapter sca1 = SuttonChenAdapter(atomType1);
80 SuttonChenAdapter sca2 = SuttonChenAdapter(atomType2);
81 RealType n1 = sca1.getN();
82 RealType n2 = sca2.getN();
83 return 0.5 * (n1 + n2);
84 }
85
86 RealType SC::getAlpha(AtomType* atomType1, AtomType* atomType2) {
87 SuttonChenAdapter sca1 = SuttonChenAdapter(atomType1);
88 SuttonChenAdapter sca2 = SuttonChenAdapter(atomType2);
89 RealType alpha1 = sca1.getAlpha();
90 RealType alpha2 = sca2.getAlpha();
91
92 ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
93 std::string DistanceMix = fopts.getDistanceMixingRule();
94 toUpper(DistanceMix);
95
96 if (DistanceMix == "GEOMETRIC")
97 return sqrt(alpha1 * alpha2);
98 else
99 return 0.5 * (alpha1 + alpha2);
100 }
101
102 RealType SC::getEpsilon(AtomType* atomType1, AtomType* atomType2) {
103 SuttonChenAdapter sca1 = SuttonChenAdapter(atomType1);
104 SuttonChenAdapter sca2 = SuttonChenAdapter(atomType2);
105 RealType epsilon1 = sca1.getEpsilon();
106 RealType epsilon2 = sca2.getEpsilon();
107 return sqrt(epsilon1 * epsilon2);
108 }
109
110 void SC::initialize() {
111 // find all of the SC atom Types:
112 SCtypes.clear();
113 SCtids.clear();
114 SCdata.clear();
115 MixingMap.clear();
116 nSC_ = 0;
117
118 SCtids.resize(forceField_->getNAtomType(), -1);
119
120 AtomTypeSet::iterator at;
121 for (at = simTypes_.begin(); at != simTypes_.end(); ++at) {
122 if ((*at)->isSC()) nSC_++;
123 }
124 SCdata.resize(nSC_);
125 MixingMap.resize(nSC_);
126 for (at = simTypes_.begin(); at != simTypes_.end(); ++at) {
127 if ((*at)->isSC()) addType((*at));
128 }
129 initialized_ = true;
130 }
131
132 void SC::addType(AtomType* atomType) {
133 SuttonChenAdapter sca = SuttonChenAdapter(atomType);
134 SCAtomData scAtomData;
135
136 scAtomData.c = sca.getC();
137 scAtomData.m = sca.getM();
138 scAtomData.n = sca.getN();
139 scAtomData.alpha = sca.getAlpha();
140 scAtomData.epsilon = sca.getEpsilon();
141 scAtomData.rCut = 2.0 * scAtomData.alpha;
142
143 // add it to the map:
144 int atid = atomType->getIdent();
145 int sctid = SCtypes.size();
146
147 pair<set<int>::iterator, bool> ret;
148 ret = SCtypes.insert(atid);
149 if (ret.second == false) {
150 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
151 "SC already had a previous entry with ident %d\n", atid);
152 painCave.severity = OPENMD_INFO;
153 painCave.isFatal = 0;
154 simError();
155 }
156
157 SCtids[atid] = sctid;
158 SCdata[sctid] = scAtomData;
159 MixingMap[sctid].resize(nSC_);
160
161 // Now, iterate over all known types and add to the mixing map:
162
163 std::set<int>::iterator it;
164 for (it = SCtypes.begin(); it != SCtypes.end(); ++it) {
165 int sctid2 = SCtids[(*it)];
166 AtomType* atype2 = forceField_->getAtomType((*it));
167
168 SCInteractionData mixer;
169
170 mixer.alpha = getAlpha(atomType, atype2);
171 mixer.rCut = 2.0 * mixer.alpha;
172 mixer.epsilon = getEpsilon(atomType, atype2);
173 mixer.m = getM(atomType, atype2);
174 mixer.n = getN(atomType, atype2);
175
176 RealType dr = mixer.rCut / (np_ - 1);
177 vector<RealType> rvals;
178 vector<RealType> vvals;
179 vector<RealType> phivals;
180
181 rvals.push_back(0.0);
182 vvals.push_back(0.0);
183 phivals.push_back(0.0);
184
185 for (int k = 1; k < np_; k++) {
186 RealType r = dr * k;
187 rvals.push_back(r);
188 vvals.push_back(mixer.epsilon * pow(mixer.alpha / r, mixer.n));
189 phivals.push_back(pow(mixer.alpha / r, mixer.m));
190 }
191
192 mixer.vCut = mixer.epsilon * pow(mixer.alpha / mixer.rCut, mixer.n);
193
194 CubicSpline* V = new CubicSpline();
195 V->addPoints(rvals, vvals);
196
197 CubicSpline* phi = new CubicSpline();
198 phi->addPoints(rvals, phivals);
199
200 mixer.V = V;
201 mixer.phi = phi;
202
203 mixer.explicitlySet = false;
204
205 MixingMap[sctid2].resize(nSC_);
206
207 MixingMap[sctid][sctid2] = mixer;
208 if (sctid2 != sctid) { MixingMap[sctid2][sctid] = mixer; }
209 }
210 return;
211 }
212
213 void SC::addExplicitInteraction(AtomType* atype1, AtomType* atype2,
214 RealType epsilon, RealType m, RealType n,
215 RealType alpha) {
216 // in case these weren't already in the map
217 addType(atype1);
218 addType(atype2);
219
220 SCInteractionData mixer;
221
222 mixer.epsilon = epsilon;
223 mixer.m = m;
224 mixer.n = n;
225 mixer.alpha = alpha;
226 mixer.rCut = 2.0 * mixer.alpha;
227
228 RealType dr = mixer.rCut / (np_ - 1);
229 vector<RealType> rvals;
230 vector<RealType> vvals;
231 vector<RealType> phivals;
232
233 rvals.push_back(0.0);
234 vvals.push_back(0.0);
235 phivals.push_back(0.0);
236
237 for (int k = 1; k < np_; k++) {
238 RealType r = dr * k;
239 rvals.push_back(r);
240 vvals.push_back(mixer.epsilon * pow(mixer.alpha / r, mixer.n));
241 phivals.push_back(pow(mixer.alpha / r, mixer.m));
242 }
243
244 mixer.vCut = mixer.epsilon * pow(mixer.alpha / mixer.rCut, mixer.n);
245
246 CubicSpline* V = new CubicSpline();
247 V->addPoints(rvals, vvals);
248
249 CubicSpline* phi = new CubicSpline();
250 phi->addPoints(rvals, phivals);
251
252 mixer.V = V;
253 mixer.phi = phi;
254
255 mixer.explicitlySet = true;
256
257 int sctid1 = SCtids[atype1->getIdent()];
258 int sctid2 = SCtids[atype2->getIdent()];
259
260 MixingMap[sctid1][sctid2] = mixer;
261 if (sctid2 != sctid1) { MixingMap[sctid2][sctid1] = mixer; }
262 return;
263 }
264
265 void SC::calcDensity(InteractionData& idat) {
266 if (!initialized_) initialize();
267 int sctid1 = SCtids[idat.atid1];
268 int sctid2 = SCtids[idat.atid2];
269
270 SCInteractionData& mixer = MixingMap[sctid1][sctid2];
271
272 RealType rcij = mixer.rCut;
273
274 if (idat.rij < rcij) {
275 RealType rho = mixer.phi->getValueAt(idat.rij);
276 idat.rho1 += rho;
277 idat.rho2 += rho;
278 }
279
280 return;
281 }
282
283 void SC::calcFunctional(SelfData& sdat) {
284 if (!initialized_) initialize();
285
286 SCAtomData& data1 = SCdata[SCtids[sdat.atid]];
287
288 RealType u = -data1.c * data1.epsilon * sqrt(sdat.rho);
289 sdat.frho = u;
290 sdat.dfrhodrho = 0.5 * sdat.frho / sdat.rho;
291
292 sdat.selfPot[METALLIC_EMBEDDING_FAMILY] += u;
293
294 if (sdat.isSelected) sdat.selePot[METALLIC_EMBEDDING_FAMILY] += u;
295
296 if (sdat.doParticlePot) { sdat.particlePot += u; }
297
298 return;
299 }
300
301 void SC::calcForce(InteractionData& idat) {
302 if (!initialized_) initialize();
303
304 int& sctid1 = SCtids[idat.atid1];
305 int& sctid2 = SCtids[idat.atid2];
306
307 SCAtomData& data1 = SCdata[sctid1];
308 SCAtomData& data2 = SCdata[sctid2];
309
310 SCInteractionData& mixer = MixingMap[sctid1][sctid2];
311
312 RealType rcij = mixer.rCut;
313
314 if (idat.rij < rcij) {
315 RealType vcij = mixer.vCut;
316 RealType rhtmp, drhodr, vptmp, dvpdr;
317
318 mixer.phi->getValueAndDerivativeAt(idat.rij, rhtmp, drhodr);
319 mixer.V->getValueAndDerivativeAt(idat.rij, vptmp, dvpdr);
320
321 RealType pot_temp = vptmp - vcij;
322 idat.vpair += pot_temp;
323
324 RealType dudr = drhodr * (idat.dfrho1 + idat.dfrho2) + dvpdr;
325
326 idat.f1 += idat.d * dudr / idat.rij;
327
328 if (idat.doParticlePot) {
329 // particlePot is the difference between the full potential and
330 // the full potential without the presence of a particular
331 // particle (atom1).
332 //
333 // This reduces the density at other particle locations, so we
334 // need to recompute the density at atom2 assuming atom1 didn't
335 // contribute. This then requires recomputing the density
336 // functional for atom2 as well.
337
338 idat.particlePot1 -=
339 data2.c * data2.epsilon * sqrt(idat.rho2 - rhtmp) + idat.frho2;
340
341 idat.particlePot2 -=
342 data1.c * data1.epsilon * sqrt(idat.rho1 - rhtmp) + idat.frho1;
343 }
344
345 idat.pot[METALLIC_PAIR_FAMILY] += pot_temp;
346
347 if (idat.isSelected) idat.selePot[METALLIC_PAIR_FAMILY] += pot_temp;
348 }
349
350 return;
351 }
352
353 RealType SC::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
354 if (!initialized_) initialize();
355
356 int atid1 = atypes.first->getIdent();
357 int atid2 = atypes.second->getIdent();
358 int& sctid1 = SCtids[atid1];
359 int& sctid2 = SCtids[atid2];
360
361 if (sctid1 == -1 || sctid2 == -1) {
362 return 0.0;
363 } else {
364 return MixingMap[sctid1][sctid2].rCut;
365 }
366 }
367} // namespace OpenMD
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
@ METALLIC_EMBEDDING_FAMILY
Transition metal interactions involving electron density.
@ METALLIC_PAIR_FAMILY
Transition metal interactions involving pair potentials.