Unverified Commit ad029f56 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer Committed by GitHub
Browse files

Merge pull request #1965 from martok/meamc-docs

MEAM/C: Improve documentation, error messages
parents 06a9fda7 2d15071c
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -2783,7 +2783,7 @@ Doc page with :doc:`WARNING messages <Errors_warnings>`
   if this helps.

*Did not find all elements in MEAM library file*
   The requested elements were not found in the MEAM file.
   Some requested elements were not found in the MEAM file. Check spelling etc.

*Did not find fix shake partner info*
   Could not find bond partners implied by fix shake command.  This error
@@ -3135,6 +3135,9 @@ Doc page with :doc:`WARNING messages <Errors_warnings>`
*Epsilon or sigma reference not set by pair style in ewald/n*
   The pair style is not providing the needed epsilon or sigma values.

*Error in MEAM parameter file: keyword %s (further information)*
   Self-explanatory. Check the parameter file.

*Error in vdw spline: inner radius > outer radius*
   A pre-tabulated spline is invalid.  Likely a problem with the
   potential parameters.
@@ -4611,7 +4614,7 @@ Doc page with :doc:`WARNING messages <Errors_warnings>`
*Incorrect format in COMB3 potential file*
   Incorrect number of words per line in the potential file.

*Incorrect format in MEAM potential file*
*Incorrect format in MEAM library file*
   Incorrect number of words per line in the potential file.

*Incorrect format in SNAP coefficient file*
@@ -5669,6 +5672,9 @@ Doc page with :doc:`WARNING messages <Errors_warnings>`
   A fix is referenced incorrectly or a fix that produces per-atom
   values is used in an equal-style variable formula.

*Mismatched parameter in MEAM library file: z!=lat*
   The coordination number and lattice do not match, check that consistent values are given.

*Mismatched variable in variable formula*
   A variable is referenced incorrectly or an atom-style variable that
   produces per-atom values is used in an equal-style variable
@@ -7764,6 +7770,9 @@ keyword to allow for additional bonds to be formed
*Too many atoms to dump sort*
   Cannot sort when running with more than 2\^31 atoms.

*Too many elements extracted from MEAM library.*
   Increase 'maxelt' in meam.h and recompile.

*Too many exponent bits for lookup table*
   Table size specified via pair_modify command does not work with your
   machine's floating point representation.
@@ -7997,11 +8006,11 @@ keyword to allow for additional bonds to be formed
*Unknown unit_style*
   Self-explanatory. Check the input script or data file.

*Unrecognized lattice type in MEAM file 1*
*Unrecognized lattice type in MEAM library file*
   The lattice type in an entry of the MEAM library file is not
   valid.

*Unrecognized lattice type in MEAM file 2*
*Unrecognized lattice type in MEAM parameter file*
   The lattice type in an entry of the MEAM parameter file is not
   valid.

@@ -8017,6 +8026,9 @@ keyword to allow for additional bonds to be formed
*Unsupported order in kspace_style pppm/disp, pair_style %s*
   Only pair styles with 1/r and 1/r\^6 dependence are currently supported.

*Unsupported parameter in MEAM library file*
   Self-explanatory.

*Use cutoff keyword to set cutoff in single mode*
   Mode is single so cutoff/multi keyword cannot be used.

+9 −13
Original line number Diff line number Diff line
@@ -93,12 +93,13 @@ and the 4th to be C, you would use the following pair_coeff command:
   pair_coeff * * library.meam Si C sic.meam Si Si Si C

The 1st 2 arguments must be \* \* so as to span all LAMMPS atom types.
The two filenames are for the library and parameter file respectively.
The Si and C arguments (between the file names) are the two elements
for which info will be extracted from the library file.  The first
three trailing Si arguments map LAMMPS atom types 1,2,3 to the MEAM Si
element.  The final C argument maps LAMMPS atom type 4 to the MEAM C
element.
The first filename is the element library file. The list of elements following
it extracts lines from the library file and assigns numeric indices to these
elements. The second filename is the alloy parameter file, which refers to
elements using the numeric indices assigned before.
The arguments after the parameter file map LAMMPS atom types to elements, i.e.
LAMMPS atom types 1,2,3 to the MEAM Si element.  The final C argument maps
LAMMPS atom type 4 to the MEAM C element.

