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