Apply clang-format to source tree
[alexxy/gromacs.git] / src / gromacs / pbcutil / pbc.cpp
index 7cab160d884b436aec3965071521da4952bad4e2..b60c20aa2dfeb2c54312a60637308ede8c2e87e9 100644 (file)
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
 
-const char *epbc_names[epbcNR+1] =
-{
-    "xyz", "no", "xy", "screw", nullptr
-};
+const char* epbc_names[epbcNR + 1] = { "xyz", "no", "xy", "screw", nullptr };
 
 /* Skip 0 so we have more chance of detecting if we forgot to call set_pbc. */
-enum {
-    epbcdxRECTANGULAR = 1, epbcdxTRICLINIC,
-    epbcdx2D_RECT,       epbcdx2D_TRIC,
-    epbcdx1D_RECT,       epbcdx1D_TRIC,
-    epbcdxSCREW_RECT,    epbcdxSCREW_TRIC,
-    epbcdxNOPBC,         epbcdxUNSUPPORTED
+enum
+{
+    epbcdxRECTANGULAR = 1,
+    epbcdxTRICLINIC,
+    epbcdx2D_RECT,
+    epbcdx2D_TRIC,
+    epbcdx1D_RECT,
+    epbcdx1D_TRIC,
+    epbcdxSCREW_RECT,
+    epbcdxSCREW_TRIC,
+    epbcdxNOPBC,
+    epbcdxUNSUPPORTED
 };
 
 //! Margin factor for error message
-#define BOX_MARGIN         1.0010
+#define BOX_MARGIN 1.0010
 //! Margin correction if the box is too skewed
 #define BOX_MARGIN_CORRECT 1.0005
 
@@ -87,17 +90,17 @@ int ePBC2npbcdim(int ePBC)
 
     switch (ePBC)
     {
-        case epbcXYZ:   npbcdim = 3; break;
-        case epbcXY:    npbcdim = 2; break;
+        case epbcXYZ: npbcdim = 3; break;
+        case epbcXY: npbcdim = 2; break;
         case epbcSCREW: npbcdim = 3; break;
-        case epbcNONE:  npbcdim = 0; break;
+        case epbcNONE: npbcdim = 0; break;
         default: gmx_fatal(FARGS, "Unknown ePBC=%d in ePBC2npbcdim", ePBC);
     }
 
     return npbcdim;
 }
 
-void dump_pbc(FILE *fp, t_pbc *pbc)
+void dump_pbc(FILE* fp, t_pbc* pbc)
 {
     rvec sum_box;
 
@@ -117,9 +120,9 @@ void dump_pbc(FILE *fp, t_pbc *pbc)
     }
 }
 
-const char *check_box(int ePBC, const matrix box)
+const charcheck_box(int ePBC, const matrix box)
 {
-    const char *ptr;
+    const charptr;
 
     if (ePBC == -1)
     {
@@ -133,16 +136,17 @@ const char *check_box(int ePBC, const matrix box)
 
     if ((box[XX][YY] != 0) || (box[XX][ZZ] != 0) || (box[YY][ZZ] != 0))
     {
-        ptr = "Only triclinic boxes with the first vector parallel to the x-axis and the second vector in the xy-plane are supported.";
+        ptr = "Only triclinic boxes with the first vector parallel to the x-axis and the second "
+              "vector in the xy-plane are supported.";
     }
     else if (ePBC == epbcSCREW && (box[YY][XX] != 0 || box[ZZ][XX] != 0))
     {
         ptr = "The unit cell can not have off-diagonal x-components with screw pbc";
     }
-    else if (std::fabs(box[YY][XX]) > BOX_MARGIN*0.5*box[XX][XX] ||
-             (ePBC != epbcXY &&
-              (std::fabs(box[ZZ][XX]) > BOX_MARGIN*0.5*box[XX][XX] ||
-               std::fabs(box[ZZ][YY]) > BOX_MARGIN*0.5*box[YY][YY])))
+    else if (std::fabs(box[YY][XX]) > BOX_MARGIN * 0.5 * box[XX][XX]
+             || (ePBC != epbcXY
+                 && (std::fabs(box[ZZ][XX]) > BOX_MARGIN * 0.5 * box[XX][XX]
+                     || std::fabs(box[ZZ][YY]) > BOX_MARGIN * 0.5 * box[YY][YY])))
     {
         ptr = "Triclinic box is too skewed.";
     }
@@ -159,13 +163,12 @@ void matrix_convert(matrix box, const rvec vec, const rvec angleInDegrees)
     rvec angle;
     svmul(DEG2RAD, angleInDegrees, angle);
     box[XX][XX] = vec[XX];
-    box[YY][XX] = vec[YY]*cos(angle[ZZ]);
-    box[YY][YY] = vec[YY]*sin(angle[ZZ]);
-    box[ZZ][XX] = vec[ZZ]*cos(angle[YY]);
-    box[ZZ][YY] = vec[ZZ]
-        *(cos(angle[XX])-cos(angle[YY])*cos(angle[ZZ]))/sin(angle[ZZ]);
-    box[ZZ][ZZ] = std::sqrt(gmx::square(vec[ZZ])
-                            -box[ZZ][XX]*box[ZZ][XX]-box[ZZ][YY]*box[ZZ][YY]);
+    box[YY][XX] = vec[YY] * cos(angle[ZZ]);
+    box[YY][YY] = vec[YY] * sin(angle[ZZ]);
+    box[ZZ][XX] = vec[ZZ] * cos(angle[YY]);
+    box[ZZ][YY] = vec[ZZ] * (cos(angle[XX]) - cos(angle[YY]) * cos(angle[ZZ])) / sin(angle[ZZ]);
+    box[ZZ][ZZ] =
+            std::sqrt(gmx::square(vec[ZZ]) - box[ZZ][XX] * box[ZZ][XX] - box[ZZ][YY] * box[ZZ][YY]);
 }
 
 real max_cutoff2(int ePBC, const matrix box)
@@ -196,7 +199,7 @@ real max_cutoff2(int ePBC, const matrix box)
         min_ss = std::min(box[XX][XX], std::min(box[YY][YY] - std::fabs(box[ZZ][YY]), box[ZZ][ZZ]));
     }
 
