ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/io/ElectrostaticAtomTypesSectionParser.cpp
Revision: 1869
Committed: Wed Dec 8 20:37:47 2004 UTC (19 years, 9 months ago) by tim
File size: 5788 byte(s)
Log Message:
fix a parsing bug in ElectroStaticAtomTypesSectionParser

File Contents

# User Rev Content
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 1869 DirectionalAtomType* dAtomType;
64 tim 1770 if (atomType != NULL) {
65 tim 1869
66 tim 1815 switch (biggestRank) {
67 tim 1869 case 0 :
68 tim 1815 parseCharge(tokenizer, atomType);
69     break;
70    
71 tim 1869 case 1 :
72    
73     dAtomType = dynamic_cast<DirectionalAtomType*>(atomType);
74     if (dAtomType == NULL) {
75     std::cerr << "ElectrostaticAtomTypesSectionParser Warning:" << std::endl;
76     }
77    
78 tim 1815 parseCharge(tokenizer, dAtomType);
79     parseDipole(tokenizer, dAtomType);
80     parseElectroBodyFrame(tokenizer, dAtomType);
81     break;
82    
83 tim 1869 case 2:
84    
85     dAtomType = dynamic_cast<DirectionalAtomType*>(atomType);
86     if (dAtomType == NULL) {
87     std::cerr << "ElectrostaticAtomTypesSectionParser Warning:" << std::endl;
88     }
89    
90 tim 1815 parseCharge(tokenizer, dAtomType);
91     parseDipole(tokenizer, dAtomType);
92     parseQuadruple(tokenizer, dAtomType);
93     parseElectroBodyFrame(tokenizer, dAtomType);
94     break;
95    
96     default :
97     break;
98    
99     }
100 tim 1770
101     } else {
102     std::cerr << "ElectrostaticAtomTypesSectionParser Error: Can not find matched AtomType " << atomTypeName
103     << "at line " << lineNo << std::endl;
104     }
105    
106     }
107    
108    
109     }
110    
111 tim 1813
112     void ElectrostaticAtomTypesSectionParser::parseCharge(StringTokenizer& tokenizer,
113     AtomType* atomType) {
114    
115     double charge = tokenizer.nextTokenAsDouble();
116     atomType->addProperty(new DoubleGenericData("Charge", charge));
117     atomType->setCharge();
118    
119     }
120     void ElectrostaticAtomTypesSectionParser::parseDipole(StringTokenizer& tokenizer,
121     DirectionalAtomType* dAtomType) {
122    
123     double Dipole = tokenizer.nextTokenAsDouble();
124     dAtomType->addProperty(new DoubleGenericData("Dipole", Dipole));
125     dAtomType->setDipole();
126     }
127    
128     void ElectrostaticAtomTypesSectionParser::parseQuadruple(StringTokenizer& tokenizer,
129     DirectionalAtomType* dAtomType) {
130    
131     Vector3d Q;
132 tim 1815 Q[0] = tokenizer.nextTokenAsDouble();
133     Q[1] = tokenizer.nextTokenAsDouble();
134     Q[2] = tokenizer.nextTokenAsDouble();
135 tim 1813
136     dAtomType->addProperty(new Vector3dGenericData("Quadrupole", Q));
137     dAtomType->setQuadrupole();
138     }
139     void ElectrostaticAtomTypesSectionParser::parseElectroBodyFrame(StringTokenizer& tokenizer,
140     DirectionalAtomType* dAtomType) {
141    
142 tim 1815 double phi;
143     double theta;
144     double psi;
145 tim 1813
146 tim 1815 if (tokenizer.countTokens() >=3 ) {
147     phi = tokenizer.nextTokenAsDouble()/180.0;
148     theta = tokenizer.nextTokenAsDouble()/180.0;
149     psi = tokenizer.nextTokenAsDouble()/180.0;
150     } else {
151     phi = 0.0;
152     theta = 0.0;
153     psi = 0.0;
154     }
155    
156 tim 1813 RotMat3x3d electroBodyFrame(phi, theta, psi);
157     dAtomType->setElectroBodyFrame(electroBodyFrame);
158    
159     }
160    
161 tim 1770 } //end namespace oopse
162    
163    
164