1 |
gezelter |
1930 |
/* |
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/ElectrostaticAtomTypesSectionParser.hpp" |
43 |
|
|
#include "UseTheForce/ForceField.hpp" |
44 |
|
|
#include "utils/NumericConstant.hpp" |
45 |
|
|
namespace oopse { |
46 |
|
|
|
47 |
|
|
ElectrostaticAtomTypesSectionParser::ElectrostaticAtomTypesSectionParser() { |
48 |
|
|
setSectionName("ElectrostaticAtomTypes"); |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
void ElectrostaticAtomTypesSectionParser::parseLine(ForceField& ff,const std::string& line, int lineNo){ |
52 |
|
|
StringTokenizer tokenizer(line); |
53 |
|
|
int nTokens = tokenizer.countTokens(); |
54 |
|
|
|
55 |
|
|
//in AtomTypeSection, a line at least contains 2 tokens |
56 |
|
|
//atomTypeName and biggest rank |
57 |
|
|
//for the time being, we only support up to quadrupole |
58 |
|
|
// "name" must match the name in the AtomTypes section |
59 |
|
|
// charge is given in units of electrons (1.61 x 10^-19 C) |
60 |
|
|
// Directionality for dipoles and quadrupoles must be given because the body-fixed |
61 |
|
|
// reference frame for directional atoms is determined by the *mass* distribution and |
62 |
|
|
// not by the charge distribution. |
63 |
|
|
// Dipoles are given in units of Debye |
64 |
|
|
// Quadrupoles are given in units of |
65 |
|
|
// name 0 charge |
66 |
|
|
// name 1 charge |u| [theta phi psi] |
67 |
|
|
// name 2 charge |u| Qxx Qyy Qzz [theta phi psi] |
68 |
|
|
|
69 |
|
|
if (nTokens < 2) { |
70 |
|
|
std::cerr << "ElectrostaticAtomTypesSectionParser Error: Not enought Tokens at line " << lineNo << std::endl; |
71 |
|
|
} else { |
72 |
|
|
|
73 |
|
|
std::string atomTypeName = tokenizer.nextToken(); |
74 |
|
|
int biggestRank = tokenizer.nextTokenAsInt(); |
75 |
|
|
nTokens -= 2; |
76 |
|
|
|
77 |
|
|
AtomType* atomType = ff.getAtomType(atomTypeName); |
78 |
|
|
DirectionalAtomType* dAtomType; |
79 |
|
|
if (atomType != NULL) { |
80 |
|
|
|
81 |
|
|
switch (biggestRank) { |
82 |
|
|
case 0 : |
83 |
|
|
parseCharge(tokenizer, atomType); |
84 |
|
|
break; |
85 |
|
|
|
86 |
|
|
case 1 : |
87 |
|
|
|
88 |
|
|
dAtomType = dynamic_cast<DirectionalAtomType*>(atomType); |
89 |
|
|
if (dAtomType == NULL) { |
90 |
|
|
std::cerr << "ElectrostaticAtomTypesSectionParser Warning:" << std::endl; |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
parseCharge(tokenizer, dAtomType); |
94 |
|
|
parseDipole(tokenizer, dAtomType); |
95 |
|
|
parseElectroBodyFrame(tokenizer, dAtomType); |
96 |
|
|
break; |
97 |
|
|
|
98 |
|
|
case 2: |
99 |
|
|
|
100 |
|
|
dAtomType = dynamic_cast<DirectionalAtomType*>(atomType); |
101 |
|
|
if (dAtomType == NULL) { |
102 |
|
|
std::cerr << "ElectrostaticAtomTypesSectionParser Warning:" << std::endl; |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
parseCharge(tokenizer, dAtomType); |
106 |
|
|
parseDipole(tokenizer, dAtomType); |
107 |
|
|
parseQuadruple(tokenizer, dAtomType); |
108 |
|
|
parseElectroBodyFrame(tokenizer, dAtomType); |
109 |
|
|
break; |
110 |
|
|
|
111 |
|
|
default : |
112 |
|
|
break; |
113 |
|
|
|
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
} else { |
117 |
|
|
std::cerr << "ElectrostaticAtomTypesSectionParser Error: Can not find matched AtomType " << atomTypeName |
118 |
|
|
<< "at line " << lineNo << std::endl; |
119 |
|
|
} |
120 |
|
|
|
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
|
124 |
|
|
} |
125 |
|
|
|
126 |
|
|
|
127 |
|
|
void ElectrostaticAtomTypesSectionParser::parseCharge(StringTokenizer& tokenizer, |
128 |
|
|
AtomType* atomType) { |
129 |
|
|
|
130 |
|
|
double charge = tokenizer.nextTokenAsDouble(); |
131 |
|
|
|
132 |
|
|
if (fabs(charge) > NumericConstant::epsilon) { |
133 |
|
|
atomType->addProperty(new DoubleGenericData("Charge", charge)); |
134 |
|
|
atomType->setCharge(); |
135 |
|
|
} |
136 |
|
|
} |
137 |
|
|
void ElectrostaticAtomTypesSectionParser::parseDipole(StringTokenizer& tokenizer, |
138 |
|
|
DirectionalAtomType* dAtomType) { |
139 |
|
|
|
140 |
|
|
double dipole = tokenizer.nextTokenAsDouble(); |
141 |
|
|
|
142 |
|
|
if (fabs(dipole) > NumericConstant::epsilon) { |
143 |
|
|
|
144 |
|
|
dAtomType->addProperty(new DoubleGenericData("Dipole", dipole)); |
145 |
|
|
dAtomType->setDipole(); |
146 |
|
|
} |
147 |
|
|
} |
148 |
|
|
|
149 |
|
|
void ElectrostaticAtomTypesSectionParser::parseQuadruple(StringTokenizer& tokenizer, |
150 |
|
|
DirectionalAtomType* dAtomType) { |
151 |
|
|
|
152 |
|
|
Vector3d Q; |
153 |
|
|
Q[0] = tokenizer.nextTokenAsDouble(); |
154 |
|
|
Q[1] = tokenizer.nextTokenAsDouble(); |
155 |
|
|
Q[2] = tokenizer.nextTokenAsDouble(); |
156 |
|
|
|
157 |
|
|
if (fabs(Q[0]) > NumericConstant::epsilon && fabs(Q[1]) > NumericConstant::epsilon |
158 |
|
|
&& fabs(Q[2]) > NumericConstant::epsilon) { |
159 |
|
|
|
160 |
|
|
dAtomType->addProperty(new Vector3dGenericData("Quadrupole", Q)); |
161 |
|
|
dAtomType->setQuadrupole(); |
162 |
|
|
} |
163 |
|
|
} |
164 |
|
|
void ElectrostaticAtomTypesSectionParser::parseElectroBodyFrame(StringTokenizer& tokenizer, |
165 |
|
|
DirectionalAtomType* dAtomType) { |
166 |
|
|
|
167 |
|
|
double phi; |
168 |
|
|
double theta; |
169 |
|
|
double psi; |
170 |
|
|
|
171 |
|
|
if (tokenizer.countTokens() >=3 ) { |
172 |
|
|
phi = tokenizer.nextTokenAsDouble()/180.0; |
173 |
|
|
theta = tokenizer.nextTokenAsDouble()/180.0; |
174 |
|
|
psi = tokenizer.nextTokenAsDouble()/180.0; |
175 |
|
|
} else { |
176 |
|
|
phi = 0.0; |
177 |
|
|
theta = 0.0; |
178 |
|
|
psi = 0.0; |
179 |
|
|
} |
180 |
|
|
|
181 |
|
|
RotMat3x3d electroBodyFrame(phi, theta, psi); |
182 |
|
|
dAtomType->setElectroBodyFrame(electroBodyFrame); |
183 |
|
|
|
184 |
|
|
} |
185 |
|
|
|
186 |
|
|
} //end namespace oopse |
187 |
|
|
|
188 |
|
|
|
189 |
|
|
|