add gao-weber potentials (regular and with ZBL core) with SiC potential files

NOTE: documentation is missing
This commit is contained in:
Axel Kohlmeyer 2017-05-15 17:44:25 -04:00
parent 06c151421c
commit d9d4ef17c8
6 changed files with 1356 additions and 0 deletions

19
potentials/SiC.gw Normal file
View File

@ -0,0 +1,19 @@
# DATE: 2016-05-06 CONTRIBUTOR: German Samolyuk, samolyuk@gmail.com CITATION: ???
# Gao-Weber parameters for various elements and mixtures
# multiple entries can be added to this file, LAMMPS reads the ones it needs
# these entries are in LAMMPS "metal" units:
# format of a single entry (one or more lines):
# element 1, element 2, element 3,
# m, gamma, lambda3, c, d, h, n, beta, lambda2, X_ij*B, R, D, lambda1, A
#E1 E2 E3 m gamma lambda3 c d h n beta lambda2 B R D lambda1 A
Si Si Si 1 0.013318 0 14 2.1 -1 0.78000 1 1.80821400248640 632.658058300867 2.35 0.15 2.38684248328205 1708.79738703139
Si Si C 1 0.013318 0 14 2.1 -1 0.78000 1 1.80821400248640 632.658058300867 2.35 0.15 2.38684248328205 1708.79738703139
Si C Si 1 0.013318 0 14 2.1 -1 0.78000 1 1.96859970919818 428.946015420752 2.35 0.15 3.03361215187440 1820.05673775234
C Si Si 1 0.011304 0 19 2.5 -1 0.80468 1 1.96859970919818 428.946015420752 2.35 0.15 3.03361215187440 1820.05673775234
C C Si 1 0.011304 0 19 2.5 -1 0.80469 1 1.76776695296637 203.208547714849 2.35 0.15 2.54558441227157 458.510465798439
C Si C 1 0.011304 0 19 2.5 -1 0.80469 1 1.96859970919818 428.946015420752 2.35 0.15 3.03361215187440 1820.05673775234
Si C C 1 0.013318 0 14 2.1 -1 0.78000 1 1.96859970919818 428.946015420752 2.35 0.15 3.03361215187440 1820.05673775234
C C C 1 0.011304 0 19 2.5 -1 0.80469 1 1.76776695296637 203.208547714849 2.35 0.15 2.54558441227157 458.510465798439

19
potentials/SiC.gw.zbl Normal file
View File

@ -0,0 +1,19 @@
# DATE: 2016-05-06 CONTRIBUTOR: German Samolyuk, samolyuk@gmail.com CITATION: ???
# Gao-Weber parameters for various elements and mixtures
# multiple entries can be added to this file, LAMMPS reads the ones it needs
# these entries are in LAMMPS "metal" units:
# format of a single entry (one or more lines):
# element 1, element 2, element 3,
# m, gamma, lambda3, c, d, h, n, beta, lambda2, X_ij*B, R, D, lambda1, A
#E1 E2 E3 m gamma lambda3 c d h n beta lambda2 B R D lambda1 A Z_i, Z_j, ZBLcut, ZBLexpscale
Si Si Si 1 0.013318 0 14 2.1 -1 0.78000 1 1.80821400248640 632.658058300867 2.35 0.15 2.38684248328205 1708.79738703139 14 14 .95 14
Si Si C 1 0.013318 0 14 2.1 -1 0.78000 1 1.80821400248640 632.658058300867 2.35 0.15 2.38684248328205 1708.79738703139 14 14 .95 14
Si C Si 1 0.013318 0 14 2.1 -1 0.78000 1 1.96859970919818 428.946015420752 2.35 0.15 3.03361215187440 1820.05673775234 14 6 .95 14
C Si Si 1 0.011304 0 19 2.5 -1 0.80468 1 1.96859970919818 428.946015420752 2.35 0.15 3.03361215187440 1820.05673775234 6 14 .95 14
C C Si 1 0.011304 0 19 2.5 -1 0.80469 1 1.76776695296637 203.208547714849 2.35 0.15 2.54558441227157 458.510465798439 6 6 .95 14
C Si C 1 0.011304 0 19 2.5 -1 0.80469 1 1.96859970919818 428.946015420752 2.35 0.15 3.03361215187440 1820.05673775234 6 14 .95 14
Si C C 1 0.013318 0 14 2.1 -1 0.78000 1 1.96859970919818 428.946015420752 2.35 0.15 3.03361215187440 1820.05673775234 14 6 .95 14
C C C 1 0.011304 0 19 2.5 -1 0.80469 1 1.76776695296637 203.208547714849 2.35 0.15 2.54558441227157 458.510465798439 6 6 .95 14

763
src/MANYBODY/pair_gw.cpp Normal file
View File

