ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-2.0/src/io/ElectrostaticAtomTypesSectionParser.cpp
Revision: 1883
Committed: Mon Dec 13 22:30:27 2004 UTC (19 years, 7 months ago) by tim
File size: 6114 byte(s)
Log Message:
MPI version is built

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