enable and apply clang-format

This commit is contained in:
Axel Kohlmeyer
2022-03-17 19:44:53 -04:00
parent 58030009da
commit 85e581eb2a
5 changed files with 535 additions and 548 deletions

View File

@ -1,4 +1,3 @@
// clang-format off
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories https://www.lammps.org/, Sandia National Laboratories
@ -32,13 +31,13 @@
#include <cmath> #include <cmath>
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using namespace MathConst; using MathConst::DEG2RAD;
#define TOLERANCE 0.05 static constexpr double TOLERANCE = 0.05;
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
DihedralCharmm::DihedralCharmm(LAMMPS *lmp) : Dihedral(lmp) DihedralCharmm::DihedralCharmm(LAMMPS *_lmp) : Dihedral(_lmp)
{ {
weightflag = 0; weightflag = 0;
writedata = 1; writedata = 1;
@ -144,8 +143,7 @@ void DihedralCharmm::compute(int eflag, int vflag)
// error check // error check
if (c > 1.0 + TOLERANCE || c < (-1.0 - TOLERANCE)) if (c > 1.0 + TOLERANCE || c < (-1.0 - TOLERANCE)) problem(FLERR, i1, i2, i3, i4);
problem(FLERR, i1, i2, i3, i4);
if (c > 1.0) c = 1.0; if (c > 1.0) c = 1.0;
if (c < -1.0) c = -1.0; if (c < -1.0) c = -1.0;
@ -238,8 +236,8 @@ void DihedralCharmm::compute(int eflag, int vflag)
} }
if (evflag) if (evflag)
ev_tally(i1,i2,i3,i4,nlocal,newton_bond,edihedral,f1,f3,f4, ev_tally(i1, i2, i3, i4, nlocal, newton_bond, edihedral, f1, f3, f4, vb1x, vb1y, vb1z, vb2x,
vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z); vb2y, vb2z, vb3x, vb3y, vb3z);
// 1-4 LJ and Coulomb interactions // 1-4 LJ and Coulomb interactions
// tally energy/virial in pair, using newton_bond as newton flag // tally energy/virial in pair, using newton_bond as newton flag
@ -255,8 +253,10 @@ void DihedralCharmm::compute(int eflag, int vflag)
r2inv = 1.0 / rsq; r2inv = 1.0 / rsq;
r6inv = r2inv * r2inv * r2inv; r6inv = r2inv * r2inv * r2inv;
if (implicit) forcecoul = qqrd2e * q[i1]*q[i4]*r2inv; if (implicit)
else forcecoul = qqrd2e * q[i1]*q[i4]*sqrt(r2inv); forcecoul = qqrd2e * q[i1] * q[i4] * r2inv;
else
forcecoul = qqrd2e * q[i1] * q[i4] * sqrt(r2inv);
forcelj = r6inv * (lj14_1[itype][jtype] * r6inv - lj14_2[itype][jtype]); forcelj = r6inv * (lj14_1[itype][jtype] * r6inv - lj14_2[itype][jtype]);
fpair = weight[type] * (forcelj + forcecoul) * r2inv; fpair = weight[type] * (forcelj + forcecoul) * r2inv;
@ -277,8 +277,8 @@ void DihedralCharmm::compute(int eflag, int vflag)
f[i4][2] -= delz * fpair; f[i4][2] -= delz * fpair;
} }
if (evflag) force->pair->ev_tally(i1,i4,nlocal,newton_bond, if (evflag)
evdwl,ecoul,fpair,delx,dely,delz); force->pair->ev_tally(i1, i4, nlocal, newton_bond, evdwl, ecoul, fpair, delx, dely, delz);
} }
} }
} }
@ -288,17 +288,17 @@ void DihedralCharmm::compute(int eflag, int vflag)
void DihedralCharmm::allocate() void DihedralCharmm::allocate()
{ {
allocated = 1; allocated = 1;
int n = atom->ndihedraltypes; const int np1 = atom->ndihedraltypes + 1;
memory->create(k,n+1,"dihedral:k"); memory->create(k, np1, "dihedral:k");
memory->create(multiplicity,n+1,"dihedral:multiplicity"); memory->create(multiplicity, np1, "dihedral:multiplicity");
memory->create(shift,n+1,"dihedral:shift"); memory->create(shift, np1, "dihedral:shift");
memory->create(cos_shift,n+1,"dihedral:cos_shift"); memory->create(cos_shift, np1, "dihedral:cos_shift");
memory->create(sin_shift,n+1,"dihedral:sin_shift"); memory->create(sin_shift, np1, "dihedral:sin_shift");
memory->create(weight,n+1,"dihedral:weight"); memory->create(weight, np1, "dihedral:weight");
memory->create(setflag,n+1,"dihedral:setflag"); memory->create(setflag, np1, "dihedral:setflag");
for (int i = 1; i <= n; i++) setflag[i] = 0; for (int i = 1; i < np1; i++) setflag[i] = 0;
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
@ -332,8 +332,8 @@ void DihedralCharmm::coeff(int narg, char **arg)
for (int i = ilo; i <= ihi; i++) { for (int i = ilo; i <= ihi; i++) {
k[i] = k_one; k[i] = k_one;
shift[i] = shift_one; shift[i] = shift_one;
cos_shift[i] = cos(MY_PI*shift_one/180.0); cos_shift[i] = cos(DEG2RAD * shift_one);
sin_shift[i] = sin(MY_PI*shift_one/180.0); sin_shift[i] = sin(DEG2RAD * shift_one);
multiplicity[i] = multiplicity_one; multiplicity[i] = multiplicity_one;
weight[i] = weight_one; weight[i] = weight_one;
setflag[i] = 1; setflag[i] = 1;
@ -352,11 +352,9 @@ void DihedralCharmm::init_style()
if (utils::strmatch(update->integrate_style, "^respa")) { if (utils::strmatch(update->integrate_style, "^respa")) {
Respa *r = (Respa *) update->integrate; Respa *r = (Respa *) update->integrate;
if (r->level_pair >= 0 && (r->level_pair != r->level_dihedral)) if (r->level_pair >= 0 && (r->level_pair != r->level_dihedral))
error->all(FLERR,"Dihedral style charmm must be set to same" error->all(FLERR, "Dihedral style charmm must be set to same r-RESPA level as 'pair'");
" r-RESPA level as 'pair'");
if (r->level_outer >= 0 && (r->level_outer != r->level_dihedral)) if (r->level_outer >= 0 && (r->level_outer != r->level_dihedral))
error->all(FLERR,"Dihedral style charmm must be set to same" error->all(FLERR, "Dihedral style charmm must be set to same r-RESPA level as 'outer'");
" r-RESPA level as 'outer'");
} }
// insure use of CHARMM pair_style if any weight factors are non-zero // insure use of CHARMM pair_style if any weight factors are non-zero
@ -366,8 +364,9 @@ void DihedralCharmm::init_style()
if (weightflag) { if (weightflag) {
if ((force->special_lj[3] != 0.0) || (force->special_coul[3] != 0.0)) if ((force->special_lj[3] != 0.0) || (force->special_coul[3] != 0.0))
error->all(FLERR,"Must use 'special_bonds charmm' with" error->all(FLERR,
" dihedral style charmm for use with CHARMM pair styles"); "Must use 'special_bonds charmm' with dihedral "
"style charmm for use with CHARMM pair styles");
int itmp; int itmp;
if (force->pair == nullptr) if (force->pair == nullptr)
@ -419,8 +418,8 @@ void DihedralCharmm::read_restart(FILE *fp)
for (int i = 1; i <= atom->ndihedraltypes; i++) { for (int i = 1; i <= atom->ndihedraltypes; i++) {
setflag[i] = 1; setflag[i] = 1;
cos_shift[i] = cos(MY_PI*shift[i]/180.0); cos_shift[i] = cos(DEG2RAD * shift[i]);
sin_shift[i] = sin(MY_PI*shift[i]/180.0); sin_shift[i] = sin(DEG2RAD * shift[i]);
} }
} }
@ -433,4 +432,3 @@ void DihedralCharmm::write_data(FILE *fp)
for (int i = 1; i <= atom->ndihedraltypes; i++) for (int i = 1; i <= atom->ndihedraltypes; i++)
fprintf(fp, "%d %g %d %d %g\n", i, k[i], multiplicity[i], shift[i], weight[i]); fprintf(fp, "%d %g %d %d %g\n", i, k[i], multiplicity[i], shift[i], weight[i]);
} }

View File

@ -1,4 +1,3 @@
// clang-format off
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories https://www.lammps.org/, Sandia National Laboratories
@ -35,13 +34,13 @@
#include <cmath> #include <cmath>
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using namespace MathConst; using MathConst::DEG2RAD;
#define TOLERANCE 0.05 static constexpr double TOLERANCE = 0.05;
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
DihedralCharmmfsw::DihedralCharmmfsw(LAMMPS *lmp) : Dihedral(lmp) DihedralCharmmfsw::DihedralCharmmfsw(LAMMPS *_lmp) : Dihedral(_lmp)
{ {
weightflag = 0; weightflag = 0;
writedata = 1; writedata = 1;
@ -147,8 +146,7 @@ void DihedralCharmmfsw::compute(int eflag, int vflag)
// error check // error check
if (c > 1.0 + TOLERANCE || c < (-1.0 - TOLERANCE)) if (c > 1.0 + TOLERANCE || c < (-1.0 - TOLERANCE)) problem(FLERR, i1, i2, i3, i4);
problem(FLERR, i1, i2, i3, i4);
if (c > 1.0) c = 1.0; if (c > 1.0) c = 1.0;
if (c < -1.0) c = -1.0; if (c < -1.0) c = -1.0;
@ -241,8 +239,8 @@ void DihedralCharmmfsw::compute(int eflag, int vflag)
} }
if (evflag) if (evflag)
ev_tally(i1,i2,i3,i4,nlocal,newton_bond,edihedral,f1,f3,f4, ev_tally(i1, i2, i3, i4, nlocal, newton_bond, edihedral, f1, f3, f4, vb1x, vb1y, vb1z, vb2x,
vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z); vb2y, vb2z, vb3x, vb3y, vb3z);
// 1-4 LJ and Coulomb interactions // 1-4 LJ and Coulomb interactions
// tally energy/virial in pair, using newton_bond as newton flag // tally energy/virial in pair, using newton_bond as newton flag
@ -264,22 +262,25 @@ void DihedralCharmmfsw::compute(int eflag, int vflag)
// for r < cut_inner, so switching not applied // for r < cut_inner, so switching not applied
r = sqrt(rsq); r = sqrt(rsq);
if (implicit) forcecoul = qqrd2e * q[i1]*q[i4]*r2inv; if (implicit)
else if (dihedflag) forcecoul = qqrd2e * q[i1]*q[i4]*sqrt(r2inv); forcecoul = qqrd2e * q[i1] * q[i4] * r2inv;
else forcecoul = qqrd2e * q[i1]*q[i4]*(sqrt(r2inv) - else if (dihedflag)
r*cut_coulinv14*cut_coulinv14); forcecoul = qqrd2e * q[i1] * q[i4] * sqrt(r2inv);
else
forcecoul = qqrd2e * q[i1] * q[i4] * (sqrt(r2inv) - r * cut_coulinv14 * cut_coulinv14);
forcelj = r6inv * (lj14_1[itype][jtype] * r6inv - lj14_2[itype][jtype]); forcelj = r6inv * (lj14_1[itype][jtype] * r6inv - lj14_2[itype][jtype]);
fpair = weight[type] * (forcelj + forcecoul) * r2inv; fpair = weight[type] * (forcelj + forcecoul) * r2inv;
if (eflag) { if (eflag) {
if (dihedflag) ecoul = weight[type] * forcecoul; if (dihedflag)
else ecoul = weight[type] * qqrd2e * q[i1]*q[i4] * ecoul = weight[type] * forcecoul;
(sqrt(r2inv) + r*cut_coulinv14*cut_coulinv14 - else
2.0*cut_coulinv14); ecoul = weight[type] * qqrd2e * q[i1] * q[i4] *
(sqrt(r2inv) + r * cut_coulinv14 * cut_coulinv14 - 2.0 * cut_coulinv14);
evdwl14_12 = r6inv * lj14_3[itype][jtype] * r6inv - evdwl14_12 = r6inv * lj14_3[itype][jtype] * r6inv -
lj14_3[itype][jtype] * cut_lj_inner6inv * cut_lj6inv; lj14_3[itype][jtype] * cut_lj_inner6inv * cut_lj6inv;
evdwl14_6 = -lj14_4[itype][jtype]*r6inv + evdwl14_6 =
lj14_4[itype][jtype]*cut_lj_inner3inv*cut_lj3inv; -lj14_4[itype][jtype] * r6inv + lj14_4[itype][jtype] * cut_lj_inner3inv * cut_lj3inv;
evdwl = evdwl14_12 + evdwl14_6; evdwl = evdwl14_12 + evdwl14_6;
evdwl *= weight[type]; evdwl *= weight[type];
} }
@ -295,8 +296,8 @@ void DihedralCharmmfsw::compute(int eflag, int vflag)
f[i4][2] -= delz * fpair; f[i4][2] -= delz * fpair;
} }
if (evflag) force->pair->ev_tally(i1,i4,nlocal,newton_bond, if (evflag)
evdwl,ecoul,fpair,delx,dely,delz); force->pair->ev_tally(i1, i4, nlocal, newton_bond, evdwl, ecoul, fpair, delx, dely, delz);
} }
} }
} }
@ -306,17 +307,17 @@ void DihedralCharmmfsw::compute(int eflag, int vflag)
void DihedralCharmmfsw::allocate() void DihedralCharmmfsw::allocate()
{ {
allocated = 1; allocated = 1;
int n = atom->ndihedraltypes; const int np1 = atom->ndihedraltypes + 1;
memory->create(k,n+1,"dihedral:k"); memory->create(k, np1, "dihedral:k");
memory->create(multiplicity,n+1,"dihedral:multiplicity"); memory->create(multiplicity, np1, "dihedral:multiplicity");
memory->create(shift,n+1,"dihedral:shift"); memory->create(shift, np1, "dihedral:shift");
memory->create(cos_shift,n+1,"dihedral:cos_shift"); memory->create(cos_shift, np1, "dihedral:cos_shift");
memory->create(sin_shift,n+1,"dihedral:sin_shift"); memory->create(sin_shift, np1, "dihedral:sin_shift");
memory->create(weight,n+1,"dihedral:weight"); memory->create(weight, np1, "dihedral:weight");
memory->create(setflag,n+1,"dihedral:setflag"); memory->create(setflag, np1, "dihedral:setflag");
for (int i = 1; i <= n; i++) setflag[i] = 0; for (int i = 1; i < np1; i++) setflag[i] = 0;
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
@ -350,8 +351,8 @@ void DihedralCharmmfsw::coeff(int narg, char **arg)
for (int i = ilo; i <= ihi; i++) { for (int i = ilo; i <= ihi; i++) {
k[i] = k_one; k[i] = k_one;
shift[i] = shift_one; shift[i] = shift_one;
cos_shift[i] = cos(MY_PI*shift_one/180.0); cos_shift[i] = cos(DEG2RAD * shift_one);
sin_shift[i] = sin(MY_PI*shift_one/180.0); sin_shift[i] = sin(DEG2RAD * shift_one);
multiplicity[i] = multiplicity_one; multiplicity[i] = multiplicity_one;
weight[i] = weight_one; weight[i] = weight_one;
setflag[i] = 1; setflag[i] = 1;
@ -370,11 +371,9 @@ void DihedralCharmmfsw::init_style()
if (utils::strmatch(update->integrate_style, "^respa")) { if (utils::strmatch(update->integrate_style, "^respa")) {
Respa *r = (Respa *) update->integrate; Respa *r = (Respa *) update->integrate;
if (r->level_pair >= 0 && (r->level_pair != r->level_dihedral)) if (r->level_pair >= 0 && (r->level_pair != r->level_dihedral))
error->all(FLERR,"Dihedral style charmmfsw must be set to same" error->all(FLERR, "Dihedral style charmmfsw must be set to same r-RESPA level as 'pair'");
" r-RESPA level as 'pair'");
if (r->level_outer >= 0 && (r->level_outer != r->level_dihedral)) if (r->level_outer >= 0 && (r->level_outer != r->level_dihedral))
error->all(FLERR,"Dihedral style charmmfsw must be set to same" error->all(FLERR, "Dihedral style charmmfsw must be set to same r-RESPA level as 'outer'");
" r-RESPA level as 'outer'");
} }
// insure use of CHARMM pair_style if any weight factors are non-zero // insure use of CHARMM pair_style if any weight factors are non-zero
@ -384,8 +383,9 @@ void DihedralCharmmfsw::init_style()
if (weightflag) { if (weightflag) {
if ((force->special_lj[3] != 0.0) || (force->special_coul[3] != 0.0)) if ((force->special_lj[3] != 0.0) || (force->special_coul[3] != 0.0))
error->all(FLERR,"Must use 'special_bonds charmm' with" error->all(FLERR,
" dihedral style charmm for use with CHARMM pair styles"); "Must use 'special_bonds charmm' with dihedral "
"style charmm for use with CHARMM pair styles");
int itmp; int itmp;
if (force->pair == nullptr) if (force->pair == nullptr)
@ -409,8 +409,8 @@ void DihedralCharmmfsw::init_style()
double *p_cutlj = (double *) force->pair->extract("cut_lj", itmp); double *p_cutlj = (double *) force->pair->extract("cut_lj", itmp);
double *p_cutcoul = (double *) force->pair->extract("cut_coul", itmp); double *p_cutcoul = (double *) force->pair->extract("cut_coul", itmp);
if (p_cutcoul == nullptr || p_cutljinner == nullptr || if (p_cutcoul == nullptr || p_cutljinner == nullptr || p_cutlj == nullptr ||
p_cutlj == nullptr || p_dihedflag == nullptr) p_dihedflag == nullptr)
error->all(FLERR, "Dihedral charmmfsw is incompatible with Pair style"); error->all(FLERR, "Dihedral charmmfsw is incompatible with Pair style");
dihedflag = *p_dihedflag; dihedflag = *p_dihedflag;
@ -419,8 +419,7 @@ void DihedralCharmmfsw::init_style()
cut_lj14 = *p_cutlj; cut_lj14 = *p_cutlj;
cut_coulinv14 = 1 / cut_coul14; cut_coulinv14 = 1 / cut_coul14;
cut_lj_inner3inv = (1/cut_lj_inner14) * (1/cut_lj_inner14) * cut_lj_inner3inv = (1 / cut_lj_inner14) * (1 / cut_lj_inner14) * (1 / cut_lj_inner14);
(1/cut_lj_inner14);
cut_lj_inner6inv = cut_lj_inner3inv * cut_lj_inner3inv; cut_lj_inner6inv = cut_lj_inner3inv * cut_lj_inner3inv;
cut_lj3inv = (1 / cut_lj14) * (1 / cut_lj14) * (1 / cut_lj14); cut_lj3inv = (1 / cut_lj14) * (1 / cut_lj14) * (1 / cut_lj14);
cut_lj6inv = cut_lj3inv * cut_lj3inv; cut_lj6inv = cut_lj3inv * cut_lj3inv;
@ -462,8 +461,8 @@ void DihedralCharmmfsw::read_restart(FILE *fp)
for (int i = 1; i <= atom->ndihedraltypes; i++) { for (int i = 1; i <= atom->ndihedraltypes; i++) {
setflag[i] = 1; setflag[i] = 1;
cos_shift[i] = cos(MY_PI*shift[i]/180.0); cos_shift[i] = cos(DEG2RAD * shift[i]);
sin_shift[i] = sin(MY_PI*shift[i]/180.0); sin_shift[i] = sin(DEG2RAD * shift[i]);
} }
} }
@ -476,4 +475,3 @@ void DihedralCharmmfsw::write_data(FILE *fp)
for (int i = 1; i <= atom->ndihedraltypes; i++) for (int i = 1; i <= atom->ndihedraltypes; i++)
fprintf(fp, "%d %g %d %d %g\n", i, k[i], multiplicity[i], shift[i], weight[i]); fprintf(fp, "%d %g %d %d %g\n", i, k[i], multiplicity[i], shift[i], weight[i]);
} }

View File

@ -1,4 +1,3 @@
// clang-format off
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories https://www.lammps.org/, Sandia National Laboratories
@ -29,12 +28,11 @@
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
#define TOLERANCE 0.05 static constexpr double TOLERANCE = 0.05;
#define SMALL 0.001
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
DihedralHarmonic::DihedralHarmonic(LAMMPS *lmp) : Dihedral(lmp) DihedralHarmonic::DihedralHarmonic(LAMMPS *_lmp) : Dihedral(_lmp)
{ {
writedata = 1; writedata = 1;
} }
@ -129,8 +127,7 @@ void DihedralHarmonic::compute(int eflag, int vflag)
// error check // error check
if (c > 1.0 + TOLERANCE || c < (-1.0 - TOLERANCE)) if (c > 1.0 + TOLERANCE || c < (-1.0 - TOLERANCE)) problem(FLERR, i1, i2, i3, i4);
problem(FLERR, i1, i2, i3, i4);
if (c > 1.0) c = 1.0; if (c > 1.0) c = 1.0;
if (c < -1.0) c = -1.0; if (c < -1.0) c = -1.0;
@ -223,8 +220,8 @@ void DihedralHarmonic::compute(int eflag, int vflag)
} }
if (evflag) if (evflag)
ev_tally(i1,i2,i3,i4,nlocal,newton_bond,edihedral,f1,f3,f4, ev_tally(i1, i2, i3, i4, nlocal, newton_bond, edihedral, f1, f3, f4, vb1x, vb1y, vb1z, vb2x,
vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z); vb2y, vb2z, vb3x, vb3y, vb3z);
} }
} }
@ -233,16 +230,16 @@ void DihedralHarmonic::compute(int eflag, int vflag)
void DihedralHarmonic::allocate() void DihedralHarmonic::allocate()
{ {
allocated = 1; allocated = 1;
int n = atom->ndihedraltypes; const int np1 = atom->ndihedraltypes + 1;
memory->create(k,n+1,"dihedral:k"); memory->create(k, np1, "dihedral:k");
memory->create(sign,n+1,"dihedral:sign"); memory->create(sign, np1, "dihedral:sign");
memory->create(multiplicity,n+1,"dihedral:multiplicity"); memory->create(multiplicity, np1, "dihedral:multiplicity");
memory->create(cos_shift,n+1,"dihedral:cos_shift"); memory->create(cos_shift, np1, "dihedral:cos_shift");
memory->create(sin_shift,n+1,"dihedral:sin_shift"); memory->create(sin_shift, np1, "dihedral:sin_shift");
memory->create(setflag,n+1,"dihedral:setflag"); memory->create(setflag, np1, "dihedral:setflag");
for (int i = 1; i <= n; i++) setflag[i] = 0; for (int i = 1; i < np1; i++) setflag[i] = 0;
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
@ -338,4 +335,3 @@ void DihedralHarmonic::write_data(FILE *fp)
for (int i = 1; i <= atom->ndihedraltypes; i++) for (int i = 1; i <= atom->ndihedraltypes; i++)
fprintf(fp, "%d %g %d %d\n", i, k[i], sign[i], multiplicity[i]); fprintf(fp, "%d %g %d %d\n", i, k[i], sign[i], multiplicity[i]);
} }

