45#include "io/FluctuatingChargeAtomTypesSectionParser.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"
57 FluctuatingChargeAtomTypesSectionParser::
60 setSectionName(
"FluctuatingChargeAtomTypes");
62 stringToEnumMap_[
"Hardness"] = fqtHardness;
63 stringToEnumMap_[
"EAM"] = fqtEAM;
64 stringToEnumMap_[
"EAMPoly"] = fqtEAMPolynomial;
65 stringToEnumMap_[
"DREAM2"] = fqtDREAM2;
68 void FluctuatingChargeAtomTypesSectionParser::parseLine(
ForceField& ff,
72 int nTokens = tokenizer.countTokens();
75 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
76 "FluctuatingChargeAtomTypesSectionParser Error: "
77 "Not enough tokens at line %d\n",
84 eus_ = options_.getFluctuatingChargeEnergyUnitScaling();
86 cus_ = options_.getChargeUnitScaling();
88 dus_ = options_.getDistanceUnitScaling();
90 oss_ = options_.getOxidationStateScaling();
93 RealType chius = eus_ / cus_;
95 RealType curvus = eus_ / (cus_ * cus_);
97 string atomTypeName = tokenizer.nextToken();
98 AtomType* atomType = ff.getAtomType(atomTypeName);
99 if (atomType != NULL) {
104 if (!fca.isFixedCharge()) {
105 RealType charge = 0.0;
106 fca.makeFixedCharge(charge);
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;
118 RealType chargeMass = tokenizer.nextTokenAsDouble();
119 FluctuatingTypeEnum fqt = getFluctuatingTypeEnum(tokenizer.nextToken());
134 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
135 "FluctuatingChargeAtomTypesSectionParser Error: "
136 "Not enough tokens at line %d\n",
138 painCave.isFatal = 1;
141 RealType chi = chius * tokenizer.nextTokenAsDouble();
142 RealType Jii = curvus * tokenizer.nextTokenAsDouble();
143 int slaterN = tokenizer.nextTokenAsInt();
144 RealType slaterZeta = tokenizer.nextTokenAsDouble() / dus_;
147 fqa.makeFluctuatingCharge(chargeMass, chi, Jii, slaterN, slaterZeta);
151 case fqtEAMPolynomial:
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",
161 painCave.isFatal = 1;
164 RealType nValence = tokenizer.nextTokenAsDouble();
169 int nPairs = nTokens / 2;
171 RealType coefficient;
173 for (
int i = 0; i < nPairs; ++i) {
174 power = tokenizer.nextTokenAsInt();
175 coefficient = tokenizer.nextTokenAsDouble() * eus_ / pow(cus_, power);
180 fqa.makeFluctuatingCharge(chargeMass, nValence, vself);
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",
197 painCave.isFatal = 1;
201 RealType nValence = tokenizer.nextTokenAsDouble() * oss_;
204 RealType nMobile = tokenizer.nextTokenAsDouble() * oss_;
209 int nPairs = nTokens / 2;
211 RealType coefficient;
213 for (
int i = 0; i < nPairs; ++i) {
214 power = tokenizer.nextTokenAsInt();
215 coefficient = oss_ * oss_ * tokenizer.nextTokenAsDouble() * eus_ /
216 pow(oss_ * cus_, power);
223 fqa.makeFluctuatingCharge(chargeMass, nValence, nMobile, vself);
229 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
230 "FluctuatingChargeAtomTypesSectionParser Error: "
231 "Unknown Fluctuating Charge Type at line %d\n",
233 painCave.isFatal = 1;
239 FluctuatingChargeAtomTypesSectionParser::FluctuatingTypeEnum
240 FluctuatingChargeAtomTypesSectionParser::getFluctuatingTypeEnum(
241 const std::string& str) {
242 std::map<std::string, FluctuatingTypeEnum>::iterator i;
243 i = stringToEnumMap_.find(str);
245 return i == stringToEnumMap_.end() ? fqtUnknown : i->second;
AtomType is what OpenMD looks to for unchanging data about an atom.
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.