@ -0,0 +1,763 @@
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: German Samolyuk (ORNL)
based on PairTersoff by Aidan Thompson (SNL)
------------------------------------------------------------------------- */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pair_gw.h"
#include "atom.h"
#include "neighbor.h"
#include "neigh_list.h"
#include "neigh_request.h"
#include "force.h"
#include "comm.h"
#include "memory.h"
#include "error.h"
#include "math_const.h"
using namespace LAMMPS_NS;
using namespace MathConst;
#define MAXLINE 1024
#define DELTA 4
/* ---------------------------------------------------------------------- */
PairGW::PairGW(LAMMPS *lmp) : Pair(lmp)
{
single_enable = 0;
restartinfo = 0;
one_coeff = 1;
manybody_flag = 1;
nelements = 0;
elements = NULL;
nparams = maxparam = 0;
params = NULL;
elem2param = NULL;
map = NULL;
}
/* ----------------------------------------------------------------------
check if allocated, since class can be destructed when incomplete
------------------------------------------------------------------------- */
PairGW::~PairGW()
{
if (elements)
for (int i = 0; i < nelements; i++) delete [] elements[i];
delete [] elements;
memory->destroy(params);
memory->destroy(elem2param);
if (allocated) {
memory->destroy(setflag);
memory->destroy(cutsq);
delete [] map;
}
}
/* ---------------------------------------------------------------------- */
void PairGW::compute(int eflag, int vflag)
{
int i,j,k,ii,jj,kk,inum,jnum;
int itag,jtag,itype,jtype,ktype,iparam_ij,iparam_ijk;
double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair;
double rsq,rsq1,rsq2;
double delr1[3],delr2[3],fi[3],fj[3],fk[3];
double zeta_ij, prefactor;
int *ilist,*jlist,*numneigh,**firstneigh;
evdwl = 0.0;
if (eflag || vflag) ev_setup(eflag,vflag);
else evflag = vflag_fdotr = vflag_atom = 0;
double **x = atom->x;
double **f = atom->f;
tagint *tag = atom->tag;
int *type = atom->type;
int nlocal = atom->nlocal;
int newton_pair = force->newton_pair;
inum = list->inum;
ilist = list->ilist;
numneigh = list->numneigh;
firstneigh = list->firstneigh;
// loop over full neighbor list of my atoms
for (ii = 0; ii < inum; ii++) {
i = ilist[ii];
itag = tag[i];
itype = map[type[i]];
xtmp = x[i][0];
ytmp = x[i][1];
ztmp = x[i][2];
// two-body interactions, skip half of them
jlist = firstneigh[i];
jnum = numneigh[i];
for (jj = 0; jj < jnum; jj++) {
j = jlist[jj];
j &= NEIGHMASK;
jtag = tag[j];
if (itag > jtag) {
if ((itag+jtag) % 2 == 0) continue;
} else if (itag < jtag) {
if ((itag+jtag) % 2 == 1) continue;
} else {
if (x[j][2] < x[i][2]) continue;
if (x[j][2] == ztmp && x[j][1] < ytmp) continue;
if (x[j][2] == ztmp && x[j][1] == ytmp && x[j][0] < xtmp) continue;
}
jtype = map[type[j]];
delx = xtmp - x[j][0];
dely = ytmp - x[j][1];
delz = ztmp - x[j][2];
rsq = delx*delx + dely*dely + delz*delz;
iparam_ij = elem2param[itype][jtype][jtype];
if (rsq > params[iparam_ij].cutsq) continue;
repulsive(&params[iparam_ij],rsq,fpair,eflag,evdwl);
f[i][0] += delx*fpair;
f[i][1] += dely*fpair;
f[i][2] += delz*fpair;
f[j][0] -= delx*fpair;
f[j][1] -= dely*fpair;
f[j][2] -= delz*fpair;
if (evflag) ev_tally(i,j,nlocal,newton_pair,
evdwl,0.0,fpair,delx,dely,delz);
}
// three-body interactions
// skip immediately if I-J is not within cutoff
for (jj = 0; jj < jnum; jj++) {
j = jlist[jj];
j &= NEIGHMASK;
jtype = map[type[j]];
iparam_ij = elem2param[itype][jtype][jtype];
delr1[0] = x[j][0] - xtmp;
delr1[1] = x[j][1] - ytmp;
delr1[2] = x[j][2] - ztmp;
rsq1 = delr1[0]*delr1[0] + delr1[1]*delr1[1] + delr1[2]*delr1[2];
if (rsq1 > params[iparam_ij].cutsq) continue;
// accumulate bondorder zeta for each i-j interaction via loop over k
zeta_ij = 1.0;
for (kk = 0; kk < jnum; kk++) {
if (jj == kk) continue;
k = jlist[kk];
k &= NEIGHMASK;
ktype = map[type[k]];
iparam_ijk = elem2param[itype][jtype][ktype];
delr2[0] = x[k][0] - xtmp;
delr2[1] = x[k][1] - ytmp;
delr2[2] = x[k][2] - ztmp;
rsq2 = delr2[0]*delr2[0] + delr2[1]*delr2[1] + delr2[2]*delr2[2];
if (rsq2 > params[iparam_ijk].cutsq) continue;
zeta_ij += zeta(&params[iparam_ijk],rsq1,rsq2,delr1,delr2);
}
// pairwise force due to zeta
force_zeta(&params[iparam_ij],rsq1,zeta_ij,fpair,prefactor,eflag,evdwl);
f[i][0] += delr1[0]*fpair;
f[i][1] += delr1[1]*fpair;
f[i][2] += delr1[2]*fpair;
f[j][0] -= delr1[0]*fpair;
f[j][1] -= delr1[1]*fpair;
f[j][2] -= delr1[2]*fpair;
if (evflag) ev_tally(i,j,nlocal,newton_pair,
evdwl,0.0,-fpair,-delr1[0],-delr1[1],-delr1[2]);
// attractive term via loop over k
for (kk = 0; kk < jnum; kk++) {
if (jj == kk) continue;
k = jlist[kk];
k &= NEIGHMASK;
ktype = map[type[k]];
iparam_ijk = elem2param[itype][jtype][ktype];
delr2[0] = x[k][0] - xtmp;
delr2[1] = x[k][1] - ytmp;
delr2[2] = x[k][2] - ztmp;
rsq2 = delr2[0]*delr2[0] + delr2[1]*delr2[1] + delr2[2]*delr2[2];
if (rsq2 > params[iparam_ijk].cutsq) continue;
attractive(&params[iparam_ijk],prefactor,
rsq1,rsq2,delr1,delr2,fi,fj,fk);
f[i][0] += fi[0];
f[i][1] += fi[1];
f[i][2] += fi[2];
f[j][0] += fj[0];
f[j][1] += fj[1];
f[j][2] += fj[2];
f[k][0] += fk[0];
f[k][1] += fk[1];
f[k][2] += fk[2];
if (vflag_atom) v_tally3(i,j,k,fj,fk,delr1,delr2);
} // kk
} // jj
} // ii
if (vflag_fdotr) virial_fdotr_compute();
}
/* ---------------------------------------------------------------------- */
void PairGW::allocate()
{
allocated = 1;
int n = atom->ntypes;
memory->create(setflag,n+1,n+1,"pair:setflag");
memory->create(cutsq,n+1,n+1,"pair:cutsq");
map = new int[n+1];
}
/* ----------------------------------------------------------------------
global settings
------------------------------------------------------------------------- */
void PairGW::settings(int narg, char **arg)
{
if (narg != 0) error->all(FLERR,"Illegal pair_style command");
}
/* ----------------------------------------------------------------------
set coeffs for one or more type pairs
------------------------------------------------------------------------- */
void PairGW::coeff(int narg, char **arg)
{
int i,j,n;
if (!allocated) allocate();
if (narg != 3 + atom->ntypes)
error->all(FLERR,"Incorrect args for pair coefficients");
// insure I,J args are * *
if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0)
error->all(FLERR,"Incorrect args for pair coefficients");
// read args that map atom types to elements in potential file
// map[i] = which element the Ith atom type is, -1 if NULL
// nelements = # of unique elements
// elements = list of element names
if (elements) {
for (i = 0; i < nelements; i++) delete [] elements[i];
delete [] elements;
}
elements = new char*[atom->ntypes];
for (i = 0; i < atom->ntypes; i++) elements[i] = NULL;
nelements = 0;
for (i = 3; i < narg; i++) {
if (strcmp(arg[i],"NULL") == 0) {
map[i-2] = -1;
continue;
}
for (j = 0; j < nelements; j++)
if (strcmp(arg[i],elements[j]) == 0) break;
map[i-2] = j;
if (j == nelements) {
n = strlen(arg[i]) + 1;
elements[j] = new char[n];
strcpy(elements[j],arg[i]);
nelements++;
}
}
// read potential file and initialize potential parameters
read_file(arg[2]);
setup_params();
// clear setflag since coeff() called once with I,J = * *
n = atom->ntypes;
for (i = 1; i <= n; i++)
for (j = i; j <= n; j++)
setflag[i][j] = 0;
// set setflag i,j for type pairs where both are mapped to elements
int count = 0;
for (i = 1; i <= n; i++)
for (j = i; j <= n; j++)
if (map[i] >= 0 && map[j] >= 0) {
setflag[i][j] = 1;
count++;
}
if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients");
}
/* ----------------------------------------------------------------------
init specific to this pair style
------------------------------------------------------------------------- */
void PairGW::init_style()
{
if (atom->tag_enable == 0)
error->all(FLERR,"Pair style GW requires atom IDs");
if (force->newton_pair == 0)
error->all(FLERR,"Pair style GW requires newton pair on");
// need a full neighbor list
int irequest = neighbor->request(this,instance_me);
neighbor->requests[irequest]->half = 0;
neighbor->requests[irequest]->full = 1;
}
/* ----------------------------------------------------------------------
init for one type pair i,j and corresponding j,i
------------------------------------------------------------------------- */
double PairGW::init_one(int i, int j)
{
if (setflag[i][j] == 0) error->all(FLERR,"All pair coeffs are not set");
return cutmax;
}
/* ---------------------------------------------------------------------- */
void PairGW::read_file(char *file)
{
int params_per_line = 17;
char **words = new char*[params_per_line+1];
memory->sfree(params);
params = NULL;
nparams = maxparam = 0;
// open file on proc 0
FILE *fp;
if (comm->me == 0) {
fp = force->open_potential(file);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open GW potential file %s",file);
error->one(FLERR,str);
}
}
// read each line out of file, skipping blank lines or leading '#'
// store line of params if all 3 element tags are in element list
int n,nwords,ielement,jelement,kelement;
char line[MAXLINE],*ptr;
int eof = 0;
while (1) {
if (comm->me == 0) {
ptr = fgets(line,MAXLINE,fp);
if (ptr == NULL) {
eof = 1;
fclose(fp);
} else n = 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);
// strip comment, skip line if blank
if ((ptr = strchr(line,'#'))) *ptr = '\0';
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) {
ptr = fgets(&line[n],MAXLINE-n,fp);
if (ptr == NULL) {
eof = 1;
fclose(fp);
} else n = 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);
if ((ptr = strchr(line,'#'))) *ptr = '\0';
nwords = atom->count_words(line);
}
if (nwords != params_per_line)
error->all(FLERR,"Incorrect format in GW potential file");
// words = ptrs to all words in line
nwords = 0;
words[nwords++] = strtok(line," \t\n\r\f");
while ((words[nwords++] = strtok(NULL," \t\n\r\f"))) continue;
// ielement,jelement,kelement = 1st args
// if all 3 args are in element list, then parse this line
// else skip to next line
for (ielement = 0; ielement < nelements; ielement++)
if (strcmp(words[0],elements[ielement]) == 0) break;
if (ielement == nelements) continue;
for (jelement = 0; jelement < nelements; jelement++)
if (strcmp(words[1],elements[jelement]) == 0) break;
if (jelement == nelements) continue;
for (kelement = 0; kelement < nelements; kelement++)
if (strcmp(words[2],elements[kelement]) == 0) break;
if (kelement == nelements) continue;
// load up parameter settings and error check their values
if (nparams == maxparam) {
maxparam += DELTA;
params = (Param *) memory->srealloc(params,maxparam*sizeof(Param),
"pair:params");
}
params[nparams].ielement = ielement;
params[nparams].jelement = jelement;
params[nparams].kelement = kelement;
params[nparams].powerm = atof(words[3]);
params[nparams].gamma = atof(words[4]);
params[nparams].lam3 = atof(words[5]);
params[nparams].c = atof(words[6]);
params[nparams].d = atof(words[7]);
params[nparams].h = atof(words[8]);
params[nparams].powern = atof(words[9]);
params[nparams].beta = atof(words[10]);
params[nparams].lam2 = atof(words[11]);
params[nparams].bigb = atof(words[12]);
params[nparams].bigr = atof(words[13]);
params[nparams].bigd = atof(words[14]);
params[nparams].lam1 = atof(words[15]);
params[nparams].biga = atof(words[16]);
// currently only allow m exponent of 1 or 3
params[nparams].powermint = int(params[nparams].powerm);
if (params[nparams].c < 0.0 || params[nparams].d < 0.0 ||
params[nparams].powern < 0.0 || params[nparams].beta < 0.0 ||
params[nparams].lam2 < 0.0 || params[nparams].bigb < 0.0 ||
params[nparams].bigr < 0.0 ||params[nparams].bigd < 0.0 ||
params[nparams].bigd > params[nparams].bigr ||
params[nparams].lam1 < 0.0 || params[nparams].biga < 0.0 ||
params[nparams].powerm - params[nparams].powermint != 0.0 ||
(params[nparams].powermint != 3 && params[nparams].powermint != 1) ||
params[nparams].gamma < 0.0)
error->all(FLERR,"Illegal GW parameter");
nparams++;
}
delete [] words;
}
/* ---------------------------------------------------------------------- */
void PairGW::setup_params()
{
int i,j,k,m,n;
// set elem2param for all element triplet combinations
// must be a single exact match to lines read from file
// do not allow for ACB in place of ABC
memory->destroy(elem2param);
memory->create(elem2param,nelements,nelements,nelements,"pair:elem2param");
for (i = 0; i < nelements; i++)
for (j = 0; j < nelements; j++)
for (k = 0; k < nelements; k++) {
n = -1;
for (m = 0; m < nparams; m++) {
if (i == params[m].ielement && j == params[m].jelement &&
k == params[m].kelement) {
if (n >= 0) error->all(FLERR,"Potential file has duplicate entry");
n = m;
}
}
if (n < 0) error->all(FLERR,"Potential file is missing an entry");
elem2param[i][j][k] = n;
}
// compute parameter values derived from inputs
for (m = 0; m < nparams; m++) {
params[m].cut = params[m].bigr + params[m].bigd;
params[m].cutsq = params[m].cut*params[m].cut;
params[m].c1 = pow(2.0*params[m].powern*1.0e-16,-1.0/params[m].powern);
params[m].c2 = pow(2.0*params[m].powern*1.0e-8,-1.0/params[m].powern);
params[m].c3 = 1.0/params[m].c2;
params[m].c4 = 1.0/params[m].c1;
}
// set cutmax to max of all params
cutmax = 0.0;
for (m = 0; m < nparams; m++)
if (params[m].cut > cutmax) cutmax = params[m].cut;
}
/* ---------------------------------------------------------------------- */
void PairGW::repulsive(Param *param, double rsq, double &fforce,
int eflag, double &eng)
{
double r,tmp_fc,tmp_fc_d,tmp_exp;
r = sqrt(rsq);
tmp_fc = gw_fc(r,param);
tmp_fc_d = gw_fc_d(r,param);
tmp_exp = exp(-param->lam1 * r);
fforce = -param->biga * tmp_exp * (tmp_fc_d - tmp_fc*param->lam1) / r;
if (eflag) eng = tmp_fc * param->biga * tmp_exp;
}
/* ---------------------------------------------------------------------- */
double PairGW::zeta(Param *param, double rsqij, double rsqik,
double *delrij, double *delrik)
{
double rij,rik,costheta,arg,ex_delr;
rij = sqrt(rsqij);
rik = sqrt(rsqik);
costheta = (delrij[0]*delrik[0] + delrij[1]*delrik[1] +
delrij[2]*delrik[2]) / (rij*rik);
if (param->powermint == 3) arg = pow(param->lam3 * (rij-rik),3.0);
else arg = param->lam3 * (rij-rik);
if (arg > 69.0776) ex_delr = 1.e30;
else if (arg < -69.0776) ex_delr = 0.0;
else ex_delr = exp(arg);
return gw_fc(rik,param) * gw_gijk(costheta,param) * ex_delr;
}
/* ---------------------------------------------------------------------- */
void PairGW::force_zeta(Param *param_i, double rsq, double zeta_ij,
double &fforce, double &prefactor,
int eflag, double &eng)
{
double r,fa,fa_d,bij;
r = sqrt(rsq);
fa = gw_fa(r,param_i);
fa_d = gw_fa_d(r,param_i);
bij = gw_bij(zeta_ij,param_i);
fforce = 0.5*bij*fa_d / r;
prefactor = -0.5*fa * gw_bij_d(zeta_ij,param_i);
if (eflag) eng = 0.5*bij*fa;
}
/* ----------------------------------------------------------------------
attractive term
use param_ij cutoff for rij test
use param_ijk cutoff for rik test
------------------------------------------------------------------------- */
void PairGW::attractive(Param *param, double prefactor,
double rsqij, double rsqik,
double *delrij, double *delrik,
double *fi, double *fj, double *fk)
{
double rij_hat[3],rik_hat[3];
double rij,rijinv,rik,rikinv;
rij = sqrt(rsqij);
rijinv = 1.0/rij;
vec3_scale(rijinv,delrij,rij_hat);
rik = sqrt(rsqik);
rikinv = 1.0/rik;
vec3_scale(rikinv,delrik,rik_hat);
gw_zetaterm_d(prefactor,rij_hat,rij,rik_hat,rik,fi,fj,fk,param);
}
/* ---------------------------------------------------------------------- */
double PairGW::gw_fc(double r, Param *param)
{
double gw_R = param->bigr;
double gw_D = param->bigd;
if (r < gw_R-gw_D) return 1.0;
if (r > gw_R+gw_D) return 0.0;
return 0.5*(1.0 - sin(MY_PI2*(r - gw_R)/gw_D));
}
/* ---------------------------------------------------------------------- */
double PairGW::gw_fc_d(double r, Param *param)
{
double gw_R = param->bigr;
double gw_D = param->bigd;
if (r < gw_R-gw_D) return 0.0;
if (r > gw_R+gw_D) return 0.0;
return -(MY_PI4/gw_D) * cos(MY_PI2*(r - gw_R)/gw_D);
}
/* ---------------------------------------------------------------------- */
double PairGW::gw_fa(double r, Param *param)
{
if (r > param->bigr + param->bigd) return 0.0;
return -param->bigb * exp(-param->lam2 * r) * gw_fc(r,param);
}
/* ---------------------------------------------------------------------- */
double PairGW::gw_fa_d(double r, Param *param)
{
if (r > param->bigr + param->bigd) return 0.0;
return param->bigb * exp(-param->lam2 * r) *
(param->lam2 * gw_fc(r,param) - gw_fc_d(r,param));
}
/* ---------------------------------------------------------------------- */
double PairGW::gw_bij(double zeta_ij, Param *param_i)
{
double tmp = param_i->beta * zeta_ij;
return pow(tmp,-param_i->powern);
}
/* ---------------------------------------------------------------------- */
double PairGW::gw_bij_d(double zeta_ij, Param *param_i)
{
double tmp = param_i->beta * zeta_ij;
return - param_i->powern * pow(tmp,-param_i->powern-1)*tmp / zeta_ij;
}
/* ---------------------------------------------------------------------- */
void PairGW::gw_zetaterm_d(double prefactor,
double *rij_hat, double rij,
double *rik_hat, double rik,
double *dri, double *drj, double *drk,
Param *param)
{
double gijk,gijk_d,ex_delr,ex_delr_d,fc,dfc,cos_theta,tmp;
double dcosdri[3],dcosdrj[3],dcosdrk[3];
fc = gw_fc(rik,param);
dfc = gw_fc_d(rik,param);
if (param->powermint == 3) tmp = pow(param->lam3 * (rij-rik),3.0);
else tmp = param->lam3 * (rij-rik);
if (tmp > 69.0776) ex_delr = 1.e30;
else if (tmp < -69.0776) ex_delr = 0.0;
else ex_delr = exp(tmp);
if (param->powermint == 3)
ex_delr_d = 3.0*pow(param->lam3,3.0) * pow(rij-rik,2.0)*ex_delr;
else ex_delr_d = param->lam3 * ex_delr;
cos_theta = vec3_dot(rij_hat,rik_hat);
gijk = gw_gijk(cos_theta,param);
gijk_d = gw_gijk_d(cos_theta,param);
costheta_d(rij_hat,rij,rik_hat,rik,dcosdri,dcosdrj,dcosdrk);
// compute the derivative wrt Ri
// dri = -dfc*gijk*ex_delr*rik_hat;
// dri += fc*gijk_d*ex_delr*dcosdri;
// dri += fc*gijk*ex_delr_d*(rik_hat - rij_hat);
vec3_scale(-dfc*gijk*ex_delr,rik_hat,dri);
vec3_scaleadd(fc*gijk_d*ex_delr,dcosdri,dri,dri);
vec3_scaleadd(fc*gijk*ex_delr_d,rik_hat,dri,dri);
vec3_scaleadd(-fc*gijk*ex_delr_d,rij_hat,dri,dri);
vec3_scale(prefactor,dri,dri);
// compute the derivative wrt Rj
// drj = fc*gijk_d*ex_delr*dcosdrj;
// drj += fc*gijk*ex_delr_d*rij_hat;
vec3_scale(fc*gijk_d*ex_delr,dcosdrj,drj);
vec3_scaleadd(fc*gijk*ex_delr_d,rij_hat,drj,drj);
vec3_scale(prefactor,drj,drj);
// compute the derivative wrt Rk
// drk = dfc*gijk*ex_delr*rik_hat;
// drk += fc*gijk_d*ex_delr*dcosdrk;
// drk += -fc*gijk*ex_delr_d*rik_hat;
vec3_scale(dfc*gijk*ex_delr,rik_hat,drk);
vec3_scaleadd(fc*gijk_d*ex_delr,dcosdrk,drk,drk);
vec3_scaleadd(-fc*gijk*ex_delr_d,rik_hat,drk,drk);
vec3_scale(prefactor,drk,drk);
}
/* ---------------------------------------------------------------------- */
void PairGW::costheta_d(double *rij_hat, double rij,
double *rik_hat, double rik,
double *dri, double *drj, double *drk)
{
// first element is devative wrt Ri, second wrt Rj, third wrt Rk
double cos_theta = vec3_dot(rij_hat,rik_hat);
vec3_scaleadd(-cos_theta,rij_hat,rik_hat,drj);
vec3_scale(1.0/rij,drj,drj);
vec3_scaleadd(-cos_theta,rik_hat,rij_hat,drk);
vec3_scale(1.0/rik,drk,drk);
vec3_add(drj,drk,dri);
vec3_scale(-1.0,dri,dri);
}

