diff --git a/src/USER-REAXC/reaxc_ffield.cpp b/src/USER-REAXC/reaxc_ffield.cpp index bd75498a42..197a2252a1 100644 --- a/src/USER-REAXC/reaxc_ffield.cpp +++ b/src/USER-REAXC/reaxc_ffield.cpp @@ -45,7 +45,7 @@ char Read_Force_Field( char *ffield_file, reax_interaction *reax, comm = MPI_COMM_WORLD; /* open force field file */ - if ( (fp = fopen( ffield_file, "r" ) ) == NULL ) { + if ( (fp = lmp_open_potential( ffield_file ) ) == NULL ) { fprintf( stderr, "error opening the force field file! terminating...\n" ); MPI_Abort( comm, FILE_NOT_FOUND ); } diff --git a/src/USER-REAXC/reaxc_tool_box.cpp b/src/USER-REAXC/reaxc_tool_box.cpp index 503d980ffa..92043174e9 100644 --- a/src/USER-REAXC/reaxc_tool_box.cpp +++ b/src/USER-REAXC/reaxc_tool_box.cpp @@ -238,3 +238,76 @@ void sfree( void *ptr, const char *name ) free( ptr ); 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 d7784fc0d3..1c65d362d1 100644 --- a/src/USER-REAXC/reaxc_tool_box.h +++ b/src/USER-REAXC/reaxc_tool_box.h @@ -64,5 +64,5 @@ 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 diff --git a/src/fix_nh.cpp b/src/fix_nh.cpp index a78a109396..795bd3ee5b 100644 --- a/src/fix_nh.cpp +++ b/src/fix_nh.cpp @@ -836,12 +836,13 @@ void FixNH::final_integrate() nve_v(); // re-compute temp before nh_v_press() - // only needed for temperature computes with BIAS: + // only needed for temperature computes with BIAS on reneighboring steps: // b/c some biases store per-atom values (e.g. temp/profile) // per-atom values are invalid if reneigh/comm occurred // since temp->compute() in initial_integrate() - if (which == BIAS) t_current = temperature->compute_scalar(); + if (which == BIAS && neighbor->ago == 0) + t_current = temperature->compute_scalar(); if (pstat_flag) nh_v_press();