diff --git a/src/MANYBODY/pair_adp.cpp b/src/MANYBODY/pair_adp.cpp index 203bf0d1ce..0c06cc06eb 100644 --- a/src/MANYBODY/pair_adp.cpp +++ b/src/MANYBODY/pair_adp.cpp @@ -547,7 +547,7 @@ void PairADP::read_file(char *filename) char line[MAXLINE]; if (me == 0) { - fp = open_potential(filename); + fp = force->open_potential(filename); if (fp == NULL) { char str[128]; sprintf(str,"Cannot open ADP potential file %s",filename); diff --git a/src/MANYBODY/pair_airebo.cpp b/src/MANYBODY/pair_airebo.cpp index 033d3e36f1..febc3cb308 100644 --- a/src/MANYBODY/pair_airebo.cpp +++ b/src/MANYBODY/pair_airebo.cpp @@ -3327,7 +3327,7 @@ void PairAIREBO::read_file(char *filename) // read file on proc 0 if (me == 0) { - FILE *fp = open_potential(filename); + FILE *fp = force->open_potential(filename); if (fp == NULL) { char str[128]; sprintf(str,"Cannot open AIREBO potential file %s",filename); diff --git a/src/MANYBODY/pair_bop.cpp b/src/MANYBODY/pair_bop.cpp index e9f43113a2..6bfabaf3e0 100644 --- a/src/MANYBODY/pair_bop.cpp +++ b/src/MANYBODY/pair_bop.cpp @@ -8204,7 +8204,7 @@ void PairBOP::read_file(char *filename) rcore=0.1; if (me == 0) { - FILE *fp = open_potential(filename); + FILE *fp = force->open_potential(filename); if (fp == NULL) { char str[128]; sprintf(str,"Cannot open BOP potential file %s",filename); @@ -8264,7 +8264,7 @@ void PairBOP::read_file(char *filename) if (me == 0) { words = new char*[bop_types]; for(i=0;iopen_potential(filename); if (fp == NULL) { char str[128]; sprintf(str,"Cannot open BOP potential file %s",filename); @@ -8428,7 +8428,7 @@ void PairBOP::read_table(char *filename) MPI_Comm_rank(world,&me); if (me == 0) { - FILE *fp = open_potential(filename); + FILE *fp = force->open_potential(filename); if (fp == NULL) { char str[128]; sprintf(str,"Cannot open BOP potential file %s",filename); @@ -8477,7 +8477,7 @@ void PairBOP::read_table(char *filename) allocate(); if (me == 0) { - FILE *fp = open_potential(filename); + FILE *fp = force->open_potential(filename); if (fp == NULL) { char str[128]; sprintf(str,"Cannot open BOP potential file %s",filename); diff --git a/src/MANYBODY/pair_comb.cpp b/src/MANYBODY/pair_comb.cpp index 7c18ccd3fc..7632afa172 100644 --- a/src/MANYBODY/pair_comb.cpp +++ b/src/MANYBODY/pair_comb.cpp @@ -592,7 +592,7 @@ void PairComb::read_file(char *file) FILE *fp; if (comm->me == 0) { - fp = open_potential(file); + fp = force->open_potential(file); if (fp == NULL) { char str[128]; sprintf(str,"Cannot open COMB potential file %s",file); diff --git a/src/MANYBODY/pair_comb3.cpp b/src/MANYBODY/pair_comb3.cpp index bd4b5b0c9b..eebf9fee45 100644 --- a/src/MANYBODY/pair_comb3.cpp +++ b/src/MANYBODY/pair_comb3.cpp @@ -318,9 +318,9 @@ void PairComb3::read_lib() MPI_Comm_rank(world,&comm->me); // open libraray file on proc 0 - + if(comm->me == 0) { - FILE *fp = open_potential("lib.comb3"); + FILE *fp = force->open_potential("lib.comb3"); if (fp == NULL) { char str[128]; sprintf(str,"Cannot open COMB3 C library file \n"); diff --git a/src/MANYBODY/pair_eam.cpp b/src/MANYBODY/pair_eam.cpp index b9d21423c8..9a86a14c12 100644 --- a/src/MANYBODY/pair_eam.cpp +++ b/src/MANYBODY/pair_eam.cpp @@ -439,7 +439,7 @@ void PairEAM::read_file(char *filename) char line[MAXLINE]; if (me == 0) { - fptr = open_potential(filename); + fptr = force->open_potential(filename); if (fptr == NULL) { char str[128]; sprintf(str,"Cannot open EAM potential file %s",filename); diff --git a/src/MANYBODY/pair_eam_alloy.cpp b/src/MANYBODY/pair_eam_alloy.cpp index c8abf116a0..cdb7d54ecb 100644 --- a/src/MANYBODY/pair_eam_alloy.cpp +++ b/src/MANYBODY/pair_eam_alloy.cpp @@ -21,6 +21,7 @@ #include "pair_eam_alloy.h" #include "atom.h" #include "comm.h" +#include "force.h" #include "memory.h" #include "error.h" @@ -122,7 +123,7 @@ void PairEAMAlloy::read_file(char *filename) char line[MAXLINE]; if (me == 0) { - fptr = open_potential(filename); + fptr = force->open_potential(filename); if (fptr == NULL) { char str[128]; sprintf(str,"Cannot open EAM potential file %s",filename); diff --git a/src/MANYBODY/pair_eam_fs.cpp b/src/MANYBODY/pair_eam_fs.cpp index 0d6fc2110f..894c9d89a6 100644 --- a/src/MANYBODY/pair_eam_fs.cpp +++ b/src/MANYBODY/pair_eam_fs.cpp @@ -21,6 +21,7 @@ #include "pair_eam_fs.h" #include "atom.h" #include "comm.h" +#include "force.h" #include "memory.h" #include "error.h" @@ -122,7 +123,7 @@ void PairEAMFS::read_file(char *filename) char line[MAXLINE]; if (me == 0) { - fptr = open_potential(filename); + fptr = force->open_potential(filename); if (fptr == NULL) { char str[128]; sprintf(str,"Cannot open EAM potential file %s",filename); diff --git a/src/MANYBODY/pair_eim.cpp b/src/MANYBODY/pair_eim.cpp index f271bb0030..6f9be6fac1 100644 --- a/src/MANYBODY/pair_eim.cpp +++ b/src/MANYBODY/pair_eim.cpp @@ -457,7 +457,7 @@ void PairEIM::read_file(char *filename) FILE *fptr; if (me == 0) { - fptr = open_potential(filename); + fptr = force->open_potential(filename); if (fptr == NULL) { char str[128]; sprintf(str,"Cannot open EIM potential file %s",filename); diff --git a/src/MANYBODY/pair_lcbop.cpp b/src/MANYBODY/pair_lcbop.cpp index 8ccb7ee8aa..f6b35d9717 100644 --- a/src/MANYBODY/pair_lcbop.cpp +++ b/src/MANYBODY/pair_lcbop.cpp @@ -975,7 +975,7 @@ void PairLCBOP::read_file(char *filename) // read file on proc 0 if (me == 0) { - FILE *fp = open_potential(filename); + FILE *fp = force->open_potential(filename); if (fp == NULL) { char str[128]; sprintf(str,"Cannot open LCBOP potential file %s",filename); diff --git a/src/MANYBODY/pair_nb3b_harmonic.cpp b/src/MANYBODY/pair_nb3b_harmonic.cpp index 0f7b787924..b3512f5087 100644 --- a/src/MANYBODY/pair_nb3b_harmonic.cpp +++ b/src/MANYBODY/pair_nb3b_harmonic.cpp @@ -327,7 +327,7 @@ void PairNb3bHarmonic::read_file(char *file) FILE *fp = NULL; if (comm->me == 0) { - fp = open_potential(file); + fp = force->open_potential(file); if (fp == NULL) { char str[128]; sprintf(str,"Cannot open nb3b/harmonic potential file %s",file); diff --git a/src/MANYBODY/pair_sw.cpp b/src/MANYBODY/pair_sw.cpp index 3928ff0d0b..00c8461c01 100755 --- a/src/MANYBODY/pair_sw.cpp +++ b/src/MANYBODY/pair_sw.cpp @@ -337,7 +337,7 @@ void PairSW::read_file(char *file) FILE *fp; if (comm->me == 0) { - fp = open_potential(file); + fp = force->open_potential(file); if (fp == NULL) { char str[128]; sprintf(str,"Cannot open Stillinger-Weber potential file %s",file); diff --git a/src/MANYBODY/pair_tersoff.cpp b/src/MANYBODY/pair_tersoff.cpp index fe02371fec..be85d2e634 100755 --- a/src/MANYBODY/pair_tersoff.cpp +++ b/src/MANYBODY/pair_tersoff.cpp @@ -377,7 +377,7 @@ void PairTersoff::read_file(char *file) FILE *fp; if (comm->me == 0) { - fp = open_potential(file); + fp = force->open_potential(file); if (fp == NULL) { char str[128]; sprintf(str,"Cannot open Tersoff potential file %s",file); diff --git a/src/MANYBODY/pair_tersoff_mod.cpp b/src/MANYBODY/pair_tersoff_mod.cpp index b452be0fa9..b19c843a16 100644 --- a/src/MANYBODY/pair_tersoff_mod.cpp +++ b/src/MANYBODY/pair_tersoff_mod.cpp @@ -57,7 +57,7 @@ void PairTersoffMOD::read_file(char *file) FILE *fp; if (comm->me == 0) { - fp = open_potential(file); + fp = force->open_potential(file); if (fp == NULL) { char str[128]; sprintf(str,"Cannot open Tersoff potential file %s",file); diff --git a/src/MANYBODY/pair_tersoff_zbl.cpp b/src/MANYBODY/pair_tersoff_zbl.cpp index a1624cd659..2d55e11517 100644 --- a/src/MANYBODY/pair_tersoff_zbl.cpp +++ b/src/MANYBODY/pair_tersoff_zbl.cpp @@ -74,7 +74,7 @@ void PairTersoffZBL::read_file(char *file) FILE *fp; if (comm->me == 0) { - fp = open_potential(file); + fp = force->open_potential(file); if (fp == NULL) { char str[128]; sprintf(str,"Cannot open Tersoff potential file %s",file); diff --git a/src/MEAM/pair_meam.cpp b/src/MEAM/pair_meam.cpp index 291af44d8f..ab883d4c75 100644 --- a/src/MEAM/pair_meam.cpp +++ b/src/MEAM/pair_meam.cpp @@ -460,7 +460,7 @@ void PairMEAM::read_files(char *globalfile, char *userfile) FILE *fp; if (comm->me == 0) { - fp = open_potential(globalfile); + fp = force->open_potential(globalfile); if (fp == NULL) { char str[128]; sprintf(str,"Cannot open MEAM potential file %s",globalfile); @@ -641,7 +641,7 @@ void PairMEAM::read_files(char *globalfile, char *userfile) // open user param file on proc 0 if (comm->me == 0) { - fp = open_potential(userfile); + fp = force->open_potential(userfile); if (fp == NULL) { char str[128]; sprintf(str,"Cannot open MEAM potential file %s",userfile); diff --git a/src/MOLECULE/angle_table.cpp b/src/MOLECULE/angle_table.cpp index ca8b6c3e73..682ee4f8ae 100644 --- a/src/MOLECULE/angle_table.cpp +++ b/src/MOLECULE/angle_table.cpp @@ -366,7 +366,7 @@ void AngleTable::read_table(Table *tb, char *file, char *keyword) // open file - FILE *fp = fopen(file,"r"); + FILE *fp = force->open_potential(file); if (fp == NULL) { char str[128]; sprintf(str,"Cannot open file %s",file); diff --git a/src/MOLECULE/bond_table.cpp b/src/MOLECULE/bond_table.cpp index 80b040254b..cdccf6ee91 100644 --- a/src/MOLECULE/bond_table.cpp +++ b/src/MOLECULE/bond_table.cpp @@ -292,7 +292,7 @@ void BondTable::read_table(Table *tb, char *file, char *keyword) // open file - FILE *fp = fopen(file,"r"); + FILE *fp = force->open_potential(file); if (fp == NULL) { char str[128]; sprintf(str,"Cannot open file %s",file); diff --git a/src/USER-MISC/dihedral_table.cpp b/src/USER-MISC/dihedral_table.cpp index ce5d851ca3..5d7163cb53 100644 --- a/src/USER-MISC/dihedral_table.cpp +++ b/src/USER-MISC/dihedral_table.cpp @@ -1011,7 +1011,7 @@ void DihedralTable::read_table(Table *tb, char *file, char *keyword) // open file - FILE *fp = fopen(file,"r"); + FILE *fp = force->open_potential(file); if (fp == NULL) { string err_msg = string("Cannot open file ") + string(file); error->one(FLERR,err_msg.c_str()); diff --git a/src/USER-MISC/pair_cdeam.cpp b/src/USER-MISC/pair_cdeam.cpp index 5edab54d89..b3ce1b18f4 100644 --- a/src/USER-MISC/pair_cdeam.cpp +++ b/src/USER-MISC/pair_cdeam.cpp @@ -461,7 +461,7 @@ void PairCDEAM::read_h_coeff(char *filename) FILE *fp; char line[MAXLINE]; char nextline[MAXLINE]; - fp = open_potential(filename); + fp = force->open_potential(filename); if (fp == NULL) { char str[128]; sprintf(str,"Cannot open EAM potential file %s", filename); diff --git a/src/USER-MISC/pair_edip.cpp b/src/USER-MISC/pair_edip.cpp index 4c236649a2..bb4d67015b 100755 --- a/src/USER-MISC/pair_edip.cpp +++ b/src/USER-MISC/pair_edip.cpp @@ -877,7 +877,7 @@ void PairEDIP::read_file(char *file) FILE *fp; if (comm->me == 0) { - fp = open_potential(file); + fp = force->open_potential(file); if (fp == NULL) { char str[128]; sprintf(str,"Cannot open EDIP potential file %s",file); diff --git a/src/USER-MISC/pair_list.cpp b/src/USER-MISC/pair_list.cpp index 83b8c209ec..880cab6c31 100644 --- a/src/USER-MISC/pair_list.cpp +++ b/src/USER-MISC/pair_list.cpp @@ -218,7 +218,7 @@ void PairList::settings(int narg, char **arg) if (strcmp(arg[2],"check") == 0) check_flag = 1; } - FILE *fp = open_potential(arg[0]); + FILE *fp = force->open_potential(arg[0]); char line[1024]; if (fp == NULL) error->all(FLERR,"Cannot open pair list file"); diff --git a/src/USER-MISC/pair_meam_spline.cpp b/src/USER-MISC/pair_meam_spline.cpp index c0260ab6f2..8af973c861 100644 --- a/src/USER-MISC/pair_meam_spline.cpp +++ b/src/USER-MISC/pair_meam_spline.cpp @@ -434,7 +434,7 @@ void PairMEAMSpline::coeff(int narg, char **arg) void PairMEAMSpline::read_file(const char* filename) { if(comm->me == 0) { - FILE *fp = open_potential(filename); + FILE *fp = force->open_potential(filename); if(fp == NULL) { char str[1024]; sprintf(str,"Cannot open spline MEAM potential file %s", filename); diff --git a/src/USER-MISC/pair_meam_sw_spline.cpp b/src/USER-MISC/pair_meam_sw_spline.cpp index fe13170e2d..f23d52e3f1 100644 --- a/src/USER-MISC/pair_meam_sw_spline.cpp +++ b/src/USER-MISC/pair_meam_sw_spline.cpp @@ -463,7 +463,7 @@ void PairMEAMSWSpline::coeff(int narg, char **arg) void PairMEAMSWSpline::read_file(const char* filename) { if(comm->me == 0) { - FILE *fp = open_potential(filename); + FILE *fp = force->open_potential(filename); if(fp == NULL) { char str[1024]; sprintf(str,"Cannot open spline MEAM potential file %s", filename); diff --git a/src/USER-MISC/pair_tersoff_table.cpp b/src/USER-MISC/pair_tersoff_table.cpp index 60673b8e43..0ac7cf06c4 100644 --- a/src/USER-MISC/pair_tersoff_table.cpp +++ b/src/USER-MISC/pair_tersoff_table.cpp @@ -851,7 +851,7 @@ void PairTersoffTable::read_file(char *file) FILE *fp; if (comm->me == 0) { - fp = open_potential(file); + fp = force->open_potential(file); if (fp == NULL) { char str[128]; sprintf(str,"Cannot open Tersoff potential file %s",file); diff --git a/src/USER-OMP/pair_eam_alloy_omp.cpp b/src/USER-OMP/pair_eam_alloy_omp.cpp index d2aa9b855f..03e6a1058f 100644 --- a/src/USER-OMP/pair_eam_alloy_omp.cpp +++ b/src/USER-OMP/pair_eam_alloy_omp.cpp @@ -21,6 +21,7 @@ #include "pair_eam_alloy_omp.h" #include "atom.h" #include "comm.h" +#include "force.h" #include "memory.h" #include "error.h" @@ -121,7 +122,7 @@ void PairEAMAlloyOMP::read_file(char *filename) char line[MAXLINE]; if (me == 0) { - fptr = open_potential(filename); + fptr = force->open_potential(filename); if (fptr == NULL) { char str[128]; sprintf(str,"Cannot open EAM potential file %s",filename); diff --git a/src/USER-OMP/pair_eam_fs_omp.cpp b/src/USER-OMP/pair_eam_fs_omp.cpp index 63b990d650..fc22bde3ce 100644 --- a/src/USER-OMP/pair_eam_fs_omp.cpp +++ b/src/USER-OMP/pair_eam_fs_omp.cpp @@ -21,6 +21,7 @@ #include "pair_eam_fs_omp.h" #include "atom.h" #include "comm.h" +#include "force.h" #include "memory.h" #include "error.h" @@ -121,7 +122,7 @@ void PairEAMFSOMP::read_file(char *filename) char line[MAXLINE]; if (me == 0) { - fptr = open_potential(filename); + fptr = force->open_potential(filename); if (fptr == NULL) { char str[128]; sprintf(str,"Cannot open EAM potential file %s",filename); diff --git a/src/force.cpp b/src/force.cpp index d486493c92..04dea56633 100644 --- a/src/force.cpp +++ b/src/force.cpp @@ -780,6 +780,77 @@ bigint Force::bnumeric(const char *file, int line, char *str) return ATOLL(str); } +/* ---------------------------------------------------------------------- + open a potential file as specified by name; failing that, + search in dir specified by env variable LAMMPS_POTENTIALS +------------------------------------------------------------------------- */ + +FILE *Force::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; +} + +/* ---------------------------------------------------------------------- + strip off leading part of path, return just the filename +------------------------------------------------------------------------- */ + +const char *Force::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; +} + /* ---------------------------------------------------------------------- memory usage of force classes ------------------------------------------------------------------------- */ diff --git a/src/force.h b/src/force.h index bb6788faf1..bd72567812 100644 --- a/src/force.h +++ b/src/force.h @@ -104,6 +104,10 @@ class Force : protected Pointers { double numeric(const char *, int, char *); int inumeric(const char *, int, char *); bigint bnumeric(const char *, int, char *); + + FILE *open_potential(const char *); + const char *potname(const char *); + bigint memory_usage(); private: diff --git a/src/pair.cpp b/src/pair.cpp index 8d21f9143a..c9f01d86b8 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -1624,77 +1624,6 @@ void Pair::init_bitmap(double inner, double outer, int ntablebits, masklo = rsq_lookup.i & ~(nmask); } -/* ---------------------------------------------------------------------- - open a potential file as specified by name - failing that, search in dir specified by env variable LAMMPS_POTENTIALS -------------------------------------------------------------------------- */ - -FILE *Pair::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; -} - -/* ---------------------------------------------------------------------- - strip off leading part of path, return just the filename -------------------------------------------------------------------------- */ - -const char *Pair::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; -} - /* ---------------------------------------------------------------------- */ double Pair::memory_usage() diff --git a/src/pair.h b/src/pair.h index 9f6c21019c..399b46ad2c 100644 --- a/src/pair.h +++ b/src/pair.h @@ -213,9 +213,6 @@ class Pair : protected Pointers { double, double, double, double, double, double); void virial_fdotr_compute(); - FILE *open_potential(const char *); - const char *potname(const char *); - inline int sbmask(int j) { return j >> SBBITS & 3; } diff --git a/src/pair_table.cpp b/src/pair_table.cpp index f12271a03a..4c637b2d1f 100644 --- a/src/pair_table.cpp +++ b/src/pair_table.cpp @@ -343,7 +343,7 @@ void PairTable::read_table(Table *tb, char *file, char *keyword) // open file - FILE *fp = open_potential(file); + FILE *fp = force->open_potential(file); if (fp == NULL) { char str[128]; sprintf(str,"Cannot open file %s",file);