type label support for pair_write

This commit is contained in:
Jacob Gissinger
2024-08-06 23:51:49 -04:00
parent 3833309725
commit c4510ba1ed
2 changed files with 22 additions and 20 deletions

View File

@ -10,7 +10,7 @@ Syntax
pair_write itype jtype N style inner outer file keyword Qi Qj pair_write itype jtype N style inner outer file keyword Qi Qj
* itype,jtype = 2 atom types * itype,jtype = 2 atom types (numeric or type label)
* N = # of values * N = # of values
* style = *r* or *rsq* or *bitmap* * style = *r* or *rsq* or *bitmap*
* inner,outer = inner and outer cutoff (distance units) * inner,outer = inner and outer cutoff (distance units)
@ -26,6 +26,9 @@ Examples
pair_write 1 3 500 r 1.0 10.0 table.txt LJ pair_write 1 3 500 r 1.0 10.0 table.txt LJ
pair_write 1 1 1000 rsq 2.0 8.0 table.txt Yukawa_1_1 -0.5 0.5 pair_write 1 1 1000 rsq 2.0 8.0 table.txt Yukawa_1_1 -0.5 0.5
labelmap atom 1 C 2 H
pair_write C H 500 r 1.0 10.0 table.txt LJ
Description Description
""""""""""" """""""""""
@ -42,7 +45,7 @@ compared against the entry in the file, if present, and pair_write
will refuse to add a table if the units are not the same. will refuse to add a table if the units are not the same.
The energy and force values are computed at distances from inner to The energy and force values are computed at distances from inner to
outer for 2 interacting atoms of type itype and jtype, using the outer for 2 interacting atoms of type *itype* and *jtype*, using the
appropriate :doc:`pair_coeff <pair_coeff>` coefficients. If the style appropriate :doc:`pair_coeff <pair_coeff>` coefficients. If the style
is *r*, then N distances are used, evenly spaced in r; if the style is is *r*, then N distances are used, evenly spaced in r; if the style is
*rsq*, N distances are used, evenly spaced in r\^2. *rsq*, N distances are used, evenly spaced in r\^2.

View File

