OpenMD 3.0
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
FluctuatingChargeAtomTypesSectionParser.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 "io/FluctuatingChargeAtomTypesSectionParser.hpp"
46
47#include "brains/ForceField.hpp"
48#include "io/ForceFieldOptions.hpp"
49#include "types/AtomType.hpp"
50#include "types/FixedChargeAdapter.hpp"
51#include "types/FluctuatingChargeAdapter.hpp"
52#include "utils/simError.h"
53
54using namespace std;
55namespace OpenMD {
56
57 FluctuatingChargeAtomTypesSectionParser::
58 FluctuatingChargeAtomTypesSectionParser(ForceFieldOptions& options) :
59 options_(options) {
60 setSectionName("FluctuatingChargeAtomTypes");
61
62 stringToEnumMap_["Hardness"] = fqtHardness;
63 stringToEnumMap_["EAM"] = fqtEAM;
64 stringToEnumMap_["EAMPoly"] = fqtEAMPolynomial;
65 stringToEnumMap_["DREAM2"] = fqtDREAM2;
66 }
67
68 void FluctuatingChargeAtomTypesSectionParser::parseLine(ForceField& ff,
69 const string& line,
70 int lineNo) {
71 StringTokenizer tokenizer(line);
72 int nTokens = tokenizer.countTokens();
73
74 if (nTokens < 3) {
75 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
76 "FluctuatingChargeAtomTypesSectionParser Error: "
77 "Not enough tokens at line %d\n",
78 lineNo);
79 painCave.isFatal = 1;
80 simError();
81 }
82
83 // conversion to kcal / mol
84 eus_ = options_.getFluctuatingChargeEnergyUnitScaling();
85 // conversion to electrons
86 cus_ = options_.getChargeUnitScaling();
87 // conversion to angstroms
88 dus_ = options_.getDistanceUnitScaling();
89 // oxidation state scaling
90 oss_ = options_.getOxidationStateScaling();
91
92 // electronegativity conversion
93 RealType chius = eus_ / cus_;
94 // curvature (hardness) conversion
95 RealType curvus = eus_ / (cus_ * cus_);
96
97 string atomTypeName = tokenizer.nextToken();
98 AtomType* atomType = ff.getAtomType(atomTypeName);
99 if (atomType != NULL) {
101
102 // All fluctuating charges are charges, and if we haven't
103 // already set values for the charge, then start with zero.
104 if (!fca.isFixedCharge()) {
105 RealType charge = 0.0;
106 fca.makeFixedCharge(charge);
107 }
108
109 } else {
110 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
111 "FluctuatingChargeAtomTypesSectionParser Error: Atom Type [%s] "
112 "has not been created yet\n",
113 atomTypeName.c_str());
114 painCave.isFatal = 1;
115 simError();
116 }
117
118 RealType chargeMass = tokenizer.nextTokenAsDouble();
119 FluctuatingTypeEnum fqt = getFluctuatingTypeEnum(tokenizer.nextToken());
120
121 nTokens -= 3;
122
123 switch (fqt) {
124 case fqtHardness:
125 // For Rick, Stuart, Berne style fluctuating charges, there's a
126 // self charge potential defined by electronegativity and
127 // hardness. On molecular structures, the slater-type overlap
128 // integral is used to compute the hardness.
129
130 // atomTypeName, chargeMass, Hardness, electronegativity,
131 // hardness (Jii), slaterN, slaterZeta
132
133 if (nTokens < 4) {
134 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
135 "FluctuatingChargeAtomTypesSectionParser Error: "
136 "Not enough tokens at line %d\n",
137 lineNo);
138 painCave.isFatal = 1;
139 simError();
140 } else {
141 RealType chi = chius * tokenizer.nextTokenAsDouble();
142 RealType Jii = curvus * tokenizer.nextTokenAsDouble();
143 int slaterN = tokenizer.nextTokenAsInt();
144 RealType slaterZeta = tokenizer.nextTokenAsDouble() / dus_;
145
147 fqa.makeFluctuatingCharge(chargeMass, chi, Jii, slaterN, slaterZeta);
148 }
149 break;
150
151 case fqtEAMPolynomial:
152
153 // For DR-EAM v1, oxidation state scaling is built in to
154 // fluctuating charge parameters and nValence.
155
156 if (nTokens < 3 || nTokens % 2 != 1) {
157 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
158 "FluctuatingChargeAtomTypesSectionParser Error: "
159 "Not enough tokens at line %d\n",
160 lineNo);
161 painCave.isFatal = 1;
162 simError();
163 } else {
164 RealType nValence = tokenizer.nextTokenAsDouble();
165 nTokens -= 1;
166
167 DoublePolynomial vself;
168
169 int nPairs = nTokens / 2;
170 int power;
171 RealType coefficient;
172
173 for (int i = 0; i < nPairs; ++i) {
174 power = tokenizer.nextTokenAsInt();
175 coefficient = tokenizer.nextTokenAsDouble() * eus_ / pow(cus_, power);
176 vself.setCoefficient(power, coefficient);
177 }
178
180 fqa.makeFluctuatingCharge(chargeMass, nValence, vself);
181 }
182 break;
183
184 case fqtDREAM2:
185
186 // For DR-EAM v2, oxidation state scaling (oss_) is a force
187 // field parameter, fluctuating charge parameters, nValence, and
188 // nMobile in the force field file should assume unit charge
189 // oxidation state fits to ionization states and electron
190 // affinities.
191
192 if (nTokens < 3 || nTokens % 2 != 0) {
193 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
194 "FluctuatingChargeAtomTypesSectionParser Error: "
195 "Not enough tokens at line %d\n",
196 lineNo);
197 painCave.isFatal = 1;
198 simError();
199 } else {
200 // Neutral atom valence count
201 RealType nValence = tokenizer.nextTokenAsDouble() * oss_;
202 nTokens -= 1;
203 // Mobile electron count
204 RealType nMobile = tokenizer.nextTokenAsDouble() * oss_;
205 nTokens -= 1;
206
207 DoublePolynomial vself;
208
209 int nPairs = nTokens / 2;
210 int power;
211 RealType coefficient;
212
213 for (int i = 0; i < nPairs; ++i) {
214 power = tokenizer.nextTokenAsInt();
215 coefficient = oss_ * oss_ * tokenizer.nextTokenAsDouble() * eus_ /
216 pow(oss_ * cus_, power);
217
218 vself.setCoefficient(power, coefficient);
219 }
220
222
223 fqa.makeFluctuatingCharge(chargeMass, nValence, nMobile, vself);
224 }
225 break;
226
227 case fqtUnknown:
228 default:
229 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
230 "FluctuatingChargeAtomTypesSectionParser Error: "
231 "Unknown Fluctuating Charge Type at line %d\n",
232 lineNo);
233 painCave.isFatal = 1;
234 simError();
235 break;
236 }
237 }
238
239 FluctuatingChargeAtomTypesSectionParser::FluctuatingTypeEnum
240 FluctuatingChargeAtomTypesSectionParser::getFluctuatingTypeEnum(
241 const std::string& str) {
242 std::map<std::string, FluctuatingTypeEnum>::iterator i;
243 i = stringToEnumMap_.find(str);
244
245 return i == stringToEnumMap_.end() ? fqtUnknown : i->second;
246 }
247
248} // namespace OpenMD
AtomType is what OpenMD looks to for unchanging data about an atom.
Definition AtomType.hpp:66
void setCoefficient(int exponent, const Real &coefficient)
Set the coefficent of the specified exponent, if the coefficient is already there,...
The string tokenizer class allows an application to break a string into tokens The set of delimiters ...
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.