196
src/MANYBODY/pair_gw.h Normal file
View File

@ -0,0 +1,196 @@
/* -*- c++ -*- ----------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#ifdef PAIR_CLASS
PairStyle(gw,PairGW)
#else
#ifndef LMP_PAIR_GW_H
#define LMP_PAIR_GW_H
#include "pair.h"
namespace LAMMPS_NS {
class PairGW : public Pair {
public:
PairGW(class LAMMPS *);
virtual ~PairGW();
virtual void compute(int, int);
void settings(int, char **);
void coeff(int, char **);
void init_style();
double init_one(int, int);
protected:
struct Param {
double lam1,lam2,lam3;
double c,d,h;
double gamma,powerm;
double powern,beta;
double biga,bigb,bigd,bigr;
double cut,cutsq;
double c1,c2,c3,c4;
int ielement,jelement,kelement;
int powermint;
double Z_i,Z_j;
double ZBLcut,ZBLexpscale;
};
Param *params; // parameter set for an I-J-K interaction
char **elements; // names of unique elements
int ***elem2param; // mapping from element triplets to paramegw
int *map; // mapping from atom types to elements
double cutmax; // max cutoff for all elements
int nelements; // # of unique elements
int nparams; // # of stored parameter sets
int maxparam; // max # of parameter sets
int **pages; // neighbor list pages
int maxlocal; // size of numneigh, firstneigh arrays
int maxpage; // # of pages currently allocated
int pgsize; // size of neighbor page
int oneatom; // max # of neighbors for one atom
int *GW_numneigh; // # of pair neighbors for each atom
int **GW_firstneigh; // ptr to 1st neighbor of each atom
void GW_neigh();
void add_pages(int howmany = 1);
void allocate();
virtual void read_file(char *);
void setup_params();
virtual void repulsive(Param *, double, double &, int, double &);
double zeta(Param *, double, double, double *, double *);
virtual void force_zeta(Param *, double, double, double &,
double &, int, double &);
void attractive(Param *, double, double, double, double *, double *,
double *, double *, double *);
double gw_fc(double, Param *);
double gw_fc_d(double, Param *);
virtual double gw_fa(double, Param *);
virtual double gw_fa_d(double, Param *);
double gw_bij(double, Param *);
double gw_bij_d(double, Param *);
void gw_zetaterm_d(double, double *, double, double *, double,
double *, double *, double *, Param *);
void costheta_d(double *, double, double *, double,
double *, double *, double *);
// inlined functions for efficiency
inline double gw_gijk(const double costheta,
const Param * const param) const {
const double gw_c = param->c * param->c;
const double gw_d = param->d * param->d;
const double hcth = param->h - costheta;
//printf("gw_gijk: gw_c=%f gw_d=%f hcth=%f=%f-%f\n", gw_c, gw_d, hcth, param->h, costheta);
return param->gamma*(1.0 + gw_c/gw_d - gw_c / (gw_d + hcth*hcth));
}
inline double gw_gijk_d(const double costheta,
const Param * const param) const {
const double gw_c = param->c * param->c;
const double gw_d = param->d * param->d;
const double hcth = param->h - costheta;
const double numerator = -2.0 * gw_c * hcth;
const double denominator = 1.0/(gw_d + hcth*hcth);
return param->gamma*numerator*denominator*denominator;
}
inline double vec3_dot(const double x[3], const double y[3]) const {
return x[0]*y[0] + x[1]*y[1] + x[2]*y[2];
}
inline void vec3_add(const double x[3], const double y[3],
double * const z) const {
z[0] = x[0]+y[0]; z[1] = x[1]+y[1]; z[2] = x[2]+y[2];
}
inline void vec3_scale(const double k, const double x[3],
double y[3]) const {
y[0] = k*x[0]; y[1] = k*x[1]; y[2] = k*x[2];
}
inline void vec3_scaleadd(const double k, const double x[3],
const double y[3], double * const z) const {
z[0] = k*x[0]+y[0];
z[1] = k*x[1]+y[1];
z[2] = k*x[2]+y[2];
}
};
}
#endif
#endif
/* ERROR/WARNING messages:
E: Illegal ... command
Self-explanatory. Check the input script syntax and compare to the
documentation for the command. You can use -echo screen as a
command-line option when running LAMMPS to see the offending line.
E: Incorrect args for pair coefficients
Self-explanatory. Check the input script or data file.
E: Pair style GW requires atom IDs
This is a requirement to use the GW potential.
E: Pair style GW requires newton pair on
See the newton command. This is a restriction to use the GW
potential.
E: All pair coeffs are not set
All pair coefficients must be set in the data file or by the
pair_coeff command before running a simulation.
E: Cannot open GW potential file %s
The specified GW potential file cannot be opened. Check that the
path and name are correct.
E: Incorrect format in GW potential file
Incorrect number of words per line in the potential file.
E: Illegal GW parameter
One or more of the coefficients defined in the potential file is
invalid.
E: Potential file has duplicate entry
The potential file for a SW or GW potential has more than
one entry for the same 3 ordered elements.
E: Potential file is missing an entry
The potential file for a SW or GW potential does not have a
needed entry.
*/

