OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
RepulsivePower.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 appropriate papers when you publish your
33 * work. Good starting points are:
34 *
35 * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
36 * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
37 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
38 * [4] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
39 * [5] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
40 * [6] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
41 * [7] Lamichhane, Newman & Gezelter, J. Chem. Phys. 141, 134110 (2014).
42 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
43 */
44
45#include "nonbonded/RepulsivePower.hpp"
46
47#include <cmath>
48#include <cstdio>
49#include <cstring>
50
51#include "types/RepulsivePowerInteractionType.hpp"
52#include "utils/simError.h"
53
54using namespace std;
55
56namespace OpenMD {
57
58 RepulsivePower::RepulsivePower() :
59 initialized_(false), forceField_(NULL), name_("RepulsivePower") {}
60
61 void RepulsivePower::initialize() {
62 RPtypes.clear();
63 RPtids.clear();
64 MixingMap.clear();
65 RPtids.resize(forceField_->getNAtomType(), -1);
66
67 ForceField::NonBondedInteractionTypeContainer* nbiTypes =
68 forceField_->getNonBondedInteractionTypes();
69 ForceField::NonBondedInteractionTypeContainer::MapTypeIterator j;
70 ForceField::NonBondedInteractionTypeContainer::KeyType keys;
71 NonBondedInteractionType* nbt;
72 int rptid1, rptid2;
73
74 for (nbt = nbiTypes->beginType(j); nbt != NULL;
75 nbt = nbiTypes->nextType(j)) {
76 if (nbt->isRepulsivePower()) {
77 keys = nbiTypes->getKeys(j);
78 AtomType* at1 = forceField_->getAtomType(keys[0]);
79 if (at1 == NULL) {
80 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
81 "RepulsivePower::initialize could not find AtomType %s\n"
82 "\tto for for %s - %s interaction.\n",
83 keys[0].c_str(), keys[0].c_str(), keys[1].c_str());
84 painCave.severity = OPENMD_ERROR;
85 painCave.isFatal = 1;
86 simError();
87 }
88
89 AtomType* at2 = forceField_->getAtomType(keys[1]);
90 if (at2 == NULL) {
91 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
92 "RepulsivePower::initialize could not find AtomType %s\n"
93 "\tfor %s - %s nonbonded interaction.\n",
94 keys[1].c_str(), keys[0].c_str(), keys[1].c_str());
95 painCave.severity = OPENMD_ERROR;
96 painCave.isFatal = 1;
97 simError();
98 }
99
100 int atid1 = at1->getIdent();
101 if (RPtids[atid1] == -1) {
102 rptid1 = RPtypes.size();
103 RPtypes.insert(atid1);
104 RPtids[atid1] = rptid1;
105 }
106 int atid2 = at2->getIdent();
107 if (RPtids[atid2] == -1) {
108 rptid2 = RPtypes.size();
109 RPtypes.insert(atid2);
110 RPtids[atid2] = rptid2;
111 }
112
113 RepulsivePowerInteractionType* rpit =
114 dynamic_cast<RepulsivePowerInteractionType*>(nbt);
115 if (rpit == NULL) {
116 snprintf(
117 painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
118 "RepulsivePower::initialize could not convert "
119 "NonBondedInteractionType\n"
120 "\tto RepulsivePowerInteractionType for %s - %s interaction.\n",
121 at1->getName().c_str(), at2->getName().c_str());
122 painCave.severity = OPENMD_ERROR;
123 painCave.isFatal = 1;
124 simError();
125 }
126
127 RealType sigma = rpit->getSigma();
128 RealType epsilon = rpit->getEpsilon();
129 int nRep = rpit->getNrep();
130
131 addExplicitInteraction(at1, at2, sigma, epsilon, nRep);
132 }
133 }
134 initialized_ = true;
135 }
136
137 void RepulsivePower::addExplicitInteraction(AtomType* atype1,
138 AtomType* atype2, RealType sigma,
139 RealType epsilon, int nRep) {
140 RPInteractionData mixer;
141 mixer.sigma = sigma;
142 mixer.epsilon = epsilon;
143 mixer.sigmai = 1.0 / mixer.sigma;
144 mixer.nRep = nRep;
145
146 int nRP = RPtypes.size();
147 int atid1 = atype1->getIdent();
148 int atid2 = atype2->getIdent();
149 int rptid1, rptid2;
150
151 pair<set<int>::iterator, bool> ret;
152 ret = RPtypes.insert(atid1);
153 if (ret.second == false) {
154 // already had this type in the MieMap, just get the mietid:
155 rptid1 = RPtids[atid1];
156 } else {
157 // didn't already have it, so make a new one and assign it:
158 rptid1 = nRP;
159 RPtids[atid1] = nRP;
160 nRP++;
161 }
162
163 ret = RPtypes.insert(atid2);
164 if (ret.second == false) {
165 // already had this type in the MieMap, just get the mietid:
166 rptid2 = RPtids[atid2];
167 } else {
168 // didn't already have it, so make a new one and assign it:
169 rptid2 = nRP;
170 RPtids[atid2] = nRP;
171 nRP++;
172 }
173
174 MixingMap.resize(nRP);
175 MixingMap[rptid1].resize(nRP);
176
177 MixingMap[rptid1][rptid2] = mixer;
178 if (rptid2 != rptid1) {
179 MixingMap[rptid2].resize(nRP);
180 MixingMap[rptid2][rptid1] = mixer;
181 }
182 }
183
184 void RepulsivePower::calcForce(InteractionData& idat) {
185 if (!initialized_) initialize();
186
187 RPInteractionData& mixer =
188 MixingMap[RPtids[idat.atid1]][RPtids[idat.atid2]];
189 RealType sigmai = mixer.sigmai;
190 RealType epsilon = mixer.epsilon;
191 int nRep = mixer.nRep;
192
193 RealType ros;
194 RealType rcos;
195 RealType myPot = 0.0;
196 RealType myPotC = 0.0;
197 RealType myDeriv = 0.0;
198 RealType myDerivC = 0.0;
199
200 ros = idat.rij * sigmai;
201
202 getNRepulsionFunc(ros, nRep, myPot, myDeriv);
203
204 if (idat.shiftedPot) {
205 rcos = idat.rcut * sigmai;
206 getNRepulsionFunc(rcos, nRep, myPotC, myDerivC);
207 myDerivC = 0.0;
208 } else if (idat.shiftedForce) {
209 rcos = idat.rcut * sigmai;
210 getNRepulsionFunc(rcos, nRep, myPotC, myDerivC);
211 myPotC = myPotC + myDerivC * (idat.rij - idat.rcut) * sigmai;
212 } else {
213 myPotC = 0.0;
214 myDerivC = 0.0;
215 }
216
217 RealType pot_temp = idat.vdwMult * epsilon * (myPot - myPotC);
218 idat.vpair += pot_temp;
219
220 RealType dudr =
221 idat.sw * idat.vdwMult * epsilon * (myDeriv - myDerivC) * sigmai;
222
223 idat.pot[VANDERWAALS_FAMILY] += idat.sw * pot_temp;
224 if (idat.isSelected) idat.selePot[VANDERWAALS_FAMILY] += idat.sw * pot_temp;
225
226 idat.f1 += idat.d * dudr / idat.rij;
227
228 return;
229 }
230
231 void RepulsivePower::getNRepulsionFunc(const RealType& r, int& n,
232 RealType& pot, RealType& deriv) {
233 RealType ri = 1.0 / r;
234 RealType rin = pow(ri, n);
235 RealType rin1 = rin * ri;
236
237 pot = rin;
238 deriv = -n * rin1;
239
240 return;
241 }
242
243 RealType RepulsivePower::getSuggestedCutoffRadius(
244 pair<AtomType*, AtomType*> atypes) {
245 if (!initialized_) initialize();
246
247 int atid1 = atypes.first->getIdent();
248 int atid2 = atypes.second->getIdent();
249 int rptid1 = RPtids[atid1];
250 int rptid2 = RPtids[atid2];
251
252 if (rptid1 == -1 || rptid2 == -1)
253 return 0.0;
254 else {
255 RPInteractionData mixer = MixingMap[rptid1][rptid2];
256 return 2.5 * mixer.sigma;
257 }
258 }
259} // namespace OpenMD
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
@ VANDERWAALS_FAMILY
Long-range dispersion and short-range pauli repulsion.