@ -1794,8 +1794,8 @@ void Pair::write_file(int narg, char **arg)
// parse arguments // parse arguments
int itype = utils::inumeric(FLERR,arg[0],false,lmp); int itype = utils::expand_type_int(FLERR, arg[0], Atom::ATOM, lmp);
int jtype = utils::inumeric(FLERR,arg[1],false,lmp); int jtype = utils::expand_type_int(FLERR, arg[1], Atom::ATOM, lmp);
if (itype < 1 || itype > atom->ntypes || jtype < 1 || jtype > atom->ntypes) if (itype < 1 || itype > atom->ntypes || jtype < 1 || jtype > atom->ntypes)
error->all(FLERR,"Invalid atom types in pair_write command"); error->all(FLERR,"Invalid atom types in pair_write command");
@ -1809,8 +1809,8 @@ void Pair::write_file(int narg, char **arg)
if (n < 2) error->all(FLERR, "Must have at least 2 table values"); if (n < 2) error->all(FLERR, "Must have at least 2 table values");
double inner = utils::numeric(FLERR,arg[4],false,lmp); double inner = utils::numeric(FLERR, arg[4], false, lmp);
double outer = utils::numeric(FLERR,arg[5],false,lmp); double outer = utils::numeric(FLERR, arg[5], false, lmp);
if (inner <= 0.0 || inner >= outer) if (inner <= 0.0 || inner >= outer)
error->all(FLERR,"Invalid cutoffs in pair_write command"); error->all(FLERR,"Invalid cutoffs in pair_write command");
@ -1828,13 +1828,13 @@ void Pair::write_file(int narg, char **arg)
// - if the file already exists, print a message about appending // - if the file already exists, print a message about appending
// while printing the date and check that units are consistent. // while printing the date and check that units are consistent.
if (platform::file_is_readable(table_file)) { if (platform::file_is_readable(table_file)) {
std::string units = utils::get_potential_units(table_file,"table"); std::string units = utils::get_potential_units(table_file, "table");
if (!units.empty() && (units != update->unit_style)) { if (!units.empty() && (units != update->unit_style)) {
error->one(FLERR,"Trying to append to a table file " error->one(FLERR,"Trying to append to a table file "
"with UNITS: {} while units are {}", "with UNITS: {} while units are {}",
units, update->unit_style); units, update->unit_style);
} }
std::string date = utils::get_potential_date(table_file,"table"); std::string date = utils::get_potential_date(table_file, "table");
utils::logmesg(lmp,"Appending to table file {} with DATE: {}\n", table_file, date); utils::logmesg(lmp,"Appending to table file {} with DATE: {}\n", table_file, date);
fp = fopen(table_file.c_str(),"a"); fp = fopen(table_file.c_str(),"a");
} else { } else {
@ -1846,12 +1846,12 @@ void Pair::write_file(int narg, char **arg)
} }
if (fp == nullptr) if (fp == nullptr)
error->one(FLERR,"Cannot open pair_write file {}: {}",table_file, utils::getsyserror()); error->one(FLERR,"Cannot open pair_write file {}: {}",table_file, utils::getsyserror());
fprintf(fp,"# Pair potential %s for atom types %d %d: i,r,energy,force\n", fprintf(fp, "# Pair potential %s for atom types %d %d: i,r,energy,force\n",
force->pair_style,itype,jtype); force->pair_style, itype, jtype);
if (style == RLINEAR) if (style == RLINEAR)
fprintf(fp,"\n%s\nN %d R %.15g %.15g\n\n",arg[7],n,inner,outer); fprintf(fp, "\n%s\nN %d R %.15g %.15g\n\n", arg[7], n, inner, outer);
if (style == RSQ) if (style == RSQ)
fprintf(fp,"\n%s\nN %d RSQ %.15g %.15g\n\n",arg[7],n,inner,outer); fprintf(fp, "\n%s\nN %d RSQ %.15g %.15g\n\n", arg[7], n, inner, outer);
} }
// initialize potentials before evaluating pair potential // initialize potentials before evaluating pair potential
@ -1869,7 +1869,7 @@ void Pair::write_file(int narg, char **arg)
double *eamfp_hold; double *eamfp_hold;
Pair *epair = force->pair_match("^eam",0); Pair *epair = force->pair_match("^eam",0);
if (epair) epair->swap_eam(eamfp,&eamfp_hold); if (epair) epair->swap_eam(eamfp, &eamfp_hold);
if ((comm->me == 0) && (epair)) if ((comm->me == 0) && (epair))
error->warning(FLERR,"EAM pair style. Table will not include embedding term"); error->warning(FLERR,"EAM pair style. Table will not include embedding term");
@ -1878,8 +1878,8 @@ void Pair::write_file(int narg, char **arg)
double q[2]; double q[2];
q[0] = q[1] = 1.0; q[0] = q[1] = 1.0;
if (narg == 10) { if (narg == 10) {
q[0] = utils::numeric(FLERR,arg[8],false,lmp); q[0] = utils::numeric(FLERR, arg[8], false, lmp);
q[1] = utils::numeric(FLERR,arg[9],false,lmp); q[1] = utils::numeric(FLERR, arg[9], false, lmp);
} }
double *q_hold; double *q_hold;
@ -1892,10 +1892,10 @@ void Pair::write_file(int narg, char **arg)
int masklo,maskhi,nmask,nshiftbits; int masklo,maskhi,nmask,nshiftbits;
if (style == BMP) { if (style == BMP) {
init_bitmap(inner,outer,n,masklo,maskhi,nmask,nshiftbits); init_bitmap(inner, outer, n, masklo, maskhi, nmask, nshiftbits);
int ntable = 1 << n; int ntable = 1 << n;
if (comm->me == 0) if (comm->me == 0)
fprintf(fp,"\n%s\nN %d BITMAP %.15g %.15g\n\n",arg[7],ntable,inner,outer); fprintf(fp, "\n%s\nN %d BITMAP %.15g %.15g\n\n", arg[7], ntable, inner, outer);
n = ntable; n = ntable;
} }
@ -1921,7 +1921,7 @@ void Pair::write_file(int narg, char **arg)
} }
if (rsq < cutsq[itype][jtype]) { if (rsq < cutsq[itype][jtype]) {
e = single(0,1,itype,jtype,rsq,1.0,1.0,f); e = single(0, 1, itype, jtype, rsq, 1.0, 1.0, f);
f *= r; f *= r;
} else e = f = 0.0; } else e = f = 0.0;
if (comm->me == 0) fprintf(fp,"%8d %- 22.15g %- 22.15g %- 22.15g\n",i+1,r,e,f); if (comm->me == 0) fprintf(fp,"%8d %- 22.15g %- 22.15g %- 22.15g\n",i+1,r,e,f);
@ -1930,7 +1930,7 @@ void Pair::write_file(int narg, char **arg)
// restore original vecs that were swapped in for // restore original vecs that were swapped in for
double *tmp; double *tmp;
if (epair) epair->swap_eam(eamfp_hold,&tmp); if (epair) epair->swap_eam(eamfp_hold, &tmp);
if (atom->q) atom->q = q_hold; if (atom->q) atom->q = q_hold;
if (comm->me == 0) fclose(fp); if (comm->me == 0) fclose(fp);
@ -2009,4 +2009,3 @@ double Pair::memory_usage()
bytes += (double)comm->nthreads*maxcvatom*9 * sizeof(double); bytes += (double)comm->nthreads*maxcvatom*9 * sizeof(double);
return bytes; return bytes;
} }