From d2b5f557379fdd8f7abb4ed6886aeb4028968084 Mon Sep 17 00:00:00 2001 From: EiPi Fun Date: Sun, 1 Sep 2024 16:07:52 +0800 Subject: [PATCH 01/70] Copy and rename base files --- .../pair_hbond_dreiding_lj_angleoffset.cpp | 572 ++++++++++++++++++ .../pair_hbond_dreiding_lj_angleoffset.h | 66 ++ .../pair_hbond_dreiding_morse_angleoffset.cpp | 474 +++++++++++++++ .../pair_hbond_dreiding_morse_angleoffset.h | 40 ++ ...pair_hbond_dreiding_lj_angleoffset_omp.cpp | 317 ++++++++++ .../pair_hbond_dreiding_lj_angleoffset_omp.h | 52 ++ ...r_hbond_dreiding_morse_angleoffset_omp.cpp | 316 ++++++++++ ...air_hbond_dreiding_morse_angleoffset_omp.h | 52 ++ 8 files changed, 1889 insertions(+) create mode 100644 src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp create mode 100644 src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.h create mode 100644 src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp create mode 100644 src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h create mode 100644 src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.cpp create mode 100644 src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.h create mode 100644 src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.cpp create mode 100644 src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.h diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp new file mode 100644 index 0000000000..274f8bc2a3 --- /dev/null +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp @@ -0,0 +1,572 @@ +// clang-format off +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS development team: developers@lammps.org + + 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: Tod A Pascal (Caltech) +------------------------------------------------------------------------- */ + +#include "pair_hbond_dreiding_lj.h" + +#include "atom.h" +#include "atom_vec.h" +#include "domain.h" +#include "error.h" +#include "force.h" +#include "math_const.h" +#include "math_special.h" +#include "memory.h" +#include "molecule.h" +#include "neigh_list.h" +#include "neighbor.h" + +#include +#include + +using namespace LAMMPS_NS; +using namespace MathConst; +using namespace MathSpecial; + +static constexpr double SMALL = 0.001; +static constexpr int CHUNK = 8; + +/* ---------------------------------------------------------------------- */ + +PairHbondDreidingLJ::PairHbondDreidingLJ(LAMMPS *lmp) : Pair(lmp) +{ + // hbond cannot compute virial as F dot r + // due to using map() to find bonded H atoms which are not near donor atom + + no_virial_fdotr_compute = 1; + restartinfo = 0; + + nparams = maxparam = 0; + params = nullptr; + + nextra = 2; + pvector = new double[2]; +} + +/* ---------------------------------------------------------------------- */ + +PairHbondDreidingLJ::~PairHbondDreidingLJ() +{ + memory->sfree(params); + delete [] pvector; + + if (allocated) { + memory->destroy(setflag); + memory->destroy(cutsq); + + delete [] donor; + delete [] acceptor; + memory->destroy(type2param); + } +} + +/* ---------------------------------------------------------------------- */ + +void PairHbondDreidingLJ::compute(int eflag, int vflag) +{ + int i,j,k,m,ii,jj,kk,inum,jnum,knum,itype,jtype,ktype,iatom,imol; + tagint tagprev; + double delx,dely,delz,rsq,rsq1,rsq2,r1,r2; + double factor_hb,force_angle,force_kernel,evdwl,eng_lj,ehbond,force_switch; + double c,s,a,b,ac,a11,a12,a22,vx1,vx2,vy1,vy2,vz1,vz2,d; + double fi[3],fj[3],delr1[3],delr2[3]; + double r2inv,r10inv; + double switch1,switch2; + int *ilist,*jlist,*numneigh,**firstneigh; + tagint *klist; + + evdwl = ehbond = 0.0; + ev_init(eflag,vflag); + + double **x = atom->x; + double **f = atom->f; + tagint *tag = atom->tag; + int *molindex = atom->molindex; + int *molatom = atom->molatom; + tagint **special = atom->special; + int **nspecial = atom->nspecial; + int *type = atom->type; + double *special_lj = force->special_lj; + int molecular = atom->molecular; + Molecule **onemols = atom->avec->onemols; + + inum = list->inum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; + + // ii = loop over donors + // jj = loop over acceptors + // kk = loop over hydrogens bonded to donor + + int hbcount = 0; + + for (ii = 0; ii < inum; ii++) { + i = ilist[ii]; + itype = type[i]; + if (!donor[itype]) continue; + if (molecular == Atom::MOLECULAR) { + klist = special[i]; + knum = nspecial[i][0]; + } else { + if (molindex[i] < 0) continue; + imol = molindex[i]; + iatom = molatom[i]; + klist = onemols[imol]->special[iatom]; + knum = onemols[imol]->nspecial[iatom][0]; + tagprev = tag[i] - iatom - 1; + } + jlist = firstneigh[i]; + jnum = numneigh[i]; + + for (jj = 0; jj < jnum; jj++) { + j = jlist[jj]; + factor_hb = special_lj[sbmask(j)]; + j &= NEIGHMASK; + + jtype = type[j]; + if (!acceptor[jtype]) continue; + + delx = x[i][0] - x[j][0]; + dely = x[i][1] - x[j][1]; + delz = x[i][2] - x[j][2]; + rsq = delx*delx + dely*dely + delz*delz; + + for (kk = 0; kk < knum; kk++) { + if (molecular == Atom::MOLECULAR) k = atom->map(klist[kk]); + else k = atom->map(klist[kk]+tagprev); + if (k < 0) continue; + ktype = type[k]; + m = type2param[itype][jtype][ktype]; + if (m < 0) continue; + const Param &pm = params[m]; + + if (rsq < pm.cut_outersq) { + delr1[0] = x[i][0] - x[k][0]; + delr1[1] = x[i][1] - x[k][1]; + delr1[2] = x[i][2] - x[k][2]; + domain->minimum_image(delr1); + rsq1 = delr1[0]*delr1[0] + delr1[1]*delr1[1] + delr1[2]*delr1[2]; + r1 = sqrt(rsq1); + + delr2[0] = x[j][0] - x[k][0]; + delr2[1] = x[j][1] - x[k][1]; + delr2[2] = x[j][2] - x[k][2]; + domain->minimum_image(delr2); + rsq2 = delr2[0]*delr2[0] + delr2[1]*delr2[1] + delr2[2]*delr2[2]; + r2 = sqrt(rsq2); + + // angle (cos and sin) + + c = delr1[0]*delr2[0] + delr1[1]*delr2[1] + delr1[2]*delr2[2]; + c /= r1*r2; + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; + ac = acos(c); + + if (ac > pm.cut_angle && ac < (2.0*MY_PI - pm.cut_angle)) { + s = sqrt(1.0 - c*c); + if (s < SMALL) s = SMALL; + + // LJ-specific kernel + + r2inv = 1.0/rsq; + r10inv = r2inv*r2inv*r2inv*r2inv*r2inv; + force_kernel = r10inv*(pm.lj1*r2inv - pm.lj2)*r2inv * + powint(c,pm.ap); + force_angle = pm.ap * r10inv*(pm.lj3*r2inv - pm.lj4) * + powint(c,pm.ap-1)*s; + + eng_lj = r10inv*(pm.lj3*r2inv - pm.lj4); + + force_switch=0.0; + + if (rsq > pm.cut_innersq) { + switch1 = (pm.cut_outersq-rsq) * (pm.cut_outersq-rsq) * + (pm.cut_outersq + 2.0*rsq - 3.0*pm.cut_innersq) / + pm.denom_vdw; + switch2 = 12.0*rsq * (pm.cut_outersq-rsq) * + (rsq-pm.cut_innersq) / pm.denom_vdw; + + force_kernel *= switch1; + force_angle *= switch1; + force_switch = eng_lj*switch2/rsq; + eng_lj *= switch1; + } + + if (eflag) { + evdwl = eng_lj * powint(c,pm.ap); + evdwl *= factor_hb; + ehbond += evdwl; + } + + a = factor_hb*force_angle/s; + b = factor_hb*force_kernel; + d = factor_hb*force_switch; + + a11 = a*c / rsq1; + a12 = -a / (r1*r2); + a22 = a*c / rsq2; + + vx1 = a11*delr1[0] + a12*delr2[0]; + vx2 = a22*delr2[0] + a12*delr1[0]; + vy1 = a11*delr1[1] + a12*delr2[1]; + vy2 = a22*delr2[1] + a12*delr1[1]; + vz1 = a11*delr1[2] + a12*delr2[2]; + vz2 = a22*delr2[2] + a12*delr1[2]; + + fi[0] = vx1 + b*delx + d*delx; + fi[1] = vy1 + b*dely + d*dely; + fi[2] = vz1 + b*delz + d*delz; + fj[0] = vx2 - b*delx - d*delx; + fj[1] = vy2 - b*dely - d*dely; + fj[2] = vz2 - b*delz - d*delz; + + 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] -= vx1 + vx2; + f[k][1] -= vy1 + vy2; + f[k][2] -= vz1 + vz2; + + // KIJ instead of IJK b/c delr1/delr2 are both with respect to k + + if (evflag) ev_tally3(k,i,j,evdwl,0.0,fi,fj,delr1,delr2); + + hbcount++; + } + } + } + } + } + + if (eflag_global) { + pvector[0] = hbcount; + pvector[1] = ehbond; + } +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +void PairHbondDreidingLJ::allocate() +{ + allocated = 1; + int n = atom->ntypes; + + // mark all setflag as set, since don't require pair_coeff of all I,J + + memory->create(setflag,n+1,n+1,"pair:setflag"); + for (int i = 1; i <= n; i++) + for (int j = i; j <= n; j++) + setflag[i][j] = 1; + + memory->create(cutsq,n+1,n+1,"pair:cutsq"); + + donor = new int[n+1]; + acceptor = new int[n+1]; + memory->create(type2param,n+1,n+1,n+1,"pair:type2param"); + + int i,j,k; + for (i = 1; i <= n; i++) + for (j = 1; j <= n; j++) + for (k = 1; k <= n; k++) + type2param[i][j][k] = -1; +} + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +void PairHbondDreidingLJ::settings(int narg, char **arg) +{ + if (narg != 4) error->all(FLERR,"Illegal pair_style command"); + + ap_global = utils::inumeric(FLERR,arg[0],false,lmp); + cut_inner_global = utils::numeric(FLERR,arg[1],false,lmp); + cut_outer_global = utils::numeric(FLERR,arg[2],false,lmp); + cut_angle_global = utils::numeric(FLERR,arg[3],false,lmp) * MY_PI/180.0; +} + +/* ---------------------------------------------------------------------- + set coeffs for one or more type pairs +------------------------------------------------------------------------- */ + +void PairHbondDreidingLJ::coeff(int narg, char **arg) +{ + if (narg < 6 || narg > 10) + error->all(FLERR,"Incorrect args for pair coefficients"); + if (!allocated) allocate(); + + int ilo,ihi,jlo,jhi,klo,khi; + utils::bounds(FLERR, arg[0], 1, atom->ntypes, ilo, ihi, error); + utils::bounds(FLERR, arg[1], 1, atom->ntypes, jlo, jhi, error); + utils::bounds_typelabel(FLERR, arg[2], 1, atom->ntypes, klo, khi, lmp, Atom::ATOM); + + int donor_flag; + if (strcmp(arg[3],"i") == 0) donor_flag = 0; + else if (strcmp(arg[3],"j") == 0) donor_flag = 1; + else error->all(FLERR,"Incorrect args for pair coefficients"); + + double epsilon_one = utils::numeric(FLERR, arg[4], false, lmp); + double sigma_one = utils::numeric(FLERR, arg[5], false, lmp); + + int ap_one = ap_global; + if (narg > 6) ap_one = utils::inumeric(FLERR, arg[6], false, lmp); + double cut_inner_one = cut_inner_global; + double cut_outer_one = cut_outer_global; + if (narg > 8) { + cut_inner_one = utils::numeric(FLERR, arg[7], false, lmp); + cut_outer_one = utils::numeric(FLERR, arg[8], false, lmp); + } + if (cut_inner_one>cut_outer_one) + error->all(FLERR,"Pair inner cutoff >= Pair outer cutoff"); + double cut_angle_one = cut_angle_global; + if (narg == 10) cut_angle_one = utils::numeric(FLERR, arg[9], false, lmp) * MY_PI/180.0; + // grow params array if necessary + + if (nparams == maxparam) { + maxparam += CHUNK; + params = (Param *) memory->srealloc(params, maxparam*sizeof(Param), + "pair:params"); + + // make certain all addional allocated storage is initialized + // to avoid false positives when checking with valgrind + + memset(params + nparams, 0, CHUNK*sizeof(Param)); + } + + params[nparams].epsilon = epsilon_one; + params[nparams].sigma = sigma_one; + params[nparams].ap = ap_one; + params[nparams].cut_inner = cut_inner_one; + params[nparams].cut_outer = cut_outer_one; + params[nparams].cut_innersq = cut_inner_one*cut_inner_one; + params[nparams].cut_outersq = cut_outer_one*cut_outer_one; + params[nparams].cut_angle = cut_angle_one; + params[nparams].denom_vdw = + (params[nparams].cut_outersq-params[nparams].cut_innersq) * + (params[nparams].cut_outersq-params[nparams].cut_innersq) * + (params[nparams].cut_outersq-params[nparams].cut_innersq); + + // flag type2param with either i,j = D,A or j,i = D,A + + int count = 0; + for (int i = ilo; i <= ihi; i++) + for (int j = MAX(jlo,i); j <= jhi; j++) + for (int k = klo; k <= khi; k++) { + if (donor_flag == 0) type2param[i][j][k] = nparams; + else type2param[j][i][k] = nparams; + count++; + } + nparams++; + + if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +void PairHbondDreidingLJ::init_style() +{ + // molecular system required to use special list to find H atoms + // tags required to use special list + // pair newton on required since are looping over D atoms + // and computing forces on A,H which may be on different procs + + if (atom->molecular == Atom::ATOMIC) + error->all(FLERR,"Pair style hbond/dreiding requires molecular system"); + if (atom->tag_enable == 0) + error->all(FLERR,"Pair style hbond/dreiding requires atom IDs"); + if (atom->map_style == Atom::MAP_NONE) + error->all(FLERR,"Pair style hbond/dreiding requires an atom map, " + "see atom_modify"); + if (force->newton_pair == 0) + error->all(FLERR,"Pair style hbond/dreiding requires newton pair on"); + + // set donor[M]/acceptor[M] if any atom of type M is a donor/acceptor + + int anyflag = 0; + int n = atom->ntypes; + for (int m = 1; m <= n; m++) donor[m] = acceptor[m] = 0; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= n; j++) + for (int k = 1; k <= n; k++) + if (type2param[i][j][k] >= 0) { + anyflag = 1; + donor[i] = 1; + acceptor[j] = 1; + } + + if (!anyflag) error->all(FLERR,"No pair hbond/dreiding coefficients set"); + + // set additional param values + // offset is for LJ only, angle term is not included + + for (int m = 0; m < nparams; m++) { + params[m].lj1 = 60.0*params[m].epsilon*pow(params[m].sigma,12.0); + params[m].lj2 = 60.0*params[m].epsilon*pow(params[m].sigma,10.0); + params[m].lj3 = 5.0*params[m].epsilon*pow(params[m].sigma,12.0); + params[m].lj4 = 6.0*params[m].epsilon*pow(params[m].sigma,10.0); + + /* + if (offset_flag) { + double ratio = params[m].sigma / params[m].cut_outer; + params[m].offset = params[m].epsilon * + ((2.0*pow(ratio,9.0)) - (3.0*pow(ratio,6.0))); + } else params[m].offset = 0.0; + */ + } + + // full neighbor list request + + neighbor->add_request(this, NeighConst::REQ_FULL); +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +double PairHbondDreidingLJ::init_one(int i, int j) +{ + int m; + + // return maximum cutoff for any K with I,J = D,A or J,I = D,A + // donor/acceptor is not symmetric, IJ interaction != JI interaction + + double cut = 0.0; + for (int k = 1; k <= atom->ntypes; k++) { + m = type2param[i][j][k]; + if (m >= 0) cut = MAX(cut,params[m].cut_outer); + m = type2param[j][i][k]; + if (m >= 0) cut = MAX(cut,params[m].cut_outer); + } + return cut; +} + +/* ---------------------------------------------------------------------- */ + +double PairHbondDreidingLJ::single(int i, int j, int itype, int jtype, + double rsq, + double /*factor_coul*/, double /*factor_lj*/, + double &fforce) +{ + int k,kk,ktype,knum,m; + tagint tagprev; + double eng,eng_lj,force_kernel,force_angle; + double rsq1,rsq2,r1,r2,c,s,ac,r2inv,r10inv,factor_hb; + double switch1,switch2; + double delr1[3],delr2[3]; + tagint *klist; + + double **x = atom->x; + int *type = atom->type; + double *special_lj = force->special_lj; + + eng = 0.0; + fforce = 0; + + // sanity check + + if (!donor[itype]) return 0.0; + if (!acceptor[jtype]) return 0.0; + + int molecular = atom->molecular; + if (molecular == Atom::MOLECULAR) { + klist = atom->special[i]; + knum = atom->nspecial[i][0]; + } else { + if (atom->molindex[i] < 0) return 0.0; + int imol = atom->molindex[i]; + int iatom = atom->molatom[i]; + Molecule **onemols = atom->avec->onemols; + klist = onemols[imol]->special[iatom]; + knum = onemols[imol]->nspecial[iatom][0]; + tagprev = atom->tag[i] - iatom - 1; + } + + factor_hb = special_lj[sbmask(j)]; + + for (kk = 0; kk < knum; kk++) { + if (molecular == Atom::MOLECULAR) k = atom->map(klist[kk]); + else k = atom->map(klist[kk]+tagprev); + + if (k < 0) continue; + ktype = type[k]; + m = type2param[itype][jtype][ktype]; + if (m < 0) continue; + const Param &pm = params[m]; + + delr1[0] = x[i][0] - x[k][0]; + delr1[1] = x[i][1] - x[k][1]; + delr1[2] = x[i][2] - x[k][2]; + domain->minimum_image(delr1); + rsq1 = delr1[0]*delr1[0] + delr1[1]*delr1[1] + delr1[2]*delr1[2]; + r1 = sqrt(rsq1); + + delr2[0] = x[j][0] - x[k][0]; + delr2[1] = x[j][1] - x[k][1]; + delr2[2] = x[j][2] - x[k][2]; + domain->minimum_image(delr2); + rsq2 = delr2[0]*delr2[0] + delr2[1]*delr2[1] + delr2[2]*delr2[2]; + r2 = sqrt(rsq2); + + // angle (cos and sin) + + c = delr1[0]*delr2[0] + delr1[1]*delr2[1] + delr1[2]*delr2[2]; + c /= r1*r2; + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; + ac = acos(c); + + if (ac < pm.cut_angle || ac > (2.0*MY_PI - pm.cut_angle)) return 0.0; + s = sqrt(1.0 - c*c); + if (s < SMALL) s = SMALL; + + // LJ-specific kernel + + r2inv = 1.0/rsq; + r10inv = r2inv*r2inv*r2inv*r2inv*r2inv; + force_kernel = r10inv*(pm.lj1*r2inv - pm.lj2)*r2inv * powint(c,pm.ap); + force_angle = pm.ap * r10inv*(pm.lj3*r2inv - pm.lj4) * + powint(c,pm.ap-1)*s; + + // only lj part for now + + eng_lj = r10inv*(pm.lj3*r2inv - pm.lj4); + if (rsq > pm.cut_innersq) { + switch1 = (pm.cut_outersq-rsq) * (pm.cut_outersq-rsq) * + (pm.cut_outersq + 2.0*rsq - 3.0*pm.cut_innersq) / pm.denom_vdw; + switch2 = 12.0*rsq * (pm.cut_outersq-rsq) * + (rsq-pm.cut_innersq) / pm.denom_vdw; + force_kernel = force_kernel*switch1 + eng_lj*switch2; + eng_lj *= switch1; + } + + fforce += force_kernel*powint(c,pm.ap) + eng_lj*force_angle; + eng += eng_lj * powint(c,pm.ap) * factor_hb; + } + + return eng; +} diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.h b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.h new file mode 100644 index 0000000000..91a906c5cb --- /dev/null +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.h @@ -0,0 +1,66 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS development team: developers@lammps.org + + 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 +// clang-format off +PairStyle(hbond/dreiding/lj,PairHbondDreidingLJ); +// clang-format on +#else + +#ifndef LMP_PAIR_HBOND_DREIDING_LJ_H +#define LMP_PAIR_HBOND_DREIDING_LJ_H + +#include "pair.h" + +namespace LAMMPS_NS { + +class PairHbondDreidingLJ : public Pair { + public: + PairHbondDreidingLJ(class LAMMPS *); + ~PairHbondDreidingLJ() override; + void compute(int, int) override; + void settings(int, char **) override; + void coeff(int, char **) override; + void init_style() override; + double init_one(int, int) override; + double single(int, int, int, int, double, double, double, double &) override; + + protected: + double cut_inner_global, cut_outer_global, cut_angle_global; + int ap_global; + + struct Param { + double epsilon, sigma; + double lj1, lj2, lj3, lj4; + double d0, alpha, r0; + double morse1; + double denom_vdw; + double cut_inner, cut_outer, cut_innersq, cut_outersq, cut_angle, offset; + int ap; + }; + + Param *params; // parameter set for an I-J-K interaction + int nparams; // number of parameters read + int maxparam; + + int *donor; // 1 if this type is ever a donor, else 0 + int *acceptor; // 1 if this type is ever an acceptor, else 0 + int ***type2param; // mapping from D,A,H to params, -1 if no map + + void allocate(); +}; + +} // namespace LAMMPS_NS + +#endif +#endif diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp new file mode 100644 index 0000000000..c8bc0a627d --- /dev/null +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp @@ -0,0 +1,474 @@ +// clang-format off +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS development team: developers@lammps.org + + 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: Tod A Pascal (Caltech) +------------------------------------------------------------------------- */ + +#include "pair_hbond_dreiding_morse.h" + +#include "atom.h" +#include "atom_vec.h" +#include "domain.h" +#include "error.h" +#include "force.h" +#include "math_const.h" +#include "math_special.h" +#include "memory.h" +#include "molecule.h" +#include "neigh_list.h" +#include "neighbor.h" + +#include +#include + +using namespace LAMMPS_NS; +using namespace MathConst; +using namespace MathSpecial; + +static constexpr double SMALL = 0.001; +static constexpr int CHUNK = 8; + +/* ---------------------------------------------------------------------- */ + +PairHbondDreidingMorse::PairHbondDreidingMorse(LAMMPS *lmp) : + PairHbondDreidingLJ(lmp) {} + +/* ---------------------------------------------------------------------- */ + +void PairHbondDreidingMorse::compute(int eflag, int vflag) +{ + int i,j,k,m,ii,jj,kk,inum,jnum,knum,itype,jtype,ktype,imol,iatom; + tagint tagprev; + double delx,dely,delz,rsq,rsq1,rsq2,r1,r2; + double factor_hb,force_angle,force_kernel,force_switch,evdwl,ehbond; + double c,s,a,b,d,ac,a11,a12,a22,vx1,vx2,vy1,vy2,vz1,vz2; + double fi[3],fj[3],delr1[3],delr2[3]; + double r,dr,dexp,eng_morse,switch1,switch2; + int *ilist,*jlist,*numneigh,**firstneigh; + tagint *klist; + + evdwl = ehbond = 0.0; + ev_init(eflag,vflag); + + double **x = atom->x; + double **f = atom->f; + tagint *tag = atom->tag; + int *molindex = atom->molindex; + int *molatom = atom->molatom; + tagint **special = atom->special; + int **nspecial = atom->nspecial; + int *type = atom->type; + double *special_lj = force->special_lj; + int molecular = atom->molecular; + Molecule **onemols = atom->avec->onemols; + + inum = list->inum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; + + // ii = loop over donors + // jj = loop over acceptors + // kk = loop over hydrogens bonded to donor + + int hbcount = 0; + + for (ii = 0; ii < inum; ii++) { + i = ilist[ii]; + itype = type[i]; + if (!donor[itype]) continue; + if (molecular == Atom::MOLECULAR) { + klist = special[i]; + knum = nspecial[i][0]; + } else { + if (molindex[i] < 0) continue; + imol = molindex[i]; + iatom = molatom[i]; + klist = onemols[imol]->special[iatom]; + knum = onemols[imol]->nspecial[iatom][0]; + tagprev = tag[i] - iatom - 1; + } + jlist = firstneigh[i]; + jnum = numneigh[i]; + + for (jj = 0; jj < jnum; jj++) { + j = jlist[jj]; + factor_hb = special_lj[sbmask(j)]; + j &= NEIGHMASK; + + jtype = type[j]; + if (!acceptor[jtype]) continue; + + delx = x[i][0] - x[j][0]; + dely = x[i][1] - x[j][1]; + delz = x[i][2] - x[j][2]; + rsq = delx*delx + dely*dely + delz*delz; + + for (kk = 0; kk < knum; kk++) { + if (molecular == Atom::MOLECULAR) k = atom->map(klist[kk]); + else k = atom->map(klist[kk]+tagprev); + if (k < 0) continue; + ktype = type[k]; + m = type2param[itype][jtype][ktype]; + if (m < 0) continue; + const Param &pm = params[m]; + + if (rsq < pm.cut_outersq) { + delr1[0] = x[i][0] - x[k][0]; + delr1[1] = x[i][1] - x[k][1]; + delr1[2] = x[i][2] - x[k][2]; + domain->minimum_image(delr1); + rsq1 = delr1[0]*delr1[0] + delr1[1]*delr1[1] + delr1[2]*delr1[2]; + r1 = sqrt(rsq1); + + delr2[0] = x[j][0] - x[k][0]; + delr2[1] = x[j][1] - x[k][1]; + delr2[2] = x[j][2] - x[k][2]; + domain->minimum_image(delr2); + rsq2 = delr2[0]*delr2[0] + delr2[1]*delr2[1] + delr2[2]*delr2[2]; + r2 = sqrt(rsq2); + + // angle (cos and sin) + + c = delr1[0]*delr2[0] + delr1[1]*delr2[1] + delr1[2]*delr2[2]; + c /= r1*r2; + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; + ac = acos(c); + + if (ac > pm.cut_angle && ac < (2.0*MY_PI - pm.cut_angle)) { + s = sqrt(1.0 - c*c); + if (s < SMALL) s = SMALL; + + // Morse-specific kernel + + r = sqrt(rsq); + dr = r - pm.r0; + dexp = exp(-pm.alpha * dr); + eng_morse = pm.d0 * (dexp*dexp - 2.0*dexp); + force_kernel = pm.morse1*(dexp*dexp - dexp)/r * powint(c,pm.ap); + force_angle = pm.ap * eng_morse * powint(c,pm.ap-1)*s; + force_switch = 0.0; + + if (rsq > pm.cut_innersq) { + switch1 = (pm.cut_outersq-rsq) * (pm.cut_outersq-rsq) * + (pm.cut_outersq + 2.0*rsq - 3.0*pm.cut_innersq) / + pm.denom_vdw; + switch2 = 12.0*rsq * (pm.cut_outersq-rsq) * + (rsq-pm.cut_innersq) / pm.denom_vdw; + + force_kernel *= switch1; + force_angle *= switch1; + force_switch = eng_morse*switch2/rsq; + eng_morse *= switch1; + } + + if (eflag) { + evdwl = eng_morse * powint(c,pm.ap); + evdwl *= factor_hb; + ehbond += evdwl; + } + + a = factor_hb*force_angle/s; + b = factor_hb*force_kernel; + d = factor_hb*force_switch; + + a11 = a*c / rsq1; + a12 = -a / (r1*r2); + a22 = a*c / rsq2; + + vx1 = a11*delr1[0] + a12*delr2[0]; + vx2 = a22*delr2[0] + a12*delr1[0]; + vy1 = a11*delr1[1] + a12*delr2[1]; + vy2 = a22*delr2[1] + a12*delr1[1]; + vz1 = a11*delr1[2] + a12*delr2[2]; + vz2 = a22*delr2[2] + a12*delr1[2]; + + fi[0] = vx1 + (b+d)*delx; + fi[1] = vy1 + (b+d)*dely; + fi[2] = vz1 + (b+d)*delz; + fj[0] = vx2 - (b+d)*delx; + fj[1] = vy2 - (b+d)*dely; + fj[2] = vz2 - (b+d)*delz; + + 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] -= vx1 + vx2; + f[k][1] -= vy1 + vy2; + f[k][2] -= vz1 + vz2; + + // KIJ instead of IJK b/c delr1/delr2 are both with respect to k + + if (evflag) ev_tally3(k,i,j,evdwl,0.0,fi,fj,delr1,delr2); + + hbcount++; + } + } + } + } + } + + if (eflag_global) { + pvector[0] = hbcount; + pvector[1] = ehbond; + } +} + +/* ---------------------------------------------------------------------- + set coeffs for one or more type pairs +------------------------------------------------------------------------- */ + +void PairHbondDreidingMorse::coeff(int narg, char **arg) +{ + if (narg < 7 || narg > 11) + error->all(FLERR,"Incorrect args for pair coefficients"); + if (!allocated) allocate(); + + int ilo,ihi,jlo,jhi,klo,khi; + utils::bounds(FLERR, arg[0], 1, atom->ntypes, ilo, ihi, error); + utils::bounds(FLERR, arg[1], 1, atom->ntypes, jlo, jhi, error); + utils::bounds_typelabel(FLERR, arg[2], 1, atom->ntypes, klo, khi, lmp, Atom::ATOM); + + int donor_flag; + if (strcmp(arg[3],"i") == 0) donor_flag = 0; + else if (strcmp(arg[3],"j") == 0) donor_flag = 1; + else error->all(FLERR,"Incorrect args for pair coefficients"); + + double d0_one = utils::numeric(FLERR, arg[4], false, lmp); + double alpha_one = utils::numeric(FLERR, arg[5], false, lmp); + double r0_one = utils::numeric(FLERR, arg[6], false, lmp); + + int ap_one = ap_global; + if (narg > 7) ap_one = utils::inumeric(FLERR, arg[7], false, lmp); + double cut_inner_one = cut_inner_global; + double cut_outer_one = cut_outer_global; + if (narg > 9) { + cut_inner_one = utils::numeric(FLERR, arg[8], false, lmp); + cut_outer_one = utils::numeric(FLERR, arg[9], false, lmp); + } + if (cut_inner_one>cut_outer_one) + error->all(FLERR,"Pair inner cutoff >= Pair outer cutoff"); + double cut_angle_one = cut_angle_global; + if (narg > 10) cut_angle_one = utils::numeric(FLERR, arg[10], false, lmp) * MY_PI/180.0; + + // grow params array if necessary + + if (nparams == maxparam) { + maxparam += CHUNK; + params = (Param *) memory->srealloc(params, maxparam*sizeof(Param), + "pair:params"); + + // make certain all addional allocated storage is initialized + // to avoid false positives when checking with valgrind + + memset(params + nparams, 0, CHUNK*sizeof(Param)); + } + + params[nparams].d0 = d0_one; + params[nparams].alpha = alpha_one; + params[nparams].r0 = r0_one; + params[nparams].ap = ap_one; + params[nparams].cut_inner = cut_inner_one; + params[nparams].cut_outer = cut_outer_one; + params[nparams].cut_innersq = cut_inner_one*cut_inner_one; + params[nparams].cut_outersq = cut_outer_one*cut_outer_one; + params[nparams].cut_angle = cut_angle_one; + params[nparams].denom_vdw = + (params[nparams].cut_outersq-params[nparams].cut_innersq) * + (params[nparams].cut_outersq-params[nparams].cut_innersq) * + (params[nparams].cut_outersq-params[nparams].cut_innersq); + + // flag type2param with either i,j = D,A or j,i = D,A + + int count = 0; + for (int i = ilo; i <= ihi; i++) + for (int j = MAX(jlo,i); j <= jhi; j++) + for (int k = klo; k <= khi; k++) { + if (donor_flag == 0) type2param[i][j][k] = nparams; + else type2param[j][i][k] = nparams; + count++; + } + nparams++; + + if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); +} + +/* ---------------------------------------------------------------------- + init specific to this pair style +------------------------------------------------------------------------- */ + +void PairHbondDreidingMorse::init_style() +{ + // molecular system required to use special list to find H atoms + // tags required to use special list + // pair newton on required since are looping over D atoms + // and computing forces on A,H which may be on different procs + + if (atom->molecular == Atom::ATOMIC) + error->all(FLERR,"Pair style hbond/dreiding requires molecular system"); + if (atom->tag_enable == 0) + error->all(FLERR,"Pair style hbond/dreiding requires atom IDs"); + if (atom->map_style == Atom::MAP_NONE) + error->all(FLERR,"Pair style hbond/dreiding requires an atom map, " + "see atom_modify"); + if (force->newton_pair == 0) + error->all(FLERR,"Pair style hbond/dreiding requires newton pair on"); + + // set donor[M]/acceptor[M] if any atom of type M is a donor/acceptor + + int anyflag = 0; + int n = atom->ntypes; + for (int m = 1; m <= n; m++) donor[m] = acceptor[m] = 0; + for (int i = 1; i <= n; i++) + for (int j = 1; j <= n; j++) + for (int k = 1; k <= n; k++) + if (type2param[i][j][k] >= 0) { + anyflag = 1; + donor[i] = 1; + acceptor[j] = 1; + } + + if (!anyflag) error->all(FLERR,"No pair hbond/dreiding coefficients set"); + + // set additional param values + // offset is for Morse only, angle term is not included + + for (int m = 0; m < nparams; m++) { + params[m].morse1 = 2.0*params[m].d0*params[m].alpha; + + /* + if (offset_flag) { + double alpha_dr = -params[m].alpha * (params[m].cut - params[m].r0); + params[m].offset = params[m].d0 * + ((exp(2.0*alpha_dr)) - (2.0*exp(alpha_dr))); + } else params[m].offset = 0.0; + */ + } + + // full neighbor list request + + neighbor->add_request(this, NeighConst::REQ_FULL); +} + +/* ---------------------------------------------------------------------- */ + +double PairHbondDreidingMorse::single(int i, int j, int itype, int jtype, + double rsq, + double /*factor_coul*/, double /*factor_lj*/, + double &fforce) +{ + int k,kk,ktype,knum,m; + tagint tagprev; + double eng,eng_morse,force_kernel,force_angle; + double rsq1,rsq2,r1,r2,c,s,ac,r,dr,dexp,factor_hb; + double switch1,switch2; + double delr1[3],delr2[3]; + tagint *klist; + + double **x = atom->x; + int *type = atom->type; + double *special_lj = force->special_lj; + + eng = 0.0; + fforce = 0; + + //sanity check + + if (!donor[itype]) return 0.0; + if (!acceptor[jtype]) return 0.0; + + int molecular = atom->molecular; + if (molecular == Atom::MOLECULAR) { + klist = atom->special[i]; + knum = atom->nspecial[i][0]; + } else { + if (atom->molindex[i] < 0) return 0.0; + int imol = atom->molindex[i]; + int iatom = atom->molatom[i]; + Molecule **onemols = atom->avec->onemols; + klist = onemols[imol]->special[iatom]; + knum = onemols[imol]->nspecial[iatom][0]; + tagprev = atom->tag[i] - iatom - 1; + } + + factor_hb = special_lj[sbmask(j)]; + + for (kk = 0; kk < knum; kk++) { + if (molecular == Atom::MOLECULAR) k = atom->map(klist[kk]); + else k = atom->map(klist[kk]+tagprev); + + if (k < 0) continue; + ktype = type[k]; + m = type2param[itype][jtype][ktype]; + if (m < 0) continue; + const Param &pm = params[m]; + + delr1[0] = x[i][0] - x[k][0]; + delr1[1] = x[i][1] - x[k][1]; + delr1[2] = x[i][2] - x[k][2]; + domain->minimum_image(delr1); + rsq1 = delr1[0]*delr1[0] + delr1[1]*delr1[1] + delr1[2]*delr1[2]; + r1 = sqrt(rsq1); + + delr2[0] = x[j][0] - x[k][0]; + delr2[1] = x[j][1] - x[k][1]; + delr2[2] = x[j][2] - x[k][2]; + domain->minimum_image(delr2); + rsq2 = delr2[0]*delr2[0] + delr2[1]*delr2[1] + delr2[2]*delr2[2]; + r2 = sqrt(rsq2); + + // angle (cos and sin) + + c = delr1[0]*delr2[0] + delr1[1]*delr2[1] + delr1[2]*delr2[2]; + c /= r1*r2; + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; + ac = acos(c); + + if (ac < pm.cut_angle || ac > (2.0*MY_PI - pm.cut_angle)) return 0.0; + s = sqrt(1.0 - c*c); + if (s < SMALL) s = SMALL; + + // Morse-specific kernel + + r = sqrt(rsq); + dr = r - pm.r0; + dexp = exp(-pm.alpha * dr); + eng_morse = pm.d0 * (dexp*dexp - 2.0*dexp); //<-- BUGFIX 2012-11-14 + force_kernel = pm.morse1*(dexp*dexp - dexp)/r * powint(c,pm.ap); + force_angle = pm.ap * eng_morse * powint(c,pm.ap-1)*s; + + if (rsq > pm.cut_innersq) { + switch1 = (pm.cut_outersq-rsq) * (pm.cut_outersq-rsq) * + (pm.cut_outersq + 2.0*rsq - 3.0*pm.cut_innersq) / + pm.denom_vdw; + switch2 = 12.0*rsq * (pm.cut_outersq-rsq) * + (rsq-pm.cut_innersq) / pm.denom_vdw; + force_kernel = force_kernel*switch1 + eng_morse*switch2; + eng_morse *= switch1; + } + + eng += eng_morse * powint(c,pm.ap)* factor_hb; + fforce += force_kernel*powint(c,pm.ap) + eng_morse*force_angle; + } + + return eng; +} diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h new file mode 100644 index 0000000000..8d4646451e --- /dev/null +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h @@ -0,0 +1,40 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS development team: developers@lammps.org + + 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 +// clang-format off +PairStyle(hbond/dreiding/morse,PairHbondDreidingMorse); +// clang-format on +#else + +#ifndef LMP_PAIR_HBOND_DREIDING_MORSE_H +#define LMP_PAIR_HBOND_DREIDING_MORSE_H + +#include "pair_hbond_dreiding_lj.h" + +namespace LAMMPS_NS { + +class PairHbondDreidingMorse : public PairHbondDreidingLJ { + public: + PairHbondDreidingMorse(class LAMMPS *); + + void compute(int, int) override; + void coeff(int, char **) override; + void init_style() override; + double single(int, int, int, int, double, double, double, double &) override; +}; + +} // namespace LAMMPS_NS + +#endif +#endif diff --git a/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.cpp b/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.cpp new file mode 100644 index 0000000000..b0f6dcfb5b --- /dev/null +++ b/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.cpp @@ -0,0 +1,317 @@ +// clang-format off +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS development team: developers@lammps.org + + This software is distributed under the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Axel Kohlmeyer (Temple U) +------------------------------------------------------------------------- */ + +#include "pair_hbond_dreiding_lj_omp.h" + +#include "atom.h" +#include "atom_vec.h" +#include "comm.h" +#include "domain.h" +#include "force.h" +#include "math_const.h" +#include "math_special.h" +#include "molecule.h" +#include "neigh_list.h" +#include "suffix.h" + +#include + +#include "omp_compat.h" +using namespace LAMMPS_NS; +using namespace MathConst; +using namespace MathSpecial; + +static constexpr double SMALL = 0.001; + +/* ---------------------------------------------------------------------- */ + +PairHbondDreidingLJOMP::PairHbondDreidingLJOMP(LAMMPS *lmp) : + PairHbondDreidingLJ(lmp), ThrOMP(lmp, THR_PAIR) +{ + suffix_flag |= Suffix::OMP; + respa_enable = 0; + hbcount_thr = hbeng_thr = nullptr; +} + +/* ---------------------------------------------------------------------- */ + +PairHbondDreidingLJOMP::~PairHbondDreidingLJOMP() +{ + if (hbcount_thr) { + delete[] hbcount_thr; + delete[] hbeng_thr; + } +} + +/* ---------------------------------------------------------------------- */ + +void PairHbondDreidingLJOMP::compute(int eflag, int vflag) +{ + ev_init(eflag,vflag); + + const int nall = atom->nlocal + atom->nghost; + const int nthreads = comm->nthreads; + const int inum = list->inum; + + if (!hbcount_thr) { + hbcount_thr = new double[nthreads]; + hbeng_thr = new double[nthreads]; + } + + for (int i=0; i < nthreads; ++i) { + hbcount_thr[i] = 0.0; + hbeng_thr[i] = 0.0; + } + +#if defined(_OPENMP) +#pragma omp parallel LMP_DEFAULT_NONE LMP_SHARED(eflag,vflag) +#endif + { + int ifrom, ito, tid; + + loop_setup_thr(ifrom, ito, tid, inum, nthreads); + ThrData *thr = fix->get_thr(tid); + thr->timer(Timer::START); + ev_setup_thr(eflag, vflag, nall, eatom, vatom, nullptr, thr); + + if (evflag) { + if (eflag) { + if (force->newton_pair) eval<1,1,1>(ifrom, ito, thr); + else eval<1,1,0>(ifrom, ito, thr); + } else { + if (force->newton_pair) eval<1,0,1>(ifrom, ito, thr); + else eval<1,0,0>(ifrom, ito, thr); + } + } else { + if (force->newton_pair) eval<0,0,1>(ifrom, ito, thr); + else eval<0,0,0>(ifrom, ito, thr); + } + + thr->timer(Timer::PAIR); + reduce_thr(this, eflag, vflag, thr); + } // end of omp parallel region + + // reduce per thread hbond data + if (eflag_global) { + pvector[0] = 0.0; + pvector[1] = 0.0; + for (int i=0; i < nthreads; ++i) { + pvector[0] += hbcount_thr[i]; + pvector[1] += hbeng_thr[i]; + } + } +} + +template +void PairHbondDreidingLJOMP::eval(int iifrom, int iito, ThrData * const thr) +{ + int i,j,k,m,ii,jj,kk,jnum,knum,itype,jtype,ktype,iatom,imol; + tagint tagprev; + double xtmp,ytmp,ztmp,delx,dely,delz,rsq,rsq1,rsq2,r1,r2; + double factor_hb,force_angle,force_kernel,evdwl,eng_lj; + double c,s,a,b,ac,a11,a12,a22,vx1,vx2,vy1,vy2,vz1,vz2; + double fi[3],fj[3],delr1[3],delr2[3]; + double r2inv,r10inv; + double switch1,switch2; + int *ilist,*jlist,*numneigh,**firstneigh; + const tagint *klist; + + evdwl = 0.0; + + const auto * _noalias const x = (dbl3_t *) atom->x[0]; + auto * _noalias const f = (dbl3_t *) thr->get_f()[0]; + const tagint * _noalias const tag = atom->tag; + const int * _noalias const molindex = atom->molindex; + const int * _noalias const molatom = atom->molatom; + const int * _noalias const type = atom->type; + const double * _noalias const special_lj = force->special_lj; + const int * const * const nspecial = atom->nspecial; + const tagint * const * const special = atom->special; + const int molecular = atom->molecular; + Molecule * const * const onemols = atom->avec->onemols; + double fxtmp,fytmp,fztmp; + + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; + + // ii = loop over donors + // jj = loop over acceptors + // kk = loop over hydrogens bonded to donor + + int hbcount = 0; + double hbeng = 0.0; + + for (ii = iifrom; ii < iito; ++ii) { + i = ilist[ii]; + itype = type[i]; + if (!donor[itype]) continue; + if (molecular == Atom::MOLECULAR) { + klist = special[i]; + knum = nspecial[i][0]; + } else { + if (molindex[i] < 0) continue; + imol = molindex[i]; + iatom = molatom[i]; + klist = onemols[imol]->special[iatom]; + knum = onemols[imol]->nspecial[iatom][0]; + tagprev = tag[i] - iatom - 1; + } + jlist = firstneigh[i]; + jnum = numneigh[i]; + fxtmp=fytmp=fztmp=0.0; + + xtmp = x[i].x; + ytmp = x[i].y; + ztmp = x[i].z; + + for (jj = 0; jj < jnum; jj++) { + j = jlist[jj]; + factor_hb = special_lj[sbmask(j)]; + j &= NEIGHMASK; + + jtype = type[j]; + if (!acceptor[jtype]) continue; + + delx = xtmp - x[j].x; + dely = ytmp - x[j].y; + delz = ztmp - x[j].z; + rsq = delx*delx + dely*dely + delz*delz; + + for (kk = 0; kk < knum; kk++) { + if (molecular == Atom::MOLECULAR) k = atom->map(klist[kk]); + else k = atom->map(klist[kk]+tagprev); + if (k < 0) continue; + ktype = type[k]; + m = type2param[itype][jtype][ktype]; + if (m < 0) continue; + const Param &pm = params[m]; + + if (rsq < pm.cut_outersq) { + delr1[0] = xtmp - x[k].x; + delr1[1] = ytmp - x[k].y; + delr1[2] = ztmp - x[k].z; + domain->minimum_image(delr1); + rsq1 = delr1[0]*delr1[0] + delr1[1]*delr1[1] + delr1[2]*delr1[2]; + r1 = sqrt(rsq1); + + delr2[0] = x[j].x - x[k].x; + delr2[1] = x[j].y - x[k].y; + delr2[2] = x[j].z - x[k].z; + domain->minimum_image(delr2); + rsq2 = delr2[0]*delr2[0] + delr2[1]*delr2[1] + delr2[2]*delr2[2]; + r2 = sqrt(rsq2); + + // angle (cos and sin) + + c = delr1[0]*delr2[0] + delr1[1]*delr2[1] + delr1[2]*delr2[2]; + c /= r1*r2; + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; + ac = acos(c); + + if (ac > pm.cut_angle && ac < (2.0*MY_PI - pm.cut_angle)) { + s = sqrt(1.0 - c*c); + if (s < SMALL) s = SMALL; + + // LJ-specific kernel + + r2inv = 1.0/rsq; + r10inv = r2inv*r2inv*r2inv*r2inv*r2inv; + force_kernel = r10inv*(pm.lj1*r2inv - pm.lj2)*r2inv * + powint(c,pm.ap); + force_angle = pm.ap * r10inv*(pm.lj3*r2inv - pm.lj4) * + powint(c,pm.ap-1)*s; + + eng_lj = r10inv*(pm.lj3*r2inv - pm.lj4); + if (rsq > pm.cut_innersq) { + switch1 = (pm.cut_outersq-rsq) * (pm.cut_outersq-rsq) * + (pm.cut_outersq + 2.0*rsq - 3.0*pm.cut_innersq) / + pm.denom_vdw; + switch2 = 12.0*rsq * (pm.cut_outersq-rsq) * + (rsq-pm.cut_innersq) / pm.denom_vdw; + force_kernel = force_kernel*switch1 + eng_lj*switch2/rsq; + force_angle *= switch1; + eng_lj *= switch1; + } + + if (EFLAG) { + evdwl = eng_lj * powint(c,pm.ap); + evdwl *= factor_hb; + } + + a = factor_hb*force_angle/s; + b = factor_hb*force_kernel; + + a11 = a*c / rsq1; + a12 = -a / (r1*r2); + a22 = a*c / rsq2; + + vx1 = a11*delr1[0] + a12*delr2[0]; + vx2 = a22*delr2[0] + a12*delr1[0]; + vy1 = a11*delr1[1] + a12*delr2[1]; + vy2 = a22*delr2[1] + a12*delr1[1]; + vz1 = a11*delr1[2] + a12*delr2[2]; + vz2 = a22*delr2[2] + a12*delr1[2]; + + fi[0] = vx1 + b*delx; + fi[1] = vy1 + b*dely; + fi[2] = vz1 + b*delz; + fj[0] = vx2 - b*delx; + fj[1] = vy2 - b*dely; + fj[2] = vz2 - b*delz; + + fxtmp += fi[0]; + fytmp += fi[1]; + fztmp += fi[2]; + + f[j].x += fj[0]; + f[j].y += fj[1]; + f[j].z += fj[2]; + + f[k].x -= vx1 + vx2; + f[k].y -= vy1 + vy2; + f[k].z -= vz1 + vz2; + + // KIJ instead of IJK b/c delr1/delr2 are both with respect to k + + if (EVFLAG) ev_tally3_thr(this,k,i,j,evdwl,0.0,fi,fj,delr1,delr2,thr); + if (EFLAG) { + hbcount++; + hbeng += evdwl; + } + } + } + } + } + f[i].x += fxtmp; + f[i].y += fytmp; + f[i].z += fztmp; + } + const int tid = thr->get_tid(); + hbcount_thr[tid] = static_cast(hbcount); + hbeng_thr[tid] = hbeng; +} + +/* ---------------------------------------------------------------------- */ + +double PairHbondDreidingLJOMP::memory_usage() +{ + double bytes = memory_usage_thr(); + bytes += (double)comm->nthreads * 2 * sizeof(double); + bytes += PairHbondDreidingLJ::memory_usage(); + + return bytes; +} diff --git a/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.h b/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.h new file mode 100644 index 0000000000..792a9a6f8c --- /dev/null +++ b/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.h @@ -0,0 +1,52 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS development team: developers@lammps.org + + 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: Axel Kohlmeyer (Temple U) +------------------------------------------------------------------------- */ + +#ifdef PAIR_CLASS +// clang-format off +PairStyle(hbond/dreiding/lj/omp,PairHbondDreidingLJOMP); +// clang-format on +#else + +#ifndef LMP_PAIR_HBOND_DREIDING_LJ_OMP_H +#define LMP_PAIR_HBOND_DREIDING_LJ_OMP_H + +#include "pair_hbond_dreiding_lj.h" +#include "thr_omp.h" + +namespace LAMMPS_NS { + +class PairHbondDreidingLJOMP : public PairHbondDreidingLJ, public ThrOMP { + + public: + PairHbondDreidingLJOMP(class LAMMPS *); + ~PairHbondDreidingLJOMP() override; + + void compute(int, int) override; + double memory_usage() override; + + protected: + double *hbcount_thr, *hbeng_thr; + + private: + template + void eval(int ifrom, int ito, ThrData *const thr); +}; + +} // namespace LAMMPS_NS + +#endif +#endif diff --git a/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.cpp b/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.cpp new file mode 100644 index 0000000000..0e43e2a037 --- /dev/null +++ b/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.cpp @@ -0,0 +1,316 @@ +// clang-format off +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS development team: developers@lammps.org + + This software is distributed under the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Axel Kohlmeyer (Temple U) +------------------------------------------------------------------------- */ + +#include "pair_hbond_dreiding_morse_omp.h" + +#include "atom.h" +#include "atom_vec.h" +#include "comm.h" +#include "domain.h" +#include "force.h" +#include "math_const.h" +#include "math_special.h" +#include "molecule.h" +#include "neigh_list.h" +#include "suffix.h" + +#include + +#include "omp_compat.h" +using namespace LAMMPS_NS; +using namespace MathConst; +using namespace MathSpecial; + +static constexpr double SMALL = 0.001; + +/* ---------------------------------------------------------------------- */ + +PairHbondDreidingMorseOMP::PairHbondDreidingMorseOMP(LAMMPS *lmp) : + PairHbondDreidingMorse(lmp), ThrOMP(lmp, THR_PAIR) +{ + suffix_flag |= Suffix::OMP; + respa_enable = 0; + hbcount_thr = hbeng_thr = nullptr; +} + +/* ---------------------------------------------------------------------- */ + +PairHbondDreidingMorseOMP::~PairHbondDreidingMorseOMP() +{ + if (hbcount_thr) { + delete[] hbcount_thr; + delete[] hbeng_thr; + } +} + +/* ---------------------------------------------------------------------- */ + +void PairHbondDreidingMorseOMP::compute(int eflag, int vflag) +{ + ev_init(eflag,vflag); + + const int nall = atom->nlocal + atom->nghost; + const int nthreads = comm->nthreads; + const int inum = list->inum; + + if (!hbcount_thr) { + hbcount_thr = new double[nthreads]; + hbeng_thr = new double[nthreads]; + } + + for (int i=0; i < nthreads; ++i) { + hbcount_thr[i] = 0.0; + hbeng_thr[i] = 0.0; + } + +#if defined(_OPENMP) +#pragma omp parallel LMP_DEFAULT_NONE LMP_SHARED(eflag,vflag) +#endif + { + int ifrom, ito, tid; + + loop_setup_thr(ifrom, ito, tid, inum, nthreads); + ThrData *thr = fix->get_thr(tid); + thr->timer(Timer::START); + ev_setup_thr(eflag, vflag, nall, eatom, vatom, nullptr, thr); + + if (evflag) { + if (eflag) { + if (force->newton_pair) eval<1,1,1>(ifrom, ito, thr); + else eval<1,1,0>(ifrom, ito, thr); + } else { + if (force->newton_pair) eval<1,0,1>(ifrom, ito, thr); + else eval<1,0,0>(ifrom, ito, thr); + } + } else { + if (force->newton_pair) eval<0,0,1>(ifrom, ito, thr); + else eval<0,0,0>(ifrom, ito, thr); + } + + thr->timer(Timer::PAIR); + reduce_thr(this, eflag, vflag, thr); + } // end of omp parallel region + + // reduce per thread hbond data + if (eflag_global) { + pvector[0] = 0.0; + pvector[1] = 0.0; + for (int i=0; i < nthreads; ++i) { + pvector[0] += hbcount_thr[i]; + pvector[1] += hbeng_thr[i]; + } + } +} + +template +void PairHbondDreidingMorseOMP::eval(int iifrom, int iito, ThrData * const thr) +{ + int i,j,k,m,ii,jj,kk,jnum,knum,itype,jtype,ktype,imol,iatom; + tagint tagprev; + double xtmp,ytmp,ztmp,delx,dely,delz,rsq,rsq1,rsq2,r1,r2; + double factor_hb,force_angle,force_kernel,evdwl; + double c,s,a,b,ac,a11,a12,a22,vx1,vx2,vy1,vy2,vz1,vz2; + double fi[3],fj[3],delr1[3],delr2[3]; + double r,dr,dexp,eng_morse,switch1,switch2; + int *ilist,*jlist,*numneigh,**firstneigh; + const tagint *klist; + + evdwl = 0.0; + + const auto * _noalias const x = (dbl3_t *) atom->x[0]; + auto * _noalias const f = (dbl3_t *) thr->get_f()[0]; + const tagint * _noalias const tag = atom->tag; + const int * _noalias const type = atom->type; + const int * _noalias const molindex = atom->molindex; + const int * _noalias const molatom = atom->molatom; + const double * _noalias const special_lj = force->special_lj; + const int * const * const nspecial = atom->nspecial; + const tagint * const * const special = atom->special; + const int molecular = atom->molecular; + Molecule * const * const onemols = atom->avec->onemols; + double fxtmp,fytmp,fztmp; + + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; + + // ii = loop over donors + // jj = loop over acceptors + // kk = loop over hydrogens bonded to donor + + int hbcount = 0; + double hbeng = 0.0; + + for (ii = iifrom; ii < iito; ++ii) { + + i = ilist[ii]; + itype = type[i]; + if (!donor[itype]) continue; + if (molecular == Atom::MOLECULAR) { + klist = special[i]; + knum = nspecial[i][0]; + } else { + if (molindex[i] < 0) continue; + imol = molindex[i]; + iatom = molatom[i]; + klist = onemols[imol]->special[iatom]; + knum = onemols[imol]->nspecial[iatom][0]; + tagprev = tag[i] - iatom - 1; + } + jlist = firstneigh[i]; + jnum = numneigh[i]; + fxtmp=fytmp=fztmp=0.0; + + xtmp = x[i].x; + ytmp = x[i].y; + ztmp = x[i].z; + + for (jj = 0; jj < jnum; jj++) { + j = jlist[jj]; + factor_hb = special_lj[sbmask(j)]; + j &= NEIGHMASK; + + jtype = type[j]; + if (!acceptor[jtype]) continue; + + delx = xtmp - x[j].x; + dely = ytmp - x[j].y; + delz = ztmp - x[j].z; + rsq = delx*delx + dely*dely + delz*delz; + + for (kk = 0; kk < knum; kk++) { + if (molecular == Atom::MOLECULAR) k = atom->map(klist[kk]); + else k = atom->map(klist[kk]+tagprev); + if (k < 0) continue; + ktype = type[k]; + m = type2param[itype][jtype][ktype]; + if (m < 0) continue; + const Param &pm = params[m]; + + if (rsq < pm.cut_outersq) { + delr1[0] = xtmp - x[k].x; + delr1[1] = ytmp - x[k].y; + delr1[2] = ztmp - x[k].z; + domain->minimum_image(delr1); + rsq1 = delr1[0]*delr1[0] + delr1[1]*delr1[1] + delr1[2]*delr1[2]; + r1 = sqrt(rsq1); + + delr2[0] = x[j].x - x[k].x; + delr2[1] = x[j].y - x[k].y; + delr2[2] = x[j].z - x[k].z; + domain->minimum_image(delr2); + rsq2 = delr2[0]*delr2[0] + delr2[1]*delr2[1] + delr2[2]*delr2[2]; + r2 = sqrt(rsq2); + + // angle (cos and sin) + + c = delr1[0]*delr2[0] + delr1[1]*delr2[1] + delr1[2]*delr2[2]; + c /= r1*r2; + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; + ac = acos(c); + + if (ac > pm.cut_angle && ac < (2.0*MY_PI - pm.cut_angle)) { + s = sqrt(1.0 - c*c); + if (s < SMALL) s = SMALL; + + // Morse-specific kernel + + r = sqrt(rsq); + dr = r - pm.r0; + dexp = exp(-pm.alpha * dr); + eng_morse = pm.d0 * (dexp*dexp - 2.0*dexp); + force_kernel = pm.morse1*(dexp*dexp - dexp)/r * powint(c,pm.ap); + force_angle = pm.ap * eng_morse * powint(c,pm.ap-1)*s; + + if (rsq > pm.cut_innersq) { + switch1 = (pm.cut_outersq-rsq) * (pm.cut_outersq-rsq) * + (pm.cut_outersq + 2.0*rsq - 3.0*pm.cut_innersq) / + pm.denom_vdw; + switch2 = 12.0*rsq * (pm.cut_outersq-rsq) * + (rsq-pm.cut_innersq) / pm.denom_vdw; + force_kernel = force_kernel*switch1 + eng_morse*switch2/rsq; + force_angle *= switch1; + eng_morse *= switch1; + } + + if (EFLAG) { + evdwl = eng_morse * powint(c,pm.ap); + evdwl *= factor_hb; + } + + a = factor_hb*force_angle/s; + b = factor_hb*force_kernel; + + a11 = a*c / rsq1; + a12 = -a / (r1*r2); + a22 = a*c / rsq2; + + vx1 = a11*delr1[0] + a12*delr2[0]; + vx2 = a22*delr2[0] + a12*delr1[0]; + vy1 = a11*delr1[1] + a12*delr2[1]; + vy2 = a22*delr2[1] + a12*delr1[1]; + vz1 = a11*delr1[2] + a12*delr2[2]; + vz2 = a22*delr2[2] + a12*delr1[2]; + + fi[0] = vx1 + b*delx; + fi[1] = vy1 + b*dely; + fi[2] = vz1 + b*delz; + fj[0] = vx2 - b*delx; + fj[1] = vy2 - b*dely; + fj[2] = vz2 - b*delz; + + fxtmp += fi[0]; + fytmp += fi[1]; + fztmp += fi[2]; + + f[j].x += fj[0]; + f[j].y += fj[1]; + f[j].z += fj[2]; + + f[k].x -= vx1 + vx2; + f[k].y -= vy1 + vy2; + f[k].z -= vz1 + vz2; + + // KIJ instead of IJK b/c delr1/delr2 are both with respect to k + + if (EVFLAG) ev_tally3_thr(this,k,i,j,evdwl,0.0,fi,fj,delr1,delr2,thr); + if (EFLAG) { + hbcount++; + hbeng += evdwl; + } + } + } + } + } + f[i].x += fxtmp; + f[i].y += fytmp; + f[i].z += fztmp; + } + const int tid = thr->get_tid(); + hbcount_thr[tid] = static_cast(hbcount); + hbeng_thr[tid] = hbeng; +} + +/* ---------------------------------------------------------------------- */ + +double PairHbondDreidingMorseOMP::memory_usage() +{ + double bytes = memory_usage_thr(); + bytes += (double)comm->nthreads * 2 * sizeof(double); + bytes += PairHbondDreidingMorse::memory_usage(); + + return bytes; +} diff --git a/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.h b/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.h new file mode 100644 index 0000000000..016154b762 --- /dev/null +++ b/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.h @@ -0,0 +1,52 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS development team: developers@lammps.org + + 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: Axel Kohlmeyer (Temple U) +------------------------------------------------------------------------- */ + +#ifdef PAIR_CLASS +// clang-format off +PairStyle(hbond/dreiding/morse/omp,PairHbondDreidingMorseOMP); +// clang-format on +#else + +#ifndef LMP_PAIR_HBOND_DREIDING_MORSE_OMP_H +#define LMP_PAIR_HBOND_DREIDING_MORSE_OMP_H + +#include "pair_hbond_dreiding_morse.h" +#include "thr_omp.h" + +namespace LAMMPS_NS { + +class PairHbondDreidingMorseOMP : public PairHbondDreidingMorse, public ThrOMP { + + public: + PairHbondDreidingMorseOMP(class LAMMPS *); + ~PairHbondDreidingMorseOMP() override; + + void compute(int, int) override; + double memory_usage() override; + + protected: + double *hbcount_thr, *hbeng_thr; + + private: + template + void eval(int ifrom, int ito, ThrData *const thr); +}; + +} // namespace LAMMPS_NS + +#endif +#endif From 898d97e603f7ddce47456e0a8e5f5979c5ba6f27 Mon Sep 17 00:00:00 2001 From: EiPi Fun Date: Sun, 1 Sep 2024 16:13:20 +0800 Subject: [PATCH 02/70] Add angle offset for pair_hbond_dreiding --- .../pair_hbond_dreiding_lj_angleoffset.cpp | 45 +++++++++++++------ .../pair_hbond_dreiding_lj_angleoffset.h | 16 +++---- .../pair_hbond_dreiding_morse_angleoffset.cpp | 33 ++++++++++---- .../pair_hbond_dreiding_morse_angleoffset.h | 12 ++--- ...pair_hbond_dreiding_lj_angleoffset_omp.cpp | 23 ++++++---- .../pair_hbond_dreiding_lj_angleoffset_omp.h | 16 +++---- ...r_hbond_dreiding_morse_angleoffset_omp.cpp | 23 ++++++---- ...air_hbond_dreiding_morse_angleoffset_omp.h | 16 +++---- 8 files changed, 113 insertions(+), 71 deletions(-) diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp index 274f8bc2a3..ab15d7c0b5 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp @@ -13,10 +13,10 @@ ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- - Contributing author: Tod A Pascal (Caltech) + Contributing author: Tod A Pascal (Caltech), Don Xu/EiPi Fun ------------------------------------------------------------------------- */ -#include "pair_hbond_dreiding_lj.h" +#include "pair_hbond_dreiding_lj_angleoffset.h" #include "atom.h" #include "atom_vec.h" @@ -42,7 +42,7 @@ static constexpr int CHUNK = 8; /* ---------------------------------------------------------------------- */ -PairHbondDreidingLJ::PairHbondDreidingLJ(LAMMPS *lmp) : Pair(lmp) +PairHbondDreidingLJangleoffset::PairHbondDreidingLJangleoffset(LAMMPS *lmp) : Pair(lmp) { // hbond cannot compute virial as F dot r // due to using map() to find bonded H atoms which are not near donor atom @@ -59,7 +59,7 @@ PairHbondDreidingLJ::PairHbondDreidingLJ(LAMMPS *lmp) : Pair(lmp) /* ---------------------------------------------------------------------- */ -PairHbondDreidingLJ::~PairHbondDreidingLJ() +PairHbondDreidingLJangleoffset::~PairHbondDreidingLJangleoffset() { memory->sfree(params); delete [] pvector; @@ -76,7 +76,7 @@ PairHbondDreidingLJ::~PairHbondDreidingLJ() /* ---------------------------------------------------------------------- */ -void PairHbondDreidingLJ::compute(int eflag, int vflag) +void PairHbondDreidingLJangleoffset::compute(int eflag, int vflag) { int i,j,k,m,ii,jj,kk,inum,jnum,knum,itype,jtype,ktype,iatom,imol; tagint tagprev; @@ -178,6 +178,11 @@ void PairHbondDreidingLJ::compute(int eflag, int vflag) if (c < -1.0) c = -1.0; ac = acos(c); + ac = ac + pm.angle_offset; + c = cos(ac); + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; + if (ac > pm.cut_angle && ac < (2.0*MY_PI - pm.cut_angle)) { s = sqrt(1.0 - c*c); if (s < SMALL) s = SMALL; @@ -269,7 +274,7 @@ void PairHbondDreidingLJ::compute(int eflag, int vflag) allocate all arrays ------------------------------------------------------------------------- */ -void PairHbondDreidingLJ::allocate() +void PairHbondDreidingLJangleoffset::allocate() { allocated = 1; int n = atom->ntypes; @@ -298,23 +303,24 @@ void PairHbondDreidingLJ::allocate() global settings ------------------------------------------------------------------------- */ -void PairHbondDreidingLJ::settings(int narg, char **arg) +void PairHbondDreidingLJangleoffset::settings(int narg, char **arg) { - if (narg != 4) error->all(FLERR,"Illegal pair_style command"); + if (narg != 5) error->all(FLERR,"Illegal pair_style command"); ap_global = utils::inumeric(FLERR,arg[0],false,lmp); cut_inner_global = utils::numeric(FLERR,arg[1],false,lmp); cut_outer_global = utils::numeric(FLERR,arg[2],false,lmp); cut_angle_global = utils::numeric(FLERR,arg[3],false,lmp) * MY_PI/180.0; + angle_offset_global = (180.0 - utils::numeric(FLERR,arg[4],false,lmp)) * MY_PI/180.0; } /* ---------------------------------------------------------------------- set coeffs for one or more type pairs ------------------------------------------------------------------------- */ -void PairHbondDreidingLJ::coeff(int narg, char **arg) +void PairHbondDreidingLJangleoffset::coeff(int narg, char **arg) { - if (narg < 6 || narg > 10) + if (narg < 6 || narg > 11) error->all(FLERR,"Incorrect args for pair coefficients"); if (!allocated) allocate(); @@ -342,7 +348,12 @@ void PairHbondDreidingLJ::coeff(int narg, char **arg) if (cut_inner_one>cut_outer_one) error->all(FLERR,"Pair inner cutoff >= Pair outer cutoff"); double cut_angle_one = cut_angle_global; - if (narg == 10) cut_angle_one = utils::numeric(FLERR, arg[9], false, lmp) * MY_PI/180.0; + if (narg > 9) cut_angle_one = utils::numeric(FLERR, arg[9], false, lmp) * MY_PI/180.0; + double angle_offset_one = angle_offset_global; + if (narg == 11) angle_offset_one = (180.0 - utils::numeric(FLERR, arg[10], false, lmp)) * MY_PI/180.0; + if (angle_offset_one < 0.0 || angle_offset_one > 90.0 * MY_PI/180.0) + error->all(FLERR,"Illegal angle offset"); + // grow params array if necessary if (nparams == maxparam) { @@ -364,6 +375,7 @@ void PairHbondDreidingLJ::coeff(int narg, char **arg) params[nparams].cut_innersq = cut_inner_one*cut_inner_one; params[nparams].cut_outersq = cut_outer_one*cut_outer_one; params[nparams].cut_angle = cut_angle_one; + params[nparams].angle_offset = angle_offset_one; params[nparams].denom_vdw = (params[nparams].cut_outersq-params[nparams].cut_innersq) * (params[nparams].cut_outersq-params[nparams].cut_innersq) * @@ -388,7 +400,7 @@ void PairHbondDreidingLJ::coeff(int narg, char **arg) init specific to this pair style ------------------------------------------------------------------------- */ -void PairHbondDreidingLJ::init_style() +void PairHbondDreidingLJangleoffset::init_style() { // molecular system required to use special list to find H atoms // tags required to use special list @@ -448,7 +460,7 @@ void PairHbondDreidingLJ::init_style() init for one type pair i,j and corresponding j,i ------------------------------------------------------------------------- */ -double PairHbondDreidingLJ::init_one(int i, int j) +double PairHbondDreidingLJangleoffset::init_one(int i, int j) { int m; @@ -467,7 +479,7 @@ double PairHbondDreidingLJ::init_one(int i, int j) /* ---------------------------------------------------------------------- */ -double PairHbondDreidingLJ::single(int i, int j, int itype, int jtype, +double PairHbondDreidingLJangleoffset::single(int i, int j, int itype, int jtype, double rsq, double /*factor_coul*/, double /*factor_lj*/, double &fforce) @@ -540,6 +552,11 @@ double PairHbondDreidingLJ::single(int i, int j, int itype, int jtype, if (c < -1.0) c = -1.0; ac = acos(c); + ac = ac + pm.angle_offset; + c = cos(ac); + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; + if (ac < pm.cut_angle || ac > (2.0*MY_PI - pm.cut_angle)) return 0.0; s = sqrt(1.0 - c*c); if (s < SMALL) s = SMALL; diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.h b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.h index 91a906c5cb..331d8e2ac1 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.h +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.h @@ -13,21 +13,21 @@ #ifdef PAIR_CLASS // clang-format off -PairStyle(hbond/dreiding/lj,PairHbondDreidingLJ); +PairStyle(hbond/dreiding/lj/angleoffset,PairHbondDreidingLJangleoffset); // clang-format on #else -#ifndef LMP_PAIR_HBOND_DREIDING_LJ_H -#define LMP_PAIR_HBOND_DREIDING_LJ_H +#ifndef LMP_PAIR_HBOND_DREIDING_LJ_ANGLEOFFSET_H +#define LMP_PAIR_HBOND_DREIDING_LJ_ANGLEOFFSET_H #include "pair.h" namespace LAMMPS_NS { -class PairHbondDreidingLJ : public Pair { +class PairHbondDreidingLJangleoffset : public Pair { public: - PairHbondDreidingLJ(class LAMMPS *); - ~PairHbondDreidingLJ() override; + PairHbondDreidingLJangleoffset(class LAMMPS *); + ~PairHbondDreidingLJangleoffset() override; void compute(int, int) override; void settings(int, char **) override; void coeff(int, char **) override; @@ -36,7 +36,7 @@ class PairHbondDreidingLJ : public Pair { double single(int, int, int, int, double, double, double, double &) override; protected: - double cut_inner_global, cut_outer_global, cut_angle_global; + double cut_inner_global, cut_outer_global, cut_angle_global, angle_offset_global; int ap_global; struct Param { @@ -45,7 +45,7 @@ class PairHbondDreidingLJ : public Pair { double d0, alpha, r0; double morse1; double denom_vdw; - double cut_inner, cut_outer, cut_innersq, cut_outersq, cut_angle, offset; + double cut_inner, cut_outer, cut_innersq, cut_outersq, cut_angle, offset, angle_offset; int ap; }; diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp index c8bc0a627d..1ee4f7ba08 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp @@ -13,10 +13,10 @@ ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- - Contributing author: Tod A Pascal (Caltech) + Contributing author: Tod A Pascal (Caltech), Don Xu/EiPi Fun ------------------------------------------------------------------------- */ -#include "pair_hbond_dreiding_morse.h" +#include "pair_hbond_dreiding_morse_angleoffset.h" #include "atom.h" #include "atom_vec.h" @@ -42,12 +42,12 @@ static constexpr int CHUNK = 8; /* ---------------------------------------------------------------------- */ -PairHbondDreidingMorse::PairHbondDreidingMorse(LAMMPS *lmp) : - PairHbondDreidingLJ(lmp) {} +PairHbondDreidingMorseAngleoffset::PairHbondDreidingMorseAngleoffset(LAMMPS *lmp) : + PairHbondDreidingLJangleoffset(lmp) {} /* ---------------------------------------------------------------------- */ -void PairHbondDreidingMorse::compute(int eflag, int vflag) +void PairHbondDreidingMorseAngleoffset::compute(int eflag, int vflag) { int i,j,k,m,ii,jj,kk,inum,jnum,knum,itype,jtype,ktype,imol,iatom; tagint tagprev; @@ -148,6 +148,11 @@ void PairHbondDreidingMorse::compute(int eflag, int vflag) if (c < -1.0) c = -1.0; ac = acos(c); + ac = ac + pm.angle_offset; + c = cos(ac); + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; + if (ac > pm.cut_angle && ac < (2.0*MY_PI - pm.cut_angle)) { s = sqrt(1.0 - c*c); if (s < SMALL) s = SMALL; @@ -236,9 +241,9 @@ void PairHbondDreidingMorse::compute(int eflag, int vflag) set coeffs for one or more type pairs ------------------------------------------------------------------------- */ -void PairHbondDreidingMorse::coeff(int narg, char **arg) +void PairHbondDreidingMorseAngleoffset::coeff(int narg, char **arg) { - if (narg < 7 || narg > 11) + if (narg < 7 || narg > 12) error->all(FLERR,"Incorrect args for pair coefficients"); if (!allocated) allocate(); @@ -268,6 +273,10 @@ void PairHbondDreidingMorse::coeff(int narg, char **arg) error->all(FLERR,"Pair inner cutoff >= Pair outer cutoff"); double cut_angle_one = cut_angle_global; if (narg > 10) cut_angle_one = utils::numeric(FLERR, arg[10], false, lmp) * MY_PI/180.0; + double angle_offset_one = angle_offset_global; + if (narg == 12) angle_offset_one = (180.0 - utils::numeric(FLERR,arg[11],false,lmp)) * MY_PI/180.0; + if (angle_offset_one < 0.0 || angle_offset_one > 90.0 * MY_PI/180.0) + error->all(FLERR,"Illegal angle offset"); // grow params array if necessary @@ -291,6 +300,7 @@ void PairHbondDreidingMorse::coeff(int narg, char **arg) params[nparams].cut_innersq = cut_inner_one*cut_inner_one; params[nparams].cut_outersq = cut_outer_one*cut_outer_one; params[nparams].cut_angle = cut_angle_one; + params[nparams].angle_offset = angle_offset_one; params[nparams].denom_vdw = (params[nparams].cut_outersq-params[nparams].cut_innersq) * (params[nparams].cut_outersq-params[nparams].cut_innersq) * @@ -315,7 +325,7 @@ void PairHbondDreidingMorse::coeff(int narg, char **arg) init specific to this pair style ------------------------------------------------------------------------- */ -void PairHbondDreidingMorse::init_style() +void PairHbondDreidingMorseAngleoffset::init_style() { // molecular system required to use special list to find H atoms // tags required to use special list @@ -370,7 +380,7 @@ void PairHbondDreidingMorse::init_style() /* ---------------------------------------------------------------------- */ -double PairHbondDreidingMorse::single(int i, int j, int itype, int jtype, +double PairHbondDreidingMorseAngleoffset::single(int i, int j, int itype, int jtype, double rsq, double /*factor_coul*/, double /*factor_lj*/, double &fforce) @@ -443,6 +453,11 @@ double PairHbondDreidingMorse::single(int i, int j, int itype, int jtype, if (c < -1.0) c = -1.0; ac = acos(c); + ac = ac + pm.angle_offset; + c = cos(ac); + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; + if (ac < pm.cut_angle || ac > (2.0*MY_PI - pm.cut_angle)) return 0.0; s = sqrt(1.0 - c*c); if (s < SMALL) s = SMALL; diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h index 8d4646451e..c1b0cf2f30 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h @@ -13,20 +13,20 @@ #ifdef PAIR_CLASS // clang-format off -PairStyle(hbond/dreiding/morse,PairHbondDreidingMorse); +PairStyle(hbond/dreiding/morse/angleoffset,PairHbondDreidingMorseAngleoffset); // clang-format on #else -#ifndef LMP_PAIR_HBOND_DREIDING_MORSE_H -#define LMP_PAIR_HBOND_DREIDING_MORSE_H +#ifndef LMP_PAIR_HBOND_DREIDING_MORSE_ANGLEOFFSET_H +#define LMP_PAIR_HBOND_DREIDING_MORSE_ANGLEOFFSET_H -#include "pair_hbond_dreiding_lj.h" +#include "pair_hbond_dreiding_lj_angleoffset.h" namespace LAMMPS_NS { -class PairHbondDreidingMorse : public PairHbondDreidingLJ { +class PairHbondDreidingMorseAngleoffset : public PairHbondDreidingLJangleoffset { public: - PairHbondDreidingMorse(class LAMMPS *); + PairHbondDreidingMorseAngleoffset(class LAMMPS *); void compute(int, int) override; void coeff(int, char **) override; diff --git a/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.cpp b/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.cpp index b0f6dcfb5b..094beca70a 100644 --- a/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.cpp +++ b/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.cpp @@ -10,10 +10,10 @@ ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- - Contributing author: Axel Kohlmeyer (Temple U) + Contributing author: Axel Kohlmeyer (Temple U), Don Xu/EiPi Fun ------------------------------------------------------------------------- */ -#include "pair_hbond_dreiding_lj_omp.h" +#include "pair_hbond_dreiding_lj_angleoffset_omp.h" #include "atom.h" #include "atom_vec.h" @@ -37,8 +37,8 @@ static constexpr double SMALL = 0.001; /* ---------------------------------------------------------------------- */ -PairHbondDreidingLJOMP::PairHbondDreidingLJOMP(LAMMPS *lmp) : - PairHbondDreidingLJ(lmp), ThrOMP(lmp, THR_PAIR) +PairHbondDreidingLJangleoffsetOMP::PairHbondDreidingLJangleoffsetOMP(LAMMPS *lmp) : + PairHbondDreidingLJangleoffset(lmp), ThrOMP(lmp, THR_PAIR) { suffix_flag |= Suffix::OMP; respa_enable = 0; @@ -47,7 +47,7 @@ PairHbondDreidingLJOMP::PairHbondDreidingLJOMP(LAMMPS *lmp) : /* ---------------------------------------------------------------------- */ -PairHbondDreidingLJOMP::~PairHbondDreidingLJOMP() +PairHbondDreidingLJangleoffsetOMP::~PairHbondDreidingLJangleoffsetOMP() { if (hbcount_thr) { delete[] hbcount_thr; @@ -57,7 +57,7 @@ PairHbondDreidingLJOMP::~PairHbondDreidingLJOMP() /* ---------------------------------------------------------------------- */ -void PairHbondDreidingLJOMP::compute(int eflag, int vflag) +void PairHbondDreidingLJangleoffsetOMP::compute(int eflag, int vflag) { ev_init(eflag,vflag); @@ -115,7 +115,7 @@ void PairHbondDreidingLJOMP::compute(int eflag, int vflag) } template -void PairHbondDreidingLJOMP::eval(int iifrom, int iito, ThrData * const thr) +void PairHbondDreidingLJangleoffsetOMP::eval(int iifrom, int iito, ThrData * const thr) { int i,j,k,m,ii,jj,kk,jnum,knum,itype,jtype,ktype,iatom,imol; tagint tagprev; @@ -222,6 +222,11 @@ void PairHbondDreidingLJOMP::eval(int iifrom, int iito, ThrData * const thr) if (c < -1.0) c = -1.0; ac = acos(c); + ac = ac + pm.angle_offset; + c = cos(ac); + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; + if (ac > pm.cut_angle && ac < (2.0*MY_PI - pm.cut_angle)) { s = sqrt(1.0 - c*c); if (s < SMALL) s = SMALL; @@ -307,11 +312,11 @@ void PairHbondDreidingLJOMP::eval(int iifrom, int iito, ThrData * const thr) /* ---------------------------------------------------------------------- */ -double PairHbondDreidingLJOMP::memory_usage() +double PairHbondDreidingLJangleoffsetOMP::memory_usage() { double bytes = memory_usage_thr(); bytes += (double)comm->nthreads * 2 * sizeof(double); - bytes += PairHbondDreidingLJ::memory_usage(); + bytes += PairHbondDreidingLJangleoffset::memory_usage(); return bytes; } diff --git a/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.h b/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.h index 792a9a6f8c..0a4e14f68d 100644 --- a/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.h +++ b/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.h @@ -12,28 +12,28 @@ ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- - Contributing author: Axel Kohlmeyer (Temple U) + Contributing author: Axel Kohlmeyer (Temple U), Don Xu/EiPi Fun ------------------------------------------------------------------------- */ #ifdef PAIR_CLASS // clang-format off -PairStyle(hbond/dreiding/lj/omp,PairHbondDreidingLJOMP); +PairStyle(hbond/dreiding/lj/angleoffset/omp,PairHbondDreidingLJangleoffsetOMP); // clang-format on #else -#ifndef LMP_PAIR_HBOND_DREIDING_LJ_OMP_H -#define LMP_PAIR_HBOND_DREIDING_LJ_OMP_H +#ifndef LMP_PAIR_HBOND_DREIDING_LJ_ANGLEOFFSET_OMP_H +#define LMP_PAIR_HBOND_DREIDING_LJ_ANGLEOFFSET_OMP_H -#include "pair_hbond_dreiding_lj.h" +#include "pair_hbond_dreiding_lj_angleoffset.h" #include "thr_omp.h" namespace LAMMPS_NS { -class PairHbondDreidingLJOMP : public PairHbondDreidingLJ, public ThrOMP { +class PairHbondDreidingLJangleoffsetOMP : public PairHbondDreidingLJangleoffset, public ThrOMP { public: - PairHbondDreidingLJOMP(class LAMMPS *); - ~PairHbondDreidingLJOMP() override; + PairHbondDreidingLJangleoffsetOMP(class LAMMPS *); + ~PairHbondDreidingLJangleoffsetOMP() override; void compute(int, int) override; double memory_usage() override; diff --git a/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.cpp b/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.cpp index 0e43e2a037..ad5c43f7b7 100644 --- a/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.cpp +++ b/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.cpp @@ -10,10 +10,10 @@ ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- - Contributing author: Axel Kohlmeyer (Temple U) + Contributing author: Axel Kohlmeyer (Temple U), Don Xu/EiPi Fun ------------------------------------------------------------------------- */ -#include "pair_hbond_dreiding_morse_omp.h" +#include "pair_hbond_dreiding_morse_angleoffset_omp.h" #include "atom.h" #include "atom_vec.h" @@ -37,8 +37,8 @@ static constexpr double SMALL = 0.001; /* ---------------------------------------------------------------------- */ -PairHbondDreidingMorseOMP::PairHbondDreidingMorseOMP(LAMMPS *lmp) : - PairHbondDreidingMorse(lmp), ThrOMP(lmp, THR_PAIR) +PairHbondDreidingMorseAngleoffsetOMP::PairHbondDreidingMorseAngleoffsetOMP(LAMMPS *lmp) : + PairHbondDreidingMorseAngleoffset(lmp), ThrOMP(lmp, THR_PAIR) { suffix_flag |= Suffix::OMP; respa_enable = 0; @@ -47,7 +47,7 @@ PairHbondDreidingMorseOMP::PairHbondDreidingMorseOMP(LAMMPS *lmp) : /* ---------------------------------------------------------------------- */ -PairHbondDreidingMorseOMP::~PairHbondDreidingMorseOMP() +PairHbondDreidingMorseAngleoffsetOMP::~PairHbondDreidingMorseAngleoffsetOMP() { if (hbcount_thr) { delete[] hbcount_thr; @@ -57,7 +57,7 @@ PairHbondDreidingMorseOMP::~PairHbondDreidingMorseOMP() /* ---------------------------------------------------------------------- */ -void PairHbondDreidingMorseOMP::compute(int eflag, int vflag) +void PairHbondDreidingMorseAngleoffsetOMP::compute(int eflag, int vflag) { ev_init(eflag,vflag); @@ -115,7 +115,7 @@ void PairHbondDreidingMorseOMP::compute(int eflag, int vflag) } template -void PairHbondDreidingMorseOMP::eval(int iifrom, int iito, ThrData * const thr) +void PairHbondDreidingMorseAngleoffsetOMP::eval(int iifrom, int iito, ThrData * const thr) { int i,j,k,m,ii,jj,kk,jnum,knum,itype,jtype,ktype,imol,iatom; tagint tagprev; @@ -222,6 +222,11 @@ void PairHbondDreidingMorseOMP::eval(int iifrom, int iito, ThrData * const thr) if (c < -1.0) c = -1.0; ac = acos(c); + ac = ac + pm.angle_offset; + c = cos(ac); + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; + if (ac > pm.cut_angle && ac < (2.0*MY_PI - pm.cut_angle)) { s = sqrt(1.0 - c*c); if (s < SMALL) s = SMALL; @@ -306,11 +311,11 @@ void PairHbondDreidingMorseOMP::eval(int iifrom, int iito, ThrData * const thr) /* ---------------------------------------------------------------------- */ -double PairHbondDreidingMorseOMP::memory_usage() +double PairHbondDreidingMorseAngleoffsetOMP::memory_usage() { double bytes = memory_usage_thr(); bytes += (double)comm->nthreads * 2 * sizeof(double); - bytes += PairHbondDreidingMorse::memory_usage(); + bytes += PairHbondDreidingMorseAngleoffset::memory_usage(); return bytes; } diff --git a/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.h b/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.h index 016154b762..fb95988c6f 100644 --- a/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.h +++ b/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.h @@ -12,28 +12,28 @@ ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- - Contributing author: Axel Kohlmeyer (Temple U) + Contributing author: Axel Kohlmeyer (Temple U), Don Xu/EiPi Fun ------------------------------------------------------------------------- */ #ifdef PAIR_CLASS // clang-format off -PairStyle(hbond/dreiding/morse/omp,PairHbondDreidingMorseOMP); +PairStyle(hbond/dreiding/morse/angleoffset/omp,PairHbondDreidingMorseAngleoffsetOMP); // clang-format on #else -#ifndef LMP_PAIR_HBOND_DREIDING_MORSE_OMP_H -#define LMP_PAIR_HBOND_DREIDING_MORSE_OMP_H +#ifndef LMP_PAIR_HBOND_DREIDING_MORSE_ANGLEOFFSET_OMP_H +#define LMP_PAIR_HBOND_DREIDING_MORSE_ANGLEOFFSET_OMP_H -#include "pair_hbond_dreiding_morse.h" +#include "pair_hbond_dreiding_morse_angleoffset.h" #include "thr_omp.h" namespace LAMMPS_NS { -class PairHbondDreidingMorseOMP : public PairHbondDreidingMorse, public ThrOMP { +class PairHbondDreidingMorseAngleoffsetOMP : public PairHbondDreidingMorseAngleoffset, public ThrOMP { public: - PairHbondDreidingMorseOMP(class LAMMPS *); - ~PairHbondDreidingMorseOMP() override; + PairHbondDreidingMorseAngleoffsetOMP(class LAMMPS *); + ~PairHbondDreidingMorseAngleoffsetOMP() override; void compute(int, int) override; double memory_usage() override; From bb1624b20d772129d93c18b9f3d0e5c4da491c91 Mon Sep 17 00:00:00 2001 From: EiPi Fun Date: Sun, 1 Sep 2024 16:16:47 +0800 Subject: [PATCH 03/70] Add documentation for modified pair_hbond_dreiding with angleoffset --- doc/src/pair_hbond_dreiding_angleoffset.rst | 130 ++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 doc/src/pair_hbond_dreiding_angleoffset.rst diff --git a/doc/src/pair_hbond_dreiding_angleoffset.rst b/doc/src/pair_hbond_dreiding_angleoffset.rst new file mode 100644 index 0000000000..e827a644ac --- /dev/null +++ b/doc/src/pair_hbond_dreiding_angleoffset.rst @@ -0,0 +1,130 @@ +.. index:: pair_style hbond/dreiding/lj/angleoffset +.. index:: pair_style hbond/dreiding/lj/angleoffset/omp +.. index:: pair_style hbond/dreiding/morse/angleoffset +.. index:: pair_style hbond/dreiding/morse/angleoffest/omp + +pair_style hbond/dreiding/lj/angleoffset command +==================================== + +Accelerator Variants: *hbond/dreiding/lj/angleoffset/omp* + +pair_style hbond/dreiding/morse/angleoffset command +======================================= + +Accelerator Variants: *hbond/dreiding/morse/angleoffset/omp* + +Syntax +"""""" + +.. code-block:: LAMMPS + + pair_style style N inner_distance_cutoff outer_distance_cutoff angle_cutoff equilibrium_angle + +* style = *hbond/dreiding/lj/angleoffset* or *hbond/dreiding/morse/angleoffset* +* N = power of cosine of sum of angle theta and angle offset (integer) +* inner_distance_cutoff = global inner cutoff for Donor-Acceptor interactions (distance units) +* outer_distance_cutoff = global cutoff for Donor-Acceptor interactions (distance units) +* angle_cutoff = global angle cutoff for Acceptor-Hydrogen-Donor interactions (degrees) +* equilibrium_angle = global equilibrium angle for Acceptor-Hydrogen-Donor interactions (degrees) + +(Tips: angle offset is the supplementary angle of equilibrium angle. It means if equilibrium angle is 166.6, the angle offset is 13.4) + +Examples +"""""""" + +.. code-block:: LAMMPS + + pair_style hybrid/overlay lj/cut 10.0 hbond/dreiding/lj/angleoffset 4 9.0 11.0 90.0 170.0 + pair_coeff 1 2 hbond/dreiding/lj 3 i 9.5 2.75 4 9.0 11.0 90.0 160.0 + + pair_style hybrid/overlay lj/cut 10.0 hbond/dreiding/morse/angleoffset 2 9.0 11.0 90.0 170.0 + pair_coeff 1 2 hbond/dreiding/morse 3 i 3.88 1.7241379 2.9 2 9.0 11.0 90.0 160.0 + + labelmap atom 1 C 2 O 3 H + pair_coeff C O hbond/dreiding/morse H i 3.88 1.7241379 2.9 2 9.0 11.0 90.0 160.0 + +Description +""""""""""" + +The *hbond/dreiding/\*/angleoffset* styles are modified version of *hbond/dreiding* styles. + +In some cases, the angle of acceptor-hydrogen-donor in the equilibrium state could not achieve 180 degree especially in some coarse grained models. +In these cases, an angle offset is required to ensure that equilibrium state could be the minimum energy state. + +The *hbond/dreiding/\*/angleoffset* styles compute the Acceptor-Hydrogen-Donor (AHD) +3-body hydrogen bond interaction for the :doc:`DREIDING ` +force field with an angle offset, given by: + +.. math:: + + E = & \left[LJ(r) | Morse(r) \right] \qquad \qquad \qquad r < r_{\rm in} and \theta + \theta_{offset} < \theta_c \\ + = & S(r) * \left[LJ(r) | Morse(r) \right] \qquad \qquad r_{\rm in} < r < r_{\rm out} and \theta + \theta_{offset} < \theta_c \\ + = & 0 \qquad \qquad \qquad \qquad \qquad \qquad \qquad r > r_{\rm out} and \theta + \theta_{offset} < \theta_c \\ + LJ(r) = & AR^{-12}-BR^{-10}cos^n(\theta + \theta_{offset})= + \epsilon\left\lbrace 5\left[ \frac{\sigma}{r}\right]^{12}- + 6\left[ \frac{\sigma}{r}\right]^{10} \right\rbrace cos^n(\theta + \theta_{offset})\\ + Morse(r) = & D_0\left\lbrace \chi^2 - 2\chi\right\rbrace cos^n(\theta + \theta_{offset})= + D_{0}\left\lbrace e^{- 2 \alpha (r - r_0)} - 2 e^{- \alpha (r - r_0)} + \right\rbrace cos^n(\theta + \theta_{offset})\ + S(r) = & \frac{ \left[r_{\rm out}^2 - r^2\right]^2 + \left[r_{\rm out}^2 + 2r^2 - 3{r_{\rm in}^2}\right]} + { \left[r_{\rm out}^2 - {r_{\rm in}}^2\right]^3 } + +where :math:`r_{\rm in}` is the inner spline distance cutoff, +:math:`r_{\rm out}` is the outer distance cutoff, :math:`\theta_c` is +the angle cutoff, :math:`\theta_offset` is the angle offset, and :math:`n` is the power of the cosine of the sum of the angle :math:`\theta` and the angle offset :math:`\theta_offset` + +Here, *r* is the radial distance between the donor (D) and acceptor +(A) atoms and :math:`\theta` is the bond angle between the acceptor, the +hydrogen (H) and the donor atoms: + +.. image:: JPG/dreiding_hbond.jpg + :align: center + +For the *hbond/dreiding/lj/angleoffset* style the list of coefficients is as +follows: + +* K = hydrogen atom type = 1 to Ntypes, or type label +* donor flag = *i* or *j* +* :math:`\epsilon` (energy units) +* :math:`\sigma` (distance units) +* *n* = exponent in formula above +* distance cutoff :math:`r_{\rm in}` (distance units) +* distance cutoff :math:`r_{\rm out}` (distance units) +* angle cutoff (degrees) +* equilibrium angle (degrees) + +(Tips: angle offset is the supplementary angle of equilibrium angle) + +For the *hbond/dreiding/morse/angleoffset* style the list of coefficients is as +follows: + +* K = hydrogen atom type = 1 to Ntypes, or type label +* donor flag = *i* or *j* +* :math:`D_0` (energy units) +* :math:`\alpha` (1/distance units) +* :math:`r_0` (distance units) +* *n* = exponent in formula above +* distance cutoff :math:`r_{\rm in}` (distance units) +* distance cutoff :math:`r_{out}` (distance units) +* angle cutoff (degrees) +* equilibrium angle (degrees) + +(Tips: angle offset is the supplementary angle of equilibrium angle) + +---------- + +Additional Information +"""""""""""" + +For more information about DREIDING force field and other notes, please refer to the documentation of *hbond/dreiding* styles. + +---------- + +Restrictions +"""""""""""" + +This pair style can only be used if LAMMPS was built with the +EXTRA-MOLECULE package. See the :doc:`Build package ` doc page +for more info. + From 9f73494c91f82cd46079ac3496fdee006be26a77 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 2 Sep 2024 20:42:05 -0400 Subject: [PATCH 04/70] correct ReStructuredText and LaTeX formatting issues --- doc/src/pair_hbond_dreiding_angleoffset.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/src/pair_hbond_dreiding_angleoffset.rst b/doc/src/pair_hbond_dreiding_angleoffset.rst index e827a644ac..5aa8950961 100644 --- a/doc/src/pair_hbond_dreiding_angleoffset.rst +++ b/doc/src/pair_hbond_dreiding_angleoffset.rst @@ -4,12 +4,12 @@ .. index:: pair_style hbond/dreiding/morse/angleoffest/omp pair_style hbond/dreiding/lj/angleoffset command -==================================== +================================================ Accelerator Variants: *hbond/dreiding/lj/angleoffset/omp* pair_style hbond/dreiding/morse/angleoffset command -======================================= +=================================================== Accelerator Variants: *hbond/dreiding/morse/angleoffset/omp* @@ -65,7 +65,7 @@ force field with an angle offset, given by: 6\left[ \frac{\sigma}{r}\right]^{10} \right\rbrace cos^n(\theta + \theta_{offset})\\ Morse(r) = & D_0\left\lbrace \chi^2 - 2\chi\right\rbrace cos^n(\theta + \theta_{offset})= D_{0}\left\lbrace e^{- 2 \alpha (r - r_0)} - 2 e^{- \alpha (r - r_0)} - \right\rbrace cos^n(\theta + \theta_{offset})\ + \right\rbrace cos^n(\theta + \theta_{offset})\\ S(r) = & \frac{ \left[r_{\rm out}^2 - r^2\right]^2 \left[r_{\rm out}^2 + 2r^2 - 3{r_{\rm in}^2}\right]} { \left[r_{\rm out}^2 - {r_{\rm in}}^2\right]^3 } @@ -115,7 +115,7 @@ follows: ---------- Additional Information -"""""""""""" +"""""""""""""""""""""" For more information about DREIDING force field and other notes, please refer to the documentation of *hbond/dreiding* styles. @@ -125,6 +125,6 @@ Restrictions """""""""""" This pair style can only be used if LAMMPS was built with the -EXTRA-MOLECULE package. See the :doc:`Build package ` doc page -for more info. +EXTRA-MOLECULE package. See the :doc:`Build package ` +doc page for more info. From 7c13562c4101635face95b9ea34a3c9db91c4607 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 2 Sep 2024 20:42:15 -0400 Subject: [PATCH 05/70] spelling --- doc/utils/sphinx-config/false_positives.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index cfbddbe5f6..7b9ff540f2 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -107,6 +107,7 @@ Andrienko Andzelm Ang anglegrad +angleoffset angletangrad angmom angmomx From 9f2e542c807f1c0802ec172eddde5f873a534410 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 2 Sep 2024 20:42:33 -0400 Subject: [PATCH 06/70] integrate into manual build --- doc/src/Commands_pair.rst | 2 ++ doc/src/pair_style.rst | 2 ++ 2 files changed, 4 insertions(+) diff --git a/doc/src/Commands_pair.rst b/doc/src/Commands_pair.rst index dfed8f7485..a813bb771d 100644 --- a/doc/src/Commands_pair.rst +++ b/doc/src/Commands_pair.rst @@ -113,7 +113,9 @@ OPT. * :doc:`gw/zbl ` * :doc:`harmonic/cut (o) ` * :doc:`hbond/dreiding/lj (o) ` + * :doc:`hbond/dreiding/lj/angleoffset (o) ` * :doc:`hbond/dreiding/morse (o) ` + * :doc:`hbond/dreiding/morse/angleoffset (o) ` * :doc:`hdnnp ` * :doc:`hippo (g) ` * :doc:`ilp/graphene/hbn (t) ` diff --git a/doc/src/pair_style.rst b/doc/src/pair_style.rst index 51350c86a4..6e59d697a8 100644 --- a/doc/src/pair_style.rst +++ b/doc/src/pair_style.rst @@ -205,7 +205,9 @@ accelerated styles exist. * :doc:`gw/zbl ` - Gao-Weber potential with a repulsive ZBL core * :doc:`harmonic/cut ` - repulsive-only harmonic potential * :doc:`hbond/dreiding/lj ` - DREIDING hydrogen bonding LJ potential +* :doc:`hbond/dreiding/lj/angleoffset ` - DREIDING hydrogen bonding LJ potential with offset for hbond angle * :doc:`hbond/dreiding/morse ` - DREIDING hydrogen bonding Morse potential +* :doc:`hbond/dreiding/morse/angleoffset ` - DREIDING hydrogen bonding Morse potential with offset for hbond angle * :doc:`hdnnp ` - High-dimensional neural network potential * :doc:`hippo ` - * :doc:`ilp/graphene/hbn ` - registry-dependent interlayer potential (ILP) From 6aa592d28696a39b326c64c8458b9c5baddbdfc1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 2 Sep 2024 20:43:48 -0400 Subject: [PATCH 07/70] build system integration --- src/.gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/.gitignore b/src/.gitignore index c26eaaba30..d706ef4a7d 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1262,6 +1262,10 @@ /pair_hbond_dreiding_lj.h /pair_hbond_dreiding_morse.cpp /pair_hbond_dreiding_morse.h +/pair_hbond_dreiding_lj_angleoffset.cpp +/pair_hbond_dreiding_lj_angleoffset.h +/pair_hbond_dreiding_morse_angleoffset.cpp +/pair_hbond_dreiding_morse_angleoffset.h /pair_hdnnp.cpp /pair_hdnnp.h /pair_ilp_graphene_hbn.cpp From e763f9e052e893c6e79f1624132f9d0506e96cec Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 2 Sep 2024 20:49:41 -0400 Subject: [PATCH 08/70] use correct style in error messages --- .../pair_hbond_dreiding_lj_angleoffset.cpp | 18 ++++---------- .../pair_hbond_dreiding_morse_angleoffset.cpp | 24 ++++++------------- 2 files changed, 12 insertions(+), 30 deletions(-) diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp index ab15d7c0b5..3b30baa2b3 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp @@ -408,14 +408,14 @@ void PairHbondDreidingLJangleoffset::init_style() // and computing forces on A,H which may be on different procs if (atom->molecular == Atom::ATOMIC) - error->all(FLERR,"Pair style hbond/dreiding requires molecular system"); + error->all(FLERR,"Pair style hbond/dreiding/lj/angleoffset requires molecular system"); if (atom->tag_enable == 0) - error->all(FLERR,"Pair style hbond/dreiding requires atom IDs"); + error->all(FLERR,"Pair style hbond/dreiding/lj/angleoffset requires atom IDs"); if (atom->map_style == Atom::MAP_NONE) - error->all(FLERR,"Pair style hbond/dreiding requires an atom map, " + error->all(FLERR,"Pair style hbond/dreiding/lj/angleoffset requires an atom map, " "see atom_modify"); if (force->newton_pair == 0) - error->all(FLERR,"Pair style hbond/dreiding requires newton pair on"); + error->all(FLERR,"Pair style hbond/dreiding/lj/angleoffset requires newton pair on"); // set donor[M]/acceptor[M] if any atom of type M is a donor/acceptor @@ -431,7 +431,7 @@ void PairHbondDreidingLJangleoffset::init_style() acceptor[j] = 1; } - if (!anyflag) error->all(FLERR,"No pair hbond/dreiding coefficients set"); + if (!anyflag) error->all(FLERR,"No pair hbond/dreiding/lj/angleoffset coefficients set"); // set additional param values // offset is for LJ only, angle term is not included @@ -441,14 +441,6 @@ void PairHbondDreidingLJangleoffset::init_style() params[m].lj2 = 60.0*params[m].epsilon*pow(params[m].sigma,10.0); params[m].lj3 = 5.0*params[m].epsilon*pow(params[m].sigma,12.0); params[m].lj4 = 6.0*params[m].epsilon*pow(params[m].sigma,10.0); - - /* - if (offset_flag) { - double ratio = params[m].sigma / params[m].cut_outer; - params[m].offset = params[m].epsilon * - ((2.0*pow(ratio,9.0)) - (3.0*pow(ratio,6.0))); - } else params[m].offset = 0.0; - */ } // full neighbor list request diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp index 1ee4f7ba08..173eac605f 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp @@ -282,8 +282,7 @@ void PairHbondDreidingMorseAngleoffset::coeff(int narg, char **arg) if (nparams == maxparam) { maxparam += CHUNK; - params = (Param *) memory->srealloc(params, maxparam*sizeof(Param), - "pair:params"); + params = (Param *) memory->srealloc(params, maxparam*sizeof(Param),"pair:params"); // make certain all addional allocated storage is initialized // to avoid false positives when checking with valgrind @@ -301,8 +300,7 @@ void PairHbondDreidingMorseAngleoffset::coeff(int narg, char **arg) params[nparams].cut_outersq = cut_outer_one*cut_outer_one; params[nparams].cut_angle = cut_angle_one; params[nparams].angle_offset = angle_offset_one; - params[nparams].denom_vdw = - (params[nparams].cut_outersq-params[nparams].cut_innersq) * + params[nparams].denom_vdw = (params[nparams].cut_outersq-params[nparams].cut_innersq) * (params[nparams].cut_outersq-params[nparams].cut_innersq) * (params[nparams].cut_outersq-params[nparams].cut_innersq); @@ -333,14 +331,14 @@ void PairHbondDreidingMorseAngleoffset::init_style() // and computing forces on A,H which may be on different procs if (atom->molecular == Atom::ATOMIC) - error->all(FLERR,"Pair style hbond/dreiding requires molecular system"); + error->all(FLERR,"Pair style hbond/dreiding/morse/angleoffset requires molecular system"); if (atom->tag_enable == 0) - error->all(FLERR,"Pair style hbond/dreiding requires atom IDs"); + error->all(FLERR,"Pair style hbond/dreiding/morse/angleoffset requires atom IDs"); if (atom->map_style == Atom::MAP_NONE) - error->all(FLERR,"Pair style hbond/dreiding requires an atom map, " + error->all(FLERR,"Pair style hbond/dreiding/morse/angleoffset requires an atom map, " "see atom_modify"); if (force->newton_pair == 0) - error->all(FLERR,"Pair style hbond/dreiding requires newton pair on"); + error->all(FLERR,"Pair style hbond/dreiding/morse/angleoffset requires newton pair on"); // set donor[M]/acceptor[M] if any atom of type M is a donor/acceptor @@ -356,21 +354,13 @@ void PairHbondDreidingMorseAngleoffset::init_style() acceptor[j] = 1; } - if (!anyflag) error->all(FLERR,"No pair hbond/dreiding coefficients set"); + if (!anyflag) error->all(FLERR,"No pair hbond/dreiding/morse/angleoffset coefficients set"); // set additional param values // offset is for Morse only, angle term is not included for (int m = 0; m < nparams; m++) { params[m].morse1 = 2.0*params[m].d0*params[m].alpha; - - /* - if (offset_flag) { - double alpha_dr = -params[m].alpha * (params[m].cut - params[m].r0); - params[m].offset = params[m].d0 * - ((exp(2.0*alpha_dr)) - (2.0*exp(alpha_dr))); - } else params[m].offset = 0.0; - */ } // full neighbor list request From 9cfbf3dcdd46e91570fb24b7102ef3fb06c8e1f0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 2 Sep 2024 20:58:40 -0400 Subject: [PATCH 09/70] fix link and grammar --- doc/src/pair_hbond_dreiding_angleoffset.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/src/pair_hbond_dreiding_angleoffset.rst b/doc/src/pair_hbond_dreiding_angleoffset.rst index 5aa8950961..888be1bb10 100644 --- a/doc/src/pair_hbond_dreiding_angleoffset.rst +++ b/doc/src/pair_hbond_dreiding_angleoffset.rst @@ -27,7 +27,8 @@ Syntax * angle_cutoff = global angle cutoff for Acceptor-Hydrogen-Donor interactions (degrees) * equilibrium_angle = global equilibrium angle for Acceptor-Hydrogen-Donor interactions (degrees) -(Tips: angle offset is the supplementary angle of equilibrium angle. It means if equilibrium angle is 166.6, the angle offset is 13.4) +(Tips: angle offset is the supplementary angle of the equilibrium angle. It means if the +equilibrium angle is 166.6, the angle offset is 13.4) Examples """""""" @@ -117,7 +118,8 @@ follows: Additional Information """""""""""""""""""""" -For more information about DREIDING force field and other notes, please refer to the documentation of *hbond/dreiding* styles. +For more information about DREIDING force field and other notes, please refer +to the :doc:`documentation of the *hbond/dreiding* styles `. ---------- From 61ffe1ece17e09c01dd0d2e585f801f5d794ddfe Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 2 Sep 2024 21:00:02 -0400 Subject: [PATCH 10/70] correct link --- doc/src/pair_hbond_dreiding_angleoffset.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/pair_hbond_dreiding_angleoffset.rst b/doc/src/pair_hbond_dreiding_angleoffset.rst index 888be1bb10..8262937db2 100644 --- a/doc/src/pair_hbond_dreiding_angleoffset.rst +++ b/doc/src/pair_hbond_dreiding_angleoffset.rst @@ -119,7 +119,7 @@ Additional Information """""""""""""""""""""" For more information about DREIDING force field and other notes, please refer -to the :doc:`documentation of the *hbond/dreiding* styles `. +to the :doc:`documentation of the *hbond/dreiding* pair styles `. ---------- From 4b56e81b66e5ed603ee3876b3e3be61ed6cc3e57 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 2 Sep 2024 21:03:16 -0400 Subject: [PATCH 11/70] fix typo --- doc/src/pair_hbond_dreiding_angleoffset.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/pair_hbond_dreiding_angleoffset.rst b/doc/src/pair_hbond_dreiding_angleoffset.rst index 8262937db2..682dd7564a 100644 --- a/doc/src/pair_hbond_dreiding_angleoffset.rst +++ b/doc/src/pair_hbond_dreiding_angleoffset.rst @@ -1,7 +1,7 @@ .. index:: pair_style hbond/dreiding/lj/angleoffset .. index:: pair_style hbond/dreiding/lj/angleoffset/omp .. index:: pair_style hbond/dreiding/morse/angleoffset -.. index:: pair_style hbond/dreiding/morse/angleoffest/omp +.. index:: pair_style hbond/dreiding/morse/angleoffset/omp pair_style hbond/dreiding/lj/angleoffset command ================================================ From a48b67baae4b037d68fd67229fcd83a3a83168ab Mon Sep 17 00:00:00 2001 From: EiPiFun <132569654+EiPiFun@users.noreply.github.com> Date: Tue, 3 Sep 2024 11:09:35 +0800 Subject: [PATCH 12/70] Fix angle cutoff logical error Angle should > angle cutoff instead of < --- doc/src/pair_hbond_dreiding_angleoffset.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/src/pair_hbond_dreiding_angleoffset.rst b/doc/src/pair_hbond_dreiding_angleoffset.rst index 682dd7564a..dff6040218 100644 --- a/doc/src/pair_hbond_dreiding_angleoffset.rst +++ b/doc/src/pair_hbond_dreiding_angleoffset.rst @@ -58,9 +58,9 @@ force field with an angle offset, given by: .. math:: - E = & \left[LJ(r) | Morse(r) \right] \qquad \qquad \qquad r < r_{\rm in} and \theta + \theta_{offset} < \theta_c \\ - = & S(r) * \left[LJ(r) | Morse(r) \right] \qquad \qquad r_{\rm in} < r < r_{\rm out} and \theta + \theta_{offset} < \theta_c \\ - = & 0 \qquad \qquad \qquad \qquad \qquad \qquad \qquad r > r_{\rm out} and \theta + \theta_{offset} < \theta_c \\ + E = & \left[LJ(r) | Morse(r) \right] \qquad \qquad \qquad r < r_{\rm in} and \theta + \theta_{offset} > \theta_c \\ + = & S(r) * \left[LJ(r) | Morse(r) \right] \qquad \qquad r_{\rm in} < r < r_{\rm out} and \theta + \theta_{offset} > \theta_c \\ + = & 0 \qquad \qquad \qquad \qquad \qquad \qquad \qquad r > r_{\rm out} and \theta + \theta_{offset} > \theta_c \\ LJ(r) = & AR^{-12}-BR^{-10}cos^n(\theta + \theta_{offset})= \epsilon\left\lbrace 5\left[ \frac{\sigma}{r}\right]^{12}- 6\left[ \frac{\sigma}{r}\right]^{10} \right\rbrace cos^n(\theta + \theta_{offset})\\ From 787c49d8415a15d07e7565762b25b7ef0c00ad73 Mon Sep 17 00:00:00 2001 From: EiPi Fun Date: Tue, 3 Sep 2024 21:14:10 +0800 Subject: [PATCH 13/70] Add information about mixing and shift into doc and improve code format --- doc/src/pair_hbond_dreiding_angleoffset.rst | 6 ++++++ .../pair_hbond_dreiding_lj_angleoffset.cpp | 12 ++++++------ .../pair_hbond_dreiding_morse_angleoffset.cpp | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/doc/src/pair_hbond_dreiding_angleoffset.rst b/doc/src/pair_hbond_dreiding_angleoffset.rst index dff6040218..97bf93ffe4 100644 --- a/doc/src/pair_hbond_dreiding_angleoffset.rst +++ b/doc/src/pair_hbond_dreiding_angleoffset.rst @@ -118,6 +118,12 @@ follows: Additional Information """""""""""""""""""""" +These pair styles do not support mixing. You must explicitly identify +each donor/acceptor type pair. + +These styles do not support the :doc:`pair_modify ` shift +option for the energy of the interactions. + For more information about DREIDING force field and other notes, please refer to the :doc:`documentation of the *hbond/dreiding* pair styles `. diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp index 3b30baa2b3..68cf24c5ac 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp @@ -305,13 +305,13 @@ void PairHbondDreidingLJangleoffset::allocate() void PairHbondDreidingLJangleoffset::settings(int narg, char **arg) { - if (narg != 5) error->all(FLERR,"Illegal pair_style command"); + if (narg != 5) error->all(FLERR, "Illegal pair_style command"); - ap_global = utils::inumeric(FLERR,arg[0],false,lmp); - cut_inner_global = utils::numeric(FLERR,arg[1],false,lmp); - cut_outer_global = utils::numeric(FLERR,arg[2],false,lmp); - cut_angle_global = utils::numeric(FLERR,arg[3],false,lmp) * MY_PI/180.0; - angle_offset_global = (180.0 - utils::numeric(FLERR,arg[4],false,lmp)) * MY_PI/180.0; + ap_global = utils::inumeric(FLERR, arg[0], false, lmp); + cut_inner_global = utils::numeric(FLERR, arg[1], false, lmp); + cut_outer_global = utils::numeric(FLERR, arg[2], false, lmp); + cut_angle_global = utils::numeric(FLERR, arg[3], false, lmp) * MY_PI/180.0; + angle_offset_global = (180.0 - utils::numeric(FLERR, arg[4], false, lmp)) * MY_PI/180.0; } /* ---------------------------------------------------------------------- diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp index 173eac605f..2a1b6f1142 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp @@ -274,7 +274,7 @@ void PairHbondDreidingMorseAngleoffset::coeff(int narg, char **arg) double cut_angle_one = cut_angle_global; if (narg > 10) cut_angle_one = utils::numeric(FLERR, arg[10], false, lmp) * MY_PI/180.0; double angle_offset_one = angle_offset_global; - if (narg == 12) angle_offset_one = (180.0 - utils::numeric(FLERR,arg[11],false,lmp)) * MY_PI/180.0; + if (narg == 12) angle_offset_one = (180.0 - utils::numeric(FLERR, arg[11], false, lmp)) * MY_PI/180.0; if (angle_offset_one < 0.0 || angle_offset_one > 90.0 * MY_PI/180.0) error->all(FLERR,"Illegal angle offset"); From 0fa1255cc33804e275f71efc68b91a69d7011f3d Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 12 Nov 2024 09:38:16 -0700 Subject: [PATCH 14/70] fix python/invoke: ensure computes have run --- src/PYTHON/fix_python_invoke.cpp | 18 ++++++++++++++++++ src/PYTHON/fix_python_invoke.h | 1 + 2 files changed, 19 insertions(+) diff --git a/src/PYTHON/fix_python_invoke.cpp b/src/PYTHON/fix_python_invoke.cpp index 7fd3ad88f7..b47a94c6c7 100644 --- a/src/PYTHON/fix_python_invoke.cpp +++ b/src/PYTHON/fix_python_invoke.cpp @@ -22,6 +22,7 @@ #include "lmppython.h" #include "python_compat.h" #include "python_utils.h" +#include "modify.h" #include "update.h" #include @@ -70,6 +71,8 @@ FixPythonInvoke::FixPythonInvoke(LAMMPS *lmp, int narg, char **arg) : } lmpPtr = PY_VOID_POINTER(lmp); + + modify->addstep_compute_all(nextvalid()); } /* ---------------------------------------------------------------------- */ @@ -91,6 +94,8 @@ int FixPythonInvoke::setmask() void FixPythonInvoke::end_of_step() { + modify->clearstep_compute(); + PyUtils::GIL lock; PyObject * result = PyObject_CallFunction((PyObject*)pFunc, (char *)"O", (PyObject*)lmpPtr); @@ -101,6 +106,8 @@ void FixPythonInvoke::end_of_step() } Py_CLEAR(result); + + modify->addstep_compute(nextvalid()); } /* ---------------------------------------------------------------------- */ @@ -116,6 +123,8 @@ void FixPythonInvoke::post_force(int vflag) { if (update->ntimestep % nevery != 0) return; + modify->clearstep_compute(); + PyUtils::GIL lock; char fmt[] = "Oi"; @@ -127,4 +136,13 @@ void FixPythonInvoke::post_force(int vflag) } Py_CLEAR(result); + + modify->addstep_compute(nextvalid()); +} + +/* ---------------------------------------------------------------------- */ + +bigint FixPythonInvoke::nextvalid() +{ + return (update->ntimestep/nevery + 1)*nevery; } diff --git a/src/PYTHON/fix_python_invoke.h b/src/PYTHON/fix_python_invoke.h index 09382e5780..3d2324a939 100644 --- a/src/PYTHON/fix_python_invoke.h +++ b/src/PYTHON/fix_python_invoke.h @@ -38,6 +38,7 @@ class FixPythonInvoke : public Fix { void *lmpPtr; void *pFunc; int selected_callback; + bigint nextvalid(); }; } // namespace LAMMPS_NS From c6e9e90e15a053c1766002250e5b30c711743873 Mon Sep 17 00:00:00 2001 From: megmcca Date: Mon, 16 Dec 2024 09:37:21 -0700 Subject: [PATCH 15/70] refactor to mirror airebo/morse class structure --- doc/src/pair_hbond_dreiding.rst | 40 +- doc/src/pair_hbond_dreiding_angleoffset.rst | 138 ------ .../pair_hbond_dreiding_lj_angleoffset.cpp | 464 +----------------- .../pair_hbond_dreiding_lj_angleoffset.h | 43 +- .../pair_hbond_dreiding_morse_angleoffset.cpp | 375 +------------- .../pair_hbond_dreiding_morse_angleoffset.h | 14 +- src/MOLECULE/pair_hbond_dreiding_lj.cpp | 43 +- src/MOLECULE/pair_hbond_dreiding_lj.h | 4 +- src/MOLECULE/pair_hbond_dreiding_morse.cpp | 16 + 9 files changed, 147 insertions(+), 990 deletions(-) delete mode 100644 doc/src/pair_hbond_dreiding_angleoffset.rst diff --git a/doc/src/pair_hbond_dreiding.rst b/doc/src/pair_hbond_dreiding.rst index 7e73f23b08..33f81f2439 100644 --- a/doc/src/pair_hbond_dreiding.rst +++ b/doc/src/pair_hbond_dreiding.rst @@ -1,31 +1,46 @@ .. index:: pair_style hbond/dreiding/lj .. index:: pair_style hbond/dreiding/lj/omp +.. index:: pair_style hbond/dreiding/lj/angleoffset +.. index:: pair_style hbond/dreiding/lj/angleoffset/omp .. index:: pair_style hbond/dreiding/morse .. index:: pair_style hbond/dreiding/morse/omp +.. index:: pair_style hbond/dreiding/morse/angleoffset +.. index:: pair_style hbond/dreiding/morse/angleoffset/omp pair_style hbond/dreiding/lj command ==================================== Accelerator Variants: *hbond/dreiding/lj/omp* +pair_style hbond/dreiding/lj/angleoffset command +================================================ + +Accelerator Variants: *hbond/dreiding/lj/angleoffset/omp* + pair_style hbond/dreiding/morse command ======================================= Accelerator Variants: *hbond/dreiding/morse/omp* +pair_style hbond/dreiding/morse/angleoffset command +=================================================== + +Accelerator Variants: *hbond/dreiding/morse/angleoffset/omp* + + Syntax """""" .. code-block:: LAMMPS - pair_style style N inner_distance_cutoff outer_distance_cutoff angle_cutof + pair_style style N inner_distance_cutoff outer_distance_cutoff angle_cutoff equilibrium_angle -* style = *hbond/dreiding/lj* or *hbond/dreiding/morse* +* style = *hbond/dreiding/lj* or *hbond/dreiding/morse* or *hbond/dreiding/lj/angleoffset* or *hbond/dreiding/morse/angleoffset* * n = cosine angle periodicity * inner_distance_cutoff = global inner cutoff for Donor-Acceptor interactions (distance units) * outer_distance_cutoff = global cutoff for Donor-Acceptor interactions (distance units) -* angle_cutoff = global angle cutoff for Acceptor-Hydrogen-Donor -* interactions (degrees) +* angle_cutoff = global angle cutoff for Acceptor-Hydrogen-Donor interactions (degrees) +* (with style angleoffset) equilibrium_angle = global equilibrium angle for Acceptor-Hydrogen-Donor interactions (degrees) Examples """""""" @@ -41,6 +56,9 @@ Examples labelmap atom 1 C 2 O 3 H pair_coeff C O hbond/dreiding/morse H i 3.88 1.7241379 2.9 2 9 11 90 + pair_style hybrid/overlay lj/cut 10.0 hbond/dreiding/lj 4 9.0 11.0 90 170.0 + pair_coeff 1 2 hbond/dreiding/lj 3 i 9.5 2.75 4 9.0 11.0 90.0 + Description """"""""""" @@ -91,6 +109,8 @@ potential for the Donor-Acceptor interactions. :ref:`(Liu) ` showed that the Morse form gives improved results for Dendrimer simulations, when n = 2. +The style variants *hbond/dreiding/lj/angleoffset* and *hbond/dreiding/lj/angleoffset* takes the equilibrium angle of the AHD as input, allowing it to reach 180 degrees. This variant option was added to account for cases (especially in some coarse-grained models) in which the equilibrium state of the bonds may equal the minimum energy state. + See the :doc:`Howto bioFF ` page for more information on the DREIDING force field. @@ -119,6 +139,10 @@ on the DREIDING force field. special_bonds command (e.g. "special_bonds lj 0.0 0.0 1.0") to turn these interactions on. +.. note:: + + For the *angle_offset* variants, the referenced angle offset is the supplementary angle of the equilibrium angle parameter. It means if the equilibrium angle is 166.6 degrees, the calculated angle offset is 13.4 degrees. + ---------- The following coefficients must be defined for pairs of eligible @@ -169,7 +193,10 @@ follows: * distance cutoff :math:`r_{out}` (distance units) * angle cutoff (degrees) -A single hydrogen atom type K can be specified, or a wild-card asterisk +For both the *hbond/dreiding/lj/angleoffset* and *hbond/dreiding/morse/angleoffset* styles an additional parameter is added: +* equilibrium angle (degrees) + +For all styles, a single hydrogen atom type K can be specified, or a wild-card asterisk can be used in place of or in conjunction with the K arguments to select multiple types as hydrogen atoms. This takes the form "\*" or "\*n" or "n\*" or "m\*n". See the :doc:`pair_coeff ` @@ -244,8 +271,7 @@ heading) the following commands could be included in an input script: Restrictions """""""""""" -This pair style can only be used if LAMMPS was built with the -MOLECULE package. See the :doc:`Build package ` doc page +The base pair styles can only be used if LAMMPS was built with the MOLECULE package. The *angleoffset* variant also requires the EXTRA-MOLECULE package. See the :doc:`Build package ` doc page for more info. Related commands diff --git a/doc/src/pair_hbond_dreiding_angleoffset.rst b/doc/src/pair_hbond_dreiding_angleoffset.rst deleted file mode 100644 index 97bf93ffe4..0000000000 --- a/doc/src/pair_hbond_dreiding_angleoffset.rst +++ /dev/null @@ -1,138 +0,0 @@ -.. index:: pair_style hbond/dreiding/lj/angleoffset -.. index:: pair_style hbond/dreiding/lj/angleoffset/omp -.. index:: pair_style hbond/dreiding/morse/angleoffset -.. index:: pair_style hbond/dreiding/morse/angleoffset/omp - -pair_style hbond/dreiding/lj/angleoffset command -================================================ - -Accelerator Variants: *hbond/dreiding/lj/angleoffset/omp* - -pair_style hbond/dreiding/morse/angleoffset command -=================================================== - -Accelerator Variants: *hbond/dreiding/morse/angleoffset/omp* - -Syntax -"""""" - -.. code-block:: LAMMPS - - pair_style style N inner_distance_cutoff outer_distance_cutoff angle_cutoff equilibrium_angle - -* style = *hbond/dreiding/lj/angleoffset* or *hbond/dreiding/morse/angleoffset* -* N = power of cosine of sum of angle theta and angle offset (integer) -* inner_distance_cutoff = global inner cutoff for Donor-Acceptor interactions (distance units) -* outer_distance_cutoff = global cutoff for Donor-Acceptor interactions (distance units) -* angle_cutoff = global angle cutoff for Acceptor-Hydrogen-Donor interactions (degrees) -* equilibrium_angle = global equilibrium angle for Acceptor-Hydrogen-Donor interactions (degrees) - -(Tips: angle offset is the supplementary angle of the equilibrium angle. It means if the -equilibrium angle is 166.6, the angle offset is 13.4) - -Examples -"""""""" - -.. code-block:: LAMMPS - - pair_style hybrid/overlay lj/cut 10.0 hbond/dreiding/lj/angleoffset 4 9.0 11.0 90.0 170.0 - pair_coeff 1 2 hbond/dreiding/lj 3 i 9.5 2.75 4 9.0 11.0 90.0 160.0 - - pair_style hybrid/overlay lj/cut 10.0 hbond/dreiding/morse/angleoffset 2 9.0 11.0 90.0 170.0 - pair_coeff 1 2 hbond/dreiding/morse 3 i 3.88 1.7241379 2.9 2 9.0 11.0 90.0 160.0 - - labelmap atom 1 C 2 O 3 H - pair_coeff C O hbond/dreiding/morse H i 3.88 1.7241379 2.9 2 9.0 11.0 90.0 160.0 - -Description -""""""""""" - -The *hbond/dreiding/\*/angleoffset* styles are modified version of *hbond/dreiding* styles. - -In some cases, the angle of acceptor-hydrogen-donor in the equilibrium state could not achieve 180 degree especially in some coarse grained models. -In these cases, an angle offset is required to ensure that equilibrium state could be the minimum energy state. - -The *hbond/dreiding/\*/angleoffset* styles compute the Acceptor-Hydrogen-Donor (AHD) -3-body hydrogen bond interaction for the :doc:`DREIDING ` -force field with an angle offset, given by: - -.. math:: - - E = & \left[LJ(r) | Morse(r) \right] \qquad \qquad \qquad r < r_{\rm in} and \theta + \theta_{offset} > \theta_c \\ - = & S(r) * \left[LJ(r) | Morse(r) \right] \qquad \qquad r_{\rm in} < r < r_{\rm out} and \theta + \theta_{offset} > \theta_c \\ - = & 0 \qquad \qquad \qquad \qquad \qquad \qquad \qquad r > r_{\rm out} and \theta + \theta_{offset} > \theta_c \\ - LJ(r) = & AR^{-12}-BR^{-10}cos^n(\theta + \theta_{offset})= - \epsilon\left\lbrace 5\left[ \frac{\sigma}{r}\right]^{12}- - 6\left[ \frac{\sigma}{r}\right]^{10} \right\rbrace cos^n(\theta + \theta_{offset})\\ - Morse(r) = & D_0\left\lbrace \chi^2 - 2\chi\right\rbrace cos^n(\theta + \theta_{offset})= - D_{0}\left\lbrace e^{- 2 \alpha (r - r_0)} - 2 e^{- \alpha (r - r_0)} - \right\rbrace cos^n(\theta + \theta_{offset})\\ - S(r) = & \frac{ \left[r_{\rm out}^2 - r^2\right]^2 - \left[r_{\rm out}^2 + 2r^2 - 3{r_{\rm in}^2}\right]} - { \left[r_{\rm out}^2 - {r_{\rm in}}^2\right]^3 } - -where :math:`r_{\rm in}` is the inner spline distance cutoff, -:math:`r_{\rm out}` is the outer distance cutoff, :math:`\theta_c` is -the angle cutoff, :math:`\theta_offset` is the angle offset, and :math:`n` is the power of the cosine of the sum of the angle :math:`\theta` and the angle offset :math:`\theta_offset` - -Here, *r* is the radial distance between the donor (D) and acceptor -(A) atoms and :math:`\theta` is the bond angle between the acceptor, the -hydrogen (H) and the donor atoms: - -.. image:: JPG/dreiding_hbond.jpg - :align: center - -For the *hbond/dreiding/lj/angleoffset* style the list of coefficients is as -follows: - -* K = hydrogen atom type = 1 to Ntypes, or type label -* donor flag = *i* or *j* -* :math:`\epsilon` (energy units) -* :math:`\sigma` (distance units) -* *n* = exponent in formula above -* distance cutoff :math:`r_{\rm in}` (distance units) -* distance cutoff :math:`r_{\rm out}` (distance units) -* angle cutoff (degrees) -* equilibrium angle (degrees) - -(Tips: angle offset is the supplementary angle of equilibrium angle) - -For the *hbond/dreiding/morse/angleoffset* style the list of coefficients is as -follows: - -* K = hydrogen atom type = 1 to Ntypes, or type label -* donor flag = *i* or *j* -* :math:`D_0` (energy units) -* :math:`\alpha` (1/distance units) -* :math:`r_0` (distance units) -* *n* = exponent in formula above -* distance cutoff :math:`r_{\rm in}` (distance units) -* distance cutoff :math:`r_{out}` (distance units) -* angle cutoff (degrees) -* equilibrium angle (degrees) - -(Tips: angle offset is the supplementary angle of equilibrium angle) - ----------- - -Additional Information -"""""""""""""""""""""" - -These pair styles do not support mixing. You must explicitly identify -each donor/acceptor type pair. - -These styles do not support the :doc:`pair_modify ` shift -option for the energy of the interactions. - -For more information about DREIDING force field and other notes, please refer -to the :doc:`documentation of the *hbond/dreiding* pair styles `. - ----------- - -Restrictions -"""""""""""" - -This pair style can only be used if LAMMPS was built with the -EXTRA-MOLECULE package. See the :doc:`Build package ` -doc page for more info. - diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp index 68cf24c5ac..829c750536 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp @@ -33,292 +33,44 @@ #include #include -using namespace LAMMPS_NS; -using namespace MathConst; -using namespace MathSpecial; - static constexpr double SMALL = 0.001; static constexpr int CHUNK = 8; -/* ---------------------------------------------------------------------- */ - -PairHbondDreidingLJangleoffset::PairHbondDreidingLJangleoffset(LAMMPS *lmp) : Pair(lmp) -{ - // hbond cannot compute virial as F dot r - // due to using map() to find bonded H atoms which are not near donor atom - - no_virial_fdotr_compute = 1; - restartinfo = 0; - - nparams = maxparam = 0; - params = nullptr; - - nextra = 2; - pvector = new double[2]; -} +using namespace LAMMPS_NS; +using namespace MathConst; +// using namespace MathSpecial; /* ---------------------------------------------------------------------- */ -PairHbondDreidingLJangleoffset::~PairHbondDreidingLJangleoffset() -{ - memory->sfree(params); - delete [] pvector; +PairHbondDreidingLJAngleoffset::PairHbondDreidingLJAngleoffset(LAMMPS *lmp) + : PairHbondDreidingLJ(lmp) { - if (allocated) { - memory->destroy(setflag); - memory->destroy(cutsq); - - delete [] donor; - delete [] acceptor; - memory->destroy(type2param); - } -} - -/* ---------------------------------------------------------------------- */ - -void PairHbondDreidingLJangleoffset::compute(int eflag, int vflag) -{ - int i,j,k,m,ii,jj,kk,inum,jnum,knum,itype,jtype,ktype,iatom,imol; - tagint tagprev; - double delx,dely,delz,rsq,rsq1,rsq2,r1,r2; - double factor_hb,force_angle,force_kernel,evdwl,eng_lj,ehbond,force_switch; - double c,s,a,b,ac,a11,a12,a22,vx1,vx2,vy1,vy2,vz1,vz2,d; - double fi[3],fj[3],delr1[3],delr2[3]; - double r2inv,r10inv; - double switch1,switch2; - int *ilist,*jlist,*numneigh,**firstneigh; - tagint *klist; - - evdwl = ehbond = 0.0; - ev_init(eflag,vflag); - - double **x = atom->x; - double **f = atom->f; - tagint *tag = atom->tag; - int *molindex = atom->molindex; - int *molatom = atom->molatom; - tagint **special = atom->special; - int **nspecial = atom->nspecial; - int *type = atom->type; - double *special_lj = force->special_lj; - int molecular = atom->molecular; - Molecule **onemols = atom->avec->onemols; - - inum = list->inum; - ilist = list->ilist; - numneigh = list->numneigh; - firstneigh = list->firstneigh; - - // ii = loop over donors - // jj = loop over acceptors - // kk = loop over hydrogens bonded to donor - - int hbcount = 0; - - for (ii = 0; ii < inum; ii++) { - i = ilist[ii]; - itype = type[i]; - if (!donor[itype]) continue; - if (molecular == Atom::MOLECULAR) { - klist = special[i]; - knum = nspecial[i][0]; - } else { - if (molindex[i] < 0) continue; - imol = molindex[i]; - iatom = molatom[i]; - klist = onemols[imol]->special[iatom]; - knum = onemols[imol]->nspecial[iatom][0]; - tagprev = tag[i] - iatom - 1; - } - jlist = firstneigh[i]; - jnum = numneigh[i]; - - for (jj = 0; jj < jnum; jj++) { - j = jlist[jj]; - factor_hb = special_lj[sbmask(j)]; - j &= NEIGHMASK; - - jtype = type[j]; - if (!acceptor[jtype]) continue; - - delx = x[i][0] - x[j][0]; - dely = x[i][1] - x[j][1]; - delz = x[i][2] - x[j][2]; - rsq = delx*delx + dely*dely + delz*delz; - - for (kk = 0; kk < knum; kk++) { - if (molecular == Atom::MOLECULAR) k = atom->map(klist[kk]); - else k = atom->map(klist[kk]+tagprev); - if (k < 0) continue; - ktype = type[k]; - m = type2param[itype][jtype][ktype]; - if (m < 0) continue; - const Param &pm = params[m]; - - if (rsq < pm.cut_outersq) { - delr1[0] = x[i][0] - x[k][0]; - delr1[1] = x[i][1] - x[k][1]; - delr1[2] = x[i][2] - x[k][2]; - domain->minimum_image(delr1); - rsq1 = delr1[0]*delr1[0] + delr1[1]*delr1[1] + delr1[2]*delr1[2]; - r1 = sqrt(rsq1); - - delr2[0] = x[j][0] - x[k][0]; - delr2[1] = x[j][1] - x[k][1]; - delr2[2] = x[j][2] - x[k][2]; - domain->minimum_image(delr2); - rsq2 = delr2[0]*delr2[0] + delr2[1]*delr2[1] + delr2[2]*delr2[2]; - r2 = sqrt(rsq2); - - // angle (cos and sin) - - c = delr1[0]*delr2[0] + delr1[1]*delr2[1] + delr1[2]*delr2[2]; - c /= r1*r2; - if (c > 1.0) c = 1.0; - if (c < -1.0) c = -1.0; - ac = acos(c); - - ac = ac + pm.angle_offset; - c = cos(ac); - if (c > 1.0) c = 1.0; - if (c < -1.0) c = -1.0; - - if (ac > pm.cut_angle && ac < (2.0*MY_PI - pm.cut_angle)) { - s = sqrt(1.0 - c*c); - if (s < SMALL) s = SMALL; - - // LJ-specific kernel - - r2inv = 1.0/rsq; - r10inv = r2inv*r2inv*r2inv*r2inv*r2inv; - force_kernel = r10inv*(pm.lj1*r2inv - pm.lj2)*r2inv * - powint(c,pm.ap); - force_angle = pm.ap * r10inv*(pm.lj3*r2inv - pm.lj4) * - powint(c,pm.ap-1)*s; - - eng_lj = r10inv*(pm.lj3*r2inv - pm.lj4); - - force_switch=0.0; - - if (rsq > pm.cut_innersq) { - switch1 = (pm.cut_outersq-rsq) * (pm.cut_outersq-rsq) * - (pm.cut_outersq + 2.0*rsq - 3.0*pm.cut_innersq) / - pm.denom_vdw; - switch2 = 12.0*rsq * (pm.cut_outersq-rsq) * - (rsq-pm.cut_innersq) / pm.denom_vdw; - - force_kernel *= switch1; - force_angle *= switch1; - force_switch = eng_lj*switch2/rsq; - eng_lj *= switch1; - } - - if (eflag) { - evdwl = eng_lj * powint(c,pm.ap); - evdwl *= factor_hb; - ehbond += evdwl; - } - - a = factor_hb*force_angle/s; - b = factor_hb*force_kernel; - d = factor_hb*force_switch; - - a11 = a*c / rsq1; - a12 = -a / (r1*r2); - a22 = a*c / rsq2; - - vx1 = a11*delr1[0] + a12*delr2[0]; - vx2 = a22*delr2[0] + a12*delr1[0]; - vy1 = a11*delr1[1] + a12*delr2[1]; - vy2 = a22*delr2[1] + a12*delr1[1]; - vz1 = a11*delr1[2] + a12*delr2[2]; - vz2 = a22*delr2[2] + a12*delr1[2]; - - fi[0] = vx1 + b*delx + d*delx; - fi[1] = vy1 + b*dely + d*dely; - fi[2] = vz1 + b*delz + d*delz; - fj[0] = vx2 - b*delx - d*delx; - fj[1] = vy2 - b*dely - d*dely; - fj[2] = vz2 - b*delz - d*delz; - - 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] -= vx1 + vx2; - f[k][1] -= vy1 + vy2; - f[k][2] -= vz1 + vz2; - - // KIJ instead of IJK b/c delr1/delr2 are both with respect to k - - if (evflag) ev_tally3(k,i,j,evdwl,0.0,fi,fj,delr1,delr2); - - hbcount++; - } - } - } - } - } - - if (eflag_global) { - pvector[0] = hbcount; - pvector[1] = ehbond; - } -} - -/* ---------------------------------------------------------------------- - allocate all arrays -------------------------------------------------------------------------- */ - -void PairHbondDreidingLJangleoffset::allocate() -{ - allocated = 1; - int n = atom->ntypes; - - // mark all setflag as set, since don't require pair_coeff of all I,J - - memory->create(setflag,n+1,n+1,"pair:setflag"); - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 1; - - memory->create(cutsq,n+1,n+1,"pair:cutsq"); - - donor = new int[n+1]; - acceptor = new int[n+1]; - memory->create(type2param,n+1,n+1,n+1,"pair:type2param"); - - int i,j,k; - for (i = 1; i <= n; i++) - for (j = 1; j <= n; j++) - for (k = 1; k <= n; k++) - type2param[i][j][k] = -1; + angle_offset_flag = 1; + angle_offset_global = 0.0; + angle_offset_one = 0.0; } /* ---------------------------------------------------------------------- global settings ------------------------------------------------------------------------- */ -void PairHbondDreidingLJangleoffset::settings(int narg, char **arg) +void PairHbondDreidingLJAngleoffset::settings(int narg, char **arg) { - if (narg != 5) error->all(FLERR, "Illegal pair_style command"); + if (narg != 5) error->all(FLERR,"Illegal pair_style command"); + + // use first four settings args in parent method to update other variables + + PairHbondDreidingLJ::settings(4,arg); - ap_global = utils::inumeric(FLERR, arg[0], false, lmp); - cut_inner_global = utils::numeric(FLERR, arg[1], false, lmp); - cut_outer_global = utils::numeric(FLERR, arg[2], false, lmp); - cut_angle_global = utils::numeric(FLERR, arg[3], false, lmp) * MY_PI/180.0; angle_offset_global = (180.0 - utils::numeric(FLERR, arg[4], false, lmp)) * MY_PI/180.0; + } /* ---------------------------------------------------------------------- set coeffs for one or more type pairs ------------------------------------------------------------------------- */ -void PairHbondDreidingLJangleoffset::coeff(int narg, char **arg) +void PairHbondDreidingLJAngleoffset::coeff(int narg, char **arg) { if (narg < 6 || narg > 11) error->all(FLERR,"Incorrect args for pair coefficients"); @@ -395,187 +147,3 @@ void PairHbondDreidingLJangleoffset::coeff(int narg, char **arg) if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } - -/* ---------------------------------------------------------------------- - init specific to this pair style -------------------------------------------------------------------------- */ - -void PairHbondDreidingLJangleoffset::init_style() -{ - // molecular system required to use special list to find H atoms - // tags required to use special list - // pair newton on required since are looping over D atoms - // and computing forces on A,H which may be on different procs - - if (atom->molecular == Atom::ATOMIC) - error->all(FLERR,"Pair style hbond/dreiding/lj/angleoffset requires molecular system"); - if (atom->tag_enable == 0) - error->all(FLERR,"Pair style hbond/dreiding/lj/angleoffset requires atom IDs"); - if (atom->map_style == Atom::MAP_NONE) - error->all(FLERR,"Pair style hbond/dreiding/lj/angleoffset requires an atom map, " - "see atom_modify"); - if (force->newton_pair == 0) - error->all(FLERR,"Pair style hbond/dreiding/lj/angleoffset requires newton pair on"); - - // set donor[M]/acceptor[M] if any atom of type M is a donor/acceptor - - int anyflag = 0; - int n = atom->ntypes; - for (int m = 1; m <= n; m++) donor[m] = acceptor[m] = 0; - for (int i = 1; i <= n; i++) - for (int j = 1; j <= n; j++) - for (int k = 1; k <= n; k++) - if (type2param[i][j][k] >= 0) { - anyflag = 1; - donor[i] = 1; - acceptor[j] = 1; - } - - if (!anyflag) error->all(FLERR,"No pair hbond/dreiding/lj/angleoffset coefficients set"); - - // set additional param values - // offset is for LJ only, angle term is not included - - for (int m = 0; m < nparams; m++) { - params[m].lj1 = 60.0*params[m].epsilon*pow(params[m].sigma,12.0); - params[m].lj2 = 60.0*params[m].epsilon*pow(params[m].sigma,10.0); - params[m].lj3 = 5.0*params[m].epsilon*pow(params[m].sigma,12.0); - params[m].lj4 = 6.0*params[m].epsilon*pow(params[m].sigma,10.0); - } - - // full neighbor list request - - neighbor->add_request(this, NeighConst::REQ_FULL); -} - -/* ---------------------------------------------------------------------- - init for one type pair i,j and corresponding j,i -------------------------------------------------------------------------- */ - -double PairHbondDreidingLJangleoffset::init_one(int i, int j) -{ - int m; - - // return maximum cutoff for any K with I,J = D,A or J,I = D,A - // donor/acceptor is not symmetric, IJ interaction != JI interaction - - double cut = 0.0; - for (int k = 1; k <= atom->ntypes; k++) { - m = type2param[i][j][k]; - if (m >= 0) cut = MAX(cut,params[m].cut_outer); - m = type2param[j][i][k]; - if (m >= 0) cut = MAX(cut,params[m].cut_outer); - } - return cut; -} - -/* ---------------------------------------------------------------------- */ - -double PairHbondDreidingLJangleoffset::single(int i, int j, int itype, int jtype, - double rsq, - double /*factor_coul*/, double /*factor_lj*/, - double &fforce) -{ - int k,kk,ktype,knum,m; - tagint tagprev; - double eng,eng_lj,force_kernel,force_angle; - double rsq1,rsq2,r1,r2,c,s,ac,r2inv,r10inv,factor_hb; - double switch1,switch2; - double delr1[3],delr2[3]; - tagint *klist; - - double **x = atom->x; - int *type = atom->type; - double *special_lj = force->special_lj; - - eng = 0.0; - fforce = 0; - - // sanity check - - if (!donor[itype]) return 0.0; - if (!acceptor[jtype]) return 0.0; - - int molecular = atom->molecular; - if (molecular == Atom::MOLECULAR) { - klist = atom->special[i]; - knum = atom->nspecial[i][0]; - } else { - if (atom->molindex[i] < 0) return 0.0; - int imol = atom->molindex[i]; - int iatom = atom->molatom[i]; - Molecule **onemols = atom->avec->onemols; - klist = onemols[imol]->special[iatom]; - knum = onemols[imol]->nspecial[iatom][0]; - tagprev = atom->tag[i] - iatom - 1; - } - - factor_hb = special_lj[sbmask(j)]; - - for (kk = 0; kk < knum; kk++) { - if (molecular == Atom::MOLECULAR) k = atom->map(klist[kk]); - else k = atom->map(klist[kk]+tagprev); - - if (k < 0) continue; - ktype = type[k]; - m = type2param[itype][jtype][ktype]; - if (m < 0) continue; - const Param &pm = params[m]; - - delr1[0] = x[i][0] - x[k][0]; - delr1[1] = x[i][1] - x[k][1]; - delr1[2] = x[i][2] - x[k][2]; - domain->minimum_image(delr1); - rsq1 = delr1[0]*delr1[0] + delr1[1]*delr1[1] + delr1[2]*delr1[2]; - r1 = sqrt(rsq1); - - delr2[0] = x[j][0] - x[k][0]; - delr2[1] = x[j][1] - x[k][1]; - delr2[2] = x[j][2] - x[k][2]; - domain->minimum_image(delr2); - rsq2 = delr2[0]*delr2[0] + delr2[1]*delr2[1] + delr2[2]*delr2[2]; - r2 = sqrt(rsq2); - - // angle (cos and sin) - - c = delr1[0]*delr2[0] + delr1[1]*delr2[1] + delr1[2]*delr2[2]; - c /= r1*r2; - if (c > 1.0) c = 1.0; - if (c < -1.0) c = -1.0; - ac = acos(c); - - ac = ac + pm.angle_offset; - c = cos(ac); - if (c > 1.0) c = 1.0; - if (c < -1.0) c = -1.0; - - if (ac < pm.cut_angle || ac > (2.0*MY_PI - pm.cut_angle)) return 0.0; - s = sqrt(1.0 - c*c); - if (s < SMALL) s = SMALL; - - // LJ-specific kernel - - r2inv = 1.0/rsq; - r10inv = r2inv*r2inv*r2inv*r2inv*r2inv; - force_kernel = r10inv*(pm.lj1*r2inv - pm.lj2)*r2inv * powint(c,pm.ap); - force_angle = pm.ap * r10inv*(pm.lj3*r2inv - pm.lj4) * - powint(c,pm.ap-1)*s; - - // only lj part for now - - eng_lj = r10inv*(pm.lj3*r2inv - pm.lj4); - if (rsq > pm.cut_innersq) { - switch1 = (pm.cut_outersq-rsq) * (pm.cut_outersq-rsq) * - (pm.cut_outersq + 2.0*rsq - 3.0*pm.cut_innersq) / pm.denom_vdw; - switch2 = 12.0*rsq * (pm.cut_outersq-rsq) * - (rsq-pm.cut_innersq) / pm.denom_vdw; - force_kernel = force_kernel*switch1 + eng_lj*switch2; - eng_lj *= switch1; - } - - fforce += force_kernel*powint(c,pm.ap) + eng_lj*force_angle; - eng += eng_lj * powint(c,pm.ap) * factor_hb; - } - - return eng; -} diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.h b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.h index 331d8e2ac1..590c5198b7 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.h +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.h @@ -13,53 +13,28 @@ #ifdef PAIR_CLASS // clang-format off -PairStyle(hbond/dreiding/lj/angleoffset,PairHbondDreidingLJangleoffset); +PairStyle(hbond/dreiding/lj/angleoffset,PairHbondDreidingLJAngleoffset); // clang-format on #else #ifndef LMP_PAIR_HBOND_DREIDING_LJ_ANGLEOFFSET_H #define LMP_PAIR_HBOND_DREIDING_LJ_ANGLEOFFSET_H -#include "pair.h" +#include "pair_hbond_dreiding_lj.h" namespace LAMMPS_NS { -class PairHbondDreidingLJangleoffset : public Pair { - public: - PairHbondDreidingLJangleoffset(class LAMMPS *); - ~PairHbondDreidingLJangleoffset() override; - void compute(int, int) override; - void settings(int, char **) override; - void coeff(int, char **) override; - void init_style() override; - double init_one(int, int) override; - double single(int, int, int, int, double, double, double, double &) override; + class PairHbondDreidingLJAngleoffset : public PairHbondDreidingLJ { - protected: - double cut_inner_global, cut_outer_global, cut_angle_global, angle_offset_global; - int ap_global; + public: + PairHbondDreidingLJAngleoffset(class LAMMPS *); + void settings(int, char **) override; + void coeff(int, char **) override; - struct Param { - double epsilon, sigma; - double lj1, lj2, lj3, lj4; - double d0, alpha, r0; - double morse1; - double denom_vdw; - double cut_inner, cut_outer, cut_innersq, cut_outersq, cut_angle, offset, angle_offset; - int ap; + protected: + double angle_offset_global, angle_offset_one, cut_angle_one; }; - Param *params; // parameter set for an I-J-K interaction - int nparams; // number of parameters read - int maxparam; - - int *donor; // 1 if this type is ever a donor, else 0 - int *acceptor; // 1 if this type is ever an acceptor, else 0 - int ***type2param; // mapping from D,A,H to params, -1 if no map - - void allocate(); -}; - } // namespace LAMMPS_NS #endif diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp index 2a1b6f1142..227b84cc4d 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp @@ -35,212 +35,40 @@ using namespace LAMMPS_NS; using namespace MathConst; -using namespace MathSpecial; -static constexpr double SMALL = 0.001; static constexpr int CHUNK = 8; /* ---------------------------------------------------------------------- */ PairHbondDreidingMorseAngleoffset::PairHbondDreidingMorseAngleoffset(LAMMPS *lmp) : - PairHbondDreidingLJangleoffset(lmp) {} + PairHbondDreidingLJ(lmp) { -/* ---------------------------------------------------------------------- */ - -void PairHbondDreidingMorseAngleoffset::compute(int eflag, int vflag) -{ - int i,j,k,m,ii,jj,kk,inum,jnum,knum,itype,jtype,ktype,imol,iatom; - tagint tagprev; - double delx,dely,delz,rsq,rsq1,rsq2,r1,r2; - double factor_hb,force_angle,force_kernel,force_switch,evdwl,ehbond; - double c,s,a,b,d,ac,a11,a12,a22,vx1,vx2,vy1,vy2,vz1,vz2; - double fi[3],fj[3],delr1[3],delr2[3]; - double r,dr,dexp,eng_morse,switch1,switch2; - int *ilist,*jlist,*numneigh,**firstneigh; - tagint *klist; - - evdwl = ehbond = 0.0; - ev_init(eflag,vflag); - - double **x = atom->x; - double **f = atom->f; - tagint *tag = atom->tag; - int *molindex = atom->molindex; - int *molatom = atom->molatom; - tagint **special = atom->special; - int **nspecial = atom->nspecial; - int *type = atom->type; - double *special_lj = force->special_lj; - int molecular = atom->molecular; - Molecule **onemols = atom->avec->onemols; - - inum = list->inum; - ilist = list->ilist; - numneigh = list->numneigh; - firstneigh = list->firstneigh; - - // ii = loop over donors - // jj = loop over acceptors - // kk = loop over hydrogens bonded to donor - - int hbcount = 0; - - for (ii = 0; ii < inum; ii++) { - i = ilist[ii]; - itype = type[i]; - if (!donor[itype]) continue; - if (molecular == Atom::MOLECULAR) { - klist = special[i]; - knum = nspecial[i][0]; - } else { - if (molindex[i] < 0) continue; - imol = molindex[i]; - iatom = molatom[i]; - klist = onemols[imol]->special[iatom]; - knum = onemols[imol]->nspecial[iatom][0]; - tagprev = tag[i] - iatom - 1; - } - jlist = firstneigh[i]; - jnum = numneigh[i]; - - for (jj = 0; jj < jnum; jj++) { - j = jlist[jj]; - factor_hb = special_lj[sbmask(j)]; - j &= NEIGHMASK; - - jtype = type[j]; - if (!acceptor[jtype]) continue; - - delx = x[i][0] - x[j][0]; - dely = x[i][1] - x[j][1]; - delz = x[i][2] - x[j][2]; - rsq = delx*delx + dely*dely + delz*delz; - - for (kk = 0; kk < knum; kk++) { - if (molecular == Atom::MOLECULAR) k = atom->map(klist[kk]); - else k = atom->map(klist[kk]+tagprev); - if (k < 0) continue; - ktype = type[k]; - m = type2param[itype][jtype][ktype]; - if (m < 0) continue; - const Param &pm = params[m]; - - if (rsq < pm.cut_outersq) { - delr1[0] = x[i][0] - x[k][0]; - delr1[1] = x[i][1] - x[k][1]; - delr1[2] = x[i][2] - x[k][2]; - domain->minimum_image(delr1); - rsq1 = delr1[0]*delr1[0] + delr1[1]*delr1[1] + delr1[2]*delr1[2]; - r1 = sqrt(rsq1); - - delr2[0] = x[j][0] - x[k][0]; - delr2[1] = x[j][1] - x[k][1]; - delr2[2] = x[j][2] - x[k][2]; - domain->minimum_image(delr2); - rsq2 = delr2[0]*delr2[0] + delr2[1]*delr2[1] + delr2[2]*delr2[2]; - r2 = sqrt(rsq2); - - // angle (cos and sin) - - c = delr1[0]*delr2[0] + delr1[1]*delr2[1] + delr1[2]*delr2[2]; - c /= r1*r2; - if (c > 1.0) c = 1.0; - if (c < -1.0) c = -1.0; - ac = acos(c); - - ac = ac + pm.angle_offset; - c = cos(ac); - if (c > 1.0) c = 1.0; - if (c < -1.0) c = -1.0; - - if (ac > pm.cut_angle && ac < (2.0*MY_PI - pm.cut_angle)) { - s = sqrt(1.0 - c*c); - if (s < SMALL) s = SMALL; - - // Morse-specific kernel - - r = sqrt(rsq); - dr = r - pm.r0; - dexp = exp(-pm.alpha * dr); - eng_morse = pm.d0 * (dexp*dexp - 2.0*dexp); - force_kernel = pm.morse1*(dexp*dexp - dexp)/r * powint(c,pm.ap); - force_angle = pm.ap * eng_morse * powint(c,pm.ap-1)*s; - force_switch = 0.0; - - if (rsq > pm.cut_innersq) { - switch1 = (pm.cut_outersq-rsq) * (pm.cut_outersq-rsq) * - (pm.cut_outersq + 2.0*rsq - 3.0*pm.cut_innersq) / - pm.denom_vdw; - switch2 = 12.0*rsq * (pm.cut_outersq-rsq) * - (rsq-pm.cut_innersq) / pm.denom_vdw; - - force_kernel *= switch1; - force_angle *= switch1; - force_switch = eng_morse*switch2/rsq; - eng_morse *= switch1; - } - - if (eflag) { - evdwl = eng_morse * powint(c,pm.ap); - evdwl *= factor_hb; - ehbond += evdwl; - } - - a = factor_hb*force_angle/s; - b = factor_hb*force_kernel; - d = factor_hb*force_switch; - - a11 = a*c / rsq1; - a12 = -a / (r1*r2); - a22 = a*c / rsq2; - - vx1 = a11*delr1[0] + a12*delr2[0]; - vx2 = a22*delr2[0] + a12*delr1[0]; - vy1 = a11*delr1[1] + a12*delr2[1]; - vy2 = a22*delr2[1] + a12*delr1[1]; - vz1 = a11*delr1[2] + a12*delr2[2]; - vz2 = a22*delr2[2] + a12*delr1[2]; - - fi[0] = vx1 + (b+d)*delx; - fi[1] = vy1 + (b+d)*dely; - fi[2] = vz1 + (b+d)*delz; - fj[0] = vx2 - (b+d)*delx; - fj[1] = vy2 - (b+d)*dely; - fj[2] = vz2 - (b+d)*delz; - - 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] -= vx1 + vx2; - f[k][1] -= vy1 + vy2; - f[k][2] -= vz1 + vz2; - - // KIJ instead of IJK b/c delr1/delr2 are both with respect to k - - if (evflag) ev_tally3(k,i,j,evdwl,0.0,fi,fj,delr1,delr2); - - hbcount++; - } - } - } - } - } - - if (eflag_global) { - pvector[0] = hbcount; - pvector[1] = ehbond; - } + angle_offset_flag = 1; + angle_offset_global = 0.0; + angle_offset_one = 0.0; } + /* ---------------------------------------------------------------------- - set coeffs for one or more type pairs + global settings ------------------------------------------------------------------------- */ +void PairHbondDreidingMorseAngleoffset::settings(int narg, char **arg) +{ + if (narg != 5) error->all(FLERR,"Illegal pair_style command"); + + // use first four settings args in parent method to update other variables + + PairHbondDreidingLJ::settings(4,arg); + + angle_offset_global = (180.0 - utils::numeric(FLERR, arg[4], false, lmp)) * MY_PI/180.0; + +} + +// /* ---------------------------------------------------------------------- +// set coeffs for one or more type pairs +// ------------------------------------------------------------------------- */ + void PairHbondDreidingMorseAngleoffset::coeff(int narg, char **arg) { if (narg < 7 || narg > 12) @@ -318,162 +146,3 @@ void PairHbondDreidingMorseAngleoffset::coeff(int narg, char **arg) if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } - -/* ---------------------------------------------------------------------- - init specific to this pair style -------------------------------------------------------------------------- */ - -void PairHbondDreidingMorseAngleoffset::init_style() -{ - // molecular system required to use special list to find H atoms - // tags required to use special list - // pair newton on required since are looping over D atoms - // and computing forces on A,H which may be on different procs - - if (atom->molecular == Atom::ATOMIC) - error->all(FLERR,"Pair style hbond/dreiding/morse/angleoffset requires molecular system"); - if (atom->tag_enable == 0) - error->all(FLERR,"Pair style hbond/dreiding/morse/angleoffset requires atom IDs"); - if (atom->map_style == Atom::MAP_NONE) - error->all(FLERR,"Pair style hbond/dreiding/morse/angleoffset requires an atom map, " - "see atom_modify"); - if (force->newton_pair == 0) - error->all(FLERR,"Pair style hbond/dreiding/morse/angleoffset requires newton pair on"); - - // set donor[M]/acceptor[M] if any atom of type M is a donor/acceptor - - int anyflag = 0; - int n = atom->ntypes; - for (int m = 1; m <= n; m++) donor[m] = acceptor[m] = 0; - for (int i = 1; i <= n; i++) - for (int j = 1; j <= n; j++) - for (int k = 1; k <= n; k++) - if (type2param[i][j][k] >= 0) { - anyflag = 1; - donor[i] = 1; - acceptor[j] = 1; - } - - if (!anyflag) error->all(FLERR,"No pair hbond/dreiding/morse/angleoffset coefficients set"); - - // set additional param values - // offset is for Morse only, angle term is not included - - for (int m = 0; m < nparams; m++) { - params[m].morse1 = 2.0*params[m].d0*params[m].alpha; - } - - // full neighbor list request - - neighbor->add_request(this, NeighConst::REQ_FULL); -} - -/* ---------------------------------------------------------------------- */ - -double PairHbondDreidingMorseAngleoffset::single(int i, int j, int itype, int jtype, - double rsq, - double /*factor_coul*/, double /*factor_lj*/, - double &fforce) -{ - int k,kk,ktype,knum,m; - tagint tagprev; - double eng,eng_morse,force_kernel,force_angle; - double rsq1,rsq2,r1,r2,c,s,ac,r,dr,dexp,factor_hb; - double switch1,switch2; - double delr1[3],delr2[3]; - tagint *klist; - - double **x = atom->x; - int *type = atom->type; - double *special_lj = force->special_lj; - - eng = 0.0; - fforce = 0; - - //sanity check - - if (!donor[itype]) return 0.0; - if (!acceptor[jtype]) return 0.0; - - int molecular = atom->molecular; - if (molecular == Atom::MOLECULAR) { - klist = atom->special[i]; - knum = atom->nspecial[i][0]; - } else { - if (atom->molindex[i] < 0) return 0.0; - int imol = atom->molindex[i]; - int iatom = atom->molatom[i]; - Molecule **onemols = atom->avec->onemols; - klist = onemols[imol]->special[iatom]; - knum = onemols[imol]->nspecial[iatom][0]; - tagprev = atom->tag[i] - iatom - 1; - } - - factor_hb = special_lj[sbmask(j)]; - - for (kk = 0; kk < knum; kk++) { - if (molecular == Atom::MOLECULAR) k = atom->map(klist[kk]); - else k = atom->map(klist[kk]+tagprev); - - if (k < 0) continue; - ktype = type[k]; - m = type2param[itype][jtype][ktype]; - if (m < 0) continue; - const Param &pm = params[m]; - - delr1[0] = x[i][0] - x[k][0]; - delr1[1] = x[i][1] - x[k][1]; - delr1[2] = x[i][2] - x[k][2]; - domain->minimum_image(delr1); - rsq1 = delr1[0]*delr1[0] + delr1[1]*delr1[1] + delr1[2]*delr1[2]; - r1 = sqrt(rsq1); - - delr2[0] = x[j][0] - x[k][0]; - delr2[1] = x[j][1] - x[k][1]; - delr2[2] = x[j][2] - x[k][2]; - domain->minimum_image(delr2); - rsq2 = delr2[0]*delr2[0] + delr2[1]*delr2[1] + delr2[2]*delr2[2]; - r2 = sqrt(rsq2); - - // angle (cos and sin) - - c = delr1[0]*delr2[0] + delr1[1]*delr2[1] + delr1[2]*delr2[2]; - c /= r1*r2; - if (c > 1.0) c = 1.0; - if (c < -1.0) c = -1.0; - ac = acos(c); - - ac = ac + pm.angle_offset; - c = cos(ac); - if (c > 1.0) c = 1.0; - if (c < -1.0) c = -1.0; - - if (ac < pm.cut_angle || ac > (2.0*MY_PI - pm.cut_angle)) return 0.0; - s = sqrt(1.0 - c*c); - if (s < SMALL) s = SMALL; - - // Morse-specific kernel - - r = sqrt(rsq); - dr = r - pm.r0; - dexp = exp(-pm.alpha * dr); - eng_morse = pm.d0 * (dexp*dexp - 2.0*dexp); //<-- BUGFIX 2012-11-14 - force_kernel = pm.morse1*(dexp*dexp - dexp)/r * powint(c,pm.ap); - force_angle = pm.ap * eng_morse * powint(c,pm.ap-1)*s; - - if (rsq > pm.cut_innersq) { - switch1 = (pm.cut_outersq-rsq) * (pm.cut_outersq-rsq) * - (pm.cut_outersq + 2.0*rsq - 3.0*pm.cut_innersq) / - pm.denom_vdw; - switch2 = 12.0*rsq * (pm.cut_outersq-rsq) * - (rsq-pm.cut_innersq) / pm.denom_vdw; - force_kernel = force_kernel*switch1 + eng_morse*switch2; - eng_morse *= switch1; - } - - eng += eng_morse * powint(c,pm.ap)* factor_hb; - fforce += force_kernel*powint(c,pm.ap) + eng_morse*force_angle; - } - - return eng; -} diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h index c1b0cf2f30..2622aed852 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h @@ -20,18 +20,20 @@ PairStyle(hbond/dreiding/morse/angleoffset,PairHbondDreidingMorseAngleoffset); #ifndef LMP_PAIR_HBOND_DREIDING_MORSE_ANGLEOFFSET_H #define LMP_PAIR_HBOND_DREIDING_MORSE_ANGLEOFFSET_H -#include "pair_hbond_dreiding_lj_angleoffset.h" +#include "pair_hbond_dreiding_lj.h" +// #include "pair_hbond_dreiding_morse.h" namespace LAMMPS_NS { -class PairHbondDreidingMorseAngleoffset : public PairHbondDreidingLJangleoffset { +class PairHbondDreidingMorseAngleoffset : public PairHbondDreidingLJ { + public: PairHbondDreidingMorseAngleoffset(class LAMMPS *); - - void compute(int, int) override; + void settings(int, char **) override; void coeff(int, char **) override; - void init_style() override; - double single(int, int, int, int, double, double, double, double &) override; + + protected: + double angle_offset_global, angle_offset_one, cut_angle_one; }; } // namespace LAMMPS_NS diff --git a/src/MOLECULE/pair_hbond_dreiding_lj.cpp b/src/MOLECULE/pair_hbond_dreiding_lj.cpp index 274f8bc2a3..491e17230a 100644 --- a/src/MOLECULE/pair_hbond_dreiding_lj.cpp +++ b/src/MOLECULE/pair_hbond_dreiding_lj.cpp @@ -13,13 +13,14 @@ ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- - Contributing author: Tod A Pascal (Caltech) + Contributing authors: Tod A Pascal (Caltech), Don Xu/EiPi Fun ------------------------------------------------------------------------- */ #include "pair_hbond_dreiding_lj.h" #include "atom.h" #include "atom_vec.h" +#include "comm.h" #include "domain.h" #include "error.h" #include "force.h" @@ -55,6 +56,8 @@ PairHbondDreidingLJ::PairHbondDreidingLJ(LAMMPS *lmp) : Pair(lmp) nextra = 2; pvector = new double[2]; + + angle_offset_flag = 0; } /* ---------------------------------------------------------------------- */ @@ -178,6 +181,13 @@ void PairHbondDreidingLJ::compute(int eflag, int vflag) if (c < -1.0) c = -1.0; ac = acos(c); + if (angle_offset_flag){ + ac = ac + pm.angle_offset; + c = cos(ac); + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; + } + if (ac > pm.cut_angle && ac < (2.0*MY_PI - pm.cut_angle)) { s = sqrt(1.0 - c*c); if (s < SMALL) s = SMALL; @@ -314,8 +324,14 @@ void PairHbondDreidingLJ::settings(int narg, char **arg) void PairHbondDreidingLJ::coeff(int narg, char **arg) { - if (narg < 6 || narg > 10) + // account for angleoffset variant in EXTRA-MOLECULE + int maxarg = 10; + if (angle_offset_flag == 1) maxarg = 11; + + // check settings + if (narg < 6 || narg > maxarg) error->all(FLERR,"Incorrect args for pair coefficients"); + if (!allocated) allocate(); int ilo,ihi,jlo,jhi,klo,khi; @@ -343,8 +359,14 @@ void PairHbondDreidingLJ::coeff(int narg, char **arg) error->all(FLERR,"Pair inner cutoff >= Pair outer cutoff"); double cut_angle_one = cut_angle_global; if (narg == 10) cut_angle_one = utils::numeric(FLERR, arg[9], false, lmp) * MY_PI/180.0; + + if (comm->me == 0) + utils::logmesg(lmp,"---> DEBUG BASECLASS cut_angle_one {} \n", cut_angle_one); + // grow params array if necessary + if (comm->me == 0) + utils::logmesg(lmp,"---> DEBUG BASECLASS coeff nparams {} maxparam {}\n", nparams, maxparam); if (nparams == maxparam) { maxparam += CHUNK; params = (Param *) memory->srealloc(params, maxparam*sizeof(Param), @@ -352,10 +374,12 @@ void PairHbondDreidingLJ::coeff(int narg, char **arg) // make certain all addional allocated storage is initialized // to avoid false positives when checking with valgrind - memset(params + nparams, 0, CHUNK*sizeof(Param)); } + if (comm->me == 0) + utils::logmesg(lmp,"---> DEBUG BASECLASS coeff POST MEM nparams {} maxparam {}\n", nparams, maxparam); + params[nparams].epsilon = epsilon_one; params[nparams].sigma = sigma_one; params[nparams].ap = ap_one; @@ -369,6 +393,9 @@ void PairHbondDreidingLJ::coeff(int narg, char **arg) (params[nparams].cut_outersq-params[nparams].cut_innersq) * (params[nparams].cut_outersq-params[nparams].cut_innersq); + if (comm->me == 0) + utils::logmesg(lmp,"BASECLASS PARAMS angle_offset_flag {}\n eps {}\n sigma {}\n ap {}\n cin {}\n cout {}\n cangle {}\n denom_vdw {}\n ",angle_offset_flag, params[nparams].epsilon,params[nparams].sigma, params[nparams].ap,params[nparams].cut_inner, params[nparams].cut_outer, params[nparams].cut_angle, params[nparams].denom_vdw); + // flag type2param with either i,j = D,A or j,i = D,A int count = 0; @@ -381,6 +408,9 @@ void PairHbondDreidingLJ::coeff(int narg, char **arg) } nparams++; + if (comm->me == 0) + utils::logmesg(lmp,"---> DEBUG BASECLASS coeff END nparams {} count {}\n", nparams, count); + if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } @@ -540,6 +570,13 @@ double PairHbondDreidingLJ::single(int i, int j, int itype, int jtype, if (c < -1.0) c = -1.0; ac = acos(c); + if (angle_offset_flag){ + ac = ac + pm.angle_offset; + c = cos(ac); + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; + } + if (ac < pm.cut_angle || ac > (2.0*MY_PI - pm.cut_angle)) return 0.0; s = sqrt(1.0 - c*c); if (s < SMALL) s = SMALL; diff --git a/src/MOLECULE/pair_hbond_dreiding_lj.h b/src/MOLECULE/pair_hbond_dreiding_lj.h index 91a906c5cb..e5cde8da69 100644 --- a/src/MOLECULE/pair_hbond_dreiding_lj.h +++ b/src/MOLECULE/pair_hbond_dreiding_lj.h @@ -25,6 +25,7 @@ PairStyle(hbond/dreiding/lj,PairHbondDreidingLJ); namespace LAMMPS_NS { class PairHbondDreidingLJ : public Pair { + public: PairHbondDreidingLJ(class LAMMPS *); ~PairHbondDreidingLJ() override; @@ -38,6 +39,7 @@ class PairHbondDreidingLJ : public Pair { protected: double cut_inner_global, cut_outer_global, cut_angle_global; int ap_global; + int angle_offset_flag; // 1 if angle offset variant used struct Param { double epsilon, sigma; @@ -45,7 +47,7 @@ class PairHbondDreidingLJ : public Pair { double d0, alpha, r0; double morse1; double denom_vdw; - double cut_inner, cut_outer, cut_innersq, cut_outersq, cut_angle, offset; + double cut_inner, cut_outer, cut_innersq, cut_outersq, cut_angle, offset, angle_offset; int ap; }; diff --git a/src/MOLECULE/pair_hbond_dreiding_morse.cpp b/src/MOLECULE/pair_hbond_dreiding_morse.cpp index c8bc0a627d..11cb9cc354 100644 --- a/src/MOLECULE/pair_hbond_dreiding_morse.cpp +++ b/src/MOLECULE/pair_hbond_dreiding_morse.cpp @@ -148,6 +148,14 @@ void PairHbondDreidingMorse::compute(int eflag, int vflag) if (c < -1.0) c = -1.0; ac = acos(c); + if (angle_offset_flag){ + ac = ac + pm.angle_offset; + c = cos(ac); + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; + } + + if (ac > pm.cut_angle && ac < (2.0*MY_PI - pm.cut_angle)) { s = sqrt(1.0 - c*c); if (s < SMALL) s = SMALL; @@ -295,6 +303,7 @@ void PairHbondDreidingMorse::coeff(int narg, char **arg) (params[nparams].cut_outersq-params[nparams].cut_innersq) * (params[nparams].cut_outersq-params[nparams].cut_innersq) * (params[nparams].cut_outersq-params[nparams].cut_innersq); + // if (angle_offset_flag) params[nparams].angle_offset = angle_offset_one; // flag type2param with either i,j = D,A or j,i = D,A @@ -443,6 +452,13 @@ double PairHbondDreidingMorse::single(int i, int j, int itype, int jtype, if (c < -1.0) c = -1.0; ac = acos(c); + if (angle_offset_flag){ + ac = ac + pm.angle_offset; + c = cos(ac); + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; + } + if (ac < pm.cut_angle || ac > (2.0*MY_PI - pm.cut_angle)) return 0.0; s = sqrt(1.0 - c*c); if (s < SMALL) s = SMALL; From 1896244d96ed99d187bd8cd17748ff67b6602038 Mon Sep 17 00:00:00 2001 From: jtclemm Date: Thu, 19 Dec 2024 15:15:39 -0700 Subject: [PATCH 16/70] Adding reference to deform/pressure in barostat howto --- doc/src/Howto_barostat.rst | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/doc/src/Howto_barostat.rst b/doc/src/Howto_barostat.rst index 0c25e2c53c..89ff4d183f 100644 --- a/doc/src/Howto_barostat.rst +++ b/doc/src/Howto_barostat.rst @@ -10,20 +10,21 @@ and/or pressure (P) is specified by the user, and the thermostat or barostat attempts to equilibrate the system to the requested T and/or P. -Barostatting in LAMMPS is performed by :doc:`fixes `. Two +Barostatting in LAMMPS is performed by :doc:`fixes `. Three barostatting methods are currently available: Nose-Hoover (npt and -nph) and Berendsen: +nph), Berendsen, and various linear controllers in deform/pressure: * :doc:`fix npt ` * :doc:`fix npt/sphere ` * :doc:`fix npt/asphere ` * :doc:`fix nph ` * :doc:`fix press/berendsen ` +* :doc:`fix deform/pressure ` The :doc:`fix npt ` commands include a Nose-Hoover thermostat and barostat. :doc:`Fix nph ` is just a Nose/Hoover barostat; -it does no thermostatting. Both :doc:`fix nph ` and :doc:`fix press/berendsen ` can be used in conjunction -with any of the thermostatting fixes. +it does no thermostatting. The fixes :doc:`nph `, :doc:`press/berendsen `, and :doc:`deform/pressure ` +can be used in conjunction with any of the thermostatting fixes. As with the :doc:`thermostats `, :doc:`fix npt ` and :doc:`fix nph ` only use translational motion of the @@ -44,9 +45,9 @@ a temperature or pressure compute to a barostatting fix. .. note:: As with the thermostats, the Nose/Hoover methods (:doc:`fix npt ` and :doc:`fix nph `) perform time integration. - :doc:`Fix press/berendsen ` does NOT, so it should - be used with one of the constant NVE fixes or with one of the NVT - fixes. + :doc:`Fix press/berendsen ` and :doc:`fix deform/pressure ` + do NOT, so they should be used with one of the constant NVE fixes or with + one of the NVT fixes. Thermodynamic output, which can be setup via the :doc:`thermo_style ` command, often includes pressure From 83a73ba0b91c8a9f7bac9a1a50a7598d7a19d96e Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 12 Nov 2024 13:43:22 -0700 Subject: [PATCH 17/70] library: add API for compute clearstep and addstep --- python/lammps/core.py | 22 ++++++++++++ src/library.cpp | 81 +++++++++++++++++++++++++++++++++++++++++++ src/library.h | 9 +++++ 3 files changed, 112 insertions(+) diff --git a/python/lammps/core.py b/python/lammps/core.py index 30df44f050..045d893448 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -339,6 +339,10 @@ class lammps(object): self.lib.lammps_extract_variable_datatype.argtypes = [c_void_p, c_char_p] self.lib.lammps_extract_variable_datatype.restype = c_int + self.lib.lammps_compute_clearstep.argtype = [c_void_p] + self.lib.lammps_compute_addstep.argtype = [c_void_p, self.c_bigint] + self.lib.lammps_compute_addstep_all.argtype = [c_void_p, self.c_bigint] + self.lib.lammps_fix_external_get_force.argtypes = [c_void_p, c_char_p] self.lib.lammps_fix_external_get_force.restype = POINTER(POINTER(c_double)) @@ -1453,6 +1457,24 @@ class lammps(object): # ------------------------------------------------------------------------- + def compute_clearstep(self, nextstep): + with ExceptionCheck(self): + return self.lib.lammps_compute_clearstep(self.lmp) + + # ------------------------------------------------------------------------- + + def compute_addstep(self, nextstep): + with ExceptionCheck(self): + return self.lib.lammps_compute_addstep(self.lmp, nextstep) + + # ------------------------------------------------------------------------- + + def compute_addstep_all(self, nextstep): + with ExceptionCheck(self): + return self.lib.lammps_compute_addstep_all(self.lmp, nextstep) + + # ------------------------------------------------------------------------- + def flush_buffers(self): """Flush output buffers diff --git a/src/library.cpp b/src/library.cpp index 9876d363e5..89c6e92bbd 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -2904,6 +2904,87 @@ int lammps_variable_info(void *handle, int idx, char *buffer, int buf_size) { return 0; } +/* ---------------------------------------------------------------------- */ + +/** Clear whether a compute has been invoked. + * +\verbatim embed:rst + +.. versionadded:: TBD + + This function clears the invoked flag of all computes. + Called everywhere that computes are used, before computes are invoked. + The invoked flag is used to avoid re-invoking same compute multiple times + and to flag computes that store invocation times as having been invoked + +\endverbatim + + * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. + */ +void lammps_compute_clearstep(void * handle) { + auto lmp = (LAMMPS *) handle; + + BEGIN_CAPTURE + { + lmp->modify->clearstep_compute(); + } + END_CAPTURE +} + +/* ---------------------------------------------------------------------- */ + +/** Add next timestep to all computes + * +\verbatim embed:rst + +.. versionadded:: TBD + + loop over all computes + schedule next invocation for those that store invocation times + called when not sure what computes will be needed on newstep + do not loop only over n_timeflag, since may not be set yet + +\endverbatim + + * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. + * \param newstep next timestep the compute will be invoked + */ +void lammps_compute_addstep_all(void * handle, bigint newstep) { + auto lmp = (LAMMPS *) handle; + + BEGIN_CAPTURE + { + lmp->modify->addstep_compute_all(newstep); + } + END_CAPTURE +} +/* ---------------------------------------------------------------------- */ + +/** Add next timestep to compute if it has been invoked in the current timestep + * +\verbatim embed:rst + +.. versionadded:: TBD + + loop over computes that store invocation times + if its invoked flag set on this timestep, schedule next invocation + called everywhere that computes are used, after computes are invoked + +\endverbatim + + * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. + * \param newstep next timestep the compute will be invoked + */ +void lammps_compute_addstep(void * handle, bigint newstep) { + auto lmp = (LAMMPS *) handle; + + BEGIN_CAPTURE + { + lmp->modify->addstep_compute(newstep); + } + END_CAPTURE +} + // ---------------------------------------------------------------------- // Library functions for scatter/gather operations of data // ---------------------------------------------------------------------- diff --git a/src/library.h b/src/library.h index 36e67470ae..b1213b67c8 100644 --- a/src/library.h +++ b/src/library.h @@ -190,6 +190,15 @@ int lammps_set_string_variable(void *handle, const char *name, const char *str); int lammps_set_internal_variable(void *handle, const char *name, double value); int lammps_variable_info(void *handle, int idx, char *buf, int bufsize); +void lammps_compute_clearstep(void * handle); +#if defined(LAMMPS_SMALLSMALL) +void lammps_compute_addstep_all(void * handle, int nextstep); +void lammps_compute_addstep(void * handle, int nextstep); +#else +void lammps_compute_addstep_all(void * handle, int64_t nextstep); +void lammps_compute_addstep(void * handle, int64_t nextstep); +#endif + /* ---------------------------------------------------------------------- * Library functions for scatter/gather operations of data * ---------------------------------------------------------------------- */ From 783d21c19b2b988c16a91dcadf294a885026c89a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 14 Jan 2025 00:55:48 -0500 Subject: [PATCH 18/70] these functions do not create errors or throw exceptions --- src/library.cpp | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/src/library.cpp b/src/library.cpp index 71243611a2..17225fec40 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -2979,12 +2979,7 @@ double lammps_eval(void *handle, const char *expr) */ void lammps_compute_clearstep(void * handle) { auto lmp = (LAMMPS *) handle; - - BEGIN_CAPTURE - { - lmp->modify->clearstep_compute(); - } - END_CAPTURE + lmp->modify->clearstep_compute(); } /* ---------------------------------------------------------------------- */ @@ -3007,12 +3002,7 @@ void lammps_compute_clearstep(void * handle) { */ void lammps_compute_addstep_all(void * handle, bigint newstep) { auto lmp = (LAMMPS *) handle; - - BEGIN_CAPTURE - { - lmp->modify->addstep_compute_all(newstep); - } - END_CAPTURE + lmp->modify->addstep_compute_all(newstep); } /* ---------------------------------------------------------------------- */ @@ -3033,12 +3023,7 @@ void lammps_compute_addstep_all(void * handle, bigint newstep) { */ void lammps_compute_addstep(void * handle, bigint newstep) { auto lmp = (LAMMPS *) handle; - - BEGIN_CAPTURE - { - lmp->modify->addstep_compute(newstep); - } - END_CAPTURE + lmp->modify->addstep_compute(newstep); } // ---------------------------------------------------------------------- From e682f3d3e5a94cda53163e37022726c2624160a2 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 14 Jan 2025 01:18:59 -0500 Subject: [PATCH 19/70] work on docs --- doc/src/Library_objects.rst | 18 ++++++++++++++++++ src/library.cpp | 12 ++++++++++++ src/library.h | 10 +++++----- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/doc/src/Library_objects.rst b/doc/src/Library_objects.rst index 53edfce9e6..bea5dec167 100644 --- a/doc/src/Library_objects.rst +++ b/doc/src/Library_objects.rst @@ -13,6 +13,9 @@ fixes, or variables in LAMMPS using the following functions: - :cpp:func:`lammps_set_internal_variable` - :cpp:func:`lammps_variable_info` - :cpp:func:`lammps_eval` +- :cpp:func:`lammps_compute_clearstep` +- :cpp:func:`lammps_compute_addstep_all` +- :cpp:func:`lammps_compute_addstep` ----------------------- @@ -61,6 +64,21 @@ fixes, or variables in LAMMPS using the following functions: ----------------------- +.. doxygenfunction:: lammps_compute_clearstep + :project: progguide + +----------------------- + +.. doxygenfunction:: lammps_compute_addstep_all(void *handle, int nextstep) + :project: progguide + +----------------------- + +.. doxygenfunction:: lammps_compute_addstep(void *handle, int nextstep) + :project: progguide + +----------------------- + .. doxygenenum:: _LMP_DATATYPE_CONST .. doxygenenum:: _LMP_STYLE_CONST diff --git a/src/library.cpp b/src/library.cpp index 17225fec40..1bb589c2b2 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -2973,6 +2973,10 @@ double lammps_eval(void *handle, const char *expr) The invoked flag is used to avoid re-invoking same compute multiple times and to flag computes that store invocation times as having been invoked +*See also* + :cpp:func:`lammps_compute_addstep_all` + :cpp:func:`lammps_compute_addstep` + \endverbatim * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. @@ -2995,6 +2999,10 @@ void lammps_compute_clearstep(void * handle) { called when not sure what computes will be needed on newstep do not loop only over n_timeflag, since may not be set yet +*See also* + :cpp:func:`lammps_compute_clearstep` + :cpp:func:`lammps_compute_addstep` + \endverbatim * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. @@ -3016,6 +3024,10 @@ void lammps_compute_addstep_all(void * handle, bigint newstep) { if its invoked flag set on this timestep, schedule next invocation called everywhere that computes are used, after computes are invoked +*See also* + :cpp:func:`lammps_compute_addstep_all` + :cpp:func:`lammps_compute_clearstep` + \endverbatim * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. diff --git a/src/library.h b/src/library.h index 54600ed422..a2575db20a 100644 --- a/src/library.h +++ b/src/library.h @@ -191,13 +191,13 @@ int lammps_set_internal_variable(void *handle, const char *name, double value); int lammps_variable_info(void *handle, int idx, char *buf, int bufsize); double lammps_eval(void *handle, const char *expr); -void lammps_compute_clearstep(void * handle); +void lammps_compute_clearstep(void *handle); #if defined(LAMMPS_SMALLSMALL) -void lammps_compute_addstep_all(void * handle, int nextstep); -void lammps_compute_addstep(void * handle, int nextstep); +void lammps_compute_addstep_all(void *handle, int nextstep); +void lammps_compute_addstep(void *handle, int nextstep); #else -void lammps_compute_addstep_all(void * handle, int64_t nextstep); -void lammps_compute_addstep(void * handle, int64_t nextstep); +void lammps_compute_addstep_all(void *handle, int64_t nextstep); +void lammps_compute_addstep(void *handle, int64_t nextstep); #endif /* ---------------------------------------------------------------------- From 41555a66e995a802f627d17f210a4394ce32f2aa Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 15 Jan 2025 04:20:34 -0500 Subject: [PATCH 20/70] correct documentation and add versionadded tag --- doc/src/Commands_pair.rst | 4 +-- doc/src/pair_hbond_dreiding.rst | 48 ++++++++++++++++++++------------- doc/src/pair_style.rst | 4 +-- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/doc/src/Commands_pair.rst b/doc/src/Commands_pair.rst index 8c0e09b446..048a54ed37 100644 --- a/doc/src/Commands_pair.rst +++ b/doc/src/Commands_pair.rst @@ -115,9 +115,9 @@ OPT. * :doc:`gw/zbl ` * :doc:`harmonic/cut (o) ` * :doc:`hbond/dreiding/lj (o) ` - * :doc:`hbond/dreiding/lj/angleoffset (o) ` + * :doc:`hbond/dreiding/lj/angleoffset (o) ` * :doc:`hbond/dreiding/morse (o) ` - * :doc:`hbond/dreiding/morse/angleoffset (o) ` + * :doc:`hbond/dreiding/morse/angleoffset (o) ` * :doc:`hdnnp ` * :doc:`hippo (g) ` * :doc:`ilp/graphene/hbn (t) ` diff --git a/doc/src/pair_hbond_dreiding.rst b/doc/src/pair_hbond_dreiding.rst index 363186f108..3b4c6e08a2 100644 --- a/doc/src/pair_hbond_dreiding.rst +++ b/doc/src/pair_hbond_dreiding.rst @@ -35,7 +35,7 @@ Syntax pair_style style N inner_distance_cutoff outer_distance_cutoff angle_cutoff equilibrium_angle -* style = *hbond/dreiding/lj* or *hbond/dreiding/morse* or *hbond/dreiding/lj/angleoffset* or *hbond/dreiding/morse/angleoffset +* style = *hbond/dreiding/lj* or *hbond/dreiding/morse* or *hbond/dreiding/lj/angleoffset* or *hbond/dreiding/morse/angleoffset* * N = power of cosine of angle theta (integer) * inner_distance_cutoff = global inner cutoff for Donor-Acceptor interactions (distance units) * outer_distance_cutoff = global cutoff for Donor-Acceptor interactions (distance units) @@ -93,44 +93,53 @@ hydrogen (H) and the donor atoms: .. image:: JPG/dreiding_hbond.jpg :align: center -These 3-body interactions can be defined for pairs of acceptor and -donor atoms, based on atom types. For each donor/acceptor atom pair, -the third atom in the interaction is a hydrogen permanently bonded to -the donor atom, e.g. in a bond list read in from a data file via the +These 3-body interactions can be defined for pairs of acceptor and donor +atoms, based on atom types. For each donor/acceptor atom pair, the +third atom in the interaction is a hydrogen permanently bonded to the +donor atom, e.g. in a bond list read in from a data file via the :doc:`read_data ` command. The atom types of possible hydrogen atoms for each donor/acceptor type pair are specified by the :doc:`pair_coeff ` command (see below). Style *hbond/dreiding/lj* is the original DREIDING potential of -:ref:`(Mayo) `. It uses a LJ 12/10 functional for the Donor-Acceptor -interactions. To match the results in the original paper, use n = 4. +:ref:`(Mayo) `. It uses a LJ 12/10 functional for the +Donor-Acceptor interactions. To match the results in the original paper, +use n = 4. Style *hbond/dreiding/morse* is an improved version using a Morse potential for the Donor-Acceptor interactions. :ref:`(Liu) ` showed that the Morse form gives improved results for Dendrimer simulations, when n = 2. -The style variants *hbond/dreiding/lj/angleoffset* and *hbond/dreiding/lj/angleoffset* take the equilibrium angle of the AHD as input, allowing it to reach 180 degrees. This variant option was added to account for cases (especially in some coarse-grained models) in which the equilibrium state of the bonds may equal the minimum energy state. +.. versionadded:: TBD + +The style variants *hbond/dreiding/lj/angleoffset* and +*hbond/dreiding/lj/angleoffset* take the equilibrium angle of the AHD as +input, allowing it to reach 180 degrees. This variant option was added +to account for cases (especially in some coarse-grained models) in which +the equilibrium state of the bonds may equal the minimum energy state. See the :doc:`Howto bioFF ` page for more information on the DREIDING force field. .. note:: - Because the Dreiding hydrogen bond potential is only one portion - of an overall force field which typically includes other pairwise - interactions, it is common to use it as a sub-style in a :doc:`pair_style hybrid/overlay ` command, where another pair style - provides the repulsive core interaction between pairs of atoms, e.g. a - 1/r\^12 Lennard-Jones repulsion. + Because the Dreiding hydrogen bond potential is only one portion of + an overall force field which typically includes other pairwise + interactions, it is common to use it as a sub-style in a + :doc:`pair_style hybrid/overlay ` command, where another + pair style provides the repulsive core interaction between pairs of + atoms, e.g. a 1/r\^12 Lennard-Jones repulsion. .. note:: - When using the hbond/dreiding pair styles with :doc:`pair_style hybrid/overlay `, you should explicitly define pair + When using the hbond/dreiding pair styles with :doc:`pair_style + hybrid/overlay `, you should explicitly define pair interactions between the donor atom and acceptor atoms, (as well as between these atoms and ALL other atoms in your system). Whenever - :doc:`pair_style hybrid/overlay ` is used, ordinary mixing - rules are not applied to atoms like the donor and acceptor atoms - because they are typically referenced in multiple pair styles. + :doc:`pair_style hybrid/overlay ` is used, ordinary + mixing rules are not applied to atoms like the donor and acceptor + atoms because they are typically referenced in multiple pair styles. Neglecting to do this can cause difficult-to-detect physics problems. .. note:: @@ -142,7 +151,10 @@ on the DREIDING force field. .. note:: - For the *angle_offset* variants, the referenced angle offset is the supplementary angle of the equilibrium angle parameter. It means if the equilibrium angle is 166.6 degrees, the calculated angle offset is 13.4 degrees. + For the *angleoffset* variants, the referenced angle offset is the + supplementary angle of the equilibrium angle parameter. It means if + the equilibrium angle is 166.6 degrees, the calculated angle offset + is 13.4 degrees. ---------- diff --git a/doc/src/pair_style.rst b/doc/src/pair_style.rst index 709383bb93..bdf06d6b66 100644 --- a/doc/src/pair_style.rst +++ b/doc/src/pair_style.rst @@ -207,9 +207,9 @@ accelerated styles exist. * :doc:`gw/zbl ` - Gao-Weber potential with a repulsive ZBL core * :doc:`harmonic/cut ` - repulsive-only harmonic potential * :doc:`hbond/dreiding/lj ` - DREIDING hydrogen bonding LJ potential -* :doc:`hbond/dreiding/lj/angleoffset ` - DREIDING hydrogen bonding LJ potential with offset for hbond angle +* :doc:`hbond/dreiding/lj/angleoffset ` - DREIDING hydrogen bonding LJ potential with offset for hbond angle * :doc:`hbond/dreiding/morse ` - DREIDING hydrogen bonding Morse potential -* :doc:`hbond/dreiding/morse/angleoffset ` - DREIDING hydrogen bonding Morse potential with offset for hbond angle +* :doc:`hbond/dreiding/morse/angleoffset ` - DREIDING hydrogen bonding Morse potential with offset for hbond angle * :doc:`hdnnp ` - High-dimensional neural network potential * :doc:`hippo ` - * :doc:`ilp/graphene/hbn ` - registry-dependent interlayer potential (ILP) From 11a790a04a7247c695e463aba87de75a4266b81e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 15 Jan 2025 04:36:51 -0500 Subject: [PATCH 21/70] angle_offset_one and cut_angle_one are only local variables --- src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp | 1 - src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.h | 2 +- src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp | 1 - src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h | 2 +- 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp index 829c750536..403377b3e0 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp @@ -47,7 +47,6 @@ PairHbondDreidingLJAngleoffset::PairHbondDreidingLJAngleoffset(LAMMPS *lmp) angle_offset_flag = 1; angle_offset_global = 0.0; - angle_offset_one = 0.0; } /* ---------------------------------------------------------------------- diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.h b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.h index 590c5198b7..6a286d9306 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.h +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.h @@ -32,7 +32,7 @@ namespace LAMMPS_NS { void coeff(int, char **) override; protected: - double angle_offset_global, angle_offset_one, cut_angle_one; + double angle_offset_global; }; } // namespace LAMMPS_NS diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp index 227b84cc4d..ba23b03775 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp @@ -45,7 +45,6 @@ PairHbondDreidingMorseAngleoffset::PairHbondDreidingMorseAngleoffset(LAMMPS *lmp angle_offset_flag = 1; angle_offset_global = 0.0; - angle_offset_one = 0.0; } diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h index 2622aed852..3cfb68821f 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h @@ -33,7 +33,7 @@ class PairHbondDreidingMorseAngleoffset : public PairHbondDreidingLJ { void coeff(int, char **) override; protected: - double angle_offset_global, angle_offset_one, cut_angle_one; + double angle_offset_global; }; } // namespace LAMMPS_NS From dfd8631394b66976b2202a9026012866bcbe2261 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 15 Jan 2025 04:40:48 -0500 Subject: [PATCH 22/70] remove debug output --- src/MOLECULE/pair_hbond_dreiding_lj.cpp | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/src/MOLECULE/pair_hbond_dreiding_lj.cpp b/src/MOLECULE/pair_hbond_dreiding_lj.cpp index 66055f754e..65b333ba02 100644 --- a/src/MOLECULE/pair_hbond_dreiding_lj.cpp +++ b/src/MOLECULE/pair_hbond_dreiding_lj.cpp @@ -20,7 +20,6 @@ #include "atom.h" #include "atom_vec.h" -#include "comm.h" #include "domain.h" #include "error.h" #include "force.h" @@ -360,26 +359,17 @@ void PairHbondDreidingLJ::coeff(int narg, char **arg) double cut_angle_one = cut_angle_global; if (narg == 10) cut_angle_one = utils::numeric(FLERR, arg[9], false, lmp) * MY_PI/180.0; - if (comm->me == 0) - utils::logmesg(lmp,"---> DEBUG BASECLASS cut_angle_one {} \n", cut_angle_one); - // grow params array if necessary - if (comm->me == 0) - utils::logmesg(lmp,"---> DEBUG BASECLASS coeff nparams {} maxparam {}\n", nparams, maxparam); if (nparams == maxparam) { maxparam += CHUNK; - params = (Param *) memory->srealloc(params, maxparam*sizeof(Param), - "pair:params"); + params = (Param *) memory->srealloc(params, maxparam*sizeof(Param), "pair:params"); // make certain all addional allocated storage is initialized // to avoid false positives when checking with valgrind memset(params + nparams, 0, CHUNK*sizeof(Param)); } - if (comm->me == 0) - utils::logmesg(lmp,"---> DEBUG BASECLASS coeff POST MEM nparams {} maxparam {}\n", nparams, maxparam); - params[nparams].epsilon = epsilon_one; params[nparams].sigma = sigma_one; params[nparams].ap = ap_one; @@ -393,9 +383,6 @@ void PairHbondDreidingLJ::coeff(int narg, char **arg) (params[nparams].cut_outersq-params[nparams].cut_innersq) * (params[nparams].cut_outersq-params[nparams].cut_innersq); - if (comm->me == 0) - utils::logmesg(lmp,"BASECLASS PARAMS angle_offset_flag {}\n eps {}\n sigma {}\n ap {}\n cin {}\n cout {}\n cangle {}\n denom_vdw {}\n ",angle_offset_flag, params[nparams].epsilon,params[nparams].sigma, params[nparams].ap,params[nparams].cut_inner, params[nparams].cut_outer, params[nparams].cut_angle, params[nparams].denom_vdw); - // flag type2param with either i,j = D,A or j,i = D,A int count = 0; @@ -408,9 +395,6 @@ void PairHbondDreidingLJ::coeff(int narg, char **arg) } nparams++; - if (comm->me == 0) - utils::logmesg(lmp,"---> DEBUG BASECLASS coeff END nparams {} count {}\n", nparams, count); - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } From 865ce67e83aba8f53960b431b3e02bbb15c52e21 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 15 Jan 2025 04:48:07 -0500 Subject: [PATCH 23/70] use correct base class --- .../pair_hbond_dreiding_morse_angleoffset.cpp | 6 +++--- src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp index ba23b03775..0d2dbf4fcf 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp @@ -41,7 +41,7 @@ static constexpr int CHUNK = 8; /* ---------------------------------------------------------------------- */ PairHbondDreidingMorseAngleoffset::PairHbondDreidingMorseAngleoffset(LAMMPS *lmp) : - PairHbondDreidingLJ(lmp) { + PairHbondDreidingMorse(lmp) { angle_offset_flag = 1; angle_offset_global = 0.0; @@ -58,7 +58,7 @@ void PairHbondDreidingMorseAngleoffset::settings(int narg, char **arg) // use first four settings args in parent method to update other variables - PairHbondDreidingLJ::settings(4,arg); + PairHbondDreidingMorse::settings(4,arg); angle_offset_global = (180.0 - utils::numeric(FLERR, arg[4], false, lmp)) * MY_PI/180.0; @@ -103,7 +103,7 @@ void PairHbondDreidingMorseAngleoffset::coeff(int narg, char **arg) double angle_offset_one = angle_offset_global; if (narg == 12) angle_offset_one = (180.0 - utils::numeric(FLERR, arg[11], false, lmp)) * MY_PI/180.0; if (angle_offset_one < 0.0 || angle_offset_one > 90.0 * MY_PI/180.0) - error->all(FLERR,"Illegal angle offset"); + error->all(FLERR,"Illegal angle offset {}", angle_offset_one); // grow params array if necessary diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h index 3cfb68821f..82c5b3bd50 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h @@ -20,12 +20,11 @@ PairStyle(hbond/dreiding/morse/angleoffset,PairHbondDreidingMorseAngleoffset); #ifndef LMP_PAIR_HBOND_DREIDING_MORSE_ANGLEOFFSET_H #define LMP_PAIR_HBOND_DREIDING_MORSE_ANGLEOFFSET_H -#include "pair_hbond_dreiding_lj.h" -// #include "pair_hbond_dreiding_morse.h" +#include "pair_hbond_dreiding_morse.h" namespace LAMMPS_NS { -class PairHbondDreidingMorseAngleoffset : public PairHbondDreidingLJ { +class PairHbondDreidingMorseAngleoffset : public PairHbondDreidingMorse { public: PairHbondDreidingMorseAngleoffset(class LAMMPS *); @@ -33,7 +32,7 @@ class PairHbondDreidingMorseAngleoffset : public PairHbondDreidingLJ { void coeff(int, char **) override; protected: - double angle_offset_global; + double angle_offset_global; }; } // namespace LAMMPS_NS From f1fb0906be91f33e943352a843d58ba42b821fdc Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 15 Jan 2025 04:49:21 -0500 Subject: [PATCH 24/70] correct class name --- .../pair_hbond_dreiding_lj_angleoffset_omp.cpp | 14 +++++++------- .../pair_hbond_dreiding_lj_angleoffset_omp.h | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.cpp b/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.cpp index 094beca70a..9d4b06af43 100644 --- a/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.cpp +++ b/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.cpp @@ -37,8 +37,8 @@ static constexpr double SMALL = 0.001; /* ---------------------------------------------------------------------- */ -PairHbondDreidingLJangleoffsetOMP::PairHbondDreidingLJangleoffsetOMP(LAMMPS *lmp) : - PairHbondDreidingLJangleoffset(lmp), ThrOMP(lmp, THR_PAIR) +PairHbondDreidingLJAngleoffsetOMP::PairHbondDreidingLJAngleoffsetOMP(LAMMPS *lmp) : + PairHbondDreidingLJAngleoffset(lmp), ThrOMP(lmp, THR_PAIR) { suffix_flag |= Suffix::OMP; respa_enable = 0; @@ -47,7 +47,7 @@ PairHbondDreidingLJangleoffsetOMP::PairHbondDreidingLJangleoffsetOMP(LAMMPS *lmp /* ---------------------------------------------------------------------- */ -PairHbondDreidingLJangleoffsetOMP::~PairHbondDreidingLJangleoffsetOMP() +PairHbondDreidingLJAngleoffsetOMP::~PairHbondDreidingLJAngleoffsetOMP() { if (hbcount_thr) { delete[] hbcount_thr; @@ -57,7 +57,7 @@ PairHbondDreidingLJangleoffsetOMP::~PairHbondDreidingLJangleoffsetOMP() /* ---------------------------------------------------------------------- */ -void PairHbondDreidingLJangleoffsetOMP::compute(int eflag, int vflag) +void PairHbondDreidingLJAngleoffsetOMP::compute(int eflag, int vflag) { ev_init(eflag,vflag); @@ -115,7 +115,7 @@ void PairHbondDreidingLJangleoffsetOMP::compute(int eflag, int vflag) } template -void PairHbondDreidingLJangleoffsetOMP::eval(int iifrom, int iito, ThrData * const thr) +void PairHbondDreidingLJAngleoffsetOMP::eval(int iifrom, int iito, ThrData * const thr) { int i,j,k,m,ii,jj,kk,jnum,knum,itype,jtype,ktype,iatom,imol; tagint tagprev; @@ -312,11 +312,11 @@ void PairHbondDreidingLJangleoffsetOMP::eval(int iifrom, int iito, ThrData * con /* ---------------------------------------------------------------------- */ -double PairHbondDreidingLJangleoffsetOMP::memory_usage() +double PairHbondDreidingLJAngleoffsetOMP::memory_usage() { double bytes = memory_usage_thr(); bytes += (double)comm->nthreads * 2 * sizeof(double); - bytes += PairHbondDreidingLJangleoffset::memory_usage(); + bytes += PairHbondDreidingLJAngleoffset::memory_usage(); return bytes; } diff --git a/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.h b/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.h index 0a4e14f68d..ef2ff9ee2e 100644 --- a/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.h +++ b/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.h @@ -17,7 +17,7 @@ #ifdef PAIR_CLASS // clang-format off -PairStyle(hbond/dreiding/lj/angleoffset/omp,PairHbondDreidingLJangleoffsetOMP); +PairStyle(hbond/dreiding/lj/angleoffset/omp,PairHbondDreidingLJAngleoffsetOMP); // clang-format on #else @@ -29,11 +29,11 @@ PairStyle(hbond/dreiding/lj/angleoffset/omp,PairHbondDreidingLJangleoffsetOMP); namespace LAMMPS_NS { -class PairHbondDreidingLJangleoffsetOMP : public PairHbondDreidingLJangleoffset, public ThrOMP { +class PairHbondDreidingLJAngleoffsetOMP : public PairHbondDreidingLJAngleoffset, public ThrOMP { public: - PairHbondDreidingLJangleoffsetOMP(class LAMMPS *); - ~PairHbondDreidingLJangleoffsetOMP() override; + PairHbondDreidingLJAngleoffsetOMP(class LAMMPS *); + ~PairHbondDreidingLJAngleoffsetOMP() override; void compute(int, int) override; double memory_usage() override; From 29fca919b1dfc732c266551e636ac2f909d13a63 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 15 Jan 2025 04:49:34 -0500 Subject: [PATCH 25/70] apply clang-format --- .../pair_hbond_dreiding_lj_angleoffset.h | 16 ++++++++-------- src/MOLECULE/pair_hbond_dreiding_morse.cpp | 1 - .../pair_hbond_dreiding_morse_angleoffset_omp.h | 4 +++- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.h b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.h index 6a286d9306..8b1a93b1bc 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.h +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.h @@ -24,16 +24,16 @@ PairStyle(hbond/dreiding/lj/angleoffset,PairHbondDreidingLJAngleoffset); namespace LAMMPS_NS { - class PairHbondDreidingLJAngleoffset : public PairHbondDreidingLJ { +class PairHbondDreidingLJAngleoffset : public PairHbondDreidingLJ { - public: - PairHbondDreidingLJAngleoffset(class LAMMPS *); - void settings(int, char **) override; - void coeff(int, char **) override; + public: + PairHbondDreidingLJAngleoffset(class LAMMPS *); + void settings(int, char **) override; + void coeff(int, char **) override; - protected: - double angle_offset_global; - }; + protected: + double angle_offset_global; +}; } // namespace LAMMPS_NS diff --git a/src/MOLECULE/pair_hbond_dreiding_morse.cpp b/src/MOLECULE/pair_hbond_dreiding_morse.cpp index 15e9d49654..34fddc9f89 100644 --- a/src/MOLECULE/pair_hbond_dreiding_morse.cpp +++ b/src/MOLECULE/pair_hbond_dreiding_morse.cpp @@ -303,7 +303,6 @@ void PairHbondDreidingMorse::coeff(int narg, char **arg) (params[nparams].cut_outersq-params[nparams].cut_innersq) * (params[nparams].cut_outersq-params[nparams].cut_innersq) * (params[nparams].cut_outersq-params[nparams].cut_innersq); - // if (angle_offset_flag) params[nparams].angle_offset = angle_offset_one; // flag type2param with either i,j = D,A or j,i = D,A diff --git a/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.h b/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.h index fb95988c6f..5e87908df3 100644 --- a/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.h +++ b/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.h @@ -29,7 +29,9 @@ PairStyle(hbond/dreiding/morse/angleoffset/omp,PairHbondDreidingMorseAngleoffset namespace LAMMPS_NS { -class PairHbondDreidingMorseAngleoffsetOMP : public PairHbondDreidingMorseAngleoffset, public ThrOMP { +class PairHbondDreidingMorseAngleoffsetOMP : + public PairHbondDreidingMorseAngleoffset, + public ThrOMP { public: PairHbondDreidingMorseAngleoffsetOMP(class LAMMPS *); From 66ffb1c39e9a66a62d5f98de08eb5bc14592956b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 15 Jan 2025 04:55:36 -0500 Subject: [PATCH 26/70] whitespace --- doc/src/pair_hbond_dreiding.rst | 4 ++-- src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp | 2 +- src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/src/pair_hbond_dreiding.rst b/doc/src/pair_hbond_dreiding.rst index 3b4c6e08a2..e059fdf2ba 100644 --- a/doc/src/pair_hbond_dreiding.rst +++ b/doc/src/pair_hbond_dreiding.rst @@ -40,7 +40,7 @@ Syntax * inner_distance_cutoff = global inner cutoff for Donor-Acceptor interactions (distance units) * outer_distance_cutoff = global cutoff for Donor-Acceptor interactions (distance units) * angle_cutoff = global angle cutoff for Acceptor-Hydrogen-Donor interactions (degrees) -* (with style angleoffset) equilibrium_angle = global equilibrium angle for Acceptor-Hydrogen-Donor interactions (degrees) +* (with style angleoffset) equilibrium_angle = global equilibrium angle for Acceptor-Hydrogen-Donor interactions (degrees) Examples """""""" @@ -207,7 +207,7 @@ follows: * angle cutoff (degrees) For both the *hbond/dreiding/lj/angleoffset* and *hbond/dreiding/morse/angleoffset* styles an additional parameter is added: -* equilibrium angle (degrees) +* equilibrium angle (degrees) For all styles, a single hydrogen atom type K can be specified, or a wild-card asterisk can be used in place of or in conjunction with the K arguments to diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp index 403377b3e0..390b72725d 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp @@ -42,7 +42,7 @@ using namespace MathConst; /* ---------------------------------------------------------------------- */ -PairHbondDreidingLJAngleoffset::PairHbondDreidingLJAngleoffset(LAMMPS *lmp) +PairHbondDreidingLJAngleoffset::PairHbondDreidingLJAngleoffset(LAMMPS *lmp) : PairHbondDreidingLJ(lmp) { angle_offset_flag = 1; diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp index 0d2dbf4fcf..37bcdd7ee2 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp @@ -57,11 +57,11 @@ void PairHbondDreidingMorseAngleoffset::settings(int narg, char **arg) if (narg != 5) error->all(FLERR,"Illegal pair_style command"); // use first four settings args in parent method to update other variables - + PairHbondDreidingMorse::settings(4,arg); angle_offset_global = (180.0 - utils::numeric(FLERR, arg[4], false, lmp)) * MY_PI/180.0; - + } // /* ---------------------------------------------------------------------- From 7fa1bf39f3d2db7488f5a315f770cef01d29cdf3 Mon Sep 17 00:00:00 2001 From: megmcca Date: Wed, 15 Jan 2025 10:24:25 -0700 Subject: [PATCH 27/70] shift settings check from angleoffset to base LJ --- .../pair_hbond_dreiding_lj_angleoffset.cpp | 17 ----------------- .../pair_hbond_dreiding_lj_angleoffset.h | 3 --- .../pair_hbond_dreiding_morse_angleoffset.cpp | 17 ----------------- .../pair_hbond_dreiding_morse_angleoffset.h | 5 +---- src/MOLECULE/pair_hbond_dreiding_lj.cpp | 10 +++++++++- src/MOLECULE/pair_hbond_dreiding_lj.h | 1 + 6 files changed, 11 insertions(+), 42 deletions(-) diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp index 390b72725d..02ac009773 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.cpp @@ -46,23 +46,6 @@ PairHbondDreidingLJAngleoffset::PairHbondDreidingLJAngleoffset(LAMMPS *lmp) : PairHbondDreidingLJ(lmp) { angle_offset_flag = 1; - angle_offset_global = 0.0; -} - -/* ---------------------------------------------------------------------- - global settings -------------------------------------------------------------------------- */ - -void PairHbondDreidingLJAngleoffset::settings(int narg, char **arg) -{ - if (narg != 5) error->all(FLERR,"Illegal pair_style command"); - - // use first four settings args in parent method to update other variables - - PairHbondDreidingLJ::settings(4,arg); - - angle_offset_global = (180.0 - utils::numeric(FLERR, arg[4], false, lmp)) * MY_PI/180.0; - } /* ---------------------------------------------------------------------- diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.h b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.h index 8b1a93b1bc..5ae1fcba28 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.h +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_lj_angleoffset.h @@ -28,11 +28,8 @@ class PairHbondDreidingLJAngleoffset : public PairHbondDreidingLJ { public: PairHbondDreidingLJAngleoffset(class LAMMPS *); - void settings(int, char **) override; void coeff(int, char **) override; - protected: - double angle_offset_global; }; } // namespace LAMMPS_NS diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp index 37bcdd7ee2..dedbbb8c9f 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp @@ -47,23 +47,6 @@ PairHbondDreidingMorseAngleoffset::PairHbondDreidingMorseAngleoffset(LAMMPS *lmp angle_offset_global = 0.0; } - -/* ---------------------------------------------------------------------- - global settings -------------------------------------------------------------------------- */ - -void PairHbondDreidingMorseAngleoffset::settings(int narg, char **arg) -{ - if (narg != 5) error->all(FLERR,"Illegal pair_style command"); - - // use first four settings args in parent method to update other variables - - PairHbondDreidingMorse::settings(4,arg); - - angle_offset_global = (180.0 - utils::numeric(FLERR, arg[4], false, lmp)) * MY_PI/180.0; - -} - // /* ---------------------------------------------------------------------- // set coeffs for one or more type pairs // ------------------------------------------------------------------------- */ diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h index 82c5b3bd50..5eeb1796a2 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h @@ -28,11 +28,8 @@ class PairHbondDreidingMorseAngleoffset : public PairHbondDreidingMorse { public: PairHbondDreidingMorseAngleoffset(class LAMMPS *); - void settings(int, char **) override; void coeff(int, char **) override; - - protected: - double angle_offset_global; + }; } // namespace LAMMPS_NS diff --git a/src/MOLECULE/pair_hbond_dreiding_lj.cpp b/src/MOLECULE/pair_hbond_dreiding_lj.cpp index 65b333ba02..ebe7fdd123 100644 --- a/src/MOLECULE/pair_hbond_dreiding_lj.cpp +++ b/src/MOLECULE/pair_hbond_dreiding_lj.cpp @@ -57,6 +57,7 @@ PairHbondDreidingLJ::PairHbondDreidingLJ(LAMMPS *lmp) : Pair(lmp) pvector = new double[2]; angle_offset_flag = 0; + angle_offset_global = 0.0; } /* ---------------------------------------------------------------------- */ @@ -309,12 +310,19 @@ void PairHbondDreidingLJ::allocate() void PairHbondDreidingLJ::settings(int narg, char **arg) { - if (narg != 4) error->all(FLERR,"Illegal pair_style command"); + + // narg = 4 for standard form and narg = 5 if angleoffset variant (from EXTRA-MOLECULE) + if (narg != 4 && narg != 5) error->all(FLERR,"Illegal pair_style command"); ap_global = utils::inumeric(FLERR,arg[0],false,lmp); cut_inner_global = utils::numeric(FLERR,arg[1],false,lmp); cut_outer_global = utils::numeric(FLERR,arg[2],false,lmp); cut_angle_global = utils::numeric(FLERR,arg[3],false,lmp) * MY_PI/180.0; + + // update when using angleoffset variant + if (angle_offset_flag) { + angle_offset_global = (180.0 - utils::numeric(FLERR, arg[4], false, lmp)) * MY_PI/180.0; + } } /* ---------------------------------------------------------------------- diff --git a/src/MOLECULE/pair_hbond_dreiding_lj.h b/src/MOLECULE/pair_hbond_dreiding_lj.h index e5cde8da69..131f3946b3 100644 --- a/src/MOLECULE/pair_hbond_dreiding_lj.h +++ b/src/MOLECULE/pair_hbond_dreiding_lj.h @@ -40,6 +40,7 @@ class PairHbondDreidingLJ : public Pair { double cut_inner_global, cut_outer_global, cut_angle_global; int ap_global; int angle_offset_flag; // 1 if angle offset variant used + double angle_offset_global; // updated if angle offset variant used struct Param { double epsilon, sigma; From fecf1c2f692d86b5b620bee9f23af32abee12411 Mon Sep 17 00:00:00 2001 From: megmcca Date: Fri, 17 Jan 2025 15:59:28 -0700 Subject: [PATCH 28/70] update morse coeff method, fix bug in flag --- src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp | 1 - src/MOLECULE/pair_hbond_dreiding_lj.cpp | 2 +- src/MOLECULE/pair_hbond_dreiding_morse.cpp | 4 +++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp index dedbbb8c9f..a687d4d7ea 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp @@ -44,7 +44,6 @@ PairHbondDreidingMorseAngleoffset::PairHbondDreidingMorseAngleoffset(LAMMPS *lmp PairHbondDreidingMorse(lmp) { angle_offset_flag = 1; - angle_offset_global = 0.0; } // /* ---------------------------------------------------------------------- diff --git a/src/MOLECULE/pair_hbond_dreiding_lj.cpp b/src/MOLECULE/pair_hbond_dreiding_lj.cpp index ebe7fdd123..0511ecb021 100644 --- a/src/MOLECULE/pair_hbond_dreiding_lj.cpp +++ b/src/MOLECULE/pair_hbond_dreiding_lj.cpp @@ -311,7 +311,7 @@ void PairHbondDreidingLJ::allocate() void PairHbondDreidingLJ::settings(int narg, char **arg) { - // narg = 4 for standard form and narg = 5 if angleoffset variant (from EXTRA-MOLECULE) + // narg = 4 for standard form, narg = 5 or 6 if angleoffset LJ or Morse variants respectively (from EXTRA-MOLECULE) if (narg != 4 && narg != 5) error->all(FLERR,"Illegal pair_style command"); ap_global = utils::inumeric(FLERR,arg[0],false,lmp); diff --git a/src/MOLECULE/pair_hbond_dreiding_morse.cpp b/src/MOLECULE/pair_hbond_dreiding_morse.cpp index 34fddc9f89..56f9c16442 100644 --- a/src/MOLECULE/pair_hbond_dreiding_morse.cpp +++ b/src/MOLECULE/pair_hbond_dreiding_morse.cpp @@ -246,7 +246,9 @@ void PairHbondDreidingMorse::compute(int eflag, int vflag) void PairHbondDreidingMorse::coeff(int narg, char **arg) { - if (narg < 7 || narg > 11) + int maxarg = 12; + if (angle_offset_flag == 1) maxarg = 12; + if (narg < 7 || narg > maxarg) error->all(FLERR,"Incorrect args for pair coefficients"); if (!allocated) allocate(); From 2c82ce8142cc3465dfeef70ac81d7571fbb02f24 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Sun, 19 Jan 2025 16:06:33 -0700 Subject: [PATCH 29/70] library: update new function signatures to use void* instead of bigint --- doc/src/Library_objects.rst | 12 ++++++------ python/lammps/core.py | 20 +++++++++++--------- src/library.cpp | 24 ++++++++++++------------ src/library.h | 11 +++-------- 4 files changed, 32 insertions(+), 35 deletions(-) diff --git a/doc/src/Library_objects.rst b/doc/src/Library_objects.rst index bea5dec167..86b6d253f0 100644 --- a/doc/src/Library_objects.rst +++ b/doc/src/Library_objects.rst @@ -13,9 +13,9 @@ fixes, or variables in LAMMPS using the following functions: - :cpp:func:`lammps_set_internal_variable` - :cpp:func:`lammps_variable_info` - :cpp:func:`lammps_eval` -- :cpp:func:`lammps_compute_clearstep` -- :cpp:func:`lammps_compute_addstep_all` -- :cpp:func:`lammps_compute_addstep` +- :cpp:func:`lammps_clearstep_compute` +- :cpp:func:`lammps_addstep_compute_all` +- :cpp:func:`lammps_addstep_compute` ----------------------- @@ -64,17 +64,17 @@ fixes, or variables in LAMMPS using the following functions: ----------------------- -.. doxygenfunction:: lammps_compute_clearstep +.. doxygenfunction:: lammps_clearstep_compute :project: progguide ----------------------- -.. doxygenfunction:: lammps_compute_addstep_all(void *handle, int nextstep) +.. doxygenfunction:: lammps_addstep_compute_all :project: progguide ----------------------- -.. doxygenfunction:: lammps_compute_addstep(void *handle, int nextstep) +.. doxygenfunction:: lammps_addstep_compute :project: progguide ----------------------- diff --git a/python/lammps/core.py b/python/lammps/core.py index 7e70b5392a..15968ee605 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -422,9 +422,9 @@ class lammps(object): self.lib.lammps_extract_variable_datatype.argtypes = [c_void_p, c_char_p] self.lib.lammps_extract_variable_datatype.restype = c_int - self.lib.lammps_compute_clearstep.argtype = [c_void_p] - self.lib.lammps_compute_addstep.argtype = [c_void_p, self.c_bigint] - self.lib.lammps_compute_addstep_all.argtype = [c_void_p, self.c_bigint] + self.lib.lammps_clearstep_compute.argtype = [c_void_p] + self.lib.lammps_addstep_compute.argtype = [c_void_p, c_void_p] + self.lib.lammps_addstep_compute_all.argtype = [c_void_p, c_void_p] self.lib.lammps_eval.argtypes = [c_void_p, c_char_p] self.lib.lammps_eval.restype = c_double @@ -1598,21 +1598,23 @@ class lammps(object): # ------------------------------------------------------------------------- - def compute_clearstep(self, nextstep): + def clearstep_compute(self, nextstep): with ExceptionCheck(self): - return self.lib.lammps_compute_clearstep(self.lmp) + return self.lib.lammps_clearstep_compute(self.lmp) # ------------------------------------------------------------------------- - def compute_addstep(self, nextstep): + def addstep_compute(self, nextstep): with ExceptionCheck(self): - return self.lib.lammps_compute_addstep(self.lmp, nextstep) + nextstep = self.c_bigint(nextstep) + return self.lib.lammps_addstep_compute(self.lmp, pointer(nextstep)) # ------------------------------------------------------------------------- - def compute_addstep_all(self, nextstep): + def addstep_compute_all(self, nextstep): with ExceptionCheck(self): - return self.lib.lammps_compute_addstep_all(self.lmp, nextstep) + nextstep = self.c_bigint(nextstep) + return self.lib.lammps_addstep_compute_all(self.lmp, pointer(nextstep)) # ------------------------------------------------------------------------- diff --git a/src/library.cpp b/src/library.cpp index 1bb589c2b2..4902236e98 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -2974,14 +2974,14 @@ double lammps_eval(void *handle, const char *expr) and to flag computes that store invocation times as having been invoked *See also* - :cpp:func:`lammps_compute_addstep_all` - :cpp:func:`lammps_compute_addstep` + :cpp:func:`lammps_addstep_compute_all` + :cpp:func:`lammps_addstep_compute` \endverbatim * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. */ -void lammps_compute_clearstep(void * handle) { +void lammps_clearstep_compute(void * handle) { auto lmp = (LAMMPS *) handle; lmp->modify->clearstep_compute(); } @@ -3000,17 +3000,17 @@ void lammps_compute_clearstep(void * handle) { do not loop only over n_timeflag, since may not be set yet *See also* - :cpp:func:`lammps_compute_clearstep` - :cpp:func:`lammps_compute_addstep` + :cpp:func:`lammps_clearstep_compute` + :cpp:func:`lammps_addstep_compute` \endverbatim * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. - * \param newstep next timestep the compute will be invoked + * \param newstep pointer to bigint of next timestep the compute will be invoked */ -void lammps_compute_addstep_all(void * handle, bigint newstep) { +void lammps_addstep_compute_all(void * handle, void * newstep) { auto lmp = (LAMMPS *) handle; - lmp->modify->addstep_compute_all(newstep); + lmp->modify->addstep_compute_all(*static_cast(newstep)); } /* ---------------------------------------------------------------------- */ @@ -3025,17 +3025,17 @@ void lammps_compute_addstep_all(void * handle, bigint newstep) { called everywhere that computes are used, after computes are invoked *See also* - :cpp:func:`lammps_compute_addstep_all` - :cpp:func:`lammps_compute_clearstep` + :cpp:func:`lammps_addstep_compute_all` + :cpp:func:`lammps_clearstep_compute` \endverbatim * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. * \param newstep next timestep the compute will be invoked */ -void lammps_compute_addstep(void * handle, bigint newstep) { +void lammps_addstep_compute(void * handle, void * newstep) { auto lmp = (LAMMPS *) handle; - lmp->modify->addstep_compute(newstep); + lmp->modify->addstep_compute(*static_cast(newstep)); } // ---------------------------------------------------------------------- diff --git a/src/library.h b/src/library.h index a2575db20a..99b251ee85 100644 --- a/src/library.h +++ b/src/library.h @@ -191,14 +191,9 @@ int lammps_set_internal_variable(void *handle, const char *name, double value); int lammps_variable_info(void *handle, int idx, char *buf, int bufsize); double lammps_eval(void *handle, const char *expr); -void lammps_compute_clearstep(void *handle); -#if defined(LAMMPS_SMALLSMALL) -void lammps_compute_addstep_all(void *handle, int nextstep); -void lammps_compute_addstep(void *handle, int nextstep); -#else -void lammps_compute_addstep_all(void *handle, int64_t nextstep); -void lammps_compute_addstep(void *handle, int64_t nextstep); -#endif +void lammps_clearstep_compute(void *handle); +void lammps_addstep_compute_all(void *handle, void * nextstep); +void lammps_addstep_compute(void *handle, void * nextstep); /* ---------------------------------------------------------------------- * Library functions for scatter/gather operations of data From c6adf793abe1e62134b4bfe6002999dedbb7d295 Mon Sep 17 00:00:00 2001 From: jtclemm Date: Tue, 21 Jan 2025 13:05:02 -0700 Subject: [PATCH 30/70] Fixing comment in example script --- examples/multi/in.granular | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/multi/in.granular b/examples/multi/in.granular index 468d0dcbf1..6abbd8da3b 100644 --- a/examples/multi/in.granular +++ b/examples/multi/in.granular @@ -1,4 +1,4 @@ -# Big colloid particles and small LJ particles +# Binary granular system units lj atom_style sphere From 7c0254caeea5ff629a2d1c6f111dd8ed7d25fe5a Mon Sep 17 00:00:00 2001 From: jtclemm Date: Tue, 21 Jan 2025 13:47:22 -0700 Subject: [PATCH 31/70] Limiting rho calculation for tait equation --- src/RHEO/fix_rheo_pressure.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/RHEO/fix_rheo_pressure.cpp b/src/RHEO/fix_rheo_pressure.cpp index d972f19ffa..121473f7e3 100644 --- a/src/RHEO/fix_rheo_pressure.cpp +++ b/src/RHEO/fix_rheo_pressure.cpp @@ -273,11 +273,13 @@ double FixRHEOPressure::calc_rho(double p, int i) error->one(FLERR, "Rho calculation from pressure not yet supported for cubic pressure equation"); } else if (pressure_style[type] == TAITWATER) { - rho = pow(7.0 * p + csq[type] * rho0[type], SEVENTH); + double tmp = 7.0 * p + csq[type] * rho0[type]; + rho = pow(MAX(0.0, tmp), SEVENTH); rho *= pow(rho0[type], 6.0 * SEVENTH); rho *= pow(csq[type], -SEVENTH); } else if (pressure_style[type] == TAITGENERAL) { - rho = pow(tpower[type] * p + csq[type] * rho0[type], 1.0 / tpower[type]); + double tmp = tpower[type] * p + csq[type] * rho0[type]; + rho = pow(MAX(0.0, tmp), 1.0 / tpower[type]); rho *= pow(rho0[type], 1.0 - 1.0 / tpower[type]); rho *= pow(csq[type], -1.0 / tpower[type]); } else if (pressure_style[type] == IDEAL) { From c1662f64cafb2d548b8c73b495d24750262b3f3e Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Wed, 22 Jan 2025 23:52:52 -0500 Subject: [PATCH 32/70] reaxff/species: post_integrate->end_of_step fix for incorrect molecule IDs (variable: clusterID) output by reaxff/species vector Co-Authored-By: mkanski <20713012+mkanski@users.noreply.github.com> Co-Authored-By: Navraj <88741755+navlalli@users.noreply.github.com> --- src/REAXFF/fix_reaxff_species.cpp | 6 +++--- src/REAXFF/fix_reaxff_species.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/REAXFF/fix_reaxff_species.cpp b/src/REAXFF/fix_reaxff_species.cpp index 4ef7799c24..834e830808 100644 --- a/src/REAXFF/fix_reaxff_species.cpp +++ b/src/REAXFF/fix_reaxff_species.cpp @@ -339,7 +339,7 @@ FixReaxFFSpecies::~FixReaxFFSpecies() int FixReaxFFSpecies::setmask() { int mask = 0; - mask |= POST_INTEGRATE; + mask |= END_OF_STEP; return mask; } @@ -356,7 +356,7 @@ void FixReaxFFSpecies::setup(int /*vflag*/) memory->destroy(Name); memory->create(Name, nutypes, "reaxff/species:Name"); - post_integrate(); + end_of_step(); } /* ---------------------------------------------------------------------- */ @@ -411,7 +411,7 @@ void FixReaxFFSpecies::init_list(int /*id*/, NeighList *ptr) /* ---------------------------------------------------------------------- */ -void FixReaxFFSpecies::post_integrate() +void FixReaxFFSpecies::end_of_step() { Output_ReaxFF_Bonds(update->ntimestep, fp); if (comm->me == 0) fflush(fp); diff --git a/src/REAXFF/fix_reaxff_species.h b/src/REAXFF/fix_reaxff_species.h index b9afc5466a..d283c1fff6 100644 --- a/src/REAXFF/fix_reaxff_species.h +++ b/src/REAXFF/fix_reaxff_species.h @@ -39,7 +39,7 @@ class FixReaxFFSpecies : public Fix { void init() override; void init_list(int, class NeighList *) override; void setup(int) override; - void post_integrate() override; + void end_of_step() override; double compute_vector(int) override; protected: From 3a44a03f046caa4ced448503d5472dc3d25d51d2 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Fri, 24 Jan 2025 23:29:10 -0500 Subject: [PATCH 33/70] migrate clusterID to fix property/atom --- src/REAXFF/fix_reaxff_species.cpp | 36 +++++++++++++++++-------------- src/REAXFF/fix_reaxff_species.h | 3 ++- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/REAXFF/fix_reaxff_species.cpp b/src/REAXFF/fix_reaxff_species.cpp index 834e830808..1ba3ae08e7 100644 --- a/src/REAXFF/fix_reaxff_species.cpp +++ b/src/REAXFF/fix_reaxff_species.cpp @@ -26,6 +26,7 @@ #include "domain.h" #include "error.h" #include "fix_ave_atom.h" +#include "fix_property_atom.h" #include "force.h" #include "group.h" #include "input.h" @@ -141,13 +142,6 @@ FixReaxFFSpecies::FixReaxFFSpecies(LAMMPS *lmp, int narg, char **arg) : } x0 = nullptr; - clusterID = nullptr; - - int ntmp = atom->nmax; - memory->create(x0, ntmp, "reaxff/species:x0"); - memory->create(clusterID, ntmp, "reaxff/species:clusterID"); - memset(clusterID, 0, sizeof(double) * ntmp); - vector_atom = clusterID; nmax = 0; setupflag = 0; @@ -304,7 +298,6 @@ FixReaxFFSpecies::FixReaxFFSpecies(LAMMPS *lmp, int narg, char **arg) : FixReaxFFSpecies::~FixReaxFFSpecies() { memory->destroy(BOCut); - memory->destroy(clusterID); memory->destroy(x0); memory->destroy(nd); @@ -330,6 +323,7 @@ FixReaxFFSpecies::~FixReaxFFSpecies() try { modify->delete_compute(fmt::format("SPECATOM_{}", id)); modify->delete_fix(fmt::format("SPECBOND_{}", id)); + modify->delete_fix(fmt::format("clusterID_{}", id)); } catch (std::exception &) { } } @@ -339,7 +333,7 @@ FixReaxFFSpecies::~FixReaxFFSpecies() int FixReaxFFSpecies::setmask() { int mask = 0; - mask |= END_OF_STEP; + mask |= POST_INTEGRATE; return mask; } @@ -356,7 +350,7 @@ void FixReaxFFSpecies::setup(int /*vflag*/) memory->destroy(Name); memory->create(Name, nutypes, "reaxff/species:Name"); - end_of_step(); + post_integrate(); } /* ---------------------------------------------------------------------- */ @@ -387,6 +381,20 @@ void FixReaxFFSpecies::init() auto fixcmd = fmt::format("SPECBOND_{} all ave/atom {} {} {}", id, nevery, nrepeat, nfreq); for (int i = 1; i < 32; ++i) fixcmd += fmt::format(" c_SPECATOM_{}[{}]", id, i); f_SPECBOND = dynamic_cast(modify->add_fix(fixcmd)); + + // create a fix to point to fix_property_atom for storing clusterID + fixcmd = fmt::format("clusterID_{} all property/atom d_clusterID ghost yes", id); + f_clusterID = dynamic_cast(modify->add_fix(fixcmd)); + + // per-atom property for clusterID + int flag,cols; + int index1 = atom->find_custom("clusterID",flag,cols); + clusterID = atom->dvector[index1]; + vector_atom = clusterID; + + int ntmp = atom->nmax; + memory->create(x0, ntmp, "reaxff/species:x0"); + setupflag = 1; } @@ -411,7 +419,7 @@ void FixReaxFFSpecies::init_list(int /*id*/, NeighList *ptr) /* ---------------------------------------------------------------------- */ -void FixReaxFFSpecies::end_of_step() +void FixReaxFFSpecies::post_integrate() { Output_ReaxFF_Bonds(update->ntimestep, fp); if (comm->me == 0) fflush(fp); @@ -439,11 +447,7 @@ void FixReaxFFSpecies::Output_ReaxFF_Bonds(bigint ntimestep, FILE * /*fp*/) if (atom->nmax > nmax) { nmax = atom->nmax; memory->destroy(x0); - memory->destroy(clusterID); memory->create(x0, nmax, "reaxff/species:x0"); - memory->create(clusterID, nmax, "reaxff/species:clusterID"); - memset(clusterID, 0, sizeof(double) * nmax); - vector_atom = clusterID; } for (int i = 0; i < nmax; i++) { x0[i].x = x0[i].y = x0[i].z = 0.0; } @@ -1177,7 +1181,7 @@ double FixReaxFFSpecies::memory_usage() { double bytes; - bytes = 4 * nmax * sizeof(double); // clusterID + x0 + bytes = 3 * nmax * sizeof(double); // x0 return bytes; } diff --git a/src/REAXFF/fix_reaxff_species.h b/src/REAXFF/fix_reaxff_species.h index d283c1fff6..d378065a82 100644 --- a/src/REAXFF/fix_reaxff_species.h +++ b/src/REAXFF/fix_reaxff_species.h @@ -39,7 +39,7 @@ class FixReaxFFSpecies : public Fix { void init() override; void init_list(int, class NeighList *) override; void setup(int) override; - void end_of_step() override; + void post_integrate() override; double compute_vector(int) override; protected: @@ -88,6 +88,7 @@ class FixReaxFFSpecies : public Fix { class NeighList *list; class FixAveAtom *f_SPECBOND; + class FixPropertyAtom *f_clusterID; class PairReaxFF *reaxff; }; } // namespace LAMMPS_NS From 4bdc02ef3a627c94c37b8db55d442bd8c740eb50 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Fri, 24 Jan 2025 23:41:00 -0500 Subject: [PATCH 34/70] bugfix for when not using variable Nlimit for delete option --- src/REAXFF/fix_reaxff_species.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/REAXFF/fix_reaxff_species.cpp b/src/REAXFF/fix_reaxff_species.cpp index 1ba3ae08e7..138ce1dc19 100644 --- a/src/REAXFF/fix_reaxff_species.cpp +++ b/src/REAXFF/fix_reaxff_species.cpp @@ -399,7 +399,7 @@ void FixReaxFFSpecies::init() } // check for valid variable name for delete Nlimit keyword - if (delete_Nsteps > 0) { + if (delete_Nsteps > 0 && delete_Nlimit_varid > -1) { delete_Nlimit_varid = input->variable->find(delete_Nlimit_varname.c_str()); if (delete_Nlimit_varid < 0) error->all(FLERR, "Fix reaxff/species: Variable name {} does not exist", From cbd99d29cf1cd9776f15dcc5c5ec15965f4c5a7d Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Sat, 25 Jan 2025 14:17:20 -0500 Subject: [PATCH 35/70] update pointers in case changed at some point is 'clusterID' name for per-atom property too general? --- src/REAXFF/fix_reaxff_species.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/REAXFF/fix_reaxff_species.cpp b/src/REAXFF/fix_reaxff_species.cpp index 138ce1dc19..2e605339cb 100644 --- a/src/REAXFF/fix_reaxff_species.cpp +++ b/src/REAXFF/fix_reaxff_species.cpp @@ -432,6 +432,12 @@ void FixReaxFFSpecies::Output_ReaxFF_Bonds(bigint ntimestep, FILE * /*fp*/) { int Nmole, Nspec; + // per-atom property for clusterID + int flag,cols; + int index1 = atom->find_custom("clusterID",flag,cols); + clusterID = atom->dvector[index1]; + vector_atom = clusterID; + // point to fix_ave_atom f_SPECBOND->end_of_step(); From 0a954b0129bf8eda52de769a015ab6d2850c39a4 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Sat, 25 Jan 2025 14:44:18 -0500 Subject: [PATCH 36/70] per-atom mass bugfix for delete keyword --- src/REAXFF/fix_reaxff_species.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/REAXFF/fix_reaxff_species.cpp b/src/REAXFF/fix_reaxff_species.cpp index 2e605339cb..05ce474b73 100644 --- a/src/REAXFF/fix_reaxff_species.cpp +++ b/src/REAXFF/fix_reaxff_species.cpp @@ -947,6 +947,8 @@ void FixReaxFFSpecies::DeleteSpecies(int Nmole, int Nspec) int ndel, ndelone, count, count_tmp; int *Nameall; int *mask = atom->mask; + double *mass = atom->mass; + double *rmass = atom->rmass; double localmass, totalmass; std::string species_str; @@ -999,7 +1001,8 @@ void FixReaxFFSpecies::DeleteSpecies(int Nmole, int Nspec) Name[itype]++; count++; marklist[nmarklist++] = i; - localmass += atom->mass[atom->type[i]]; + if (rmass) localmass += rmass[i]; + else localmass += atom->mass[atom->type[i]]; } } From ceac416f9a8b59e1f81098dc883252a3c97422bb Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Sat, 25 Jan 2025 15:16:26 -0500 Subject: [PATCH 37/70] average charge -> total charge in pos file --- src/REAXFF/fix_reaxff_species.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/REAXFF/fix_reaxff_species.cpp b/src/REAXFF/fix_reaxff_species.cpp index 05ce474b73..b81feab771 100644 --- a/src/REAXFF/fix_reaxff_species.cpp +++ b/src/REAXFF/fix_reaxff_species.cpp @@ -836,7 +836,7 @@ void FixReaxFFSpecies::WritePos(int Nmole, int Nspec) int count, count_tmp, m, n, k; int *Nameall; int *mask = atom->mask; - double avq, avq_tmp, avx[3], avx_tmp, box[3], halfbox[3]; + double totq, totq_tmp, avx[3], avx_tmp, box[3], halfbox[3]; double **spec_atom = f_SPECBOND->array_atom; if (multipos) OpenPos(); @@ -863,7 +863,7 @@ void FixReaxFFSpecies::WritePos(int Nmole, int Nspec) for (m = 1; m <= Nmole; m++) { count = 0; - avq = 0.0; + totq = 0.0; for (n = 0; n < 3; n++) avx[n] = 0.0; for (n = 0; n < nutypes; n++) Name[n] = 0; @@ -874,7 +874,7 @@ void FixReaxFFSpecies::WritePos(int Nmole, int Nspec) itype = ele2uele[atom->type[i] - 1]; Name[itype]++; count++; - avq += spec_atom[i][0]; + totq += spec_atom[i][0]; if ((x0[i].x - spec_atom[i][1]) > halfbox[0]) spec_atom[i][1] += box[0]; if ((spec_atom[i][1] - x0[i].x) > halfbox[0]) spec_atom[i][1] -= box[0]; if ((x0[i].y - spec_atom[i][2]) > halfbox[1]) spec_atom[i][2] += box[1]; @@ -885,9 +885,9 @@ void FixReaxFFSpecies::WritePos(int Nmole, int Nspec) } } - avq_tmp = 0.0; - MPI_Allreduce(&avq, &avq_tmp, 1, MPI_DOUBLE, MPI_SUM, world); - avq = avq_tmp; + totq_tmp = 0.0; + MPI_Allreduce(&totq, &totq_tmp, 1, MPI_DOUBLE, MPI_SUM, world); + totq = totq_tmp; for (n = 0; n < 3; n++) { avx_tmp = 0.0; @@ -910,7 +910,6 @@ void FixReaxFFSpecies::WritePos(int Nmole, int Nspec) } } if (count > 0) { - avq /= count; for (k = 0; k < 3; k++) { avx[k] /= count; if (avx[k] >= domain->boxhi[k]) avx[k] -= box[k]; @@ -919,7 +918,7 @@ void FixReaxFFSpecies::WritePos(int Nmole, int Nspec) avx[k] -= domain->boxlo[k]; avx[k] /= box[k]; } - fprintf(pos, "\t%.8f \t%.8f \t%.8f \t%.8f", avq, avx[0], avx[1], avx[2]); + fprintf(pos, "\t%.8f \t%.8f \t%.8f \t%.8f", totq, avx[0], avx[1], avx[2]); } fprintf(pos, "\n"); } From ccc790265d5b6d538e2680e1c60c9f9cee45c0e8 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Sat, 25 Jan 2025 16:21:21 -0500 Subject: [PATCH 38/70] geometric center -> com --- src/REAXFF/fix_reaxff_species.cpp | 33 ++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/REAXFF/fix_reaxff_species.cpp b/src/REAXFF/fix_reaxff_species.cpp index b81feab771..4d635cccf5 100644 --- a/src/REAXFF/fix_reaxff_species.cpp +++ b/src/REAXFF/fix_reaxff_species.cpp @@ -836,7 +836,8 @@ void FixReaxFFSpecies::WritePos(int Nmole, int Nspec) int count, count_tmp, m, n, k; int *Nameall; int *mask = atom->mask; - double totq, totq_tmp, avx[3], avx_tmp, box[3], halfbox[3]; + double *rmass = atom->rmass; + double totq, totq_tmp, com[3], com_tmp, thism, totm, box[3], halfbox[3]; double **spec_atom = f_SPECBOND->array_atom; if (multipos) OpenPos(); @@ -864,7 +865,8 @@ void FixReaxFFSpecies::WritePos(int Nmole, int Nspec) count = 0; totq = 0.0; - for (n = 0; n < 3; n++) avx[n] = 0.0; + totm = 0.0; + for (n = 0; n < 3; n++) com[n] = 0.0; for (n = 0; n < nutypes; n++) Name[n] = 0; for (i = 0; i < nlocal; i++) { @@ -881,7 +883,10 @@ void FixReaxFFSpecies::WritePos(int Nmole, int Nspec) if ((spec_atom[i][2] - x0[i].y) > halfbox[1]) spec_atom[i][2] -= box[1]; if ((x0[i].z - spec_atom[i][3]) > halfbox[2]) spec_atom[i][3] += box[2]; if ((spec_atom[i][3] - x0[i].z) > halfbox[2]) spec_atom[i][3] -= box[2]; - for (n = 0; n < 3; n++) avx[n] += spec_atom[i][n + 1]; + if (rmass) thism = rmass[i]; + else thism = atom->mass[atom->type[i]]; + for (n = 0; n < 3; n++) com[n] += spec_atom[i][n+1]*thism; + totm += thism; } } @@ -890,14 +895,18 @@ void FixReaxFFSpecies::WritePos(int Nmole, int Nspec) totq = totq_tmp; for (n = 0; n < 3; n++) { - avx_tmp = 0.0; - MPI_Reduce(&avx[n], &avx_tmp, 1, MPI_DOUBLE, MPI_SUM, 0, world); - avx[n] = avx_tmp; + com_tmp = 0.0; + MPI_Reduce(&com[n], &com_tmp, 1, MPI_DOUBLE, MPI_SUM, 0, world); + com[n] = com_tmp; } MPI_Reduce(&count, &count_tmp, 1, MPI_INT, MPI_SUM, 0, world); count = count_tmp; + com_tmp = 0.0; + MPI_Reduce(&totm, &com_tmp, 1, MPI_DOUBLE, MPI_SUM, 0, world); + totm = com_tmp; + MPI_Reduce(Name, Nameall, nutypes, MPI_INT, MPI_SUM, 0, world); for (n = 0; n < nutypes; n++) Name[n] = Nameall[n]; @@ -911,14 +920,14 @@ void FixReaxFFSpecies::WritePos(int Nmole, int Nspec) } if (count > 0) { for (k = 0; k < 3; k++) { - avx[k] /= count; - if (avx[k] >= domain->boxhi[k]) avx[k] -= box[k]; - if (avx[k] < domain->boxlo[k]) avx[k] += box[k]; + com[k] /= totm; + if (com[k] >= domain->boxhi[k]) com[k] -= box[k]; + if (com[k] < domain->boxlo[k]) com[k] += box[k]; - avx[k] -= domain->boxlo[k]; - avx[k] /= box[k]; + com[k] -= domain->boxlo[k]; + com[k] /= box[k]; } - fprintf(pos, "\t%.8f \t%.8f \t%.8f \t%.8f", totq, avx[0], avx[1], avx[2]); + fprintf(pos, "\t%.8f \t%.8f \t%.8f \t%.8f", totq, com[0], com[1], com[2]); } fprintf(pos, "\n"); } From 8482d150e1073172ea46c9f0a2f4f6c1ae8710a6 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Sat, 25 Jan 2025 16:22:12 -0500 Subject: [PATCH 39/70] update label --- src/REAXFF/fix_reaxff_species.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/REAXFF/fix_reaxff_species.cpp b/src/REAXFF/fix_reaxff_species.cpp index 4d635cccf5..adaa2c8c65 100644 --- a/src/REAXFF/fix_reaxff_species.cpp +++ b/src/REAXFF/fix_reaxff_species.cpp @@ -855,7 +855,7 @@ void FixReaxFFSpecies::WritePos(int Nmole, int Nspec) update->ntimestep, Nmole, Nspec, domain->boxlo[0], domain->boxhi[0], domain->boxlo[1], domain->boxhi[1], domain->boxlo[2], domain->boxhi[2]); - fprintf(pos, "ID\tAtom_Count\tType\tAve_q\t\tCoM_x\t\tCoM_y\t\tCoM_z\n"); + fprintf(pos, "ID\tAtom_Count\tType\tTot_q\t\tCoM_x\t\tCoM_y\t\tCoM_z\n"); } Nameall = nullptr; From baf9a9b2d230a36888f486253a04ffa9e1fb69ed Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Sat, 25 Jan 2025 23:14:09 -0500 Subject: [PATCH 40/70] need to update delete_Tcount before returning needs to be every timestep, regarding of Nfreq, etc. settings --- src/REAXFF/fix_reaxff_species.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/REAXFF/fix_reaxff_species.cpp b/src/REAXFF/fix_reaxff_species.cpp index adaa2c8c65..f832b52c52 100644 --- a/src/REAXFF/fix_reaxff_species.cpp +++ b/src/REAXFF/fix_reaxff_species.cpp @@ -940,18 +940,24 @@ void FixReaxFFSpecies::WritePos(int Nmole, int Nspec) void FixReaxFFSpecies::DeleteSpecies(int Nmole, int Nspec) { - int ndeletions; + int i, ndeletions; int headroom = -1; if (delete_Nsteps > 0) { - if (delete_Tcount[delete_Nsteps - 1] == -1) return; + if (delete_Tcount[delete_Nsteps - 1] == -1) { + for (i = delete_Nsteps - 1; i > 0; i--) delete_Tcount[i] = delete_Tcount[i - 1]; + return; + } ndeletions = delete_Tcount[0] - delete_Tcount[delete_Nsteps - 1]; if (delete_Nlimit_varid > -1) delete_Nlimit = input->variable->compute_equal(delete_Nlimit_varid); headroom = MAX(0, delete_Nlimit - ndeletions); - if (headroom == 0) return; + if (headroom == 0) { + for (i = delete_Nsteps - 1; i > 0; i--) delete_Tcount[i] = delete_Tcount[i - 1]; + return; + } } - int i, j, m, n, itype, cid; + int j, m, n, itype, cid; int ndel, ndelone, count, count_tmp; int *Nameall; int *mask = atom->mask; From 464d9d82d65d0bbfc4b9fe3e575fbbd707d9f3d3 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Sat, 25 Jan 2025 23:33:04 -0500 Subject: [PATCH 41/70] return correct clusterIDs even on first timestep --- src/REAXFF/fix_reaxff_species.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/REAXFF/fix_reaxff_species.cpp b/src/REAXFF/fix_reaxff_species.cpp index f832b52c52..67beb32740 100644 --- a/src/REAXFF/fix_reaxff_species.cpp +++ b/src/REAXFF/fix_reaxff_species.cpp @@ -82,7 +82,7 @@ FixReaxFFSpecies::FixReaxFFSpecies(LAMMPS *lmp, int narg, char **arg) : peratom_freq = 1; compressed = 0; - nvalid = -1; + nvalid = update->ntimestep; ntypes = atom->ntypes; eletype.resize(ntypes); From 991b8c11fffac8e38adce39d052850f7277d8443 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Sat, 25 Jan 2025 23:38:15 -0500 Subject: [PATCH 42/70] delete option: reset molecule ID to index from 1 --- src/REAXFF/fix_reaxff_species.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/REAXFF/fix_reaxff_species.cpp b/src/REAXFF/fix_reaxff_species.cpp index 67beb32740..51c2545409 100644 --- a/src/REAXFF/fix_reaxff_species.cpp +++ b/src/REAXFF/fix_reaxff_species.cpp @@ -474,7 +474,12 @@ void FixReaxFFSpecies::Output_ReaxFF_Bonds(bigint ntimestep, FILE * /*fp*/) if (comm->me == 0) fflush(pos); } - if (delflag) DeleteSpecies(Nmole, Nspec); + if (delflag) { + DeleteSpecies(Nmole, Nspec); + + // reset molecule ID to index from 1 + SortMolecule(Nmole); + } nvalid += nfreq; } From 4c2241054852f1301c32bbd8152ed91d6262fdd1 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Sat, 25 Jan 2025 23:41:35 -0500 Subject: [PATCH 43/70] docs: molIDs range from 1 to # molecules --- doc/src/fix_reaxff_species.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/src/fix_reaxff_species.rst b/doc/src/fix_reaxff_species.rst index 107695f0f6..068d1de995 100644 --- a/doc/src/fix_reaxff_species.rst +++ b/doc/src/fix_reaxff_species.rst @@ -200,8 +200,8 @@ The 2 values in the global vector are as follows: The per-atom vector stores the molecule ID for each atom as identified by the fix. If an atom is not in a molecule, its ID will be 0. For atoms in the same molecule, the molecule ID for all of them -will be the same and will be equal to the smallest atom ID of -any atom in the molecule. +will be the same, and molecule IDs will range from 1 to the number +of molecules. No parameter of this fix can be used with the *start/stop* keywords of the :doc:`run ` command. From 8e2cb0f4c8bcf6f9489674411034ab26c9a7365c Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Sun, 26 Jan 2025 15:22:00 -0500 Subject: [PATCH 44/70] calculate molids on first timetstep of run but do not delete molecules --- src/REAXFF/fix_reaxff_species.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/REAXFF/fix_reaxff_species.cpp b/src/REAXFF/fix_reaxff_species.cpp index 51c2545409..d96f8214ec 100644 --- a/src/REAXFF/fix_reaxff_species.cpp +++ b/src/REAXFF/fix_reaxff_species.cpp @@ -82,7 +82,7 @@ FixReaxFFSpecies::FixReaxFFSpecies(LAMMPS *lmp, int narg, char **arg) : peratom_freq = 1; compressed = 0; - nvalid = update->ntimestep; + nvalid = -1; ntypes = atom->ntypes; eletype.resize(ntypes); @@ -366,9 +366,6 @@ void FixReaxFFSpecies::init() reaxff->fixspecies_flag = 1; - // reset next output timestep if not yet set or timestep has been reset - if (nvalid != update->ntimestep) nvalid = update->ntimestep + nfreq; - if (!setupflag) { // create a compute to store properties modify->add_compute(fmt::format("SPECATOM_{} all SPEC/ATOM q x y z vx vy vz abo01 abo02 " @@ -441,7 +438,7 @@ void FixReaxFFSpecies::Output_ReaxFF_Bonds(bigint ntimestep, FILE * /*fp*/) // point to fix_ave_atom f_SPECBOND->end_of_step(); - if (ntimestep != nvalid) { + if (ntimestep != nvalid && nvalid != -1) { // push back delete_Tcount on every step if (delete_Nsteps > 0) for (int i = delete_Nsteps - 1; i > 0; i--) delete_Tcount[i] = delete_Tcount[i - 1]; @@ -474,14 +471,14 @@ void FixReaxFFSpecies::Output_ReaxFF_Bonds(bigint ntimestep, FILE * /*fp*/) if (comm->me == 0) fflush(pos); } - if (delflag) { + if (delflag && nvalid != -1) { DeleteSpecies(Nmole, Nspec); // reset molecule ID to index from 1 SortMolecule(Nmole); } - nvalid += nfreq; + nvalid = ntimestep + nfreq; } /* ---------------------------------------------------------------------- */ From a242511ce77712a8933314d46b7e153ea457ddc9 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 27 Jan 2025 11:16:27 -0500 Subject: [PATCH 45/70] avoid segfaults --- src/library.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/library.cpp b/src/library.cpp index dd7fec1ed0..07ed9184bc 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -2981,7 +2981,7 @@ double lammps_eval(void *handle, const char *expr) * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. */ -void lammps_clearstep_compute(void * handle) { +void lammps_clearstep_compute(void *handle) { auto lmp = (LAMMPS *) handle; lmp->modify->clearstep_compute(); } @@ -3008,9 +3008,10 @@ void lammps_clearstep_compute(void * handle) { * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. * \param newstep pointer to bigint of next timestep the compute will be invoked */ -void lammps_addstep_compute_all(void * handle, void * newstep) { +void lammps_addstep_compute_all(void *handle, void *newstep) { auto lmp = (LAMMPS *) handle; - lmp->modify->addstep_compute_all(*static_cast(newstep)); + auto ns = (bigint *) newstep; + if (lmp && lmp->modify && ns) lmp->modify->addstep_compute_all(*ns); } /* ---------------------------------------------------------------------- */ @@ -3033,9 +3034,10 @@ void lammps_addstep_compute_all(void * handle, void * newstep) { * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. * \param newstep next timestep the compute will be invoked */ -void lammps_addstep_compute(void * handle, void * newstep) { +void lammps_addstep_compute(void *handle, void *newstep) { auto lmp = (LAMMPS *) handle; - lmp->modify->addstep_compute(*static_cast(newstep)); + auto ns = (bigint *) newstep; + if (lmp && lmp->modify && ns) lmp->modify->addstep_compute(*ns); } // ---------------------------------------------------------------------- From 0fde98cfbc873ba154248463b8b33f1832db3fe3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 27 Jan 2025 11:17:04 -0500 Subject: [PATCH 46/70] use POINTER() captitalization consistently --- python/lammps/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/lammps/core.py b/python/lammps/core.py index 15968ee605..bbfd5ba6f4 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -1607,14 +1607,14 @@ class lammps(object): def addstep_compute(self, nextstep): with ExceptionCheck(self): nextstep = self.c_bigint(nextstep) - return self.lib.lammps_addstep_compute(self.lmp, pointer(nextstep)) + return self.lib.lammps_addstep_compute(self.lmp, POINTER(nextstep)) # ------------------------------------------------------------------------- def addstep_compute_all(self, nextstep): with ExceptionCheck(self): nextstep = self.c_bigint(nextstep) - return self.lib.lammps_addstep_compute_all(self.lmp, pointer(nextstep)) + return self.lib.lammps_addstep_compute_all(self.lmp, POINTER(nextstep)) # ------------------------------------------------------------------------- From 6398a7c7aac2b1f02d962f3c1a226f2e8f37777a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 27 Jan 2025 12:25:46 -0500 Subject: [PATCH 47/70] add test for the library interface to clearstep_compute and addstep_compute --- .../c-library/test_library_properties.cpp | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/unittest/c-library/test_library_properties.cpp b/unittest/c-library/test_library_properties.cpp index 737015ccdc..1feccf5cb0 100644 --- a/unittest/c-library/test_library_properties.cpp +++ b/unittest/c-library/test_library_properties.cpp @@ -3,9 +3,12 @@ #include "library.h" #include "atom.h" +#include "compute.h" #include "lammps.h" #include "lmptype.h" +#include "modify.h" #include "platform.h" + #include #include @@ -668,6 +671,77 @@ TEST_F(LibraryProperties, neighlist) } }; +static constexpr char lj_setup[] = "lattice fcc 0.8442\n" + "region box block 0 10 0 10 0 10\n" + "create_box 1 box\n" + "create_atoms 1 box\n" + "mass 1 1.0\n" + "pair_style lj/cut 2.5\n" + "pair_coeff 1 1 1.0 1.0\n" + "fix 1 all nve\n"; + +TEST_F(LibraryProperties, step_compute) +{ + ::testing::internal::CaptureStdout(); + lammps_commands_string(lmp, lj_setup); + lammps_command(lmp, "compute pr all pressure thermo_temp"); + lammps_command(lmp, "fix av all ave/time 2 1 2 c_pr mode scalar"); + lammps_command(lmp, "run 2 post no"); + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + if (lammps_has_error(lmp)) { + char buf[2048]; + lammps_get_last_error_message(lmp, buf, 2048); + FAIL() << buf << "\n"; + } + auto lammps = (LAMMPS_NS::LAMMPS *)lmp; + auto icomp = lammps->modify->get_compute_by_id("pr"); + EXPECT_EQ(icomp->ntime, 2); + EXPECT_EQ(icomp->tlist[0], 4); + EXPECT_EQ(icomp->tlist[1], 2); + EXPECT_EQ(icomp->invoked_flag, 0); + EXPECT_EQ(icomp->invoked_scalar, 2); + EXPECT_EQ(icomp->invoked_vector, -1); + lammps_clearstep_compute(lmp); + EXPECT_EQ(icomp->invoked_flag, 0); + EXPECT_EQ(icomp->invoked_scalar, 2); + EXPECT_EQ(icomp->invoked_vector, -1); + bigint nextstep = 6; + lammps_addstep_compute(lmp, (void *)&nextstep); + EXPECT_EQ(icomp->ntime, 3); + EXPECT_EQ(icomp->tlist[0], 6); + EXPECT_EQ(icomp->tlist[1], 4); + EXPECT_EQ(icomp->tlist[2], 2); + EXPECT_EQ(icomp->invoked_flag, 0); + EXPECT_EQ(icomp->invoked_scalar, 2); + EXPECT_EQ(icomp->invoked_vector, -1); + lammps_command(lmp, "run 4 post no"); + EXPECT_EQ(icomp->ntime, 2); + EXPECT_EQ(icomp->tlist[0], 8); + EXPECT_EQ(icomp->tlist[1], 6); + EXPECT_EQ(icomp->invoked_flag, 0); + EXPECT_EQ(icomp->invoked_scalar, 6); + EXPECT_EQ(icomp->invoked_vector, -1); + lammps_command(lmp, "run 2 post no"); + EXPECT_EQ(icomp->ntime, 2); + EXPECT_EQ(icomp->tlist[0], 10); + EXPECT_EQ(icomp->tlist[1], 8); + EXPECT_EQ(icomp->invoked_flag, 0); + EXPECT_EQ(icomp->invoked_scalar, 8); + EXPECT_EQ(icomp->invoked_vector, -1); + nextstep = 9; + lammps_addstep_compute(lmp, (void *)&nextstep); + lammps_command(lmp, "run 1 post no"); + EXPECT_EQ(icomp->ntime, 2); + EXPECT_EQ(icomp->tlist[0], 10); + EXPECT_EQ(icomp->tlist[1], 9); + EXPECT_EQ(icomp->invoked_flag, 0); + EXPECT_EQ(icomp->invoked_scalar, -1); + EXPECT_EQ(icomp->invoked_vector, -1); + icomp->compute_scalar(); + EXPECT_EQ(icomp->invoked_scalar, 9); +} + TEST_F(LibraryProperties, has_error) { EXPECT_EQ(lammps_has_error(lmp), 0); From 5d47c417ed28530cc174526422c594a655a80077 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 27 Jan 2025 14:18:50 -0500 Subject: [PATCH 48/70] add fortran interface for lammps_clearstep_compute() --- doc/src/Fortran.rst | 2 ++ fortran/lammps.f90 | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/doc/src/Fortran.rst b/doc/src/Fortran.rst index bc641a237f..18d96875a8 100644 --- a/doc/src/Fortran.rst +++ b/doc/src/Fortran.rst @@ -323,6 +323,8 @@ of the contents of the :f:mod:`LIBLAMMPS` Fortran interface to LAMMPS. :ftype set_internal_variable: subroutine :f eval: :f:func:`eval` :ftype eval: function + :f clearstep_compute: :f:subr:`clearstep_compute` + :ftype clearstep_compute: subroutine :f gather_atoms: :f:subr:`gather_atoms` :ftype gather_atoms: subroutine :f gather_atoms_concat: :f:subr:`gather_atoms_concat` diff --git a/fortran/lammps.f90 b/fortran/lammps.f90 index 552b3dfad3..fee8d41de1 100644 --- a/fortran/lammps.f90 +++ b/fortran/lammps.f90 @@ -127,6 +127,7 @@ MODULE LIBLAMMPS PROCEDURE :: set_string_variable => lmp_set_string_variable PROCEDURE :: set_internal_variable => lmp_set_internal_variable PROCEDURE :: eval => lmp_eval + PROCEDURE :: clearstep_compute => lmp_clearstep_compute PROCEDURE, PRIVATE :: lmp_gather_atoms_int PROCEDURE, PRIVATE :: lmp_gather_atoms_double GENERIC :: gather_atoms => lmp_gather_atoms_int, & @@ -626,6 +627,12 @@ MODULE LIBLAMMPS REAL(c_double) :: lammps_eval END FUNCTION lammps_eval + SUBROUTINE lammps_clearstep_compute(handle) BIND(C) + IMPORT :: c_ptr + IMPLICIT NONE + TYPE(c_ptr), VALUE :: handle + END SUBROUTINE lammps_clearstep_compute + SUBROUTINE lammps_gather_atoms(handle, name, TYPE, count, DATA) BIND(C) IMPORT :: c_int, c_ptr IMPLICIT NONE @@ -1846,6 +1853,12 @@ CONTAINS CALL lammps_free(Cexpr) END FUNCTION lmp_eval + ! equivalent subroutine to lammps_clearstep_compute + SUBROUTINE lmp_clearstep_compute(self) + CLASS(lammps), INTENT(IN) :: self + CALL lammps_clearstep_compute(self%handle) + END SUBROUTINE lmp_clearstep_compute + ! equivalent function to lammps_gather_atoms (for integers) SUBROUTINE lmp_gather_atoms_int(self, name, count, data) CLASS(lammps), INTENT(IN) :: self From 23045d62c57ce16f048aff722a234054fa38db84 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 27 Jan 2025 14:27:34 -0500 Subject: [PATCH 49/70] add plugin wrapper and swig interface to new LAMMPS library functions --- examples/COUPLE/plugin/liblammpsplugin.c | 3 +++ examples/COUPLE/plugin/liblammpsplugin.h | 3 +++ tools/swig/lammps.i | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/examples/COUPLE/plugin/liblammpsplugin.c b/examples/COUPLE/plugin/liblammpsplugin.c index 99e38df32b..619b8828fc 100644 --- a/examples/COUPLE/plugin/liblammpsplugin.c +++ b/examples/COUPLE/plugin/liblammpsplugin.c @@ -118,6 +118,9 @@ liblammpsplugin_t *liblammpsplugin_load(const char *lib) ADDSYM(set_internal_variable); ADDSYM(variable_info); ADDSYM(eval); + ADDSYM(clearstep_compute); + ADDSYM(addstep_compute); + ADDSYM(addstep_compute_all); ADDSYM(gather_atoms); ADDSYM(gather_atoms_concat); diff --git a/examples/COUPLE/plugin/liblammpsplugin.h b/examples/COUPLE/plugin/liblammpsplugin.h index dd1c9628f5..c765b0adc3 100644 --- a/examples/COUPLE/plugin/liblammpsplugin.h +++ b/examples/COUPLE/plugin/liblammpsplugin.h @@ -164,6 +164,9 @@ struct _liblammpsplugin { int (*set_internal_variable)(void *, const char *, double); int (*variable_info)(void *, int, char *, int); double (*eval)(void *, const char *); + void (*clearstep_compute)(void *); + void (*addstep_compute)(void *, void *); + void (*addstep_compute_all)(void *, void *); void (*gather_atoms)(void *, const char *, int, int, void *); void (*gather_atoms_concat)(void *, const char *, int, int, void *); diff --git a/tools/swig/lammps.i b/tools/swig/lammps.i index bc9f46f407..476e6ad17d 100644 --- a/tools/swig/lammps.i +++ b/tools/swig/lammps.i @@ -143,6 +143,9 @@ extern int lammps_set_string_variable(void *, const char *, const char *); extern int lammps_set_internal_variable(void *, const char *, double); extern int lammps_variable_info(void *handle, int idx, char *buf, int bufsize); extern double lammps_eval(void *handle, const char *expr); +extern void lammps_clearstep_compute(void *handle); +extern void lammps_addstep_compute(void *handle, void *nstep); +extern void lammps_addstep_compute_all(void *handle, void *nstep); extern void lammps_gather_atoms(void *, char *, int, int, void *); extern void lammps_gather_atoms_concat(void *, char *, int, int, void *); @@ -336,6 +339,9 @@ extern int lammps_set_string_variable(void *, const char *, const char *); extern int lammps_set_internal_variable(void *, const char *, double); extern int lammps_variable_info(void *handle, int idx, char *buf, int bufsize); extern double lammps_eval(void *handle, const char *expr); +extern void lammps_clearstep_compute(void *handle); +extern void lammps_addstep_compute(void *handle, void *nstep); +extern void lammps_addstep_compute_all(void *handle, void *nstep); extern void lammps_gather_atoms(void *, char *, int, int, void *); extern void lammps_gather_atoms_concat(void *, char *, int, int, void *); From 8f551df46a56497d96f3e1253df7bb331662d95b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 27 Jan 2025 20:38:08 -0500 Subject: [PATCH 50/70] add fortran interface for lammps_addstep_compute() and lammps_addstep_compute_all() --- fortran/lammps.f90 | 89 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/fortran/lammps.f90 b/fortran/lammps.f90 index fee8d41de1..2cfd4422b0 100644 --- a/fortran/lammps.f90 +++ b/fortran/lammps.f90 @@ -127,7 +127,16 @@ MODULE LIBLAMMPS PROCEDURE :: set_string_variable => lmp_set_string_variable PROCEDURE :: set_internal_variable => lmp_set_internal_variable PROCEDURE :: eval => lmp_eval + PROCEDURE :: clearstep_compute => lmp_clearstep_compute + PROCEDURE, PRIVATE :: lmp_addstep_compute_smallint + PROCEDURE, PRIVATE :: lmp_addstep_compute_bigint + GENERIC :: addstep_compute => lmp_addstep_compute_smallint, lmp_addstep_compute_bigint + PROCEDURE, PRIVATE :: lmp_addstep_compute_all_smallint + PROCEDURE, PRIVATE :: lmp_addstep_compute_all_bigint + GENERIC :: addstep_compute_all => lmp_addstep_compute_all_smallint, & + lmp_addstep_compute_all_bigint + PROCEDURE, PRIVATE :: lmp_gather_atoms_int PROCEDURE, PRIVATE :: lmp_gather_atoms_double GENERIC :: gather_atoms => lmp_gather_atoms_int, & @@ -633,6 +642,18 @@ MODULE LIBLAMMPS TYPE(c_ptr), VALUE :: handle END SUBROUTINE lammps_clearstep_compute + SUBROUTINE lammps_addstep_compute(handle, step) BIND(C) + IMPORT :: c_ptr + IMPLICIT NONE + TYPE(c_ptr), VALUE :: handle, step + END SUBROUTINE lammps_addstep_compute + + SUBROUTINE lammps_addstep_compute_all(handle, step) BIND(C) + IMPORT :: c_ptr + IMPLICIT NONE + TYPE(c_ptr), VALUE :: handle, step + END SUBROUTINE lammps_addstep_compute_all + SUBROUTINE lammps_gather_atoms(handle, name, TYPE, count, DATA) BIND(C) IMPORT :: c_int, c_ptr IMPLICIT NONE @@ -1859,6 +1880,74 @@ CONTAINS CALL lammps_clearstep_compute(self%handle) END SUBROUTINE lmp_clearstep_compute + ! equivalent subroutine to lammps_addstep_compute + SUBROUTINE lmp_addstep_compute_bigint(self, nextstep) + CLASS(lammps), INTENT(IN) :: self + INTEGER(kind=8), INTENT(IN) :: nextstep + INTEGER(c_int), TARGET :: smallstep + INTEGER(c_int64_t), TARGET :: bigstep + TYPE(c_ptr) :: ptrstep + IF (SIZE_BIGINT == 4_c_int) THEN + smallstep = INT(nextstep,kind=c_int) + ptrstep = C_LOC(smallstep) + ELSE + bigstep = nextstep + ptrstep = C_LOC(bigstep) + END IF + CALL lammps_addstep_compute(self%handle, ptrstep) + END SUBROUTINE lmp_addstep_compute_bigint + + ! equivalent subroutine to lammps_addstep_compute + SUBROUTINE lmp_addstep_compute_smallint(self, nextstep) + CLASS(lammps), INTENT(IN) :: self + INTEGER(kind=4), INTENT(IN) :: nextstep + INTEGER(c_int), TARGET :: smallstep + INTEGER(c_int64_t), TARGET :: bigstep + TYPE(c_ptr) :: ptrstep + IF (SIZE_BIGINT == 4_c_int) THEN + smallstep = nextstep + ptrstep = C_LOC(smallstep) + ELSE + bigstep = nextstep + ptrstep = C_LOC(bigstep) + END IF + CALL lammps_addstep_compute(self%handle, ptrstep) + END SUBROUTINE lmp_addstep_compute_smallint + + ! equivalent subroutine to lammps_addstep_compute_all + SUBROUTINE lmp_addstep_compute_all_bigint(self, nextstep) + CLASS(lammps), INTENT(IN) :: self + INTEGER(kind=8), INTENT(IN) :: nextstep + INTEGER(c_int), TARGET :: smallstep + INTEGER(c_int64_t), TARGET :: bigstep + TYPE(c_ptr) :: ptrstep + IF (SIZE_BIGINT == 4_c_int) THEN + smallstep = INT(nextstep,kind=c_int) + ptrstep = C_LOC(smallstep) + ELSE + bigstep = nextstep + ptrstep = C_LOC(bigstep) + END IF + CALL lammps_addstep_compute_all(self%handle, ptrstep) + END SUBROUTINE lmp_addstep_compute_all_bigint + + ! equivalent subroutine to lammps_addstep_compute_all + SUBROUTINE lmp_addstep_compute_all_smallint(self, nextstep) + CLASS(lammps), INTENT(IN) :: self + INTEGER(kind=4), INTENT(IN) :: nextstep + INTEGER(c_int), TARGET :: smallstep + INTEGER(c_int64_t), TARGET :: bigstep + TYPE(c_ptr) :: ptrstep + IF (SIZE_BIGINT == 4_c_int) THEN + smallstep = nextstep + ptrstep = C_LOC(smallstep) + ELSE + bigstep = nextstep + ptrstep = C_LOC(bigstep) + END IF + CALL lammps_addstep_compute_all(self%handle, ptrstep) + END SUBROUTINE lmp_addstep_compute_all_smallint + ! equivalent function to lammps_gather_atoms (for integers) SUBROUTINE lmp_gather_atoms_int(self, name, count, data) CLASS(lammps), INTENT(IN) :: self From 2c3f0d65acf6f0a8ff971a1f467fe5a8318c6d40 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 27 Jan 2025 20:58:49 -0500 Subject: [PATCH 51/70] update docs --- doc/src/Fortran.rst | 57 ++++++++++++++++++++- doc/utils/sphinx-config/false_positives.txt | 2 + 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/doc/src/Fortran.rst b/doc/src/Fortran.rst index 18d96875a8..30d0d5f4a7 100644 --- a/doc/src/Fortran.rst +++ b/doc/src/Fortran.rst @@ -325,6 +325,10 @@ of the contents of the :f:mod:`LIBLAMMPS` Fortran interface to LAMMPS. :ftype eval: function :f clearstep_compute: :f:subr:`clearstep_compute` :ftype clearstep_compute: subroutine + :f addstep_compute: :f:subr:`addstep_compute` + :ftype addstep_compute: subroutine + :f addstep_compute_all: :f:subr:`addstep_compute_all` + :ftype addstep_compute_all: subroutine :f gather_atoms: :f:subr:`gather_atoms` :ftype gather_atoms: subroutine :f gather_atoms_concat: :f:subr:`gather_atoms_concat` @@ -1452,11 +1456,62 @@ Procedures Bound to the :f:type:`lammps` Derived Type an internal-style variable, an error is generated. :p character(len=*) name: name of the variable - :p read(c_double) val: new value to assign to the variable + :p real(c_double) val: new value to assign to the variable :to: :cpp:func:`lammps_set_internal_variable` -------- +.. f:function:: eval(expr) + + This function is a wrapper around :cpp:func:`lammps_eval` that takes a + LAMMPS equal style variable string, evaluates it and returns the resulting + scalar value as a floating-point number. + + .. versionadded:: TBD + + :p character(len=\*) expr: string to be evaluated + :to: :cpp:func:`lammps_eval` + :r value [real(c_double)]: result of the evaluated string + +-------- + +.. f:subroutine:: clearstep_compute() + + Clear whether a compute has been invoked + + .. versionadded:: TBD + + :to: :cpp:func:`lammps_clearstep_compute` + +-------- + +.. f:subroutine:: addstep_compute(nextstep) + + Add timestep to list of future compute invocations + if the compute has been invoked on the current timestep + + .. versionadded:: TBD + + overloaded for 32-bit and 64-bit integer arguments + + :p integer(kind=8 or kind=4) nextstep: next timestep + :to: :cpp:func:`lammps_addstep_compute` + +-------- + +.. f:subroutine:: addstep_compute_all(nextstep) + + Add timestep to list of future compute invocations + + .. versionadded:: TBD + + overloaded for 32-bit and 64-bit integer arguments + + :p integer(kind=8 or kind=4) nextstep: next timestep + :to: :cpp:func:`lammps_addstep_compute_all` + +-------- + .. f:subroutine:: gather_atoms(name, count, data) This function calls :cpp:func:`lammps_gather_atoms` to gather the named diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index 6746d591c6..c43e0941a5 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -2532,6 +2532,7 @@ Nevery Nevins newfile Newns +newstep newtype nextsort Neyts @@ -3769,6 +3770,7 @@ Tigran Tij Tildesley Timan +timeflag timeI timespan timestamp From bb83497f6164a8fb7228ead44f1c4dda03d7c1c8 Mon Sep 17 00:00:00 2001 From: megmcca Date: Tue, 28 Jan 2025 12:40:50 -0700 Subject: [PATCH 52/70] add offset code to base omp files --- src/OPENMP/pair_hbond_dreiding_lj_omp.cpp | 7 +++++++ src/OPENMP/pair_hbond_dreiding_morse_omp.cpp | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/OPENMP/pair_hbond_dreiding_lj_omp.cpp b/src/OPENMP/pair_hbond_dreiding_lj_omp.cpp index b0f6dcfb5b..9bc5f5d254 100644 --- a/src/OPENMP/pair_hbond_dreiding_lj_omp.cpp +++ b/src/OPENMP/pair_hbond_dreiding_lj_omp.cpp @@ -222,6 +222,13 @@ void PairHbondDreidingLJOMP::eval(int iifrom, int iito, ThrData * const thr) if (c < -1.0) c = -1.0; ac = acos(c); + if (angle_offset_flag){ + ac = ac + pm.angle_offset; + c = cos(ac); + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; + } + if (ac > pm.cut_angle && ac < (2.0*MY_PI - pm.cut_angle)) { s = sqrt(1.0 - c*c); if (s < SMALL) s = SMALL; diff --git a/src/OPENMP/pair_hbond_dreiding_morse_omp.cpp b/src/OPENMP/pair_hbond_dreiding_morse_omp.cpp index 0e43e2a037..bb0970dbdc 100644 --- a/src/OPENMP/pair_hbond_dreiding_morse_omp.cpp +++ b/src/OPENMP/pair_hbond_dreiding_morse_omp.cpp @@ -222,6 +222,13 @@ void PairHbondDreidingMorseOMP::eval(int iifrom, int iito, ThrData * const thr) if (c < -1.0) c = -1.0; ac = acos(c); + if (angle_offset_flag){ + ac = ac + pm.angle_offset; + c = cos(ac); + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; + } + if (ac > pm.cut_angle && ac < (2.0*MY_PI - pm.cut_angle)) { s = sqrt(1.0 - c*c); if (s < SMALL) s = SMALL; From f8ac22ade7ced34117f0755e3b19864d2a9ff5f2 Mon Sep 17 00:00:00 2001 From: megmcca Date: Tue, 28 Jan 2025 12:42:34 -0700 Subject: [PATCH 53/70] add flags and set up inheritance --- ...pair_hbond_dreiding_lj_angleoffset_omp.cpp | 282 +----------------- .../pair_hbond_dreiding_lj_angleoffset_omp.h | 16 +- ...r_hbond_dreiding_morse_angleoffset_omp.cpp | 282 +----------------- ...air_hbond_dreiding_morse_angleoffset_omp.h | 18 +- 4 files changed, 9 insertions(+), 589 deletions(-) diff --git a/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.cpp b/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.cpp index 9d4b06af43..1a5126971a 100644 --- a/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.cpp +++ b/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.cpp @@ -38,285 +38,7 @@ static constexpr double SMALL = 0.001; /* ---------------------------------------------------------------------- */ PairHbondDreidingLJAngleoffsetOMP::PairHbondDreidingLJAngleoffsetOMP(LAMMPS *lmp) : - PairHbondDreidingLJAngleoffset(lmp), ThrOMP(lmp, THR_PAIR) -{ - suffix_flag |= Suffix::OMP; - respa_enable = 0; - hbcount_thr = hbeng_thr = nullptr; + PairHbondDreidingLJOMP(lmp) { + angle_offset_flag = 1; } -/* ---------------------------------------------------------------------- */ - -PairHbondDreidingLJAngleoffsetOMP::~PairHbondDreidingLJAngleoffsetOMP() -{ - if (hbcount_thr) { - delete[] hbcount_thr; - delete[] hbeng_thr; - } -} - -/* ---------------------------------------------------------------------- */ - -void PairHbondDreidingLJAngleoffsetOMP::compute(int eflag, int vflag) -{ - ev_init(eflag,vflag); - - const int nall = atom->nlocal + atom->nghost; - const int nthreads = comm->nthreads; - const int inum = list->inum; - - if (!hbcount_thr) { - hbcount_thr = new double[nthreads]; - hbeng_thr = new double[nthreads]; - } - - for (int i=0; i < nthreads; ++i) { - hbcount_thr[i] = 0.0; - hbeng_thr[i] = 0.0; - } - -#if defined(_OPENMP) -#pragma omp parallel LMP_DEFAULT_NONE LMP_SHARED(eflag,vflag) -#endif - { - int ifrom, ito, tid; - - loop_setup_thr(ifrom, ito, tid, inum, nthreads); - ThrData *thr = fix->get_thr(tid); - thr->timer(Timer::START); - ev_setup_thr(eflag, vflag, nall, eatom, vatom, nullptr, thr); - - if (evflag) { - if (eflag) { - if (force->newton_pair) eval<1,1,1>(ifrom, ito, thr); - else eval<1,1,0>(ifrom, ito, thr); - } else { - if (force->newton_pair) eval<1,0,1>(ifrom, ito, thr); - else eval<1,0,0>(ifrom, ito, thr); - } - } else { - if (force->newton_pair) eval<0,0,1>(ifrom, ito, thr); - else eval<0,0,0>(ifrom, ito, thr); - } - - thr->timer(Timer::PAIR); - reduce_thr(this, eflag, vflag, thr); - } // end of omp parallel region - - // reduce per thread hbond data - if (eflag_global) { - pvector[0] = 0.0; - pvector[1] = 0.0; - for (int i=0; i < nthreads; ++i) { - pvector[0] += hbcount_thr[i]; - pvector[1] += hbeng_thr[i]; - } - } -} - -template -void PairHbondDreidingLJAngleoffsetOMP::eval(int iifrom, int iito, ThrData * const thr) -{ - int i,j,k,m,ii,jj,kk,jnum,knum,itype,jtype,ktype,iatom,imol; - tagint tagprev; - double xtmp,ytmp,ztmp,delx,dely,delz,rsq,rsq1,rsq2,r1,r2; - double factor_hb,force_angle,force_kernel,evdwl,eng_lj; - double c,s,a,b,ac,a11,a12,a22,vx1,vx2,vy1,vy2,vz1,vz2; - double fi[3],fj[3],delr1[3],delr2[3]; - double r2inv,r10inv; - double switch1,switch2; - int *ilist,*jlist,*numneigh,**firstneigh; - const tagint *klist; - - evdwl = 0.0; - - const auto * _noalias const x = (dbl3_t *) atom->x[0]; - auto * _noalias const f = (dbl3_t *) thr->get_f()[0]; - const tagint * _noalias const tag = atom->tag; - const int * _noalias const molindex = atom->molindex; - const int * _noalias const molatom = atom->molatom; - const int * _noalias const type = atom->type; - const double * _noalias const special_lj = force->special_lj; - const int * const * const nspecial = atom->nspecial; - const tagint * const * const special = atom->special; - const int molecular = atom->molecular; - Molecule * const * const onemols = atom->avec->onemols; - double fxtmp,fytmp,fztmp; - - ilist = list->ilist; - numneigh = list->numneigh; - firstneigh = list->firstneigh; - - // ii = loop over donors - // jj = loop over acceptors - // kk = loop over hydrogens bonded to donor - - int hbcount = 0; - double hbeng = 0.0; - - for (ii = iifrom; ii < iito; ++ii) { - i = ilist[ii]; - itype = type[i]; - if (!donor[itype]) continue; - if (molecular == Atom::MOLECULAR) { - klist = special[i]; - knum = nspecial[i][0]; - } else { - if (molindex[i] < 0) continue; - imol = molindex[i]; - iatom = molatom[i]; - klist = onemols[imol]->special[iatom]; - knum = onemols[imol]->nspecial[iatom][0]; - tagprev = tag[i] - iatom - 1; - } - jlist = firstneigh[i]; - jnum = numneigh[i]; - fxtmp=fytmp=fztmp=0.0; - - xtmp = x[i].x; - ytmp = x[i].y; - ztmp = x[i].z; - - for (jj = 0; jj < jnum; jj++) { - j = jlist[jj]; - factor_hb = special_lj[sbmask(j)]; - j &= NEIGHMASK; - - jtype = type[j]; - if (!acceptor[jtype]) continue; - - delx = xtmp - x[j].x; - dely = ytmp - x[j].y; - delz = ztmp - x[j].z; - rsq = delx*delx + dely*dely + delz*delz; - - for (kk = 0; kk < knum; kk++) { - if (molecular == Atom::MOLECULAR) k = atom->map(klist[kk]); - else k = atom->map(klist[kk]+tagprev); - if (k < 0) continue; - ktype = type[k]; - m = type2param[itype][jtype][ktype]; - if (m < 0) continue; - const Param &pm = params[m]; - - if (rsq < pm.cut_outersq) { - delr1[0] = xtmp - x[k].x; - delr1[1] = ytmp - x[k].y; - delr1[2] = ztmp - x[k].z; - domain->minimum_image(delr1); - rsq1 = delr1[0]*delr1[0] + delr1[1]*delr1[1] + delr1[2]*delr1[2]; - r1 = sqrt(rsq1); - - delr2[0] = x[j].x - x[k].x; - delr2[1] = x[j].y - x[k].y; - delr2[2] = x[j].z - x[k].z; - domain->minimum_image(delr2); - rsq2 = delr2[0]*delr2[0] + delr2[1]*delr2[1] + delr2[2]*delr2[2]; - r2 = sqrt(rsq2); - - // angle (cos and sin) - - c = delr1[0]*delr2[0] + delr1[1]*delr2[1] + delr1[2]*delr2[2]; - c /= r1*r2; - if (c > 1.0) c = 1.0; - if (c < -1.0) c = -1.0; - ac = acos(c); - - ac = ac + pm.angle_offset; - c = cos(ac); - if (c > 1.0) c = 1.0; - if (c < -1.0) c = -1.0; - - if (ac > pm.cut_angle && ac < (2.0*MY_PI - pm.cut_angle)) { - s = sqrt(1.0 - c*c); - if (s < SMALL) s = SMALL; - - // LJ-specific kernel - - r2inv = 1.0/rsq; - r10inv = r2inv*r2inv*r2inv*r2inv*r2inv; - force_kernel = r10inv*(pm.lj1*r2inv - pm.lj2)*r2inv * - powint(c,pm.ap); - force_angle = pm.ap * r10inv*(pm.lj3*r2inv - pm.lj4) * - powint(c,pm.ap-1)*s; - - eng_lj = r10inv*(pm.lj3*r2inv - pm.lj4); - if (rsq > pm.cut_innersq) { - switch1 = (pm.cut_outersq-rsq) * (pm.cut_outersq-rsq) * - (pm.cut_outersq + 2.0*rsq - 3.0*pm.cut_innersq) / - pm.denom_vdw; - switch2 = 12.0*rsq * (pm.cut_outersq-rsq) * - (rsq-pm.cut_innersq) / pm.denom_vdw; - force_kernel = force_kernel*switch1 + eng_lj*switch2/rsq; - force_angle *= switch1; - eng_lj *= switch1; - } - - if (EFLAG) { - evdwl = eng_lj * powint(c,pm.ap); - evdwl *= factor_hb; - } - - a = factor_hb*force_angle/s; - b = factor_hb*force_kernel; - - a11 = a*c / rsq1; - a12 = -a / (r1*r2); - a22 = a*c / rsq2; - - vx1 = a11*delr1[0] + a12*delr2[0]; - vx2 = a22*delr2[0] + a12*delr1[0]; - vy1 = a11*delr1[1] + a12*delr2[1]; - vy2 = a22*delr2[1] + a12*delr1[1]; - vz1 = a11*delr1[2] + a12*delr2[2]; - vz2 = a22*delr2[2] + a12*delr1[2]; - - fi[0] = vx1 + b*delx; - fi[1] = vy1 + b*dely; - fi[2] = vz1 + b*delz; - fj[0] = vx2 - b*delx; - fj[1] = vy2 - b*dely; - fj[2] = vz2 - b*delz; - - fxtmp += fi[0]; - fytmp += fi[1]; - fztmp += fi[2]; - - f[j].x += fj[0]; - f[j].y += fj[1]; - f[j].z += fj[2]; - - f[k].x -= vx1 + vx2; - f[k].y -= vy1 + vy2; - f[k].z -= vz1 + vz2; - - // KIJ instead of IJK b/c delr1/delr2 are both with respect to k - - if (EVFLAG) ev_tally3_thr(this,k,i,j,evdwl,0.0,fi,fj,delr1,delr2,thr); - if (EFLAG) { - hbcount++; - hbeng += evdwl; - } - } - } - } - } - f[i].x += fxtmp; - f[i].y += fytmp; - f[i].z += fztmp; - } - const int tid = thr->get_tid(); - hbcount_thr[tid] = static_cast(hbcount); - hbeng_thr[tid] = hbeng; -} - -/* ---------------------------------------------------------------------- */ - -double PairHbondDreidingLJAngleoffsetOMP::memory_usage() -{ - double bytes = memory_usage_thr(); - bytes += (double)comm->nthreads * 2 * sizeof(double); - bytes += PairHbondDreidingLJAngleoffset::memory_usage(); - - return bytes; -} diff --git a/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.h b/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.h index ef2ff9ee2e..ce79a03dee 100644 --- a/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.h +++ b/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.h @@ -24,26 +24,14 @@ PairStyle(hbond/dreiding/lj/angleoffset/omp,PairHbondDreidingLJAngleoffsetOMP); #ifndef LMP_PAIR_HBOND_DREIDING_LJ_ANGLEOFFSET_OMP_H #define LMP_PAIR_HBOND_DREIDING_LJ_ANGLEOFFSET_OMP_H -#include "pair_hbond_dreiding_lj_angleoffset.h" -#include "thr_omp.h" +#include "pair_hbond_dreiding_lj_omp.h" namespace LAMMPS_NS { -class PairHbondDreidingLJAngleoffsetOMP : public PairHbondDreidingLJAngleoffset, public ThrOMP { +class PairHbondDreidingLJAngleoffsetOMP : public PairHbondDreidingLJOMP { public: PairHbondDreidingLJAngleoffsetOMP(class LAMMPS *); - ~PairHbondDreidingLJAngleoffsetOMP() override; - - void compute(int, int) override; - double memory_usage() override; - - protected: - double *hbcount_thr, *hbeng_thr; - - private: - template - void eval(int ifrom, int ito, ThrData *const thr); }; } // namespace LAMMPS_NS diff --git a/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.cpp b/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.cpp index ad5c43f7b7..b0f9cde92f 100644 --- a/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.cpp +++ b/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.cpp @@ -38,284 +38,6 @@ static constexpr double SMALL = 0.001; /* ---------------------------------------------------------------------- */ PairHbondDreidingMorseAngleoffsetOMP::PairHbondDreidingMorseAngleoffsetOMP(LAMMPS *lmp) : - PairHbondDreidingMorseAngleoffset(lmp), ThrOMP(lmp, THR_PAIR) -{ - suffix_flag |= Suffix::OMP; - respa_enable = 0; - hbcount_thr = hbeng_thr = nullptr; -} - -/* ---------------------------------------------------------------------- */ - -PairHbondDreidingMorseAngleoffsetOMP::~PairHbondDreidingMorseAngleoffsetOMP() -{ - if (hbcount_thr) { - delete[] hbcount_thr; - delete[] hbeng_thr; - } -} - -/* ---------------------------------------------------------------------- */ - -void PairHbondDreidingMorseAngleoffsetOMP::compute(int eflag, int vflag) -{ - ev_init(eflag,vflag); - - const int nall = atom->nlocal + atom->nghost; - const int nthreads = comm->nthreads; - const int inum = list->inum; - - if (!hbcount_thr) { - hbcount_thr = new double[nthreads]; - hbeng_thr = new double[nthreads]; - } - - for (int i=0; i < nthreads; ++i) { - hbcount_thr[i] = 0.0; - hbeng_thr[i] = 0.0; - } - -#if defined(_OPENMP) -#pragma omp parallel LMP_DEFAULT_NONE LMP_SHARED(eflag,vflag) -#endif - { - int ifrom, ito, tid; - - loop_setup_thr(ifrom, ito, tid, inum, nthreads); - ThrData *thr = fix->get_thr(tid); - thr->timer(Timer::START); - ev_setup_thr(eflag, vflag, nall, eatom, vatom, nullptr, thr); - - if (evflag) { - if (eflag) { - if (force->newton_pair) eval<1,1,1>(ifrom, ito, thr); - else eval<1,1,0>(ifrom, ito, thr); - } else { - if (force->newton_pair) eval<1,0,1>(ifrom, ito, thr); - else eval<1,0,0>(ifrom, ito, thr); - } - } else { - if (force->newton_pair) eval<0,0,1>(ifrom, ito, thr); - else eval<0,0,0>(ifrom, ito, thr); - } - - thr->timer(Timer::PAIR); - reduce_thr(this, eflag, vflag, thr); - } // end of omp parallel region - - // reduce per thread hbond data - if (eflag_global) { - pvector[0] = 0.0; - pvector[1] = 0.0; - for (int i=0; i < nthreads; ++i) { - pvector[0] += hbcount_thr[i]; - pvector[1] += hbeng_thr[i]; - } - } -} - -template -void PairHbondDreidingMorseAngleoffsetOMP::eval(int iifrom, int iito, ThrData * const thr) -{ - int i,j,k,m,ii,jj,kk,jnum,knum,itype,jtype,ktype,imol,iatom; - tagint tagprev; - double xtmp,ytmp,ztmp,delx,dely,delz,rsq,rsq1,rsq2,r1,r2; - double factor_hb,force_angle,force_kernel,evdwl; - double c,s,a,b,ac,a11,a12,a22,vx1,vx2,vy1,vy2,vz1,vz2; - double fi[3],fj[3],delr1[3],delr2[3]; - double r,dr,dexp,eng_morse,switch1,switch2; - int *ilist,*jlist,*numneigh,**firstneigh; - const tagint *klist; - - evdwl = 0.0; - - const auto * _noalias const x = (dbl3_t *) atom->x[0]; - auto * _noalias const f = (dbl3_t *) thr->get_f()[0]; - const tagint * _noalias const tag = atom->tag; - const int * _noalias const type = atom->type; - const int * _noalias const molindex = atom->molindex; - const int * _noalias const molatom = atom->molatom; - const double * _noalias const special_lj = force->special_lj; - const int * const * const nspecial = atom->nspecial; - const tagint * const * const special = atom->special; - const int molecular = atom->molecular; - Molecule * const * const onemols = atom->avec->onemols; - double fxtmp,fytmp,fztmp; - - ilist = list->ilist; - numneigh = list->numneigh; - firstneigh = list->firstneigh; - - // ii = loop over donors - // jj = loop over acceptors - // kk = loop over hydrogens bonded to donor - - int hbcount = 0; - double hbeng = 0.0; - - for (ii = iifrom; ii < iito; ++ii) { - - i = ilist[ii]; - itype = type[i]; - if (!donor[itype]) continue; - if (molecular == Atom::MOLECULAR) { - klist = special[i]; - knum = nspecial[i][0]; - } else { - if (molindex[i] < 0) continue; - imol = molindex[i]; - iatom = molatom[i]; - klist = onemols[imol]->special[iatom]; - knum = onemols[imol]->nspecial[iatom][0]; - tagprev = tag[i] - iatom - 1; - } - jlist = firstneigh[i]; - jnum = numneigh[i]; - fxtmp=fytmp=fztmp=0.0; - - xtmp = x[i].x; - ytmp = x[i].y; - ztmp = x[i].z; - - for (jj = 0; jj < jnum; jj++) { - j = jlist[jj]; - factor_hb = special_lj[sbmask(j)]; - j &= NEIGHMASK; - - jtype = type[j]; - if (!acceptor[jtype]) continue; - - delx = xtmp - x[j].x; - dely = ytmp - x[j].y; - delz = ztmp - x[j].z; - rsq = delx*delx + dely*dely + delz*delz; - - for (kk = 0; kk < knum; kk++) { - if (molecular == Atom::MOLECULAR) k = atom->map(klist[kk]); - else k = atom->map(klist[kk]+tagprev); - if (k < 0) continue; - ktype = type[k]; - m = type2param[itype][jtype][ktype]; - if (m < 0) continue; - const Param &pm = params[m]; - - if (rsq < pm.cut_outersq) { - delr1[0] = xtmp - x[k].x; - delr1[1] = ytmp - x[k].y; - delr1[2] = ztmp - x[k].z; - domain->minimum_image(delr1); - rsq1 = delr1[0]*delr1[0] + delr1[1]*delr1[1] + delr1[2]*delr1[2]; - r1 = sqrt(rsq1); - - delr2[0] = x[j].x - x[k].x; - delr2[1] = x[j].y - x[k].y; - delr2[2] = x[j].z - x[k].z; - domain->minimum_image(delr2); - rsq2 = delr2[0]*delr2[0] + delr2[1]*delr2[1] + delr2[2]*delr2[2]; - r2 = sqrt(rsq2); - - // angle (cos and sin) - - c = delr1[0]*delr2[0] + delr1[1]*delr2[1] + delr1[2]*delr2[2]; - c /= r1*r2; - if (c > 1.0) c = 1.0; - if (c < -1.0) c = -1.0; - ac = acos(c); - - ac = ac + pm.angle_offset; - c = cos(ac); - if (c > 1.0) c = 1.0; - if (c < -1.0) c = -1.0; - - if (ac > pm.cut_angle && ac < (2.0*MY_PI - pm.cut_angle)) { - s = sqrt(1.0 - c*c); - if (s < SMALL) s = SMALL; - - // Morse-specific kernel - - r = sqrt(rsq); - dr = r - pm.r0; - dexp = exp(-pm.alpha * dr); - eng_morse = pm.d0 * (dexp*dexp - 2.0*dexp); - force_kernel = pm.morse1*(dexp*dexp - dexp)/r * powint(c,pm.ap); - force_angle = pm.ap * eng_morse * powint(c,pm.ap-1)*s; - - if (rsq > pm.cut_innersq) { - switch1 = (pm.cut_outersq-rsq) * (pm.cut_outersq-rsq) * - (pm.cut_outersq + 2.0*rsq - 3.0*pm.cut_innersq) / - pm.denom_vdw; - switch2 = 12.0*rsq * (pm.cut_outersq-rsq) * - (rsq-pm.cut_innersq) / pm.denom_vdw; - force_kernel = force_kernel*switch1 + eng_morse*switch2/rsq; - force_angle *= switch1; - eng_morse *= switch1; - } - - if (EFLAG) { - evdwl = eng_morse * powint(c,pm.ap); - evdwl *= factor_hb; - } - - a = factor_hb*force_angle/s; - b = factor_hb*force_kernel; - - a11 = a*c / rsq1; - a12 = -a / (r1*r2); - a22 = a*c / rsq2; - - vx1 = a11*delr1[0] + a12*delr2[0]; - vx2 = a22*delr2[0] + a12*delr1[0]; - vy1 = a11*delr1[1] + a12*delr2[1]; - vy2 = a22*delr2[1] + a12*delr1[1]; - vz1 = a11*delr1[2] + a12*delr2[2]; - vz2 = a22*delr2[2] + a12*delr1[2]; - - fi[0] = vx1 + b*delx; - fi[1] = vy1 + b*dely; - fi[2] = vz1 + b*delz; - fj[0] = vx2 - b*delx; - fj[1] = vy2 - b*dely; - fj[2] = vz2 - b*delz; - - fxtmp += fi[0]; - fytmp += fi[1]; - fztmp += fi[2]; - - f[j].x += fj[0]; - f[j].y += fj[1]; - f[j].z += fj[2]; - - f[k].x -= vx1 + vx2; - f[k].y -= vy1 + vy2; - f[k].z -= vz1 + vz2; - - // KIJ instead of IJK b/c delr1/delr2 are both with respect to k - - if (EVFLAG) ev_tally3_thr(this,k,i,j,evdwl,0.0,fi,fj,delr1,delr2,thr); - if (EFLAG) { - hbcount++; - hbeng += evdwl; - } - } - } - } - } - f[i].x += fxtmp; - f[i].y += fytmp; - f[i].z += fztmp; - } - const int tid = thr->get_tid(); - hbcount_thr[tid] = static_cast(hbcount); - hbeng_thr[tid] = hbeng; -} - -/* ---------------------------------------------------------------------- */ - -double PairHbondDreidingMorseAngleoffsetOMP::memory_usage() -{ - double bytes = memory_usage_thr(); - bytes += (double)comm->nthreads * 2 * sizeof(double); - bytes += PairHbondDreidingMorseAngleoffset::memory_usage(); - - return bytes; + PairHbondDreidingMorseOMP(lmp) { + angle_offset_flag = 1; } diff --git a/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.h b/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.h index 5e87908df3..2808ed1e68 100644 --- a/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.h +++ b/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.h @@ -24,28 +24,16 @@ PairStyle(hbond/dreiding/morse/angleoffset/omp,PairHbondDreidingMorseAngleoffset #ifndef LMP_PAIR_HBOND_DREIDING_MORSE_ANGLEOFFSET_OMP_H #define LMP_PAIR_HBOND_DREIDING_MORSE_ANGLEOFFSET_OMP_H -#include "pair_hbond_dreiding_morse_angleoffset.h" -#include "thr_omp.h" +#include "pair_hbond_dreiding_morse_omp.h" namespace LAMMPS_NS { class PairHbondDreidingMorseAngleoffsetOMP : - public PairHbondDreidingMorseAngleoffset, - public ThrOMP { + public PairHbondDreidingMorseOMP { public: PairHbondDreidingMorseAngleoffsetOMP(class LAMMPS *); - ~PairHbondDreidingMorseAngleoffsetOMP() override; - - void compute(int, int) override; - double memory_usage() override; - - protected: - double *hbcount_thr, *hbeng_thr; - - private: - template - void eval(int ifrom, int ito, ThrData *const thr); + }; } // namespace LAMMPS_NS From 8b85ee22a31ba9466de9d29adee05415cf663501 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 28 Jan 2025 21:32:13 -0500 Subject: [PATCH 54/70] use consistent formatting across all hbond/dreiding styles --- .../pair_hbond_dreiding_morse_angleoffset.cpp | 6 +++--- src/MOLECULE/pair_hbond_dreiding_lj.cpp | 11 ++++------- src/MOLECULE/pair_hbond_dreiding_morse.cpp | 14 +++++++------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp index a687d4d7ea..21f26ea8d1 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.cpp @@ -46,9 +46,9 @@ PairHbondDreidingMorseAngleoffset::PairHbondDreidingMorseAngleoffset(LAMMPS *lmp angle_offset_flag = 1; } -// /* ---------------------------------------------------------------------- -// set coeffs for one or more type pairs -// ------------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------- + * set coeffs for one or more type pairs + * ---------------------------------------------------------------------- */ void PairHbondDreidingMorseAngleoffset::coeff(int narg, char **arg) { diff --git a/src/MOLECULE/pair_hbond_dreiding_lj.cpp b/src/MOLECULE/pair_hbond_dreiding_lj.cpp index 0511ecb021..fd0e61edd2 100644 --- a/src/MOLECULE/pair_hbond_dreiding_lj.cpp +++ b/src/MOLECULE/pair_hbond_dreiding_lj.cpp @@ -85,7 +85,7 @@ void PairHbondDreidingLJ::compute(int eflag, int vflag) tagint tagprev; double delx,dely,delz,rsq,rsq1,rsq2,r1,r2; double factor_hb,force_angle,force_kernel,evdwl,eng_lj,ehbond,force_switch; - double c,s,a,b,ac,a11,a12,a22,vx1,vx2,vy1,vy2,vz1,vz2,d; + double c,s,a,b,d,ac,a11,a12,a22,vx1,vx2,vy1,vy2,vz1,vz2; double fi[3],fj[3],delr1[3],delr2[3]; double r2inv,r10inv; double switch1,switch2; @@ -196,15 +196,12 @@ void PairHbondDreidingLJ::compute(int eflag, int vflag) r2inv = 1.0/rsq; r10inv = r2inv*r2inv*r2inv*r2inv*r2inv; - force_kernel = r10inv*(pm.lj1*r2inv - pm.lj2)*r2inv * - powint(c,pm.ap); - force_angle = pm.ap * r10inv*(pm.lj3*r2inv - pm.lj4) * - powint(c,pm.ap-1)*s; + force_kernel = r10inv*(pm.lj1*r2inv - pm.lj2)*r2inv * powint(c,pm.ap); + force_angle = pm.ap * r10inv*(pm.lj3*r2inv - pm.lj4) * powint(c,pm.ap-1)*s; + force_switch = 0.0; eng_lj = r10inv*(pm.lj3*r2inv - pm.lj4); - force_switch=0.0; - if (rsq > pm.cut_innersq) { switch1 = (pm.cut_outersq-rsq) * (pm.cut_outersq-rsq) * (pm.cut_outersq + 2.0*rsq - 3.0*pm.cut_innersq) / diff --git a/src/MOLECULE/pair_hbond_dreiding_morse.cpp b/src/MOLECULE/pair_hbond_dreiding_morse.cpp index 56f9c16442..8506765984 100644 --- a/src/MOLECULE/pair_hbond_dreiding_morse.cpp +++ b/src/MOLECULE/pair_hbond_dreiding_morse.cpp @@ -155,7 +155,6 @@ void PairHbondDreidingMorse::compute(int eflag, int vflag) if (c < -1.0) c = -1.0; } - if (ac > pm.cut_angle && ac < (2.0*MY_PI - pm.cut_angle)) { s = sqrt(1.0 - c*c); if (s < SMALL) s = SMALL; @@ -166,6 +165,7 @@ void PairHbondDreidingMorse::compute(int eflag, int vflag) dr = r - pm.r0; dexp = exp(-pm.alpha * dr); eng_morse = pm.d0 * (dexp*dexp - 2.0*dexp); + force_kernel = pm.morse1*(dexp*dexp - dexp)/r * powint(c,pm.ap); force_angle = pm.ap * eng_morse * powint(c,pm.ap-1)*s; force_switch = 0.0; @@ -204,12 +204,12 @@ void PairHbondDreidingMorse::compute(int eflag, int vflag) vz1 = a11*delr1[2] + a12*delr2[2]; vz2 = a22*delr2[2] + a12*delr1[2]; - fi[0] = vx1 + (b+d)*delx; - fi[1] = vy1 + (b+d)*dely; - fi[2] = vz1 + (b+d)*delz; - fj[0] = vx2 - (b+d)*delx; - fj[1] = vy2 - (b+d)*dely; - fj[2] = vz2 - (b+d)*delz; + fi[0] = vx1 + b*delx + d*delx; + fi[1] = vy1 + b*dely + d*dely; + fi[2] = vz1 + b*delz + d*delz; + fj[0] = vx2 - b*delx - d*delx; + fj[1] = vy2 - b*dely - d*dely; + fj[2] = vz2 - b*delz - d*delz; f[i][0] += fi[0]; f[i][1] += fi[1]; From 759a37cc75aa619f9bfd6f3522256a8078d50db0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 28 Jan 2025 21:33:03 -0500 Subject: [PATCH 55/70] update and synchronize with implementation of the non-OPENMP version --- src/OPENMP/pair_hbond_dreiding_lj_omp.cpp | 44 ++++++++++---------- src/OPENMP/pair_hbond_dreiding_morse_omp.cpp | 31 ++++++++------ 2 files changed, 41 insertions(+), 34 deletions(-) diff --git a/src/OPENMP/pair_hbond_dreiding_lj_omp.cpp b/src/OPENMP/pair_hbond_dreiding_lj_omp.cpp index 9bc5f5d254..60ec8938fe 100644 --- a/src/OPENMP/pair_hbond_dreiding_lj_omp.cpp +++ b/src/OPENMP/pair_hbond_dreiding_lj_omp.cpp @@ -120,15 +120,16 @@ void PairHbondDreidingLJOMP::eval(int iifrom, int iito, ThrData * const thr) int i,j,k,m,ii,jj,kk,jnum,knum,itype,jtype,ktype,iatom,imol; tagint tagprev; double xtmp,ytmp,ztmp,delx,dely,delz,rsq,rsq1,rsq2,r1,r2; - double factor_hb,force_angle,force_kernel,evdwl,eng_lj; - double c,s,a,b,ac,a11,a12,a22,vx1,vx2,vy1,vy2,vz1,vz2; + double factor_hb,force_angle,force_kernel,evdwl,eng_lj,ehbond,force_switch; + double c,s,a,b,d,ac,a11,a12,a22,vx1,vx2,vy1,vy2,vz1,vz2; double fi[3],fj[3],delr1[3],delr2[3]; double r2inv,r10inv; double switch1,switch2; int *ilist,*jlist,*numneigh,**firstneigh; const tagint *klist; - evdwl = 0.0; + evdwl = ehbond = 0.0; + int hbcount = 0; const auto * _noalias const x = (dbl3_t *) atom->x[0]; auto * _noalias const f = (dbl3_t *) thr->get_f()[0]; @@ -151,9 +152,6 @@ void PairHbondDreidingLJOMP::eval(int iifrom, int iito, ThrData * const thr) // jj = loop over acceptors // kk = loop over hydrogens bonded to donor - int hbcount = 0; - double hbeng = 0.0; - for (ii = iifrom; ii < iito; ++ii) { i = ilist[ii]; itype = type[i]; @@ -237,30 +235,34 @@ void PairHbondDreidingLJOMP::eval(int iifrom, int iito, ThrData * const thr) r2inv = 1.0/rsq; r10inv = r2inv*r2inv*r2inv*r2inv*r2inv; - force_kernel = r10inv*(pm.lj1*r2inv - pm.lj2)*r2inv * - powint(c,pm.ap); - force_angle = pm.ap * r10inv*(pm.lj3*r2inv - pm.lj4) * - powint(c,pm.ap-1)*s; + force_kernel = r10inv*(pm.lj1*r2inv - pm.lj2)*r2inv * powint(c,pm.ap); + force_angle = pm.ap * r10inv*(pm.lj3*r2inv - pm.lj4) * powint(c,pm.ap-1)*s; + force_switch = 0.0; eng_lj = r10inv*(pm.lj3*r2inv - pm.lj4); + if (rsq > pm.cut_innersq) { switch1 = (pm.cut_outersq-rsq) * (pm.cut_outersq-rsq) * (pm.cut_outersq + 2.0*rsq - 3.0*pm.cut_innersq) / pm.denom_vdw; switch2 = 12.0*rsq * (pm.cut_outersq-rsq) * (rsq-pm.cut_innersq) / pm.denom_vdw; - force_kernel = force_kernel*switch1 + eng_lj*switch2/rsq; - force_angle *= switch1; - eng_lj *= switch1; + + force_kernel *= switch1; + force_angle *= switch1; + force_switch = eng_lj*switch2/rsq; + eng_lj *= switch1; } if (EFLAG) { evdwl = eng_lj * powint(c,pm.ap); evdwl *= factor_hb; + ehbond += evdwl; } a = factor_hb*force_angle/s; b = factor_hb*force_kernel; + d = factor_hb*force_switch; a11 = a*c / rsq1; a12 = -a / (r1*r2); @@ -273,12 +275,12 @@ void PairHbondDreidingLJOMP::eval(int iifrom, int iito, ThrData * const thr) vz1 = a11*delr1[2] + a12*delr2[2]; vz2 = a22*delr2[2] + a12*delr1[2]; - fi[0] = vx1 + b*delx; - fi[1] = vy1 + b*dely; - fi[2] = vz1 + b*delz; - fj[0] = vx2 - b*delx; - fj[1] = vy2 - b*dely; - fj[2] = vz2 - b*delz; + fi[0] = vx1 + b*delx + d*delx; + fi[1] = vy1 + b*dely + d*dely; + fi[2] = vz1 + b*delz + d*delz; + fj[0] = vx2 - b*delx - d*delx; + fj[1] = vy2 - b*dely - d*dely; + fj[2] = vz2 - b*delz - d*delz; fxtmp += fi[0]; fytmp += fi[1]; @@ -297,7 +299,7 @@ void PairHbondDreidingLJOMP::eval(int iifrom, int iito, ThrData * const thr) if (EVFLAG) ev_tally3_thr(this,k,i,j,evdwl,0.0,fi,fj,delr1,delr2,thr); if (EFLAG) { hbcount++; - hbeng += evdwl; + ehbond += evdwl; } } } @@ -309,7 +311,7 @@ void PairHbondDreidingLJOMP::eval(int iifrom, int iito, ThrData * const thr) } const int tid = thr->get_tid(); hbcount_thr[tid] = static_cast(hbcount); - hbeng_thr[tid] = hbeng; + hbeng_thr[tid] = ehbond; } /* ---------------------------------------------------------------------- */ diff --git a/src/OPENMP/pair_hbond_dreiding_morse_omp.cpp b/src/OPENMP/pair_hbond_dreiding_morse_omp.cpp index bb0970dbdc..7772ea69fa 100644 --- a/src/OPENMP/pair_hbond_dreiding_morse_omp.cpp +++ b/src/OPENMP/pair_hbond_dreiding_morse_omp.cpp @@ -120,14 +120,14 @@ void PairHbondDreidingMorseOMP::eval(int iifrom, int iito, ThrData * const thr) int i,j,k,m,ii,jj,kk,jnum,knum,itype,jtype,ktype,imol,iatom; tagint tagprev; double xtmp,ytmp,ztmp,delx,dely,delz,rsq,rsq1,rsq2,r1,r2; - double factor_hb,force_angle,force_kernel,evdwl; - double c,s,a,b,ac,a11,a12,a22,vx1,vx2,vy1,vy2,vz1,vz2; + double factor_hb,force_angle,force_kernel,force_switch,evdwl,ehbond; + double c,s,a,b,d,ac,a11,a12,a22,vx1,vx2,vy1,vy2,vz1,vz2; double fi[3],fj[3],delr1[3],delr2[3]; double r,dr,dexp,eng_morse,switch1,switch2; int *ilist,*jlist,*numneigh,**firstneigh; const tagint *klist; - evdwl = 0.0; + evdwl = ehbond = 0.0; const auto * _noalias const x = (dbl3_t *) atom->x[0]; auto * _noalias const f = (dbl3_t *) thr->get_f()[0]; @@ -151,7 +151,6 @@ void PairHbondDreidingMorseOMP::eval(int iifrom, int iito, ThrData * const thr) // kk = loop over hydrogens bonded to donor int hbcount = 0; - double hbeng = 0.0; for (ii = iifrom; ii < iito; ++ii) { @@ -239,8 +238,10 @@ void PairHbondDreidingMorseOMP::eval(int iifrom, int iito, ThrData * const thr) dr = r - pm.r0; dexp = exp(-pm.alpha * dr); eng_morse = pm.d0 * (dexp*dexp - 2.0*dexp); + force_kernel = pm.morse1*(dexp*dexp - dexp)/r * powint(c,pm.ap); force_angle = pm.ap * eng_morse * powint(c,pm.ap-1)*s; + force_switch = 0.0; if (rsq > pm.cut_innersq) { switch1 = (pm.cut_outersq-rsq) * (pm.cut_outersq-rsq) * @@ -248,18 +249,22 @@ void PairHbondDreidingMorseOMP::eval(int iifrom, int iito, ThrData * const thr) pm.denom_vdw; switch2 = 12.0*rsq * (pm.cut_outersq-rsq) * (rsq-pm.cut_innersq) / pm.denom_vdw; - force_kernel = force_kernel*switch1 + eng_morse*switch2/rsq; + + force_kernel *= switch1; force_angle *= switch1; + force_switch = eng_morse*switch2/rsq; eng_morse *= switch1; } if (EFLAG) { evdwl = eng_morse * powint(c,pm.ap); evdwl *= factor_hb; + ehbond += evdwl; } a = factor_hb*force_angle/s; b = factor_hb*force_kernel; + d = factor_hb*force_switch; a11 = a*c / rsq1; a12 = -a / (r1*r2); @@ -272,12 +277,12 @@ void PairHbondDreidingMorseOMP::eval(int iifrom, int iito, ThrData * const thr) vz1 = a11*delr1[2] + a12*delr2[2]; vz2 = a22*delr2[2] + a12*delr1[2]; - fi[0] = vx1 + b*delx; - fi[1] = vy1 + b*dely; - fi[2] = vz1 + b*delz; - fj[0] = vx2 - b*delx; - fj[1] = vy2 - b*dely; - fj[2] = vz2 - b*delz; + fi[0] = vx1 + b*delx + d*delx; + fi[1] = vy1 + b*dely + d*dely; + fi[2] = vz1 + b*delz + d*delz; + fj[0] = vx2 - b*delx - d*delx; + fj[1] = vy2 - b*dely - d*dely; + fj[2] = vz2 - b*delz - d*delz; fxtmp += fi[0]; fytmp += fi[1]; @@ -296,7 +301,7 @@ void PairHbondDreidingMorseOMP::eval(int iifrom, int iito, ThrData * const thr) if (EVFLAG) ev_tally3_thr(this,k,i,j,evdwl,0.0,fi,fj,delr1,delr2,thr); if (EFLAG) { hbcount++; - hbeng += evdwl; + ehbond += evdwl; } } } @@ -308,7 +313,7 @@ void PairHbondDreidingMorseOMP::eval(int iifrom, int iito, ThrData * const thr) } const int tid = thr->get_tid(); hbcount_thr[tid] = static_cast(hbcount); - hbeng_thr[tid] = hbeng; + hbeng_thr[tid] = ehbond; } /* ---------------------------------------------------------------------- */ From 201d1a59b5cc7550c9ff3b768473a78f66c1fb1f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 28 Jan 2025 21:33:44 -0500 Subject: [PATCH 56/70] the /angleoffset versions have their own different parameter file and reader --- ...pair_hbond_dreiding_lj_angleoffset_omp.cpp | 85 +++++++++++++++++- .../pair_hbond_dreiding_lj_angleoffset_omp.h | 1 + ...r_hbond_dreiding_morse_angleoffset_omp.cpp | 86 ++++++++++++++++++- ...air_hbond_dreiding_morse_angleoffset_omp.h | 2 +- 4 files changed, 171 insertions(+), 3 deletions(-) diff --git a/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.cpp b/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.cpp index 1a5126971a..11c09ed549 100644 --- a/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.cpp +++ b/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.cpp @@ -22,6 +22,7 @@ #include "force.h" #include "math_const.h" #include "math_special.h" +#include "memory.h" #include "molecule.h" #include "neigh_list.h" #include "suffix.h" @@ -33,7 +34,7 @@ using namespace LAMMPS_NS; using namespace MathConst; using namespace MathSpecial; -static constexpr double SMALL = 0.001; +static constexpr int CHUNK = 8; /* ---------------------------------------------------------------------- */ @@ -42,3 +43,85 @@ PairHbondDreidingLJAngleoffsetOMP::PairHbondDreidingLJAngleoffsetOMP(LAMMPS *lmp angle_offset_flag = 1; } +/* ---------------------------------------------------------------------- + set coeffs for one or more type pairs +------------------------------------------------------------------------- */ + +void PairHbondDreidingLJAngleoffsetOMP::coeff(int narg, char **arg) +{ + auto mylmp = PairHbondDreidingLJ::lmp; + if (narg < 6 || narg > 11) + error->all(FLERR,"Incorrect args for pair coefficients"); + if (!allocated) allocate(); + + int ilo,ihi,jlo,jhi,klo,khi; + utils::bounds(FLERR, arg[0], 1, atom->ntypes, ilo, ihi, error); + utils::bounds(FLERR, arg[1], 1, atom->ntypes, jlo, jhi, error); + utils::bounds_typelabel(FLERR, arg[2], 1, atom->ntypes, klo, khi, mylmp, Atom::ATOM); + + int donor_flag; + if (strcmp(arg[3],"i") == 0) donor_flag = 0; + else if (strcmp(arg[3],"j") == 0) donor_flag = 1; + else error->all(FLERR,"Incorrect args for pair coefficients"); + + double epsilon_one = utils::numeric(FLERR, arg[4], false, mylmp); + double sigma_one = utils::numeric(FLERR, arg[5], false, mylmp); + + int ap_one = ap_global; + if (narg > 6) ap_one = utils::inumeric(FLERR, arg[6], false, mylmp); + double cut_inner_one = cut_inner_global; + double cut_outer_one = cut_outer_global; + if (narg > 8) { + cut_inner_one = utils::numeric(FLERR, arg[7], false, mylmp); + cut_outer_one = utils::numeric(FLERR, arg[8], false, mylmp); + } + if (cut_inner_one>cut_outer_one) + error->all(FLERR,"Pair inner cutoff >= Pair outer cutoff"); + double cut_angle_one = cut_angle_global; + if (narg > 9) cut_angle_one = utils::numeric(FLERR, arg[9], false, mylmp) * MY_PI/180.0; + double angle_offset_one = angle_offset_global; + if (narg == 11) angle_offset_one = (180.0 - utils::numeric(FLERR, arg[10], false, mylmp)) * MY_PI/180.0; + if (angle_offset_one < 0.0 || angle_offset_one > 90.0 * MY_PI/180.0) + error->all(FLERR,"Illegal angle offset"); + + // grow params array if necessary + + if (nparams == maxparam) { + maxparam += CHUNK; + params = (Param *) memory->srealloc(params, maxparam*sizeof(Param), + "pair:params"); + + // make certain all addional allocated storage is initialized + // to avoid false positives when checking with valgrind + + memset(params + nparams, 0, CHUNK*sizeof(Param)); + } + + params[nparams].epsilon = epsilon_one; + params[nparams].sigma = sigma_one; + params[nparams].ap = ap_one; + params[nparams].cut_inner = cut_inner_one; + params[nparams].cut_outer = cut_outer_one; + params[nparams].cut_innersq = cut_inner_one*cut_inner_one; + params[nparams].cut_outersq = cut_outer_one*cut_outer_one; + params[nparams].cut_angle = cut_angle_one; + params[nparams].angle_offset = angle_offset_one; + params[nparams].denom_vdw = + (params[nparams].cut_outersq-params[nparams].cut_innersq) * + (params[nparams].cut_outersq-params[nparams].cut_innersq) * + (params[nparams].cut_outersq-params[nparams].cut_innersq); + + // flag type2param with either i,j = D,A or j,i = D,A + + int count = 0; + for (int i = ilo; i <= ihi; i++) + for (int j = MAX(jlo,i); j <= jhi; j++) + for (int k = klo; k <= khi; k++) { + if (donor_flag == 0) type2param[i][j][k] = nparams; + else type2param[j][i][k] = nparams; + count++; + } + nparams++; + + if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); +} diff --git a/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.h b/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.h index ce79a03dee..03d3392e4d 100644 --- a/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.h +++ b/src/OPENMP/pair_hbond_dreiding_lj_angleoffset_omp.h @@ -32,6 +32,7 @@ class PairHbondDreidingLJAngleoffsetOMP : public PairHbondDreidingLJOMP { public: PairHbondDreidingLJAngleoffsetOMP(class LAMMPS *); + void coeff(int, char **) override; }; } // namespace LAMMPS_NS diff --git a/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.cpp b/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.cpp index b0f9cde92f..e7c75f29e4 100644 --- a/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.cpp +++ b/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.cpp @@ -22,6 +22,7 @@ #include "force.h" #include "math_const.h" #include "math_special.h" +#include "memory.h" #include "molecule.h" #include "neigh_list.h" #include "suffix.h" @@ -33,7 +34,7 @@ using namespace LAMMPS_NS; using namespace MathConst; using namespace MathSpecial; -static constexpr double SMALL = 0.001; +static constexpr int CHUNK = 8; /* ---------------------------------------------------------------------- */ @@ -41,3 +42,86 @@ PairHbondDreidingMorseAngleoffsetOMP::PairHbondDreidingMorseAngleoffsetOMP(LAMMP PairHbondDreidingMorseOMP(lmp) { angle_offset_flag = 1; } + +/* ---------------------------------------------------------------------- + * set coeffs for one or more type pairs + * ---------------------------------------------------------------------- */ + +void PairHbondDreidingMorseAngleoffsetOMP::coeff(int narg, char **arg) +{ + auto mylmp = PairHbondDreidingMorse::lmp; + if (narg < 7 || narg > 12) + error->all(FLERR,"Incorrect args for pair coefficients"); + if (!allocated) allocate(); + + int ilo,ihi,jlo,jhi,klo,khi; + utils::bounds(FLERR, arg[0], 1, atom->ntypes, ilo, ihi, error); + utils::bounds(FLERR, arg[1], 1, atom->ntypes, jlo, jhi, error); + utils::bounds_typelabel(FLERR, arg[2], 1, atom->ntypes, klo, khi, mylmp, Atom::ATOM); + + int donor_flag; + if (strcmp(arg[3],"i") == 0) donor_flag = 0; + else if (strcmp(arg[3],"j") == 0) donor_flag = 1; + else error->all(FLERR,"Incorrect args for pair coefficients"); + + double d0_one = utils::numeric(FLERR, arg[4], false, mylmp); + double alpha_one = utils::numeric(FLERR, arg[5], false, mylmp); + double r0_one = utils::numeric(FLERR, arg[6], false, mylmp); + + int ap_one = ap_global; + if (narg > 7) ap_one = utils::inumeric(FLERR, arg[7], false, mylmp); + double cut_inner_one = cut_inner_global; + double cut_outer_one = cut_outer_global; + if (narg > 9) { + cut_inner_one = utils::numeric(FLERR, arg[8], false, mylmp); + cut_outer_one = utils::numeric(FLERR, arg[9], false, mylmp); + } + if (cut_inner_one>cut_outer_one) + error->all(FLERR,"Pair inner cutoff >= Pair outer cutoff"); + double cut_angle_one = cut_angle_global; + if (narg > 10) cut_angle_one = utils::numeric(FLERR, arg[10], false, mylmp) * MY_PI/180.0; + double angle_offset_one = angle_offset_global; + if (narg == 12) angle_offset_one = (180.0 - utils::numeric(FLERR, arg[11], false, mylmp)) * MY_PI/180.0; + if (angle_offset_one < 0.0 || angle_offset_one > 90.0 * MY_PI/180.0) + error->all(FLERR,"Illegal angle offset {}", angle_offset_one); + + // grow params array if necessary + + if (nparams == maxparam) { + maxparam += CHUNK; + params = (Param *) memory->srealloc(params, maxparam*sizeof(Param),"pair:params"); + + // make certain all addional allocated storage is initialized + // to avoid false positives when checking with valgrind + + memset(params + nparams, 0, CHUNK*sizeof(Param)); + } + + params[nparams].d0 = d0_one; + params[nparams].alpha = alpha_one; + params[nparams].r0 = r0_one; + params[nparams].ap = ap_one; + params[nparams].cut_inner = cut_inner_one; + params[nparams].cut_outer = cut_outer_one; + params[nparams].cut_innersq = cut_inner_one*cut_inner_one; + params[nparams].cut_outersq = cut_outer_one*cut_outer_one; + params[nparams].cut_angle = cut_angle_one; + params[nparams].angle_offset = angle_offset_one; + params[nparams].denom_vdw = (params[nparams].cut_outersq-params[nparams].cut_innersq) * + (params[nparams].cut_outersq-params[nparams].cut_innersq) * + (params[nparams].cut_outersq-params[nparams].cut_innersq); + + // flag type2param with either i,j = D,A or j,i = D,A + + int count = 0; + for (int i = ilo; i <= ihi; i++) + for (int j = MAX(jlo,i); j <= jhi; j++) + for (int k = klo; k <= khi; k++) { + if (donor_flag == 0) type2param[i][j][k] = nparams; + else type2param[j][i][k] = nparams; + count++; + } + nparams++; + + if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); +} diff --git a/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.h b/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.h index 2808ed1e68..94b6131f98 100644 --- a/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.h +++ b/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.h @@ -33,7 +33,7 @@ class PairHbondDreidingMorseAngleoffsetOMP : public: PairHbondDreidingMorseAngleoffsetOMP(class LAMMPS *); - + void coeff(int, char **) override; }; } // namespace LAMMPS_NS From 229916e11fdb855c8940fd79d5943fad249dc3d8 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 28 Jan 2025 21:35:11 -0500 Subject: [PATCH 57/70] whitespace --- src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h | 2 +- src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h index 5eeb1796a2..20d2a8698d 100644 --- a/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h +++ b/src/EXTRA-MOLECULE/pair_hbond_dreiding_morse_angleoffset.h @@ -29,7 +29,7 @@ class PairHbondDreidingMorseAngleoffset : public PairHbondDreidingMorse { public: PairHbondDreidingMorseAngleoffset(class LAMMPS *); void coeff(int, char **) override; - + }; } // namespace LAMMPS_NS diff --git a/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.h b/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.h index 94b6131f98..40a797ac33 100644 --- a/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.h +++ b/src/OPENMP/pair_hbond_dreiding_morse_angleoffset_omp.h @@ -33,7 +33,7 @@ class PairHbondDreidingMorseAngleoffsetOMP : public: PairHbondDreidingMorseAngleoffsetOMP(class LAMMPS *); - void coeff(int, char **) override; + void coeff(int, char **) override; }; } // namespace LAMMPS_NS From ff340cf409b34bdec8454463621480d1a8c7f8ce Mon Sep 17 00:00:00 2001 From: jtclemm Date: Wed, 29 Jan 2025 13:09:49 -0700 Subject: [PATCH 58/70] Repairing srp wildcard logic --- src/MISC/pair_srp.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/MISC/pair_srp.cpp b/src/MISC/pair_srp.cpp index 8decae5aca..1fe19bc30c 100644 --- a/src/MISC/pair_srp.cpp +++ b/src/MISC/pair_srp.cpp @@ -397,10 +397,11 @@ void PairSRP::coeff(int narg, char **arg) error->all(FLERR,"PairSRP: Incorrect args for pair coeff"); if (!allocated) allocate(); - if (btype_str.size() > 0) + if (btype_str.size() > 0) { btype = utils::expand_type_int(FLERR, btype_str, Atom::BOND, lmp); - if ((btype > atom->nbondtypes) || (btype <= 0)) - error->all(FLERR,"Invalid bond type {} for pair style srp", btype); + if ((btype > atom->nbondtypes) || (btype <= 0)) + error->all(FLERR,"Invalid bond type {} for pair style srp", btype); + } if (bptype_str.size() > 0) bptype = utils::expand_type_int(FLERR, bptype_str, Atom::ATOM, lmp); From d638f66b68d169259098f188f8b06d751c2f660f Mon Sep 17 00:00:00 2001 From: jtclemm Date: Wed, 29 Jan 2025 13:29:15 -0700 Subject: [PATCH 59/70] updating to match new 1d syntax --- examples/PACKAGES/stressprofile/in.flat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/PACKAGES/stressprofile/in.flat b/examples/PACKAGES/stressprofile/in.flat index 8b484a423f..a0aea07d83 100644 --- a/examples/PACKAGES/stressprofile/in.flat +++ b/examples/PACKAGES/stressprofile/in.flat @@ -32,7 +32,7 @@ fix 1 all nvt temp 0.7 0.7 0.2 #dump_modify 3 pad 3 fix 2 all recenter NULL NULL 15 units lattice -compute p1 all stress/cartesian z 0.5 +compute p1 all stress/cartesian z 0.5 NULL 0 fix 3 all ave/time 100 1 100 c_p1[*] file flat.out mode vector thermo 50 From b4eee0c27a0c8d94ff5bdf2bf497c97b5ad3dee8 Mon Sep 17 00:00:00 2001 From: jtclemm Date: Wed, 29 Jan 2025 13:58:47 -0700 Subject: [PATCH 60/70] Marking scalar intensive in elec/stop/fit fix --- src/EXTRA-FIX/fix_electron_stopping_fit.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/EXTRA-FIX/fix_electron_stopping_fit.cpp b/src/EXTRA-FIX/fix_electron_stopping_fit.cpp index 2657ddc85f..c9cca2679d 100644 --- a/src/EXTRA-FIX/fix_electron_stopping_fit.cpp +++ b/src/EXTRA-FIX/fix_electron_stopping_fit.cpp @@ -68,7 +68,8 @@ FixElectronStoppingFit::FixElectronStoppingFit(LAMMPS *lmp, int narg, char **arg error->all(FLERR,"Incorrect number of fix electron/stopping/fit arguments"); } - scalar_flag = 1; + scalar_flag = 1; // intensive total energy loss since start of run + extscalar = 0; global_freq = 1; energy_coh_in = new double[atom->ntypes+1]; From f5a80196549860d6f63ca99eb8ec2af00dfb3f2d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 29 Jan 2025 16:39:53 -0500 Subject: [PATCH 61/70] spelling fixes and updates for the manual --- doc/src/Build_basics.rst | 4 ++-- doc/src/fix_wall_gran.rst | 8 ++++---- doc/src/fix_wall_gran_region.rst | 8 ++++---- doc/src/pair_granular.rst | 15 ++++++++------- doc/utils/sphinx-config/false_positives.txt | 4 ++++ 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/doc/src/Build_basics.rst b/doc/src/Build_basics.rst index 761c743e2a..be4b312578 100644 --- a/doc/src/Build_basics.rst +++ b/doc/src/Build_basics.rst @@ -203,7 +203,7 @@ LAMMPS. check if the detected or selected compiler is compatible with the C++ support requirements of LAMMPS and stop with an error, if this is not the case. A C++11 compatible compiler is currently - required, but a transition to require C++17 is in progess and + required, but a transition to require C++17 is in progress and planned to be completed in Summer 2025. Currently, setting ``-DLAMMPS_CXX11=yes`` is required when configuring with CMake while using a C++11 compatible compiler that does not support C++17, @@ -329,7 +329,7 @@ LAMMPS. either as a binary package or through compiling from source. While a C++11 compatible compiler is currently sufficient to compile - LAMMPS, a transition to require C++17 is in progess and planned to + LAMMPS, a transition to require C++17 is in progress and planned to be completed in Summer 2025. Currently, setting ``-DLAMMPS_CXX11`` in the ``LMP_INC =`` line in the machine makefile is required when using a C++11 compatible compiler that does not support C++17. diff --git a/doc/src/fix_wall_gran.rst b/doc/src/fix_wall_gran.rst index 0d864cce88..81a411ffc8 100644 --- a/doc/src/fix_wall_gran.rst +++ b/doc/src/fix_wall_gran.rst @@ -248,11 +248,11 @@ listed in the following table. | 8 | Radius :math:`r` of atom | distance units | +-------+----------------------------------------------------+----------------+ -If a granular submodel calculates additional contact information (e.g. the -heat submodels calculate the amount of heat exchanged), these quantities +If a granular sub-model calculates additional contact information (e.g. the +heat sub-models calculate the amount of heat exchanged), these quantities are appended to the end of this array. First, any extra values from the -normal submodel are appended followed by the damping, tangential, rolling, -twisting, then heat models. See the descriptions of granular submodels in +normal sub-model are appended followed by the damping, tangential, rolling, +twisting, then heat models. See the descriptions of granular sub-models in the :doc:`pair granular ` page for information on any extra quantities. diff --git a/doc/src/fix_wall_gran_region.rst b/doc/src/fix_wall_gran_region.rst index 0e5e98f1a8..4ad3b9d6c5 100644 --- a/doc/src/fix_wall_gran_region.rst +++ b/doc/src/fix_wall_gran_region.rst @@ -269,11 +269,11 @@ listed in the following table. | 8 | Radius :math:`r` of atom | distance units | +-------+----------------------------------------------------+----------------+ -If a granular submodel calculates additional contact information (e.g. the -heat submodels calculate the amount of heat exchanged), these quantities +If a granular sub-model calculates additional contact information (e.g. the +heat sub-models calculate the amount of heat exchanged), these quantities are appended to the end of this array. First, any extra values from the -normal submodel are appended followed by the damping, tangential, rolling, -twisting, then heat models. See the descriptions of granular submodels in +normal sub-model are appended followed by the damping, tangential, rolling, +twisting, then heat models. See the descriptions of granular sub-models in the :doc:`pair granular ` page for information on any extra quantities. diff --git a/doc/src/pair_granular.rst b/doc/src/pair_granular.rst index 0a44ccb197..db5e7410b4 100644 --- a/doc/src/pair_granular.rst +++ b/doc/src/pair_granular.rst @@ -258,7 +258,7 @@ in damping model. The definition of multiple *mdr* models in the *pair_style* is currently not supported. Similarly, the *mdr* model cannot be combined with a different normal -model in the *pair_style*. Physically this means that only one homogenous +model in the *pair_style*. Physically this means that only one homogeneous collection of particles governed by a single *mdr* model is allowed. The *mdr* model currently only supports *fix wall/gran/region*, not @@ -303,6 +303,7 @@ radius in the *mdr* model, the keyword/arg pair *cutoff radius* must be specifie simulation involving 200 particles named *in.tableting.200*. The second is a triaxial compaction simulation involving 12 particles named *in.triaxial.compaction.12*. + ---------- In addition, the normal force is augmented by a damping term of the @@ -941,16 +942,16 @@ particle I. The next entry (8) is the magnitude of the rolling torque. The next entry (9) is the magnitude of the twisting torque acting about the vector connecting the two particle centers. The next 3 (10-12) are the components of the vector connecting -the centers of the two particles (x_I - x_J). If a granular submodel -calculates additional contact information (e.g. the heat submodels +the centers of the two particles (x_I - x_J). If a granular sub-model +calculates additional contact information (e.g. the heat sub-models calculate the amount of heat exchanged), these quantities are appended -to the end of this list. First, any extra values from the normal submodel +to the end of this list. First, any extra values from the normal sub-model are appended followed by the damping, tangential, rolling, twisting, then -heat models. See the descriptions of specific granular submodels above +heat models. See the descriptions of specific granular sub-models above for information on any extra quantities. If two or more models are defined by pair coefficients, the size of the array is set by the maximum number of extra quantities in a model but the order of quantities -is determined by each model's specific set of submodels. Any unused +is determined by each model's specific set of sub-models. Any unused quantities are zeroed. These extra quantities can be accessed by the :doc:`compute pair/local ` command, as *p1*, *p2*, ..., @@ -1046,7 +1047,7 @@ a bulk elastic response. Journal of the Mechanics and Physics of Solids, **(Zunker et al, 2025)** Zunker, W., Dunatunga, S., Thakur, S., Tang, P., & Kamrin, K. (2025). Experimentally validated DEM for large deformation powder compaction: mechanically-derived contact model and -screening of non-physical contacts. engrXiv. +screening of non-physical contacts. .. _Luding2008: diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index 6746d591c6..4bab2b1a95 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -1583,6 +1583,7 @@ Impropers imulator includelink incompressible +incompressibility incrementing indenter indenters @@ -1762,6 +1763,7 @@ Kadiri Kai Kalia Kamberaj +Kamrin Kantorovich Kapfer Kapil @@ -3731,6 +3733,7 @@ tgnpt tgnvt th Thakkar +Thakur Thaokar thb thei @@ -3831,6 +3834,7 @@ Tref Tretyakov tri triangleflag +triaxial Tribello triclinic Triclinic From 29891e06c0dfd38d55a8b8b2b0c4b98261c89fb1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 29 Jan 2025 20:52:34 -0500 Subject: [PATCH 62/70] correct dependency for efield/lepton tests --- unittest/force-styles/tests/fix-timestep-efield_lepton.yaml | 2 +- .../force-styles/tests/fix-timestep-efield_lepton_region.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/unittest/force-styles/tests/fix-timestep-efield_lepton.yaml b/unittest/force-styles/tests/fix-timestep-efield_lepton.yaml index c6f80af274..7928c81c45 100644 --- a/unittest/force-styles/tests/fix-timestep-efield_lepton.yaml +++ b/unittest/force-styles/tests/fix-timestep-efield_lepton.yaml @@ -6,7 +6,7 @@ epsilon: 2e-13 skip_tests: prerequisites: ! | atom full - fix efield + fix efield/lepton pre_commands: ! "" post_commands: ! | region half block 0 EDGE EDGE EDGE EDGE EDGE diff --git a/unittest/force-styles/tests/fix-timestep-efield_lepton_region.yaml b/unittest/force-styles/tests/fix-timestep-efield_lepton_region.yaml index b2275f047b..f0a6b121a4 100644 --- a/unittest/force-styles/tests/fix-timestep-efield_lepton_region.yaml +++ b/unittest/force-styles/tests/fix-timestep-efield_lepton_region.yaml @@ -6,7 +6,7 @@ epsilon: 2e-13 skip_tests: prerequisites: ! | atom full - fix efield + fix efield/lepton pre_commands: ! "" post_commands: ! | region half block 0 EDGE EDGE EDGE EDGE EDGE From 06bdb7b637f4ce38e07f6b7bbd246f2beabea4d0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 29 Jan 2025 23:09:48 -0500 Subject: [PATCH 63/70] refactor catching exceptions during LAMMPS initialization this will avoid the nasty segfaults with "cannot have multiple stdout capturers" instead it will catch and display any exception thrown during init. --- unittest/force-styles/test_angle_style.cpp | 105 +++++++++---- unittest/force-styles/test_bond_style.cpp | 106 ++++++++++---- unittest/force-styles/test_dihedral_style.cpp | 74 ++++++++-- unittest/force-styles/test_fix_timestep.cpp | 71 +++++++-- unittest/force-styles/test_improper_style.cpp | 89 +++++++---- unittest/force-styles/test_pair_style.cpp | 138 +++++++++++++----- 6 files changed, 425 insertions(+), 158 deletions(-) diff --git a/unittest/force-styles/test_angle_style.cpp b/unittest/force-styles/test_angle_style.cpp index ebd8170b7c..80601d3632 100644 --- a/unittest/force-styles/test_angle_style.cpp +++ b/unittest/force-styles/test_angle_style.cpp @@ -61,7 +61,7 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) delete lmp; } -LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton = true) +LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton) { LAMMPS *lmp; @@ -92,21 +92,7 @@ LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton // utility lambdas to improve readability auto command = [&](const std::string &line) { - try { - lmp->input->one(line); - } catch (LAMMPSAbortException &ae) { - fprintf(stderr, "LAMMPS Error: %s\n", ae.what()); - exit(2); - } catch (LAMMPSException &e) { - fprintf(stderr, "LAMMPS Error: %s\n", e.what()); - exit(3); - } catch (fmt::format_error &fe) { - fprintf(stderr, "fmt::format_error: %s\n", fe.what()); - exit(4); - } catch (std::exception &e) { - fprintf(stderr, "General exception: %s\n", e.what()); - exit(5); - } + lmp->input->one(line); }; auto parse_input_script = [&](const std::string &filename) { lmp->input->file(filename.c_str()); @@ -230,7 +216,12 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // initialize system geometry LAMMPS::argv args = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; - LAMMPS *lmp = init_lammps(args, config); + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, config, true); + } catch (std::exception &e) { + FAIL() << e.what(); + } if (!lmp) { std::cerr << "One or more prerequisite styles are not available " "in this LAMMPS configuration:\n"; @@ -321,8 +312,14 @@ TEST(AngleStyle, plain) LAMMPS::argv args = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config, true); - + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -371,7 +368,12 @@ TEST(AngleStyle, plain) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(args, test_config, false); + try { + lmp = init_lammps(args, test_config, false); + } catch (std::exception &e) { + if (!verbose) ::testing::internal::GetCapturedStdout(); + FAIL() << e.what(); + } if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton bond is forced to be on @@ -439,8 +441,14 @@ TEST(AngleStyle, omp) "-pk", "omp", "4", "-sf", "omp"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config, true); - + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -493,7 +501,12 @@ TEST(AngleStyle, omp) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(args, test_config, false); + try { + lmp = init_lammps(args, test_config, false); + } catch (std::exception &e) { + if (!verbose) ::testing::internal::GetCapturedStdout(); + FAIL() << e.what(); + } if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton bond is forced to be on @@ -540,14 +553,21 @@ TEST(AngleStyle, kokkos_omp) // if KOKKOS has GPU support enabled, it *must* be used. We cannot test OpenMP only. if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") || Info::has_accelerator_feature("KOKKOS", "api", "hip") || - Info::has_accelerator_feature("KOKKOS", "api", "sycl")) GTEST_SKIP(); + Info::has_accelerator_feature("KOKKOS", "api", "sycl")) + GTEST_SKIP() << "Cannot test KOKKOS/OpenMP with GPU support enabled"; LAMMPS::argv args = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite", "-k", "on", "t", "4", "-sf", "kk"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config, true); - + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -597,7 +617,12 @@ TEST(AngleStyle, kokkos_omp) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(args, test_config, false); + try { + lmp = init_lammps(args, test_config, false); + } catch (std::exception &e) { + if (!verbose) ::testing::internal::GetCapturedStdout(); + FAIL() << e.what(); + } if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton bond is forced to be on @@ -664,8 +689,14 @@ TEST(AngleStyle, numdiff) LAMMPS::argv args = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config, true); - + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -717,7 +748,13 @@ TEST(AngleStyle, single) // create a LAMMPS instance with standard settings to detect the number of atom types if (!verbose) ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config); + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + if (!verbose) ::testing::internal::GetCapturedStdout(); + FAIL() << e.what(); + } if (!verbose) ::testing::internal::GetCapturedStdout(); if (!lmp) { @@ -865,7 +902,13 @@ TEST(AngleStyle, extract) LAMMPS::argv args = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; if (!verbose) ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config, true); + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + if (!verbose) ::testing::internal::GetCapturedStdout(); + FAIL() << e.what(); + } if (!verbose) ::testing::internal::GetCapturedStdout(); if (!lmp) { diff --git a/unittest/force-styles/test_bond_style.cpp b/unittest/force-styles/test_bond_style.cpp index 4a3a985ffc..6c680feaa3 100644 --- a/unittest/force-styles/test_bond_style.cpp +++ b/unittest/force-styles/test_bond_style.cpp @@ -61,7 +61,7 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) delete lmp; } -LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton = true) +LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton) { LAMMPS *lmp; @@ -92,21 +92,7 @@ LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton // utility lambdas to improve readability auto command = [&](const std::string &line) { - try { - lmp->input->one(line); - } catch (LAMMPSAbortException &ae) { - fprintf(stderr, "LAMMPS Error: %s\n", ae.what()); - exit(2); - } catch (LAMMPSException &e) { - fprintf(stderr, "LAMMPS Error: %s\n", e.what()); - exit(3); - } catch (fmt::format_error &fe) { - fprintf(stderr, "fmt::format_error: %s\n", fe.what()); - exit(4); - } catch (std::exception &e) { - fprintf(stderr, "General exception: %s\n", e.what()); - exit(5); - } + lmp->input->one(line); }; auto parse_input_script = [&](const std::string &filename) { lmp->input->file(filename.c_str()); @@ -230,7 +216,13 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // initialize system geometry LAMMPS::argv args = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; - LAMMPS *lmp = init_lammps(args, config); + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, config, true); + } catch (std::exception &e) { + FAIL() << e.what(); + } + if (!lmp) { std::cerr << "One or more prerequisite styles are not available " "in this LAMMPS configuration:\n"; @@ -321,8 +313,14 @@ TEST(BondStyle, plain) LAMMPS::argv args = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config, true); - + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -371,7 +369,12 @@ TEST(BondStyle, plain) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(args, test_config, false); + try { + lmp = init_lammps(args, test_config, false); + } catch (std::exception &e) { + if (!verbose) ::testing::internal::GetCapturedStdout(); + FAIL() << e.what(); + } if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton bond is forced to be on @@ -441,8 +444,14 @@ TEST(BondStyle, omp) "-pk", "omp", "4", "-sf", "omp"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config, true); - + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -495,7 +504,12 @@ TEST(BondStyle, omp) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(args, test_config, false); + try { + lmp = init_lammps(args, test_config, false); + } catch (std::exception &e) { + if (!verbose) ::testing::internal::GetCapturedStdout(); + FAIL() << e.what(); + } if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton bond is forced to be on @@ -542,14 +556,21 @@ TEST(BondStyle, kokkos_omp) // if KOKKOS has GPU support enabled, it *must* be used. We cannot test OpenMP only. if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") || Info::has_accelerator_feature("KOKKOS", "api", "hip") || - Info::has_accelerator_feature("KOKKOS", "api", "sycl")) GTEST_SKIP(); + Info::has_accelerator_feature("KOKKOS", "api", "sycl")) + GTEST_SKIP() << "Cannot test KOKKOS/OpenMP with GPU support enabled"; LAMMPS::argv args = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite", "-k", "on", "t", "4", "-sf", "kk"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config, true); - + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -603,7 +624,12 @@ TEST(BondStyle, kokkos_omp) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(args, test_config, false); + try { + lmp = init_lammps(args, test_config, false); + } catch (std::exception &e) { + if (!verbose) ::testing::internal::GetCapturedStdout(); + FAIL() << e.what(); + } if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton bond is forced to be on @@ -652,8 +678,14 @@ TEST(BondStyle, numdiff) LAMMPS::argv args = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config, true); - + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -705,7 +737,13 @@ TEST(BondStyle, single) // create a LAMMPS instance with standard settings to detect the number of atom types if (!verbose) ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config); + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + if (!verbose) ::testing::internal::GetCapturedStdout(); + FAIL() << e.what(); + } if (!verbose) ::testing::internal::GetCapturedStdout(); if (!lmp) { @@ -959,7 +997,13 @@ TEST(BondStyle, extract) LAMMPS::argv args = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; if (!verbose) ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config, true); + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + if (!verbose) ::testing::internal::GetCapturedStdout(); + FAIL() << e.what(); + } if (!verbose) ::testing::internal::GetCapturedStdout(); if (!lmp) { diff --git a/unittest/force-styles/test_dihedral_style.cpp b/unittest/force-styles/test_dihedral_style.cpp index b538c45f42..ed9ceff1e8 100644 --- a/unittest/force-styles/test_dihedral_style.cpp +++ b/unittest/force-styles/test_dihedral_style.cpp @@ -61,7 +61,7 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) delete lmp; } -LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton = true) +LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton) { auto *lmp = new LAMMPS(args, MPI_COMM_WORLD); @@ -237,7 +237,13 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // initialize system geometry LAMMPS::argv args = {"DihedralStyle", "-log", "none", "-echo", "screen", "-nocite"}; - LAMMPS *lmp = init_lammps(args, config); + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, config, true); + } catch (std::exception &e) { + FAIL() << e.what(); + } + if (!lmp) { std::cerr << "One or more prerequisite styles are not available " "in this LAMMPS configuration:\n"; @@ -322,8 +328,14 @@ TEST(DihedralStyle, plain) LAMMPS::argv args = {"DihedralStyle", "-log", "none", "-echo", "screen", "-nocite"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config, true); - + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -372,7 +384,12 @@ TEST(DihedralStyle, plain) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(args, test_config, false); + try { + lmp = init_lammps(args, test_config, false); + } catch (std::exception &e) { + if (!verbose) ::testing::internal::GetCapturedStdout(); + FAIL() << e.what(); + } if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton bond is forced to be on @@ -442,8 +459,14 @@ TEST(DihedralStyle, omp) "-pk", "omp", "4", "-sf", "omp"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config, true); - + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -497,7 +520,12 @@ TEST(DihedralStyle, omp) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(args, test_config, false); + try { + lmp = init_lammps(args, test_config, false); + } catch (std::exception &e) { + if (!verbose) ::testing::internal::GetCapturedStdout(); + FAIL() << e.what(); + } if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton bond is forced to be on @@ -544,15 +572,22 @@ TEST(DihedralStyle, kokkos_omp) // if KOKKOS has GPU support enabled, it *must* be used. We cannot test OpenMP only. if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") || Info::has_accelerator_feature("KOKKOS", "api", "hip") || - Info::has_accelerator_feature("KOKKOS", "api", "sycl")) GTEST_SKIP(); + Info::has_accelerator_feature("KOKKOS", "api", "sycl")) + GTEST_SKIP() << "Cannot test KOKKOS/OpenMP with GPU support enabled"; LAMMPS::argv args = {"DihedralStyle", "-log", "none", "-echo", "screen", "-nocite", "-k", "on", "t", "4", "-sf", "kk"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config, true); - + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -606,7 +641,12 @@ TEST(DihedralStyle, kokkos_omp) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(args, test_config, false); + try { + lmp = init_lammps(args, test_config, false); + } catch (std::exception &e) { + if (!verbose) ::testing::internal::GetCapturedStdout(); + FAIL() << e.what(); + } if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton bond is forced to be on @@ -655,8 +695,14 @@ TEST(DihedralStyle, numdiff) LAMMPS::argv args = {"DihedralStyle", "-log", "none", "-echo", "screen", "-nocite"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config, true); - + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; diff --git a/unittest/force-styles/test_fix_timestep.cpp b/unittest/force-styles/test_fix_timestep.cpp index 957226d22b..f175e1cd64 100644 --- a/unittest/force-styles/test_fix_timestep.cpp +++ b/unittest/force-styles/test_fix_timestep.cpp @@ -62,7 +62,7 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) delete lmp; } -LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool use_respa = false) +LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool use_respa) { LAMMPS *lmp; @@ -178,7 +178,12 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) { // initialize system geometry LAMMPS::argv args = {"FixIntegrate", "-log", "none", "-echo", "screen", "-nocite"}; - LAMMPS *lmp = init_lammps(args, config); + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, config, false); + } catch (std::exception &e) { + FAIL() << e.what(); + } if (!lmp) { std::cerr << "One or more prerequisite styles are not available " "in this LAMMPS configuration:\n"; @@ -272,7 +277,14 @@ TEST(FixTimestep, plain) LAMMPS::argv args = {"FixTimestep", "-log", "none", "-echo", "screen", "-nocite"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config); + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, false); + } catch (std::exception &e) { + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -430,14 +442,20 @@ TEST(FixTimestep, plain) // fix nve/limit cannot work with r-RESPA ifix = lmp->modify->get_fix_by_id("test"); if (ifix && !utils::strmatch(ifix->style, "^rigid") && - !utils::strmatch(ifix->style, "^nve/limit") && - !utils::strmatch(ifix->style, "^recenter")) { + !utils::strmatch(ifix->style, "^nve/limit") && !utils::strmatch(ifix->style, "^recenter")) { if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); ::testing::internal::CaptureStdout(); - lmp = init_lammps(args, test_config, true); + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -572,15 +590,26 @@ TEST(FixTimestep, omp) "-pk", "omp", "4", "-sf", "omp"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config); + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, false); + } catch (std::exception &e) { + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; if (!lmp) { - std::cerr << "One or more prerequisite styles are not available " + std::cerr << "One or more prerequisite styles with /omp suffix are not available " "in this LAMMPS configuration:\n"; for (auto &prerequisite : test_config.prerequisites) { - std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; + if (prerequisite.first == "atom") { + std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; + } else { + std::cerr << prerequisite.first << "_style " << prerequisite.second << "/omp\n"; + } } GTEST_SKIP(); } @@ -731,7 +760,13 @@ TEST(FixTimestep, omp) if (!verbose) ::testing::internal::GetCapturedStdout(); ::testing::internal::CaptureStdout(); - lmp = init_lammps(args, test_config, true); + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -861,13 +896,21 @@ TEST(FixTimestep, kokkos_omp) // if KOKKOS has GPU support enabled, it *must* be used. We cannot test OpenMP only. if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") || Info::has_accelerator_feature("KOKKOS", "api", "hip") || - Info::has_accelerator_feature("KOKKOS", "api", "sycl")) GTEST_SKIP(); - + Info::has_accelerator_feature("KOKKOS", "api", "sycl")) { + GTEST_SKIP() << "Cannot test KOKKOS/OpenMP with GPU support enabled"; + } LAMMPS::argv args = {"FixTimestep", "-log", "none", "-echo", "screen", "-nocite", "-k", "on", "t", "4", "-sf", "kk"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config); + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, false); + } catch (std::exception &e) { + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -875,7 +918,7 @@ TEST(FixTimestep, kokkos_omp) std::cerr << "One or more prerequisite styles with /kk suffix\n" "are not available in this LAMMPS configuration:\n"; for (auto &prerequisite : test_config.prerequisites) { - std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; + std::cerr << prerequisite.first << "_style " << prerequisite.second << "/kk\n"; } GTEST_SKIP(); } diff --git a/unittest/force-styles/test_improper_style.cpp b/unittest/force-styles/test_improper_style.cpp index cddb27a2f7..5b38ad38c4 100644 --- a/unittest/force-styles/test_improper_style.cpp +++ b/unittest/force-styles/test_improper_style.cpp @@ -61,7 +61,7 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) delete lmp; } -LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton = true) +LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton) { LAMMPS *lmp; @@ -92,21 +92,7 @@ LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton // utility lambdas to improve readability auto command = [&](const std::string &line) { - try { - lmp->input->one(line); - } catch (LAMMPSAbortException &ae) { - fprintf(stderr, "LAMMPS Error: %s\n", ae.what()); - exit(2); - } catch (LAMMPSException &e) { - fprintf(stderr, "LAMMPS Error: %s\n", e.what()); - exit(3); - } catch (fmt::format_error &fe) { - fprintf(stderr, "fmt::format_error: %s\n", fe.what()); - exit(4); - } catch (std::exception &e) { - fprintf(stderr, "General exception: %s\n", e.what()); - exit(5); - } + lmp->input->one(line); }; auto parse_input_script = [&](const std::string &filename) { lmp->input->file(filename.c_str()); @@ -230,7 +216,12 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // initialize system geometry LAMMPS::argv args = {"ImproperStyle", "-log", "none", "-echo", "screen", "-nocite"}; - LAMMPS *lmp = init_lammps(args, config); + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, config, true); + } catch (std::exception &e) { + FAIL() << e.what(); + } if (!lmp) { std::cerr << "One or more prerequisite styles are not available " "in this LAMMPS configuration:\n"; @@ -315,8 +306,14 @@ TEST(ImproperStyle, plain) LAMMPS::argv args = {"ImproperStyle", "-log", "none", "-echo", "screen", "-nocite"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config, true); - + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -365,7 +362,12 @@ TEST(ImproperStyle, plain) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(args, test_config, false); + try { + lmp = init_lammps(args, test_config, false); + } catch (std::exception &e) { + if (!verbose) ::testing::internal::GetCapturedStdout(); + FAIL() << e.what(); + } if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton bond is forced to be on @@ -435,8 +437,14 @@ TEST(ImproperStyle, omp) "-pk", "omp", "4", "-sf", "omp"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config, true); - + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -490,7 +498,12 @@ TEST(ImproperStyle, omp) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(args, test_config, false); + try { + lmp = init_lammps(args, test_config, false); + } catch (std::exception &e) { + if (!verbose) ::testing::internal::GetCapturedStdout(); + FAIL() << e.what(); + } if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton bond is forced to be on @@ -536,15 +549,22 @@ TEST(ImproperStyle, kokkos_omp) // if KOKKOS has GPU support enabled, it *must* be used. We cannot test OpenMP only. if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") || Info::has_accelerator_feature("KOKKOS", "api", "hip") || - Info::has_accelerator_feature("KOKKOS", "api", "sycl")) GTEST_SKIP(); + Info::has_accelerator_feature("KOKKOS", "api", "sycl")) + GTEST_SKIP() << "Cannot test KOKKOS/OpenMP with GPU support enabled"; LAMMPS::argv args = {"ImproperStyle", "-log", "none", "-echo", "screen", "-nocite", "-k", "on", "t", "4", "-sf", "kk"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config, true); - + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -597,7 +617,12 @@ TEST(ImproperStyle, kokkos_omp) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(args, test_config, false); + try { + lmp = init_lammps(args, test_config, false); + } catch (std::exception &e) { + if (!verbose) ::testing::internal::GetCapturedStdout(); + FAIL() << e.what(); + } if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton bond is forced to be on @@ -644,8 +669,14 @@ TEST(ImproperStyle, numdiff) LAMMPS::argv args = {"ImproperStyle", "-log", "none", "-echo", "screen", "-nocite"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config, true); - + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; diff --git a/unittest/force-styles/test_pair_style.cpp b/unittest/force-styles/test_pair_style.cpp index bb1346fe70..90ebe09513 100644 --- a/unittest/force-styles/test_pair_style.cpp +++ b/unittest/force-styles/test_pair_style.cpp @@ -62,7 +62,7 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) delete lmp; } -LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton = true) +LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton) { LAMMPS *lmp; @@ -93,21 +93,7 @@ LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton // utility lambdas to improve readability auto command = [&](const std::string &line) { - try { - lmp->input->one(line); - } catch (LAMMPSAbortException &ae) { - fprintf(stderr, "LAMMPS Error: %s\n", ae.what()); - exit(2); - } catch (LAMMPSException &e) { - fprintf(stderr, "LAMMPS Error: %s\n", e.what()); - exit(3); - } catch (fmt::format_error &fe) { - fprintf(stderr, "fmt::format_error: %s\n", fe.what()); - exit(4); - } catch (std::exception &e) { - fprintf(stderr, "General exception: %s\n", e.what()); - exit(5); - } + lmp->input->one(line); }; auto parse_input_script = [&](const std::string &filename) { @@ -242,8 +228,12 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) { // initialize system geometry LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; - - LAMMPS *lmp = init_lammps(args, config); + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, config, true); + } catch (std::exception &e) { + FAIL() << e.what(); + } if (!lmp) { std::cerr << "One or more prerequisite styles are not available " "in this LAMMPS configuration:\n"; @@ -340,8 +330,14 @@ TEST(PairStyle, plain) LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config, true); - + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -399,7 +395,12 @@ TEST(PairStyle, plain) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(args, test_config, false); + try { + lmp = init_lammps(args, test_config, false); + } catch (std::exception &e) { + if (!verbose) ::testing::internal::GetCapturedStdout(); + FAIL() << e.what(); + } if (!verbose) ::testing::internal::GetCapturedStdout(); // skip over these tests if newton pair is forced to be on @@ -480,9 +481,14 @@ TEST(PairStyle, plain) if (pair->respa_enable) { if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(args, test_config, false); - lmp->input->one("run_style respa 2 1 inner 1 4.8 5.5 outer 2"); - run_lammps(lmp); + try { + lmp = init_lammps(args, test_config, false); + lmp->input->one("run_style respa 2 1 inner 1 4.8 5.5 outer 2"); + run_lammps(lmp); + } catch (std::exception &e) { + if (!verbose) ::testing::internal::GetCapturedStdout(); + FAIL() << e.what(); + } if (!verbose) ::testing::internal::GetCapturedStdout(); // need to relax error by a large amount with tabulation, since @@ -519,8 +525,14 @@ TEST(PairStyle, omp) if (utils::strmatch(test_config.pair_style, "^dpd")) args[8] = "1"; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config, true); - + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -578,7 +590,12 @@ TEST(PairStyle, omp) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(args, test_config, false); + try { + lmp = init_lammps(args, test_config, false); + } catch (std::exception &e) { + if (!verbose) ::testing::internal::GetCapturedStdout(); + FAIL() << e.what(); + } if (!verbose) ::testing::internal::GetCapturedStdout(); pair = lmp->force->pair; @@ -636,7 +653,9 @@ TEST(PairStyle, kokkos_omp) // if KOKKOS has GPU support enabled, it *must* be used. We cannot test OpenMP only. if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") || Info::has_accelerator_feature("KOKKOS", "api", "hip") || - Info::has_accelerator_feature("KOKKOS", "api", "sycl")) GTEST_SKIP(); + Info::has_accelerator_feature("KOKKOS", "api", "sycl")) { + GTEST_SKIP() << "Cannot test KOKKOS/OpenMP with GPU support enabled"; + } LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", "-k", "on", "t", "4", "-sf", "kk"}; @@ -655,8 +674,14 @@ TEST(PairStyle, kokkos_omp) args[9] = "1"; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config, true); - + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -713,7 +738,12 @@ TEST(PairStyle, kokkos_omp) if (lmp->force->newton_pair == 0) { if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); - lmp = init_lammps(args, test_config, false); + try { + lmp = init_lammps(args, test_config, false); + } catch (std::exception &e) { + if (!verbose) ::testing::internal::GetCapturedStdout(); + FAIL() << e.what(); + } if (!verbose) ::testing::internal::GetCapturedStdout(); pair = lmp->force->pair; @@ -788,8 +818,14 @@ TEST(PairStyle, gpu) } ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config, false); - + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, false); + } catch (std::exception &e) { + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -868,8 +904,14 @@ TEST(PairStyle, intel) if (utils::strmatch(test_config.pair_style, "^dpd")) args[12] = "1"; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config, true); - + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -948,8 +990,14 @@ TEST(PairStyle, opt) LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", "-sf", "opt"}; ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config); - + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + FAIL() << e.what(); + } std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; @@ -1032,7 +1080,13 @@ TEST(PairStyle, single) // create a LAMMPS instance with standard settings to detect the number of atom types if (!verbose) ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config); + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + if (!verbose) ::testing::internal::GetCapturedStdout(); + FAIL() << e.what(); + } if (!verbose) ::testing::internal::GetCapturedStdout(); if (!lmp) { @@ -1276,7 +1330,13 @@ TEST(PairStyle, extract) LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; if (!verbose) ::testing::internal::CaptureStdout(); - LAMMPS *lmp = init_lammps(args, test_config, true); + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + if (!verbose) ::testing::internal::GetCapturedStdout(); + FAIL() << e.what(); + } if (!verbose) ::testing::internal::GetCapturedStdout(); if (!lmp) { From da1bbec0be814f83cce805c78c964822f232defa Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 29 Jan 2025 23:32:52 -0500 Subject: [PATCH 64/70] set lmp pointer to NULL after delete to avoid using it or deleting it a second time --- unittest/force-styles/test_angle_style.cpp | 3 ++- unittest/force-styles/test_bond_style.cpp | 3 ++- unittest/force-styles/test_dihedral_style.cpp | 3 ++- unittest/force-styles/test_fix_timestep.cpp | 3 ++- unittest/force-styles/test_improper_style.cpp | 3 ++- unittest/force-styles/test_pair_style.cpp | 3 ++- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/unittest/force-styles/test_angle_style.cpp b/unittest/force-styles/test_angle_style.cpp index 80601d3632..e24e5401df 100644 --- a/unittest/force-styles/test_angle_style.cpp +++ b/unittest/force-styles/test_angle_style.cpp @@ -53,12 +53,13 @@ using ::testing::StartsWith; using namespace LAMMPS_NS; -void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) +void cleanup_lammps(LAMMPS *&lmp, const TestConfig &cfg) { platform::unlink(cfg.basename + ".restart"); platform::unlink(cfg.basename + ".data"); platform::unlink(cfg.basename + "-coeffs.in"); delete lmp; + lmp = nullptr; } LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton) diff --git a/unittest/force-styles/test_bond_style.cpp b/unittest/force-styles/test_bond_style.cpp index 6c680feaa3..660435cf49 100644 --- a/unittest/force-styles/test_bond_style.cpp +++ b/unittest/force-styles/test_bond_style.cpp @@ -53,12 +53,13 @@ using ::testing::StartsWith; using namespace LAMMPS_NS; -void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) +void cleanup_lammps(LAMMPS *&lmp, const TestConfig &cfg) { platform::unlink(cfg.basename + ".restart"); platform::unlink(cfg.basename + ".data"); platform::unlink(cfg.basename + "-coeffs.in"); delete lmp; + lmp = nullptr; } LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton) diff --git a/unittest/force-styles/test_dihedral_style.cpp b/unittest/force-styles/test_dihedral_style.cpp index ed9ceff1e8..5d0bd86d2b 100644 --- a/unittest/force-styles/test_dihedral_style.cpp +++ b/unittest/force-styles/test_dihedral_style.cpp @@ -53,12 +53,13 @@ using ::testing::StartsWith; using namespace LAMMPS_NS; -void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) +void cleanup_lammps(LAMMPS *&lmp, const TestConfig &cfg) { platform::unlink(cfg.basename + ".restart"); platform::unlink(cfg.basename + ".data"); platform::unlink(cfg.basename + "-coeffs.in"); delete lmp; + lmp = nullptr; } LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton) diff --git a/unittest/force-styles/test_fix_timestep.cpp b/unittest/force-styles/test_fix_timestep.cpp index f175e1cd64..b952a3c045 100644 --- a/unittest/force-styles/test_fix_timestep.cpp +++ b/unittest/force-styles/test_fix_timestep.cpp @@ -56,10 +56,11 @@ using ::testing::StartsWith; using namespace LAMMPS_NS; -void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) +void cleanup_lammps(LAMMPS *&lmp, const TestConfig &cfg) { platform::unlink(cfg.basename + ".restart"); delete lmp; + lmp = nullptr; } LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool use_respa) diff --git a/unittest/force-styles/test_improper_style.cpp b/unittest/force-styles/test_improper_style.cpp index 5b38ad38c4..e272033e85 100644 --- a/unittest/force-styles/test_improper_style.cpp +++ b/unittest/force-styles/test_improper_style.cpp @@ -53,12 +53,13 @@ using ::testing::StartsWith; using namespace LAMMPS_NS; -void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) +void cleanup_lammps(LAMMPS *&lmp, const TestConfig &cfg) { platform::unlink(cfg.basename + ".restart"); platform::unlink(cfg.basename + ".data"); platform::unlink(cfg.basename + "-coeffs.in"); delete lmp; + lmp = nullptr; } LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton) diff --git a/unittest/force-styles/test_pair_style.cpp b/unittest/force-styles/test_pair_style.cpp index 90ebe09513..6dabeab7a4 100644 --- a/unittest/force-styles/test_pair_style.cpp +++ b/unittest/force-styles/test_pair_style.cpp @@ -54,12 +54,13 @@ using ::testing::StartsWith; using namespace LAMMPS_NS; -void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) +void cleanup_lammps(LAMMPS *&lmp, const TestConfig &cfg) { platform::unlink(cfg.basename + ".restart"); platform::unlink(cfg.basename + ".data"); platform::unlink(cfg.basename + "-coeffs.in"); delete lmp; + lmp = nullptr; } LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton) From 6685524fdb33ca925ee76ee07478dd9c4e6cba6d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 29 Jan 2025 23:39:30 -0500 Subject: [PATCH 65/70] correctly apply environment variables --- unittest/force-styles/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/force-styles/CMakeLists.txt b/unittest/force-styles/CMakeLists.txt index 043b628fd3..fb6cd1a63b 100644 --- a/unittest/force-styles/CMakeLists.txt +++ b/unittest/force-styles/CMakeLists.txt @@ -246,7 +246,7 @@ if(MLIAP_ENABLE_PYTHON AND (NOT WIN32)) add_executable(test_mliappy_unified test_mliappy_unified.cpp) target_link_libraries(test_mliappy_unified PRIVATE lammps GTest::GMockMain) add_test(NAME TestMliapPyUnified COMMAND test_mliappy_unified) - set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "${FORCE_TEST_ENVIRONMENT}") + set_tests_properties(TestMliapPyUnified PROPERTIES ENVIRONMENT "${FORCE_TEST_ENVIRONMENT}") endif() add_executable(test_pair_list test_pair_list.cpp) From 48f749fbdd2956423f02de5e31f784f67c83b20a Mon Sep 17 00:00:00 2001 From: ljwoods2 Date: Wed, 29 Jan 2025 23:16:44 -0700 Subject: [PATCH 66/70] exact copy of v2 unwrap logic --- src/MISC/fix_imd.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/MISC/fix_imd.cpp b/src/MISC/fix_imd.cpp index cca2025a61..1f14115adf 100644 --- a/src/MISC/fix_imd.cpp +++ b/src/MISC/fix_imd.cpp @@ -1672,15 +1672,14 @@ void FixIMD::handle_output_v3() { if (domain->triclinic) { buf[idx].tag = tag[i]; - buf[idx].x = x[i][0]; + ix * xprd + iy * xy + iz * xz; - buf[idx].y = x[i][1]; + iy * yprd + iz * yz; - buf[idx].z = x[i][2]; + iz * zprd; - } - else { + buf[idx].x = x[i][0] + ix * xprd + iy * xy + iz * xz; + buf[idx].y = x[i][1] + iy * yprd + iz * yz; + buf[idx].z = x[i][2] + iz * zprd; + } else { buf[idx].tag = tag[i]; - buf[idx].x = x[i][0]; + ix * xprd; - buf[idx].y = x[i][1]; + iy * yprd; - buf[idx].z = x[i][2]; + iz * zprd; + buf[idx].x = x[i][0] + ix * xprd; + buf[idx].y = x[i][1] + iy * yprd; + buf[idx].z = x[i][2] + iz * zprd; } ++idx; } From 31720b27413f1f6351385827bf56ec6e1769f8fd Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Wed, 29 Jan 2025 23:53:23 -0700 Subject: [PATCH 67/70] add missing init function to fix python/invoke --- src/PYTHON/fix_python_invoke.cpp | 26 +++++++++++++++++++++++--- src/PYTHON/fix_python_invoke.h | 2 ++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/PYTHON/fix_python_invoke.cpp b/src/PYTHON/fix_python_invoke.cpp index b47a94c6c7..6f27831438 100644 --- a/src/PYTHON/fix_python_invoke.cpp +++ b/src/PYTHON/fix_python_invoke.cpp @@ -72,7 +72,11 @@ FixPythonInvoke::FixPythonInvoke(LAMMPS *lmp, int narg, char **arg) : lmpPtr = PY_VOID_POINTER(lmp); - modify->addstep_compute_all(nextvalid()); + // nvalid = next step on which end_of_step or post_force does something + // add nextvalid() to all computes that store invocation times + // since we don't know a priori which are invoked by python code + nvalid = nextvalid(); + modify->addstep_compute_all(nvalid); } /* ---------------------------------------------------------------------- */ @@ -92,8 +96,21 @@ int FixPythonInvoke::setmask() /* ---------------------------------------------------------------------- */ +void FixPythonInvoke::init() +{ + // need to reset nvalid if nvalid < ntimestep b/c minimize was performed + + if (nvalid < update->ntimestep) { + nvalid = nextvalid(); + modify->addstep_compute_all(nvalid); + } +} + +/* ---------------------------------------------------------------------- */ + void FixPythonInvoke::end_of_step() { + // python code may invoke computes so wrap with clear/add modify->clearstep_compute(); PyUtils::GIL lock; @@ -107,7 +124,8 @@ void FixPythonInvoke::end_of_step() Py_CLEAR(result); - modify->addstep_compute(nextvalid()); + nvalid = nextvalid(); + modify->addstep_compute(nvalid); } /* ---------------------------------------------------------------------- */ @@ -123,6 +141,7 @@ void FixPythonInvoke::post_force(int vflag) { if (update->ntimestep % nevery != 0) return; + // python code may invoke computes so wrap with clear/add modify->clearstep_compute(); PyUtils::GIL lock; @@ -137,7 +156,8 @@ void FixPythonInvoke::post_force(int vflag) Py_CLEAR(result); - modify->addstep_compute(nextvalid()); + nvalid = nextvalid(); + modify->addstep_compute(nvalid); } /* ---------------------------------------------------------------------- */ diff --git a/src/PYTHON/fix_python_invoke.h b/src/PYTHON/fix_python_invoke.h index 3d2324a939..fdb931b69c 100644 --- a/src/PYTHON/fix_python_invoke.h +++ b/src/PYTHON/fix_python_invoke.h @@ -31,6 +31,7 @@ class FixPythonInvoke : public Fix { ~FixPythonInvoke() override; int setmask() override; void setup(int) override; + void init() override; void end_of_step() override; void post_force(int) override; @@ -39,6 +40,7 @@ class FixPythonInvoke : public Fix { void *pFunc; int selected_callback; bigint nextvalid(); + bigint nvalid; }; } // namespace LAMMPS_NS From 2b0a6419b76b09fbdef33104672c36f9f3fe0498 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Wed, 29 Jan 2025 23:57:44 -0700 Subject: [PATCH 68/70] add missing doc section for fix python/invoke --- doc/src/fix_python_invoke.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/src/fix_python_invoke.rst b/doc/src/fix_python_invoke.rst index ad55882270..4f33f5483b 100644 --- a/doc/src/fix_python_invoke.rst +++ b/doc/src/fix_python_invoke.rst @@ -66,6 +66,15 @@ gives access to the LAMMPS state from Python. from these callbacks, trying to execute input script commands will in the best case not work or in the worst case result in undefined behavior. +Restart, fix_modify, output, run start/stop, minimize info +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +No information about this fix is written to :doc:`binary restart files `. None of the :doc:`fix_modify ` options +are relevant to this fix. No global or per-atom quantities are stored +by this fix for access by various :doc:`output commands `. +No parameter of this fix can be used with the *start/stop* keywords of +the :doc:`run ` command. This fix is not invoked during :doc:`energy minimization `. + Restrictions """""""""""" From 444c6d78f7253569a61eec2d1f6c1a96c5c7ee87 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 30 Jan 2025 03:54:26 -0500 Subject: [PATCH 69/70] consistently use a :class: qualifier for admonitions --- doc/src/Developer_code_design.rst | 1 + doc/src/Fortran.rst | 3 +++ doc/src/Install_git.rst | 1 + doc/src/pair_mliap.rst | 1 + 4 files changed, 6 insertions(+) diff --git a/doc/src/Developer_code_design.rst b/doc/src/Developer_code_design.rst index 974266ec7f..b4b23958a8 100644 --- a/doc/src/Developer_code_design.rst +++ b/doc/src/Developer_code_design.rst @@ -203,6 +203,7 @@ processed in the expected order before types are removed from dynamic dispatch. .. admonition:: Important Notes + :class: note In order to be able to detect incompatibilities at compile time and to avoid unexpected behavior, it is crucial that all member functions diff --git a/doc/src/Fortran.rst b/doc/src/Fortran.rst index bc641a237f..6f87b8c97a 100644 --- a/doc/src/Fortran.rst +++ b/doc/src/Fortran.rst @@ -956,6 +956,7 @@ Procedures Bound to the :f:type:`lammps` Derived Type :f:func:`extract_atom` between runs. .. admonition:: Array index order + :class: tip Two-dimensional arrays returned from :f:func:`extract_atom` will be **transposed** from equivalent arrays in C, and they will be indexed @@ -1068,6 +1069,7 @@ Procedures Bound to the :f:type:`lammps` Derived Type you based on data from the :cpp:class:`Compute` class. .. admonition:: Array index order + :class: tip Two-dimensional arrays returned from :f:func:`extract_compute` will be **transposed** from equivalent arrays in C, and they will be indexed @@ -1326,6 +1328,7 @@ Procedures Bound to the :f:type:`lammps` Derived Type :rtype data: polymorphic .. admonition:: Array index order + :class: tip Two-dimensional global, per-atom, or local array data from :f:func:`extract_fix` will be **transposed** from equivalent arrays in diff --git a/doc/src/Install_git.rst b/doc/src/Install_git.rst index 5108009a73..d01bc6a4c5 100644 --- a/doc/src/Install_git.rst +++ b/doc/src/Install_git.rst @@ -52,6 +52,7 @@ your machine and "release" is one of the 3 branches listed above. between them at any time using "git checkout ".) .. admonition:: Saving time and disk space when using ``git clone`` + :class: note The complete git history of the LAMMPS project is quite large because it contains the entire commit history of the project since fall 2006, diff --git a/doc/src/pair_mliap.rst b/doc/src/pair_mliap.rst index e325de0aa6..7f8b36bb83 100644 --- a/doc/src/pair_mliap.rst +++ b/doc/src/pair_mliap.rst @@ -145,6 +145,7 @@ per line. The detail of *nn* module implementation can be found at :ref:`(Yanxon) `. .. admonition:: Notes on mliappy models + :class: note When the *model* keyword is *mliappy*, if the filename ends in '.pt', or '.pth', it will be loaded using pytorch; otherwise, it will be From 363309a7d8db0548f0cc879ffae7ce45ba878790 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 30 Jan 2025 03:57:30 -0500 Subject: [PATCH 70/70] add tip for addressing memory management issues with ReaxFF --- doc/src/pair_reaxff.rst | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/doc/src/pair_reaxff.rst b/doc/src/pair_reaxff.rst index 495572dc0e..45532bc2a6 100644 --- a/doc/src/pair_reaxff.rst +++ b/doc/src/pair_reaxff.rst @@ -158,11 +158,36 @@ drops to zero. Optional keywords *safezone*, *mincap*, and *minhbonds* are used for allocating reaxff arrays. Increasing these values can avoid memory problems, such as segmentation faults and bondchk failed errors, that -could occur under certain conditions. These keywords are not used by +could occur under certain conditions. These keywords are **not** used by the Kokkos version, which instead uses a more robust memory allocation scheme that checks if the sizes of the arrays have been exceeded and automatically allocates more memory. +.. admonition:: Memory management problems with ReaxFF + :class: tip + + The LAMMPS implementation of ReaxFF is adapted from a standalone MD + program written in C called `PuReMD + `_. It inherits from this code + a heuristic memory management that is different from what the rest of + LAMMPS uses. It assumes that a system is dense and already well + equilibrated, so that there are no large changes in how many and what + types of neighbors atoms have. However, not all systems are like + that, and thus there can be errors or segmentation faults if the + system changes too much. If you run into problems, here are three + options to avoid them: + + - Use the KOKKOS version of ReaxFF (KOKKOS is not only for GPUs, + but can also be compiled for serial or OpenMP execution) which + uses a different memory management approach. + - Break down a run command during which memory related errors happen + into multiple smaller segments so that the memory management + heuristics are re-initialized for each segment before they become + invalid. + - Increase the values for *safezone*, *mincap*, and *minhbonds* as + needed. This can lead to significant increase of memory consumption + through. + The keyword *tabulate* controls the size of interpolation table for Lennard-Jones and Coulomb interactions. Tabulation may also be set in the control file (see below). If tabulation is set in both the input script and the