1 |
#include <stdlib.h> |
2 |
#include <stdio.h> |
3 |
#include <string.h> |
4 |
|
5 |
#include <iostream> |
6 |
using namespace std; |
7 |
|
8 |
#ifdef IS_MPI |
9 |
#include <mpi.h> |
10 |
#endif //is_mpi |
11 |
|
12 |
#include "ForceFields.hpp" |
13 |
#include "SRI.hpp" |
14 |
#include "simError.h" |
15 |
|
16 |
#include "fortranWrappers.hpp" |
17 |
|
18 |
#ifdef IS_MPI |
19 |
#include "mpiForceField.h" |
20 |
#endif // is_mpi |
21 |
|
22 |
|
23 |
|
24 |
namespace EAM_NS{ |
25 |
|
26 |
// Declare the structures that will be passed by the parser and MPI |
27 |
|
28 |
typedef struct{ |
29 |
char name[15]; |
30 |
double mass; |
31 |
double lattice_constant; |
32 |
double eam_drho; // The distance between each of the points indexed by rho. |
33 |
double eam_rcut; // The cutoff radius for eam. |
34 |
double eam_dr; // The distance between each of the rho points. |
35 |
int eam_nrho; // Number of points indexed by rho |
36 |
int eam_nr; // The number of points based on r (Both Phi(r) and Rho(r)). |
37 |
int eam_ident; // Atomic number |
38 |
int ident; |
39 |
int last; // 0 -> default |
40 |
// 1 -> in MPI: tells nodes to stop listening |
41 |
} atomStruct; |
42 |
|
43 |
int parseAtom( char *lineBuffer, int lineNum, atomStruct &info, char *eamPotFile ); |
44 |
int parseEAM( atomStruct &info, char *eamPotFile, double **eam_rvals, |
45 |
double **eam_rhovals, double **eam_Frhovals); |
46 |
#ifdef IS_MPI |
47 |
|
48 |
MPI_Datatype mpiAtomStructType; |
49 |
|
50 |
#endif |
51 |
|
52 |
class LinkedAtomType { |
53 |
public: |
54 |
LinkedAtomType(){ |
55 |
next = NULL; |
56 |
name[0] = '\0'; |
57 |
eam_rvals = NULL; |
58 |
eam_rhovals = NULL; |
59 |
eam_Frhovals = NULL; |
60 |
} |
61 |
|
62 |
~LinkedAtomType(){ |
63 |
if( next != NULL ) delete next; |
64 |
if( eam_rvals != NULL ) delete[] eam_rvals; |
65 |
if( eam_rhovals != NULL ) delete[] eam_rhovals; |
66 |
if( eam_Frhovals != NULL ) delete[] eam_Frhovals; |
67 |
} |
68 |
|
69 |
LinkedAtomType* find(char* key){ |
70 |
if( !strcmp(name, key) ) return this; |
71 |
if( next != NULL ) return next->find(key); |
72 |
return NULL; |
73 |
} |
74 |
|
75 |
|
76 |
void add( atomStruct &info, double *the_eam_rvals, |
77 |
double *the_eam_rhovals,double *the_eam_Frhovals ){ |
78 |
|
79 |
// check for duplicates |
80 |
|
81 |
if( !strcmp( info.name, name ) ){ |
82 |
sprintf( painCave.errMsg, |
83 |
"Duplicate LJ atom type \"%s\" found in " |
84 |
"the LJ_FF param file./n", |
85 |
name ); |
86 |
painCave.isFatal = 1; |
87 |
simError(); |
88 |
} |
89 |
|
90 |
if( next != NULL ) next->add(info, the_eam_rvals, the_eam_rhovals, the_eam_Frhovals); |
91 |
else{ |
92 |
next = new LinkedAtomType(); |
93 |
strcpy(next->name, info.name); |
94 |
next->mass = info.mass; |
95 |
next->lattice_constant = info.lattice_constant; |
96 |
next->eam_nrho = info.eam_nrho; |
97 |
next->eam_drho = info.eam_drho; |
98 |
next->eam_nr = info.eam_nr; |
99 |
next->eam_dr = info.eam_dr; |
100 |
next->eam_rcut = info.eam_rcut; |
101 |
next->eam_ident = info.eam_ident; |
102 |
next->ident = info.ident; |
103 |
|
104 |
next->eam_rvals = the_eam_rvals; |
105 |
next->eam_rhovals = the_eam_rhovals; |
106 |
next->eam_Frhovals = the_eam_Frhovals; |
107 |
} |
108 |
} |
109 |
|
110 |
|
111 |
#ifdef IS_MPI |
112 |
|
113 |
void duplicate( atomStruct &info ){ |
114 |
strcpy(info.name, name); |
115 |
info.mass = mass; |
116 |
info.lattice_constant = lattice_constant; |
117 |
info.eam_nrho = eam_nrho; |
118 |
info.eam_drho = eam_drho; |
119 |
info.eam_nr = eam_nr; |
120 |
info.eam_dr = eam_dr; |
121 |
info.eam_rcut = eam_rcut; |
122 |
info.eam_ident = eam_ident; |
123 |
info.ident = ident; |
124 |
info.last = 0; |
125 |
} |
126 |
|
127 |
|
128 |
#endif |
129 |
|
130 |
char name[15]; |
131 |
double mass; |
132 |
double lattice_constant; |
133 |
int eam_nrho; // Number of points indexed by rho |
134 |
double eam_drho; // The distance between each of the points indexed by rho. |
135 |
int eam_nr; // The number of points based on r (Both Phi(r) and Rho(r)). |
136 |
double eam_dr; // The distance between each of the rho points. |
137 |
double eam_rcut; // The cutoff radius for eam. |
138 |
|
139 |
double *eam_rvals; // Z of r values |
140 |
double *eam_rhovals; // rho of r values |
141 |
double *eam_Frhovals; // F of rho values |
142 |
int eam_ident; // eam identity (atomic number) |
143 |
int ident; |
144 |
LinkedAtomType* next; |
145 |
}; |
146 |
|
147 |
LinkedAtomType* headAtomType; |
148 |
LinkedAtomType* currentAtomType; |
149 |
|
150 |
} |
151 |
|
152 |
using namespace EAM_NS; |
153 |
|
154 |
//**************************************************************** |
155 |
// begins the actual forcefield stuff. |
156 |
//**************************************************************** |
157 |
|
158 |
|
159 |
EAM_FF::EAM_FF(){ |
160 |
|
161 |
char fileName[200]; |
162 |
char* ffPath_env = "FORCE_PARAM_PATH"; |
163 |
char* ffPath; |
164 |
char temp[200]; |
165 |
|
166 |
headAtomType = NULL; |
167 |
currentAtomType = NULL; |
168 |
|
169 |
// Set eamRcut to 0.0 |
170 |
eamRcut = 0.0; |
171 |
|
172 |
// do the funtion wrapping |
173 |
wrapMeFF( this ); |
174 |
|
175 |
#ifdef IS_MPI |
176 |
int i; |
177 |
|
178 |
// ********************************************************************** |
179 |
// Init the atomStruct mpi type |
180 |
|
181 |
atomStruct atomProto; // mpiPrototype |
182 |
int atomBC[3] = {15,5,5}; // block counts |
183 |
MPI_Aint atomDspls[3]; // displacements |
184 |
MPI_Datatype atomMbrTypes[3]; // member mpi types |
185 |
|
186 |
MPI_Address(&atomProto.name, &atomDspls[0]); |
187 |
MPI_Address(&atomProto.mass, &atomDspls[1]); |
188 |
MPI_Address(&atomProto.eam_nrho, &atomDspls[2]); |
189 |
|
190 |
atomMbrTypes[0] = MPI_CHAR; |
191 |
atomMbrTypes[1] = MPI_DOUBLE; |
192 |
atomMbrTypes[2] = MPI_INT; |
193 |
|
194 |
for (i=2; i >= 0; i--) atomDspls[i] -= atomDspls[0]; |
195 |
|
196 |
MPI_Type_struct(3, atomBC, atomDspls, atomMbrTypes, &mpiAtomStructType); |
197 |
MPI_Type_commit(&mpiAtomStructType); |
198 |
|
199 |
// *********************************************************************** |
200 |
|
201 |
if( worldRank == 0 ){ |
202 |
#endif |
203 |
|
204 |
// generate the force file name |
205 |
|
206 |
strcpy( fileName, "EAM_FF.frc" ); |
207 |
// fprintf( stderr,"Trying to open %s\n", fileName ); |
208 |
|
209 |
// attempt to open the file in the current directory first. |
210 |
|
211 |
frcFile = fopen( fileName, "r" ); |
212 |
|
213 |
if( frcFile == NULL ){ |
214 |
|
215 |
// next see if the force path enviorment variable is set |
216 |
|
217 |
ffPath = getenv( ffPath_env ); |
218 |
if( ffPath == NULL ) { |
219 |
STR_DEFINE(ffPath, FRC_PATH ); |
220 |
} |
221 |
|
222 |
|
223 |
strcpy( temp, ffPath ); |
224 |
strcat( temp, "/" ); |
225 |
strcat( temp, fileName ); |
226 |
strcpy( fileName, temp ); |
227 |
|
228 |
frcFile = fopen( fileName, "r" ); |
229 |
|
230 |
if( frcFile == NULL ){ |
231 |
|
232 |
sprintf( painCave.errMsg, |
233 |
"Error opening the force field parameter file: %s\n" |
234 |
"Have you tried setting the FORCE_PARAM_PATH environment " |
235 |
"vairable?\n", |
236 |
fileName ); |
237 |
painCave.isFatal = 1; |
238 |
simError(); |
239 |
} |
240 |
} |
241 |
|
242 |
#ifdef IS_MPI |
243 |
} |
244 |
|
245 |
sprintf( checkPointMsg, "EAM_FF file opened sucessfully." ); |
246 |
MPIcheckPoint(); |
247 |
|
248 |
#endif // is_mpi |
249 |
} |
250 |
|
251 |
|
252 |
EAM_FF::~EAM_FF(){ |
253 |
|
254 |
if( headAtomType != NULL ) delete headAtomType; |
255 |
|
256 |
#ifdef IS_MPI |
257 |
if( worldRank == 0 ){ |
258 |
#endif // is_mpi |
259 |
|
260 |
fclose( frcFile ); |
261 |
|
262 |
#ifdef IS_MPI |
263 |
} |
264 |
#endif // is_mpi |
265 |
} |
266 |
|
267 |
|
268 |
void EAM_FF::calcRcut( void ){ |
269 |
|
270 |
#ifdef IS_MPI |
271 |
double tempEamRcut = eamRcut; |
272 |
MPI_Allreduce( &tempEamRcut, &eamRcut, 1, MPI_DOUBLE, MPI_MAX, |
273 |
MPI_COMM_WORLD); |
274 |
#endif //is_mpi |
275 |
entry_plug->setRcut(eamRcut); |
276 |
} |
277 |
|
278 |
|
279 |
void EAM_FF::initForceField( int ljMixRule ){ |
280 |
initFortran( ljMixRule, 0 ); |
281 |
} |
282 |
|
283 |
void EAM_FF::cleanMe( void ){ |
284 |
|
285 |
#ifdef IS_MPI |
286 |
|
287 |
// keep the linked list in the mpi version |
288 |
|
289 |
#else // is_mpi |
290 |
|
291 |
// delete the linked list in the single processor version |
292 |
|
293 |
if( headAtomType != NULL ) delete headAtomType; |
294 |
|
295 |
#endif // is_mpi |
296 |
} |
297 |
|
298 |
|
299 |
void EAM_FF::readParams( void ){ |
300 |
|
301 |
atomStruct info; |
302 |
info.last = 1; // initialize last to have the last set. |
303 |
// if things go well, last will be set to 0 |
304 |
|
305 |
int identNum; |
306 |
double *eam_rvals; // Z of r values |
307 |
double *eam_rhovals; // rho of r values |
308 |
double *eam_Frhovals; // F of rho values |
309 |
char eamPotFile[1000]; |
310 |
|
311 |
|
312 |
bigSigma = 0.0; |
313 |
#ifdef IS_MPI |
314 |
if( worldRank == 0 ){ |
315 |
#endif |
316 |
|
317 |
// read in the atom types. |
318 |
|
319 |
headAtomType = new LinkedAtomType; |
320 |
|
321 |
fastForward( "AtomTypes", "eam atom readParams" ); |
322 |
|
323 |
// we are now at the AtomTypes section. |
324 |
|
325 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
326 |
lineNum++; |
327 |
|
328 |
|
329 |
// read a line, and start parseing out the atom types |
330 |
|
331 |
if( eof_test == NULL ){ |
332 |
sprintf( painCave.errMsg, |
333 |
"Error in reading Atoms from force file at line %d.\n", |
334 |
lineNum ); |
335 |
painCave.isFatal = 1; |
336 |
simError(); |
337 |
} |
338 |
|
339 |
identNum = 1; |
340 |
// stop reading at end of file, or at next section |
341 |
|
342 |
while( readLine[0] != '#' && eof_test != NULL ){ |
343 |
|
344 |
// toss comment lines |
345 |
if( readLine[0] != '!' ){ |
346 |
|
347 |
// the parser returns 0 if the line was blank |
348 |
if( parseAtom( readLine, lineNum, info, eamPotFile ) ){ |
349 |
parseEAM(info,eamPotFile, &eam_rvals, |
350 |
&eam_rhovals, &eam_Frhovals); |
351 |
info.ident = identNum; |
352 |
headAtomType->add( info, eam_rvals, |
353 |
eam_rhovals,eam_Frhovals ); |
354 |
identNum++; |
355 |
} |
356 |
} |
357 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
358 |
lineNum++; |
359 |
} |
360 |
|
361 |
|
362 |
|
363 |
#ifdef IS_MPI |
364 |
|
365 |
|
366 |
// send out the linked list to all the other processes |
367 |
|
368 |
sprintf( checkPointMsg, |
369 |
"EAM_FF atom structures read successfully." ); |
370 |
MPIcheckPoint(); |
371 |
|
372 |
currentAtomType = headAtomType->next; //skip the first element who is a place holder. |
373 |
while( currentAtomType != NULL ){ |
374 |
currentAtomType->duplicate( info ); |
375 |
|
376 |
|
377 |
|
378 |
sendFrcStruct( &info, mpiAtomStructType ); |
379 |
|
380 |
// We have to now broadcast the Arrays |
381 |
MPI_Bcast(currentAtomType->eam_rvals, |
382 |
currentAtomType->eam_nr, |
383 |
MPI_DOUBLE,0,MPI_COMM_WORLD); |
384 |
MPI_Bcast(currentAtomType->eam_rhovals, |
385 |
currentAtomType->eam_nr, |
386 |
MPI_DOUBLE,0,MPI_COMM_WORLD); |
387 |
MPI_Bcast(currentAtomType->eam_Frhovals, |
388 |
currentAtomType->eam_nrho, |
389 |
MPI_DOUBLE,0,MPI_COMM_WORLD); |
390 |
|
391 |
sprintf( checkPointMsg, |
392 |
"successfully sent EAM force type: \"%s\"\n", |
393 |
info.name ); |
394 |
MPIcheckPoint(); |
395 |
|
396 |
currentAtomType = currentAtomType->next; |
397 |
} |
398 |
info.last = 1; |
399 |
sendFrcStruct( &info, mpiAtomStructType ); |
400 |
|
401 |
} |
402 |
|
403 |
else{ |
404 |
|
405 |
// listen for node 0 to send out the force params |
406 |
|
407 |
MPIcheckPoint(); |
408 |
|
409 |
headAtomType = new LinkedAtomType; |
410 |
recieveFrcStruct( &info, mpiAtomStructType ); |
411 |
|
412 |
while( !info.last ){ |
413 |
|
414 |
// allocate the arrays |
415 |
|
416 |
eam_rvals = new double[info.eam_nr]; |
417 |
eam_rhovals = new double[info.eam_nr]; |
418 |
eam_Frhovals = new double[info.eam_nrho]; |
419 |
|
420 |
// We have to now broadcast the Arrays |
421 |
MPI_Bcast(eam_rvals, |
422 |
info.eam_nr, |
423 |
MPI_DOUBLE,0,MPI_COMM_WORLD); |
424 |
MPI_Bcast(eam_rhovals, |
425 |
info.eam_nr, |
426 |
MPI_DOUBLE,0,MPI_COMM_WORLD); |
427 |
MPI_Bcast(eam_Frhovals, |
428 |
info.eam_nrho, |
429 |
MPI_DOUBLE,0,MPI_COMM_WORLD); |
430 |
|
431 |
|
432 |
headAtomType->add( info, eam_rvals, eam_rhovals, eam_Frhovals ); |
433 |
|
434 |
MPIcheckPoint(); |
435 |
|
436 |
recieveFrcStruct( &info, mpiAtomStructType ); |
437 |
|
438 |
|
439 |
} |
440 |
} |
441 |
#endif // is_mpi |
442 |
|
443 |
// call new A_types in fortran |
444 |
|
445 |
int isError; |
446 |
|
447 |
// dummy variables |
448 |
int isLJ = 0; |
449 |
int isDipole = 0; |
450 |
int isSSD = 0; |
451 |
int isGB = 0; |
452 |
int isEAM= 1; |
453 |
double dipole = 0.0; |
454 |
double eamSigma = 0.0; |
455 |
double eamEpslon = 0.0; |
456 |
|
457 |
currentAtomType = headAtomType->next; |
458 |
while( currentAtomType != NULL ){ |
459 |
|
460 |
if( currentAtomType->name[0] != '\0' ){ |
461 |
isError = 0; |
462 |
makeAtype( &(currentAtomType->ident), |
463 |
&isLJ, |
464 |
&isSSD, |
465 |
&isDipole, |
466 |
&isGB, |
467 |
&isEAM, |
468 |
&eamEpslon, |
469 |
&eamSigma, |
470 |
&dipole, |
471 |
&isError ); |
472 |
if( isError ){ |
473 |
sprintf( painCave.errMsg, |
474 |
"Error initializing the \"%s\" atom type in fortran\n", |
475 |
currentAtomType->name ); |
476 |
painCave.isFatal = 1; |
477 |
simError(); |
478 |
} |
479 |
} |
480 |
currentAtomType = currentAtomType->next; |
481 |
} |
482 |
|
483 |
entry_plug->useLJ = 0; |
484 |
entry_plug->useEAM = 1; |
485 |
// Walk down again and send out EAM type |
486 |
currentAtomType = headAtomType->next; |
487 |
while( currentAtomType != NULL ){ |
488 |
|
489 |
if( currentAtomType->name[0] != '\0' ){ |
490 |
isError = 0; |
491 |
|
492 |
newEAMtype( &(currentAtomType->lattice_constant), |
493 |
&(currentAtomType->eam_nrho), |
494 |
&(currentAtomType->eam_drho), |
495 |
&(currentAtomType->eam_nr), |
496 |
&(currentAtomType->eam_dr), |
497 |
&(currentAtomType->eam_rcut), |
498 |
currentAtomType->eam_rvals, |
499 |
currentAtomType->eam_rhovals, |
500 |
currentAtomType->eam_Frhovals, |
501 |
&(currentAtomType->eam_ident), |
502 |
&isError); |
503 |
|
504 |
if( isError ){ |
505 |
sprintf( painCave.errMsg, |
506 |
"Error initializing the \"%s\" atom type in fortran EAM\n", |
507 |
currentAtomType->name ); |
508 |
painCave.isFatal = 1; |
509 |
simError(); |
510 |
} |
511 |
} |
512 |
currentAtomType = currentAtomType->next; |
513 |
} |
514 |
|
515 |
|
516 |
|
517 |
#ifdef IS_MPI |
518 |
sprintf( checkPointMsg, |
519 |
"EAM_FF atom structures successfully sent to fortran\n" ); |
520 |
MPIcheckPoint(); |
521 |
#endif // is_mpi |
522 |
|
523 |
|
524 |
|
525 |
} |
526 |
|
527 |
|
528 |
void EAM_FF::initializeAtoms( int nAtoms, Atom** the_atoms ){ |
529 |
|
530 |
int i; |
531 |
|
532 |
// initialize the atoms |
533 |
|
534 |
for( i=0; i<nAtoms; i++ ){ |
535 |
|
536 |
currentAtomType = headAtomType->find( the_atoms[i]->getType() ); |
537 |
if( currentAtomType == NULL ){ |
538 |
sprintf( painCave.errMsg, |
539 |
"AtomType error, %s not found in force file.\n", |
540 |
the_atoms[i]->getType() ); |
541 |
painCave.isFatal = 1; |
542 |
simError(); |
543 |
} |
544 |
|
545 |
the_atoms[i]->setMass( currentAtomType->mass ); |
546 |
the_atoms[i]->setIdent( currentAtomType->ident ); |
547 |
the_atoms[i]->setEAM(); |
548 |
the_atoms[i]->setEamRcut( currentAtomType->eam_rcut); |
549 |
|
550 |
if (eamRcut < currentAtomType->eam_rcut) eamRcut = currentAtomType->eam_rcut; |
551 |
|
552 |
} |
553 |
} |
554 |
|
555 |
void EAM_FF::initializeBonds( int nBonds, Bond** BondArray, |
556 |
bond_pair* the_bonds ){ |
557 |
|
558 |
if( nBonds ){ |
559 |
sprintf( painCave.errMsg, |
560 |
"LJ_FF does not support bonds.\n" ); |
561 |
painCave.isFatal = 1; |
562 |
simError(); |
563 |
} |
564 |
} |
565 |
|
566 |
void EAM_FF::initializeBends( int nBends, Bend** bendArray, |
567 |
bend_set* the_bends ){ |
568 |
|
569 |
if( nBends ){ |
570 |
sprintf( painCave.errMsg, |
571 |
"LJ_FF does not support bends.\n" ); |
572 |
painCave.isFatal = 1; |
573 |
simError(); |
574 |
} |
575 |
} |
576 |
|
577 |
void EAM_FF::initializeTorsions( int nTorsions, Torsion** torsionArray, |
578 |
torsion_set* the_torsions ){ |
579 |
|
580 |
if( nTorsions ){ |
581 |
sprintf( painCave.errMsg, |
582 |
"LJ_FF does not support torsions.\n" ); |
583 |
painCave.isFatal = 1; |
584 |
simError(); |
585 |
} |
586 |
} |
587 |
|
588 |
void EAM_FF::fastForward( char* stopText, char* searchOwner ){ |
589 |
|
590 |
int foundText = 0; |
591 |
char* the_token; |
592 |
|
593 |
rewind( frcFile ); |
594 |
lineNum = 0; |
595 |
|
596 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
597 |
lineNum++; |
598 |
if( eof_test == NULL ){ |
599 |
sprintf( painCave.errMsg, "Error fast forwarding force file for %s: " |
600 |
" file is empty.\n", |
601 |
searchOwner ); |
602 |
painCave.isFatal = 1; |
603 |
simError(); |
604 |
} |
605 |
|
606 |
|
607 |
while( !foundText ){ |
608 |
while( eof_test != NULL && readLine[0] != '#' ){ |
609 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
610 |
lineNum++; |
611 |
} |
612 |
if( eof_test == NULL ){ |
613 |
sprintf( painCave.errMsg, |
614 |
"Error fast forwarding force file for %s at " |
615 |
"line %d: file ended unexpectedly.\n", |
616 |
searchOwner, |
617 |
lineNum ); |
618 |
painCave.isFatal = 1; |
619 |
simError(); |
620 |
} |
621 |
|
622 |
the_token = strtok( readLine, " ,;\t#\n" ); |
623 |
foundText = !strcmp( stopText, the_token ); |
624 |
|
625 |
if( !foundText ){ |
626 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
627 |
lineNum++; |
628 |
|
629 |
if( eof_test == NULL ){ |
630 |
sprintf( painCave.errMsg, |
631 |
"Error fast forwarding force file for %s at " |
632 |
"line %d: file ended unexpectedly.\n", |
633 |
searchOwner, |
634 |
lineNum ); |
635 |
painCave.isFatal = 1; |
636 |
simError(); |
637 |
} |
638 |
} |
639 |
} |
640 |
} |
641 |
|
642 |
|
643 |
|
644 |
int EAM_NS::parseAtom( char *lineBuffer, int lineNum, atomStruct &info, char *eamPotFile ){ |
645 |
|
646 |
char* the_token; |
647 |
|
648 |
the_token = strtok( lineBuffer, " \n\t,;" ); |
649 |
if( the_token != NULL ){ |
650 |
|
651 |
strcpy( info.name, the_token ); |
652 |
|
653 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
654 |
sprintf( painCave.errMsg, |
655 |
"Error parseing AtomTypes: line %d\n", lineNum ); |
656 |
painCave.isFatal = 1; |
657 |
simError(); |
658 |
} |
659 |
|
660 |
info.mass = atof( the_token ); |
661 |
|
662 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
663 |
sprintf( painCave.errMsg, |
664 |
"Error parseing AtomTypes: line %d\n", lineNum ); |
665 |
painCave.isFatal = 1; |
666 |
simError(); |
667 |
} |
668 |
|
669 |
strcpy( eamPotFile, the_token ); |
670 |
return 1; |
671 |
} |
672 |
else return 0; |
673 |
} |
674 |
|
675 |
int EAM_NS::parseEAM(atomStruct &info, char *eamPotFile, |
676 |
double **eam_rvals, |
677 |
double **eam_rhovals, |
678 |
double **eam_Frhovals){ |
679 |
double* myEam_rvals; |
680 |
double* myEam_rhovals; |
681 |
double* myEam_Frhovals; |
682 |
|
683 |
char* ffPath_env = "FORCE_PARAM_PATH"; |
684 |
char* ffPath; |
685 |
char* the_token; |
686 |
char* eam_eof_test; |
687 |
FILE *eamFile; |
688 |
const int BUFFERSIZE = 3000; |
689 |
|
690 |
char temp[200]; |
691 |
int linenumber; |
692 |
int nReadLines; |
693 |
char eam_read_buffer[BUFFERSIZE]; |
694 |
|
695 |
|
696 |
int i,j; |
697 |
|
698 |
linenumber = 0; |
699 |
|
700 |
// Open eam file |
701 |
eamFile = fopen( eamPotFile, "r" ); |
702 |
|
703 |
|
704 |
if( eamFile == NULL ){ |
705 |
|
706 |
// next see if the force path enviorment variable is set |
707 |
|
708 |
ffPath = getenv( ffPath_env ); |
709 |
if( ffPath == NULL ) { |
710 |
STR_DEFINE(ffPath, FRC_PATH ); |
711 |
} |
712 |
|
713 |
|
714 |
strcpy( temp, ffPath ); |
715 |
strcat( temp, "/" ); |
716 |
strcat( temp, eamPotFile ); |
717 |
strcpy( eamPotFile, temp ); |
718 |
|
719 |
eamFile = fopen( eamPotFile, "r" ); |
720 |
|
721 |
|
722 |
|
723 |
if( eamFile == NULL ){ |
724 |
|
725 |
sprintf( painCave.errMsg, |
726 |
"Error opening the EAM force parameter file: %s\n" |
727 |
"Have you tried setting the FORCE_PARAM_PATH environment " |
728 |
"vairable?\n", |
729 |
eamPotFile ); |
730 |
painCave.isFatal = 1; |
731 |
simError(); |
732 |
} |
733 |
} |
734 |
|
735 |
// First line is a comment line, read and toss it.... |
736 |
eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile); |
737 |
linenumber++; |
738 |
if(eam_eof_test == NULL){ |
739 |
sprintf( painCave.errMsg, |
740 |
"error in reading commment in %s\n", eamPotFile); |
741 |
painCave.isFatal = 1; |
742 |
simError(); |
743 |
} |
744 |
|
745 |
|
746 |
|
747 |
// The Second line contains atomic number, atomic mass and a lattice constant |
748 |
eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile); |
749 |
linenumber++; |
750 |
if(eam_eof_test == NULL){ |
751 |
sprintf( painCave.errMsg, |
752 |
"error in reading Identifier line in %s\n", eamPotFile); |
753 |
painCave.isFatal = 1; |
754 |
simError(); |
755 |
} |
756 |
|
757 |
|
758 |
|
759 |
|
760 |
if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ |
761 |
sprintf( painCave.errMsg, |
762 |
"Error parseing EAM ident line in %s\n", eamPotFile ); |
763 |
painCave.isFatal = 1; |
764 |
simError(); |
765 |
} |
766 |
|
767 |
info.eam_ident = atoi( the_token ); |
768 |
|
769 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
770 |
sprintf( painCave.errMsg, |
771 |
"Error parseing EAM mass in %s\n", eamPotFile ); |
772 |
painCave.isFatal = 1; |
773 |
simError(); |
774 |
} |
775 |
info.mass = atof( the_token); |
776 |
|
777 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
778 |
sprintf( painCave.errMsg, |
779 |
"Error parseing EAM Lattice Constant %s\n", eamPotFile ); |
780 |
painCave.isFatal = 1; |
781 |
simError(); |
782 |
} |
783 |
info.lattice_constant = atof( the_token); |
784 |
|
785 |
// Next line is nrho, drho, nr, dr and rcut |
786 |
eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile); |
787 |
if(eam_eof_test == NULL){ |
788 |
sprintf( painCave.errMsg, |
789 |
"error in reading number of points line in %s\n", eamPotFile); |
790 |
painCave.isFatal = 1; |
791 |
simError(); |
792 |
} |
793 |
|
794 |
if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ |
795 |
sprintf( painCave.errMsg, |
796 |
"Error parseing EAM nrho: line in %s\n", eamPotFile ); |
797 |
painCave.isFatal = 1; |
798 |
simError(); |
799 |
} |
800 |
|
801 |
info.eam_nrho = atoi( the_token ); |
802 |
|
803 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
804 |
sprintf( painCave.errMsg, |
805 |
"Error parseing EAM drho in %s\n", eamPotFile ); |
806 |
painCave.isFatal = 1; |
807 |
simError(); |
808 |
} |
809 |
info.eam_drho = atof( the_token); |
810 |
|
811 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
812 |
sprintf( painCave.errMsg, |
813 |
"Error parseing EAM # r in %s\n", eamPotFile ); |
814 |
painCave.isFatal = 1; |
815 |
simError(); |
816 |
} |
817 |
info.eam_nr = atoi( the_token); |
818 |
|
819 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
820 |
sprintf( painCave.errMsg, |
821 |
"Error parseing EAM dr in %s\n", eamPotFile ); |
822 |
painCave.isFatal = 1; |
823 |
simError(); |
824 |
} |
825 |
info.eam_dr = atof( the_token); |
826 |
|
827 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
828 |
sprintf( painCave.errMsg, |
829 |
"Error parseing EAM rcut in %s\n", eamPotFile ); |
830 |
painCave.isFatal = 1; |
831 |
simError(); |
832 |
} |
833 |
info.eam_rcut = atof( the_token); |
834 |
|
835 |
|
836 |
|
837 |
|
838 |
|
839 |
// Ok now we have to allocate point arrays and read in number of points |
840 |
// Index the arrays for fortran, starting at 1 |
841 |
myEam_Frhovals = new double[info.eam_nrho]; |
842 |
myEam_rvals = new double[info.eam_nr]; |
843 |
myEam_rhovals = new double[info.eam_nr]; |
844 |
|
845 |
// Parse F of rho vals. |
846 |
|
847 |
// Assume for now that we have a complete number of lines |
848 |
nReadLines = int(info.eam_nrho/5); |
849 |
|
850 |
|
851 |
|
852 |
for (i=0;i<nReadLines;i++){ |
853 |
j = i*5; |
854 |
|
855 |
// Read next line |
856 |
eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile); |
857 |
linenumber++; |
858 |
if(eam_eof_test == NULL){ |
859 |
sprintf( painCave.errMsg, |
860 |
"error in reading EAM file %s at line %d\n", |
861 |
eamPotFile,linenumber); |
862 |
painCave.isFatal = 1; |
863 |
simError(); |
864 |
} |
865 |
|
866 |
// Parse 5 values on each line into array |
867 |
// Value 1 |
868 |
if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ |
869 |
sprintf( painCave.errMsg, |
870 |
"Error parseing EAM nrho: line in %s\n", eamPotFile ); |
871 |
painCave.isFatal = 1; |
872 |
simError(); |
873 |
} |
874 |
|
875 |
myEam_Frhovals[j+0] = atof( the_token ); |
876 |
|
877 |
// Value 2 |
878 |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
879 |
sprintf( painCave.errMsg, |
880 |
"Error parseing EAM nrho: line in %s\n", eamPotFile ); |
881 |
painCave.isFatal = 1; |
882 |
simError(); |
883 |
} |
884 |
|
885 |
myEam_Frhovals[j+1] = atof( the_token ); |
886 |
|
887 |
// Value 3 |
888 |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
889 |
sprintf( painCave.errMsg, |
890 |
"Error parseing EAM nrho: line in %s\n", eamPotFile ); |
891 |
painCave.isFatal = 1; |
892 |
simError(); |
893 |
} |
894 |
|
895 |
myEam_Frhovals[j+2] = atof( the_token ); |
896 |
|
897 |
// Value 4 |
898 |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
899 |
sprintf( painCave.errMsg, |
900 |
"Error parseing EAM nrho: line in %s\n", eamPotFile ); |
901 |
painCave.isFatal = 1; |
902 |
simError(); |
903 |
} |
904 |
|
905 |
myEam_Frhovals[j+3] = atof( the_token ); |
906 |
|
907 |
// Value 5 |
908 |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
909 |
sprintf( painCave.errMsg, |
910 |
"Error parseing EAM nrho: line in %s\n", eamPotFile ); |
911 |
painCave.isFatal = 1; |
912 |
simError(); |
913 |
} |
914 |
|
915 |
myEam_Frhovals[j+4] = atof( the_token ); |
916 |
|
917 |
} |
918 |
// Parse Z of r vals |
919 |
|
920 |
// Assume for now that we have a complete number of lines |
921 |
nReadLines = int(info.eam_nr/5); |
922 |
|
923 |
for (i=0;i<nReadLines;i++){ |
924 |
j = i*5; |
925 |
|
926 |
// Read next line |
927 |
eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile); |
928 |
linenumber++; |
929 |
if(eam_eof_test == NULL){ |
930 |
sprintf( painCave.errMsg, |
931 |
"error in reading EAM file %s at line %d\n", |
932 |
eamPotFile,linenumber); |
933 |
painCave.isFatal = 1; |
934 |
simError(); |
935 |
} |
936 |
|
937 |
// Parse 5 values on each line into array |
938 |
// Value 1 |
939 |
if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ |
940 |
sprintf( painCave.errMsg, |
941 |
"Error parseing EAM nrho: line in %s\n", eamPotFile ); |
942 |
painCave.isFatal = 1; |
943 |
simError(); |
944 |
} |
945 |
|
946 |
myEam_rvals[j+0] = atof( the_token ); |
947 |
|
948 |
// Value 2 |
949 |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
950 |
sprintf( painCave.errMsg, |
951 |
"Error parseing EAM nrho: line in %s\n", eamPotFile ); |
952 |
painCave.isFatal = 1; |
953 |
simError(); |
954 |
} |
955 |
|
956 |
myEam_rvals[j+1] = atof( the_token ); |
957 |
|
958 |
// Value 3 |
959 |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
960 |
sprintf( painCave.errMsg, |
961 |
"Error parseing EAM nrho: line in %s\n", eamPotFile ); |
962 |
painCave.isFatal = 1; |
963 |
simError(); |
964 |
} |
965 |
|
966 |
myEam_rvals[j+2] = atof( the_token ); |
967 |
|
968 |
// Value 4 |
969 |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
970 |
sprintf( painCave.errMsg, |
971 |
"Error parseing EAM nrho: line in %s\n", eamPotFile ); |
972 |
painCave.isFatal = 1; |
973 |
simError(); |
974 |
} |
975 |
|
976 |
myEam_rvals[j+3] = atof( the_token ); |
977 |
|
978 |
// Value 5 |
979 |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
980 |
sprintf( painCave.errMsg, |
981 |
"Error parseing EAM nrho: line in %s\n", eamPotFile ); |
982 |
painCave.isFatal = 1; |
983 |
simError(); |
984 |
} |
985 |
|
986 |
myEam_rvals[j+4] = atof( the_token ); |
987 |
|
988 |
} |
989 |
// Parse rho of r vals |
990 |
|
991 |
// Assume for now that we have a complete number of lines |
992 |
|
993 |
for (i=0;i<nReadLines;i++){ |
994 |
j = i*5; |
995 |
|
996 |
// Read next line |
997 |
eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile); |
998 |
linenumber++; |
999 |
if(eam_eof_test == NULL){ |
1000 |
sprintf( painCave.errMsg, |
1001 |
"error in reading EAM file %s at line %d\n", |
1002 |
eamPotFile,linenumber); |
1003 |
painCave.isFatal = 1; |
1004 |
simError(); |
1005 |
} |
1006 |
|
1007 |
// Parse 5 values on each line into array |
1008 |
// Value 1 |
1009 |
if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ |
1010 |
sprintf( painCave.errMsg, |
1011 |
"Error parseing EAM nrho: line in %s\n", eamPotFile ); |
1012 |
painCave.isFatal = 1; |
1013 |
simError(); |
1014 |
} |
1015 |
|
1016 |
myEam_rhovals[j+0] = atof( the_token ); |
1017 |
|
1018 |
// Value 2 |
1019 |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
1020 |
sprintf( painCave.errMsg, |
1021 |
"Error parseing EAM nrho: line in %s\n", eamPotFile ); |
1022 |
painCave.isFatal = 1; |
1023 |
simError(); |
1024 |
} |
1025 |
|
1026 |
myEam_rhovals[j+1] = atof( the_token ); |
1027 |
|
1028 |
// Value 3 |
1029 |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
1030 |
sprintf( painCave.errMsg, |
1031 |
"Error parseing EAM nrho: line in %s\n", eamPotFile ); |
1032 |
painCave.isFatal = 1; |
1033 |
simError(); |
1034 |
} |
1035 |
|
1036 |
myEam_rhovals[j+2] = atof( the_token ); |
1037 |
|
1038 |
// Value 4 |
1039 |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
1040 |
sprintf( painCave.errMsg, |
1041 |
"Error parseing EAM nrho: line in %s\n", eamPotFile ); |
1042 |
painCave.isFatal = 1; |
1043 |
simError(); |
1044 |
} |
1045 |
|
1046 |
myEam_rhovals[j+3] = atof( the_token ); |
1047 |
|
1048 |
// Value 5 |
1049 |
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
1050 |
sprintf( painCave.errMsg, |
1051 |
"Error parseing EAM nrho: line in %s\n", eamPotFile ); |
1052 |
painCave.isFatal = 1; |
1053 |
simError(); |
1054 |
} |
1055 |
|
1056 |
myEam_rhovals[j+4] = atof( the_token ); |
1057 |
|
1058 |
} |
1059 |
*eam_rvals = myEam_rvals; |
1060 |
*eam_rhovals = myEam_rhovals; |
1061 |
*eam_Frhovals = myEam_Frhovals; |
1062 |
|
1063 |
fclose(eamFile); |
1064 |
return 0; |
1065 |
} |