1 |
+ |
/* |
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 |
|
#include <stdlib.h> |
11 |
|
#include <stdio.h> |
12 |
|
#include <string.h> |
13 |
< |
|
13 |
> |
#include <map> |
14 |
> |
#include <cmath> |
15 |
|
#include <iostream> |
6 |
– |
using namespace std; |
16 |
|
|
17 |
|
#ifdef IS_MPI |
18 |
|
#include <mpi.h> |
21 |
|
#include "UseTheForce/ForceFields.hpp" |
22 |
|
#include "primitives/SRI.hpp" |
23 |
|
#include "utils/simError.h" |
24 |
< |
|
25 |
< |
#include "UseTheForce/fortranWrappers.hpp" |
24 |
> |
#include "utils/StringUtils.hpp" |
25 |
> |
#include "io/basic_ifstrstream.hpp" |
26 |
> |
#include "math/RealSphericalHarmonic.hpp" |
27 |
> |
#include "math/SquareMatrix3.hpp" |
28 |
> |
#include "types/ShapeAtomType.hpp" |
29 |
> |
#include "UseTheForce/DarkSide/atype_interface.h" |
30 |
|
#include "UseTheForce/DarkSide/shapes_interface.h" |
31 |
|
|
32 |
|
#ifdef IS_MPI |
33 |
|
#include "UseTheForce/mpiForceField.h" |
34 |
|
#endif // is_mpi |
35 |
|
|
36 |
< |
Shapes_FF::Shapes_FF() { |
37 |
< |
Shapes_FF(""); |
25 |
< |
} |
36 |
> |
using namespace std; |
37 |
> |
using namespace oopse; |
38 |
|
|
27 |
– |
Shapes_FF::Shapes_FF(char* the_variant){ |
28 |
– |
|
29 |
– |
char fileName[200]; |
30 |
– |
char* ffPath_env = "FORCE_PARAM_PATH"; |
31 |
– |
char* ffPath; |
32 |
– |
char temp[200]; |
33 |
– |
|
34 |
– |
// do the funtion wrapping |
35 |
– |
wrapMeFF( this ); |
36 |
– |
|
37 |
– |
#ifdef IS_MPI |
38 |
– |
if( worldRank == 0 ){ |
39 |
– |
#endif |
40 |
– |
|
41 |
– |
// generate the force file name |
42 |
– |
|
43 |
– |
strcpy( fileName, "Shapes" ); |
44 |
– |
|
45 |
– |
if (strlen(the_variant) > 0) { |
46 |
– |
has_variant = 1; |
47 |
– |
strcpy( variant, the_variant); |
48 |
– |
strcat( fileName, "."); |
49 |
– |
strcat( fileName, variant ); |
50 |
– |
|
51 |
– |
sprintf( painCave.errMsg, |
52 |
– |
"Using %s variant of Shapes force field.\n", |
53 |
– |
variant ); |
54 |
– |
painCave.severity = OOPSE_INFO; |
55 |
– |
painCave.isFatal = 0; |
56 |
– |
simError(); |
57 |
– |
} |
58 |
– |
strcat( fileName, ".frc"); |
59 |
– |
|
60 |
– |
// attempt to open the file in the current directory first. |
61 |
– |
|
62 |
– |
frcFile = fopen( fileName, "r" ); |
63 |
– |
|
64 |
– |
if( frcFile == NULL ){ |
65 |
– |
|
66 |
– |
// next see if the force path enviorment variable is set |
67 |
– |
|
68 |
– |
ffPath = getenv( ffPath_env ); |
69 |
– |
if( ffPath == NULL ) { |
70 |
– |
STR_DEFINE(ffPath, FRC_PATH ); |
71 |
– |
} |
72 |
– |
|
73 |
– |
|
74 |
– |
strcpy( temp, ffPath ); |
75 |
– |
strcat( temp, "/" ); |
76 |
– |
strcat( temp, fileName ); |
77 |
– |
strcpy( fileName, temp ); |
78 |
– |
|
79 |
– |
frcFile = fopen( fileName, "r" ); |
80 |
– |
|
81 |
– |
if( frcFile == NULL ){ |
82 |
– |
|
83 |
– |
sprintf( painCave.errMsg, |
84 |
– |
"Error opening the force field parameter file:\n" |
85 |
– |
"\t%s\n" |
86 |
– |
"\tHave you tried setting the FORCE_PARAM_PATH environment " |
87 |
– |
"variable?\n", |
88 |
– |
fileName ); |
89 |
– |
painCave.severity = OOPSE_ERROR; |
90 |
– |
painCave.isFatal = 1; |
91 |
– |
simError(); |
92 |
– |
} |
93 |
– |
} |
94 |
– |
|
95 |
– |
|
96 |
– |
#ifdef IS_MPI |
97 |
– |
} |
98 |
– |
|
99 |
– |
sprintf( checkPointMsg, "Shapes_FF file opened sucessfully." ); |
100 |
– |
MPIcheckPoint(); |
101 |
– |
|
102 |
– |
#endif // is_mpi |
103 |
– |
} |
104 |
– |
|
105 |
– |
|
39 |
|
Shapes_FF::~Shapes_FF(){ |
40 |
|
|
41 |
|
#ifdef IS_MPI |
42 |
|
if( worldRank == 0 ){ |
43 |
|
#endif // is_mpi |
44 |
|
|
45 |
< |
fclose( frcFile ); |
45 |
> |
forceFile.close(); |
46 |
|
|
47 |
|
#ifdef IS_MPI |
48 |
|
} |
53 |
|
void Shapes_FF::calcRcut( void ){ |
54 |
|
|
55 |
|
#ifdef IS_MPI |
56 |
< |
double tempShapesRcut = shapesRcut; |
56 |
> |
double tempShapesRcut = bigContact; |
57 |
|
MPI_Allreduce( &tempShapesRcut, &shapesRcut, 1, MPI_DOUBLE, MPI_MAX, |
58 |
|
MPI_COMM_WORLD); |
59 |
+ |
#else |
60 |
+ |
shapesRcut = bigContact; |
61 |
|
#endif //is_mpi |
62 |
|
entry_plug->setDefaultRcut(shapesRcut); |
63 |
|
} |
64 |
|
|
65 |
|
|
66 |
< |
void Shapes_FF::initForceField(int ljMixRule){ |
67 |
< |
initFortran(ljMixRule, 0); |
66 |
> |
void Shapes_FF::initForceField(){ |
67 |
> |
initFortran(0); |
68 |
|
} |
69 |
|
|
70 |
|
|
71 |
|
void Shapes_FF::readParams( void ){ |
72 |
|
|
73 |
< |
char shapePotFile[1000]; |
139 |
< |
|
140 |
< |
#ifdef IS_MPI |
141 |
< |
if( worldRank == 0 ){ |
142 |
< |
#endif |
143 |
< |
|
144 |
< |
// read in the atom types. |
73 |
> |
char readLine[1024]; |
74 |
|
|
75 |
< |
fastForward( "AtomTypes", "eam atom readParams" ); |
75 |
> |
string fileName; |
76 |
> |
string shapeFileName; |
77 |
> |
string tempString; |
78 |
|
|
79 |
< |
// we are now at the AtomTypes section. |
79 |
> |
char *nameToken; |
80 |
> |
char *delim = " ,;\t\n"; |
81 |
> |
int nTokens, i; |
82 |
> |
int nContact = 0; |
83 |
> |
int nRange = 0; |
84 |
> |
int nStrength = 0; |
85 |
> |
int myATID; |
86 |
> |
int isError; |
87 |
> |
string nameString; |
88 |
> |
AtomType* at; |
89 |
> |
DirectionalAtomType* dat; |
90 |
> |
ShapeAtomType* st; |
91 |
> |
|
92 |
> |
map<string, AtomType*>::iterator iter; |
93 |
> |
|
94 |
> |
// vectors for shape transfer to fortran |
95 |
> |
vector<RealSphericalHarmonic*> tempSHVector; |
96 |
> |
vector<int> contactL; |
97 |
> |
vector<int> contactM; |
98 |
> |
vector<int> contactFunc; |
99 |
> |
vector<double> contactCoeff; |
100 |
> |
vector<int> rangeL; |
101 |
> |
vector<int> rangeM; |
102 |
> |
vector<int> rangeFunc; |
103 |
> |
vector<double> rangeCoeff; |
104 |
> |
vector<int> strengthL; |
105 |
> |
vector<int> strengthM; |
106 |
> |
vector<int> strengthFunc; |
107 |
> |
vector<double> strengthCoeff; |
108 |
> |
|
109 |
> |
// generate the force file name |
110 |
> |
fileName = "Shapes.frc"; |
111 |
> |
|
112 |
> |
// attempt to open the file in the current directory first. |
113 |
> |
forceFile.open( fileName.c_str() ); |
114 |
> |
|
115 |
> |
if( forceFile == NULL ){ |
116 |
|
|
117 |
< |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
118 |
< |
lineNum++; |
117 |
> |
tempString = ffPath; |
118 |
> |
tempString += "/"; |
119 |
> |
tempString += fileName; |
120 |
> |
fileName = tempString; |
121 |
|
|
122 |
+ |
forceFile.open( fileName.c_str() ); |
123 |
|
|
124 |
< |
// read a line, and start parseing out the atom types |
125 |
< |
|
126 |
< |
if( eof_test == NULL ){ |
127 |
< |
sprintf( painCave.errMsg, |
128 |
< |
"Error in reading Atoms from force file at line %d.\n", |
129 |
< |
lineNum ); |
124 |
> |
if( forceFile == NULL ){ |
125 |
> |
|
126 |
> |
sprintf( painCave.errMsg, |
127 |
> |
"Error opening the force field parameter file:\n" |
128 |
> |
"\t%s\n" |
129 |
> |
"\tHave you tried setting the FORCE_PARAM_PATH environment " |
130 |
> |
"variable?\n", |
131 |
> |
fileName.c_str() ); |
132 |
> |
painCave.severity = OOPSE_ERROR; |
133 |
|
painCave.isFatal = 1; |
134 |
|
simError(); |
135 |
|
} |
136 |
< |
|
137 |
< |
identNum = 1; |
138 |
< |
// stop reading at end of file, or at next section |
136 |
> |
} |
137 |
> |
|
138 |
> |
// read in the shape types. |
139 |
> |
|
140 |
> |
findBegin( forceFile, "ShapeTypes" ); |
141 |
> |
|
142 |
> |
while( !forceFile.eof() ){ |
143 |
> |
forceFile.getline( readLine, sizeof(readLine) ); |
144 |
|
|
145 |
< |
while( readLine[0] != '#' && eof_test != NULL ){ |
146 |
< |
|
147 |
< |
// toss comment lines |
148 |
< |
if( readLine[0] != '!' ){ |
149 |
< |
|
150 |
< |
// the parser returns 0 if the line was blank |
151 |
< |
if( parseAtom( readLine, lineNum, info, eamPotFile ) ){ |
152 |
< |
parseEAM(info,eamPotFile, &eam_rvals, |
153 |
< |
&eam_rhovals, &eam_Frhovals); |
154 |
< |
info.ident = identNum; |
155 |
< |
headAtomType->add( info, eam_rvals, |
156 |
< |
eam_rhovals,eam_Frhovals ); |
157 |
< |
identNum++; |
145 |
> |
// toss comment lines |
146 |
> |
if( readLine[0] != '!' && readLine[0] != '#' ){ |
147 |
> |
|
148 |
> |
if (isEndLine(readLine)) break; |
149 |
> |
|
150 |
> |
nTokens = countTokens(readLine, " ,;\t"); |
151 |
> |
if (nTokens != 0) { |
152 |
> |
if (nTokens < 2) { |
153 |
> |
sprintf( painCave.errMsg, |
154 |
> |
"Not enough data on a ShapeTypes line in file: %s\n", |
155 |
> |
fileName.c_str() ); |
156 |
> |
painCave.severity = OOPSE_ERROR; |
157 |
> |
painCave.isFatal = 1; |
158 |
> |
simError(); |
159 |
|
} |
160 |
< |
} |
161 |
< |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
162 |
< |
lineNum++; |
184 |
< |
} |
185 |
< |
|
186 |
< |
|
160 |
> |
|
161 |
> |
nameToken = strtok( readLine, delim ); |
162 |
> |
shapeFileName = strtok( NULL, delim ); |
163 |
|
|
164 |
< |
#ifdef IS_MPI |
165 |
< |
|
190 |
< |
|
191 |
< |
// send out the linked list to all the other processes |
164 |
> |
// strings are not char arrays! |
165 |
> |
nameString = nameToken; |
166 |
|
|
167 |
< |
sprintf( checkPointMsg, |
168 |
< |
"Shapes_FF atom structures read successfully." ); |
169 |
< |
MPIcheckPoint(); |
167 |
> |
// does this AtomType name already exist in the map? |
168 |
> |
iter = atomTypeMap.find(nameString); |
169 |
> |
if (iter == atomTypeMap.end()) { |
170 |
> |
// no, it doesn't, so we may proceed: |
171 |
> |
|
172 |
> |
st = new ShapeAtomType(); |
173 |
|
|
174 |
< |
currentAtomType = headAtomType->next; //skip the first element who is a place holder. |
175 |
< |
while( currentAtomType != NULL ){ |
176 |
< |
currentAtomType->duplicate( info ); |
174 |
> |
st->setName(nameString); |
175 |
> |
myATID = atomTypeMap.size() + 1; |
176 |
> |
st->setIdent(myATID); |
177 |
> |
parseShapeFile(shapeFileName, st); |
178 |
> |
st->complete(); |
179 |
> |
atomTypeMap.insert(make_pair(nameString, st)); |
180 |
> |
|
181 |
> |
} else { |
182 |
> |
// atomType map already contained this string (i.e. it was |
183 |
> |
// declared in a previous block, and we just need to add |
184 |
> |
// the shape-specific information for this AtomType: |
185 |
|
|
186 |
< |
|
187 |
< |
|
188 |
< |
sendFrcStruct( &info, mpiAtomStructType ); |
189 |
< |
|
205 |
< |
// We have to now broadcast the Arrays |
206 |
< |
MPI_Bcast(currentAtomType->eam_rvals, |
207 |
< |
currentAtomType->eam_nr, |
208 |
< |
MPI_DOUBLE,0,MPI_COMM_WORLD); |
209 |
< |
MPI_Bcast(currentAtomType->eam_rhovals, |
210 |
< |
currentAtomType->eam_nr, |
211 |
< |
MPI_DOUBLE,0,MPI_COMM_WORLD); |
212 |
< |
MPI_Bcast(currentAtomType->eam_Frhovals, |
213 |
< |
currentAtomType->eam_nrho, |
214 |
< |
MPI_DOUBLE,0,MPI_COMM_WORLD); |
215 |
< |
|
216 |
< |
sprintf( checkPointMsg, |
217 |
< |
"successfully sent EAM force type: \"%s\"\n", |
218 |
< |
info.name ); |
219 |
< |
MPIcheckPoint(); |
220 |
< |
|
221 |
< |
currentAtomType = currentAtomType->next; |
186 |
> |
st = (ShapeAtomType*)(iter->second); |
187 |
> |
parseShapeFile(shapeFileName, st); |
188 |
> |
} |
189 |
> |
} |
190 |
|
} |
223 |
– |
info.last = 1; |
224 |
– |
sendFrcStruct( &info, mpiAtomStructType ); |
225 |
– |
|
191 |
|
} |
192 |
|
|
193 |
< |
else{ |
229 |
< |
|
230 |
< |
// listen for node 0 to send out the force params |
231 |
< |
|
232 |
< |
MPIcheckPoint(); |
193 |
> |
#ifdef IS_MPI |
194 |
|
|
195 |
< |
headAtomType = new LinkedAtomType; |
196 |
< |
receiveFrcStruct( &info, mpiAtomStructType ); |
195 |
> |
// looks like all the processors have their ShapeType vectors ready... |
196 |
> |
sprintf( checkPointMsg, |
197 |
> |
"Shapes_FF shape objects read successfully." ); |
198 |
> |
MPIcheckPoint(); |
199 |
|
|
200 |
< |
while( !info.last ){ |
238 |
< |
|
239 |
< |
// allocate the arrays |
200 |
> |
#endif // is_mpi |
201 |
|
|
202 |
< |
eam_rvals = new double[info.eam_nr]; |
203 |
< |
eam_rhovals = new double[info.eam_nr]; |
243 |
< |
eam_Frhovals = new double[info.eam_nrho]; |
202 |
> |
// pack up and send the necessary info to fortran |
203 |
> |
for (iter = atomTypeMap.begin(); iter != atomTypeMap.end(); ++iter){ |
204 |
|
|
205 |
< |
// We have to now broadcast the Arrays |
246 |
< |
MPI_Bcast(eam_rvals, |
247 |
< |
info.eam_nr, |
248 |
< |
MPI_DOUBLE,0,MPI_COMM_WORLD); |
249 |
< |
MPI_Bcast(eam_rhovals, |
250 |
< |
info.eam_nr, |
251 |
< |
MPI_DOUBLE,0,MPI_COMM_WORLD); |
252 |
< |
MPI_Bcast(eam_Frhovals, |
253 |
< |
info.eam_nrho, |
254 |
< |
MPI_DOUBLE,0,MPI_COMM_WORLD); |
255 |
< |
|
205 |
> |
at = (AtomType*)(iter->second); |
206 |
|
|
207 |
< |
headAtomType->add( info, eam_rvals, eam_rhovals, eam_Frhovals ); |
258 |
< |
|
259 |
< |
MPIcheckPoint(); |
207 |
> |
if (at->isDirectional()) { |
208 |
|
|
209 |
< |
receiveFrcStruct( &info, mpiAtomStructType ); |
209 |
> |
dat = (DirectionalAtomType*)at; |
210 |
|
|
211 |
+ |
if (dat->isShape()) { |
212 |
|
|
213 |
< |
} |
214 |
< |
} |
215 |
< |
#endif // is_mpi |
213 |
> |
st = (ShapeAtomType*)at; |
214 |
> |
|
215 |
> |
contactL.clear(); |
216 |
> |
contactM.clear(); |
217 |
> |
contactFunc.clear(); |
218 |
> |
contactCoeff.clear(); |
219 |
> |
|
220 |
> |
tempSHVector = st->getContactFuncs(); |
221 |
> |
|
222 |
> |
nContact = tempSHVector.size(); |
223 |
> |
for (i=0; i<nContact; i++){ |
224 |
> |
contactL.push_back(tempSHVector[i]->getL()); |
225 |
> |
contactM.push_back(tempSHVector[i]->getM()); |
226 |
> |
contactFunc.push_back(tempSHVector[i]->getFunctionType()); |
227 |
> |
contactCoeff.push_back(tempSHVector[i]->getCoefficient()); |
228 |
> |
} |
229 |
> |
|
230 |
> |
rangeL.clear(); |
231 |
> |
rangeM.clear(); |
232 |
> |
rangeFunc.clear(); |
233 |
> |
rangeCoeff.clear(); |
234 |
> |
|
235 |
> |
tempSHVector = st->getRangeFuncs(); |
236 |
> |
|
237 |
> |
nRange = tempSHVector.size(); |
238 |
> |
for (i=0; i<nRange; i++){ |
239 |
> |
rangeL.push_back(tempSHVector[i]->getL()); |
240 |
> |
rangeM.push_back(tempSHVector[i]->getM()); |
241 |
> |
rangeFunc.push_back(tempSHVector[i]->getFunctionType()); |
242 |
> |
rangeCoeff.push_back(tempSHVector[i]->getCoefficient()); |
243 |
> |
} |
244 |
> |
|
245 |
> |
strengthL.clear(); |
246 |
> |
strengthM.clear(); |
247 |
> |
strengthFunc.clear(); |
248 |
> |
strengthCoeff.clear(); |
249 |
> |
|
250 |
> |
tempSHVector = st->getStrengthFuncs(); |
251 |
> |
|
252 |
> |
nStrength = tempSHVector.size(); |
253 |
> |
for (i=0; i<nStrength; i++){ |
254 |
> |
strengthL.push_back(tempSHVector[i]->getL()); |
255 |
> |
strengthM.push_back(tempSHVector[i]->getM()); |
256 |
> |
strengthFunc.push_back(tempSHVector[i]->getFunctionType()); |
257 |
> |
strengthCoeff.push_back(tempSHVector[i]->getCoefficient()); |
258 |
> |
} |
259 |
> |
|
260 |
> |
isError = 0; |
261 |
> |
myATID = at->getIdent(); |
262 |
|
|
263 |
< |
// call new A_types in fortran |
264 |
< |
|
265 |
< |
int isError; |
263 |
> |
makeShape( &nContact, &contactL[0], &contactM[0], &contactFunc[0], |
264 |
> |
&contactCoeff[0], |
265 |
> |
&nRange, &rangeL[0], &rangeM[0], &rangeFunc[0], |
266 |
> |
&rangeCoeff[0], |
267 |
> |
&nStrength, &strengthL[0], &strengthM[0], |
268 |
> |
&strengthFunc[0], &strengthCoeff[0], |
269 |
> |
&myATID, |
270 |
> |
&isError); |
271 |
|
|
272 |
< |
// dummy variables |
273 |
< |
int isLJ = 0; |
274 |
< |
int isDipole = 0; |
275 |
< |
int isSSD = 0; |
276 |
< |
int isGB = 0; |
277 |
< |
int isEAM = 1; |
278 |
< |
int isCharge = 0; |
279 |
< |
double dipole = 0.0; |
280 |
< |
double charge = 0.0; |
281 |
< |
double eamSigma = 0.0; |
282 |
< |
double eamEpslon = 0.0; |
283 |
< |
|
284 |
< |
currentAtomType = headAtomType->next; |
285 |
< |
while( currentAtomType != NULL ){ |
286 |
< |
|
287 |
< |
if( currentAtomType->name[0] != '\0' ){ |
288 |
< |
isError = 0; |
289 |
< |
makeAtype( &(currentAtomType->ident), |
290 |
< |
&isLJ, |
291 |
< |
&isSSD, |
292 |
< |
&isDipole, |
293 |
< |
&isGB, |
294 |
< |
&isEAM, |
295 |
< |
&isCharge, |
296 |
< |
&eamEpslon, |
297 |
< |
&eamSigma, |
298 |
< |
&charge, |
299 |
< |
&dipole, |
300 |
< |
&isError ); |
301 |
< |
if( isError ){ |
302 |
< |
sprintf( painCave.errMsg, |
303 |
< |
"Error initializing the \"%s\" atom type in fortran\n", |
304 |
< |
currentAtomType->name ); |
305 |
< |
painCave.isFatal = 1; |
306 |
< |
simError(); |
272 |
> |
if( isError ){ |
273 |
> |
sprintf( painCave.errMsg, |
274 |
> |
"Error initializing the \"%s\" shape in fortran\n", |
275 |
> |
(iter->first).c_str() ); |
276 |
> |
painCave.isFatal = 1; |
277 |
> |
simError(); |
278 |
> |
} |
279 |
|
} |
280 |
|
} |
309 |
– |
currentAtomType = currentAtomType->next; |
281 |
|
} |
282 |
< |
|
283 |
< |
entry_plug->useLJ = 0; |
284 |
< |
entry_plug->useEAM = 1; |
285 |
< |
// Walk down again and send out EAM type |
286 |
< |
currentAtomType = headAtomType->next; |
287 |
< |
while( currentAtomType != NULL ){ |
288 |
< |
|
289 |
< |
if( currentAtomType->name[0] != '\0' ){ |
319 |
< |
isError = 0; |
320 |
< |
|
321 |
< |
newEAMtype( &(currentAtomType->lattice_constant), |
322 |
< |
&(currentAtomType->eam_nrho), |
323 |
< |
&(currentAtomType->eam_drho), |
324 |
< |
&(currentAtomType->eam_nr), |
325 |
< |
&(currentAtomType->eam_dr), |
326 |
< |
&(currentAtomType->eam_rcut), |
327 |
< |
currentAtomType->eam_rvals, |
328 |
< |
currentAtomType->eam_rhovals, |
329 |
< |
currentAtomType->eam_Frhovals, |
330 |
< |
&(currentAtomType->eam_ident), |
331 |
< |
&isError); |
332 |
< |
|
333 |
< |
if( isError ){ |
334 |
< |
sprintf( painCave.errMsg, |
335 |
< |
"Error initializing the \"%s\" atom type in fortran EAM\n", |
336 |
< |
currentAtomType->name ); |
337 |
< |
painCave.isFatal = 1; |
338 |
< |
simError(); |
339 |
< |
} |
340 |
< |
} |
341 |
< |
currentAtomType = currentAtomType->next; |
282 |
> |
|
283 |
> |
isError = 0; |
284 |
> |
completeShapeFF(&isError); |
285 |
> |
if( isError ){ |
286 |
> |
sprintf( painCave.errMsg, |
287 |
> |
"Error completing Shape FF in fortran\n"); |
288 |
> |
painCave.isFatal = 1; |
289 |
> |
simError(); |
290 |
|
} |
291 |
< |
|
344 |
< |
|
345 |
< |
|
291 |
> |
|
292 |
|
#ifdef IS_MPI |
293 |
|
sprintf( checkPointMsg, |
294 |
|
"Shapes_FF atom structures successfully sent to fortran\n" ); |
295 |
|
MPIcheckPoint(); |
296 |
|
#endif // is_mpi |
297 |
|
|
298 |
+ |
} |
299 |
|
|
300 |
+ |
void Shapes_FF::cleanMe( void ){ |
301 |
|
|
302 |
|
} |
303 |
|
|
356 |
– |
|
304 |
|
void Shapes_FF::initializeAtoms( int nAtoms, Atom** the_atoms ){ |
305 |
|
|
306 |
< |
int i; |
307 |
< |
|
306 |
> |
int i,j,k; |
307 |
> |
map<string, AtomType*>::iterator iter; |
308 |
> |
|
309 |
|
// initialize the atoms |
310 |
< |
|
310 |
> |
DirectionalAtom* dAtom; |
311 |
> |
AtomType* at; |
312 |
> |
DirectionalAtomType* dat; |
313 |
> |
ShapeAtomType* sat; |
314 |
> |
double longCutoff; |
315 |
> |
double ji[3]; |
316 |
> |
double inertialMat[3][3]; |
317 |
> |
Mat3x3d momInt; |
318 |
> |
string myTypeString; |
319 |
> |
|
320 |
> |
bigContact = 0.0; |
321 |
> |
|
322 |
|
for( i=0; i<nAtoms; i++ ){ |
323 |
|
|
324 |
< |
currentAtomType = headAtomType->find( the_atoms[i]->getType() ); |
325 |
< |
if( currentAtomType == NULL ){ |
324 |
> |
myTypeString = the_atoms[i]->getType(); |
325 |
> |
iter = atomTypeMap.find(myTypeString); |
326 |
> |
|
327 |
> |
if (iter == atomTypeMap.end()) { |
328 |
|
sprintf( painCave.errMsg, |
329 |
|
"AtomType error, %s not found in force file.\n", |
330 |
|
the_atoms[i]->getType() ); |
331 |
|
painCave.isFatal = 1; |
332 |
|
simError(); |
333 |
< |
} |
373 |
< |
|
374 |
< |
the_atoms[i]->setMass( currentAtomType->mass ); |
375 |
< |
the_atoms[i]->setIdent( currentAtomType->ident ); |
333 |
> |
} else { |
334 |
|
|
335 |
< |
if (eamRcut < currentAtomType->eam_rcut) eamRcut = currentAtomType->eam_rcut; |
378 |
< |
|
379 |
< |
} |
380 |
< |
} |
335 |
> |
at = (AtomType*)(iter->second); |
336 |
|
|
337 |
< |
void Shapes_FF::initializeBonds( int nBonds, Bond** BondArray, |
338 |
< |
bond_pair* the_bonds ){ |
339 |
< |
|
340 |
< |
if( nBonds ){ |
341 |
< |
sprintf( painCave.errMsg, |
342 |
< |
"LJ_FF does not support bonds.\n" ); |
343 |
< |
painCave.isFatal = 1; |
344 |
< |
simError(); |
345 |
< |
} |
346 |
< |
} |
337 |
> |
the_atoms[i]->setMass( at->getMass() ); |
338 |
> |
the_atoms[i]->setIdent( at->getIdent() ); |
339 |
> |
|
340 |
> |
if ( at->isShape() ) { |
341 |
> |
|
342 |
> |
sat = (ShapeAtomType*)at; |
343 |
> |
longCutoff = findCutoffDistance(sat); |
344 |
> |
if (longCutoff > bigContact) bigContact = longCutoff; |
345 |
> |
cout << bigContact << " is the cutoff value\n"; |
346 |
> |
|
347 |
> |
entry_plug->useShapes = 1; |
348 |
> |
} |
349 |
|
|
350 |
< |
void Shapes_FF::initializeBends( int nBends, Bend** bendArray, |
394 |
< |
bend_set* the_bends ){ |
350 |
> |
the_atoms[i]->setHasCharge(at->isCharge()); |
351 |
|
|
352 |
< |
if( nBends ){ |
397 |
< |
sprintf( painCave.errMsg, |
398 |
< |
"LJ_FF does not support bends.\n" ); |
399 |
< |
painCave.isFatal = 1; |
400 |
< |
simError(); |
401 |
< |
} |
402 |
< |
} |
352 |
> |
if( at->isDirectional() ){ |
353 |
|
|
354 |
< |
void Shapes_FF::initializeTorsions( int nTorsions, Torsion** torsionArray, |
355 |
< |
torsion_set* the_torsions ){ |
354 |
> |
dat = (DirectionalAtomType*)at; |
355 |
> |
dAtom = (DirectionalAtom *) the_atoms[i]; |
356 |
> |
|
357 |
> |
momInt = dat->getI(); |
358 |
|
|
359 |
< |
if( nTorsions ){ |
360 |
< |
sprintf( painCave.errMsg, |
361 |
< |
"LJ_FF does not support torsions.\n" ); |
362 |
< |
painCave.isFatal = 1; |
363 |
< |
simError(); |
359 |
> |
// zero out the moments of inertia matrix |
360 |
> |
for( j=0; j<3; j++ ) |
361 |
> |
for( k=0; k<3; k++ ) |
362 |
> |
inertialMat[j][k] = momInt(j,k); |
363 |
> |
dAtom->setI( inertialMat ); |
364 |
> |
|
365 |
> |
ji[0] = 0.0; |
366 |
> |
ji[1] = 0.0; |
367 |
> |
ji[2] = 0.0; |
368 |
> |
dAtom->setJ( ji ); |
369 |
> |
|
370 |
> |
if (dat->isDipole()) { |
371 |
> |
dAtom->setHasDipole( dat->isDipole() ); |
372 |
> |
entry_plug->n_dipoles++; |
373 |
> |
} |
374 |
> |
} |
375 |
|
} |
376 |
+ |
} |
377 |
|
} |
378 |
|
|
379 |
< |
void Shapes_FF::fastForward( char* stopText, char* searchOwner ){ |
380 |
< |
|
381 |
< |
int foundText = 0; |
382 |
< |
char* the_token; |
383 |
< |
|
384 |
< |
rewind( frcFile ); |
421 |
< |
lineNum = 0; |
422 |
< |
|
423 |
< |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
424 |
< |
lineNum++; |
425 |
< |
if( eof_test == NULL ){ |
426 |
< |
sprintf( painCave.errMsg, "Error fast forwarding force file for %s: " |
427 |
< |
" file is empty.\n", |
428 |
< |
searchOwner ); |
379 |
> |
void Shapes_FF::initializeBonds( int nBonds, Bond** BondArray, |
380 |
> |
bond_pair* the_bonds ){ |
381 |
> |
|
382 |
> |
if( nBonds ){ |
383 |
> |
sprintf( painCave.errMsg, |
384 |
> |
"Shapes_FF does not support bonds.\n" ); |
385 |
|
painCave.isFatal = 1; |
386 |
|
simError(); |
387 |
|
} |
388 |
+ |
} |
389 |
+ |
|
390 |
+ |
void Shapes_FF::initializeBends( int nBends, Bend** bendArray, |
391 |
+ |
bend_set* the_bends ){ |
392 |
|
|
393 |
< |
|
394 |
< |
while( !foundText ){ |
395 |
< |
while( eof_test != NULL && readLine[0] != '#' ){ |
396 |
< |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
397 |
< |
lineNum++; |
398 |
< |
} |
439 |
< |
if( eof_test == NULL ){ |
440 |
< |
sprintf( painCave.errMsg, |
441 |
< |
"Error fast forwarding force file for %s at " |
442 |
< |
"line %d: file ended unexpectedly.\n", |
443 |
< |
searchOwner, |
444 |
< |
lineNum ); |
445 |
< |
painCave.isFatal = 1; |
446 |
< |
simError(); |
447 |
< |
} |
448 |
< |
|
449 |
< |
the_token = strtok( readLine, " ,;\t#\n" ); |
450 |
< |
foundText = !strcmp( stopText, the_token ); |
451 |
< |
|
452 |
< |
if( !foundText ){ |
453 |
< |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
454 |
< |
lineNum++; |
455 |
< |
|
456 |
< |
if( eof_test == NULL ){ |
457 |
< |
sprintf( painCave.errMsg, |
458 |
< |
"Error fast forwarding force file for %s at " |
459 |
< |
"line %d: file ended unexpectedly.\n", |
460 |
< |
searchOwner, |
461 |
< |
lineNum ); |
462 |
< |
painCave.isFatal = 1; |
463 |
< |
simError(); |
464 |
< |
} |
465 |
< |
} |
466 |
< |
} |
393 |
> |
if( nBends ){ |
394 |
> |
sprintf( painCave.errMsg, |
395 |
> |
"Shapes_FF does not support bends.\n" ); |
396 |
> |
painCave.isFatal = 1; |
397 |
> |
simError(); |
398 |
> |
} |
399 |
|
} |
400 |
|
|
401 |
< |
|
402 |
< |
|
471 |
< |
int EAM_NS::parseAtom( char *lineBuffer, int lineNum, atomStruct &info, char *eamPotFile ){ |
472 |
< |
|
473 |
< |
char* the_token; |
401 |
> |
void Shapes_FF::initializeTorsions( int nTorsions, Torsion** torsionArray, |
402 |
> |
torsion_set* the_torsions ){ |
403 |
|
|
404 |
< |
the_token = strtok( lineBuffer, " \n\t,;" ); |
405 |
< |
if( the_token != NULL ){ |
406 |
< |
|
407 |
< |
strcpy( info.name, the_token ); |
408 |
< |
|
480 |
< |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
481 |
< |
sprintf( painCave.errMsg, |
482 |
< |
"Error parseing AtomTypes: line %d\n", lineNum ); |
483 |
< |
painCave.isFatal = 1; |
484 |
< |
simError(); |
485 |
< |
} |
486 |
< |
|
487 |
< |
info.mass = atof( the_token ); |
488 |
< |
|
489 |
< |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
490 |
< |
sprintf( painCave.errMsg, |
491 |
< |
"Error parseing AtomTypes: line %d\n", lineNum ); |
492 |
< |
painCave.isFatal = 1; |
493 |
< |
simError(); |
494 |
< |
} |
495 |
< |
|
496 |
< |
strcpy( eamPotFile, the_token ); |
497 |
< |
return 1; |
404 |
> |
if( nTorsions ){ |
405 |
> |
sprintf( painCave.errMsg, |
406 |
> |
"Shapes_FF does not support torsions.\n" ); |
407 |
> |
painCave.isFatal = 1; |
408 |
> |
simError(); |
409 |
|
} |
499 |
– |
else return 0; |
410 |
|
} |
411 |
|
|
412 |
< |
int EAM_NS::parseEAM(atomStruct &info, char *eamPotFile, |
413 |
< |
double **eam_rvals, |
414 |
< |
double **eam_rhovals, |
415 |
< |
double **eam_Frhovals){ |
416 |
< |
double* myEam_rvals; |
417 |
< |
double* myEam_rhovals; |
418 |
< |
double* myEam_Frhovals; |
412 |
> |
void Shapes_FF::parseShapeFile(string shapeFileName, ShapeAtomType* st){ |
413 |
> |
const int MAXLEN = 1024; |
414 |
> |
char inLine[MAXLEN]; |
415 |
> |
char *token; |
416 |
> |
char *delim = " ,;\t\n"; |
417 |
> |
int nTokens; |
418 |
> |
Mat3x3d momInert; |
419 |
> |
RealSphericalHarmonic* rsh; |
420 |
> |
vector<RealSphericalHarmonic*> functionVector; |
421 |
> |
ifstrstream shapeFile; |
422 |
> |
string tempString; |
423 |
|
|
424 |
< |
char* ffPath_env = "FORCE_PARAM_PATH"; |
511 |
< |
char* ffPath; |
512 |
< |
char* the_token; |
513 |
< |
char* eam_eof_test; |
514 |
< |
FILE *eamFile; |
515 |
< |
const int BUFFERSIZE = 3000; |
516 |
< |
|
517 |
< |
char temp[200]; |
518 |
< |
int linenumber; |
519 |
< |
int nReadLines; |
520 |
< |
char eam_read_buffer[BUFFERSIZE]; |
521 |
< |
|
522 |
< |
|
523 |
< |
int i,j; |
524 |
< |
|
525 |
< |
linenumber = 0; |
526 |
< |
|
527 |
< |
// Open eam file |
528 |
< |
eamFile = fopen( eamPotFile, "r" ); |
424 |
> |
shapeFile.open( shapeFileName.c_str() ); |
425 |
|
|
426 |
< |
|
531 |
< |
if( eamFile == NULL ){ |
426 |
> |
if( shapeFile == NULL ){ |
427 |
|
|
428 |
< |
// next see if the force path enviorment variable is set |
428 |
> |
tempString = ffPath; |
429 |
> |
tempString += "/"; |
430 |
> |
tempString += shapeFileName; |
431 |
> |
shapeFileName = tempString; |
432 |
> |
|
433 |
> |
shapeFile.open( shapeFileName.c_str() ); |
434 |
|
|
435 |
< |
ffPath = getenv( ffPath_env ); |
536 |
< |
if( ffPath == NULL ) { |
537 |
< |
STR_DEFINE(ffPath, FRC_PATH ); |
538 |
< |
} |
539 |
< |
|
540 |
< |
|
541 |
< |
strcpy( temp, ffPath ); |
542 |
< |
strcat( temp, "/" ); |
543 |
< |
strcat( temp, eamPotFile ); |
544 |
< |
strcpy( eamPotFile, temp ); |
545 |
< |
|
546 |
< |
eamFile = fopen( eamPotFile, "r" ); |
547 |
< |
|
548 |
< |
|
549 |
< |
|
550 |
< |
if( eamFile == NULL ){ |
435 |
> |
if( shapeFile == NULL ){ |
436 |
|
|
437 |
|
sprintf( painCave.errMsg, |
438 |
< |
"Error opening the EAM force parameter file: %s\n" |
439 |
< |
"Have you tried setting the FORCE_PARAM_PATH environment " |
438 |
> |
"Error opening the shape file:\n" |
439 |
> |
"\t%s\n" |
440 |
> |
"\tHave you tried setting the FORCE_PARAM_PATH environment " |
441 |
|
"variable?\n", |
442 |
< |
eamPotFile ); |
442 |
> |
shapeFileName.c_str() ); |
443 |
> |
painCave.severity = OOPSE_ERROR; |
444 |
|
painCave.isFatal = 1; |
445 |
|
simError(); |
446 |
|
} |
447 |
|
} |
448 |
< |
|
449 |
< |
// First line is a comment line, read and toss it.... |
450 |
< |
eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile); |
451 |
< |
linenumber++; |
452 |
< |
if(eam_eof_test == NULL){ |
453 |
< |
sprintf( painCave.errMsg, |
454 |
< |
"error in reading commment in %s\n", eamPotFile); |
455 |
< |
painCave.isFatal = 1; |
456 |
< |
simError(); |
448 |
> |
|
449 |
> |
// read in the shape types. |
450 |
> |
|
451 |
> |
// first grab the values in the ShapeInfo section |
452 |
> |
findBegin( shapeFile, "ShapeInfo"); |
453 |
> |
|
454 |
> |
shapeFile.getline(inLine, MAXLEN); |
455 |
> |
while( !shapeFile.eof() ) { |
456 |
> |
// toss comment lines |
457 |
> |
if( inLine[0] != '!' && inLine[0] != '#' ){ |
458 |
> |
// end marks section completion |
459 |
> |
if (isEndLine(inLine)) break; |
460 |
> |
|
461 |
> |
nTokens = countTokens(inLine, delim); |
462 |
> |
if (nTokens != 0) { |
463 |
> |
if (nTokens < 5) { |
464 |
> |
sprintf( painCave.errMsg, |
465 |
> |
"Not enough data on a ShapeInfo line in file: %s\n", |
466 |
> |
shapeFileName.c_str() ); |
467 |
> |
painCave.severity = OOPSE_ERROR; |
468 |
> |
painCave.isFatal = 1; |
469 |
> |
simError(); |
470 |
> |
} else { |
471 |
> |
token = strtok(inLine, delim); |
472 |
> |
token = strtok(NULL, delim); |
473 |
> |
st->setMass(atof(token)); |
474 |
> |
token = strtok(NULL, delim); |
475 |
> |
momInert(0,0) = atof(token); |
476 |
> |
token = strtok(NULL, delim); |
477 |
> |
momInert(1,1) = atof(token); |
478 |
> |
token = strtok(NULL, delim); |
479 |
> |
momInert(2,2) = atof(token); |
480 |
> |
st->setI(momInert); |
481 |
> |
} |
482 |
> |
} |
483 |
> |
} |
484 |
> |
shapeFile.getline(inLine, MAXLEN); |
485 |
|
} |
486 |
|
|
487 |
< |
|
488 |
< |
|
489 |
< |
// The Second line contains atomic number, atomic mass and a lattice constant |
490 |
< |
eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile); |
491 |
< |
linenumber++; |
492 |
< |
if(eam_eof_test == NULL){ |
493 |
< |
sprintf( painCave.errMsg, |
494 |
< |
"error in reading Identifier line in %s\n", eamPotFile); |
495 |
< |
painCave.isFatal = 1; |
496 |
< |
simError(); |
487 |
> |
// now grab the contact functions |
488 |
> |
findBegin(shapeFile, "ContactFunctions"); |
489 |
> |
functionVector.clear(); |
490 |
> |
|
491 |
> |
shapeFile.getline(inLine, MAXLEN); |
492 |
> |
while( !shapeFile.eof() ) { |
493 |
> |
// toss comment lines |
494 |
> |
if( inLine[0] != '!' && inLine[0] != '#' ){ |
495 |
> |
// end marks section completion |
496 |
> |
if (isEndLine(inLine)) break; |
497 |
> |
nTokens = countTokens(inLine, delim); |
498 |
> |
if (nTokens != 0) { |
499 |
> |
if (nTokens < 4) { |
500 |
> |
sprintf( painCave.errMsg, |
501 |
> |
"Not enough data on a ContactFunctions line in file: %s\n", |
502 |
> |
shapeFileName.c_str() ); |
503 |
> |
painCave.severity = OOPSE_ERROR; |
504 |
> |
painCave.isFatal = 1; |
505 |
> |
simError(); |
506 |
> |
} else { |
507 |
> |
// read in a spherical harmonic function |
508 |
> |
token = strtok(inLine, delim); |
509 |
> |
rsh = new RealSphericalHarmonic(); |
510 |
> |
rsh->setL(atoi(token)); |
511 |
> |
token = strtok(NULL, delim); |
512 |
> |
rsh->setM(atoi(token)); |
513 |
> |
token = strtok(NULL, delim); |
514 |
> |
if (!strcasecmp("sin",token)) |
515 |
> |
rsh->makeSinFunction(); |
516 |
> |
else |
517 |
> |
rsh->makeCosFunction(); |
518 |
> |
token = strtok(NULL, delim); |
519 |
> |
rsh->setCoefficient(atof(token)); |
520 |
> |
|
521 |
> |
functionVector.push_back(rsh); |
522 |
> |
} |
523 |
> |
} |
524 |
> |
} |
525 |
> |
shapeFile.getline(inLine, MAXLEN); |
526 |
|
} |
527 |
|
|
528 |
+ |
// pass contact functions to ShapeType |
529 |
|
|
530 |
+ |
st->setContactFuncs(functionVector); |
531 |
|
|
532 |
< |
|
533 |
< |
if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ |
534 |
< |
sprintf( painCave.errMsg, |
589 |
< |
"Error parsing EAM ident line in %s\n", eamPotFile ); |
590 |
< |
painCave.isFatal = 1; |
591 |
< |
simError(); |
592 |
< |
} |
532 |
> |
// now grab the range functions |
533 |
> |
findBegin(shapeFile, "RangeFunctions"); |
534 |
> |
functionVector.clear(); |
535 |
|
|
536 |
< |
info.eam_ident = atoi( the_token ); |
537 |
< |
|
538 |
< |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
539 |
< |
sprintf( painCave.errMsg, |
540 |
< |
"Error parsing EAM mass in %s\n", eamPotFile ); |
541 |
< |
painCave.isFatal = 1; |
542 |
< |
simError(); |
543 |
< |
} |
544 |
< |
info.mass = atof( the_token); |
545 |
< |
|
546 |
< |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
547 |
< |
sprintf( painCave.errMsg, |
548 |
< |
"Error parsing EAM Lattice Constant %s\n", eamPotFile ); |
549 |
< |
painCave.isFatal = 1; |
550 |
< |
simError(); |
551 |
< |
} |
552 |
< |
info.lattice_constant = atof( the_token); |
553 |
< |
|
554 |
< |
// Next line is nrho, drho, nr, dr and rcut |
555 |
< |
eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile); |
614 |
< |
if(eam_eof_test == NULL){ |
615 |
< |
sprintf( painCave.errMsg, |
616 |
< |
"error in reading number of points line in %s\n", eamPotFile); |
617 |
< |
painCave.isFatal = 1; |
618 |
< |
simError(); |
619 |
< |
} |
536 |
> |
shapeFile.getline(inLine, MAXLEN); |
537 |
> |
while( !shapeFile.eof() ) { |
538 |
> |
// toss comment lines |
539 |
> |
if( inLine[0] != '!' && inLine[0] != '#' ){ |
540 |
> |
// end marks section completion |
541 |
> |
if (isEndLine(inLine)) break; |
542 |
> |
|
543 |
> |
nTokens = countTokens(inLine, delim); |
544 |
> |
if (nTokens != 0) { |
545 |
> |
if (nTokens < 4) { |
546 |
> |
sprintf( painCave.errMsg, |
547 |
> |
"Not enough data on a RangeFunctions line in file: %s\n", |
548 |
> |
shapeFileName.c_str() ); |
549 |
> |
painCave.severity = OOPSE_ERROR; |
550 |
> |
painCave.isFatal = 1; |
551 |
> |
simError(); |
552 |
> |
} else { |
553 |
> |
|
554 |
> |
// read in a spherical harmonic function |
555 |
> |
token = strtok(inLine, delim); |
556 |
|
|
557 |
< |
if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ |
558 |
< |
sprintf( painCave.errMsg, |
559 |
< |
"Error parseing EAM nrho: line in %s\n", eamPotFile ); |
560 |
< |
painCave.isFatal = 1; |
561 |
< |
simError(); |
557 |
> |
rsh = new RealSphericalHarmonic(); |
558 |
> |
rsh->setL(atoi(token)); |
559 |
> |
token = strtok(NULL, delim); |
560 |
> |
rsh->setM(atoi(token)); |
561 |
> |
token = strtok(NULL, delim); |
562 |
> |
if (!strcasecmp("sin",token)) |
563 |
> |
rsh->makeSinFunction(); |
564 |
> |
else |
565 |
> |
rsh->makeCosFunction(); |
566 |
> |
token = strtok(NULL, delim); |
567 |
> |
rsh->setCoefficient(atof(token)); |
568 |
> |
|
569 |
> |
functionVector.push_back(rsh); |
570 |
> |
} |
571 |
> |
} |
572 |
> |
} |
573 |
> |
shapeFile.getline(inLine, MAXLEN); |
574 |
|
} |
627 |
– |
|
628 |
– |
info.eam_nrho = atoi( the_token ); |
629 |
– |
|
630 |
– |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
631 |
– |
sprintf( painCave.errMsg, |
632 |
– |
"Error parsing EAM drho in %s\n", eamPotFile ); |
633 |
– |
painCave.isFatal = 1; |
634 |
– |
simError(); |
635 |
– |
} |
636 |
– |
info.eam_drho = atof( the_token); |
575 |
|
|
576 |
< |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
577 |
< |
sprintf( painCave.errMsg, |
640 |
< |
"Error parsing EAM # r in %s\n", eamPotFile ); |
641 |
< |
painCave.isFatal = 1; |
642 |
< |
simError(); |
643 |
< |
} |
644 |
< |
info.eam_nr = atoi( the_token); |
645 |
< |
|
646 |
< |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
647 |
< |
sprintf( painCave.errMsg, |
648 |
< |
"Error parsing EAM dr in %s\n", eamPotFile ); |
649 |
< |
painCave.isFatal = 1; |
650 |
< |
simError(); |
651 |
< |
} |
652 |
< |
info.eam_dr = atof( the_token); |
576 |
> |
// pass range functions to ShapeType |
577 |
> |
st->setRangeFuncs(functionVector); |
578 |
|
|
579 |
< |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
580 |
< |
sprintf( painCave.errMsg, |
581 |
< |
"Error parsing EAM rcut in %s\n", eamPotFile ); |
582 |
< |
painCave.isFatal = 1; |
583 |
< |
simError(); |
584 |
< |
} |
585 |
< |
info.eam_rcut = atof( the_token); |
586 |
< |
|
579 |
> |
// finally grab the strength functions |
580 |
> |
findBegin(shapeFile, "StrengthFunctions"); |
581 |
> |
functionVector.clear(); |
582 |
> |
|
583 |
> |
shapeFile.getline(inLine, MAXLEN); |
584 |
> |
while( !shapeFile.eof() ) { |
585 |
> |
// toss comment lines |
586 |
> |
if( inLine[0] != '!' && inLine[0] != '#' ){ |
587 |
> |
// end marks section completion |
588 |
> |
if (isEndLine(inLine)) break; |
589 |
> |
|
590 |
> |
nTokens = countTokens(inLine, delim); |
591 |
> |
if (nTokens != 0) { |
592 |
> |
if (nTokens < 4) { |
593 |
> |
sprintf( painCave.errMsg, |
594 |
> |
"Not enough data on a StrengthFunctions line in file: %s\n", |
595 |
> |
shapeFileName.c_str() ); |
596 |
> |
painCave.severity = OOPSE_ERROR; |
597 |
> |
painCave.isFatal = 1; |
598 |
> |
simError(); |
599 |
> |
} else { |
600 |
> |
|
601 |
> |
// read in a spherical harmonic function |
602 |
> |
token = strtok(inLine, delim); |
603 |
> |
rsh = new RealSphericalHarmonic(); |
604 |
> |
rsh->setL(atoi(token)); |
605 |
> |
token = strtok(NULL, delim); |
606 |
> |
rsh->setM(atoi(token)); |
607 |
> |
token = strtok(NULL, delim); |
608 |
> |
if (!strcasecmp("sin",token)) |
609 |
> |
rsh->makeSinFunction(); |
610 |
> |
else |
611 |
> |
rsh->makeCosFunction(); |
612 |
> |
token = strtok(NULL, delim); |
613 |
> |
rsh->setCoefficient(atof(token)); |
614 |
> |
|
615 |
> |
functionVector.push_back(rsh); |
616 |
> |
} |
617 |
> |
} |
618 |
> |
} |
619 |
> |
shapeFile.getline(inLine, MAXLEN); |
620 |
> |
} |
621 |
|
|
622 |
+ |
// pass strength functions to ShapeType |
623 |
+ |
st->setStrengthFuncs(functionVector); |
624 |
|
|
625 |
+ |
// we're done reading from this file |
626 |
+ |
shapeFile.close(); |
627 |
+ |
} |
628 |
|
|
629 |
< |
|
630 |
< |
// Ok now we have to allocate point arrays and read in number of points |
631 |
< |
// Index the arrays for fortran, starting at 1 |
632 |
< |
myEam_Frhovals = new double[info.eam_nrho]; |
633 |
< |
myEam_rvals = new double[info.eam_nr]; |
670 |
< |
myEam_rhovals = new double[info.eam_nr]; |
671 |
< |
|
672 |
< |
// Parse F of rho vals. |
673 |
< |
|
674 |
< |
// Assume for now that we have a complete number of lines |
675 |
< |
nReadLines = int(info.eam_nrho/5); |
629 |
> |
double Shapes_FF::findLargestContactDistance(ShapeAtomType* st) { |
630 |
> |
int i, j, nSteps; |
631 |
> |
double theta, thetaStep, thetaMin, costheta; |
632 |
> |
double phi, phiStep; |
633 |
> |
double sigma, bs; |
634 |
|
|
635 |
+ |
nSteps = 16; |
636 |
|
|
637 |
< |
|
638 |
< |
for (i=0;i<nReadLines;i++){ |
639 |
< |
j = i*5; |
640 |
< |
|
641 |
< |
// Read next line |
642 |
< |
eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile); |
684 |
< |
linenumber++; |
685 |
< |
if(eam_eof_test == NULL){ |
686 |
< |
sprintf( painCave.errMsg, |
687 |
< |
"error in reading EAM file %s at line %d\n", |
688 |
< |
eamPotFile,linenumber); |
689 |
< |
painCave.isFatal = 1; |
690 |
< |
simError(); |
691 |
< |
} |
637 |
> |
thetaStep = M_PI / nSteps; |
638 |
> |
thetaMin = thetaStep / 2.0; |
639 |
> |
phiStep = thetaStep * 2.0; |
640 |
> |
bs = 0.0; |
641 |
> |
|
642 |
> |
for (i = 0; i < nSteps; i++) { |
643 |
|
|
644 |
< |
// Parse 5 values on each line into array |
645 |
< |
// Value 1 |
695 |
< |
if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ |
696 |
< |
sprintf( painCave.errMsg, |
697 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
698 |
< |
painCave.isFatal = 1; |
699 |
< |
simError(); |
700 |
< |
} |
644 |
> |
theta = thetaMin + i * thetaStep; |
645 |
> |
costheta = cos(theta); |
646 |
|
|
647 |
< |
myEam_Frhovals[j+0] = atof( the_token ); |
703 |
< |
|
704 |
< |
// Value 2 |
705 |
< |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
706 |
< |
sprintf( painCave.errMsg, |
707 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
708 |
< |
painCave.isFatal = 1; |
709 |
< |
simError(); |
710 |
< |
} |
647 |
> |
for (j = 0; j < nSteps; j++) { |
648 |
|
|
649 |
< |
myEam_Frhovals[j+1] = atof( the_token ); |
713 |
< |
|
714 |
< |
// Value 3 |
715 |
< |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
716 |
< |
sprintf( painCave.errMsg, |
717 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
718 |
< |
painCave.isFatal = 1; |
719 |
< |
simError(); |
720 |
< |
} |
649 |
> |
phi = j*phiStep; |
650 |
|
|
651 |
< |
myEam_Frhovals[j+2] = atof( the_token ); |
652 |
< |
|
653 |
< |
// Value 4 |
725 |
< |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
726 |
< |
sprintf( painCave.errMsg, |
727 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
728 |
< |
painCave.isFatal = 1; |
729 |
< |
simError(); |
651 |
> |
sigma = st->getContactValueAt(costheta, phi); |
652 |
> |
|
653 |
> |
if (sigma > bs) bs = sigma; |
654 |
|
} |
731 |
– |
|
732 |
– |
myEam_Frhovals[j+3] = atof( the_token ); |
733 |
– |
|
734 |
– |
// Value 5 |
735 |
– |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
736 |
– |
sprintf( painCave.errMsg, |
737 |
– |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
738 |
– |
painCave.isFatal = 1; |
739 |
– |
simError(); |
740 |
– |
} |
741 |
– |
|
742 |
– |
myEam_Frhovals[j+4] = atof( the_token ); |
743 |
– |
|
655 |
|
} |
745 |
– |
// Parse Z of r vals |
746 |
– |
|
747 |
– |
// Assume for now that we have a complete number of lines |
748 |
– |
nReadLines = int(info.eam_nr/5); |
656 |
|
|
657 |
< |
for (i=0;i<nReadLines;i++){ |
658 |
< |
j = i*5; |
657 |
> |
return bs; |
658 |
> |
} |
659 |
|
|
753 |
– |
// Read next line |
754 |
– |
eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile); |
755 |
– |
linenumber++; |
756 |
– |
if(eam_eof_test == NULL){ |
757 |
– |
sprintf( painCave.errMsg, |
758 |
– |
"error in reading EAM file %s at line %d\n", |
759 |
– |
eamPotFile,linenumber); |
760 |
– |
painCave.isFatal = 1; |
761 |
– |
simError(); |
762 |
– |
} |
763 |
– |
|
764 |
– |
// Parse 5 values on each line into array |
765 |
– |
// Value 1 |
766 |
– |
if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ |
767 |
– |
sprintf( painCave.errMsg, |
768 |
– |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
769 |
– |
painCave.isFatal = 1; |
770 |
– |
simError(); |
771 |
– |
} |
772 |
– |
|
773 |
– |
myEam_rvals[j+0] = atof( the_token ); |
660 |
|
|
661 |
< |
// Value 2 |
662 |
< |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
663 |
< |
sprintf( painCave.errMsg, |
664 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
665 |
< |
painCave.isFatal = 1; |
666 |
< |
simError(); |
781 |
< |
} |
782 |
< |
|
783 |
< |
myEam_rvals[j+1] = atof( the_token ); |
661 |
> |
double Shapes_FF::findCutoffDistance(ShapeAtomType* st) { |
662 |
> |
int i, j, nSteps; |
663 |
> |
double theta, thetaStep, thetaMin, costheta; |
664 |
> |
double phi, phiStep; |
665 |
> |
double sigma, range; |
666 |
> |
double bigCut, tempCut; |
667 |
|
|
668 |
< |
// Value 3 |
786 |
< |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
787 |
< |
sprintf( painCave.errMsg, |
788 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
789 |
< |
painCave.isFatal = 1; |
790 |
< |
simError(); |
791 |
< |
} |
792 |
< |
|
793 |
< |
myEam_rvals[j+2] = atof( the_token ); |
668 |
> |
nSteps = 16; |
669 |
|
|
670 |
< |
// Value 4 |
671 |
< |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
672 |
< |
sprintf( painCave.errMsg, |
673 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
799 |
< |
painCave.isFatal = 1; |
800 |
< |
simError(); |
801 |
< |
} |
670 |
> |
thetaStep = M_PI / nSteps; |
671 |
> |
thetaMin = thetaStep / 2.0; |
672 |
> |
phiStep = thetaStep * 2.0; |
673 |
> |
bigCut = 0.0; |
674 |
|
|
675 |
< |
myEam_rvals[j+3] = atof( the_token ); |
675 |
> |
for (i = 0; i < nSteps; i++) { |
676 |
> |
|
677 |
> |
theta = thetaMin + i * thetaStep; |
678 |
> |
costheta = cos(theta); |
679 |
|
|
680 |
< |
// Value 5 |
806 |
< |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
807 |
< |
sprintf( painCave.errMsg, |
808 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
809 |
< |
painCave.isFatal = 1; |
810 |
< |
simError(); |
811 |
< |
} |
812 |
< |
|
813 |
< |
myEam_rvals[j+4] = atof( the_token ); |
680 |
> |
for (j = 0; j < nSteps; j++) { |
681 |
|
|
682 |
< |
} |
816 |
< |
// Parse rho of r vals |
682 |
> |
phi = j*phiStep; |
683 |
|
|
684 |
< |
// Assume for now that we have a complete number of lines |
684 |
> |
sigma = st->getContactValueAt(costheta, phi); |
685 |
> |
range = st->getRangeValueAt(costheta, phi); |
686 |
|
|
687 |
< |
for (i=0;i<nReadLines;i++){ |
688 |
< |
j = i*5; |
687 |
> |
// cutoff for a shape is taken to be (2.5*rangeVal + contactVal) |
688 |
> |
tempCut = 2.5*range + sigma; |
689 |
|
|
690 |
< |
// Read next line |
824 |
< |
eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile); |
825 |
< |
linenumber++; |
826 |
< |
if(eam_eof_test == NULL){ |
827 |
< |
sprintf( painCave.errMsg, |
828 |
< |
"error in reading EAM file %s at line %d\n", |
829 |
< |
eamPotFile,linenumber); |
830 |
< |
painCave.isFatal = 1; |
831 |
< |
simError(); |
690 |
> |
if (tempCut > bigCut) bigCut = tempCut; |
691 |
|
} |
833 |
– |
|
834 |
– |
// Parse 5 values on each line into array |
835 |
– |
// Value 1 |
836 |
– |
if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ |
837 |
– |
sprintf( painCave.errMsg, |
838 |
– |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
839 |
– |
painCave.isFatal = 1; |
840 |
– |
simError(); |
841 |
– |
} |
842 |
– |
|
843 |
– |
myEam_rhovals[j+0] = atof( the_token ); |
844 |
– |
|
845 |
– |
// Value 2 |
846 |
– |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
847 |
– |
sprintf( painCave.errMsg, |
848 |
– |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
849 |
– |
painCave.isFatal = 1; |
850 |
– |
simError(); |
851 |
– |
} |
852 |
– |
|
853 |
– |
myEam_rhovals[j+1] = atof( the_token ); |
854 |
– |
|
855 |
– |
// Value 3 |
856 |
– |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
857 |
– |
sprintf( painCave.errMsg, |
858 |
– |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
859 |
– |
painCave.isFatal = 1; |
860 |
– |
simError(); |
861 |
– |
} |
862 |
– |
|
863 |
– |
myEam_rhovals[j+2] = atof( the_token ); |
864 |
– |
|
865 |
– |
// Value 4 |
866 |
– |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
867 |
– |
sprintf( painCave.errMsg, |
868 |
– |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
869 |
– |
painCave.isFatal = 1; |
870 |
– |
simError(); |
871 |
– |
} |
872 |
– |
|
873 |
– |
myEam_rhovals[j+3] = atof( the_token ); |
874 |
– |
|
875 |
– |
// Value 5 |
876 |
– |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
877 |
– |
sprintf( painCave.errMsg, |
878 |
– |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
879 |
– |
painCave.isFatal = 1; |
880 |
– |
simError(); |
881 |
– |
} |
882 |
– |
|
883 |
– |
myEam_rhovals[j+4] = atof( the_token ); |
884 |
– |
|
692 |
|
} |
693 |
< |
*eam_rvals = myEam_rvals; |
694 |
< |
*eam_rhovals = myEam_rhovals; |
888 |
< |
*eam_Frhovals = myEam_Frhovals; |
889 |
< |
|
890 |
< |
fclose(eamFile); |
891 |
< |
return 0; |
693 |
> |
|
694 |
> |
return bigCut; |
695 |
|
} |