ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/io/ShapeAtomTypesSectionParser.cpp
Revision: 2209
Committed: Mon Apr 18 03:50:23 2005 UTC (19 years, 2 months ago) by chrisfen
File size: 10906 byte(s)
Log Message:
Working on the shapes parser...

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 "UseTheForce/ForceField.hpp"
43 #include "io/basic_ifstrstream.hpp"
44 #include "io/ShapeAtomTypesSectionParser.hpp"
45 #include "math/RealSphericalHarmonic.hpp"
46 #include "math/SquareMatrix3.hpp"
47 #include "types/AtomType.hpp"
48 #include "types/DirectionalAtomType.hpp"
49 #include "types/ShapeAtomType.hpp"
50 #include "utils/StringUtils.hpp"
51 #include "utils/simError.h"
52
53 namespace oopse {
54
55 ShapeAtomTypesSectionParser::ShapesAtomTypesSectionParser() {
56 setSectionName("ShapesAtomTypes");
57 }
58
59 void ShapeAtomTypesSectionParser::parseLine(ForceField& ff,
60 const std::string& line,
61 int lineNo){
62 StringTokenizer tokenizer(line);
63
64 if (tokenizer.countTokens() >= 2) {
65 std::string shapeTypeName = tokenizer.nextToken();
66 std::string shapeFile = tokenizer.nextToken();
67
68 AtomType* atomType = ff.getAtomType(shapeTypeName);
69
70 if (atomType != NULL){
71 DirectionalAtomType* dAtomType =
72 dynamic_cast<DirectionalAtomType*>(atomType);
73
74 if (dAtomType != NULL) {
75 ShapeAtomType* sAtomType = dynamic_cast<ShapeAtomType*>(dAtomType);
76
77 sAtomType->setShape();
78 parseShapesFile(ff, shapeFile, sAtomType);
79 } else {
80 sprintf(painCave.errMsg,
81 "ShapesAtomTypesSectionParser Error: "
82 "Can't find ShapeAtomType [%s]\n",
83 atomTypeName.c_str());
84 painCave.severity = OOPSE_ERROR;
85 painCave.isFatal = 1;
86 simError();
87 }
88 } else {
89 sprintf(painCave.errMsg,
90 "ShapesAtomTypesSectionParser Error: "
91 "Can't find ShapeAtomType [%s]\n",
92 atomTypeName.c_str());
93 painCave.severity = OOPSE_ERROR;
94 painCave.isFatal = 1;
95 simError();
96 }
97 } else {
98 sprintf(painCave.errMsg,
99 "ShapesAtomTypesSectionParser Error: "
100 "Not enough tokens at line %d\n",
101 lineNo);
102 painCave.severity = OOPSE_ERROR;
103 painCave.isFatal = 1;
104 simError();
105 }
106 }
107
108 void ShapeAtomTypesSectionParser::parseShapeFile(ForceField& ff,
109 string shapeFileName,
110 ShapeAtomType* st) {
111
112 ifstrstream* shapeStream = ff.openForceFieldFile(shapeFileName);
113 const int bufferSize = 65535;
114 char buffer[bufferSize];
115 char *token;
116 std::string line;
117 int junk;
118 Mat3x3d momInert;
119 RealSphericalHarmonic* rsh;
120 std::vector<RealSphericalHarmonic*> functionVector;
121
122 // first parse the info. in the ShapeInfo section
123 findBegin( shapeStream, "ShapeInfo");
124 shapeStream->getline(buffer, bufferSize);
125
126 // loop over the interior of the ShapeInfo section
127 while( !shapeStream.eof() ) {
128 // toss comment lines
129 if( buffer[0] != '!' && buffer[0] != '#' ){
130 // end marks section completion
131 if (isEndLine(buffer)) break;
132 StringTokenizer tokenInfo(buffer);
133 // blank lines are ignored
134 if (tokenInfo.countTokens() != 0) {
135 if (tokenInfo.countTokens() < 5) {
136 sprintf(painCave.errMsg,
137 "ShapesAtomTypesSectionParser Error: Not enough "
138 "information on a ShapeInfo line in file: %s\n",
139 shapeFileName.c_str() );
140 painCave.severity = OOPSE_ERROR;
141 painCave.isFatal = 1;
142 simError();
143 } else {
144 junk = tokenInfo.nextTokenAsInt();
145 st->setMass( tokenInfo.nextTokenAsDouble() );
146 momInert(0,0) = tokenInfo.nextTokenAsDouble();
147 momInert(1,1) = tokenInfo.nextTokenAsDouble()
148 momInert(2,2) = tokenInfo.nextTokenAsDouble()
149 st->setI(momInert);
150 }
151 }
152 }
153 shapeStream->getline(buffer, bufferSize);
154 }
155
156 // now grab the contact functions
157 findBegin(shapeStream, "ContactFunctions");
158 functionVector.clear();
159
160 shapeStream->getline(buffer, bufferSize);
161 while( !shapeStream.eof() ) {
162 // toss comment lines
163 if( buffer[0] != '!' && buffer[0] != '#' ){
164 // end marks section completion
165 if (isEndLine(buffer)) break;
166 StringTokenizer tokenInfo1(buffer);
167 // blank lines are ignored
168 if (tokenInfo1.countTokens() != 0) {
169 if (tokenInfo1.countTokens() < 4) {
170 sprintf( painCave.errMsg,
171 "ShapesAtomTypesSectionParser Error: Not enough "
172 "information on a ContactFunctions line in file: %s\n",
173 shapeFileName.c_str() );
174 painCave.severity = OOPSE_ERROR;
175 painCave.isFatal = 1;
176 simError();
177 } else {
178 // read in a spherical harmonic function
179 rsh = new RealSphericalHarmonic();
180 rsh->setL( tokenInfo1.nextTokenAsInt() );
181 rsh->setM( tokenInfo1.nextTokenAsInt() );
182 token = tokenInfo1.nextTokenAsChar();
183 if (!strcasecmp("sin",token))
184 rsh->makeSinFunction();
185 else
186 rsh->makeCosFunction();
187 rsh->setCoefficient( tokenInfo1.nextTokenAsDouble() );
188
189 functionVector.push_back(rsh);
190 }
191 }
192 }
193 shapeStream.getline(buffer, bufferSize);
194 }
195
196 // pass contact functions to ShapeType
197 st->setContactFuncs(functionVector);
198
199 // now grab the range functions
200 findBegin(shapeStream, "RangeFunctions");
201 functionVector.clear();
202
203 shapeStream->getline(buffer, bufferSize);
204 while( !shapeStream.eof() ) {
205 // toss comment lines
206 if( buffer[0] != '!' && buffer[0] != '#' ){
207 // end marks section completion
208 if (isEndLine(buffer)) break;
209 StringTokenizer tokenInfo2(buffer);
210 // blank lines are ignored
211 if (tokenInfo2.countTokens() != 0) {
212 if (tokenInfo2.countTokens() < 4) {
213 sprintf( painCave.errMsg,
214 "ShapesAtomTypesSectionParser Error: Not enough "
215 "information on a RangeFunctions line in file: %s\n",
216 shapeFileName.c_str() );
217 painCave.severity = OOPSE_ERROR;
218 painCave.isFatal = 1;
219 simError();
220 } else {
221 // read in a spherical harmonic function
222 rsh = new RealSphericalHarmonic();
223 rsh->setL( tokenInfo2.nextTokenAsInt() );
224 rsh->setM( tokenInfo2.nextTokenAsInt() );
225 token = tokenInfo2.nextTokenAsChar();
226 if (!strcasecmp("sin",token))
227 rsh->makeSinFunction();
228 else
229 rsh->makeCosFunction();
230 rsh->setCoefficient( tokenInfo2.nextTokenAsDouble() );
231
232 functionVector.push_back(rsh);
233 }
234 }
235 }
236 shapeStream.getline(buffer, bufferSize);
237 }
238
239 // pass range functions to ShapeType
240 st->setRangeFuncs(functionVector);
241
242 // finally grab the strength functions
243 findBegin(shapeStream, "StrengthFunctions");
244 functionVector.clear();
245
246 shapeStream->getline(buffer, bufferSize);
247 while( !shapeStream.eof() ) {
248 // toss comment lines
249 if( buffer[0] != '!' && buffer[0] != '#' ){
250 // end marks section completion
251 if (isEndLine(buffer)) break;
252 StringTokenizer tokenInfo3(buffer);
253 // blank lines are ignored
254 if (tokenInfo3.countTokens() != 0) {
255 if (tokenInfo3.countTokens() < 4) {
256 sprintf( painCave.errMsg,
257 "ShapesAtomTypesSectionParser Error: Not enough "
258 "information on a StrengthFunctions line in file: %s\n",
259 shapeFileName.c_str() );
260 painCave.severity = OOPSE_ERROR;
261 painCave.isFatal = 1;
262 simError();
263 } else {
264 // read in a spherical harmonic function
265 rsh = new RealSphericalHarmonic();
266 rsh->setL( tokenInfo3.nextTokenAsInt() );
267 rsh->setM( tokenInfo3.nextTokenAsInt() );
268 token = tokenInfo3.nextTokenAsChar();
269 if (!strcasecmp("sin",token))
270 rsh->makeSinFunction();
271 else
272 rsh->makeCosFunction();
273 rsh->setCoefficient( tokenInfo3.nextTokenAsDouble() );
274
275 functionVector.push_back(rsh);
276 }
277 }
278 }
279 shapeStream.getline(buffer, bufferSize);
280 }
281
282 // pass strength functions to ShapeType
283 st->setStrengthFuncs(functionVector);
284
285 delete shapeStream;
286 }
287 } //end namespace oopse
288