diff --git a/src/USER-MISC/dihedral_quadratic.cpp b/src/USER-MISC/dihedral_quadratic.cpp index bfe13d13d1..ef5711215c 100644 --- a/src/USER-MISC/dihedral_quadratic.cpp +++ b/src/USER-MISC/dihedral_quadratic.cpp @@ -195,6 +195,8 @@ void DihedralQuadratic::compute(int eflag, int vflag) siinv = 1.0/si; double dphi = phi-phi0[type]; + if (dphi > MY_PI) dphi -= 2*MY_PI; + else if (dphi < -MY_PI) dphi += 2*MY_PI; p = k[type]*dphi; pd = - 2.0 * p * siinv; p = p * dphi; diff --git a/src/USER-OMP/dihedral_quadratic_omp.cpp b/src/USER-OMP/dihedral_quadratic_omp.cpp index 2e25258b13..d183500182 100644 --- a/src/USER-OMP/dihedral_quadratic_omp.cpp +++ b/src/USER-OMP/dihedral_quadratic_omp.cpp @@ -23,11 +23,13 @@ #include "neighbor.h" #include "force.h" #include "update.h" +#include "math_const.h" #include "error.h" #include "suffix.h" using namespace LAMMPS_NS; +using namespace MathConst; #define TOLERANCE 0.05 #define SMALL 0.001 @@ -218,6 +220,8 @@ void DihedralQuadraticOMP::eval(int nfrom, int nto, ThrData * const thr) siinv = 1.0/si; double dphi = phi-phi0[type]; + if (dphi > MY_PI) dphi -= 2*MY_PI; + else if (dphi < -MY_PI) dphi += 2*MY_PI; p = k[type]*dphi; pd = - 2.0 * p * siinv; p = p * dphi;