Apply clang-format to source tree
[alexxy/gromacs.git] / src / gromacs / mdlib / md_support.cpp
index b43e108126a925eb8300e861bf93c873cf39d44d..3f6829005d0262905fd63e38f700fc3735f4483f 100644 (file)
 #include "gromacs/utility/snprintf.h"
 
 // TODO move this to multi-sim module
-bool multisim_int_all_are_equal(const gmx_multisim_t *ms,
-                                int64_t               value)
+bool multisim_int_all_are_equal(const gmx_multisim_t* ms, int64_t value)
 {
-    bool         allValuesAreEqual = true;
-    int64_t     *buf;
+    bool     allValuesAreEqual = true;
+    int64_tbuf;
 
     GMX_RELEASE_ASSERT(ms, "Invalid use of multi-simulation pointer");
 
@@ -105,9 +104,9 @@ bool multisim_int_all_are_equal(const gmx_multisim_t *ms,
     return allValuesAreEqual;
 }
 
-int multisim_min(const gmx_multisim_t *ms, int nmin, int n)
+int multisim_min(const gmx_multisim_tms, int nmin, int n)
 {
-    int     *buf;
+    int*     buf;
     gmx_bool bPos, bEqual;
     int      s, d;
 
@@ -118,7 +117,7 @@ int multisim_min(const gmx_multisim_t *ms, int nmin, int n)
     bEqual = TRUE;
     for (s = 0; s < ms->nsim; s++)
     {
-        bPos   = bPos   && (buf[s] > 0);
+        bPos   = bPos && (buf[s] > 0);
         bEqual = bEqual && (buf[s] == buf[0]);
     }
     if (bPos)
@@ -153,20 +152,34 @@ int multisim_min(const gmx_multisim_t *ms, int nmin, int n)
 
 /* TODO Specialize this routine into init-time and loop-time versions?
    e.g. bReadEkin is only true when restoring from checkpoint */
-void compute_globals(gmx_global_stat *gstat, t_commrec *cr, const t_inputrec *ir,
-                     t_forcerec *fr, gmx_ekindata_t *ekind,
-                     const rvec *x, const rvec *v, const matrix box,
-                     real vdwLambda, const t_mdatoms *mdatoms,
-                     t_nrnb *nrnb, t_vcm *vcm, gmx_wallcycle_t wcycle,
-                     gmx_enerdata_t *enerd, tensor force_vir, tensor shake_vir, tensor total_vir,
-                     tensor pres, rvec mu_tot, gmx::Constraints *constr,
-                     gmx::SimulationSignaller *signalCoordinator,
-                     const matrix lastbox, int *totalNumberOfBondedInteractions,
-                     gmx_bool *bSumEkinhOld, const int flags)
+void compute_globals(gmx_global_stat*          gstat,
+                     t_commrec*                cr,
+                     const t_inputrec*         ir,
+                     t_forcerec*               fr,
+                     gmx_ekindata_t*           ekind,
+                     const rvec*               x,
+                     const rvec*               v,
+                     const matrix              box,
+                     real                      vdwLambda,
+                     const t_mdatoms*          mdatoms,
+                     t_nrnb*                   nrnb,
+                     t_vcm*                    vcm,
+                     gmx_wallcycle_t           wcycle,
+                     gmx_enerdata_t*           enerd,
+                     tensor                    force_vir,
+                     tensor                    shake_vir,
+                     tensor                    total_vir,
+                     tensor                    pres,
+                     rvec                      mu_tot,
+                     gmx::Constraints*         constr,
+                     gmx::SimulationSignaller* signalCoordinator,
+                     const matrix              lastbox,
+                     int*                      totalNumberOfBondedInteractions,
+                     gmx_bool*                 bSumEkinhOld,
+                     const int                 flags)
 {
     gmx_bool bEner, bPres, bTemp;
-    gmx_bool bStopCM, bGStat,
-             bReadEkin, bEkinAveVel, bScaleEkin, bConstrain;
+    gmx_bool bStopCM, bGStat, bReadEkin, bEkinAveVel, bScaleEkin, bConstrain;
     gmx_bool bCheckNumberOfBondedInteractions;
     real     dvdl_ekin;
 
@@ -203,9 +216,7 @@ void compute_globals(gmx_global_stat *gstat, t_commrec *cr, const t_inputrec *ir
         }
         if (!bReadEkin)
         {
-            calc_ke_part(
-                    x, v, box,
-                    &(ir->opts), mdatoms, ekind, nrnb, bEkinAveVel);
+            calc_ke_part(x, v, box, &(ir->opts), mdatoms, ekind, nrnb, bEkinAveVel);
         }
     }
 
@@ -223,7 +234,6 @@ void compute_globals(gmx_global_stat *gstat, t_commrec *cr, const t_inputrec *ir
              * so signal that we still have to do it.
              */
             *bSumEkinhOld = TRUE;
-
         }
         else
         {
@@ -231,11 +241,9 @@ void compute_globals(gmx_global_stat *gstat, t_commrec *cr, const t_inputrec *ir
             if (PAR(cr))
             {
                 wallcycle_start(wcycle, ewcMoveE);
-                global_stat(gstat, cr, enerd, force_vir, shake_vir, mu_tot,
-                            ir, ekind, constr, bStopCM ? vcm : nullptr,
-                            signalBuffer.size(), signalBuffer.data(),
-                            totalNumberOfBondedInteractions,
-                            *bSumEkinhOld, flags);
+                global_stat(gstat, cr, enerd, force_vir, shake_vir, mu_tot, ir, ekind, constr,
+                            bStopCM ? vcm : nullptr, signalBuffer.size(), signalBuffer.data(),
+                            totalNumberOfBondedInteractions, *bSumEkinhOld, flags);
                 wallcycle_stop(wcycle, ewcMoveE);
             }
             signalCoordinator->finalizeSignals();
@@ -246,7 +254,7 @@ void compute_globals(gmx_global_stat *gstat, t_commrec *cr, const t_inputrec *ir
     if (bEner)
     {
         /* Calculate the amplitude of the cosine velocity profile */
-        ekind->cosacc.vcos = ekind->cosacc.mvcos/mdatoms->tmass;
+        ekind->cosacc.vcos = ekind->cosacc.mvcos / mdatoms->tmass;
     }
 
     if (bTemp)
@@ -258,8 +266,7 @@ void compute_globals(gmx_global_stat *gstat, t_commrec *cr, const t_inputrec *ir
            bEkinAveVel: If TRUE, we simply multiply ekin by ekinscale to get a full step kinetic energy.
            If FALSE, we average ekinh_old and ekinh*ekinscale_nhc to get an averaged half step kinetic energy.
          */
-        enerd->term[F_TEMP] = sum_ekin(&(ir->opts), ekind, &dvdl_ekin,
-                                       bEkinAveVel, bScaleEkin);
+        enerd->term[F_TEMP] = sum_ekin(&(ir->opts), ekind, &dvdl_ekin, bEkinAveVel, bScaleEkin);
         enerd->dvdl_lin[efptMASS] = static_cast<double>(dvdl_ekin);
 
         enerd->term[F_EKIN] = trace(ekind->ekin);
@@ -287,12 +294,12 @@ void compute_globals(gmx_global_stat *gstat, t_commrec *cr, const t_inputrec *ir
            total_vir and pres tensors */
 
         const DispersionCorrection::Correction correction =
-            fr->dispersionCorrection->calculate(lastbox, vdwLambda);
+                fr->dispersionCorrection->calculate(lastbox, vdwLambda);
 
         if (bEner)
         {
-            enerd->term[F_DISPCORR]  = correction.energy;
-            enerd->term[F_EPOT]     += correction.energy;
+            enerd->term[F_DISPCORR] = correction.energy;
+            enerd->term[F_EPOT] += correction.energy;
             enerd->term[F_DVDL_VDW] += correction.dvdl;
         }
         if (bPres)
@@ -300,16 +307,19 @@ void compute_globals(gmx_global_stat *gstat, t_commrec *cr, const t_inputrec *ir
             correction.correctVirial(total_vir);
             correction.correctPressure(pres);
             enerd->term[F_PDISPCORR] = correction.pressure;
-            enerd->term[F_PRES]     += correction.pressure;
+            enerd->term[F_PRES] += correction.pressure;
         }
     }
 }
 
-void setCurrentLambdasRerun(int64_t step, const t_lambda *fepvals,
-                            const t_trxframe *rerun_fr, const double *lam0,
-                            t_state *globalState)
+void setCurrentLambdasRerun(int64_t           step,
+                            const t_lambda*   fepvals,
+                            const t_trxframe* rerun_fr,
+                            const double*     lam0,
+                            t_state*          globalState)
 {
-    GMX_RELEASE_ASSERT(globalState != nullptr, "setCurrentLambdasGlobalRerun should be called with a valid state object");
+    GMX_RELEASE_ASSERT(globalState != nullptr,
+                       "setCurrentLambdasGlobalRerun should be called with a valid state object");
 
     if (rerun_fr->bLambda)
     {
@@ -320,15 +330,16 @@ void setCurrentLambdasRerun(int64_t step, const t_lambda *fepvals,
         else
         {
             /* find out between which two value of lambda we should be */
-            real frac      = step*fepvals->delta_lambda;
-            int  fep_state = static_cast<int>(std::floor(frac*fepvals->n_lambda));
+            real frac      = step * fepvals->delta_lambda;
+            int  fep_state = static_cast<int>(std::floor(frac * fepvals->n_lambda));
             /* interpolate between this state and the next */
             /* this assumes that the initial lambda corresponds to lambda==0, which is verified in grompp */
-            frac           = frac*fepvals->n_lambda - fep_state;
+            frac = frac * fepvals->n_lambda - fep_state;
             for (int i = 0; i < efptNR; i++)
             {
-                globalState->lambda[i] = lam0[i] + (fepvals->all_lambda[i][fep_state]) +
-                    frac*(fepvals->all_lambda[i][fep_state+1] - fepvals->all_lambda[i][fep_state]);
+                globalState->lambda[i] =
+                        lam0[i] + (fepvals->all_lambda[i][fep_state])
+                        + frac * (fepvals->all_lambda[i][fep_state + 1] - fepvals->all_lambda[i][fep_state]);
             }
         }
     }
@@ -342,26 +353,28 @@ void setCurrentLambdasRerun(int64_t step, const t_lambda *fepvals,
     }
 }
 
-void setCurrentLambdasLocal(const int64_t step, const t_lambda *fepvals,
-                            const double *lam0, gmx::ArrayRef<real> lambda,
-                            const int currentFEPState)
+void setCurrentLambdasLocal(const int64_t       step,
+                            const t_lambda*     fepvals,
+                            const double*       lam0,
+                            gmx::ArrayRef<real> lambda,
+                            const int           currentFEPState)
 /* find the current lambdas.  If rerunning, we either read in a state, or a lambda value,
    requiring different logic. */
 {
     if (fepvals->delta_lambda != 0)
     {
         /* find out between which two value of lambda we should be */
-        real frac = step*fepvals->delta_lambda;
+        real frac = step * fepvals->delta_lambda;
         if (fepvals->n_lambda > 0)
         {
-            int fep_state = static_cast<int>(std::floor(frac*fepvals->n_lambda));
+            int fep_state = static_cast<int>(std::floor(frac * fepvals->n_lambda));
             /* interpolate between this state and the next */
             /* this assumes that the initial lambda corresponds to lambda==0, which is verified in grompp */
-            frac          = frac*fepvals->n_lambda - fep_state;
+            frac = frac * fepvals->n_lambda - fep_state;
             for (int i = 0; i < efptNR; i++)
             {
-                lambda[i] = lam0[i] + (fepvals->all_lambda[i][fep_state]) +
-                    frac*(fepvals->all_lambda[i][fep_state + 1] - fepvals->all_lambda[i][fep_state]);
+                lambda[i] = lam0[i] + (fepvals->all_lambda[i][fep_state])
+                            + frac * (fepvals->all_lambda[i][fep_state + 1] - fepvals->all_lambda[i][fep_state]);
             }
         }
         else
@@ -385,7 +398,7 @@ void setCurrentLambdasLocal(const int64_t step, const t_lambda *fepvals,
     }
 }
 
-static void min_zero(int *n, int i)
+static void min_zero(intn, int i)
 {
     if (i > 0 && (*n == 0 || i < *n))
     {
@@ -407,10 +420,9 @@ static int lcd4(int i1, int i2, int i3, int i4)
         gmx_incons("All 4 inputs for determining nstglobalcomm are <= 0");
     }
 
-    while (nst > 1 && ((i1 > 0 && i1 % nst != 0)  ||
-                       (i2 > 0 && i2 % nst != 0)  ||
-                       (i3 > 0 && i3 % nst != 0)  ||
-                       (i4 > 0 && i4 % nst != 0)))
+    while (nst > 1
+           && ((i1 > 0 && i1 % nst != 0) || (i2 > 0 && i2 % nst != 0) || (i3 > 0 && i3 % nst != 0)
+               || (i4 > 0 && i4 % nst != 0)))
     {
         nst--;
     }
@@ -418,17 +430,12 @@ static int lcd4(int i1, int i2, int i3, int i4)
     return nst;
 }
 
-int computeGlobalCommunicationPeriod(const gmx::MDLogger &mdlog,
-                                     t_inputrec          *ir,
-                                     const t_commrec     *cr)
+int computeGlobalCommunicationPeriod(const gmx::MDLogger& mdlog, t_inputrec* ir, const t_commrec* cr)
 {
     int nstglobalcomm;
     {
         // Set up the default behaviour
-        if (!(ir->nstcalcenergy > 0 ||
-              ir->nstlist > 0 ||
-              ir->etc != etcNO ||
-              ir->epc != epcNO))
+        if (!(ir->nstcalcenergy > 0 || ir->nstlist > 0 || ir->etc != etcNO || ir->epc != epcNO))
         {
             /* The user didn't choose the period for anything
                important, so we just make sure we can send signals and
@@ -450,9 +457,7 @@ int computeGlobalCommunicationPeriod(const gmx::MDLogger &mdlog,
              * here a leftover of the twin-range scheme? Can we remove
              * nstlist when we remove the group scheme?
              */
-            nstglobalcomm = lcd4(ir->nstcalcenergy,
-                                 ir->nstlist,
-                                 ir->etc != etcNO ? ir->nsttcouple : 0,
+            nstglobalcomm = lcd4(ir->nstcalcenergy, ir->nstlist, ir->etc != etcNO ? ir->nsttcouple : 0,
                                  ir->epc != epcNO ? ir->nstpcouple : 0);
         }
     }
@@ -461,25 +466,24 @@ int computeGlobalCommunicationPeriod(const gmx::MDLogger &mdlog,
     // a (performance) note and mdrun should not change ir.
     if (ir->comm_mode != ecmNO && ir->nstcomm < nstglobalcomm)
     {
-        GMX_LOG(mdlog.warning).asParagraph().appendTextFormatted(
-                "WARNING: Changing nstcomm from %d to %d",
-                ir->nstcomm, nstglobalcomm);
+        GMX_LOG(mdlog.warning)
+                .asParagraph()
+                .appendTextFormatted("WARNING: Changing nstcomm from %d to %d", ir->nstcomm, nstglobalcomm);
         ir->nstcomm = nstglobalcomm;
     }
 
     if (cr->nnodes > 1)
     {
-        GMX_LOG(mdlog.info).appendTextFormatted(
-                "Intra-simulation communication will occur every %d steps.\n", nstglobalcomm);
+        GMX_LOG(mdlog.info)
+                .appendTextFormatted("Intra-simulation communication will occur every %d steps.\n",
+                                     nstglobalcomm);
     }
     return nstglobalcomm;
-
 }
 
-void rerun_parallel_comm(t_commrec *cr, t_trxframe *fr,
-                         gmx_bool *bLastStep)
+void rerun_parallel_comm(t_commrec* cr, t_trxframe* fr, gmx_bool* bLastStep)
 {
-    rvec    *xp, *vp;
+    rvec *xp, *vp;
 
     if (MASTER(cr) && *bLastStep)
     {
@@ -492,11 +496,10 @@ void rerun_parallel_comm(t_commrec *cr, t_trxframe *fr,
     fr->v = vp;
 
     *bLastStep = (fr->natoms < 0);
-
 }
 
 // TODO Most of this logic seems to belong in the respective modules
-void set_state_entries(t_state *state, const t_inputrec *ir)
+void set_state_entries(t_state* state, const t_inputrec* ir)
 {
     /* The entries in the state in the tpx file might not correspond
      * with what is needed, so we correct this here.
@@ -504,57 +507,59 @@ void set_state_entries(t_state *state, const t_inputrec *ir)
     state->flags = 0;
     if (ir->efep != efepNO || ir->bExpanded)
     {
-        state->flags |= (1<<estLAMBDA);
-        state->flags |= (1<<estFEPSTATE);
+        state->flags |= (1 << estLAMBDA);
+        state->flags |= (1 << estFEPSTATE);
     }
-    state->flags |= (1<<estX);
-    GMX_RELEASE_ASSERT(state->x.size() == state->natoms, "We should start a run with an initialized state->x");
+    state->flags |= (1 << estX);
+    GMX_RELEASE_ASSERT(state->x.size() == state->natoms,
+                       "We should start a run with an initialized state->x");
     if (EI_DYNAMICS(ir->eI))
     {
-        state->flags |= (1<<estV);
+        state->flags |= (1 << estV);
     }
 
     state->nnhpres = 0;
     if (ir->ePBC != epbcNONE)
     {
-        state->flags |= (1<<estBOX);
+        state->flags |= (1 << estBOX);
         if (inputrecPreserveShape(ir))
         {
-            state->flags |= (1<<estBOX_REL);
+            state->flags |= (1 << estBOX_REL);
         }
         if ((ir->epc == epcPARRINELLORAHMAN) || (ir->epc == epcMTTK))
         {
-            state->flags |= (1<<estBOXV);
-            state->flags |= (1<<estPRES_PREV);
+            state->flags |= (1 << estBOXV);
+            state->flags |= (1 << estPRES_PREV);
         }
         if (inputrecNptTrotter(ir) || (inputrecNphTrotter(ir)))
         {
             state->nnhpres = 1;
-            state->flags  |= (1<<estNHPRES_XI);
-            state->flags  |= (1<<estNHPRES_VXI);
-            state->flags  |= (1<<estSVIR_PREV);
-            state->flags  |= (1<<estFVIR_PREV);
-            state->flags  |= (1<<estVETA);
-            state->flags  |= (1<<estVOL0);
+            state->flags |= (1 << estNHPRES_XI);
+            state->flags |= (1 << estNHPRES_VXI);
+            state->flags |= (1 << estSVIR_PREV);
+            state->flags |= (1 << estFVIR_PREV);
+            state->flags |= (1 << estVETA);
+            state->flags |= (1 << estVOL0);
         }
         if (ir->epc == epcBERENDSEN)
         {
-            state->flags  |= (1<<estBAROS_INT);
+            state->flags |= (1 << estBAROS_INT);
         }
     }
 
     if (ir->etc == etcNOSEHOOVER)
     {
-        state->flags |= (1<<estNH_XI);
-        state->flags |= (1<<estNH_VXI);
+        state->flags |= (1 << estNH_XI);
+        state->flags |= (1 << estNH_VXI);
     }
 
     if (ir->etc == etcVRESCALE || ir->etc == etcBERENDSEN)
     {
-        state->flags |= (1<<estTHERM_INT);
+        state->flags |= (1 << estTHERM_INT);
     }
 
-    init_gtc_state(state, state->ngtc, state->nnhpres, ir->opts.nhchainlength); /* allocate the space for nose-hoover chains */
+    init_gtc_state(state, state->ngtc, state->nnhpres,
+                   ir->opts.nhchainlength); /* allocate the space for nose-hoover chains */
     init_ekinstate(&state->ekinstate, ir);
 
     if (ir->bExpanded)
@@ -565,6 +570,6 @@ void set_state_entries(t_state *state, const t_inputrec *ir)
 
     if (ir->pull && ir->pull->bSetPbcRefToPrevStepCOM)
     {
-        state->flags |= (1<<estPULLCOMPREVSTEP);
+        state->flags |= (1 << estPULLCOMPREVSTEP);
     }
 }