ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/io/BendTypesSectionParser.cpp
Revision: 1957
Committed: Tue Jan 25 17:45:23 2005 UTC (19 years, 5 months ago) by tim
File size: 8049 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

# Content
1 /*
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/BendTypesSectionParser.hpp"
43 #include "types/HarmonicBendType.hpp"
44 #include "types/UreyBradleyBendType.hpp"
45 #include "types/CubicBendType.hpp"
46 #include "types/QuarticBendType.hpp"
47 #include "types/PolynomialBendType.hpp"
48 #include "UseTheForce/ForceField.hpp"
49 #include "utils/NumericConstant.hpp"
50 #include "utils/simError.h"
51 namespace oopse {
52
53 BendTypesSectionParser::BendTypesSectionParser() {
54 setSectionName("BendTypes");
55
56 stringToEnumMap_["Harmonic"] = btHarmonic;
57 stringToEnumMap_["GhostBend"] = btGhostBend;
58 stringToEnumMap_["UreyBradley"] = btUreyBradley;
59 stringToEnumMap_["Cubic"] = btCubic;
60 stringToEnumMap_["Quartic"] = btQuartic;
61 stringToEnumMap_["Polynomial"] = btPolynomial;
62 }
63
64 void BendTypesSectionParser::parseLine(ForceField& ff,const std::string& line, int lineNo){
65 StringTokenizer tokenizer(line);
66 BendType* bendType = NULL;
67
68 int nTokens = tokenizer.countTokens();
69
70 if (nTokens < 5) {
71 sprintf(painCave.errMsg, "BendTypesSectionParser Error: Not enough tokens at line %d\n",
72 lineNo);
73 painCave.isFatal = 1;
74 simError();
75 return;
76 }
77
78 std::string at1 = tokenizer.nextToken();
79 std::string at2 = tokenizer.nextToken();
80 std::string at3 = tokenizer.nextToken();
81 BendTypeEnum bt = getBendTypeEnum(tokenizer.nextToken());
82 double theta0 = tokenizer.nextTokenAsDouble() / 180.0 * NumericConstant::PI; //convert to rad
83 nTokens -= 5;
84
85 //switch is a maintain nightmare
86 switch(bt) {
87
88 case btHarmonic :
89
90 if (nTokens < 1) {
91 sprintf(painCave.errMsg, "BendTypesSectionParser Error: Not enough tokens at line %d\n",
92 lineNo);
93 painCave.isFatal = 1;
94 simError();
95 } else {
96
97 double ktheta = tokenizer.nextTokenAsDouble();
98 bendType = new HarmonicBendType(theta0, ktheta);
99 }
100 break;
101 case btGhostBend :
102 if (nTokens < 1) {
103 sprintf(painCave.errMsg, "BendTypesSectionParser Error: Not enough tokens at line %d\n",
104 lineNo);
105 painCave.isFatal = 1;
106 simError();
107 } else {
108 double ktheta = tokenizer.nextTokenAsDouble();
109 bendType = new HarmonicBendType(theta0, ktheta);
110 }
111 break;
112
113 case btUreyBradley :
114 if (nTokens < 3) {
115 sprintf(painCave.errMsg, "BendTypesSectionParser Error: Not enough tokens at line %d\n",
116 lineNo);
117 painCave.isFatal = 1;
118 simError();
119 } else {
120 double ktheta = tokenizer.nextTokenAsDouble();
121 double s0 = tokenizer.nextTokenAsDouble();
122 double kub = tokenizer.nextTokenAsDouble();
123 bendType = new UreyBradleyBendType(theta0, ktheta, s0, kub);
124 }
125 break;
126
127 case btCubic :
128 if (nTokens < 4) {
129 sprintf(painCave.errMsg, "BendTypesSectionParser Error: Not enough tokens at line %d\n",
130 lineNo);
131 painCave.isFatal = 1;
132 simError();
133 } else {
134
135 double k3 = tokenizer.nextTokenAsDouble();
136 double k2 = tokenizer.nextTokenAsDouble();
137 double k1 = tokenizer.nextTokenAsDouble();
138 double k0 = tokenizer.nextTokenAsDouble();
139
140 bendType = new CubicBendType(theta0, k3, k2, k1, k0);
141 }
142 break;
143
144 case btQuartic :
145 if (nTokens < 5) {
146 sprintf(painCave.errMsg, "BendTypesSectionParser Error: Not enough tokens at line %d\n",
147 lineNo);
148 painCave.isFatal = 1;
149 simError();
150 } else {
151
152 theta0 = tokenizer.nextTokenAsDouble();
153 double k4 = tokenizer.nextTokenAsDouble();
154 double k3 = tokenizer.nextTokenAsDouble();
155 double k2 = tokenizer.nextTokenAsDouble();
156 double k1 = tokenizer.nextTokenAsDouble();
157 double k0 = tokenizer.nextTokenAsDouble();
158
159 bendType = new QuarticBendType(theta0, k4, k3, k2, k1, k0);
160 }
161 break;
162
163 case btPolynomial :
164 if (nTokens < 2 || nTokens % 2 != 0) {
165 sprintf(painCave.errMsg, "BendTypesSectionParser Error: Not enough tokens at line %d\n",
166 lineNo);
167 painCave.isFatal = 1;
168 simError();
169 } else {
170 int nPairs = nTokens / 2;
171 int power;
172 double coefficient;
173 PolynomialBendType* pbt = new PolynomialBendType(theta0);
174
175 for (int i = 0; i < nPairs; ++i) {
176 power = tokenizer.nextTokenAsInt();
177 coefficient = tokenizer.nextTokenAsDouble();
178 pbt->setCoefficient(power, coefficient);
179 }
180 }
181
182 break;
183
184 case btUnknown :
185 default:
186 sprintf(painCave.errMsg, "BendTypesSectionParser Error: Unknown Bond Type at line %d\n",
187 lineNo);
188 painCave.isFatal = 1;
189 simError();
190 break;
191
192 }
193
194 if (bendType != NULL) {
195 ff.addBendType(at1, at2, at3, bendType);
196 }
197 }
198
199 BendTypesSectionParser::BendTypeEnum BendTypesSectionParser::getBendTypeEnum(const std::string& str) {
200 std::map<std::string, BendTypeEnum>::iterator i;
201 i = stringToEnumMap_.find(str);
202
203 return i == stringToEnumMap_.end() ? btUnknown : i->second;
204 }
205
206 } //end namespace oopse
207
208