ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/io/ShapeAtomTypesSectionParser.cpp
Revision: 2223
Committed: Wed May 11 23:15:05 2005 UTC (19 years, 1 month ago) by chuckv
File size: 11643 byte(s)
Log Message:
Fixed build issues under ifc7.

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