1 |
chrisfen |
153 |
/* |
2 |
|
|
* Shapes_FF.cpp |
3 |
|
|
* oopse |
4 |
|
|
* |
5 |
|
|
* Created by Chris Fennell on 10/20/04. |
6 |
|
|
* Copyright 2004 __MyCompanyName__. All rights reserved. |
7 |
|
|
* |
8 |
|
|
*/ |
9 |
|
|
|
10 |
gezelter |
31 |
#include <stdlib.h> |
11 |
|
|
#include <stdio.h> |
12 |
|
|
#include <string.h> |
13 |
chrisfen |
153 |
#include <map> |
14 |
gezelter |
157 |
#include <cmath> |
15 |
chrisfen |
153 |
#include <iostream> |
16 |
gezelter |
31 |
|
17 |
|
|
#ifdef IS_MPI |
18 |
|
|
#include <mpi.h> |
19 |
|
|
#endif //is_mpi |
20 |
|
|
|
21 |
|
|
#include "UseTheForce/ForceFields.hpp" |
22 |
|
|
#include "primitives/SRI.hpp" |
23 |
|
|
#include "utils/simError.h" |
24 |
gezelter |
157 |
#include "utils/StringUtils.hpp" |
25 |
chrisfen |
153 |
#include "io/basic_ifstrstream.hpp" |
26 |
|
|
#include "math/RealSphericalHarmonic.hpp" |
27 |
|
|
#include "math/SquareMatrix3.hpp" |
28 |
gezelter |
157 |
#include "types/ShapeAtomType.hpp" |
29 |
chrisfen |
153 |
#include "UseTheForce/DarkSide/atype_interface.h" |
30 |
gezelter |
120 |
#include "UseTheForce/DarkSide/shapes_interface.h" |
31 |
gezelter |
31 |
|
32 |
|
|
#ifdef IS_MPI |
33 |
|
|
#include "UseTheForce/mpiForceField.h" |
34 |
|
|
#endif // is_mpi |
35 |
|
|
|
36 |
gezelter |
157 |
using namespace std; |
37 |
|
|
using namespace oopse; |
38 |
gezelter |
31 |
|
39 |
|
|
Shapes_FF::~Shapes_FF(){ |
40 |
|
|
|
41 |
|
|
#ifdef IS_MPI |
42 |
|
|
if( worldRank == 0 ){ |
43 |
|
|
#endif // is_mpi |
44 |
|
|
|
45 |
gezelter |
157 |
forceFile.close(); |
46 |
gezelter |
31 |
|
47 |
|
|
#ifdef IS_MPI |
48 |
|
|
} |
49 |
|
|
#endif // is_mpi |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
|
53 |
|
|
void Shapes_FF::calcRcut( void ){ |
54 |
|
|
|
55 |
|
|
#ifdef IS_MPI |
56 |
|
|
double tempShapesRcut = shapesRcut; |
57 |
|
|
MPI_Allreduce( &tempShapesRcut, &shapesRcut, 1, MPI_DOUBLE, MPI_MAX, |
58 |
|
|
MPI_COMM_WORLD); |
59 |
|
|
#endif //is_mpi |
60 |
|
|
entry_plug->setDefaultRcut(shapesRcut); |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
|
64 |
gezelter |
135 |
void Shapes_FF::initForceField(){ |
65 |
|
|
initFortran(0); |
66 |
gezelter |
31 |
} |
67 |
|
|
|
68 |
|
|
|
69 |
gezelter |
157 |
void Shapes_FF::readParams( void ){ |
70 |
gezelter |
31 |
|
71 |
chrisfen |
153 |
char readLine[1024]; |
72 |
gezelter |
157 |
|
73 |
|
|
string fileName; |
74 |
|
|
string shapeFileName; |
75 |
|
|
string tempString; |
76 |
|
|
|
77 |
chrisfen |
153 |
char *nameToken; |
78 |
|
|
char *delim = " ,;\t\n"; |
79 |
|
|
int nTokens, i; |
80 |
|
|
int nContact = 0; |
81 |
|
|
int nRange = 0; |
82 |
|
|
int nStrength = 0; |
83 |
|
|
int myATID; |
84 |
gezelter |
157 |
int isError; |
85 |
chrisfen |
153 |
string nameString; |
86 |
gezelter |
157 |
AtomType* at; |
87 |
|
|
DirectionalAtomType* dat; |
88 |
|
|
ShapeAtomType* st; |
89 |
|
|
|
90 |
chrisfen |
153 |
map<string, AtomType*>::iterator iter; |
91 |
gezelter |
31 |
|
92 |
chrisfen |
153 |
// vectors for shape transfer to fortran |
93 |
gezelter |
157 |
vector<RealSphericalHarmonic*> tempSHVector; |
94 |
chrisfen |
153 |
vector<int> contactL; |
95 |
|
|
vector<int> contactM; |
96 |
|
|
vector<int> contactFunc; |
97 |
|
|
vector<double> contactCoeff; |
98 |
|
|
vector<int> rangeL; |
99 |
|
|
vector<int> rangeM; |
100 |
|
|
vector<int> rangeFunc; |
101 |
|
|
vector<double> rangeCoeff; |
102 |
|
|
vector<int> strengthL; |
103 |
|
|
vector<int> strengthM; |
104 |
|
|
vector<int> strengthFunc; |
105 |
|
|
vector<double> strengthCoeff; |
106 |
|
|
|
107 |
|
|
// generate the force file name |
108 |
gezelter |
157 |
fileName = "Shapes.frc"; |
109 |
chrisfen |
153 |
|
110 |
|
|
// attempt to open the file in the current directory first. |
111 |
gezelter |
157 |
forceFile.open( fileName.c_str() ); |
112 |
chrisfen |
153 |
|
113 |
gezelter |
157 |
if( forceFile == NULL ){ |
114 |
gezelter |
31 |
|
115 |
gezelter |
157 |
tempString = ffPath; |
116 |
|
|
tempString += "/"; |
117 |
|
|
tempString += fileName; |
118 |
|
|
fileName = tempString; |
119 |
gezelter |
31 |
|
120 |
gezelter |
157 |
forceFile.open( fileName.c_str() ); |
121 |
gezelter |
31 |
|
122 |
gezelter |
157 |
if( forceFile == NULL ){ |
123 |
chrisfen |
153 |
|
124 |
|
|
sprintf( painCave.errMsg, |
125 |
|
|
"Error opening the force field parameter file:\n" |
126 |
|
|
"\t%s\n" |
127 |
|
|
"\tHave you tried setting the FORCE_PARAM_PATH environment " |
128 |
|
|
"variable?\n", |
129 |
gezelter |
157 |
fileName.c_str() ); |
130 |
chrisfen |
153 |
painCave.severity = OOPSE_ERROR; |
131 |
gezelter |
31 |
painCave.isFatal = 1; |
132 |
|
|
simError(); |
133 |
|
|
} |
134 |
chrisfen |
153 |
} |
135 |
|
|
|
136 |
|
|
// read in the shape types. |
137 |
|
|
|
138 |
gezelter |
157 |
findBegin( forceFile, "ShapeTypes" ); |
139 |
chrisfen |
153 |
|
140 |
gezelter |
157 |
while( !forceFile.eof() ){ |
141 |
|
|
forceFile.getline( readLine, sizeof(readLine) ); |
142 |
gezelter |
31 |
|
143 |
chrisfen |
153 |
// toss comment lines |
144 |
|
|
if( readLine[0] != '!' && readLine[0] != '#' ){ |
145 |
|
|
|
146 |
|
|
if (isEndLine(readLine)) break; |
147 |
|
|
|
148 |
gezelter |
157 |
nTokens = countTokens(readLine, " ,;\t"); |
149 |
chrisfen |
153 |
if (nTokens != 0) { |
150 |
|
|
if (nTokens < 2) { |
151 |
|
|
sprintf( painCave.errMsg, |
152 |
gezelter |
157 |
"Not enough data on a ShapeTypes line in file: %s\n", |
153 |
|
|
fileName.c_str() ); |
154 |
chrisfen |
153 |
painCave.severity = OOPSE_ERROR; |
155 |
|
|
painCave.isFatal = 1; |
156 |
|
|
simError(); |
157 |
|
|
} |
158 |
gezelter |
31 |
|
159 |
chrisfen |
153 |
nameToken = strtok( readLine, delim ); |
160 |
|
|
shapeFileName = strtok( NULL, delim ); |
161 |
gezelter |
31 |
|
162 |
chrisfen |
153 |
// strings are not char arrays! |
163 |
|
|
nameString = nameToken; |
164 |
gezelter |
31 |
|
165 |
chrisfen |
153 |
// does this AtomType name already exist in the map? |
166 |
|
|
iter = atomTypeMap.find(nameString); |
167 |
|
|
if (iter == atomTypeMap.end()) { |
168 |
|
|
// no, it doesn't, so we may proceed: |
169 |
|
|
|
170 |
gezelter |
157 |
st = new ShapeAtomType(); |
171 |
gezelter |
31 |
|
172 |
chrisfen |
153 |
st->setName(nameString); |
173 |
|
|
myATID = atomTypeMap.size(); |
174 |
|
|
st->setIdent(myATID); |
175 |
|
|
parseShapeFile(shapeFileName, st); |
176 |
|
|
st->complete(); |
177 |
|
|
atomTypeMap.insert(make_pair(nameString, st)); |
178 |
|
|
|
179 |
|
|
} else { |
180 |
|
|
// atomType map already contained this string (i.e. it was |
181 |
|
|
// declared in a previous block, and we just need to add |
182 |
|
|
// the shape-specific information for this AtomType: |
183 |
gezelter |
31 |
|
184 |
gezelter |
157 |
st = (ShapeAtomType*)(iter->second); |
185 |
chrisfen |
153 |
parseShapeFile(shapeFileName, st); |
186 |
|
|
} |
187 |
|
|
} |
188 |
gezelter |
31 |
} |
189 |
|
|
} |
190 |
|
|
|
191 |
chrisfen |
153 |
#ifdef IS_MPI |
192 |
gezelter |
31 |
|
193 |
chrisfen |
153 |
// looks like all the processors have their ShapeType vectors ready... |
194 |
|
|
sprintf( checkPointMsg, |
195 |
|
|
"Shapes_FF shape objects read successfully." ); |
196 |
|
|
MPIcheckPoint(); |
197 |
gezelter |
31 |
|
198 |
chrisfen |
153 |
#endif // is_mpi |
199 |
gezelter |
31 |
|
200 |
chrisfen |
153 |
// pack up and send the necessary info to fortran |
201 |
|
|
for (iter = atomTypeMap.begin(); iter != atomTypeMap.end(); ++iter){ |
202 |
gezelter |
31 |
|
203 |
gezelter |
157 |
at = (AtomType*)(iter->second); |
204 |
gezelter |
31 |
|
205 |
chrisfen |
153 |
if (at->isDirectional()) { |
206 |
gezelter |
31 |
|
207 |
chrisfen |
153 |
dat = (DirectionalAtomType*)at; |
208 |
gezelter |
31 |
|
209 |
chrisfen |
153 |
if (dat->isShape()) { |
210 |
gezelter |
31 |
|
211 |
chrisfen |
153 |
st = (ShapeAtomType*)at; |
212 |
|
|
|
213 |
|
|
contactL.clear(); |
214 |
|
|
contactM.clear(); |
215 |
|
|
contactFunc.clear(); |
216 |
|
|
contactCoeff.clear(); |
217 |
|
|
|
218 |
|
|
tempSHVector = st->getContactFuncs(); |
219 |
|
|
|
220 |
|
|
nContact = tempSHVector.size(); |
221 |
|
|
for (i=0; i<nContact; i++){ |
222 |
gezelter |
157 |
contactL.push_back(tempSHVector[i]->getL()); |
223 |
|
|
contactM.push_back(tempSHVector[i]->getM()); |
224 |
|
|
contactFunc.push_back(tempSHVector[i]->getFunctionType()); |
225 |
|
|
contactCoeff.push_back(tempSHVector[i]->getCoefficient()); |
226 |
chrisfen |
153 |
} |
227 |
|
|
|
228 |
|
|
rangeL.clear(); |
229 |
|
|
rangeM.clear(); |
230 |
|
|
rangeFunc.clear(); |
231 |
|
|
rangeCoeff.clear(); |
232 |
|
|
|
233 |
|
|
tempSHVector = st->getRangeFuncs(); |
234 |
|
|
|
235 |
|
|
nRange = tempSHVector.size(); |
236 |
|
|
for (i=0; i<nRange; i++){ |
237 |
gezelter |
157 |
rangeL.push_back(tempSHVector[i]->getL()); |
238 |
|
|
rangeM.push_back(tempSHVector[i]->getM()); |
239 |
|
|
rangeFunc.push_back(tempSHVector[i]->getFunctionType()); |
240 |
|
|
rangeCoeff.push_back(tempSHVector[i]->getCoefficient()); |
241 |
chrisfen |
153 |
} |
242 |
|
|
|
243 |
|
|
strengthL.clear(); |
244 |
|
|
strengthM.clear(); |
245 |
|
|
strengthFunc.clear(); |
246 |
|
|
strengthCoeff.clear(); |
247 |
|
|
|
248 |
|
|
tempSHVector = st->getStrengthFuncs(); |
249 |
|
|
|
250 |
|
|
nStrength = tempSHVector.size(); |
251 |
|
|
for (i=0; i<nStrength; i++){ |
252 |
gezelter |
157 |
strengthL.push_back(tempSHVector[i]->getL()); |
253 |
|
|
strengthM.push_back(tempSHVector[i]->getM()); |
254 |
|
|
strengthFunc.push_back(tempSHVector[i]->getFunctionType()); |
255 |
|
|
strengthCoeff.push_back(tempSHVector[i]->getCoefficient()); |
256 |
chrisfen |
153 |
} |
257 |
|
|
|
258 |
|
|
isError = 0; |
259 |
|
|
myATID = at->getIdent(); |
260 |
gezelter |
157 |
makeShape( &nContact, &contactL[0], &contactM[0], &contactFunc[0], |
261 |
|
|
&contactCoeff[0], |
262 |
|
|
&nRange, &rangeL[0], &rangeM[0], &rangeFunc[0], |
263 |
|
|
&rangeCoeff[0], |
264 |
|
|
&nStrength, &strengthL[0], &strengthM[0], |
265 |
|
|
&strengthFunc[0], &strengthCoeff[0], |
266 |
chrisfen |
153 |
&myATID, |
267 |
|
|
&isError); |
268 |
|
|
if( isError ){ |
269 |
|
|
sprintf( painCave.errMsg, |
270 |
|
|
"Error initializing the \"%s\" shape in fortran\n", |
271 |
gezelter |
157 |
(iter->first).c_str() ); |
272 |
chrisfen |
153 |
painCave.isFatal = 1; |
273 |
|
|
simError(); |
274 |
|
|
} |
275 |
|
|
} |
276 |
gezelter |
31 |
} |
277 |
|
|
} |
278 |
|
|
|
279 |
|
|
#ifdef IS_MPI |
280 |
|
|
sprintf( checkPointMsg, |
281 |
|
|
"Shapes_FF atom structures successfully sent to fortran\n" ); |
282 |
|
|
MPIcheckPoint(); |
283 |
|
|
#endif // is_mpi |
284 |
|
|
|
285 |
|
|
} |
286 |
|
|
|
287 |
gezelter |
157 |
void Shapes_FF::cleanMe( void ){ |
288 |
|
|
|
289 |
|
|
} |
290 |
|
|
|
291 |
|
|
void Shapes_FF::initializeAtoms( int nAtoms, Atom** the_atoms ){ |
292 |
chrisfen |
153 |
|
293 |
|
|
int i,j,k; |
294 |
gezelter |
157 |
map<string, AtomType*>::iterator iter; |
295 |
gezelter |
31 |
|
296 |
|
|
// initialize the atoms |
297 |
chrisfen |
153 |
DirectionalAtom* dAtom; |
298 |
|
|
AtomType* at; |
299 |
|
|
DirectionalAtomType* dat; |
300 |
gezelter |
157 |
ShapeAtomType* sat; |
301 |
|
|
double sigma; |
302 |
chrisfen |
153 |
double ji[3]; |
303 |
|
|
double inertialMat[3][3]; |
304 |
|
|
Mat3x3d momInt; |
305 |
|
|
string myTypeString; |
306 |
|
|
|
307 |
gezelter |
31 |
for( i=0; i<nAtoms; i++ ){ |
308 |
|
|
|
309 |
chrisfen |
153 |
myTypeString = the_atoms[i]->getType(); |
310 |
|
|
iter = atomTypeMap.find(myTypeString); |
311 |
|
|
|
312 |
|
|
if (iter == atomTypeMap.end()) { |
313 |
gezelter |
31 |
sprintf( painCave.errMsg, |
314 |
|
|
"AtomType error, %s not found in force file.\n", |
315 |
|
|
the_atoms[i]->getType() ); |
316 |
|
|
painCave.isFatal = 1; |
317 |
|
|
simError(); |
318 |
chrisfen |
153 |
} else { |
319 |
gezelter |
31 |
|
320 |
chrisfen |
153 |
at = (AtomType*)(iter->second); |
321 |
gezelter |
31 |
|
322 |
chrisfen |
153 |
the_atoms[i]->setMass( at->getMass() ); |
323 |
|
|
the_atoms[i]->setIdent( at->getIdent() ); |
324 |
gezelter |
157 |
|
325 |
|
|
if ( at->isShape() ) { |
326 |
|
|
|
327 |
|
|
sat = (ShapeAtomType*)at; |
328 |
|
|
sigma = findLargestContactDistance(sat); |
329 |
|
|
if (sigma > bigSigma) bigSigma = sigma; |
330 |
gezelter |
31 |
|
331 |
chrisfen |
153 |
} |
332 |
gezelter |
31 |
|
333 |
chrisfen |
153 |
the_atoms[i]->setHasCharge(at->isCharge()); |
334 |
gezelter |
31 |
|
335 |
chrisfen |
153 |
if( at->isDirectional() ){ |
336 |
gezelter |
31 |
|
337 |
chrisfen |
153 |
dat = (DirectionalAtomType*)at; |
338 |
|
|
dAtom = (DirectionalAtom *) the_atoms[i]; |
339 |
gezelter |
179 |
|
340 |
chrisfen |
153 |
momInt = dat->getI(); |
341 |
gezelter |
31 |
|
342 |
chrisfen |
153 |
// zero out the moments of inertia matrix |
343 |
|
|
for( j=0; j<3; j++ ) |
344 |
|
|
for( k=0; k<3; k++ ) |
345 |
|
|
inertialMat[j][k] = momInt(j,k); |
346 |
|
|
dAtom->setI( inertialMat ); |
347 |
gezelter |
31 |
|
348 |
chrisfen |
153 |
ji[0] = 0.0; |
349 |
|
|
ji[1] = 0.0; |
350 |
|
|
ji[2] = 0.0; |
351 |
|
|
dAtom->setJ( ji ); |
352 |
gezelter |
31 |
|
353 |
chrisfen |
153 |
if (dat->isDipole()) { |
354 |
|
|
dAtom->setHasDipole( dat->isDipole() ); |
355 |
|
|
entry_plug->n_dipoles++; |
356 |
|
|
} |
357 |
|
|
} |
358 |
gezelter |
31 |
} |
359 |
|
|
} |
360 |
|
|
} |
361 |
|
|
|
362 |
chrisfen |
153 |
void Shapes_FF::initializeBonds( int nBonds, Bond** BondArray, |
363 |
|
|
bond_pair* the_bonds ){ |
364 |
gezelter |
31 |
|
365 |
chrisfen |
153 |
if( nBonds ){ |
366 |
gezelter |
31 |
sprintf( painCave.errMsg, |
367 |
chrisfen |
153 |
"Shapes_FF does not support bonds.\n" ); |
368 |
gezelter |
31 |
painCave.isFatal = 1; |
369 |
|
|
simError(); |
370 |
|
|
} |
371 |
chrisfen |
153 |
} |
372 |
gezelter |
31 |
|
373 |
chrisfen |
153 |
void Shapes_FF::initializeBends( int nBends, Bend** bendArray, |
374 |
|
|
bend_set* the_bends ){ |
375 |
|
|
|
376 |
|
|
if( nBends ){ |
377 |
gezelter |
31 |
sprintf( painCave.errMsg, |
378 |
chrisfen |
153 |
"Shapes_FF does not support bends.\n" ); |
379 |
gezelter |
31 |
painCave.isFatal = 1; |
380 |
|
|
simError(); |
381 |
|
|
} |
382 |
chrisfen |
153 |
} |
383 |
gezelter |
31 |
|
384 |
chrisfen |
153 |
void Shapes_FF::initializeTorsions( int nTorsions, Torsion** torsionArray, |
385 |
|
|
torsion_set* the_torsions ){ |
386 |
gezelter |
31 |
|
387 |
chrisfen |
153 |
if( nTorsions ){ |
388 |
gezelter |
31 |
sprintf( painCave.errMsg, |
389 |
chrisfen |
153 |
"Shapes_FF does not support torsions.\n" ); |
390 |
gezelter |
31 |
painCave.isFatal = 1; |
391 |
|
|
simError(); |
392 |
|
|
} |
393 |
chrisfen |
153 |
} |
394 |
gezelter |
31 |
|
395 |
gezelter |
157 |
void Shapes_FF::parseShapeFile(string shapeFileName, ShapeAtomType* st){ |
396 |
chrisfen |
153 |
const int MAXLEN = 1024; |
397 |
|
|
char inLine[MAXLEN]; |
398 |
|
|
char *token; |
399 |
|
|
char *delim = " ,;\t\n"; |
400 |
gezelter |
157 |
int nTokens; |
401 |
chrisfen |
153 |
Mat3x3d momInert; |
402 |
gezelter |
157 |
RealSphericalHarmonic* rsh; |
403 |
|
|
vector<RealSphericalHarmonic*> functionVector; |
404 |
|
|
ifstrstream shapeFile; |
405 |
|
|
string tempString; |
406 |
gezelter |
31 |
|
407 |
gezelter |
157 |
shapeFile.open( shapeFileName.c_str() ); |
408 |
gezelter |
31 |
|
409 |
gezelter |
157 |
if( shapeFile == NULL ){ |
410 |
|
|
|
411 |
|
|
tempString = ffPath; |
412 |
|
|
tempString += "/"; |
413 |
|
|
tempString += shapeFileName; |
414 |
|
|
shapeFileName = tempString; |
415 |
|
|
|
416 |
|
|
shapeFile.open( shapeFileName.c_str() ); |
417 |
|
|
|
418 |
|
|
if( shapeFile == NULL ){ |
419 |
|
|
|
420 |
|
|
sprintf( painCave.errMsg, |
421 |
|
|
"Error opening the shape file:\n" |
422 |
|
|
"\t%s\n" |
423 |
|
|
"\tHave you tried setting the FORCE_PARAM_PATH environment " |
424 |
|
|
"variable?\n", |
425 |
|
|
shapeFileName.c_str() ); |
426 |
|
|
painCave.severity = OOPSE_ERROR; |
427 |
|
|
painCave.isFatal = 1; |
428 |
|
|
simError(); |
429 |
|
|
} |
430 |
|
|
} |
431 |
|
|
|
432 |
|
|
// read in the shape types. |
433 |
|
|
|
434 |
chrisfen |
153 |
// first grab the values in the ShapeInfo section |
435 |
gezelter |
157 |
findBegin( shapeFile, "ShapeInfo"); |
436 |
gezelter |
31 |
|
437 |
chrisfen |
153 |
shapeFile.getline(inLine, MAXLEN); |
438 |
|
|
while( !shapeFile.eof() ) { |
439 |
|
|
// toss comment lines |
440 |
|
|
if( inLine[0] != '!' && inLine[0] != '#' ){ |
441 |
|
|
// end marks section completion |
442 |
|
|
if (isEndLine(inLine)) break; |
443 |
|
|
|
444 |
gezelter |
157 |
nTokens = countTokens(inLine, delim); |
445 |
chrisfen |
153 |
if (nTokens != 0) { |
446 |
|
|
if (nTokens < 5) { |
447 |
|
|
sprintf( painCave.errMsg, |
448 |
gezelter |
157 |
"Not enough data on a ShapeInfo line in file: %s\n", |
449 |
|
|
shapeFileName.c_str() ); |
450 |
chrisfen |
153 |
painCave.severity = OOPSE_ERROR; |
451 |
|
|
painCave.isFatal = 1; |
452 |
|
|
simError(); |
453 |
gezelter |
31 |
|
454 |
chrisfen |
153 |
token = strtok(inLine, delim); |
455 |
|
|
token = strtok(NULL, delim); |
456 |
|
|
st->setMass(atof(token)); |
457 |
|
|
token = strtok(NULL, delim); |
458 |
|
|
momInert(0,0) = atof(token); |
459 |
|
|
token = strtok(NULL, delim); |
460 |
|
|
momInert(1,1) = atof(token); |
461 |
|
|
token = strtok(NULL, delim); |
462 |
|
|
momInert(2,2) = atof(token); |
463 |
|
|
st->setI(momInert); |
464 |
|
|
} |
465 |
|
|
} |
466 |
gezelter |
31 |
} |
467 |
gezelter |
179 |
shapeFile.getline(inLine, MAXLEN); |
468 |
gezelter |
31 |
} |
469 |
|
|
|
470 |
chrisfen |
153 |
// now grab the contact functions |
471 |
|
|
findBegin(shapeFile, "ContactFunctions"); |
472 |
|
|
functionVector.clear(); |
473 |
gezelter |
31 |
|
474 |
chrisfen |
153 |
shapeFile.getline(inLine, MAXLEN); |
475 |
|
|
while( !shapeFile.eof() ) { |
476 |
|
|
// toss comment lines |
477 |
|
|
if( inLine[0] != '!' && inLine[0] != '#' ){ |
478 |
|
|
// end marks section completion |
479 |
|
|
if (isEndLine(inLine)) break; |
480 |
|
|
|
481 |
gezelter |
157 |
nTokens = countTokens(inLine, delim); |
482 |
chrisfen |
153 |
if (nTokens != 0) { |
483 |
|
|
if (nTokens < 4) { |
484 |
|
|
sprintf( painCave.errMsg, |
485 |
gezelter |
157 |
"Not enough data on a ContactFunctions line in file: %s\n", |
486 |
|
|
shapeFileName.c_str() ); |
487 |
chrisfen |
153 |
painCave.severity = OOPSE_ERROR; |
488 |
|
|
painCave.isFatal = 1; |
489 |
|
|
simError(); |
490 |
|
|
|
491 |
|
|
// read in a spherical harmonic function |
492 |
|
|
token = strtok(inLine, delim); |
493 |
gezelter |
157 |
rsh = new RealSphericalHarmonic(); |
494 |
|
|
rsh->setL(atoi(token)); |
495 |
chrisfen |
153 |
token = strtok(NULL, delim); |
496 |
gezelter |
157 |
rsh->setM(atoi(token)); |
497 |
chrisfen |
153 |
token = strtok(NULL, delim); |
498 |
|
|
if (!strcasecmp("sin",token)) |
499 |
gezelter |
157 |
rsh->makeSinFunction(); |
500 |
chrisfen |
153 |
else |
501 |
gezelter |
157 |
rsh->makeCosFunction(); |
502 |
chrisfen |
153 |
token = strtok(NULL, delim); |
503 |
gezelter |
157 |
rsh->setCoefficient(atof(token)); |
504 |
chrisfen |
153 |
|
505 |
gezelter |
157 |
functionVector.push_back(rsh); |
506 |
chrisfen |
153 |
} |
507 |
|
|
} |
508 |
gezelter |
31 |
} |
509 |
gezelter |
179 |
shapeFile.getline(inLine, MAXLEN); |
510 |
gezelter |
31 |
} |
511 |
|
|
|
512 |
chrisfen |
153 |
// pass contact functions to ShapeType |
513 |
|
|
st->setContactFuncs(functionVector); |
514 |
gezelter |
31 |
|
515 |
chrisfen |
153 |
// now grab the range functions |
516 |
|
|
findBegin(shapeFile, "RangeFunctions"); |
517 |
|
|
functionVector.clear(); |
518 |
gezelter |
31 |
|
519 |
chrisfen |
153 |
shapeFile.getline(inLine, MAXLEN); |
520 |
|
|
while( !shapeFile.eof() ) { |
521 |
|
|
// toss comment lines |
522 |
|
|
if( inLine[0] != '!' && inLine[0] != '#' ){ |
523 |
|
|
// end marks section completion |
524 |
|
|
if (isEndLine(inLine)) break; |
525 |
|
|
|
526 |
gezelter |
157 |
nTokens = countTokens(inLine, delim); |
527 |
chrisfen |
153 |
if (nTokens != 0) { |
528 |
|
|
if (nTokens < 4) { |
529 |
|
|
sprintf( painCave.errMsg, |
530 |
gezelter |
157 |
"Not enough data on a RangeFunctions line in file: %s\n", |
531 |
|
|
shapeFileName.c_str() ); |
532 |
chrisfen |
153 |
painCave.severity = OOPSE_ERROR; |
533 |
|
|
painCave.isFatal = 1; |
534 |
|
|
simError(); |
535 |
|
|
|
536 |
|
|
// read in a spherical harmonic function |
537 |
|
|
token = strtok(inLine, delim); |
538 |
gezelter |
157 |
|
539 |
|
|
rsh = new RealSphericalHarmonic(); |
540 |
|
|
rsh->setL(atoi(token)); |
541 |
chrisfen |
153 |
token = strtok(NULL, delim); |
542 |
gezelter |
157 |
rsh->setM(atoi(token)); |
543 |
chrisfen |
153 |
token = strtok(NULL, delim); |
544 |
|
|
if (!strcasecmp("sin",token)) |
545 |
gezelter |
157 |
rsh->makeSinFunction(); |
546 |
chrisfen |
153 |
else |
547 |
gezelter |
157 |
rsh->makeCosFunction(); |
548 |
chrisfen |
153 |
token = strtok(NULL, delim); |
549 |
gezelter |
157 |
rsh->setCoefficient(atof(token)); |
550 |
chrisfen |
153 |
|
551 |
gezelter |
157 |
functionVector.push_back(rsh); |
552 |
chrisfen |
153 |
} |
553 |
|
|
} |
554 |
gezelter |
31 |
} |
555 |
gezelter |
179 |
shapeFile.getline(inLine, MAXLEN); |
556 |
chrisfen |
153 |
} |
557 |
gezelter |
31 |
|
558 |
chrisfen |
153 |
// pass range functions to ShapeType |
559 |
|
|
st->setRangeFuncs(functionVector); |
560 |
gezelter |
31 |
|
561 |
chrisfen |
153 |
// finally grab the strength functions |
562 |
|
|
findBegin(shapeFile, "StrengthFunctions"); |
563 |
|
|
functionVector.clear(); |
564 |
gezelter |
31 |
|
565 |
chrisfen |
153 |
shapeFile.getline(inLine, MAXLEN); |
566 |
|
|
while( !shapeFile.eof() ) { |
567 |
|
|
// toss comment lines |
568 |
|
|
if( inLine[0] != '!' && inLine[0] != '#' ){ |
569 |
|
|
// end marks section completion |
570 |
|
|
if (isEndLine(inLine)) break; |
571 |
|
|
|
572 |
gezelter |
157 |
nTokens = countTokens(inLine, delim); |
573 |
chrisfen |
153 |
if (nTokens != 0) { |
574 |
|
|
if (nTokens < 4) { |
575 |
|
|
sprintf( painCave.errMsg, |
576 |
gezelter |
157 |
"Not enough data on a StrengthFunctions line in file: %s\n", |
577 |
|
|
shapeFileName.c_str() ); |
578 |
chrisfen |
153 |
painCave.severity = OOPSE_ERROR; |
579 |
|
|
painCave.isFatal = 1; |
580 |
|
|
simError(); |
581 |
|
|
|
582 |
|
|
// read in a spherical harmonic function |
583 |
|
|
token = strtok(inLine, delim); |
584 |
gezelter |
157 |
rsh = new RealSphericalHarmonic(); |
585 |
|
|
rsh->setL(atoi(token)); |
586 |
chrisfen |
153 |
token = strtok(NULL, delim); |
587 |
gezelter |
157 |
rsh->setM(atoi(token)); |
588 |
chrisfen |
153 |
token = strtok(NULL, delim); |
589 |
|
|
if (!strcasecmp("sin",token)) |
590 |
gezelter |
157 |
rsh->makeSinFunction(); |
591 |
chrisfen |
153 |
else |
592 |
gezelter |
157 |
rsh->makeCosFunction(); |
593 |
chrisfen |
153 |
token = strtok(NULL, delim); |
594 |
gezelter |
157 |
rsh->setCoefficient(atof(token)); |
595 |
chrisfen |
153 |
|
596 |
gezelter |
157 |
functionVector.push_back(rsh); |
597 |
chrisfen |
153 |
} |
598 |
|
|
} |
599 |
gezelter |
31 |
} |
600 |
gezelter |
179 |
shapeFile.getline(inLine, MAXLEN); |
601 |
gezelter |
31 |
} |
602 |
|
|
|
603 |
chrisfen |
153 |
// pass strength functions to ShapeType |
604 |
|
|
st->setStrengthFuncs(functionVector); |
605 |
|
|
|
606 |
|
|
// we're done reading from this file |
607 |
|
|
shapeFile.close(); |
608 |
gezelter |
31 |
} |
609 |
chrisfen |
153 |
|
610 |
gezelter |
157 |
double Shapes_FF::findLargestContactDistance(ShapeAtomType* st) { |
611 |
|
|
int i, j, nSteps; |
612 |
|
|
double theta, thetaStep, thetaMin, costheta; |
613 |
|
|
double phi, phiStep; |
614 |
|
|
double sigma, bigSigma; |
615 |
|
|
|
616 |
|
|
nSteps = 16; |
617 |
|
|
|
618 |
|
|
thetaStep = M_PI / nSteps; |
619 |
|
|
thetaMin = thetaStep / 2.0; |
620 |
|
|
phiStep = thetaStep * 2.0; |
621 |
|
|
bigSigma = 0.0; |
622 |
|
|
|
623 |
|
|
for (i = 0; i < nSteps; i++) { |
624 |
|
|
|
625 |
|
|
theta = thetaMin + i * thetaStep; |
626 |
|
|
costheta = cos(theta); |
627 |
|
|
|
628 |
|
|
for (j = 0; j < nSteps; j++) { |
629 |
|
|
|
630 |
|
|
phi = j*phiStep; |
631 |
|
|
|
632 |
|
|
sigma = st->getContactValueAt(costheta, phi); |
633 |
|
|
|
634 |
|
|
if (sigma > bigSigma) bigSigma = sigma; |
635 |
|
|
} |
636 |
|
|
} |
637 |
|
|
|
638 |
|
|
return bigSigma; |
639 |
|
|
} |