45#include "io/NonBondedInteractionsSectionParser.hpp"
48#include "types/AtomType.hpp"
49#include "types/BuckinghamInteractionType.hpp"
50#include "types/EAMInteractionType.hpp"
51#include "types/InversePowerSeriesInteractionType.hpp"
52#include "types/LennardJonesInteractionType.hpp"
53#include "types/MAWInteractionType.hpp"
54#include "types/MieInteractionType.hpp"
55#include "types/MorseInteractionType.hpp"
56#include "types/RepulsivePowerInteractionType.hpp"
57#include "utils/simError.h"
61 NonBondedInteractionsSectionParser::NonBondedInteractionsSectionParser(
62 ForceFieldOptions& options) :
64 setSectionName(
"NonBondedInteractions");
66 stringToEnumMap_[
"MAW"] = MAW;
67 stringToEnumMap_[
"ShiftedMorse"] = ShiftedMorse;
68 stringToEnumMap_[
"LennardJones"] = LennardJones;
69 stringToEnumMap_[
"RepulsiveMorse"] = RepulsiveMorse;
70 stringToEnumMap_[
"RepulsivePower"] = RepulsivePower;
71 stringToEnumMap_[
"Mie"] = Mie;
72 stringToEnumMap_[
"Buckingham"] = Buckingham;
73 stringToEnumMap_[
"EAMTable"] = EAMTable;
74 stringToEnumMap_[
"EAMZhou"] = EAMZhou;
75 stringToEnumMap_[
"EAMOxides"] = EAMOxides;
76 stringToEnumMap_[
"InversePowerSeries"] = InversePowerSeries;
79 void NonBondedInteractionsSectionParser::parseLine(ForceField& ff,
80 const std::string& line,
82 StringTokenizer tokenizer(line);
83 int nTokens = tokenizer.countTokens();
85 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
86 "NonBondedInteractionsSectionParser Error: Not enough tokens at "
93 meus_ = options_.getMetallicEnergyUnitScaling();
94 eus_ = options_.getEnergyUnitScaling();
95 dus_ = options_.getDistanceUnitScaling();
97 std::string at1 = tokenizer.nextToken();
98 std::string at2 = tokenizer.nextToken();
99 std::string itype = tokenizer.nextToken();
101 NonBondedInteractionTypeEnum nbit = getNonBondedInteractionTypeEnum(itype);
103 NonBondedInteractionType* interactionType = NULL;
109 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
110 "NonBondedInteractionsSectionParser Error: Token number "
112 "%d. 8 tokens expected. \n",
114 painCave.isFatal = 1;
117 RealType r_e = dus_ * tokenizer.nextTokenAsDouble();
118 RealType D_e = eus_ * tokenizer.nextTokenAsDouble();
119 RealType beta = tokenizer.nextTokenAsDouble() / dus_;
120 RealType ca1 = tokenizer.nextTokenAsDouble();
121 RealType cb1 = tokenizer.nextTokenAsDouble();
122 interactionType =
new MAWInteractionType(D_e, beta, r_e, ca1, cb1);
128 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
129 "NonBondedInteractionsSectionParser Error: Token number "
131 "%d. 6 tokens expected. \n",
133 painCave.isFatal = 1;
136 RealType r0 = dus_ * tokenizer.nextTokenAsDouble();
137 RealType D0 = eus_ * tokenizer.nextTokenAsDouble();
138 RealType beta0 = tokenizer.nextTokenAsDouble() / dus_;
139 interactionType =
new MorseInteractionType(D0, beta0, r0, mtShifted);
145 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
146 "NonBondedInteractionsSectionParser Error: Token number "
148 "%d. 6 tokens expected. \n",
150 painCave.isFatal = 1;
153 RealType r0 = dus_ * tokenizer.nextTokenAsDouble();
154 RealType D0 = eus_ * tokenizer.nextTokenAsDouble();
155 RealType beta0 = tokenizer.nextTokenAsDouble() / dus_;
156 interactionType =
new MorseInteractionType(D0, beta0, r0, mtRepulsive);
162 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
163 "NonBondedInteractionsSectionParser Error: Token number "
165 "%d. 5 tokens expected. \n",
167 painCave.isFatal = 1;
170 RealType sigma = dus_ * tokenizer.nextTokenAsDouble();
171 RealType epsilon = eus_ * tokenizer.nextTokenAsDouble();
172 interactionType =
new LennardJonesInteractionType(sigma, epsilon);
178 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
179 "NonBondedInteractionsSectionParser Error: Token number "
181 "%d. 6 tokens expected. \n",
183 painCave.isFatal = 1;
186 RealType sigma = dus_ * tokenizer.nextTokenAsDouble();
187 RealType epsilon = eus_ * tokenizer.nextTokenAsDouble();
188 int nRep = tokenizer.nextTokenAsInt();
190 new RepulsivePowerInteractionType(sigma, epsilon, nRep);
196 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
197 "NonBondedInteractionsSectionParser Error: Token number "
199 "%d. 7 tokens expected. \n",
201 painCave.isFatal = 1;
204 RealType sigma = dus_ * tokenizer.nextTokenAsDouble();
205 RealType epsilon = eus_ * tokenizer.nextTokenAsDouble();
206 int nRep = tokenizer.nextTokenAsInt();
207 int mAtt = tokenizer.nextTokenAsInt();
208 interactionType =
new MieInteractionType(sigma, epsilon, nRep, mAtt);
214 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
215 "NonBondedInteractionsSectionParser Error: Not enough tokens "
218 painCave.isFatal = 1;
221 std::string btype = tokenizer.nextToken();
224 RealType A = eus_ * tokenizer.nextTokenAsDouble();
225 RealType B = tokenizer.nextTokenAsDouble() / dus_;
227 tokenizer.nextTokenAsDouble();
228 RealType sigma = 0.0;
229 RealType epsilon = 0.0;
231 if (btype.compare(
"MODIFIED")) {
232 sigma = dus_ * tokenizer.nextTokenAsDouble();
233 epsilon = eus_ * tokenizer.nextTokenAsDouble();
234 interactionType =
new BuckinghamInteractionType(A, B, C, sigma,
235 epsilon, btModified);
237 }
else if (btype.compare(
"TRADITIONAL")) {
239 new BuckinghamInteractionType(A, B, C, btTraditional);
241 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
242 "NonBondedInteractionsSectionParser Error: Unknown "
243 "Buckingham Type at "
246 painCave.isFatal = 1;
254 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
255 "NonBondedInteractionsSectionParser Error: Token number "
257 "%d. 10 tokens expected. \n",
259 painCave.isFatal = 1;
262 RealType re = dus_ * tokenizer.nextTokenAsDouble();
263 RealType alpha = tokenizer.nextTokenAsDouble();
264 RealType beta = tokenizer.nextTokenAsDouble();
267 RealType A = meus_ * tokenizer.nextTokenAsDouble();
268 RealType B = meus_ * tokenizer.nextTokenAsDouble();
269 RealType kappa = tokenizer.nextTokenAsDouble();
270 RealType lambda = tokenizer.nextTokenAsDouble();
273 new EAMInteractionType(re, alpha, beta, A, B, kappa, lambda);
279 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
280 "NonBondedInteractionsSectionParser Error: Token number "
282 "%d. 8 tokens expected. \n",
284 painCave.isFatal = 1;
287 RealType re = dus_ * tokenizer.nextTokenAsDouble();
288 RealType alpha = tokenizer.nextTokenAsDouble();
291 RealType A = meus_ * tokenizer.nextTokenAsDouble();
292 RealType Ci = tokenizer.nextTokenAsDouble();
293 RealType Cj = tokenizer.nextTokenAsDouble();
295 interactionType =
new EAMInteractionType(re, alpha, A, Ci, Cj);
299 case InversePowerSeries:
300 if (nTokens < 2 || nTokens % 2 != 0) {
301 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
302 "NonBondedInteractionsSectionParser Error: Not enough tokens "
305 painCave.isFatal = 1;
308 std::vector<std::pair<int, RealType>> series;
309 int nPairs = nTokens / 2;
311 RealType coefficient;
313 for (
int i = 0; i < nPairs; ++i) {
314 power = tokenizer.nextTokenAsInt();
315 coefficient = tokenizer.nextTokenAsDouble() * eus_ * pow(dus_, power);
316 series.push_back(std::make_pair(power, coefficient));
318 interactionType =
new InversePowerSeriesInteractionType(series);
324 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
325 "NonBondedInteractionsSectionParser Error: Unknown Interaction "
329 painCave.isFatal = 1;
335 if (interactionType != NULL) {
336 ff.addNonBondedInteractionType(at1, at2, interactionType);
340 NonBondedInteractionsSectionParser::NonBondedInteractionTypeEnum
341 NonBondedInteractionsSectionParser::getNonBondedInteractionTypeEnum(
342 const std::string& str) {
343 std::map<std::string, NonBondedInteractionTypeEnum>::iterator i;
344 i = stringToEnumMap_.find(str);
346 return i == stringToEnumMap_.end() ? Unknown : i->second;
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.