42 |
|
// 1 -> in MPI: tells nodes to stop listening |
43 |
|
} atomStruct; |
44 |
|
|
45 |
< |
int parseAtom( char *lineBuffer, int lineNum, atomStruct &info, char *eamPotFile ); |
46 |
< |
int parseEAM( atomStruct &info, char *eamPotFile, double **eam_rvals, |
47 |
< |
double **eam_rhovals, double **eam_Frhovals); |
45 |
> |
int parseAtom( char *lineBuffer, int lineNum, atomStruct &info, string eamPotFile ); |
46 |
> |
int parseEAM( atomStruct &info, string ffPath, string eamPotFile, |
47 |
> |
double **eam_rvals, double **eam_rhovals, |
48 |
> |
double **eam_Frhovals); |
49 |
|
#ifdef IS_MPI |
50 |
|
|
51 |
|
MPI_Datatype mpiAtomStructType; |
69 |
|
if( eam_Frhovals != NULL ) delete[] eam_Frhovals; |
70 |
|
} |
71 |
|
|
72 |
< |
LinkedAtomType* find(char* key){ |
72 |
> |
LinkedAtomType* find(const char* key){ |
73 |
|
if( !strcmp(name, key) ) return this; |
74 |
|
if( next != NULL ) return next->find(key); |
75 |
|
return NULL; |
158 |
|
// begins the actual forcefield stuff. |
159 |
|
//**************************************************************** |
160 |
|
|
161 |
< |
EAM_FF::EAM_FF() { |
161 |
> |
EAM_FF::EAM_FF(){ |
162 |
|
EAM_FF(""); |
163 |
|
} |
164 |
|
|
165 |
< |
EAM_FF::EAM_FF(char* the_variant){ |
165 |
> |
EAM_FF::EAM_FF(const string &the_variant) : ForceFields(the_variant) { |
166 |
|
|
167 |
< |
char fileName[200]; |
168 |
< |
char* ffPath_env = "FORCE_PARAM_PATH"; |
168 |
< |
char* ffPath; |
169 |
< |
char temp[200]; |
167 |
> |
string fileName; |
168 |
> |
string tempString; |
169 |
|
|
170 |
|
headAtomType = NULL; |
171 |
|
currentAtomType = NULL; |
204 |
|
|
205 |
|
// generate the force file name |
206 |
|
|
207 |
< |
strcpy( fileName, "EAM" ); |
207 |
> |
fileName = "EAM"; |
208 |
|
|
209 |
< |
if (strlen(the_variant) > 0) { |
209 |
> |
if (!the_variant.empty()) { |
210 |
|
has_variant = 1; |
211 |
< |
strcpy( variant, the_variant); |
212 |
< |
strcat( fileName, "."); |
214 |
< |
strcat( fileName, variant ); |
215 |
< |
|
211 |
> |
fileName += "." + the_variant; |
212 |
> |
|
213 |
|
sprintf( painCave.errMsg, |
214 |
|
"Using %s variant of EAM force field.\n", |
215 |
< |
variant ); |
215 |
> |
the_variant.c_str() ); |
216 |
|
painCave.severity = OOPSE_INFO; |
217 |
|
painCave.isFatal = 0; |
218 |
|
simError(); |
219 |
< |
} |
223 |
< |
strcat( fileName, ".frc"); |
219 |
> |
} |
220 |
|
|
221 |
+ |
fileName += ".frc"; |
222 |
+ |
|
223 |
|
//fprintf( stderr,"Trying to open %s\n", fileName ); |
224 |
|
|
225 |
|
// attempt to open the file in the current directory first. |
226 |
|
|
227 |
< |
frcFile = fopen( fileName, "r" ); |
227 |
> |
frcFile = fopen( fileName.c_str(), "r" ); |
228 |
|
|
229 |
|
if( frcFile == NULL ){ |
230 |
|
|
231 |
|
// next see if the force path enviorment variable is set |
232 |
|
|
233 |
< |
ffPath = getenv( ffPath_env ); |
234 |
< |
if( ffPath == NULL ) { |
235 |
< |
STR_DEFINE(ffPath, FRC_PATH ); |
236 |
< |
} |
239 |
< |
|
240 |
< |
|
241 |
< |
strcpy( temp, ffPath ); |
242 |
< |
strcat( temp, "/" ); |
243 |
< |
strcat( temp, fileName ); |
244 |
< |
strcpy( fileName, temp ); |
245 |
< |
|
246 |
< |
frcFile = fopen( fileName, "r" ); |
233 |
> |
tempString = ffPath + "/" + fileName; |
234 |
> |
fileName = tempString; |
235 |
> |
|
236 |
> |
frcFile = fopen( fileName.c_str(), "r" ); |
237 |
|
|
238 |
|
if( frcFile == NULL ){ |
239 |
|
|
242 |
|
"\t%s\n" |
243 |
|
"\tHave you tried setting the FORCE_PARAM_PATH environment " |
244 |
|
"variable?\n", |
245 |
< |
fileName ); |
245 |
> |
fileName.c_str() ); |
246 |
|
painCave.severity = OOPSE_ERROR; |
247 |
|
painCave.isFatal = 1; |
248 |
|
simError(); |
317 |
|
double *eam_rvals; // Z of r values |
318 |
|
double *eam_rhovals; // rho of r values |
319 |
|
double *eam_Frhovals; // F of rho values |
320 |
< |
char eamPotFile[1000]; |
320 |
> |
string eamPotFile; |
321 |
|
|
322 |
|
|
323 |
|
|
358 |
|
|
359 |
|
// the parser returns 0 if the line was blank |
360 |
|
if( parseAtom( readLine, lineNum, info, eamPotFile ) ){ |
361 |
< |
parseEAM(info,eamPotFile, &eam_rvals, |
361 |
> |
parseEAM(info, ffPath, eamPotFile, &eam_rvals, |
362 |
|
&eam_rhovals, &eam_Frhovals); |
363 |
|
info.ident = identNum; |
364 |
|
headAtomType->add( info, eam_rvals, |
527 |
|
|
528 |
|
for( i=0; i<nAtoms; i++ ){ |
529 |
|
|
530 |
< |
currentAtomType = headAtomType->find( the_atoms[i]->getType() ); |
530 |
> |
currentAtomType = headAtomType->find(the_atoms[i]->getType().c_str() ); |
531 |
|
if( currentAtomType == NULL ){ |
532 |
|
sprintf( painCave.errMsg, |
533 |
|
"AtomType error, %s not found in force file.\n", |
534 |
< |
the_atoms[i]->getType() ); |
534 |
> |
the_atoms[i]->getType().c_str() ); |
535 |
|
painCave.isFatal = 1; |
536 |
|
simError(); |
537 |
|
} |
633 |
|
|
634 |
|
|
635 |
|
|
636 |
< |
int EAM_NS::parseAtom( char *lineBuffer, int lineNum, atomStruct &info, char *eamPotFile ){ |
636 |
> |
int EAM_NS::parseAtom( char *lineBuffer, int lineNum, atomStruct &info, string eamPotFile ){ |
637 |
|
|
638 |
|
char* the_token; |
639 |
|
|
657 |
|
painCave.isFatal = 1; |
658 |
|
simError(); |
659 |
|
} |
660 |
< |
|
661 |
< |
strcpy( eamPotFile, the_token ); |
660 |
> |
|
661 |
> |
eamPotFile = the_token; |
662 |
> |
|
663 |
|
return 1; |
664 |
|
} |
665 |
|
else return 0; |
666 |
|
} |
667 |
|
|
668 |
< |
int EAM_NS::parseEAM(atomStruct &info, char *eamPotFile, |
668 |
> |
int EAM_NS::parseEAM(atomStruct &info, string ffPath, string eamPotFile, |
669 |
|
double **eam_rvals, |
670 |
|
double **eam_rhovals, |
671 |
|
double **eam_Frhovals){ |
673 |
|
double* myEam_rhovals; |
674 |
|
double* myEam_Frhovals; |
675 |
|
|
685 |
– |
char* ffPath_env = "FORCE_PARAM_PATH"; |
686 |
– |
char* ffPath; |
676 |
|
char* the_token; |
677 |
|
char* eam_eof_test; |
678 |
|
FILE *eamFile; |
679 |
|
const int BUFFERSIZE = 3000; |
680 |
|
|
681 |
< |
char temp[200]; |
681 |
> |
string tempString; |
682 |
|
int linenumber; |
683 |
|
int nReadLines; |
684 |
|
char eam_read_buffer[BUFFERSIZE]; |
685 |
|
|
697 |
– |
|
686 |
|
int i,j; |
687 |
|
|
688 |
|
linenumber = 0; |
689 |
|
|
690 |
|
// Open eam file |
691 |
< |
eamFile = fopen( eamPotFile, "r" ); |
704 |
< |
|
691 |
> |
eamFile = fopen( eamPotFile.c_str(), "r" ); |
692 |
|
|
693 |
|
if( eamFile == NULL ){ |
694 |
|
|
695 |
|
// next see if the force path enviorment variable is set |
696 |
|
|
697 |
< |
ffPath = getenv( ffPath_env ); |
698 |
< |
if( ffPath == NULL ) { |
712 |
< |
STR_DEFINE(ffPath, FRC_PATH ); |
713 |
< |
} |
697 |
> |
tempString = ffPath + "/" + eamPotFile; |
698 |
> |
eamPotFile = tempString; |
699 |
|
|
700 |
+ |
eamFile = fopen( eamPotFile.c_str(), "r" ); |
701 |
|
|
716 |
– |
strcpy( temp, ffPath ); |
717 |
– |
strcat( temp, "/" ); |
718 |
– |
strcat( temp, eamPotFile ); |
719 |
– |
strcpy( eamPotFile, temp ); |
720 |
– |
|
721 |
– |
eamFile = fopen( eamPotFile, "r" ); |
722 |
– |
|
723 |
– |
|
724 |
– |
|
702 |
|
if( eamFile == NULL ){ |
703 |
|
|
704 |
|
sprintf( painCave.errMsg, |
705 |
|
"Error opening the EAM force parameter file: %s\n" |
706 |
|
"Have you tried setting the FORCE_PARAM_PATH environment " |
707 |
|
"variable?\n", |
708 |
< |
eamPotFile ); |
708 |
> |
eamPotFile.c_str() ); |
709 |
|
painCave.isFatal = 1; |
710 |
|
simError(); |
711 |
|
} |
716 |
|
linenumber++; |
717 |
|
if(eam_eof_test == NULL){ |
718 |
|
sprintf( painCave.errMsg, |
719 |
< |
"error in reading commment in %s\n", eamPotFile); |
719 |
> |
"error in reading commment in %s\n", eamPotFile.c_str()); |
720 |
|
painCave.isFatal = 1; |
721 |
|
simError(); |
722 |
|
} |
728 |
|
linenumber++; |
729 |
|
if(eam_eof_test == NULL){ |
730 |
|
sprintf( painCave.errMsg, |
731 |
< |
"error in reading Identifier line in %s\n", eamPotFile); |
731 |
> |
"error in reading Identifier line in %s\n", eamPotFile.c_str()); |
732 |
|
painCave.isFatal = 1; |
733 |
|
simError(); |
734 |
|
} |
738 |
|
|
739 |
|
if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ |
740 |
|
sprintf( painCave.errMsg, |
741 |
< |
"Error parsing EAM ident line in %s\n", eamPotFile ); |
741 |
> |
"Error parsing EAM ident line in %s\n", eamPotFile.c_str() ); |
742 |
|
painCave.isFatal = 1; |
743 |
|
simError(); |
744 |
|
} |
747 |
|
|
748 |
|
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
749 |
|
sprintf( painCave.errMsg, |
750 |
< |
"Error parsing EAM mass in %s\n", eamPotFile ); |
750 |
> |
"Error parsing EAM mass in %s\n", eamPotFile.c_str() ); |
751 |
|
painCave.isFatal = 1; |
752 |
|
simError(); |
753 |
|
} |
755 |
|
|
756 |
|
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
757 |
|
sprintf( painCave.errMsg, |
758 |
< |
"Error parsing EAM Lattice Constant %s\n", eamPotFile ); |
758 |
> |
"Error parsing EAM Lattice Constant %s\n", eamPotFile.c_str() ); |
759 |
|
painCave.isFatal = 1; |
760 |
|
simError(); |
761 |
|
} |
765 |
|
eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile); |
766 |
|
if(eam_eof_test == NULL){ |
767 |
|
sprintf( painCave.errMsg, |
768 |
< |
"error in reading number of points line in %s\n", eamPotFile); |
768 |
> |
"error in reading number of points line in %s\n", |
769 |
> |
eamPotFile.c_str()); |
770 |
|
painCave.isFatal = 1; |
771 |
|
simError(); |
772 |
|
} |
773 |
|
|
774 |
|
if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ |
775 |
|
sprintf( painCave.errMsg, |
776 |
< |
"Error parseing EAM nrho: line in %s\n", eamPotFile ); |
776 |
> |
"Error parseing EAM nrho: line in %s\n", eamPotFile.c_str() ); |
777 |
|
painCave.isFatal = 1; |
778 |
|
simError(); |
779 |
|
} |
782 |
|
|
783 |
|
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
784 |
|
sprintf( painCave.errMsg, |
785 |
< |
"Error parsing EAM drho in %s\n", eamPotFile ); |
785 |
> |
"Error parsing EAM drho in %s\n", eamPotFile.c_str() ); |
786 |
|
painCave.isFatal = 1; |
787 |
|
simError(); |
788 |
|
} |
790 |
|
|
791 |
|
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
792 |
|
sprintf( painCave.errMsg, |
793 |
< |
"Error parsing EAM # r in %s\n", eamPotFile ); |
793 |
> |
"Error parsing EAM # r in %s\n", eamPotFile.c_str() ); |
794 |
|
painCave.isFatal = 1; |
795 |
|
simError(); |
796 |
|
} |
798 |
|
|
799 |
|
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
800 |
|
sprintf( painCave.errMsg, |
801 |
< |
"Error parsing EAM dr in %s\n", eamPotFile ); |
801 |
> |
"Error parsing EAM dr in %s\n", eamPotFile.c_str() ); |
802 |
|
painCave.isFatal = 1; |
803 |
|
simError(); |
804 |
|
} |
806 |
|
|
807 |
|
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
808 |
|
sprintf( painCave.errMsg, |
809 |
< |
"Error parsing EAM rcut in %s\n", eamPotFile ); |
809 |
> |
"Error parsing EAM rcut in %s\n", eamPotFile.c_str() ); |
810 |
|
painCave.isFatal = 1; |
811 |
|
simError(); |
812 |
|
} |
838 |
|
if(eam_eof_test == NULL){ |
839 |
|
sprintf( painCave.errMsg, |
840 |
|
"error in reading EAM file %s at line %d\n", |
841 |
< |
eamPotFile,linenumber); |
841 |
> |
eamPotFile.c_str(), linenumber); |
842 |
|
painCave.isFatal = 1; |
843 |
|
simError(); |
844 |
|
} |
847 |
|
// Value 1 |
848 |
|
if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ |
849 |
|
sprintf( painCave.errMsg, |
850 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
850 |
> |
"Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() ); |
851 |
|
painCave.isFatal = 1; |
852 |
|
simError(); |
853 |
|
} |
857 |
|
// Value 2 |
858 |
|
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
859 |
|
sprintf( painCave.errMsg, |
860 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
860 |
> |
"Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() ); |
861 |
|
painCave.isFatal = 1; |
862 |
|
simError(); |
863 |
|
} |
867 |
|
// Value 3 |
868 |
|
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
869 |
|
sprintf( painCave.errMsg, |
870 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
870 |
> |
"Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() ); |
871 |
|
painCave.isFatal = 1; |
872 |
|
simError(); |
873 |
|
} |
877 |
|
// Value 4 |
878 |
|
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
879 |
|
sprintf( painCave.errMsg, |
880 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
880 |
> |
"Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() ); |
881 |
|
painCave.isFatal = 1; |
882 |
|
simError(); |
883 |
|
} |
887 |
|
// Value 5 |
888 |
|
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
889 |
|
sprintf( painCave.errMsg, |
890 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
890 |
> |
"Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() ); |
891 |
|
painCave.isFatal = 1; |
892 |
|
simError(); |
893 |
|
} |
909 |
|
if(eam_eof_test == NULL){ |
910 |
|
sprintf( painCave.errMsg, |
911 |
|
"error in reading EAM file %s at line %d\n", |
912 |
< |
eamPotFile,linenumber); |
912 |
> |
eamPotFile.c_str(), linenumber); |
913 |
|
painCave.isFatal = 1; |
914 |
|
simError(); |
915 |
|
} |
918 |
|
// Value 1 |
919 |
|
if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ |
920 |
|
sprintf( painCave.errMsg, |
921 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
921 |
> |
"Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() ); |
922 |
|
painCave.isFatal = 1; |
923 |
|
simError(); |
924 |
|
} |
928 |
|
// Value 2 |
929 |
|
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
930 |
|
sprintf( painCave.errMsg, |
931 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
931 |
> |
"Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() ); |
932 |
|
painCave.isFatal = 1; |
933 |
|
simError(); |
934 |
|
} |
938 |
|
// Value 3 |
939 |
|
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
940 |
|
sprintf( painCave.errMsg, |
941 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
941 |
> |
"Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() ); |
942 |
|
painCave.isFatal = 1; |
943 |
|
simError(); |
944 |
|
} |
948 |
|
// Value 4 |
949 |
|
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
950 |
|
sprintf( painCave.errMsg, |
951 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
951 |
> |
"Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() ); |
952 |
|
painCave.isFatal = 1; |
953 |
|
simError(); |
954 |
|
} |
958 |
|
// Value 5 |
959 |
|
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
960 |
|
sprintf( painCave.errMsg, |
961 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
961 |
> |
"Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() ); |
962 |
|
painCave.isFatal = 1; |
963 |
|
simError(); |
964 |
|
} |
979 |
|
if(eam_eof_test == NULL){ |
980 |
|
sprintf( painCave.errMsg, |
981 |
|
"error in reading EAM file %s at line %d\n", |
982 |
< |
eamPotFile,linenumber); |
982 |
> |
eamPotFile.c_str(), linenumber); |
983 |
|
painCave.isFatal = 1; |
984 |
|
simError(); |
985 |
|
} |
988 |
|
// Value 1 |
989 |
|
if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){ |
990 |
|
sprintf( painCave.errMsg, |
991 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
991 |
> |
"Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() ); |
992 |
|
painCave.isFatal = 1; |
993 |
|
simError(); |
994 |
|
} |
998 |
|
// Value 2 |
999 |
|
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
1000 |
|
sprintf( painCave.errMsg, |
1001 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
1001 |
> |
"Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() ); |
1002 |
|
painCave.isFatal = 1; |
1003 |
|
simError(); |
1004 |
|
} |
1008 |
|
// Value 3 |
1009 |
|
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
1010 |
|
sprintf( painCave.errMsg, |
1011 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
1011 |
> |
"Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() ); |
1012 |
|
painCave.isFatal = 1; |
1013 |
|
simError(); |
1014 |
|
} |
1018 |
|
// Value 4 |
1019 |
|
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
1020 |
|
sprintf( painCave.errMsg, |
1021 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
1021 |
> |
"Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() ); |
1022 |
|
painCave.isFatal = 1; |
1023 |
|
simError(); |
1024 |
|
} |
1028 |
|
// Value 5 |
1029 |
|
if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){ |
1030 |
|
sprintf( painCave.errMsg, |
1031 |
< |
"Error parsing EAM nrho: line in %s\n", eamPotFile ); |
1031 |
> |
"Error parsing EAM nrho: line in %s\n", eamPotFile.c_str() ); |
1032 |
|
painCave.isFatal = 1; |
1033 |
|
simError(); |
1034 |
|
} |