diff --git a/src/USER-REAXC/pair_reax_c.cpp b/src/USER-REAXC/pair_reax_c.cpp index 277d31ccf1d90777b1141edd46598b42e42fd7a2..5f49d3b02bc2c812f0033302d87113b3b5d2a5dc 100644 --- a/src/USER-REAXC/pair_reax_c.cpp +++ b/src/USER-REAXC/pair_reax_c.cpp @@ -279,7 +279,16 @@ void PairReaxC::coeff( int nargs, char **args ) // read ffield file - Read_Force_Field(args[2], &(system->reax_param), control); + char *file = args[2]; + FILE *fp; + fp = force->open_potential(file); + if (fp != NULL) + Read_Force_Field(fp, &(system->reax_param), control); + else if (comm->me == 0) { + char str[128]; + sprintf(str,"Cannot open ReaxFF potential file %s",file); + error->one(FLERR,str); + } // read args that map atom types to elements in potential file // map[i] = which element the Ith atom type is, -1 if NULL diff --git a/src/USER-REAXC/reaxc_ffield.cpp b/src/USER-REAXC/reaxc_ffield.cpp index 197a2252a1096ac8d85f8b6a88793da40e056f45..0292e76320d1dadc45a9cae45208d3c974d1f8fc 100644 --- a/src/USER-REAXC/reaxc_ffield.cpp +++ b/src/USER-REAXC/reaxc_ffield.cpp @@ -29,10 +29,9 @@ #include "reaxc_ffield.h" #include "reaxc_tool_box.h" -char Read_Force_Field( char *ffield_file, reax_interaction *reax, +char Read_Force_Field( FILE *fp, reax_interaction *reax, control_params *control ) { - FILE *fp; char *s; char **tmp; char ****tor_flag; @@ -44,18 +43,11 @@ char Read_Force_Field( char *ffield_file, reax_interaction *reax, comm = MPI_COMM_WORLD; - /* open force field file */ - if ( (fp = lmp_open_potential( ffield_file ) ) == NULL ) { - fprintf( stderr, "error opening the force field file! terminating...\n" ); - MPI_Abort( comm, FILE_NOT_FOUND ); - } - s = (char*) malloc(sizeof(char)*MAX_LINE); tmp = (char**) malloc(sizeof(char*)*MAX_TOKENS); for (i=0; i < MAX_TOKENS; i++) tmp[i] = (char*) malloc(sizeof(char)*MAX_TOKEN_LEN); - /* reading first header comment */ fgets( s, MAX_LINE, fp ); diff --git a/src/USER-REAXC/reaxc_ffield.h b/src/USER-REAXC/reaxc_ffield.h index 6ccc94d7d08e70f20415e8de14ac0ff89c4aaeb3..7cef730f91f26ece468fff9e551df9ca04e9bcfd 100644 --- a/src/USER-REAXC/reaxc_ffield.h +++ b/src/USER-REAXC/reaxc_ffield.h @@ -29,6 +29,6 @@ #include "reaxc_types.h" -char Read_Force_Field( char*, reax_interaction*, control_params* ); +char Read_Force_Field( FILE*, reax_interaction*, control_params* ); #endif diff --git a/src/USER-REAXC/reaxc_tool_box.cpp b/src/USER-REAXC/reaxc_tool_box.cpp index 92043174e906c2e246ab6472806025b3b7b9da3b..84a654fecfb650a970a44ee866e88b7bca51a250 100644 --- a/src/USER-REAXC/reaxc_tool_box.cpp +++ b/src/USER-REAXC/reaxc_tool_box.cpp @@ -239,75 +239,3 @@ void sfree( void *ptr, const char *name ) ptr = NULL; } -/* ---------------------------------------------------------------------- - strip off leading part of path, return just the filename -------------------------------------------------------------------------- */ - -static const char *potname(const char *path) -{ - const char *pot; - - if (path == NULL) return NULL; - -#if defined(_WIN32) - // skip over the disk drive part of windows pathnames - if (isalpha(path[0]) && path[1] == ':') - path += 2; -#endif - - for (pot = path; *path != '\0'; ++path) { -#if defined(_WIN32) - if ((*path == '\\') || (*path == '/')) pot = path + 1; -#else - if (*path == '/') pot = path + 1; -#endif - } - - return pot; -} - -/* ---------------------------------------------------------------------- - open a potential file as specified by name; failing that, - search in dir specified by env variable LAMMPS_POTENTIALS -------------------------------------------------------------------------- */ - -FILE *lmp_open_potential(const char *name) -{ - FILE *fp; - - if (name == NULL) return NULL; - - // attempt to open file directly - // if successful, return ptr - - fp = fopen(name,"r"); - if (fp) return fp; - - // try the environment variable directory - - const char *path = getenv("LAMMPS_POTENTIALS"); - if (path == NULL) return NULL; - - const char *pot = potname(name); - if (pot == NULL) return NULL; - - size_t len1 = strlen(path); - size_t len2 = strlen(pot); - char *newpath = new char[len1+len2+2]; - - strcpy(newpath,path); -#if defined(_WIN32) - newpath[len1] = '\\'; - newpath[len1+1] = 0; -#else - newpath[len1] = '/'; - newpath[len1+1] = 0; -#endif - strcat(newpath,pot); - - fp = fopen(newpath,"r"); - delete[] newpath; - return fp; -} - - diff --git a/src/USER-REAXC/reaxc_tool_box.h b/src/USER-REAXC/reaxc_tool_box.h index 1c65d362d1704926c52a890bd83562e4043aaade..e45b07d000239a5d4962865c4bc80f09b5d8b59e 100644 --- a/src/USER-REAXC/reaxc_tool_box.h +++ b/src/USER-REAXC/reaxc_tool_box.h @@ -64,5 +64,4 @@ int Tokenize( char*, char*** ); void *smalloc( long, const char*, MPI_Comm ); void *scalloc( int, int, const char*, MPI_Comm ); void sfree( void*, const char* ); -FILE *lmp_open_potential(const char *); #endif