ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/io/ElectrostaticAtomTypesSectionParser.cpp
Revision: 1957
Committed: Tue Jan 25 17:45:23 2005 UTC (19 years, 5 months ago) by tim
File size: 7409 byte(s)
Log Message:
(1) complete section parser's error message
(2) add GhostTorsion
(3) accumulate inertial tensor from the directional atoms before calculate rigidbody's inertial tensor

File Contents

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