-    return std::min(min_hv2, min_ss*min_ss);
+    return std::min(min_hv2, min_ss * min_ss);
 }
 
 //! Set to true if warning has been printed
@@ -222,7 +225,8 @@ int guess_ePBC(const matrix box)
     {
         if (!bWarnedGuess)
         {
-            fprintf(stderr, "WARNING: Unsupported box diagonal %f %f %f, "
+            fprintf(stderr,
+                    "WARNING: Unsupported box diagonal %f %f %f, "
                     "will not use periodic boundary conditions\n\n",
                     box[XX][XX], box[YY][YY], box[ZZ][ZZ]);
             bWarnedGuess = TRUE;
@@ -239,14 +243,14 @@ int guess_ePBC(const matrix box)
 }
 
 //! Check if the box still obeys the restrictions, if not, correct it
-static int correct_box_elem(FILE *fplog, int step, tensor box, int v, int d)
+static int correct_box_elem(FILEfplog, int step, tensor box, int v, int d)
 {
     int shift, maxshift = 10;
 
     shift = 0;
 
     /* correct elem d of vector v with vector d */
-    while (box[v][d] > BOX_MARGIN_CORRECT*0.5*box[d][d])
+    while (box[v][d] > BOX_MARGIN_CORRECT * 0.5 * box[d][d])
     {
         if (fplog)
         {
@@ -261,12 +265,10 @@ static int correct_box_elem(FILE *fplog, int step, tensor box, int v, int d)
         }
         if (shift <= -maxshift)
         {
-            gmx_fatal(FARGS,
-                      "Box was shifted at least %d times. Please see log-file.",
-                      maxshift);
+            gmx_fatal(FARGS, "Box was shifted at least %d times. Please see log-file.", maxshift);
         }
     }
-    while (box[v][d] < -BOX_MARGIN_CORRECT*0.5*box[d][d])
+    while (box[v][d] < -BOX_MARGIN_CORRECT * 0.5 * box[d][d])
     {
         if (fplog)
         {
@@ -281,16 +283,14 @@ static int correct_box_elem(FILE *fplog, int step, tensor box, int v, int d)
         }
         if (shift >= maxshift)
         {
-            gmx_fatal(FARGS,
-                      "Box was shifted at least %d times. Please see log-file.",
-                      maxshift);
+            gmx_fatal(FARGS, "Box was shifted at least %d times. Please see log-file.", maxshift);
         }
     }
 
     return shift;
 }
 
-gmx_bool correct_box(FILE *fplog, int step, tensor box, t_graph *graph)
+gmx_bool correct_box(FILE* fplog, int step, tensor box, t_graph* graph)
 {
     int      zy, zx, yx, i;
     gmx_bool bCorrected;
@@ -306,9 +306,9 @@ gmx_bool correct_box(FILE *fplog, int step, tensor box, t_graph *graph)
         /* correct the graph */
         for (i = graph->at_start; i < graph->at_end; i++)
         {
-            graph->ishift[i][YY] -= graph->ishift[i][ZZ]*zy;
-            graph->ishift[i][XX] -= graph->ishift[i][ZZ]*zx;
-            graph->ishift[i][XX] -= graph->ishift[i][YY]*yx;
+            graph->ishift[i][YY] -= graph->ishift[i][ZZ] * zy;
+            graph->ishift[i][XX] -= graph->ishift[i][ZZ] * zx;
+            graph->ishift[i][XX] -= graph->ishift[i][YY] * yx;
         }
     }
 
@@ -316,12 +316,11 @@ gmx_bool correct_box(FILE *fplog, int step, tensor box, t_graph *graph)
 }
 
 //! Do the real arithmetic for filling the pbc struct
-static void low_set_pbc(t_pbc *pbc, int ePBC,
-                        const ivec dd_pbc, const matrix box)
+static void low_set_pbc(t_pbc* pbc, int ePBC, const ivec dd_pbc, const matrix box)
 {
     int         order[3] = { 0, -1, 1 };
     ivec        bPBC;
-    const char *ptr;
+    const charptr;
 
     pbc->ePBC      = ePBC;
     pbc->ndim_ePBC = ePBC2npbcdim(ePBC);
@@ -334,23 +333,23 @@ static void low_set_pbc(t_pbc *pbc, int ePBC,
     }
 
     copy_mat(box, pbc->box);
-    pbc->max_cutoff2    = 0;
-    pbc->dim            = -1;
-    pbc->ntric_vec      = 0;
+    pbc->max_cutoff2 = 0;
+    pbc->dim         = -1;
+    pbc->ntric_vec   = 0;
 
     for (int i = 0; (i < DIM); i++)
     {
-        pbc->fbox_diag[i]  =  box[i][i];
-        pbc->hbox_diag[i]  =  pbc->fbox_diag[i]*0.5;
+        pbc->fbox_diag[i]  = box[i][i];
+        pbc->hbox_diag[i]  = pbc->fbox_diag[i] * 0.5;
         pbc->mhbox_diag[i] = -pbc->hbox_diag[i];
     }
 
     ptr = check_box(ePBC, box);
     if (ptr)
     {
-        fprintf(stderr,   "Warning: %s\n", ptr);
+        fprintf(stderr, "Warning: %s\n", ptr);
         pr_rvecs(stderr, 0, "         Box", box, DIM);
-        fprintf(stderr,   "         Can not fix pbc.\n\n");
+        fprintf(stderr, "         Can not fix pbc.\n\n");
         pbc->ePBCDX = epbcdxUNSUPPORTED;
     }
     else
@@ -444,15 +443,11 @@ static void low_set_pbc(t_pbc *pbc, int ePBC,
                     }
                 }
                 break;
-            default:
-                gmx_fatal(FARGS, "Incorrect number of pbc dimensions with DD: %d",
-                          npbcdim);
+            default: gmx_fatal(FARGS, "Incorrect number of pbc dimensions with DD: %d", npbcdim);
         }
         pbc->max_cutoff2 = max_cutoff2(ePBC, box);
 
