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 |
|
} |
61 |
|
} |
62 |
|
|
63 |
|
|
64 |
< |
void Shapes_FF::initForceField(int ljMixRule){ |
65 |
< |
initFortran(ljMixRule, 0); |
64 |
> |
void Shapes_FF::initForceField(){ |
65 |
> |
initFortran(0); |
66 |
|
} |
67 |
|
|
68 |
|
|
69 |
|
void Shapes_FF::readParams( void ){ |
70 |
|
|
71 |
< |
char shapePotFile[1000]; |
139 |
< |
|
140 |
< |
#ifdef IS_MPI |
141 |
< |
if( worldRank == 0 ){ |
142 |
< |
#endif |
143 |
< |
|
144 |
< |
// read in the atom types. |
71 |
> |
char readLine[1024]; |
72 |
|
|
73 |
< |
fastForward( "AtomTypes", "eam atom readParams" ); |
73 |
> |
string fileName; |
74 |
> |
string shapeFileName; |
75 |
> |
string tempString; |
76 |
|
|
77 |
< |
// we are now at the AtomTypes section. |
77 |
> |
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 |
> |
int isError; |
85 |
> |
string nameString; |
86 |
> |
AtomType* at; |
87 |
> |
DirectionalAtomType* dat; |
88 |
> |
ShapeAtomType* st; |
89 |
> |
|
90 |
> |
map<string, AtomType*>::iterator iter; |
91 |
> |
|
92 |
> |
// vectors for shape transfer to fortran |
93 |
> |
vector<RealSphericalHarmonic*> tempSHVector; |
94 |
> |
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 |
> |
fileName = "Shapes.frc"; |
109 |
> |
|
110 |
> |
// attempt to open the file in the current directory first. |
111 |
> |
forceFile.open( fileName.c_str() ); |
112 |
> |
|
113 |
> |
if( forceFile == NULL ){ |
114 |
|
|
115 |
< |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
116 |
< |
lineNum++; |
115 |
> |
tempString = ffPath; |
116 |
> |
tempString += "/"; |
117 |
> |
tempString += fileName; |
118 |
> |
fileName = tempString; |
119 |
|
|
120 |
+ |
forceFile.open( fileName.c_str() ); |
121 |
|
|
122 |
< |
// read a line, and start parseing out the atom types |
123 |
< |
|
124 |
< |
if( eof_test == NULL ){ |
125 |
< |
sprintf( painCave.errMsg, |
126 |
< |
"Error in reading Atoms from force file at line %d.\n", |
127 |
< |
lineNum ); |
122 |
> |
if( forceFile == NULL ){ |
123 |
> |
|
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 |
> |
fileName.c_str() ); |
130 |
> |
painCave.severity = OOPSE_ERROR; |
131 |
|
painCave.isFatal = 1; |
132 |
|
simError(); |
133 |
|
} |
134 |
< |
|
135 |
< |
identNum = 1; |
136 |
< |
// stop reading at end of file, or at next section |
134 |
> |
} |
135 |
> |
|
136 |
> |
// read in the shape types. |
137 |
> |
|
138 |
> |
findBegin( forceFile, "ShapeTypes" ); |
139 |
> |
|
140 |
> |
while( !forceFile.eof() ){ |
141 |
> |
forceFile.getline( readLine, sizeof(readLine) ); |
142 |
|
|
143 |
< |
while( readLine[0] != '#' && eof_test != NULL ){ |
144 |
< |
|
145 |
< |
// toss comment lines |
146 |
< |
if( readLine[0] != '!' ){ |
147 |
< |
|
148 |
< |
// the parser returns 0 if the line was blank |
149 |
< |
if( parseAtom( readLine, lineNum, info, eamPotFile ) ){ |
150 |
< |
parseEAM(info,eamPotFile, &eam_rvals, |
151 |
< |
&eam_rhovals, &eam_Frhovals); |
152 |
< |
info.ident = identNum; |
153 |
< |
headAtomType->add( info, eam_rvals, |
154 |
< |
eam_rhovals,eam_Frhovals ); |
155 |
< |
identNum++; |
143 |
> |
// toss comment lines |
144 |
> |
if( readLine[0] != '!' && readLine[0] != '#' ){ |
145 |
> |
|
146 |
> |
if (isEndLine(readLine)) break; |
147 |
> |
|
148 |
> |
nTokens = countTokens(readLine, " ,;\t"); |
149 |
> |
if (nTokens != 0) { |
150 |
> |
if (nTokens < 2) { |
151 |
> |
sprintf( painCave.errMsg, |
152 |
> |
"Not enough data on a ShapeTypes line in file: %s\n", |
153 |
> |
fileName.c_str() ); |
154 |
> |
painCave.severity = OOPSE_ERROR; |
155 |
> |
painCave.isFatal = 1; |
156 |
> |
simError(); |
157 |
|
} |
158 |
< |
} |
159 |
< |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
160 |
< |
lineNum++; |
184 |
< |
} |
185 |
< |
|
186 |
< |
|
158 |
> |
|
159 |
> |
nameToken = strtok( readLine, delim ); |
160 |
> |
shapeFileName = strtok( NULL, delim ); |
161 |
|
|
162 |
< |
#ifdef IS_MPI |
163 |
< |
|
190 |
< |
|
191 |
< |
// send out the linked list to all the other processes |
162 |
> |
// strings are not char arrays! |
163 |
> |
nameString = nameToken; |
164 |
|
|
165 |
< |
sprintf( checkPointMsg, |
166 |
< |
"Shapes_FF atom structures read successfully." ); |
167 |
< |
MPIcheckPoint(); |
165 |
> |
// 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 |
> |
st = new ShapeAtomType(); |
171 |
|
|
172 |
< |
currentAtomType = headAtomType->next; //skip the first element who is a place holder. |
173 |
< |
while( currentAtomType != NULL ){ |
174 |
< |
currentAtomType->duplicate( info ); |
172 |
> |
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 |
|
|
184 |
< |
|
185 |
< |
|
186 |
< |
sendFrcStruct( &info, mpiAtomStructType ); |
187 |
< |
|
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; |
184 |
> |
st = (ShapeAtomType*)(iter->second); |
185 |
> |
parseShapeFile(shapeFileName, st); |
186 |
> |
} |
187 |
> |
} |
188 |
|
} |
223 |
– |
info.last = 1; |
224 |
– |
sendFrcStruct( &info, mpiAtomStructType ); |
225 |
– |
|
189 |
|
} |
190 |
|
|
191 |
< |
else{ |
229 |
< |
|
230 |
< |
// listen for node 0 to send out the force params |
231 |
< |
|
232 |
< |
MPIcheckPoint(); |
191 |
> |
#ifdef IS_MPI |
192 |
|
|
193 |
< |
headAtomType = new LinkedAtomType; |
194 |
< |
receiveFrcStruct( &info, mpiAtomStructType ); |
193 |
> |
// looks like all the processors have their ShapeType vectors ready... |
194 |
> |
sprintf( checkPointMsg, |
195 |
> |
"Shapes_FF shape objects read successfully." ); |
196 |
> |
MPIcheckPoint(); |
197 |
|
|
198 |
< |
while( !info.last ){ |
238 |
< |
|
239 |
< |
// allocate the arrays |
198 |
> |
#endif // is_mpi |
199 |
|
|
200 |
< |
eam_rvals = new double[info.eam_nr]; |
201 |
< |
eam_rhovals = new double[info.eam_nr]; |
243 |
< |
eam_Frhovals = new double[info.eam_nrho]; |
200 |
> |
// pack up and send the necessary info to fortran |
201 |
> |
for (iter = atomTypeMap.begin(); iter != atomTypeMap.end(); ++iter){ |
202 |
|
|
203 |
< |
// 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 |
< |
|
203 |
> |
at = (AtomType*)(iter->second); |
204 |
|
|
205 |
< |
headAtomType->add( info, eam_rvals, eam_rhovals, eam_Frhovals ); |
258 |
< |
|
259 |
< |
MPIcheckPoint(); |
205 |
> |
if (at->isDirectional()) { |
206 |
|
|
207 |
< |
receiveFrcStruct( &info, mpiAtomStructType ); |
207 |
> |
dat = (DirectionalAtomType*)at; |
208 |
|
|
209 |
+ |
if (dat->isShape()) { |
210 |
|
|
211 |
< |
} |
212 |
< |
} |
213 |
< |
#endif // is_mpi |
214 |
< |
|
215 |
< |
// call new A_types in fortran |
216 |
< |
|
217 |
< |
int isError; |
218 |
< |
|
219 |
< |
// dummy variables |
220 |
< |
int isLJ = 0; |
221 |
< |
int isDipole = 0; |
222 |
< |
int isSSD = 0; |
223 |
< |
int isGB = 0; |
224 |
< |
int isEAM = 1; |
225 |
< |
int isCharge = 0; |
226 |
< |
double dipole = 0.0; |
227 |
< |
double charge = 0.0; |
228 |
< |
double eamSigma = 0.0; |
229 |
< |
double eamEpslon = 0.0; |
230 |
< |
|
231 |
< |
currentAtomType = headAtomType->next; |
232 |
< |
while( currentAtomType != NULL ){ |
233 |
< |
|
234 |
< |
if( currentAtomType->name[0] != '\0' ){ |
235 |
< |
isError = 0; |
236 |
< |
makeAtype( &(currentAtomType->ident), |
237 |
< |
&isLJ, |
238 |
< |
&isSSD, |
239 |
< |
&isDipole, |
240 |
< |
&isGB, |
241 |
< |
&isEAM, |
242 |
< |
&isCharge, |
243 |
< |
&eamEpslon, |
244 |
< |
&eamSigma, |
245 |
< |
&charge, |
246 |
< |
&dipole, |
247 |
< |
&isError ); |
248 |
< |
if( isError ){ |
249 |
< |
sprintf( painCave.errMsg, |
250 |
< |
"Error initializing the \"%s\" atom type in fortran\n", |
251 |
< |
currentAtomType->name ); |
252 |
< |
painCave.isFatal = 1; |
253 |
< |
simError(); |
211 |
> |
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 |
> |
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 |
> |
} |
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 |
> |
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 |
> |
} |
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 |
> |
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 |
> |
} |
257 |
> |
|
258 |
> |
isError = 0; |
259 |
> |
myATID = at->getIdent(); |
260 |
> |
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 |
> |
&myATID, |
267 |
> |
&isError); |
268 |
> |
if( isError ){ |
269 |
> |
sprintf( painCave.errMsg, |
270 |
> |
"Error initializing the \"%s\" shape in fortran\n", |
271 |
> |
(iter->first).c_str() ); |
272 |
> |
painCave.isFatal = 1; |
273 |
> |
simError(); |
274 |
> |
} |
275 |
|
} |
276 |
|
} |
309 |
– |
currentAtomType = currentAtomType->next; |
277 |
|
} |
278 |
< |
|
312 |
< |
entry_plug->useLJ = 0; |
313 |
< |
entry_plug->useEAM = 1; |
314 |
< |
// Walk down again and send out EAM type |
315 |
< |
currentAtomType = headAtomType->next; |
316 |
< |
while( currentAtomType != NULL ){ |
317 |
< |
|
318 |
< |
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; |
342 |
< |
} |
343 |
< |
|
344 |
< |
|
345 |
< |
|
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 |
+ |
void Shapes_FF::cleanMe( void ){ |
288 |
|
|
289 |
|
} |
290 |
|
|
356 |
– |
|
291 |
|
void Shapes_FF::initializeAtoms( int nAtoms, Atom** the_atoms ){ |
292 |
|
|
293 |
< |
int i; |
294 |
< |
|
293 |
> |
int i,j,k; |
294 |
> |
map<string, AtomType*>::iterator iter; |
295 |
> |
|
296 |
|
// initialize the atoms |
297 |
< |
|
297 |
> |
DirectionalAtom* dAtom; |
298 |
> |
AtomType* at; |
299 |
> |
DirectionalAtomType* dat; |
300 |
> |
ShapeAtomType* sat; |
301 |
> |
double sigma; |
302 |
> |
double ji[3]; |
303 |
> |
double inertialMat[3][3]; |
304 |
> |
Mat3x3d momInt; |
305 |
> |
string myTypeString; |
306 |
> |
|
307 |
|
for( i=0; i<nAtoms; i++ ){ |
308 |
|
|
309 |
< |
currentAtomType = headAtomType->find( the_atoms[i]->getType() ); |
310 |
< |
if( currentAtomType == NULL ){ |
309 |
> |
myTypeString = the_atoms[i]->getType().c_str(); |
310 |
> |
iter = atomTypeMap.find(myTypeString); |
311 |
> |
|
312 |
> |
if (iter == atomTypeMap.end()) { |
313 |
|
sprintf( painCave.errMsg, |
314 |
|
"AtomType error, %s not found in force file.\n", |
315 |
< |
the_atoms[i]->getType() ); |
315 |
> |
the_atoms[i]->getType().c_str() ); |
316 |
|
painCave.isFatal = 1; |
317 |
|
simError(); |
318 |
< |
} |
373 |
< |
|
374 |
< |
the_atoms[i]->setMass( currentAtomType->mass ); |
375 |
< |
the_atoms[i]->setIdent( currentAtomType->ident ); |
318 |
> |
} else { |
319 |
|
|
320 |
< |
if (eamRcut < currentAtomType->eam_rcut) eamRcut = currentAtomType->eam_rcut; |
378 |
< |
|
379 |
< |
} |
380 |
< |
} |
320 |
> |
at = (AtomType*)(iter->second); |
321 |
|
|
322 |
< |
void Shapes_FF::initializeBonds( int nBonds, Bond** BondArray, |
323 |
< |
bond_pair* the_bonds ){ |
324 |
< |
|
325 |
< |
if( nBonds ){ |
326 |
< |
sprintf( painCave.errMsg, |
327 |
< |
"LJ_FF does not support bonds.\n" ); |
328 |
< |
painCave.isFatal = 1; |
329 |
< |
simError(); |
390 |
< |
} |
391 |
< |
} |
322 |
> |
the_atoms[i]->setMass( at->getMass() ); |
323 |
> |
the_atoms[i]->setIdent( at->getIdent() ); |
324 |
> |
|
325 |
> |
if ( at->isShape() ) { |
326 |
> |
|
327 |
> |
sat = (ShapeAtomType*)at; |
328 |
> |
sigma = findLargestContactDistance(sat); |
329 |
> |
if (sigma > bigSigma) bigSigma = sigma; |
330 |
|
|
331 |
< |
void Shapes_FF::initializeBends( int nBends, Bend** bendArray, |
394 |
< |
bend_set* the_bends ){ |
331 |
> |
} |
332 |
|
|
333 |
< |
if( nBends ){ |
397 |
< |
sprintf( painCave.errMsg, |
398 |
< |
"LJ_FF does not support bends.\n" ); |
399 |
< |
painCave.isFatal = 1; |
400 |
< |
simError(); |
401 |
< |
} |
402 |
< |
} |
333 |
> |
the_atoms[i]->setHasCharge(at->isCharge()); |
334 |
|
|
335 |
< |
void Shapes_FF::initializeTorsions( int nTorsions, Torsion** torsionArray, |
405 |
< |
torsion_set* the_torsions ){ |
335 |
> |
if( at->isDirectional() ){ |
336 |
|
|
337 |
< |
if( nTorsions ){ |
338 |
< |
sprintf( painCave.errMsg, |
339 |
< |
"LJ_FF does not support torsions.\n" ); |
340 |
< |
painCave.isFatal = 1; |
411 |
< |
simError(); |
412 |
< |
} |
413 |
< |
} |
337 |
> |
dat = (DirectionalAtomType*)at; |
338 |
> |
dAtom = (DirectionalAtom *) the_atoms[i]; |
339 |
> |
|
340 |
> |
momInt = dat->getI(); |
341 |
|
|
342 |
< |
void Shapes_FF::fastForward( char* stopText, char* searchOwner ){ |
342 |
> |
// 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 |
|
|
348 |
< |
int foundText = 0; |
349 |
< |
char* the_token; |
348 |
> |
ji[0] = 0.0; |
349 |
> |
ji[1] = 0.0; |
350 |
> |
ji[2] = 0.0; |
351 |
> |
dAtom->setJ( ji ); |
352 |
|
|
353 |
< |
rewind( frcFile ); |
354 |
< |
lineNum = 0; |
353 |
> |
if (dat->isDipole()) { |
354 |
> |
dAtom->setHasDipole( dat->isDipole() ); |
355 |
> |
entry_plug->n_dipoles++; |
356 |
> |
} |
357 |
> |
} |
358 |
> |
} |
359 |
> |
} |
360 |
> |
} |
361 |
|
|
362 |
< |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
363 |
< |
lineNum++; |
364 |
< |
if( eof_test == NULL ){ |
365 |
< |
sprintf( painCave.errMsg, "Error fast forwarding force file for %s: " |
366 |
< |
" file is empty.\n", |
367 |
< |
searchOwner ); |
362 |
> |
void Shapes_FF::initializeBonds( int nBonds, Bond** BondArray, |
363 |
> |
bond_pair* the_bonds ){ |
364 |
> |
|
365 |
> |
if( nBonds ){ |
366 |
> |
sprintf( painCave.errMsg, |
367 |
> |
"Shapes_FF does not support bonds.\n" ); |
368 |
|
painCave.isFatal = 1; |
369 |
|
simError(); |
370 |
|
} |
432 |
– |
|
433 |
– |
|
434 |
– |
while( !foundText ){ |
435 |
– |
while( eof_test != NULL && readLine[0] != '#' ){ |
436 |
– |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
437 |
– |
lineNum++; |
438 |
– |
} |
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 |
– |
} |
371 |
|
} |
372 |
|
|
373 |
< |
|
374 |
< |
|
471 |
< |
int EAM_NS::parseAtom( char *lineBuffer, int lineNum, atomStruct &info, char *eamPotFile ){ |
472 |
< |
|
473 |
< |
char* the_token; |
373 |
> |
void Shapes_FF::initializeBends( int nBends, Bend** bendArray, |
374 |
> |
bend_set* the_bends ){ |
375 |
|
|
376 |
< |
the_token = strtok( lineBuffer, " \n\t,;" ); |
377 |
< |
if( the_token != NULL ){ |
378 |
< |
|
379 |
< |
strcpy( info.name, the_token ); |
380 |
< |
|
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; |
376 |
> |
if( nBends ){ |
377 |
> |
sprintf( painCave.errMsg, |
378 |
> |
"Shapes_FF does not support bends.\n" ); |
379 |
> |
painCave.isFatal = 1; |
380 |
> |
simError(); |
381 |
|
} |
499 |
– |
else return 0; |
382 |
|
} |
383 |
|
|
384 |
< |
int EAM_NS::parseEAM(atomStruct &info, char *eamPotFile, |
385 |
< |
double **eam_rvals, |
386 |
< |
double **eam_rhovals, |
387 |
< |
double **eam_Frhovals){ |
388 |
< |
double* myEam_rvals; |
389 |
< |
double* myEam_rhovals; |
390 |
< |
double* myEam_Frhovals; |
384 |
> |
void Shapes_FF::initializeTorsions( int nTorsions, Torsion** torsionArray, |
385 |
> |
torsion_set* the_torsions ){ |
386 |
> |
|
387 |
> |
if( nTorsions ){ |
388 |
> |
sprintf( painCave.errMsg, |
389 |
> |
"Shapes_FF does not support torsions.\n" ); |
390 |
> |
painCave.isFatal = 1; |
391 |
> |
simError(); |
392 |
> |
} |
393 |
> |
} |
394 |
|
|
395 |
< |
char* ffPath_env = "FORCE_PARAM_PATH"; |
396 |
< |
char* ffPath; |
397 |
< |
char* the_token; |
398 |
< |
char* eam_eof_test; |
399 |
< |
FILE *eamFile; |
400 |
< |
const int BUFFERSIZE = 3000; |
395 |
> |
void Shapes_FF::parseShapeFile(string shapeFileName, ShapeAtomType* st){ |
396 |
> |
const int MAXLEN = 1024; |
397 |
> |
char inLine[MAXLEN]; |
398 |
> |
char *token; |
399 |
> |
char *delim = " ,;\t\n"; |
400 |
> |
int nTokens; |
401 |
> |
Mat3x3d momInert; |
402 |
> |
RealSphericalHarmonic* rsh; |
403 |
> |
vector<RealSphericalHarmonic*> functionVector; |
404 |
> |
ifstrstream shapeFile; |
405 |
> |
string tempString; |
406 |
|
|
407 |
< |
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" ); |
407 |
> |
shapeFile.open( shapeFileName.c_str() ); |
408 |
|
|
409 |
< |
|
531 |
< |
if( eamFile == NULL ){ |
409 |
> |
if( shapeFile == NULL ){ |
410 |
|
|
411 |
< |
// next see if the force path enviorment variable is set |
411 |
> |
tempString = ffPath; |
412 |
> |
tempString += "/"; |
413 |
> |
tempString += shapeFileName; |
414 |
> |
shapeFileName = tempString; |
415 |
> |
|
416 |
> |
shapeFile.open( shapeFileName.c_str() ); |
417 |
|
|
418 |
< |
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 ){ |
418 |
> |
if( shapeFile == NULL ){ |
419 |
|
|
420 |
|
sprintf( painCave.errMsg, |
421 |
< |
"Error opening the EAM force parameter file: %s\n" |
422 |
< |
"Have you tried setting the FORCE_PARAM_PATH environment " |
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 |
< |
eamPotFile ); |
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 |
+ |
// first grab the values in the ShapeInfo section |
435 |
+ |
findBegin( shapeFile, "ShapeInfo"); |
436 |
+ |
|
437 |
+ |
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 |
+ |
nTokens = countTokens(inLine, delim); |
445 |
+ |
if (nTokens != 0) { |
446 |
+ |
if (nTokens < 5) { |
447 |
+ |
sprintf( painCave.errMsg, |
448 |
+ |
"Not enough data on a ShapeInfo line in file: %s\n", |
449 |
+ |
shapeFileName.c_str() ); |
450 |
+ |
painCave.severity = OOPSE_ERROR; |
451 |
+ |
painCave.isFatal = 1; |
452 |
+ |
simError(); |
453 |
|
|
454 |
< |
// First line is a comment line, read and toss it.... |
455 |
< |
eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile); |
456 |
< |
linenumber++; |
457 |
< |
if(eam_eof_test == NULL){ |
458 |
< |
sprintf( painCave.errMsg, |
459 |
< |
"error in reading commment in %s\n", eamPotFile); |
460 |
< |
painCave.isFatal = 1; |
461 |
< |
simError(); |
454 |
> |
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 |
> |
} |
467 |
> |
shapeFile.getline(inLine, MAXLEN); |
468 |
|
} |
469 |
|
|
470 |
< |
|
471 |
< |
|
472 |
< |
// The Second line contains atomic number, atomic mass and a lattice constant |
575 |
< |
eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile); |
576 |
< |
linenumber++; |
577 |
< |
if(eam_eof_test == NULL){ |
578 |
< |
sprintf( painCave.errMsg, |
579 |
< |
"error in reading Identifier line in %s\n", eamPotFile); |
580 |
< |
painCave.isFatal = 1; |
581 |
< |
simError(); |
582 |
< |
} |
583 |
< |
|
584 |
< |
|
585 |
< |
|
586 |
< |
|
587 |
< |
if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ |
588 |
< |
sprintf( painCave.errMsg, |
589 |
< |
"Error parsing EAM ident line in %s\n", eamPotFile ); |
590 |
< |
painCave.isFatal = 1; |
591 |
< |
simError(); |
592 |
< |
} |
470 |
> |
// now grab the contact functions |
471 |
> |
findBegin(shapeFile, "ContactFunctions"); |
472 |
> |
functionVector.clear(); |
473 |
|
|
474 |
< |
info.eam_ident = atoi( the_token ); |
475 |
< |
|
476 |
< |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
477 |
< |
sprintf( painCave.errMsg, |
478 |
< |
"Error parsing EAM mass in %s\n", eamPotFile ); |
479 |
< |
painCave.isFatal = 1; |
480 |
< |
simError(); |
474 |
> |
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 |
> |
nTokens = countTokens(inLine, delim); |
482 |
> |
if (nTokens != 0) { |
483 |
> |
if (nTokens < 4) { |
484 |
> |
sprintf( painCave.errMsg, |
485 |
> |
"Not enough data on a ContactFunctions line in file: %s\n", |
486 |
> |
shapeFileName.c_str() ); |
487 |
> |
painCave.severity = OOPSE_ERROR; |
488 |
> |
painCave.isFatal = 1; |
489 |
> |
simError(); |
490 |
> |
|
491 |
> |
// read in a spherical harmonic function |
492 |
> |
token = strtok(inLine, delim); |
493 |
> |
rsh = new RealSphericalHarmonic(); |
494 |
> |
rsh->setL(atoi(token)); |
495 |
> |
token = strtok(NULL, delim); |
496 |
> |
rsh->setM(atoi(token)); |
497 |
> |
token = strtok(NULL, delim); |
498 |
> |
if (!strcasecmp("sin",token)) |
499 |
> |
rsh->makeSinFunction(); |
500 |
> |
else |
501 |
> |
rsh->makeCosFunction(); |
502 |
> |
token = strtok(NULL, delim); |
503 |
> |
rsh->setCoefficient(atof(token)); |
504 |
> |
|
505 |
> |
functionVector.push_back(rsh); |
506 |
> |
} |
507 |
> |
} |
508 |
> |
} |
509 |
> |
shapeFile.getline(inLine, MAXLEN); |
510 |
|
} |
602 |
– |
info.mass = atof( the_token); |
603 |
– |
|
604 |
– |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
605 |
– |
sprintf( painCave.errMsg, |
606 |
– |
"Error parsing EAM Lattice Constant %s\n", eamPotFile ); |
607 |
– |
painCave.isFatal = 1; |
608 |
– |
simError(); |
609 |
– |
} |
610 |
– |
info.lattice_constant = atof( the_token); |
611 |
– |
|
612 |
– |
// Next line is nrho, drho, nr, dr and rcut |
613 |
– |
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 |
– |
} |
511 |
|
|
512 |
< |
if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ |
513 |
< |
sprintf( painCave.errMsg, |
623 |
< |
"Error parseing EAM nrho: line in %s\n", eamPotFile ); |
624 |
< |
painCave.isFatal = 1; |
625 |
< |
simError(); |
626 |
< |
} |
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); |
512 |
> |
// pass contact functions to ShapeType |
513 |
> |
st->setContactFuncs(functionVector); |
514 |
|
|
515 |
< |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
516 |
< |
sprintf( painCave.errMsg, |
517 |
< |
"Error parsing EAM # r in %s\n", eamPotFile ); |
641 |
< |
painCave.isFatal = 1; |
642 |
< |
simError(); |
643 |
< |
} |
644 |
< |
info.eam_nr = atoi( the_token); |
515 |
> |
// now grab the range functions |
516 |
> |
findBegin(shapeFile, "RangeFunctions"); |
517 |
> |
functionVector.clear(); |
518 |
|
|
519 |
< |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
520 |
< |
sprintf( painCave.errMsg, |
521 |
< |
"Error parsing EAM dr in %s\n", eamPotFile ); |
522 |
< |
painCave.isFatal = 1; |
523 |
< |
simError(); |
524 |
< |
} |
525 |
< |
info.eam_dr = atof( the_token); |
519 |
> |
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 |
> |
nTokens = countTokens(inLine, delim); |
527 |
> |
if (nTokens != 0) { |
528 |
> |
if (nTokens < 4) { |
529 |
> |
sprintf( painCave.errMsg, |
530 |
> |
"Not enough data on a RangeFunctions line in file: %s\n", |
531 |
> |
shapeFileName.c_str() ); |
532 |
> |
painCave.severity = OOPSE_ERROR; |
533 |
> |
painCave.isFatal = 1; |
534 |
> |
simError(); |
535 |
> |
|
536 |
> |
// read in a spherical harmonic function |
537 |
> |
token = strtok(inLine, delim); |
538 |
|
|
539 |
< |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
540 |
< |
sprintf( painCave.errMsg, |
541 |
< |
"Error parsing EAM rcut in %s\n", eamPotFile ); |
542 |
< |
painCave.isFatal = 1; |
543 |
< |
simError(); |
544 |
< |
} |
545 |
< |
info.eam_rcut = atof( the_token); |
546 |
< |
|
547 |
< |
|
548 |
< |
|
549 |
< |
|
550 |
< |
|
551 |
< |
// Ok now we have to allocate point arrays and read in number of points |
552 |
< |
// Index the arrays for fortran, starting at 1 |
553 |
< |
myEam_Frhovals = new double[info.eam_nrho]; |
669 |
< |
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); |
676 |
< |
|
677 |
< |
|
678 |
< |
|
679 |
< |
for (i=0;i<nReadLines;i++){ |
680 |
< |
j = i*5; |
681 |
< |
|
682 |
< |
// Read next line |
683 |
< |
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(); |
539 |
> |
rsh = new RealSphericalHarmonic(); |
540 |
> |
rsh->setL(atoi(token)); |
541 |
> |
token = strtok(NULL, delim); |
542 |
> |
rsh->setM(atoi(token)); |
543 |
> |
token = strtok(NULL, delim); |
544 |
> |
if (!strcasecmp("sin",token)) |
545 |
> |
rsh->makeSinFunction(); |
546 |
> |
else |
547 |
> |
rsh->makeCosFunction(); |
548 |
> |
token = strtok(NULL, delim); |
549 |
> |
rsh->setCoefficient(atof(token)); |
550 |
> |
|
551 |
> |
functionVector.push_back(rsh); |
552 |
> |
} |
553 |
> |
} |
554 |
|
} |
555 |
< |
|
693 |
< |
// Parse 5 values on each line into array |
694 |
< |
// 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 |
< |
} |
701 |
< |
|
702 |
< |
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 |
< |
} |
711 |
< |
|
712 |
< |
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 |
< |
} |
721 |
< |
|
722 |
< |
myEam_Frhovals[j+2] = atof( the_token ); |
723 |
< |
|
724 |
< |
// 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(); |
730 |
< |
} |
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 |
< |
|
555 |
> |
shapeFile.getline(inLine, MAXLEN); |
556 |
|
} |
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); |
557 |
|
|
558 |
< |
for (i=0;i<nReadLines;i++){ |
559 |
< |
j = i*5; |
558 |
> |
// pass range functions to ShapeType |
559 |
> |
st->setRangeFuncs(functionVector); |
560 |
|
|
561 |
< |
// Read next line |
562 |
< |
eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile); |
563 |
< |
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 ); |
774 |
< |
|
775 |
< |
// Value 2 |
776 |
< |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
777 |
< |
sprintf( painCave.errMsg, |
778 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
779 |
< |
painCave.isFatal = 1; |
780 |
< |
simError(); |
781 |
< |
} |
561 |
> |
// finally grab the strength functions |
562 |
> |
findBegin(shapeFile, "StrengthFunctions"); |
563 |
> |
functionVector.clear(); |
564 |
|
|
565 |
< |
myEam_rvals[j+1] = atof( the_token ); |
566 |
< |
|
567 |
< |
// Value 3 |
568 |
< |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
569 |
< |
sprintf( painCave.errMsg, |
570 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
571 |
< |
painCave.isFatal = 1; |
572 |
< |
simError(); |
565 |
> |
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 |
> |
nTokens = countTokens(inLine, delim); |
573 |
> |
if (nTokens != 0) { |
574 |
> |
if (nTokens < 4) { |
575 |
> |
sprintf( painCave.errMsg, |
576 |
> |
"Not enough data on a StrengthFunctions line in file: %s\n", |
577 |
> |
shapeFileName.c_str() ); |
578 |
> |
painCave.severity = OOPSE_ERROR; |
579 |
> |
painCave.isFatal = 1; |
580 |
> |
simError(); |
581 |
> |
|
582 |
> |
// read in a spherical harmonic function |
583 |
> |
token = strtok(inLine, delim); |
584 |
> |
rsh = new RealSphericalHarmonic(); |
585 |
> |
rsh->setL(atoi(token)); |
586 |
> |
token = strtok(NULL, delim); |
587 |
> |
rsh->setM(atoi(token)); |
588 |
> |
token = strtok(NULL, delim); |
589 |
> |
if (!strcasecmp("sin",token)) |
590 |
> |
rsh->makeSinFunction(); |
591 |
> |
else |
592 |
> |
rsh->makeCosFunction(); |
593 |
> |
token = strtok(NULL, delim); |
594 |
> |
rsh->setCoefficient(atof(token)); |
595 |
> |
|
596 |
> |
functionVector.push_back(rsh); |
597 |
> |
} |
598 |
> |
} |
599 |
|
} |
600 |
< |
|
601 |
< |
myEam_rvals[j+2] = atof( the_token ); |
600 |
> |
shapeFile.getline(inLine, MAXLEN); |
601 |
> |
} |
602 |
|
|
603 |
< |
// Value 4 |
604 |
< |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
797 |
< |
sprintf( painCave.errMsg, |
798 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
799 |
< |
painCave.isFatal = 1; |
800 |
< |
simError(); |
801 |
< |
} |
802 |
< |
|
803 |
< |
myEam_rvals[j+3] = atof( the_token ); |
603 |
> |
// pass strength functions to ShapeType |
604 |
> |
st->setStrengthFuncs(functionVector); |
605 |
|
|
606 |
< |
// Value 5 |
607 |
< |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
608 |
< |
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 ); |
606 |
> |
// we're done reading from this file |
607 |
> |
shapeFile.close(); |
608 |
> |
} |
609 |
|
|
610 |
< |
} |
611 |
< |
// Parse rho of r vals |
610 |
> |
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 |
< |
// Assume for now that we have a complete number of lines |
616 |
> |
nSteps = 16; |
617 |
|
|
618 |
< |
for (i=0;i<nReadLines;i++){ |
619 |
< |
j = i*5; |
620 |
< |
|
621 |
< |
// 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(); |
832 |
< |
} |
618 |
> |
thetaStep = M_PI / nSteps; |
619 |
> |
thetaMin = thetaStep / 2.0; |
620 |
> |
phiStep = thetaStep * 2.0; |
621 |
> |
bigSigma = 0.0; |
622 |
|
|
623 |
< |
// Parse 5 values on each line into array |
624 |
< |
// Value 1 |
625 |
< |
if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ |
626 |
< |
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 ); |
623 |
> |
for (i = 0; i < nSteps; i++) { |
624 |
> |
|
625 |
> |
theta = thetaMin + i * thetaStep; |
626 |
> |
costheta = cos(theta); |
627 |
|
|
628 |
< |
// 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 ); |
628 |
> |
for (j = 0; j < nSteps; j++) { |
629 |
|
|
630 |
< |
// 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 ); |
630 |
> |
phi = j*phiStep; |
631 |
|
|
632 |
< |
// Value 4 |
633 |
< |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
634 |
< |
sprintf( painCave.errMsg, |
868 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
869 |
< |
painCave.isFatal = 1; |
870 |
< |
simError(); |
632 |
> |
sigma = st->getContactValueAt(costheta, phi); |
633 |
> |
|
634 |
> |
if (sigma > bigSigma) bigSigma = sigma; |
635 |
|
} |
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 |
– |
|
636 |
|
} |
886 |
– |
*eam_rvals = myEam_rvals; |
887 |
– |
*eam_rhovals = myEam_rhovals; |
888 |
– |
*eam_Frhovals = myEam_Frhovals; |
637 |
|
|
638 |
< |
fclose(eamFile); |
891 |
< |
return 0; |
638 |
> |
return bigSigma; |
639 |
|
} |