View File

@ -0,0 +1,287 @@
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: German Samolyuk (ORNL)
Based on PairTersoffZBL by Aidan Thompson (SNL) and David Farrell (NWU)
------------------------------------------------------------------------- */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pair_gw_zbl.h"
#include "atom.h"
#include "update.h"
#include "neighbor.h"
#include "neigh_list.h"
#include "neigh_request.h"
#include "force.h"
#include "comm.h"
#include "memory.h"
#include "error.h"
#include "math_const.h"
using namespace LAMMPS_NS;
using namespace MathConst;
#define MAXLINE 1024
#define DELTA 4
/* ---------------------------------------------------------------------- */
PairGWZBL::PairGWZBL(LAMMPS *lmp) : PairGW(lmp)
{
// hard-wired constants in metal or real units
// a0 = Bohr radius
// epsilon0 = permittivity of vacuum = q / energy-distance units
// e = unit charge
// 1 Kcal/mole = 0.043365121 eV
if (strcmp(update->unit_style,"metal") == 0) {
global_a_0 = 0.529;
global_epsilon_0 = 0.00552635;
global_e = 1.0;
} else if (strcmp(update->unit_style,"real") == 0) {
global_a_0 = 0.529;
global_epsilon_0 = 0.00552635 * 0.043365121;
global_e = 1.0;
} else error->all(FLERR,"Pair gw/zbl requires metal or real units");
}
/* ---------------------------------------------------------------------- */
void PairGWZBL::read_file(char *file)
{
int params_per_line = 21;
char **words = new char*[params_per_line+1];
memory->sfree(params);
params = NULL;
nparams = maxparam = 0;
// open file on proc 0
FILE *fp;
if (comm->me == 0) {
fp = force->open_potential(file);
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open GW potential file %s",file);
error->one(FLERR,str);
}
}
// read each line out of file, skipping blank lines or leading '#'
// store line of params if all 3 element tags are in element list
int n,nwords,ielement,jelement,kelement;
char line[MAXLINE],*ptr;
int eof = 0;
while (1) {
if (comm->me == 0) {
ptr = fgets(line,MAXLINE,fp);
if (ptr == NULL) {
eof = 1;
fclose(fp);
} else n = 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);
// strip comment, skip line if blank
if ((ptr = strchr(line,'#'))) *ptr = '\0';
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) {
ptr = fgets(&line[n],MAXLINE-n,fp);
if (ptr == NULL) {
eof = 1;
fclose(fp);
} else n = 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);
if ((ptr = strchr(line,'#'))) *ptr = '\0';
nwords = atom->count_words(line);
}
if (nwords != params_per_line)
error->all(FLERR,"Incorrect format in GW potential file");
// words = ptrs to all words in line
nwords = 0;
words[nwords++] = strtok(line," \t\n\r\f");
while ((words[nwords++] = strtok(NULL," \t\n\r\f"))) continue;
// ielement,jelement,kelement = 1st args
// if all 3 args are in element list, then parse this line
// else skip to next line
for (ielement = 0; ielement < nelements; ielement++)
if (strcmp(words[0],elements[ielement]) == 0) break;
if (ielement == nelements) continue;
for (jelement = 0; jelement < nelements; jelement++)
if (strcmp(words[1],elements[jelement]) == 0) break;
if (jelement == nelements) continue;
for (kelement = 0; kelement < nelements; kelement++)
if (strcmp(words[2],elements[kelement]) == 0) break;
if (kelement == nelements) continue;
// load up parameter settings and error check their values
if (nparams == maxparam) {
maxparam += DELTA;
params = (Param *) memory->srealloc(params,maxparam*sizeof(Param),
"pair:params");
}
params[nparams].ielement = ielement;
params[nparams].jelement = jelement;
params[nparams].kelement = kelement;
params[nparams].powerm = atof(words[3]);
params[nparams].gamma = atof(words[4]);
params[nparams].lam3 = atof(words[5]);
params[nparams].c = atof(words[6]);
params[nparams].d = atof(words[7]);
params[nparams].h = atof(words[8]);
params[nparams].powern = atof(words[9]);
params[nparams].beta = atof(words[10]);
params[nparams].lam2 = atof(words[11]);
params[nparams].bigb = atof(words[12]);
params[nparams].bigr = atof(words[13]);
params[nparams].bigd = atof(words[14]);
params[nparams].lam1 = atof(words[15]);
params[nparams].biga = atof(words[16]);
params[nparams].Z_i = atof(words[17]);
params[nparams].Z_j = atof(words[18]);
params[nparams].ZBLcut = atof(words[19]);
params[nparams].ZBLexpscale = atof(words[20]);
// currently only allow m exponent of 1 or 3
params[nparams].powermint = int(params[nparams].powerm);
if (
params[nparams].lam3 < 0.0 || params[nparams].c < 0.0 ||
params[nparams].d < 0.0 || params[nparams].powern < 0.0 ||
params[nparams].beta < 0.0 || params[nparams].lam2 < 0.0 ||
params[nparams].bigb < 0.0 || params[nparams].bigr < 0.0 ||
params[nparams].bigd < 0.0 ||
params[nparams].bigd > params[nparams].bigr ||
params[nparams].lam3 < 0.0 || params[nparams].biga < 0.0 ||
params[nparams].powerm - params[nparams].powermint != 0.0 ||
(params[nparams].powermint != 3 && params[nparams].powermint != 1) ||
params[nparams].gamma < 0.0 ||
params[nparams].Z_i < 1.0 || params[nparams].Z_j < 1.0 ||
params[nparams].ZBLcut < 0.0 || params[nparams].ZBLexpscale < 0.0)
error->all(FLERR,"Illegal GW parameter");
nparams++;
}
delete [] words;
}
/* ---------------------------------------------------------------------- */
void PairGWZBL::repulsive(Param *param, double rsq, double &fforce,
int eflag, double &eng)
{
double r,tmp_fc,tmp_fc_d,tmp_exp;
// GW repulsive portion
r = sqrt(rsq);
tmp_fc = gw_fc(r,param);
tmp_fc_d = gw_fc_d(r,param);
tmp_exp = exp(-param->lam1 * r);
double fforce_gw = param->biga * tmp_exp * (tmp_fc_d - tmp_fc*param->lam1);
double eng_gw = tmp_fc * param->biga * tmp_exp;
// ZBL repulsive portion
double esq = pow(global_e,2.0);
double a_ij = (0.8854*global_a_0) /
(pow(param->Z_i,0.23) + pow(param->Z_j,0.23));
double premult = (param->Z_i * param->Z_j * esq)/(4.0*MY_PI*global_epsilon_0);
double r_ov_a = r/a_ij;
double phi = 0.1818*exp(-3.2*r_ov_a) + 0.5099*exp(-0.9423*r_ov_a) +
0.2802*exp(-0.4029*r_ov_a) + 0.02817*exp(-0.2016*r_ov_a);
double dphi = (1.0/a_ij) * (-3.2*0.1818*exp(-3.2*r_ov_a) -
0.9423*0.5099*exp(-0.9423*r_ov_a) -
0.4029*0.2802*exp(-0.4029*r_ov_a) -
0.2016*0.02817*exp(-0.2016*r_ov_a));
double fforce_ZBL = premult*-phi/rsq + premult*dphi/r;
double eng_ZBL = premult*(1.0/r)*phi;
// combine two parts with smoothing by Fermi-like function
fforce = -(-F_fermi_d(r,param) * eng_ZBL +
(1.0 - F_fermi(r,param))*fforce_ZBL +
F_fermi_d(r,param)*eng_gw + F_fermi(r,param)*fforce_gw) / r;
if (eflag)
eng = (1.0 - F_fermi(r,param))*eng_ZBL + F_fermi(r,param)*eng_gw;
}
/* ---------------------------------------------------------------------- */
double PairGWZBL::gw_fa(double r, Param *param)
{
if (r > param->bigr + param->bigd) return 0.0;
return -param->bigb * exp(-param->lam2 * r) * gw_fc(r,param) *
F_fermi(r,param);
}
/* ---------------------------------------------------------------------- */
double PairGWZBL::gw_fa_d(double r, Param *param)
{
if (r > param->bigr + param->bigd) return 0.0;
return param->bigb * exp(-param->lam2 * r) *
(param->lam2 * gw_fc(r,param) * F_fermi(r,param) -
gw_fc_d(r,param) * F_fermi(r,param) - gw_fc(r,param) *
F_fermi_d(r,param));
}
/* ----------------------------------------------------------------------
Fermi-like smoothing function
------------------------------------------------------------------------- */
double PairGWZBL::F_fermi(double r, Param *param)
{
return 1.0 / (1.0 + exp(-param->ZBLexpscale*(r-param->ZBLcut)));
}
/* ----------------------------------------------------------------------
Fermi-like smoothing function derivative with respect to r
------------------------------------------------------------------------- */
double PairGWZBL::F_fermi_d(double r, Param *param)
{
return param->ZBLexpscale*exp(-param->ZBLexpscale*(r-param->ZBLcut)) /
pow(1.0 + exp(-param->ZBLexpscale*(r-param->ZBLcut)),2.0);
}