View File

@ -1,4 +1,3 @@
// clang-format off
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories https://www.lammps.org/, Sandia National Laboratories
@ -29,12 +28,12 @@
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
#define TOLERANCE 0.05 static constexpr double TOLERANCE = 0.05;
#define SMALL 0.001 static constexpr double SMALL = 0.001;
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
DihedralMultiHarmonic::DihedralMultiHarmonic(LAMMPS *lmp) : Dihedral(lmp) DihedralMultiHarmonic::DihedralMultiHarmonic(LAMMPS *_lmp) : Dihedral(_lmp)
{ {
writedata = 1; writedata = 1;
} }
@ -152,8 +151,7 @@ void DihedralMultiHarmonic::compute(int eflag, int vflag)
// error check // error check
if (c > 1.0 + TOLERANCE || c < (-1.0 - TOLERANCE)) if (c > 1.0 + TOLERANCE || c < (-1.0 - TOLERANCE)) problem(FLERR, i1, i2, i3, i4);
problem(FLERR, i1, i2, i3, i4);
if (c > 1.0) c = 1.0; if (c > 1.0) c = 1.0;
if (c < -1.0) c = -1.0; if (c < -1.0) c = -1.0;
@ -224,8 +222,8 @@ void DihedralMultiHarmonic::compute(int eflag, int vflag)
} }
if (evflag) if (evflag)
ev_tally(i1,i2,i3,i4,nlocal,newton_bond,edihedral,f1,f3,f4, ev_tally(i1, i2, i3, i4, nlocal, newton_bond, edihedral, f1, f3, f4, vb1x, vb1y, vb1z, vb2x,
vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z); vb2y, vb2z, vb3x, vb3y, vb3z);
} }
} }
@ -234,16 +232,16 @@ void DihedralMultiHarmonic::compute(int eflag, int vflag)
void DihedralMultiHarmonic::allocate() void DihedralMultiHarmonic::allocate()
{ {
allocated = 1; allocated = 1;
int n = atom->ndihedraltypes; const int np1 = atom->ndihedraltypes + 1;
memory->create(a1,n+1,"dihedral:a1"); memory->create(a1, np1, "dihedral:a1");
memory->create(a2,n+1,"dihedral:a2"); memory->create(a2, np1, "dihedral:a2");
memory->create(a3,n+1,"dihedral:a3"); memory->create(a3, np1, "dihedral:a3");
memory->create(a4,n+1,"dihedral:a4"); memory->create(a4, np1, "dihedral:a4");
memory->create(a5,n+1,"dihedral:a5"); memory->create(a5, np1, "dihedral:a5");
memory->create(setflag,n+1,"dihedral:setflag"); memory->create(setflag, np1, "dihedral:setflag");
for (int i = 1; i <= n; i++) setflag[i] = 0; for (int i = 1; i < np1; i++) setflag[i] = 0;
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------

View File

@ -1,4 +1,3 @@
// clang-format off
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories https://www.lammps.org/, Sandia National Laboratories
@ -29,13 +28,13 @@
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
#define TOLERANCE 0.05 static constexpr double TOLERANCE = 0.05;
#define SMALL 0.001 static constexpr double SMALL = 0.001;
#define SMALLER 0.00001 static constexpr double SMALLER = 0.00001;
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
DihedralOPLS::DihedralOPLS(LAMMPS *lmp) : Dihedral(lmp) DihedralOPLS::DihedralOPLS(LAMMPS *_lmp) : Dihedral(_lmp)
{ {
writedata = 1; writedata = 1;
} }
@ -158,8 +157,7 @@ void DihedralOPLS::compute(int eflag, int vflag)
// error check // error check
if (c > 1.0 + TOLERANCE || c < (-1.0 - TOLERANCE)) if (c > 1.0 + TOLERANCE || c < (-1.0 - TOLERANCE)) problem(FLERR, i1, i2, i3, i4);
problem(FLERR, i1, i2, i3, i4);
if (c > 1.0) c = 1.0; if (c > 1.0) c = 1.0;
if (c < -1.0) c = -1.0; if (c < -1.0) c = -1.0;
@ -238,8 +236,8 @@ void DihedralOPLS::compute(int eflag, int vflag)
} }
if (evflag) if (evflag)
ev_tally(i1,i2,i3,i4,nlocal,newton_bond,edihedral,f1,f3,f4, ev_tally(i1, i2, i3, i4, nlocal, newton_bond, edihedral, f1, f3, f4, vb1x, vb1y, vb1z, vb2x,
vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z); vb2y, vb2z, vb3x, vb3y, vb3z);
} }
} }
@ -248,15 +246,15 @@ void DihedralOPLS::compute(int eflag, int vflag)
void DihedralOPLS::allocate() void DihedralOPLS::allocate()
{ {
allocated = 1; allocated = 1;
int n = atom->ndihedraltypes; const int np1 = atom->ndihedraltypes + 1;
memory->create(k1,n+1,"dihedral:k1"); memory->create(k1, np1, "dihedral:k1");
memory->create(k2,n+1,"dihedral:k2"); memory->create(k2, np1, "dihedral:k2");
memory->create(k3,n+1,"dihedral:k3"); memory->create(k3, np1, "dihedral:k3");
memory->create(k4,n+1,"dihedral:k4"); memory->create(k4, np1, "dihedral:k4");
memory->create(setflag,n+1,"dihedral:setflag"); memory->create(setflag, np1, "dihedral:setflag");
for (int i = 1; i <= n; i++) setflag[i] = 0; for (int i = 1; i < np1; i++) setflag[i] = 0;
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
@ -334,4 +332,3 @@ void DihedralOPLS::write_data(FILE *fp)
for (int i = 1; i <= atom->ndihedraltypes; i++) for (int i = 1; i <= atom->ndihedraltypes; i++)
fprintf(fp, "%d %g %g %g %g\n", i, 2.0 * k1[i], 2.0 * k2[i], 2.0 * k3[i], 2.0 * k4[i]); fprintf(fp, "%d %g %g %g %g\n", i, 2.0 * k1[i], 2.0 * k2[i], 2.0 * k3[i], 2.0 * k4[i]);
} }