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