1 |
tim |
2097 |
/* |
2 |
|
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
|
|
* |
4 |
|
|
* The University of Notre Dame grants you ("Licensee") a |
5 |
|
|
* non-exclusive, royalty free, license to use, modify and |
6 |
|
|
* redistribute this software in source and binary code form, provided |
7 |
|
|
* that the following conditions are met: |
8 |
|
|
* |
9 |
|
|
* 1. Acknowledgement of the program authors must be made in any |
10 |
|
|
* publication of scientific results based in part on use of the |
11 |
|
|
* program. An acceptable form of acknowledgement is citation of |
12 |
|
|
* the article in which the program was described (Matthew |
13 |
|
|
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
14 |
|
|
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
15 |
|
|
* Parallel Simulation Engine for Molecular Dynamics," |
16 |
|
|
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
17 |
|
|
* |
18 |
|
|
* 2. Redistributions of source code must retain the above copyright |
19 |
|
|
* notice, this list of conditions and the following disclaimer. |
20 |
|
|
* |
21 |
|
|
* 3. Redistributions in binary form must reproduce the above copyright |
22 |
|
|
* notice, this list of conditions and the following disclaimer in the |
23 |
|
|
* documentation and/or other materials provided with the |
24 |
|
|
* distribution. |
25 |
|
|
* |
26 |
|
|
* This software is provided "AS IS," without a warranty of any |
27 |
|
|
* kind. All express or implied conditions, representations and |
28 |
|
|
* warranties, including any implied warranty of merchantability, |
29 |
|
|
* fitness for a particular purpose or non-infringement, are hereby |
30 |
|
|
* excluded. The University of Notre Dame and its licensors shall not |
31 |
|
|
* be liable for any damages suffered by licensee as a result of |
32 |
|
|
* using, modifying or distributing the software or its |
33 |
|
|
* derivatives. In no event will the University of Notre Dame or its |
34 |
|
|
* licensors be liable for any lost revenue, profit or data, or for |
35 |
|
|
* direct, indirect, special, consequential, incidental or punitive |
36 |
|
|
* damages, however caused and regardless of the theory of liability, |
37 |
|
|
* arising out of the use of or inability to use software, even if the |
38 |
|
|
* University of Notre Dame has been advised of the possibility of |
39 |
|
|
* such damages. |
40 |
|
|
*/ |
41 |
|
|
|
42 |
|
|
#include "io/MultipoleAtomTypesSectionParser.hpp" |
43 |
|
|
#include "UseTheForce/ForceField.hpp" |
44 |
|
|
#include "utils/NumericConstant.hpp" |
45 |
|
|
#include "utils/simError.h" |
46 |
|
|
namespace oopse { |
47 |
|
|
|
48 |
|
|
MultipoleAtomTypesSectionParser::MultipoleAtomTypesSectionParser() { |
49 |
|
|
setSectionName("MultipoleAtomTypes"); |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
void MultipoleAtomTypesSectionParser::parseLine(ForceField& ff,const std::string& line, int lineNo){ |
53 |
|
|
StringTokenizer tokenizer(line); |
54 |
|
|
int nTokens = tokenizer.countTokens(); |
55 |
|
|
|
56 |
|
|
// name multipole_type theta phi psi |
57 |
|
|
// "name" must match the name in the AtomTypes section |
58 |
|
|
// avaliable multipole type is d (dipole), s (split dipole) , q (quadrupoles), dq(dipole plus quadrupole) |
59 |
|
|
// and sq(split dipole plus quadrupole) |
60 |
|
|
// Directionality for dipoles and quadrupoles is given by three euler angles (phi, theta, psi), |
61 |
|
|
//because the body-fixed reference frame for directional atoms is determined by the *mass* |
62 |
|
|
//distribution and not by the charge distribution. |
63 |
|
|
// Dipoles are given in units of Debye |
64 |
|
|
// Quadrupoles are given in units of |
65 |
|
|
// examples: |
66 |
tim |
2102 |
// 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 |
tim |
2097 |
|
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(); |
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; |
85 |
|
|
|
86 |
|
|
AtomType* atomType = ff.getAtomType(atomTypeName); |
87 |
|
|
if (atomType == NULL) { |
88 |
tim |
2098 |
sprintf(painCave.errMsg, "MultipoleAtomTypesSectionParser Error: Can not find matched AtomType[%s] at line %d\n", |
89 |
|
|
atomTypeName.c_str(), lineNo); |
90 |
tim |
2097 |
painCave.isFatal = 1; |
91 |
|
|
simError(); |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
DirectionalAtomType* dAtomType = dynamic_cast<DirectionalAtomType*>(atomType); |
95 |
|
|
if (dAtomType == NULL) { |
96 |
tim |
2098 |
sprintf(painCave.errMsg, "MultipoleAtomTypesSectionParser Error: Can not Cast Atom to DirectionalAtom at line %d\n", lineNo); |
97 |
tim |
2097 |
painCave.isFatal = 1; |
98 |
|
|
simError(); |
99 |
|
|
} |
100 |
|
|
|
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 |
|
|
} |
123 |
|
|
|
124 |
|
|
} |
125 |
|
|
|
126 |
|
|
void MultipoleAtomTypesSectionParser::parseDipole(StringTokenizer& tokenizer, |
127 |
|
|
DirectionalAtomType* dAtomType, int lineNo) { |
128 |
|
|
|
129 |
|
|
if (tokenizer.hasMoreTokens()) { |
130 |
|
|
double dipole = tokenizer.nextTokenAsDouble(); |
131 |
|
|
|
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(); |
139 |
|
|
} |
140 |
|
|
} |
141 |
|
|
|
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(); |
150 |
|
|
} else { |
151 |
|
|
sprintf(painCave.errMsg, "MultipoleAtomTypesSectionParser Error: Not enough tokens at line %d\n", |
152 |
|
|
lineNo); |
153 |
|
|
painCave.isFatal = 1; |
154 |
|
|
simError(); |
155 |
|
|
} |
156 |
|
|
} |
157 |
|
|
|
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(); |
166 |
|
|
|
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 |
|
|
} |
175 |
|
|
|
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(); |
183 |
|
|
} |
184 |
|
|
} |
185 |
|
|
|
186 |
|
|
|
187 |
|
|
} //end namespace oopse |
188 |
|
|
|
189 |
|
|
|
190 |
|
|
|