move Force::open_potential() to utils::open_potential()
This commit is contained in:
@ -1723,7 +1723,7 @@ void PairExp6rxKokkos<DeviceType>::read_file(char *file)
|
||||
FILE *fp;
|
||||
fp = NULL;
|
||||
if (comm->me == 0) {
|
||||
fp = force->open_potential(file);
|
||||
fp = utils::open_potential(file,lmp,nullptr);
|
||||
if (fp == NULL) {
|
||||
char str[128];
|
||||
snprintf(str,128,"Cannot open exp6/rx potential file %s",file);
|
||||
|
||||
@ -504,7 +504,7 @@ void PairEAMCD::read_h_coeff(char *filename)
|
||||
char line[MAXLINE];
|
||||
char nextline[MAXLINE];
|
||||
int convert_flag = unit_convert_flag;
|
||||
fptr = force->open_potential(filename, &convert_flag);
|
||||
fptr = utils::open_potential(filename, lmp, &convert_flag);
|
||||
if (fptr == NULL)
|
||||
error->one(FLERR,fmt::format("Cannot open EAMCD potential file {}",
|
||||
filename));
|
||||
|
||||
@ -1061,7 +1061,7 @@ EIMPotentialFileReader::EIMPotentialFileReader(LAMMPS *lmp,
|
||||
}
|
||||
|
||||
int unit_convert = auto_convert;
|
||||
FILE *fp = force->open_potential(filename.c_str(), &unit_convert);
|
||||
FILE *fp = utils::open_potential(filename, lmp, &unit_convert);
|
||||
conversion_factor = utils::get_conversion_factor(utils::ENERGY,unit_convert);
|
||||
|
||||
if (fp == NULL) {
|
||||
|
||||
@ -969,7 +969,7 @@ void PairLCBOP::read_file(char *filename)
|
||||
// read file on proc 0
|
||||
|
||||
if (me == 0) {
|
||||
FILE *fp = force->open_potential(filename);
|
||||
FILE *fp = utils::open_potential(filename,lmp,nullptr);
|
||||
if (fp == NULL) {
|
||||
char str[128];
|
||||
snprintf(str,128,"Cannot open LCBOP potential file %s",filename);
|
||||
|
||||
@ -376,7 +376,7 @@ void MLIAPDescriptorSNAP::read_paramfile(char *paramfilename)
|
||||
|
||||
FILE *fpparam;
|
||||
if (comm->me == 0) {
|
||||
fpparam = force->open_potential(paramfilename);
|
||||
fpparam = utils::open_potential(paramfilename,lmp,nullptr);
|
||||
if (fpparam == NULL)
|
||||
error->one(FLERR,fmt::format("Cannot open SNAP parameter file {}: {}",
|
||||
paramfilename, utils::getsyserror()));
|
||||
|
||||
@ -85,7 +85,7 @@ void MLIAPModel::read_coeffs(char *coefffilename)
|
||||
|
||||
FILE *fpcoeff;
|
||||
if (comm->me == 0) {
|
||||
fpcoeff = force->open_potential(coefffilename);
|
||||
fpcoeff = utils::open_potential(coefffilename,lmp,nullptr);
|
||||
if (fpcoeff == NULL)
|
||||
error->one(FLERR,fmt::format("Cannot open MLIAPModel coeff file {}: {}",
|
||||
coefffilename,utils::getsyserror()));
|
||||
|
||||
@ -633,7 +633,7 @@ void FixCMAP::read_grid_map(char *cmapfile)
|
||||
|
||||
FILE *fp = NULL;
|
||||
if (comm->me == 0) {
|
||||
fp = force->open_potential(cmapfile);
|
||||
fp = utils::open_potential(cmapfile,lmp,nullptr);
|
||||
if (fp == NULL)
|
||||
error->one(FLERR,fmt::format("Cannot open fix cmap file {}: {}",
|
||||
cmapfile, utils::getsyserror()));
|
||||
|
||||
@ -707,7 +707,7 @@ void FixQEq::read_file(char *file)
|
||||
|
||||
FILE *fp;
|
||||
if (comm->me == 0) {
|
||||
fp = force->open_potential(file);
|
||||
fp = utils::open_potential(file,lmp,nullptr);
|
||||
if (fp == NULL) {
|
||||
char str[128];
|
||||
snprintf(str,128,"Cannot open fix qeq parameter file %s",file);
|
||||
|
||||
@ -515,7 +515,7 @@ void PairSNAP::read_files(char *coefffilename, char *paramfilename)
|
||||
|
||||
FILE *fpcoeff;
|
||||
if (comm->me == 0) {
|
||||
fpcoeff = force->open_potential(coefffilename);
|
||||
fpcoeff = utils::open_potential(coefffilename,lmp,nullptr);
|
||||
if (fpcoeff == NULL) {
|
||||
char str[128];
|
||||
snprintf(str,128,"Cannot open SNAP coefficient file %s",coefffilename);
|
||||
@ -662,7 +662,7 @@ void PairSNAP::read_files(char *coefffilename, char *paramfilename)
|
||||
|
||||
FILE *fpparam;
|
||||
if (comm->me == 0) {
|
||||
fpparam = force->open_potential(paramfilename);
|
||||
fpparam = utils::open_potential(paramfilename,lmp,nullptr);
|
||||
if (fpparam == NULL) {
|
||||
char str[128];
|
||||
snprintf(str,128,"Cannot open SNAP parameter file %s",paramfilename);
|
||||
|
||||
@ -199,7 +199,7 @@ void FixEOStable::read_table(Table *tb, Table *tb2, char *file, char *keyword)
|
||||
|
||||
// open file
|
||||
|
||||
FILE *fp = force->open_potential(file);
|
||||
FILE *fp = utils::open_potential(file,lmp,nullptr);
|
||||
if (fp == NULL) {
|
||||
char str[128];
|
||||
snprintf(str,128,"Cannot open file %s",file);
|
||||
|
||||
@ -266,7 +266,7 @@ void FixRX::post_constructor()
|
||||
FILE *fp;
|
||||
fp = NULL;
|
||||
if (comm->me == 0) {
|
||||
fp = force->open_potential(kineticsFile);
|
||||
fp = utils::open_potential(kineticsFile,lmp,nullptr);
|
||||
if (fp == NULL) {
|
||||
char str[128];
|
||||
snprintf(str,128,"Cannot open rx file %s",kineticsFile);
|
||||
@ -855,7 +855,7 @@ void FixRX::read_file(char *file)
|
||||
FILE *fp;
|
||||
fp = NULL;
|
||||
if (comm->me == 0) {
|
||||
fp = force->open_potential(file);
|
||||
fp = utils::open_potential(file,lmp,nullptr);
|
||||
if (fp == NULL) {
|
||||
char str[128];
|
||||
snprintf(str,128,"Cannot open rx file %s",file);
|
||||
@ -892,7 +892,7 @@ void FixRX::read_file(char *file)
|
||||
}
|
||||
|
||||
// open file on proc 0
|
||||
if (comm->me == 0) fp = force->open_potential(file);
|
||||
if (comm->me == 0) fp = utils::open_potential(file,lmp,nullptr);
|
||||
|
||||
// read each reaction from kinetics file
|
||||
eof=0;
|
||||
|
||||
@ -725,7 +725,7 @@ void PairExp6rx::read_file(char *file)
|
||||
FILE *fp;
|
||||
fp = NULL;
|
||||
if (comm->me == 0) {
|
||||
fp = force->open_potential(file);
|
||||
fp = utils::open_potential(file,lmp,nullptr);
|
||||
if (fp == NULL) {
|
||||
char str[128];
|
||||
snprintf(str,128,"Cannot open exp6/rx potential file %s",file);
|
||||
|
||||
@ -493,7 +493,7 @@ void PairMultiLucyRX::read_table(Table *tb, char *file, char *keyword)
|
||||
|
||||
// open file
|
||||
|
||||
FILE *fp = force->open_potential(file);
|
||||
FILE *fp = utils::open_potential(file,lmp,nullptr);
|
||||
if (fp == NULL) {
|
||||
char str[128];
|
||||
snprintf(str,128,"Cannot open file %s",file);
|
||||
|
||||
@ -364,7 +364,7 @@ void PairMEAMC::read_files(const std::string &globalfile,
|
||||
|
||||
FILE *fp;
|
||||
if (comm->me == 0) {
|
||||
fp = force->open_potential(globalfile.c_str());
|
||||
fp = utils::open_potential(globalfile,lmp,nullptr);
|
||||
if (fp == NULL)
|
||||
error->one(FLERR,fmt::format("Cannot open MEAM potential file {}",
|
||||
globalfile));
|
||||
@ -563,7 +563,7 @@ void PairMEAMC::read_files(const std::string &globalfile,
|
||||
// open user param file on proc 0
|
||||
|
||||
if (comm->me == 0) {
|
||||
fp = force->open_potential(userfile.c_str());
|
||||
fp = utils::open_potential(userfile,lmp,nullptr);
|
||||
if (fp == NULL)
|
||||
error->one(FLERR,fmt::format("Cannot open MEAM potential file {}",
|
||||
userfile));
|
||||
|
||||
@ -759,7 +759,7 @@ void PairMesoCNT::read_file()
|
||||
|
||||
// open file
|
||||
|
||||
fp = force->open_potential(file);
|
||||
fp = utils::open_potential(file,lmp,nullptr);
|
||||
if (fp == NULL)
|
||||
error->one(FLERR,fmt::format("Cannot open mesocnt file: {}",file));
|
||||
|
||||
|
||||
@ -1904,8 +1904,8 @@ void PairMGPT::coeff(int narg, char **arg)
|
||||
printf("Volumetric pressure is %s.\n",volpres_flag ? "on" : "off");
|
||||
|
||||
if(comm->me == 0) {
|
||||
FILE *parmin_fp = force->open_potential(arg[2]);
|
||||
FILE *potin_fp = force->open_potential(arg[3]);
|
||||
FILE *parmin_fp = utils::open_potential(arg[2],lmp,nullptr);
|
||||
FILE *potin_fp = utils::open_potential(arg[3],lmp,nullptr);
|
||||
if (parmin_fp == NULL || potin_fp == NULL) {
|
||||
char str[128];
|
||||
sprintf(str,"Cannot open MGPT potential files %s %s",arg[2],arg[3]);
|
||||
|
||||
@ -1078,7 +1078,7 @@ void DihedralTableCut::read_table(Table *tb, char *file, char *keyword)
|
||||
|
||||
// open file
|
||||
|
||||
FILE *fp = force->open_potential(file);
|
||||
FILE *fp = utils::open_potential(file,lmp,nullptr);
|
||||
if (fp == NULL) {
|
||||
string err_msg = string("Cannot open file ") + string(file);
|
||||
error->one(FLERR,err_msg);
|
||||
|
||||
@ -240,7 +240,7 @@ void FixElectronStopping::read_table(const char *file)
|
||||
{
|
||||
char line[MAXLINE];
|
||||
|
||||
FILE *fp = force->open_potential(file);
|
||||
FILE *fp = utils::open_potential(file,lmp,nullptr);
|
||||
if (fp == NULL) {
|
||||
char str[128];
|
||||
snprintf(str, 128, "Cannot open stopping range table %s", file);
|
||||
|
||||
@ -221,7 +221,7 @@ FixGLE::FixGLE(LAMMPS *lmp, int narg, char **arg) :
|
||||
FILE *fgle = NULL;
|
||||
char *fname = arg[7];
|
||||
if (comm->me == 0) {
|
||||
fgle = force->open_potential(fname);
|
||||
fgle = utils::open_potential(fname,lmp,nullptr);
|
||||
if (fgle == NULL) {
|
||||
char str[128];
|
||||
snprintf(str,128,"Cannot open A-matrix file %s",fname);
|
||||
@ -291,7 +291,7 @@ FixGLE::FixGLE(LAMMPS *lmp, int narg, char **arg) :
|
||||
|
||||
} else {
|
||||
if (comm->me == 0) {
|
||||
fgle = force->open_potential(fname);
|
||||
fgle = utils::open_potential(fname,lmp,nullptr);
|
||||
if (fgle == NULL) {
|
||||
char str[128];
|
||||
snprintf(str,128,"Cannot open C-matrix file %s",fname);
|
||||
|
||||
@ -97,7 +97,7 @@ FixOrientECO::FixOrientECO(LAMMPS *lmp, int narg, char **arg) :
|
||||
char *result;
|
||||
int count;
|
||||
|
||||
FILE *infile = force->open_potential(dir_filename);
|
||||
FILE *infile = utils::open_potential(dir_filename,lmp,nullptr);
|
||||
if (infile == NULL)
|
||||
error->one(FLERR,fmt::format("Cannot open fix orient/eco file {}: {}",
|
||||
dir_filename, utils::getsyserror()));
|
||||
|
||||
@ -358,7 +358,7 @@ void PairAGNI::read_file(char *file)
|
||||
|
||||
FILE *fp;
|
||||
if (comm->me == 0) {
|
||||
fp = force->open_potential(file);
|
||||
fp = utils::open_potential(file,lmp,nullptr);
|
||||
if (fp == NULL) {
|
||||
char str[128];
|
||||
snprintf(str,128,"Cannot open AGNI potential file %s",file);
|
||||
|
||||
@ -223,7 +223,7 @@ void PairDRIP::read_file(char *filename)
|
||||
|
||||
FILE *fp;
|
||||
if (comm->me == 0) {
|
||||
fp = force->open_potential(filename);
|
||||
fp = utils::open_potential(filename,lmp,nullptr);
|
||||
if (fp == NULL) {
|
||||
char str[128];
|
||||
snprintf(str,128,"Cannot open DRIP potential file %s",filename);
|
||||
|
||||
@ -883,7 +883,7 @@ void PairEDIP::read_file(char *file)
|
||||
|
||||
FILE *fp;
|
||||
if (comm->me == 0) {
|
||||
fp = force->open_potential(file);
|
||||
fp = utils::open_potential(file,lmp,nullptr);
|
||||
if (fp == NULL) {
|
||||
char str[128];
|
||||
snprintf(str,128,"Cannot open EDIP potential file %s",file);
|
||||
|
||||
@ -640,7 +640,7 @@ void PairEDIPMulti::read_file(char *file)
|
||||
|
||||
FILE *fp;
|
||||
if (comm->me == 0) {
|
||||
fp = force->open_potential(file);
|
||||
fp = utils::open_potential(file,lmp,nullptr);
|
||||
if (fp == NULL) {
|
||||
char str[128];
|
||||
snprintf(str,128,"Cannot open EDIP potential file %s",file);
|
||||
|
||||
@ -589,7 +589,7 @@ void PairExTeP::read_file(char *file)
|
||||
|
||||
FILE *fp;
|
||||
if (comm->me == 0) {
|
||||
fp = force->open_potential(file);
|
||||
fp = utils::open_potential(file,lmp,nullptr);
|
||||
if (fp == NULL) {
|
||||
char str[128];
|
||||
snprintf(str,128,"Cannot open ExTeP potential file %s",file);
|
||||
|
||||
@ -256,7 +256,7 @@ void PairILPGrapheneHBN::read_file(char *filename)
|
||||
|
||||
FILE *fp;
|
||||
if (comm->me == 0) {
|
||||
fp = force->open_potential(filename);
|
||||
fp = utils::open_potential(filename,lmp,nullptr);
|
||||
if (fp == NULL) {
|
||||
char str[128];
|
||||
snprintf(str,128,"Cannot open ILP potential file %s",filename);
|
||||
|
||||
@ -257,7 +257,7 @@ void PairKolmogorovCrespiFull::read_file(char *filename)
|
||||
|
||||
FILE *fp;
|
||||
if (comm->me == 0) {
|
||||
fp = force->open_potential(filename);
|
||||
fp = utils::open_potential(filename,lmp,nullptr);
|
||||
if (fp == NULL) {
|
||||
char str[128];
|
||||
snprintf(str,128,"Cannot open KC potential file %s",filename);
|
||||
|
||||
@ -315,7 +315,7 @@ void PairKolmogorovCrespiZ::read_file(char *filename)
|
||||
|
||||
FILE *fp;
|
||||
if (comm->me == 0) {
|
||||
fp = force->open_potential(filename);
|
||||
fp = utils::open_potential(filename,lmp,nullptr);
|
||||
if (fp == NULL) {
|
||||
char str[128];
|
||||
snprintf(str,128,"Cannot open KC potential file %s",filename);
|
||||
|
||||
@ -311,7 +311,7 @@ void PairLebedevaZ::read_file(char *filename)
|
||||
|
||||
FILE *fp;
|
||||
if (comm->me == 0) {
|
||||
fp = force->open_potential(filename);
|
||||
fp = utils::open_potential(filename,lmp,nullptr);
|
||||
if (fp == NULL) {
|
||||
char str[128];
|
||||
sprintf(str,"Cannot open Lebedeva potential file %s",filename);
|
||||
|
||||
@ -209,7 +209,7 @@ void PairList::settings(int narg, char **arg)
|
||||
if (strcmp(arg[2],"check") == 0) check_flag = 1;
|
||||
}
|
||||
|
||||
FILE *fp = force->open_potential(arg[0]);
|
||||
FILE *fp = utils::open_potential(arg[0],lmp,nullptr);
|
||||
char line[1024];
|
||||
if (fp == NULL)
|
||||
error->all(FLERR,"Cannot open pair list file");
|
||||
|
||||
@ -458,7 +458,7 @@ void PairMEAMSpline::read_file(const char* filename)
|
||||
int nmultichoose2; // = (n+1)*n/2;
|
||||
|
||||
if(comm->me == 0) {
|
||||
FILE *fp = force->open_potential(filename);
|
||||
FILE *fp = utils::open_potential(filename,lmp,nullptr);
|
||||
if(fp == NULL) {
|
||||
char str[1024];
|
||||
snprintf(str,128,"Cannot open spline MEAM potential file %s", filename);
|
||||
|
||||
@ -460,7 +460,7 @@ void PairMEAMSWSpline::coeff(int narg, char **arg)
|
||||
void PairMEAMSWSpline::read_file(const char* filename)
|
||||
{
|
||||
if(comm->me == 0) {
|
||||
FILE *fp = force->open_potential(filename);
|
||||
FILE *fp = utils::open_potential(filename,lmp,nullptr);
|
||||
if(fp == NULL) {
|
||||
char str[1024];
|
||||
snprintf(str,1024,"Cannot open spline MEAM potential file %s", filename);
|
||||
|
||||
@ -317,7 +317,7 @@ void PairReaxC::coeff( int nargs, char **args )
|
||||
|
||||
char *file = args[2];
|
||||
FILE *fp;
|
||||
fp = force->open_potential(file);
|
||||
fp = utils::open_potential(file,lmp,nullptr);
|
||||
if (fp != NULL)
|
||||
Read_Force_Field(fp, &(system->reax_param), control);
|
||||
else {
|
||||
|
||||
@ -410,7 +410,7 @@ void PairSMTBQ::read_file(char *file)
|
||||
|
||||
// open file on all processors
|
||||
FILE *fp;
|
||||
fp = force->open_potential(file);
|
||||
fp = utils::open_potential(file,lmp,nullptr);
|
||||
if ( fp == NULL ) {
|
||||
char str[128];
|
||||
snprintf(str,128,"Cannot open SMTBQ potential file %s",file);
|
||||
|
||||
@ -836,59 +836,6 @@ void Force::set_special(int narg, char **arg)
|
||||
error->all(FLERR,"Illegal special_bonds command");
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
open a potential file as specified by name
|
||||
if fails, search in dir specified by env variable LAMMPS_POTENTIALS
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
FILE *Force::open_potential(const char *name, int *auto_convert)
|
||||
{
|
||||
std::string filepath = utils::get_potential_file_path(name);
|
||||
|
||||
if(!filepath.empty()) {
|
||||
std::string unit_style = update->unit_style;
|
||||
std::string date = utils::get_potential_date(filepath, "potential");
|
||||
std::string units = utils::get_potential_units(filepath, "potential");
|
||||
|
||||
if(!date.empty() && (comm->me == 0)) {
|
||||
utils::logmesg(lmp, fmt::format("Reading potential file {} "
|
||||
"with DATE: {}\n", name, date));
|
||||
}
|
||||
|
||||
if (auto_convert == nullptr) {
|
||||
if (!units.empty() && (units != unit_style) && (comm->me == 0)) {
|
||||
error->one(FLERR, fmt::format("Potential file {} requires {} units "
|
||||
"but {} units are in use", name, units,
|
||||
unit_style));
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
if (units.empty() || units == unit_style) {
|
||||
*auto_convert = utils::NOCONVERT;
|
||||
} else {
|
||||
if ((units == "metal") && (unit_style == "real")
|
||||
&& (*auto_convert & utils::METAL2REAL)) {
|
||||
*auto_convert = utils::METAL2REAL;
|
||||
} else if ((units == "real") && (unit_style == "metal")
|
||||
&& (*auto_convert & utils::REAL2METAL)) {
|
||||
*auto_convert = utils::REAL2METAL;
|
||||
} else {
|
||||
error->one(FLERR, fmt::format("Potential file {} requires {} units "
|
||||
"but {} units are in use", name,
|
||||
units, unit_style));
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
if ((*auto_convert != utils::NOCONVERT) && (comm->me == 0))
|
||||
lmp->error->warning(FLERR, fmt::format("Converting potential file in "
|
||||
"{} units to {} units",
|
||||
units, unit_style));
|
||||
}
|
||||
return fopen(filepath.c_str(), "r");
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
memory usage of force classes
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
@ -129,8 +129,6 @@ class Force : protected Pointers {
|
||||
void store_style(char *&, const std::string &, int);
|
||||
void set_special(int, char **);
|
||||
|
||||
FILE *open_potential(const char *, int *auto_convert = nullptr);
|
||||
|
||||
bigint memory_usage();
|
||||
|
||||
private:
|
||||
|
||||
@ -939,7 +939,8 @@ double utils::get_conversion_factor(const int property, const int conversion)
|
||||
if fails, search in dir specified by env variable LAMMPS_POTENTIALS
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
FILE *utils::open_potential(const char *name, LAMMPS *lmp, int *auto_convert)
|
||||
FILE *utils::open_potential(const std::string &name, LAMMPS *lmp,
|
||||
int *auto_convert)
|
||||
{
|
||||
auto error = lmp->error;
|
||||
auto me = lmp->comm->me;
|
||||
|
||||
@ -382,8 +382,7 @@ value is compared to the current :doc:`unit style <units>` setting.
|
||||
* \param auto_convert pointer to automatic unit conversion bitmask
|
||||
* \return FILE pointer of the opened potential file or NULL
|
||||
*/
|
||||
FILE *open_potential(const char *name, LAMMPS *lmp,
|
||||
int *auto_convert=nullptr);
|
||||
FILE *open_potential(const std::string &name, LAMMPS *lmp, int *auto_convert);
|
||||
|
||||
/** Convert a time string to seconds
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user