45#include "io/MultipoleAtomTypesSectionParser.hpp"
48#include "utils/Constants.hpp"
49#include "utils/simError.h"
53 MultipoleAtomTypesSectionParser::MultipoleAtomTypesSectionParser(
55 setSectionName(
"MultipoleAtomTypes");
58 void MultipoleAtomTypesSectionParser::parseLine(ForceField& ff,
59 const std::string& line,
61 StringTokenizer tokenizer(line);
62 int nTokens = tokenizer.countTokens();
87 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
88 "MultipoleAtomTypesSectionParser Error: Not enough tokens at "
94 std::string atomTypeName = tokenizer.nextToken();
95 std::string multipoleType = tokenizer.nextToken();
96 RealType phi = tokenizer.nextTokenAsDouble() * Constants::PI / 180.0;
97 RealType theta = tokenizer.nextTokenAsDouble() * Constants::PI / 180.0;
98 RealType psi = tokenizer.nextTokenAsDouble() * Constants::PI / 180.0;
100 AtomType* atomType = ff.getAtomType(atomTypeName);
101 if (atomType == NULL) {
102 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
103 "MultipoleAtomTypesSectionParser Error: Can not find matched "
106 atomTypeName.c_str(), lineNo);
107 painCave.isFatal = 1;
111 MultipoleAdapter ma = MultipoleAdapter(atomType);
113 RotMat3x3d eFrame(0.0);
115 eFrame.setupRotMat(phi, theta, psi);
117 RealType dipoleMoment(0);
118 Vector3d dipole(V3Zero);
119 Vector3d quadrupoleMoments(V3Zero);
120 Mat3x3d quadrupole(0.0);
122 bool isDipole(
false);
123 bool isQuadrupole(
false);
125 if (multipoleType ==
"d") {
126 parseDipole(tokenizer, dipoleMoment, lineNo);
128 }
else if (multipoleType ==
"s") {
129 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
130 "MultipoleAtomTypesSectionParser Error: \n"
131 "\tsplit dipoles (type s) have been deprecated (line: %d)\n",
133 painCave.isFatal = 1;
135 }
else if (multipoleType ==
"q") {
136 parseQuadrupole(tokenizer, quadrupoleMoments, lineNo);
138 }
else if (multipoleType ==
"dq") {
139 parseDipole(tokenizer, dipoleMoment, lineNo);
141 parseQuadrupole(tokenizer, quadrupoleMoments, lineNo);
143 }
else if (multipoleType ==
"sq") {
144 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
145 "MultipoleAtomTypesSectionParser Error: \n"
146 "\tsplit dipole quadrupoles (type sq) have been deprecated "
149 painCave.isFatal = 1;
152 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
153 "MultipoleAtomTypesSectionParser Error: unrecognized multiple "
157 painCave.isFatal = 1;
160 if (isDipole) dipole = dipoleMoment * eFrame.transpose() * V3Z;
162 quadrupole(0, 0) = quadrupoleMoments(0);
163 quadrupole(1, 1) = quadrupoleMoments(1);
164 quadrupole(2, 2) = quadrupoleMoments(2);
165 quadrupole = eFrame.transpose() * quadrupole * eFrame;
168 ma.makeMultipole(dipole, quadrupole, isDipole, isQuadrupole);
172 void MultipoleAtomTypesSectionParser::parseDipole(StringTokenizer& tokenizer,
173 RealType& dipoleMoment,
175 if (tokenizer.hasMoreTokens()) {
176 dipoleMoment = tokenizer.nextTokenAsDouble();
178 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
179 "MultipoleAtomTypesSectionParser Error: Not enough tokens at "
182 painCave.isFatal = 1;
187 void MultipoleAtomTypesSectionParser::parseQuadrupole(
188 StringTokenizer& tokenizer, Vector3d& quadrupoleMoments,
int lineNo) {
189 int nTokens = tokenizer.countTokens();
191 quadrupoleMoments[0] = tokenizer.nextTokenAsDouble();
192 quadrupoleMoments[1] = tokenizer.nextTokenAsDouble();
193 quadrupoleMoments[2] = tokenizer.nextTokenAsDouble();
205 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
206 "MultipoleAtomTypesSectionParser Error: Not enough tokens at "
209 painCave.isFatal = 1;
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.