If the 2nd filename is specified as NULL, no parameter file is read,
which simply means the generic parameters in the library file are
@@ -140,7 +141,7 @@ not required. The other numeric parameters match values in the
formulas above.  The value of the "elt" string is what is used in the
pair_coeff command to identify which settings from the library file
you wish to read in.  There can be multiple entries in the library
file with the same "elt" value; LAMMPS reads the 1st matching entry it
file with the same "elt" value; LAMMPS reads the first matching entry it
finds and ignores the rest.

Other parameters in the MEAM library file correspond to single-element
@@ -192,7 +193,7 @@ trailing comment (starting with #) which is ignored.

The indices I, J, K correspond to the elements selected from the
MEAM library file numbered in the order of how those elements were
selected starting from 1. Thus for the example given below
selected starting from 1. Thus for the example given before

.. code-block:: LAMMPS

@@ -202,11 +203,6 @@ an index of 1 would refer to Si and an index of 2 to C.

The recognized keywords for the parameter file are as follows:

Ec, alpha, rho0, delta, lattce, attrac, repuls, nn2, Cmin, Cmax, rc, delr,
augt1, gsmooth_factor, re

where

.. parsed-literal::

   rc          = cutoff radius for cutoff function; default = 4.0
+6 −0
Original line number Diff line number Diff line
@@ -49,6 +49,12 @@ MEAM::meam_checkindex(int num, int lim, int nidx, int* idx /*idx(3)*/, int* ierr
//     20 = bkgd_dyn
//     21 = theta

//     The returned errorflag has the following meanings:

//     0 = no error
//     1 = "which" out of range / invalid keyword
//     2 = not enough indices given
//     3 = an element index is out of range

void
MEAM::meam_setup_param(int which, double value, int nindex, int* index /*index(3)*/, int* errorflag)
+133 −124
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
using namespace LAMMPS_NS;

#define MAXLINE 1024
#define ERRFMT(errfn,format,...) do { char _strbuf[128]; snprintf(_strbuf,sizeof(_strbuf),format,__VA_ARGS__); errfn(FLERR,_strbuf); } while (0)

static const int nkeywords = 22;
static const char *keywords[] = {
@@ -147,9 +148,7 @@ void PairMEAMC::compute(int eflag, int vflag)
  meam_inst->meam_dens_final(nlocal,eflag_either,eflag_global,eflag_atom,
                   &eng_vdwl,eatom,ntype,type,map,scale,errorflag);
  if (errorflag) {
    char str[128];
    sprintf(str,"MEAM library error %d",errorflag);
    error->one(FLERR,str);
    ERRFMT(error->one,"MEAM library error %d",errorflag);
  }

  comm->forward_comm_pair(this);
@@ -228,8 +227,8 @@ void PairMEAMC::coeff(int narg, char **arg)
  nelements = narg - 4 - atom->ntypes;
  if (nelements < 1) error->all(FLERR,"Incorrect args for pair coefficients");
  if (nelements > maxelt)
    error->all(FLERR,"Too many elements extracted from MEAM library. "
                      "Increase 'maxelt' in meam.h and recompile.");
    ERRFMT(error->all, "Too many elements extracted from MEAM library (current limit: %d)."
                       " Increase 'maxelt' in meam.h and recompile.", maxelt);
  elements = new char*[nelements];
  mass = new double[nelements];

@@ -334,11 +333,8 @@ void PairMEAMC::read_files(char *globalfile, char *userfile)
  FILE *fp;
  if (comm->me == 0) {
    fp = force->open_potential(globalfile);
    if (fp == NULL) {
      char str[128];
      snprintf(str,128,"Cannot open MEAM potential file %s",globalfile);
      error->one(FLERR,str);
    }
    if (fp == NULL)
      ERRFMT(error->one, "Cannot open MEAM potential file %s", globalfile);
  }

  // allocate parameter arrays
@@ -372,52 +368,39 @@ void PairMEAMC::read_files(char *globalfile, char *userfile)
  // store params if element name is in element list
  // if element name appears multiple times, only store 1st entry

  int i,n,nwords;
  char **words = new char*[params_per_line+1];
  char line[MAXLINE],*ptr;
  int eof = 0;

  if (comm->me == 0) {
    int nset = 0;
    char **words = new char*[params_per_line+1];
    char line[MAXLINE];
    while (1) {
    if (comm->me == 0) {
      char *ptr;
      ptr = fgets(line,MAXLINE,fp);
      if (ptr == NULL) {
        eof = 1;
        fclose(fp);
      } else n = strlen(line) + 1;
        break;
      }
    MPI_Bcast(&eof,1,MPI_INT,0,world);
    if (eof) break;
    MPI_Bcast(&n,1,MPI_INT,0,world);
    MPI_Bcast(line,n,MPI_CHAR,0,world);

      // strip comment, skip line if blank

      if ((ptr = strchr(line,'#'))) *ptr = '\0';
    nwords = atom->count_words(line);
      int nwords = atom->count_words(line);
      if (nwords == 0) continue;

      // concatenate additional lines until have params_per_line words

      while (nwords < params_per_line) {
      n = strlen(line);
      if (comm->me == 0) {
        int n = strlen(line);
        ptr = fgets(&line[n],MAXLINE-n,fp);
        if (ptr == NULL) {
          eof = 1;
          fclose(fp);
        } else n = strlen(line) + 1;
          break;
        }
      MPI_Bcast(&eof,1,MPI_INT,0,world);
      if (eof) break;
      MPI_Bcast(&n,1,MPI_INT,0,world);
      MPI_Bcast(line,n,MPI_CHAR,0,world);
        if ((ptr = strchr(line,'#'))) *ptr = '\0';
        nwords = atom->count_words(line);
      }

      if (nwords != params_per_line)
      error->all(FLERR,"Incorrect format in MEAM potential file");
        error->one(FLERR,"Incorrect format in MEAM library file");

      // words = ptrs to all words in line
      // strip single and double quotes from words
@@ -428,54 +411,85 @@ void PairMEAMC::read_files(char *globalfile, char *userfile)

      // skip if element name isn't in element list

    for (i = 0; i < nelements; i++)
      if (strcmp(words[0],elements[i]) == 0) break;
    if (i >= nelements) continue;
      int index;
      for (index = 0; index < nelements; index++)
        if (strcmp(words[0],elements[index]) == 0) break;
      if (index == nelements) continue;

    // skip if element already appeared
      // skip if element already appeared (technically error in library file, but always ignored)

    if (found[i] == true) continue;
    found[i] = true;
      if (found[index] == true) continue;
      found[index] = true;

      // map lat string to an integer

    if (!MEAM::str_to_lat(words[1], true, lat[i]))
      error->all(FLERR,"Unrecognized lattice type in MEAM file 1");
      if (!MEAM::str_to_lat(words[1], true, lat[index]))
        ERRFMT(error->one, "Unrecognized lattice type in MEAM library file: %s", words[1]);

      // store parameters

    z[i] = atof(words[2]);
    ielement[i] = atoi(words[3]);
    atwt[i] = atof(words[4]);
    alpha[i] = atof(words[5]);
    b0[i] = atof(words[6]);
    b1[i] = atof(words[7]);
    b2[i] = atof(words[8]);
    b3[i] = atof(words[9]);
    alat[i] = atof(words[10]);
    esub[i] = atof(words[11]);
    asub[i] = atof(words[12]);
    t0[i] = atof(words[13]);
    t1[i] = atof(words[14]);
    t2[i] = atof(words[15]);
    t3[i] = atof(words[16]);
    rozero[i] = atof(words[17]);
    ibar[i] = atoi(words[18]);

    if (!isone(t0[i]))
      error->all(FLERR,"Unsupported parameter in MEAM potential file: t0!=1");
      z[index] = atof(words[2]);
      ielement[index] = atoi(words[3]);
      atwt[index] = atof(words[4]);
      alpha[index] = atof(words[5]);
      b0[index] = atof(words[6]);
      b1[index] = atof(words[7]);
      b2[index] = atof(words[8]);
      b3[index] = atof(words[9]);
      alat[index] = atof(words[10]);
      esub[index] = atof(words[11]);
      asub[index] = atof(words[12]);
      t0[index] = atof(words[13]);
      t1[index] = atof(words[14]);
      t2[index] = atof(words[15]);
      t3[index] = atof(words[16]);
      rozero[index] = atof(words[17]);
      ibar[index] = atoi(words[18]);

      if (!isone(t0[index]))
        error->one(FLERR,"Unsupported parameter in MEAM library file: t0!=1");

      // z given is ignored: if this is mismatched, we definitely won't do what the user said -> fatal error
    if (z[i] != MEAM::get_Zij(lat[i]))
      error->all(FLERR,"Mismatched parameter in MEAM potential file: z!=lat");
      if (z[index] != MEAM::get_Zij(lat[index]))
        error->one(FLERR,"Mismatched parameter in MEAM library file: z!=lat");

      nset++;
    }
      
    // error if didn't find all elements in file

  if (nset != nelements)
    error->all(FLERR,"Did not find all elements in MEAM library file");
    if (nset != nelements) {
      char str[128] = "Did not find all elements in MEAM library file, missing:";
      for (int i = 0; i < nelements; i++)
        if (!found[i]) {
          strcat(str," ");
          strcat(str,elements[i]);
        }
      error->one(FLERR,str);
    }

    delete [] words;
  }

  // distribute complete parameter sets
  MPI_Bcast(lat, nelements, MPI_INT, 0, world);
  MPI_Bcast(ielement, nelements, MPI_INT, 0, world);
  MPI_Bcast(ibar, nelements, MPI_INT, 0, world);
  MPI_Bcast(z, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(atwt, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(alpha, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(b0, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(b1, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(b2, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(b3, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(alat, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(esub, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(asub, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(t0, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(t1, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(t2, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(t3, nelements, MPI_DOUBLE, 0, world);
  MPI_Bcast(rozero, nelements, MPI_DOUBLE, 0, world);

  // pass element parameters to MEAM package

@@ -484,12 +498,10 @@ void PairMEAMC::read_files(char *globalfile, char *userfile)

  // set element masses

  for (i = 0; i < nelements; i++) mass[i] = atwt[i];
  for (int i = 0; i < nelements; i++) mass[i] = atwt[i];

  // clean-up memory

  delete [] words;

  delete [] lat;
  delete [] ielement;
  delete [] ibar;
@@ -518,48 +530,42 @@ void PairMEAMC::read_files(char *globalfile, char *userfile)

  if (comm->me == 0) {
    fp = force->open_potential(userfile);
    if (fp == NULL) {
      char str[128];
      snprintf(str,128,"Cannot open MEAM potential file %s",userfile);
      error->one(FLERR,str);
    }
    if (fp == NULL)
      ERRFMT(error->one, "Cannot open MEAM potential file %s", userfile);
  }

  // read settings
  // pass them one at a time to MEAM package
  // match strings to list of corresponding ints
  
  int which;
  double value;
  lattice_t latt;
  int nindex,index[3];
  int maxparams = 6;
  char **params = new char*[maxparams];
  int nparams;

  eof = 0;
  while (1) {
    int which;
    int nindex, index[3];
    double value;
    char line[MAXLINE];
    int nline;
    char *ptr;
    if (comm->me == 0) {
      ptr = fgets(line,MAXLINE,fp);
      if (ptr == NULL) {
        eof = 1;
        fclose(fp);
      } else n = strlen(line) + 1;
        nline = -1;
      } else nline = strlen(line) + 1;
    }
    MPI_Bcast(&eof,1,MPI_INT,0,world);
    if (eof) break;
    MPI_Bcast(&n,1,MPI_INT,0,world);
    MPI_Bcast(line,n,MPI_CHAR,0,world);
    MPI_Bcast(&nline,1,MPI_INT,0,world);
    if (nline<0) break;
    MPI_Bcast(line,nline,MPI_CHAR,0,world);

    // strip comment, skip line if blank

    if ((ptr = strchr(line,'#'))) *ptr = '\0';
    nparams = atom->count_words(line);
    if (nparams == 0) continue;
    if (atom->count_words(line) == 0) continue;

    // words = ptrs to all words in line
    // params = ptrs to all fields in line
    
    nparams = 0;
    int nparams = 0;
    params[nparams++] = strtok(line,"=(), '\t\n\r\f");
    while (nparams < maxparams &&
           (params[nparams++] = strtok(NULL,"=(), '\t\n\r\f")))
@@ -568,20 +574,18 @@ void PairMEAMC::read_files(char *globalfile, char *userfile)

    for (which = 0; which < nkeywords; which++)
      if (strcmp(params[0],keywords[which]) == 0) break;
    if (which == nkeywords) {
      char str[128];
      snprintf(str,128,"Keyword %s in MEAM parameter file not recognized",
               params[0]);
      error->all(FLERR,str);
    }
    if (which == nkeywords)
      ERRFMT(error->all, "Keyword %s in MEAM parameter file not recognized", params[0]);
    
    nindex = nparams - 2;
    for (i = 0; i < nindex; i++) index[i] = atoi(params[i+1]) - 1;
    for (int i = 0; i < nindex; i++) index[i] = atoi(params[i+1]) - 1;

    // map lattce_meam value to an integer

    if (which == 4) {
      lattice_t latt;
      if (!MEAM::str_to_lat(params[nparams-1], false, latt))
        error->all(FLERR,"Unrecognized lattice type in MEAM file 2");
        ERRFMT(error->all, "Unrecognized lattice type in MEAM parameter file: %s", params[nparams-1]);
      value = latt;
    }
    else value = atof(params[nparams-1]);
@@ -592,11 +596,16 @@ void PairMEAMC::read_files(char *globalfile, char *userfile)
    meam_inst->meam_setup_param(which,value,nindex,index,&errorflag);
    if (errorflag) {
      char str[128];
      sprintf(str,"MEAM library error %d",errorflag);
      error->all(FLERR,str);
      snprintf(str,80,"Error in MEAM parameter file: keyword %s",params[0]);
      switch(errorflag) {
        case 1: strcat(str, " is out of range (please report a bug)"); break;
        case 2: strcat(str, " expected more indices"); break;
        case 3: strcat(str, " has out of range element index"); break;
      }
      error->all(FLERR,str);
    }
    
  }
  delete [] params;
}

+18 −7
Original line number Diff line number Diff line
@@ -89,26 +89,37 @@ E: Cannot open MEAM potential file %s
The specified MEAM potential file cannot be opened.  Check that the
path and name are correct.

E: Incorrect format in MEAM potential file
E: Incorrect format in MEAM library file

Incorrect number of words per line in the potential file.

E: Unrecognized lattice type in MEAM file 1
E: Too many elements extracted from MEAM library.

The lattice type in an entry of the MEAM library file is not
Increase 'maxelt' in meam.h and recompile.

E: Unrecognized lattice type in MEAM library/parameter file

The lattice type in an entry of the MEAM library/parameter file is not
valid.

E: Unsupported parameter in MEAM library file: ...

Self-explanatory.

E: Mismatched parameter in MEAM library file: z!=lat

The coordination number and lattice do not match, check that consistent values are given.

E: Did not find all elements in MEAM library file

The requested elements were not found in the MEAM file.
Some requested elements were not found in the MEAM file. Check spelling etc.

E: Keyword %s in MEAM parameter file not recognized

Self-explanatory.

E: Unrecognized lattice type in MEAM file 2
E: Error in MEAM parameter file: keyword %s (further information)

The lattice type in an entry of the MEAM parameter file is not
valid.
Self-explanatory. Check the parameter file.

*/