apply clang-format
This commit is contained in:
@ -29,8 +29,8 @@
|
||||
#include "memory.h"
|
||||
#include "neighbor.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
using namespace MathConst;
|
||||
@ -76,11 +76,11 @@ DihedralSpherical::~DihedralSpherical()
|
||||
}
|
||||
}
|
||||
|
||||
static void norm3safe(double *v) {
|
||||
static void norm3safe(double *v)
|
||||
{
|
||||
double inv_scale = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
|
||||
double scale = 1.0;
|
||||
if (inv_scale > 0.0)
|
||||
scale = 1.0 / inv_scale;
|
||||
if (inv_scale > 0.0) scale = 1.0 / inv_scale;
|
||||
v[0] *= scale;
|
||||
v[1] *= scale;
|
||||
v[2] *= scale;
|
||||
@ -138,8 +138,6 @@ static double Phi(double const *x1, //array holding x,y,z coords atom 1
|
||||
return phi;
|
||||
} // DihedralSpherical::Phi()
|
||||
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void DihedralSpherical::compute(int eflag, int vflag)
|
||||
@ -213,7 +211,6 @@ void DihedralSpherical::compute(int eflag, int vflag)
|
||||
edihedral = 0.0;
|
||||
ev_init(eflag, vflag);
|
||||
|
||||
|
||||
for (n = 0; n < ndihedrallist; n++) {
|
||||
|
||||
i1 = dihedrallist[n][0];
|
||||
@ -229,13 +226,10 @@ void DihedralSpherical::compute(int eflag, int vflag)
|
||||
// This function also calculates the vectors:
|
||||
// vb12, vb23, vb34, n123, and n234, which we will need later.
|
||||
|
||||
|
||||
double phi = Phi(x[i1], x[i2], x[i3], x[i4], domain,
|
||||
vb12, vb23, vb34, n123, n234);
|
||||
double phi = Phi(x[i1], x[i2], x[i3], x[i4], domain, vb12, vb23, vb34, n123, n234);
|
||||
|
||||
// Step 2: Compute the gradients of phi, theta1, theta2 with atom position:
|
||||
|
||||
|
||||
// ===================== Step2a) phi dependence: ========================
|
||||
//
|
||||
// Gradient variables:
|
||||
@ -341,7 +335,6 @@ void DihedralSpherical::compute(int eflag, int vflag)
|
||||
dphi_dx3[d] = dphi123_dx3_coef * dphi_dx1[d] + dphi234_dx3_coef * dphi_dx4[d];
|
||||
}
|
||||
|
||||
|
||||
// ============= Step2b) theta1 and theta2 dependence: =============
|
||||
|
||||
// --- Compute the gradient vectors dtheta1/dx1 and dtheta2/dx4: ---
|
||||
@ -450,12 +443,16 @@ void DihedralSpherical::compute(int eflag, int vflag)
|
||||
}
|
||||
|
||||
double ct1 = -dot123 * inv_L12 * inv_L23;
|
||||
if (ct1 < -1.0) ct1 = -1.0;
|
||||
else if (ct1 > 1.0) ct1 = 1.0;
|
||||
if (ct1 < -1.0)
|
||||
ct1 = -1.0;
|
||||
else if (ct1 > 1.0)
|
||||
ct1 = 1.0;
|
||||
double theta1 = acos(ct1);
|
||||
double ct2 = -dot234 * inv_L23 * inv_L34;
|
||||
if (ct2 < -1.0) ct2 = -1.0;
|
||||
else if (ct2 > 1.0) ct2 = 1.0;
|
||||
if (ct2 < -1.0)
|
||||
ct2 = -1.0;
|
||||
else if (ct2 > 1.0)
|
||||
ct2 = 1.0;
|
||||
double theta2 = acos(ct2);
|
||||
|
||||
// - Step 3: Calculate the energy and force in the phi & theta1/2 directions
|
||||
@ -465,9 +462,7 @@ void DihedralSpherical::compute(int eflag, int vflag)
|
||||
double m_du_dth2 = 0.0; // m_du_dth2 = -du / d theta2
|
||||
double m_du_dphi = 0.0; // m_du_dphi = -du / d phi
|
||||
|
||||
u = CalcGeneralizedForces(type,
|
||||
phi, theta1, theta2,
|
||||
&m_du_dth1, &m_du_dth2, &m_du_dphi);
|
||||
u = CalcGeneralizedForces(type, phi, theta1, theta2, &m_du_dth1, &m_du_dth2, &m_du_dphi);
|
||||
|
||||
if (eflag) edihedral = u;
|
||||
|
||||
@ -513,26 +508,15 @@ void DihedralSpherical::compute(int eflag, int vflag)
|
||||
}
|
||||
|
||||
if (evflag)
|
||||
ev_tally(i1,i2,i3,i4,
|
||||
nlocal,newton_bond,edihedral,
|
||||
f1,f3,f4,
|
||||
vb12[0],vb12[1],vb12[2],
|
||||
vb23[0],vb23[1],vb23[2],
|
||||
vb34[0],vb34[1],vb34[2]);
|
||||
ev_tally(i1, i2, i3, i4, nlocal, newton_bond, edihedral, f1, f3, f4, vb12[0], vb12[1],
|
||||
vb12[2], vb23[0], vb23[1], vb23[2], vb34[0], vb34[1], vb34[2]);
|
||||
}
|
||||
} // void DihedralSpherical::compute()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// --- CalcGeneralizedForces() ---
|
||||
// --- Calculate the energy as a function of theta1, theta2, and phi ---
|
||||
// --- as well as its derivatives (with respect to theta1, theta2, and phi) ---
|
||||
|
||||
|
||||
|
||||
// The code above above is sufficiently general that it can work with any
|
||||
// any function of the angles theta1, theta2, and phi. However the
|
||||
// function below calculates the energy and force according to this specific
|
||||
@ -545,16 +529,8 @@ void DihedralSpherical::compute(int eflag, int vflag)
|
||||
// \Theta_{2i}(\theta_2) = cos((\theta_2-b_i)L_i) + v_i
|
||||
// \Phi_i(\phi) = cos((\phi - c_i)M_i) + w_i
|
||||
|
||||
|
||||
|
||||
|
||||
double DihedralSpherical::
|
||||
CalcGeneralizedForces(int type,
|
||||
double phi,
|
||||
double theta1,
|
||||
double theta2,
|
||||
double *m_du_dth1,
|
||||
double *m_du_dth2,
|
||||
double DihedralSpherical::CalcGeneralizedForces(int type, double phi, double theta1, double theta2,
|
||||
double *m_du_dth1, double *m_du_dth2,
|
||||
double *m_du_dphi)
|
||||
{
|
||||
double energy = 0.0;
|
||||
@ -594,23 +570,18 @@ CalcGeneralizedForces(int type,
|
||||
st2 = sin(t2);
|
||||
}
|
||||
|
||||
energy += Ccoeff[i][j] * (phi_offset[i][j] - cp) *
|
||||
(theta1_offset[i][j] - ct1) *
|
||||
energy += Ccoeff[i][j] * (phi_offset[i][j] - cp) * (theta1_offset[i][j] - ct1) *
|
||||
(theta2_offset[i][j] - ct2);
|
||||
|
||||
// Forces:
|
||||
*m_du_dphi += -Ccoeff[i][j] * sp * phi_mult[i][j] *
|
||||
(theta1_offset[i][j] - ct1) *
|
||||
*m_du_dphi += -Ccoeff[i][j] * sp * phi_mult[i][j] * (theta1_offset[i][j] - ct1) *
|
||||
(theta2_offset[i][j] - ct2);
|
||||
|
||||
*m_du_dth1 += -Ccoeff[i][j] * (phi_offset[i][j] - cp) *
|
||||
st1 * theta1_mult[i][j] *
|
||||
*m_du_dth1 += -Ccoeff[i][j] * (phi_offset[i][j] - cp) * st1 * theta1_mult[i][j] *
|
||||
(theta2_offset[i][j] - ct2);
|
||||
|
||||
*m_du_dth2 += -Ccoeff[i][j] * (phi_offset[i][j] - cp) *
|
||||
(theta1_offset[i][j] - ct1) *
|
||||
st2 * theta2_mult[i][j];
|
||||
|
||||
*m_du_dth2 += -Ccoeff[i][j] * (phi_offset[i][j] - cp) * (theta1_offset[i][j] - ct1) * st2 *
|
||||
theta2_mult[i][j];
|
||||
|
||||
// Things to consider later:
|
||||
// To speed up the computation, one could try to simplify the expansion:
|
||||
@ -628,12 +599,6 @@ CalcGeneralizedForces(int type,
|
||||
|
||||
} //CalcGeneralizedForces()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void DihedralSpherical::allocate()
|
||||
{
|
||||
allocated = 1;
|
||||
@ -682,8 +647,7 @@ void DihedralSpherical::coeff(int narg, char **arg)
|
||||
|
||||
int nterms_one = utils::inumeric(FLERR, arg[1], false, lmp);
|
||||
|
||||
if (nterms_one < 1)
|
||||
error->all(FLERR,"Incorrect number of terms arg for dihedral coefficients");
|
||||
if (nterms_one < 1) error->all(FLERR, "Incorrect number of terms arg for dihedral coefficients");
|
||||
|
||||
if (2 + 10 * nterms_one < narg)
|
||||
error->all(FLERR, "Incorrect number of arguments for dihedral coefficients");
|
||||
@ -810,9 +774,6 @@ void DihedralSpherical::read_restart(FILE *fp)
|
||||
for (int i = 1; i <= atom->ndihedraltypes; i++) setflag[i] = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
proc 0 writes to data file
|
||||
------------------------------------------------------------------------- */
|
||||
@ -822,10 +783,9 @@ void DihedralSpherical::write_data(FILE *fp)
|
||||
for (int i = 1; i <= atom->ndihedraltypes; i++) {
|
||||
fprintf(fp, "%d %d ", i, nterms[i]);
|
||||
for (int j = 0; j < nterms[i]; j++) {
|
||||
fprintf(fp, "%g %g %g %g %g %g %g %g %g %g ", Ccoeff[i][j],
|
||||
phi_mult[i][j], phi_shift[i][j]*180.0/MY_PI, phi_offset[i][j],
|
||||
theta1_mult[i][j], theta1_shift[i][j]*180.0/MY_PI,
|
||||
theta1_offset[i][j], theta2_mult[i][j],
|
||||
fprintf(fp, "%g %g %g %g %g %g %g %g %g %g ", Ccoeff[i][j], phi_mult[i][j],
|
||||
phi_shift[i][j] * 180.0 / MY_PI, phi_offset[i][j], theta1_mult[i][j],
|
||||
theta1_shift[i][j] * 180.0 / MY_PI, theta1_offset[i][j], theta2_mult[i][j],
|
||||
theta2_shift[i][j] * 180.0 / MY_PI, theta2_offset[i][j]);
|
||||
}
|
||||
fprintf(fp, "\n");
|
||||
@ -874,4 +834,3 @@ void DihedralSpherical::write_data(FILE *fp)
|
||||
// &m_du_dth1, &m_du_dth2, &m_du_dphi);
|
||||
// return u;
|
||||
//}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user