diff --git a/doc/src/fix_adapt.rst b/doc/src/fix_adapt.rst index aa34516d52..a110d93a8d 100644 --- a/doc/src/fix_adapt.rst +++ b/doc/src/fix_adapt.rst @@ -188,6 +188,8 @@ formulas for the meaning of these parameters: +------------------------------------------------------------------------------+--------------------------------------------------+-------------+ | :doc:`reax/c ` | chi, eta, gamma | type global | +------------------------------------------------------------------------------+--------------------------------------------------+-------------+ +| :doc:`snap ` | scale | type pairs | ++------------------------------------------------------------------------------+--------------------------------------------------+-------------+ | :doc:`spin/dmi ` | coulombic_cutoff | type global | +------------------------------------------------------------------------------+--------------------------------------------------+-------------+ | :doc:`spin/exchange ` | coulombic_cutoff | type global | diff --git a/doc/src/fix_adapt_fep.rst b/doc/src/fix_adapt_fep.rst index 10a1faf202..0f669eade3 100644 --- a/doc/src/fix_adapt_fep.rst +++ b/doc/src/fix_adapt_fep.rst @@ -173,10 +173,12 @@ styles and their energy formulas for the meaning of these parameters: +------------------------------------------------------------------------------+-------------------------+------------+ | :doc:`nm/cut/coul/cut, nm/cut/coul/long ` | e0,r0,nn,mm | type pairs | +------------------------------------------------------------------------------+-------------------------+------------+ -| :doc:`ufm ` | epsilon,sigma,scale | type pairs | +| :doc:`snap ` | scale | type pairs | +------------------------------------------------------------------------------+-------------------------+------------+ | :doc:`soft ` | a | type pairs | +------------------------------------------------------------------------------+-------------------------+------------+ +| :doc:`ufm ` | epsilon,sigma,scale | type pairs | ++------------------------------------------------------------------------------+-------------------------+------------+ .. note:: diff --git a/examples/snap/Ni_Zuo_JPCA2020.quadratic.snapcoeff b/examples/snap/Ni_Zuo_JPCA2020.quadratic.snapcoeff new file mode 120000 index 0000000000..9401393007 --- /dev/null +++ b/examples/snap/Ni_Zuo_JPCA2020.quadratic.snapcoeff @@ -0,0 +1 @@ +../../potentials/Ni_Zuo_JPCA2020.quadratic.snapcoeff \ No newline at end of file diff --git a/examples/snap/Ni_Zuo_JPCA2020.quadratic.snapparam b/examples/snap/Ni_Zuo_JPCA2020.quadratic.snapparam new file mode 120000 index 0000000000..a47ada019b --- /dev/null +++ b/examples/snap/Ni_Zuo_JPCA2020.quadratic.snapparam @@ -0,0 +1 @@ +../../potentials/Ni_Zuo_JPCA2020.quadratic.snapparam \ No newline at end of file diff --git a/examples/snap/Ni_Zuo_JPCA2020.snapcoeff b/examples/snap/Ni_Zuo_JPCA2020.snapcoeff new file mode 120000 index 0000000000..7211856b43 --- /dev/null +++ b/examples/snap/Ni_Zuo_JPCA2020.snapcoeff @@ -0,0 +1 @@ +../../potentials/Ni_Zuo_JPCA2020.snapcoeff \ No newline at end of file diff --git a/examples/snap/Ni_Zuo_JPCA2020.snapparam b/examples/snap/Ni_Zuo_JPCA2020.snapparam new file mode 120000 index 0000000000..b7fc095fab --- /dev/null +++ b/examples/snap/Ni_Zuo_JPCA2020.snapparam @@ -0,0 +1 @@ +../../potentials/Ni_Zuo_JPCA2020.snapparam \ No newline at end of file diff --git a/examples/snap/in.snap.scale.Ni_Zuo_JCPA2020 b/examples/snap/in.snap.scale.Ni_Zuo_JCPA2020 new file mode 100644 index 0000000000..ee195c11f3 --- /dev/null +++ b/examples/snap/in.snap.scale.Ni_Zuo_JCPA2020 @@ -0,0 +1,53 @@ +# Toy demonstration of SNAP "scale" parameter, using fix/adapt and hybrid/overlay +# Mixing linear and quadratic SNAP Ni potentials by Zuo et al. JCPA 2020 + +# mixing parameter + +variable lambda equal 0.2 + + +# Initialize simulation + +variable nsteps index 100 +variable nrep equal 3 +variable a equal 3.52 +units metal + +# generate the box and atom positions using a FCC lattice +variable nx equal ${nrep} +variable ny equal ${nrep} +variable nz equal ${nrep} + +boundary p p p + +lattice fcc $a +region box block 0 ${nx} 0 ${ny} 0 ${nz} +create_box 1 box +create_atoms 1 box + +mass 1 34. + +# choose bundled SNAP Ni potential from Zuo et al. JCPA 2020 +pair_style hybrid/overlay snap snap +pair_coeff * * snap 1 Ni_Zuo_JPCA2020.snapcoeff Ni_Zuo_JPCA2020.snapparam Ni +pair_coeff * * snap 2 Ni_Zuo_JPCA2020.quadratic.snapcoeff Ni_Zuo_JPCA2020.quadratic.snapparam Ni + +# scale according to mixing parameter +variable l1 equal ${lambda} +variable l2 equal 1.0-${lambda} +fix scale1 all adapt 1 pair snap:1 scale * * v_l1 +fix scale2 all adapt 1 pair snap:2 scale * * v_l2 + +# Setup output +thermo 1 +thermo_modify norm yes + +# Set up NVE run +timestep 0.5e-3 +neighbor 1.0 bin +neigh_modify every 1 delay 0 check yes + +# Run MD +velocity all create 300.0 4928459 loop geom +fix 1 all nve +run ${nsteps} diff --git a/src/ML-SNAP/pair_snap.cpp b/src/ML-SNAP/pair_snap.cpp index b8d8333902..dd023e096c 100644 --- a/src/ML-SNAP/pair_snap.cpp +++ b/src/ML-SNAP/pair_snap.cpp @@ -70,6 +70,7 @@ PairSNAP::~PairSNAP() if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); + memory->destroy(scale); } } @@ -164,6 +165,7 @@ void PairSNAP::compute(int eflag, int vflag) // for neighbors of I within cutoff: // compute Fij = dEi/dRj = -dEi/dRi // add to Fi, subtract from Fj + // scaling is that for type I snaptr->compute_yi(beta[ii]); @@ -178,12 +180,12 @@ void PairSNAP::compute(int eflag, int vflag) snaptr->compute_deidrj(fij); - f[i][0] += fij[0]; - f[i][1] += fij[1]; - f[i][2] += fij[2]; - f[j][0] -= fij[0]; - f[j][1] -= fij[1]; - f[j][2] -= fij[2]; + f[i][0] += fij[0]*scale[itype][itype]; + f[i][1] += fij[1]*scale[itype][itype]; + f[i][2] += fij[2]*scale[itype][itype]; + f[j][0] -= fij[0]*scale[itype][itype]; + f[j][1] -= fij[1]*scale[itype][itype]; + f[j][2] -= fij[2]*scale[itype][itype]; // tally per-atom virial contribution @@ -224,6 +226,7 @@ void PairSNAP::compute(int eflag, int vflag) } } } + evdwl *= scale[itype][itype]; ev_tally_full(i,2.0*evdwl,0.0,0.0,0.0,0.0,0.0); } @@ -351,9 +354,9 @@ void PairSNAP::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"); + memory->create(scale,n+1,n+1,"pair:scale"); map = new int[n+1]; } @@ -408,11 +411,16 @@ void PairSNAP::coeff(int narg, char **arg) } // Calculate maximum cutoff for all elements - rcutmax = 0.0; for (int ielem = 0; ielem < nelements; ielem++) rcutmax = MAX(2.0*radelem[ielem]*rcutfac,rcutmax); + // set default scaling + int n = atom->ntypes; + for (int ii = 0; ii < n+1; ii++) + for (int jj = 0; jj < n+1; jj++) + scale[ii][jj] = 1.0; + } /* ---------------------------------------------------------------------- @@ -441,6 +449,7 @@ void PairSNAP::init_style() double PairSNAP::init_one(int i, int j) { if (setflag[i][j] == 0) error->all(FLERR,"All pair coeffs are not set"); + scale[j][i] = scale[i][j]; return (radelem[map[i]] + radelem[map[j]])*rcutfac; } @@ -711,6 +720,7 @@ double PairSNAP::memory_usage() int n = atom->ntypes+1; bytes += (double)n*n*sizeof(int); // setflag bytes += (double)n*n*sizeof(double); // cutsq + bytes += (double)n*n*sizeof(double); // scale bytes += (double)n*sizeof(int); // map bytes += (double)beta_max*ncoeff*sizeof(double); // bispectrum bytes += (double)beta_max*ncoeff*sizeof(double); // beta @@ -720,3 +730,9 @@ double PairSNAP::memory_usage() return bytes; } +void *PairSNAP::extract(const char *str, int &dim) +{ + dim = 2; + if (strcmp(str,"scale") == 0) return (void *) scale; + return nullptr; +} diff --git a/src/ML-SNAP/pair_snap.h b/src/ML-SNAP/pair_snap.h index 0cc38ef9cb..afce4bf895 100644 --- a/src/ML-SNAP/pair_snap.h +++ b/src/ML-SNAP/pair_snap.h @@ -34,6 +34,7 @@ class PairSNAP : public Pair { virtual void init_style(); virtual double init_one(int, int); virtual double memory_usage(); + virtual void *extract(const char *, int &); double rcutfac, quadraticflag; // declared public to workaround gcc 4.9 int ncoeff; // compiler bug, manifest in KOKKOS package @@ -55,6 +56,7 @@ class PairSNAP : public Pair { double **coeffelem; // element bispectrum coefficients double **beta; // betas for all atoms in list double **bispectrum; // bispectrum components for all atoms in list + double **scale; // for thermodynamic integration int twojmax, switchflag, bzeroflag, bnormflag; int chemflag, wselfallflag; int chunksize; diff --git a/unittest/force-styles/tests/manybody-pair-snap.yaml b/unittest/force-styles/tests/manybody-pair-snap.yaml index 139d1b94d0..57e0e9d599 100644 --- a/unittest/force-styles/tests/manybody-pair-snap.yaml +++ b/unittest/force-styles/tests/manybody-pair-snap.yaml @@ -14,7 +14,8 @@ pair_style: hybrid/overlay zbl 4.0 4.8 snap pair_coeff: ! | 1*8 1*8 zbl 73 73 * * snap Ta06A.snapcoeff Ta06A.snapparam Ta Ta Ta Ta Ta Ta Ta Ta -extract: ! "" +extract: ! | + scale 2 natoms: 64 init_vdwl: -473.569864629026 init_coul: 0 diff --git a/unittest/force-styles/tests/manybody-pair-snap_chem.yaml b/unittest/force-styles/tests/manybody-pair-snap_chem.yaml index 39d2abd804..b97709863e 100644 --- a/unittest/force-styles/tests/manybody-pair-snap_chem.yaml +++ b/unittest/force-styles/tests/manybody-pair-snap_chem.yaml @@ -16,7 +16,8 @@ pair_coeff: ! | 1*4 5*8 zbl 49 15 5*8 5*8 zbl 15 15 * * snap InP_JCPA2020.snapcoeff InP_JCPA2020.snapparam In In In In P P P P -extract: ! "" +extract: ! | + scale 2 natoms: 64 init_vdwl: -185.3871232982 init_coul: 0