1 |
tim |
1770 |
/* |
2 |
|
|
* Copyright (C) 2000-2004 Object Oriented Parallel Simulation Engine (OOPSE) project |
3 |
|
|
* |
4 |
|
|
* Contact: oopse@oopse.org |
5 |
|
|
* |
6 |
|
|
* This program is free software; you can redistribute it and/or |
7 |
|
|
* modify it under the terms of the GNU Lesser General Public License |
8 |
|
|
* as published by the Free Software Foundation; either version 2.1 |
9 |
|
|
* of the License, or (at your option) any later version. |
10 |
|
|
* All we ask is that proper credit is given for our work, which includes |
11 |
|
|
* - but is not limited to - adding the above copyright notice to the beginning |
12 |
|
|
* of your source code files, and to any copyright notice that you may distribute |
13 |
|
|
* with programs based on this work. |
14 |
|
|
* |
15 |
|
|
* This program is distributed in the hope that it will be useful, |
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
|
|
* GNU Lesser General Public License for more details. |
19 |
|
|
* |
20 |
|
|
* You should have received a copy of the GNU Lesser General Public License |
21 |
|
|
* along with this program; if not, write to the Free Software |
22 |
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 |
|
|
* |
24 |
|
|
*/ |
25 |
|
|
|
26 |
|
|
#include "io/ElectrostaticAtomTypesSectionParser.hpp" |
27 |
|
|
|
28 |
tim |
1790 |
#include "UseTheForce/ForceField.hpp" |
29 |
tim |
1784 |
|
30 |
tim |
1770 |
namespace oopse { |
31 |
|
|
|
32 |
|
|
ElectrostaticAtomTypesSectionParser::ElectrostaticAtomTypesSectionParser() { |
33 |
|
|
setSectionName("ElectrostaticAtomTypes"); |
34 |
|
|
} |
35 |
|
|
|
36 |
|
|
void ElectrostaticAtomTypesSectionParser::parseLine(ForceField& ff,const std::string& line, int lineNo){ |
37 |
|
|
StringTokenizer tokenizer(line); |
38 |
|
|
int nTokens = tokenizer.countTokens(); |
39 |
|
|
|
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 |
tim |
1775 |
// "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 |
tim |
1770 |
|
54 |
|
|
if (nTokens < 2) { |
55 |
|
|
std::cerr << "ElectrostaticAtomTypesSectionParser Error: Not enought Tokens at line " << lineNo << std::endl; |
56 |
|
|
} else { |
57 |
|
|
|
58 |
|
|
std::string atomTypeName = tokenizer.nextToken(); |
59 |
|
|
int biggestRank = tokenizer.nextTokenAsInt(); |
60 |
|
|
nTokens -= 2; |
61 |
|
|
|
62 |
tim |
1790 |
AtomType* atomType = ff.getAtomType(atomTypeName); |
63 |
tim |
1770 |
|
64 |
|
|
if (atomType != NULL) { |
65 |
tim |
1815 |
|
66 |
|
|
|
67 |
tim |
1770 |
//parse charge |
68 |
tim |
1815 |
if (biggestRank >= 1) { |
69 |
|
|
parseCharge(tokenizer, atomType); |
70 |
|
|
} |
71 |
|
|
|
72 |
tim |
1770 |
DirectionalAtomType* dAtomType = dynamic_cast<DirectionalAtomType*>(atomType); |
73 |
|
|
if (dAtomType != NULL) { |
74 |
tim |
1813 |
|
75 |
tim |
1770 |
} else { |
76 |
|
|
std::cerr << "ElectrostaticAtomTypesSectionParser Warning:" << std::endl; |
77 |
|
|
} |
78 |
|
|
|
79 |
tim |
1815 |
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 |
tim |
1770 |
|
102 |
|
|
} else { |
103 |
|
|
std::cerr << "ElectrostaticAtomTypesSectionParser Error: Can not find matched AtomType " << atomTypeName |
104 |
|
|
<< "at line " << lineNo << std::endl; |
105 |
|
|
} |
106 |
|
|
|
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
|
110 |
|
|
} |
111 |
|
|
|
112 |
tim |
1813 |
|
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 |
tim |
1815 |
Q[0] = tokenizer.nextTokenAsDouble(); |
134 |
|
|
Q[1] = tokenizer.nextTokenAsDouble(); |
135 |
|
|
Q[2] = tokenizer.nextTokenAsDouble(); |
136 |
tim |
1813 |
|
137 |
|
|
dAtomType->addProperty(new Vector3dGenericData("Quadrupole", Q)); |
138 |
|
|
dAtomType->setQuadrupole(); |
139 |
|
|
} |
140 |
|
|
void ElectrostaticAtomTypesSectionParser::parseElectroBodyFrame(StringTokenizer& tokenizer, |
141 |
|
|
DirectionalAtomType* dAtomType) { |
142 |
|
|
|
143 |
tim |
1815 |
double phi; |
144 |
|
|
double theta; |
145 |
|
|
double psi; |
146 |
tim |
1813 |
|
147 |
tim |
1815 |
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 |
tim |
1813 |
RotMat3x3d electroBodyFrame(phi, theta, psi); |
158 |
|
|
dAtomType->setElectroBodyFrame(electroBodyFrame); |
159 |
|
|
|
160 |
|
|
} |
161 |
|
|
|
162 |
tim |
1770 |
} //end namespace oopse |
163 |
|
|
|
164 |
|
|
|
165 |
|
|
|