View File

@ -0,0 +1,72 @@
/* -*- c++ -*- ----------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#ifdef PAIR_CLASS
PairStyle(gw/zbl,PairGWZBL)
#else
#ifndef LMP_PAIR_GW_ZBL_H
#define LMP_PAIR_GW_ZBL_H
#include "pair_gw.h"
namespace LAMMPS_NS {
class PairGWZBL : public PairGW {
public:
PairGWZBL(class LAMMPS *);
~PairGWZBL() {}
private:
double global_a_0; // Bohr radius for Coulomb repulsion
double global_epsilon_0; // permittivity of vacuum for Coulomb repulsion
double global_e; // proton charge (negative of electron charge)
void read_file(char *);
void repulsive(Param *, double, double &, int, double &);
double gw_fa(double, Param *);
double gw_fa_d(double, Param *);
double F_fermi(double, Param *);
double F_fermi_d(double, Param *);
};
}
#endif
#endif
/* ERROR/WARNING messages:
E: Pair GW/zbl requires metal or real units
This is a current restriction of this pair potential.
E: Cannot open GW potential file %s
The specified GW potential file cannot be opened. Check that the
path and name are correct.
E: Incorrect format in GW potential file
Incorrect number of words per line in the potential file.
E: Illegal GW parameter
One or more of the coefficients defined in the potential file is
invalid.
*/