-        if (pbc->ePBCDX == epbcdxTRICLINIC ||
-            pbc->ePBCDX == epbcdx2D_TRIC ||
-            pbc->ePBCDX == epbcdxSCREW_TRIC)
+        if (pbc->ePBCDX == epbcdxTRICLINIC || pbc->ePBCDX == epbcdx2D_TRIC || pbc->ePBCDX == epbcdxSCREW_TRIC)
         {
             if (debug)
             {
@@ -491,7 +486,7 @@ static void low_set_pbc(t_pbc *pbc, int ePBC,
 
                             for (int d = 0; d < DIM; d++)
                             {
-                                trial[d] = i*box[XX][d] + j*box[YY][d] + k*box[ZZ][d];
+                                trial[d] = i * box[XX][d] + j * box[YY][d] + k * box[ZZ][d];
                                 /* Choose the vector within the brick around 0,0,0 that
                                  * will become the shortest due to shift try.
                                  */
@@ -504,7 +499,7 @@ static void low_set_pbc(t_pbc *pbc, int ePBC,
                                 {
                                     if (trial[d] < 0)
                                     {
-                                        pos[d] = std::min( pbc->hbox_diag[d], -trial[d]);
+                                        pos[d] = std::min(pbc->hbox_diag[d], -trial[d]);
                                     }
                                     else
                                     {
@@ -514,7 +509,7 @@ static void low_set_pbc(t_pbc *pbc, int ePBC,
                                 d2old += gmx::square(pos[d]);
                                 d2new += gmx::square(pos[d] + trial[d]);
                             }
-                            if (BOX_MARGIN*d2new < d2old)
+                            if (BOX_MARGIN * d2new < d2old)
                             {
                                 /* Check if shifts with one box vector less do better */
                                 gmx_bool bUse = TRUE;
@@ -526,9 +521,9 @@ static void low_set_pbc(t_pbc *pbc, int ePBC,
                                         real d2new_c = 0;
                                         for (int d = 0; d < DIM; d++)
                                         {
-                                            d2new_c += gmx::square(pos[d] + trial[d] - shift*box[dd][d]);
+                                            d2new_c += gmx::square(pos[d] + trial[d] - shift * box[dd][d]);
                                         }
-                                        if (d2new_c <= BOX_MARGIN*d2new)
+                                        if (d2new_c <= BOX_MARGIN * d2new)
                                         {
                                             bUse = FALSE;
                                         }
@@ -539,8 +534,12 @@ static void low_set_pbc(t_pbc *pbc, int ePBC,
                                     /* Accept this shift vector. */
                                     if (pbc->ntric_vec >= MAX_NTRICVEC)
                                     {
-                                        fprintf(stderr, "\nWARNING: Found more than %d triclinic correction vectors, ignoring some.\n"
-                                                "  There is probably something wrong with your box.\n", MAX_NTRICVEC);
+                                        fprintf(stderr,
+                                                "\nWARNING: Found more than %d triclinic "
+                                                "correction vectors, ignoring some.\n"
+                                                "  There is probably something wrong with your "
+                                                "box.\n",
+                                                MAX_NTRICVEC);
                                         pr_rvecs(stderr, 0, "         Box", box, DIM);
                                     }
                                     else
@@ -553,10 +552,11 @@ static void low_set_pbc(t_pbc *pbc, int ePBC,
 
                                         if (debug)
                                         {
-                                            fprintf(debug, "  tricvec %2d = %2d %2d %2d  %5.2f %5.2f  %5.2f %5.2f %5.2f  %5.2f %5.2f %5.2f\n",
-                                                    pbc->ntric_vec, i, j, k,
-                                                    sqrt(d2old), sqrt(d2new),
-                                                    trial[XX], trial[YY], trial[ZZ],
+                                            fprintf(debug,
+                                                    "  tricvec %2d = %2d %2d %2d  %5.2f %5.2f  "
+                                                    "%5.2f %5.2f %5.2f  %5.2f %5.2f %5.2f\n",
+                                                    pbc->ntric_vec, i, j, k, sqrt(d2old),
+                                                    sqrt(d2new), trial[XX], trial[YY], trial[ZZ],
                                                     pos[XX], pos[YY], pos[ZZ]);
                                         }
                                     }
@@ -570,7 +570,7 @@ static void low_set_pbc(t_pbc *pbc, int ePBC,
     }
 }
 
-void set_pbc(t_pbc *pbc, int ePBC, const matrix box)
+void set_pbc(t_pbcpbc, int ePBC, const matrix box)
 {
     if (ePBC == -1)
     {
@@ -580,9 +580,7 @@ void set_pbc(t_pbc *pbc, int ePBC, const matrix box)
     low_set_pbc(pbc, ePBC, nullptr, box);
 }
 
-t_pbc *set_pbc_dd(t_pbc *pbc, int ePBC,
-                  const ivec domdecCells,
-                  gmx_bool bSingleDir, const matrix box)
+t_pbc* set_pbc_dd(t_pbc* pbc, int ePBC, const ivec domdecCells, gmx_bool bSingleDir, const matrix box)
 {
     if (ePBC == epbcNONE)
     {
@@ -608,8 +606,7 @@ t_pbc *set_pbc_dd(t_pbc *pbc, int ePBC,
         for (int i = 0; i < DIM; i++)
         {
             usePBC[i] = 0;
-            if (domdecCells[i] <= (bSingleDir ? 1 : 2) &&
-                !(ePBC == epbcXY && i == ZZ))
+            if (domdecCells[i] <= (bSingleDir ? 1 : 2) && !(ePBC == epbcXY && i == ZZ))
             {
                 usePBC[i] = 1;
                 npbcdim++;
@@ -629,7 +626,7 @@ t_pbc *set_pbc_dd(t_pbc *pbc, int ePBC,
     return (pbc->ePBC != epbcNONE ? pbc : nullptr);
 }
 
-void pbc_dx(const t_pbc *pbc, const rvec x1, const rvec x2, rvec dx)
+void pbc_dx(const t_pbcpbc, const rvec x1, const rvec x2, rvec dx)
 {
     int      i, j;
     rvec     dx_start, trial;
@@ -654,7 +651,7 @@ void pbc_dx(const t_pbc *pbc, const rvec x1, const rvec x2, rvec dx)
             }
             break;
         case epbcdxTRICLINIC:
-            for (i = DIM-1; i >= 0; i--)
+            for (i = DIM - 1; i >= 0; i--)
             {
                 while (dx[i] > pbc->hbox_diag[i])
                 {
@@ -712,7 +709,7 @@ void pbc_dx(const t_pbc *pbc, const rvec x1, const rvec x2, rvec dx)
             break;
         case epbcdx2D_TRIC:
             d2min = 0;
-            for (i = DIM-1; i >= 0; i--)
+            for (i = DIM - 1; i >= 0; i--)
             {
                 if (i != pbc->dim)
                 {
@@ -730,7 +727,7 @@ void pbc_dx(const t_pbc *pbc, const rvec x1, const rvec x2, rvec dx)
                             dx[j] += pbc->box[i][j];
                         }
                     }
-                    d2min += dx[i]*dx[i];
+                    d2min += dx[i] * dx[i];
                 }
             }
             if (d2min > pbc->max_cutoff2)
@@ -749,7 +746,7 @@ void pbc_dx(const t_pbc *pbc, const rvec x1, const rvec x2, rvec dx)
                     {
                         if (j != pbc->dim)
                         {
-                            d2trial += trial[j]*trial[j];
+                            d2trial += trial[j] * trial[j];
                         }
                     }
                     if (d2trial < d2min)
@@ -767,12 +764,12 @@ void pbc_dx(const t_pbc *pbc, const rvec x1, const rvec x2, rvec dx)
             while (dx[XX] > pbc->hbox_diag[XX])
             {
                 dx[XX] -= pbc->fbox_diag[XX];
-                bRot    = !bRot;
+                bRot = !bRot;
             }
             while (dx[XX] <= pbc->mhbox_diag[XX])
             {
                 dx[XX] += pbc->fbox_diag[YY];
-                bRot    = !bRot;
+                bRot = !bRot;
             }
             if (bRot)
             {
@@ -794,14 +791,12 @@ void pbc_dx(const t_pbc *pbc, const rvec x1, const rvec x2, rvec dx)
             }
             break;
         case epbcdxNOPBC:
-        case epbcdxUNSUPPORTED:
-            break;
-        default:
-            gmx_fatal(FARGS, "Internal error in pbc_dx, set_pbc has not been called");
+        case epbcdxUNSUPPORTED: break;
+        default: gmx_fatal(FARGS, "Internal error in pbc_dx, set_pbc has not been called");
     }
 }
 
-int pbc_dx_aiuc(const t_pbc *pbc, const rvec x1, const rvec x2, rvec dx)
+int pbc_dx_aiuc(const t_pbcpbc, const rvec x1, const rvec x2, rvec dx)
 {
     int  i, j, is;
     rvec dx_start, trial;
@@ -818,12 +813,12 @@ int pbc_dx_aiuc(const t_pbc *pbc, const rvec x1, const rvec x2, rvec dx)
             {
                 if (dx[i] > pbc->hbox_diag[i])
                 {
-                    dx[i] -=  pbc->fbox_diag[i];
+                    dx[i] -= pbc->fbox_diag[i];
                     ishift[i]--;
                 }
                 else if (dx[i] <= pbc->mhbox_diag[i])
                 {
-                    dx[i] +=  pbc->fbox_diag[i];
+                    dx[i] += pbc->fbox_diag[i];
                     ishift[i]++;
                 }
             }
@@ -836,7 +831,7 @@ int pbc_dx_aiuc(const t_pbc *pbc, const rvec x1, const rvec x2, rvec dx)
              * can cause unlimited displacements.
              * Also allowing multiple shifts would index fshift beyond bounds.
              */
-            for (i = DIM-1; i >= 1; i--)
+            for (i = DIM - 1; i >= 1; i--)
             {
                 if (dx[i] > pbc->hbox_diag[i])
                 {
@@ -921,7 +916,7 @@ int pbc_dx_aiuc(const t_pbc *pbc, const rvec x1, const rvec x2, rvec dx)
             break;
         case epbcdx2D_TRIC:
             d2min = 0;
-            for (i = DIM-1; i >= 1; i--)
+            for (i = DIM - 1; i >= 1; i--)
             {
                 if (i != pbc->dim)
                 {
@@ -941,7 +936,7 @@ int pbc_dx_aiuc(const t_pbc *pbc, const rvec x1, const rvec x2, rvec dx)
                         }
                         ishift[i]++;
                     }
-                    d2min += dx[i]*dx[i];
+                    d2min += dx[i] * dx[i];
                 }
             }
             if (pbc->dim != XX)
@@ -967,7 +962,7 @@ int pbc_dx_aiuc(const t_pbc *pbc, const rvec x1, const rvec x2, rvec dx)
                         ishift[XX]++;
                     }
                 }
-                d2min += dx[XX]*dx[XX];
+                d2min += dx[XX] * dx[XX];
             }
             if (d2min > pbc->max_cutoff2)
             {
@@ -985,7 +980,7 @@ int pbc_dx_aiuc(const t_pbc *pbc, const rvec x1, const rvec x2, rvec dx)
                     {
                         if (j != pbc->dim)
                         {
-                            d2trial += trial[j]*trial[j];
+                            d2trial += trial[j] * trial[j];
                         }
                     }
                     if (d2trial < d2min)
@@ -1058,10 +1053,10 @@ int pbc_dx_aiuc(const t_pbc *pbc, const rvec x1, const rvec x2, rvec dx)
             }
             break;
         case epbcdxNOPBC:
-        case epbcdxUNSUPPORTED:
-            break;
+        case epbcdxUNSUPPORTED: break;
         default:
-            gmx_fatal(FARGS, "Internal error in pbc_dx_aiuc, set_pbc_dd or set_pbc has not been called");
+            gmx_fatal(FARGS,
+                      "Internal error in pbc_dx_aiuc, set_pbc_dd or set_pbc has not been called");
     }
 
     is = IVEC2IS(ishift);
@@ -1074,7 +1069,7 @@ int pbc_dx_aiuc(const t_pbc *pbc, const rvec x1, const rvec x2, rvec dx)
 }
 
 //! Compute distance vector in double precision
-void pbc_dx_d(const t_pbc *pbc, const dvec x1, const dvec x2, dvec dx)
+void pbc_dx_d(const t_pbcpbc, const dvec x1, const dvec x2, dvec dx)
 {
     int      i, j;
     dvec     dx_start, trial;
@@ -1105,7 +1100,7 @@ void pbc_dx_d(const t_pbc *pbc, const dvec x1, const dvec x2, dvec dx)
         case epbcdxTRICLINIC:
         case epbcdx2D_TRIC:
             d2min = 0;
-            for (i = DIM-1; i >= 0; i--)
+            for (i = DIM - 1; i >= 0; i--)
             {
                 if (i != pbc->dim)
                 {
@@ -1123,7 +1118,7 @@ void pbc_dx_d(const t_pbc *pbc, const dvec x1, const dvec x2, dvec dx)
                             dx[j] += pbc->box[i][j];
                         }
                     }
-                    d2min += dx[i]*dx[i];
+                    d2min += dx[i] * dx[i];
                 }
             }
             if (d2min > pbc->max_cutoff2)
@@ -1144,7 +1139,7 @@ void pbc_dx_d(const t_pbc *pbc, const dvec x1, const dvec x2, dvec dx)
                     {
                         if (j != pbc->dim)
                         {
-                            d2trial += trial[j]*trial[j];
+                            d2trial += trial[j] * trial[j];
                         }
                     }
                     if (d2trial < d2min)
@@ -1162,12 +1157,12 @@ void pbc_dx_d(const t_pbc *pbc, const dvec x1, const dvec x2, dvec dx)
             while (dx[XX] > pbc->hbox_diag[XX])
             {
                 dx[XX] -= pbc->fbox_diag[XX];
-                bRot    = !bRot;
+                bRot = !bRot;
             }
             while (dx[XX] <= pbc->mhbox_diag[XX])
             {
                 dx[XX] += pbc->fbox_diag[YY];
-                bRot    = !bRot;
+                bRot = !bRot;
             }
             if (bRot)
             {
@@ -1189,10 +1184,8 @@ void pbc_dx_d(const t_pbc *pbc, const dvec x1, const dvec x2, dvec dx)
             }
             break;
         case epbcdxNOPBC:
-        case epbcdxUNSUPPORTED:
-            break;
-        default:
-            gmx_fatal(FARGS, "Internal error in pbc_dx, set_pbc has not been called");
+        case epbcdxUNSUPPORTED: break;
+        default: gmx_fatal(FARGS, "Internal error in pbc_dx, set_pbc has not been called");
     }
 }
 
@@ -1206,7 +1199,7 @@ void calc_shifts(const matrix box, rvec shift_vec[])
             {
                 for (int d = 0; d < DIM; d++)
                 {
-                    shift_vec[n][d] = k*box[XX][d] + l*box[YY][d] + m*box[ZZ][d];
+                    shift_vec[n][d] = k * box[XX][d] + l * box[YY][d] + m * box[ZZ][d];
                 }
             }
         }
@@ -1225,20 +1218,18 @@ void calc_box_center(int ecenter, const matrix box, rvec box_center)
             {
                 for (d = 0; d < DIM; d++)
                 {
-                    box_center[d] += 0.5*box[m][d];
+                    box_center[d] += 0.5 * box[m][d];
                 }
             }
             break;
         case ecenterRECT:
             for (d = 0; d < DIM; d++)
             {
-                box_center[d] = 0.5*box[d][d];
+                box_center[d] = 0.5 * box[d][d];
             }
             break;
-        case ecenterZERO:
-            break;
-        default:
-            gmx_fatal(FARGS, "Unsupported value %d for ecenter", ecenter);
+        case ecenterZERO: break;
+        default: gmx_fatal(FARGS, "Unsupported value %d for ecenter", ecenter);
     }
 }
 
@@ -1258,7 +1249,7 @@ void calc_triclinic_images(const matrix box, rvec img[])
     /* Get the next 3 in the xy-plane as mirror images */
     for (i = 0; i < 3; i++)
     {
-        svmul(-1, img[i], img[3+i]);
+        svmul(-1, img[i], img[3 + i]);
     }
 
     /* Calculate the first 4 out of xy-plane images */
@@ -1269,13 +1260,13 @@ void calc_triclinic_images(const matrix box, rvec img[])
     }
     for (i = 0; i < 3; i++)
     {
-        rvec_add(img[6], img[i+1], img[7+i]);
+        rvec_add(img[6], img[i + 1], img[7 + i]);
     }
 
     /* Mirror the last 4 from the previous in opposite rotation */
     for (i = 0; i < 4; i++)
     {
-        svmul(-1, img[6 + (2+i) % 4], img[10+i]);
+        svmul(-1, img[6 + (2 + i) % 4], img[10 + i]);
     }
 }
 
@@ -1290,7 +1281,7 @@ void calc_compact_unitcell_vertices(int ecenter, const matrix box, rvec vert[])
     n = 0;
     for (i = 2; i <= 5; i += 3)
     {
-        tmp[0] = i-1;
+        tmp[0] = i - 1;
         if (i == 2)
         {
             tmp[1] = 8;
@@ -1299,21 +1290,21 @@ void calc_compact_unitcell_vertices(int ecenter, const matrix box, rvec vert[])
         {
             tmp[1] = 6;
         }
-        tmp[2] = (i+1) % 6;
-        tmp[3] = tmp[1]+4;
+        tmp[2] = (i + 1) % 6;
+        tmp[3] = tmp[1] + 4;
         for (j = 0; j < 4; j++)
         {
             for (d = 0; d < DIM; d++)
             {
-                vert[n][d] = img[i][d]+img[tmp[j]][d]+img[tmp[(j+1)%4]][d];
+                vert[n][d] = img[i][d] + img[tmp[j]][d] + img[tmp[(j + 1) % 4]][d];
             }
             n++;
         }
     }
     for (i = 7; i <= 13; i += 6)
     {
-        tmp[0] = (i-7)/2;
-        tmp[1] = tmp[0]+1;
+        tmp[0] = (i - 7) / 2;
+        tmp[1] = tmp[0] + 1;
         if (i == 7)
         {
             tmp[2] = 8;
@@ -1322,12 +1313,12 @@ void calc_compact_unitcell_vertices(int ecenter, const matrix box, rvec vert[])
         {
             tmp[2] = 10;
         }
-        tmp[3] = i-1;
+        tmp[3] = i - 1;
         for (j = 0; j < 4; j++)
         {
             for (d = 0; d < DIM; d++)
             {
-                vert[n][d] = img[i][d]+img[tmp[j]][d]+img[tmp[(j+1)%4]][d];
+                vert[n][d] = img[i][d] + img[tmp[j]][d] + img[tmp[(j + 1) % 4]][d];
             }
             n++;
         }
@@ -1342,7 +1333,7 @@ void calc_compact_unitcell_vertices(int ecenter, const matrix box, rvec vert[])
         {
             tmp[0] = 0;
         }
-        tmp[1] = tmp[0]+1;
+        tmp[1] = tmp[0] + 1;
         if (i == 9)
         {
             tmp[2] = 6;
@@ -1351,12 +1342,12 @@ void calc_compact_unitcell_vertices(int ecenter, const matrix box, rvec vert[])
         {
             tmp[2] = 12;
         }
-        tmp[3] = i-1;
+        tmp[3] = i - 1;
         for (j = 0; j < 4; j++)
         {
             for (d = 0; d < DIM; d++)
             {
-                vert[n][d] = img[i][d]+img[tmp[j]][d]+img[tmp[(j+1)%4]][d];
+                vert[n][d] = img[i][d] + img[tmp[j]][d] + img[tmp[(j + 1) % 4]][d];
             }
             n++;
         }
@@ -1367,35 +1358,32 @@ void calc_compact_unitcell_vertices(int ecenter, const matrix box, rvec vert[])
     {
         for (d = 0; d < DIM; d++)
         {
-            vert[i][d] = vert[i][d]*oneFourth+box_center[d];
+            vert[i][d] = vert[i][d] * oneFourth + box_center[d];
         }
     }
 }
 
-int *compact_unitcell_edges()
+intcompact_unitcell_edges()
 {
     /* this is an index in vert[] (see calc_box_vertices) */
     /*static int edge[NCUCEDGE*2];*/
-    int             *edge;
-    static const int hexcon[24] = {
-        0, 9, 1, 19, 2, 15, 3, 21,
-        4, 17, 5, 11, 6, 23, 7, 13,
-        8, 20, 10, 18, 12, 16, 14, 22
-    };
+    int*             edge;
+    static const int hexcon[24] = { 0, 9,  1, 19, 2, 15, 3,  21, 4,  17, 5,  11,
+                                    6, 23, 7, 13, 8, 20, 10, 18, 12, 16, 14, 22 };
     int              e, i, j;
 
-    snew(edge, NCUCEDGE*2);
+    snew(edge, NCUCEDGE * 2);
 
     e = 0;
     for (i = 0; i < 6; i++)
     {
         for (j = 0; j < 4; j++)
         {
-            edge[e++] = 4*i + j;
-            edge[e++] = 4*i + (j+1) % 4;
+            edge[e++] = 4 * i + j;
+            edge[e++] = 4 * i + (j + 1) % 4;
         }
     }
-    for (i = 0; i < 12*2; i++)
+    for (i = 0; i < 12 * 2; i++)
     {
         edge[e++] = hexcon[i];
     }
@@ -1425,7 +1413,7 @@ void put_atoms_in_box(int ePBC, const matrix box, gmx::ArrayRef<gmx::RVec> x)
     {
         for (gmx::index i = 0; (i < x.ssize()); ++i)
         {
-            for (m = npbcdim-1; m >= 0; m--)
+            for (m = npbcdim - 1; m >= 0; m--)
             {
                 while (x[i][m] < 0)
                 {
@@ -1471,28 +1459,27 @@ void put_atoms_in_box_omp(int ePBC, const matrix box, gmx::ArrayRef<gmx::RVec> x
         try
         {
             size_t natoms = x.size();
-            size_t offset = (natoms*t    )/nth;
-            size_t len    = (natoms*(t + 1))/nth - offset;
+            size_t offset = (natoms * t) / nth;
+            size_t len    = (natoms * (t + 1)) / nth - offset;
             put_atoms_in_box(ePBC, box, x.subArray(offset, len));
         }
-        GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
+        GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR
     }
 }
 
-void put_atoms_in_triclinic_unitcell(int ecenter, const matrix box,
-                                     gmx::ArrayRef<gmx::RVec> x)
+void put_atoms_in_triclinic_unitcell(int ecenter, const matrix box, gmx::ArrayRef<gmx::RVec> x)
 {
-    rvec   box_center, shift_center;
-    real   shm01, shm02, shm12, shift;
-    int    m, d;
+    rvec box_center, shift_center;
+    real shm01, shm02, shm12, shift;
+    int  m, d;
 
     calc_box_center(ecenter, box, box_center);
 
     /* The product of matrix shm with a coordinate gives the shift vector
        which is required determine the periodic cell position */
-    shm01 = box[1][0]/box[1][1];
-    shm02 = (box[1][1]*box[2][0] - box[2][1]*box[1][0])/(box[1][1]*box[2][2]);
-    shm12 = box[2][1]/box[2][2];
+    shm01 = box[1][0] / box[1][1];
+    shm02 = (box[1][1] * box[2][0] - box[2][1] * box[1][0]) / (box[1][1] * box[2][2]);
+    shm12 = box[2][1] / box[2][2];
 
     clear_rvec(shift_center);
     for (d = 0; d < DIM; d++)
@@ -1502,31 +1489,31 @@ void put_atoms_in_triclinic_unitcell(int ecenter, const matrix box,
     svmul(0.5, shift_center, shift_center);
     rvec_sub(box_center, shift_center, shift_center);
 
-    shift_center[0] = shm01*shift_center[1] + shm02*shift_center[2];
-    shift_center[1] = shm12*shift_center[2];
+    shift_center[0] = shm01 * shift_center[1] + shm02 * shift_center[2];
+    shift_center[1] = shm12 * shift_center[2];
     shift_center[2] = 0;
 
     for (gmx::index i = 0; (i < x.ssize()); ++i)
     {
-        for (m = DIM-1; m >= 0; m--)
+        for (m = DIM - 1; m >= 0; m--)
         {
             shift = shift_center[m];
             if (m == 0)
             {
-                shift += shm01*x[i][1] + shm02*x[i][2];
+                shift += shm01 * x[i][1] + shm02 * x[i][2];
             }
             else if (m == 1)
             {
-                shift += shm12*x[i][2];
+                shift += shm12 * x[i][2];
             }
-            while (x[i][m]-shift < 0)
+            while (x[i][m] - shift < 0)
             {
                 for (d = 0; d <= m; d++)
                 {
                     x[i][d] += box[m][d];
                 }
             }
-            while (x[i][m]-shift >= box[m][m])
+            while (x[i][m] - shift >= box[m][m])
             {
                 for (d = 0; d <= m; d++)
                 {
@@ -1537,8 +1524,7 @@ void put_atoms_in_triclinic_unitcell(int ecenter, const matrix box,
     }
 }
 
-void put_atoms_in_compact_unitcell(int ePBC, int ecenter, const matrix box,
-                                   gmx::ArrayRef<gmx::RVec> x)
+void put_atoms_in_compact_unitcell(int ePBC, int ecenter, const matrix box, gmx::ArrayRef<gmx::RVec> x)
 {
     t_pbc pbc;
     rvec  box_center, dx;
@@ -1567,12 +1553,10 @@ void put_atoms_in_compact_unitcell(int ePBC, int ecenter, const matrix box,
  * \param[in,out] x         The coordinates of the atoms
  * \param[in]     bFirst    Specifier for first-time PBC removal
  */
-static void low_do_pbc_mtop(FILE *fplog, int ePBC, const matrix box,
-                            const gmx_mtop_t *mtop, rvec x[],
-                            gmx_bool bFirst)
+static void low_do_pbc_mtop(FILE* fplog, int ePBC, const matrix box, const gmx_mtop_t* mtop, rvec x[], gmx_bool bFirst)
 {
-    t_graph        *graph;
-    int             as, mol;
+    t_graphgraph;
+    int      as, mol;
 
     if (bFirst && fplog)
     {
@@ -1581,14 +1565,13 @@ static void low_do_pbc_mtop(FILE *fplog, int ePBC, const matrix box,
 
     snew(graph, 1);
     as = 0;
-    for (const gmx_molblock_t &molb : mtop->molblock)
+    for (const gmx_molblock_tmolb : mtop->molblock)
     {
-        const gmx_moltype_t &moltype = mtop->moltype[molb.type];
-        if (moltype.atoms.nr == 1 ||
-            (!bFirst && moltype.atoms.nr == 1))
+        const gmx_moltype_t& moltype = mtop->moltype[molb.type];
+        if (moltype.atoms.nr == 1 || (!bFirst && moltype.atoms.nr == 1))
         {
             /* Just one atom or charge group in the molecule, no PBC required */
-            as += molb.nmol*moltype.atoms.nr;
+            as += molb.nmol * moltype.atoms.nr;
         }
         else
         {
@@ -1596,9 +1579,9 @@ static void low_do_pbc_mtop(FILE *fplog, int ePBC, const matrix box,
 
             for (mol = 0; mol < molb.nmol; mol++)
             {
-                mk_mshift(fplog, graph, ePBC, box, x+as);
+                mk_mshift(fplog, graph, ePBC, box, x + as);
 
-                shift_self(graph, box, x+as);
+                shift_self(graph, box, x + as);
                 /* The molecule is whole now.
                  * We don't need the second mk_mshift call as in do_pbc_first,
                  * since we no longer need this graph.
@@ -1612,14 +1595,12 @@ static void low_do_pbc_mtop(FILE *fplog, int ePBC, const matrix box,
     sfree(graph);
 }
 
-void do_pbc_first_mtop(FILE *fplog, int ePBC, const matrix box,
-                       const gmx_mtop_t *mtop, rvec x[])
+void do_pbc_first_mtop(FILE* fplog, int ePBC, const matrix box, const gmx_mtop_t* mtop, rvec x[])
 {
     low_do_pbc_mtop(fplog, ePBC, box, mtop, x, TRUE);
 }
 
-void do_pbc_mtop(int ePBC, const matrix box,
-                 const gmx_mtop_t *mtop, rvec x[])
+void do_pbc_mtop(int ePBC, const matrix box, const gmx_mtop_t* mtop, rvec x[])
 {
     low_do_pbc_mtop(nullptr, ePBC, box, mtop, x, FALSE);
 }