Skip to content

Commit

Permalink
Merge pull request uf3#96 from uf3/lammps_bug_fix
Browse files Browse the repository at this point in the history
Lammps UF3 bug fix
  • Loading branch information
JasonGibsonUfl authored Nov 15, 2023
2 parents 6808876 + 01d33e1 commit 38a5884
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 13 deletions.
48 changes: 37 additions & 11 deletions lammps_plugin/ML-UF3/pair_uf3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,25 +129,45 @@ void PairUF3::coeff(int narg, char **arg)


if (narg == 3){
for (int i = ilo; i <= ihi; i++) {
for (int j = MAX(jlo, i); j <= jhi; j++) {
if (comm->me == 0)
utils::logmesg(lmp, "\nUF3: Opening {} file\n", arg[2]);
uf3_read_pot_file(i,j,arg[2]);
if (utils::strmatch(arg[0],".*\\*.*") || utils::strmatch(arg[1],".*\\*.*")){
for (int i = ilo; i <= ihi; i++) {
for (int j = MAX(jlo, i); j <= jhi; j++) {
if (comm->me == 0)
utils::logmesg(lmp, "\nUF3: Opening {} file\n", arg[2]);
uf3_read_pot_file(i,j,arg[2]);
}
}
}

else{
int i = utils::inumeric(FLERR, arg[0], true, lmp);
int j = utils::inumeric(FLERR, arg[1], true, lmp);
if (comm->me == 0)
utils::logmesg(lmp, "\nUF3: Opening {} file\n", arg[2]);
uf3_read_pot_file(i,j,arg[2]);
}
}

if (narg == 4){
for (int i = ilo; i <= ihi; i++) {
for (int j = jlo; j <= jhi; j++) {
for (int k = MAX(klo, jlo); k <= khi; k++) {
if (comm->me == 0)
utils::logmesg(lmp, "\nUF3: Opening {} file\n", arg[3]);
uf3_read_pot_file(i,j,k,arg[3]);
if (utils::strmatch(arg[0],".*\\*.*") || utils::strmatch(arg[1],".*\\*.*") || utils::strmatch(arg[2],".*\\*.*")){
for (int i = ilo; i <= ihi; i++) {
for (int j = jlo; j <= jhi; j++) {
for (int k = MAX(klo, jlo); k <= khi; k++) {
if (comm->me == 0)
utils::logmesg(lmp, "\nUF3: Opening {} file\n", arg[3]);
uf3_read_pot_file(i,j,k,arg[3]);
}
}
}
}
else{
if (comm->me == 0)
utils::logmesg(lmp, "\nUF3: Opening {} file\n", arg[3]);
int i = utils::inumeric(FLERR, arg[0], true, lmp);
int j = utils::inumeric(FLERR, arg[1], true, lmp);
int k = utils::inumeric(FLERR, arg[2], true, lmp);
uf3_read_pot_file(i,j,k,arg[3]);
}
}
}

Expand Down Expand Up @@ -281,6 +301,9 @@ void PairUF3::uf3_read_pot_file(int itype, int jtype, char *potf_name)
utils::logmesg(lmp, "UF3: {} file should contain UF3 potential for {} {}\n", \
potf_name, itype, jtype);

if (!platform::file_is_readable(potf_name))
error->all(FLERR, "UF3: {} file is not readable", potf_name);

FILE *fp;
fp = utils::open_potential(potf_name, lmp, nullptr);

Expand Down Expand Up @@ -400,6 +423,9 @@ void PairUF3::uf3_read_pot_file(int itype, int jtype, int ktype, char *potf_name
utils::logmesg(lmp, "UF3: {} file should contain UF3 potential for {} {} {}\n",
potf_name, itype, jtype, ktype);

if (!platform::file_is_readable(potf_name))
error->all(FLERR, "UF3: {} file is not readable", potf_name);

FILE *fp;
fp = utils::open_potential(potf_name, lmp, nullptr);

Expand Down
24 changes: 22 additions & 2 deletions lammps_plugin/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ To use UF3 potentials in lammps just add the following tags to the lammps input
The 'uf3' keyword in :code:`pair_style` invokes the UF3 potentials in lammps. The number next to the :code:`uf3` keyword tells lammps whether the user wants to run the MD code with just 2-body or 2 and 3-body UF3 potentials. The last number of this line specifies the number of elemnts in the system. So in the above example, the user wants to run MD simulation with UF3 potentials containing both 2-body and 3-body interactions on a system containing only 1 element.

The :code:`pair_coeff` tag is used to read in the user-provided UF3 lammps potential files. These files can be generated directly from the :code:`json` potential files of UF3. We recommend using the :code:`generate_uf3_lammps_pots.py` script (`found here <https://github.com/monk-04/uf3/tree/lammps_implementation/lammps_plugin/scripts>`_) for generating the UF3 lammps potential files. It will also additionally print lines that should be added to the lammps input file for using UF3 lammps potential files.
The :code:`pair_coeff` tag is used to read in the user-provided UF3 lammps potential files. These files can be generated directly from the :code:`json` potential files of UF3. We recommend using the :code:`generate_uf3_lammps_pots.py` script (`found here </lammps_plugin/scripts>`_) for generating the UF3 lammps potential files. It will also additionally print lines that should be added to the lammps input file for using UF3 lammps potential files. **Note, nothing is inferred from the name of the UF3 lammps potential file. The name of the files can be completely arbitrary**

After :code:`pair_coeff` specify the interactions (two numbers for 2-body, three numbers for 3-body) followed by the name of the potential file. The user can also use asterisks:code:`*` for wild-card characters. In this case the behaviour is similar to other LAMMPS :code:`pair_style` for example LJ. The user can also specify. Make sure these files are present in the current run directory or in directories where lammps can find them.
After :code:`pair_coeff` specify the interactions (two numbers for 2-body, three numbers for 3-body) followed by the name of the potential file. The user can also use :code:`*` for wild-card characters. In this case the behaviour is similar to other LAMMPS :code:`pair_style` for example LJ. Make sure these files are present in the current run directory or in directories where lammps can find them.

As an example for a multicomponet system containing elements 'A' and 'B' the above lines can be-

Expand All @@ -77,6 +77,26 @@ As an example for a multicomponet system containing elements 'A' and 'B' the abo
pair_coeff 2 1 2 B_A_B
pair_coeff 2 2 2 B_B_B
If potential file is specified for 2-1 interaction (:code:`pair_coeff 2 1 FileName`), the potential for 1-2 interaction is automatically mapped. So, the following lines are also valid-

.. code:: bash
pair_style uf3 3 2
pair_coeff 2 2 A_A
pair_coeff 1 1 B_B
pair_coeff 2 1 A_B
pair_coeff 2 2 2 A_A_A
pair_coeff 2 2 1 A_A_B
pair_coeff 2 1 1 A_B_B
pair_coeff 1 1 1 B_B_B
pair_coeff 1 2 1 B_A_B
pair_coeff 1 2 2 B_A_A
Following format is also a valid for system containing elements 'A' and 'B'

.. code:: bash
Expand Down

0 comments on commit 38a5884

Please sign in to comment.