1 |
< |
/* |
1 |
> |
/* |
2 |
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
|
* |
4 |
|
* The University of Notre Dame grants you ("Licensee") a |
45 |
|
#include "utils/simError.h" |
46 |
|
namespace oopse { |
47 |
|
|
48 |
< |
MultipoleAtomTypesSectionParser::MultipoleAtomTypesSectionParser() { |
48 |
> |
MultipoleAtomTypesSectionParser::MultipoleAtomTypesSectionParser(ForceFieldOptions& options) : options_(options){ |
49 |
|
setSectionName("MultipoleAtomTypes"); |
50 |
< |
} |
50 |
> |
} |
51 |
|
|
52 |
< |
void MultipoleAtomTypesSectionParser::parseLine(ForceField& ff,const std::string& line, int lineNo){ |
52 |
> |
void MultipoleAtomTypesSectionParser::parseLine(ForceField& ff,const std::string& line, int lineNo){ |
53 |
|
StringTokenizer tokenizer(line); |
54 |
|
int nTokens = tokenizer.countTokens(); |
55 |
|
|
63 |
|
// Dipoles are given in units of Debye |
64 |
|
// Quadrupoles are given in units of |
65 |
|
// examples: |
66 |
< |
// name d theta phi psi dipole_moment |
67 |
< |
// name s theta phi psi dipole_moment splitdipole_distance |
68 |
< |
// name q theta phi psi Qxx Qyy Qzz |
69 |
< |
// name dq theta phi psi dipole_moment Qxx Qyy Qzz |
70 |
< |
// name sq theta phi psi dipole_moment splitdipole_distance Qxx Qyy Qzz |
66 |
> |
// name d phi theta psi dipole_moment |
67 |
> |
// name s phi theta psi dipole_moment splitdipole_distance |
68 |
> |
// name q phi theta psi Qxx Qyy Qzz |
69 |
> |
// name dq phi theta psi dipole_moment Qxx Qyy Qzz |
70 |
> |
// name sq phi theta psi dipole_moment splitdipole_distance Qxx Qyy Qzz |
71 |
|
|
72 |
|
if (nTokens < 5) { |
73 |
< |
sprintf(painCave.errMsg, "MultipoleAtomTypesSectionParser Error: Not enough tokens at line %d\n", |
74 |
< |
lineNo); |
75 |
< |
painCave.isFatal = 1; |
76 |
< |
simError(); |
73 |
> |
sprintf(painCave.errMsg, "MultipoleAtomTypesSectionParser Error: Not enough tokens at line %d\n", |
74 |
> |
lineNo); |
75 |
> |
painCave.isFatal = 1; |
76 |
> |
simError(); |
77 |
|
} else { |
78 |
|
|
79 |
< |
std::string atomTypeName = tokenizer.nextToken(); |
80 |
< |
std::string multipoleType = tokenizer.nextToken(); |
81 |
< |
double phi = tokenizer.nextTokenAsDouble() * NumericConstant::PI /180.0; |
82 |
< |
double theta = tokenizer.nextTokenAsDouble() * NumericConstant::PI /180.0; |
83 |
< |
double psi = tokenizer.nextTokenAsDouble() * NumericConstant::PI /180.0; |
84 |
< |
nTokens -= 5; |
79 |
> |
std::string atomTypeName = tokenizer.nextToken(); |
80 |
> |
std::string multipoleType = tokenizer.nextToken(); |
81 |
> |
double phi = tokenizer.nextTokenAsDouble() * NumericConstant::PI /180.0; |
82 |
> |
double theta = tokenizer.nextTokenAsDouble() * NumericConstant::PI /180.0; |
83 |
> |
double psi = tokenizer.nextTokenAsDouble() * NumericConstant::PI /180.0; |
84 |
> |
nTokens -= 5; |
85 |
|
|
86 |
< |
AtomType* atomType = ff.getAtomType(atomTypeName); |
87 |
< |
if (atomType == NULL) { |
88 |
< |
sprintf(painCave.errMsg, "MultipoleAtomTypesSectionParser Error: Can not find matched AtomType at line %d\n", |
89 |
< |
lineNo); |
90 |
< |
painCave.isFatal = 1; |
91 |
< |
simError(); |
92 |
< |
} |
86 |
> |
AtomType* atomType = ff.getAtomType(atomTypeName); |
87 |
> |
if (atomType == NULL) { |
88 |
> |
sprintf(painCave.errMsg, "MultipoleAtomTypesSectionParser Error: Can not find matched AtomType[%s] at line %d\n", |
89 |
> |
atomTypeName.c_str(), lineNo); |
90 |
> |
painCave.isFatal = 1; |
91 |
> |
simError(); |
92 |
> |
} |
93 |
|
|
94 |
< |
DirectionalAtomType* dAtomType = dynamic_cast<DirectionalAtomType*>(atomType); |
95 |
< |
if (dAtomType == NULL) { |
96 |
< |
sprintf(painCave.errMsg, "MultipoleAtomTypesSectionParser Error: Can not Cast Atom to DirectionalAtom at line \n"); |
97 |
< |
painCave.isFatal = 1; |
98 |
< |
simError(); |
99 |
< |
} |
94 |
> |
DirectionalAtomType* dAtomType = dynamic_cast<DirectionalAtomType*>(atomType); |
95 |
> |
if (dAtomType == NULL) { |
96 |
> |
sprintf(painCave.errMsg, "MultipoleAtomTypesSectionParser Error: Can not Cast Atom to DirectionalAtom at line %d\n", lineNo); |
97 |
> |
painCave.isFatal = 1; |
98 |
> |
simError(); |
99 |
> |
} |
100 |
|
|
101 |
< |
RotMat3x3d electroBodyFrame(phi, theta, psi); |
102 |
< |
dAtomType->setElectroBodyFrame(electroBodyFrame); |
101 |
> |
RotMat3x3d electroBodyFrame(phi, theta, psi); |
102 |
> |
dAtomType->setElectroBodyFrame(electroBodyFrame); |
103 |
|
|
104 |
< |
if (multipoleType== "d") { |
105 |
< |
parseDipole(tokenizer, dAtomType, lineNo); |
106 |
< |
} else if (multipoleType== "s") { |
107 |
< |
parseSplitDipole(tokenizer, dAtomType, lineNo); |
108 |
< |
} else if (multipoleType== "q") { |
109 |
< |
parseQuadruple( tokenizer, dAtomType, lineNo); |
110 |
< |
} else if (multipoleType== "dq") { |
111 |
< |
parseDipole(tokenizer, dAtomType, lineNo); |
112 |
< |
parseQuadruple( tokenizer, dAtomType, lineNo); |
113 |
< |
} else if (multipoleType== "sq") { |
114 |
< |
parseSplitDipole(tokenizer, dAtomType, lineNo); |
115 |
< |
parseQuadruple( tokenizer, dAtomType, lineNo); |
116 |
< |
} else { |
117 |
< |
sprintf(painCave.errMsg, "MultipoleAtomTypesSectionParser Error: unrecognized multiple type at line %d\n", |
118 |
< |
lineNo); |
119 |
< |
painCave.isFatal = 1; |
120 |
< |
simError(); |
121 |
< |
} |
122 |
< |
} |
104 |
> |
if (multipoleType== "d") { |
105 |
> |
parseDipole(tokenizer, dAtomType, lineNo); |
106 |
> |
} else if (multipoleType== "s") { |
107 |
> |
parseSplitDipole(tokenizer, dAtomType, lineNo); |
108 |
> |
} else if (multipoleType== "q") { |
109 |
> |
parseQuadruple( tokenizer, dAtomType, lineNo); |
110 |
> |
} else if (multipoleType== "dq") { |
111 |
> |
parseDipole(tokenizer, dAtomType, lineNo); |
112 |
> |
parseQuadruple( tokenizer, dAtomType, lineNo); |
113 |
> |
} else if (multipoleType== "sq") { |
114 |
> |
parseSplitDipole(tokenizer, dAtomType, lineNo); |
115 |
> |
parseQuadruple( tokenizer, dAtomType, lineNo); |
116 |
> |
} else { |
117 |
> |
sprintf(painCave.errMsg, "MultipoleAtomTypesSectionParser Error: unrecognized multiple type at line %d\n", |
118 |
> |
lineNo); |
119 |
> |
painCave.isFatal = 1; |
120 |
> |
simError(); |
121 |
> |
} |
122 |
> |
} |
123 |
|
|
124 |
< |
} |
124 |
> |
} |
125 |
|
|
126 |
< |
void MultipoleAtomTypesSectionParser::parseDipole(StringTokenizer& tokenizer, |
127 |
< |
DirectionalAtomType* dAtomType, int lineNo) { |
126 |
> |
void MultipoleAtomTypesSectionParser::parseDipole(StringTokenizer& tokenizer, |
127 |
> |
DirectionalAtomType* dAtomType, int lineNo) { |
128 |
|
|
129 |
|
if (tokenizer.hasMoreTokens()) { |
130 |
< |
double dipole = tokenizer.nextTokenAsDouble(); |
130 |
> |
double dipole = tokenizer.nextTokenAsDouble(); |
131 |
|
|
132 |
< |
dAtomType->addProperty(new DoubleGenericData("Dipole", dipole)); |
133 |
< |
dAtomType->setDipole(); |
132 |
> |
dAtomType->addProperty(new DoubleGenericData("Dipole", dipole)); |
133 |
> |
dAtomType->setDipole(); |
134 |
|
} else { |
135 |
< |
sprintf(painCave.errMsg, "MultipoleAtomTypesSectionParser Error: Not enough tokens at line %d\n", |
136 |
< |
lineNo); |
137 |
< |
painCave.isFatal = 1; |
138 |
< |
simError(); |
135 |
> |
sprintf(painCave.errMsg, "MultipoleAtomTypesSectionParser Error: Not enough tokens at line %d\n", |
136 |
> |
lineNo); |
137 |
> |
painCave.isFatal = 1; |
138 |
> |
simError(); |
139 |
|
} |
140 |
< |
} |
140 |
> |
} |
141 |
|
|
142 |
< |
void MultipoleAtomTypesSectionParser::parseSplitDipole(StringTokenizer& tokenizer, |
143 |
< |
DirectionalAtomType* dAtomType, int lineNo) { |
142 |
> |
void MultipoleAtomTypesSectionParser::parseSplitDipole(StringTokenizer& tokenizer, |
143 |
> |
DirectionalAtomType* dAtomType, int lineNo) { |
144 |
|
|
145 |
|
if (tokenizer.hasMoreTokens()) { |
146 |
< |
parseDipole(tokenizer, dAtomType, lineNo); |
147 |
< |
double splitDipoleDistance = tokenizer.nextTokenAsDouble(); |
148 |
< |
dAtomType->addProperty(new DoubleGenericData("SplitDipoleDistance", splitDipoleDistance)); |
149 |
< |
dAtomType->setSplitDipole(); |
146 |
> |
parseDipole(tokenizer, dAtomType, lineNo); |
147 |
> |
double splitDipoleDistance = tokenizer.nextTokenAsDouble(); |
148 |
> |
dAtomType->addProperty(new DoubleGenericData("SplitDipoleDistance", splitDipoleDistance)); |
149 |
> |
dAtomType->setSplitDipole(); |
150 |
|
} else { |
151 |
< |
sprintf(painCave.errMsg, "MultipoleAtomTypesSectionParser Error: Not enough tokens at line %d\n", |
152 |
< |
lineNo); |
153 |
< |
painCave.isFatal = 1; |
154 |
< |
simError(); |
151 |
> |
sprintf(painCave.errMsg, "MultipoleAtomTypesSectionParser Error: Not enough tokens at line %d\n", |
152 |
> |
lineNo); |
153 |
> |
painCave.isFatal = 1; |
154 |
> |
simError(); |
155 |
|
} |
156 |
< |
} |
156 |
> |
} |
157 |
|
|
158 |
< |
void MultipoleAtomTypesSectionParser::parseQuadruple(StringTokenizer& tokenizer, |
159 |
< |
DirectionalAtomType* dAtomType, int lineNo) { |
158 |
> |
void MultipoleAtomTypesSectionParser::parseQuadruple(StringTokenizer& tokenizer, |
159 |
> |
DirectionalAtomType* dAtomType, int lineNo) { |
160 |
|
int nTokens = tokenizer.countTokens(); |
161 |
< |
if (nTokens < 3) { |
162 |
< |
Vector3d Q; |
163 |
< |
Q[0] = tokenizer.nextTokenAsDouble(); |
164 |
< |
Q[1] = tokenizer.nextTokenAsDouble(); |
165 |
< |
Q[2] = tokenizer.nextTokenAsDouble(); |
161 |
> |
if (nTokens >= 3) { |
162 |
> |
Vector3d Q; |
163 |
> |
Q[0] = tokenizer.nextTokenAsDouble(); |
164 |
> |
Q[1] = tokenizer.nextTokenAsDouble(); |
165 |
> |
Q[2] = tokenizer.nextTokenAsDouble(); |
166 |
|
|
167 |
< |
double trace = Q[0] + Q[1] + Q[2]; |
167 |
> |
double trace = Q[0] + Q[1] + Q[2]; |
168 |
|
|
169 |
< |
if (fabs(trace) > oopse::epsilon) { |
170 |
< |
sprintf(painCave.errMsg, "MultipoleAtomTypesSectionParser Error: the trace of qudrupole moments is not zero at line %d\n", |
171 |
< |
lineNo); |
172 |
< |
painCave.isFatal = 1; |
173 |
< |
simError(); |
174 |
< |
} |
169 |
> |
if (fabs(trace) > oopse::epsilon) { |
170 |
> |
sprintf(painCave.errMsg, "MultipoleAtomTypesSectionParser Error: the trace of qudrupole moments is not zero at line %d\n", |
171 |
> |
lineNo); |
172 |
> |
painCave.isFatal = 1; |
173 |
> |
simError(); |
174 |
> |
} |
175 |
|
|
176 |
< |
dAtomType->addProperty(new Vector3dGenericData("QuadrupoleMoments", Q)); |
177 |
< |
dAtomType->setQuadrupole(); |
176 |
> |
dAtomType->addProperty(new Vector3dGenericData("QuadrupoleMoments", Q)); |
177 |
> |
dAtomType->setQuadrupole(); |
178 |
|
} else { |
179 |
< |
sprintf(painCave.errMsg, "MultipoleAtomTypesSectionParser Error: Not enough tokens at line %d\n", |
180 |
< |
lineNo); |
181 |
< |
painCave.isFatal = 1; |
182 |
< |
simError(); |
179 |
> |
sprintf(painCave.errMsg, "MultipoleAtomTypesSectionParser Error: Not enough tokens at line %d\n", |
180 |
> |
lineNo); |
181 |
> |
painCave.isFatal = 1; |
182 |
> |
simError(); |
183 |
|
} |
184 |
< |
} |
184 |
> |
} |
185 |
|
|
186 |
|
|
187 |
|
} //end namespace oopse |