Apply clang-format to source tree
[alexxy/gromacs.git] / src / gromacs / mdrun / mimic.cpp
index 2b2f9e9ada232df4e8030e959f0531ef8987ce0c..a86999fb3d8f6b74be7d4e0b09dca67043e12462 100644 (file)
@@ -141,21 +141,21 @@ using gmx::SimulationSignaller;
 
 void gmx::LegacySimulator::do_mimic()
 {
-    t_inputrec                  *ir   = inputrec;
-    int64_t                      step, step_rel;
-    double                       t, lam0[efptNR];
-    bool                         isLastStep               = false;
-    bool                         doFreeEnergyPerturbation = false;
-    unsigned int                 force_flags;
-    tensor                       force_vir, shake_vir, total_vir, pres;
-    rvec                         mu_tot;
-    gmx_localtop_t               top;
-    PaddedHostVector<gmx::RVec>  f {};
-    gmx_global_stat_t            gstat;
-    t_graph                     *graph = nullptr;
-    gmx_shellfc_t               *shellfc;
-
-    double                       cycles;
+    t_inputrec*                 ir = inputrec;
+    int64_t                     step, step_rel;
+    double                      t, lam0[efptNR];
+    bool                        isLastStep               = false;
+    bool                        doFreeEnergyPerturbation = false;
+    unsigned int                force_flags;
+    tensor                      force_vir, shake_vir, total_vir, pres;
+    rvec                        mu_tot;
+    gmx_localtop_t              top;
+    PaddedHostVector<gmx::RVec> f{};
+    gmx_global_stat_t           gstat;
+    t_graph*                    graph = nullptr;
+    gmx_shellfc_t*              shellfc;
+
+    double cycles;
 
     /* Domain decomposition could incorrectly miss a bonded
        interaction, but checking for that requires a global
@@ -163,8 +163,8 @@ void gmx::LegacySimulator::do_mimic()
        code. So we do that alongside the first global energy reduction
        after a new DD is made. These variables handle whether the
        check happens, and the result it returns. */
-    bool              shouldCheckNumberOfBondedInteractions = false;
-    int               totalNumberOfBondedInteractions       = -1;
+    bool shouldCheckNumberOfBondedInteractions = false;
+    int  totalNumberOfBondedInteractions       = -1;
 
     SimulationSignals signals;
     // Most global communnication stages don't propagate mdrun
@@ -200,19 +200,19 @@ void gmx::LegacySimulator::do_mimic()
         gmx_fatal(FARGS, "Multiple simulations not supported by MiMiC.");
     }
     if (std::any_of(ir->opts.annealing, ir->opts.annealing + ir->opts.ngtc,
-                    [](int i){return i != eannNO; }))
+                    [](int i) { return i != eannNO; }))
     {
         gmx_fatal(FARGS, "Simulated annealing not supported by MiMiC.");
     }
 
     /* Settings for rerun */
-    ir->nstlist       = 1;
-    ir->nstcalcenergy = 1;
+    ir->nstlist              = 1;
+    ir->nstcalcenergy        = 1;
     int        nstglobalcomm = 1;
     const bool bNS           = true;
 
     // Communicator to interact with MiMiC
-    MimicCommunicator mimicCommunicator {};
+    MimicCommunicator mimicCommunicator{};
     if (MASTER(cr))
     {
         mimicCommunicator.init();
@@ -221,35 +221,33 @@ void gmx::LegacySimulator::do_mimic()
     }
 
     ir->nstxout_compressed                   = 0;
-    SimulationGroups *groups                        = &top_global->groups;
+    SimulationGroups* groups                 = &top_global->groups;
     top_global->intermolecularExclusionGroup = genQmmmIndices(*top_global);
 
     initialize_lambdas(fplog, *ir, MASTER(cr), &state_global->fep_state, state_global->lambda, lam0);
 
-    gmx_mdoutf        *outf = init_mdoutf(fplog, nfile, fnm, mdrunOptions, cr, outputProvider, mdModulesNotifier, ir, top_global, oenv, wcycle,
-                                          StartingBehavior::NewSimulation);
-    gmx::EnergyOutput  energyOutput(mdoutf_get_fp_ene(outf), top_global, ir, pull_work, mdoutf_get_fp_dhdl(outf), true, mdModulesNotifier);
+    gmx_mdoutf* outf = init_mdoutf(fplog, nfile, fnm, mdrunOptions, cr, outputProvider, mdModulesNotifier,
+                                   ir, top_global, oenv, wcycle, StartingBehavior::NewSimulation);
+    gmx::EnergyOutput energyOutput(mdoutf_get_fp_ene(outf), top_global, ir, pull_work,
+                                   mdoutf_get_fp_dhdl(outf), true, mdModulesNotifier);
 
     gstat = global_stat_init(ir);
 
     /* Check for polarizable models and flexible constraints */
-    shellfc = init_shell_flexcon(fplog,
-                                 top_global, constr ? constr->numFlexibleConstraints() : 0,
+    shellfc = init_shell_flexcon(fplog, top_global, constr ? constr->numFlexibleConstraints() : 0,
                                  ir->nstcalcenergy, DOMAINDECOMP(cr));
 
     {
         double io = compute_io(ir, top_global->natoms, *groups, energyOutput.numEnergyTerms(), 1);
         if ((io > 2000) && MASTER(cr))
         {
-            fprintf(stderr,
-                    "\nWARNING: This run will generate roughly %.0f Mb of data\n\n",
-                    io);
+            fprintf(stderr, "\nWARNING: This run will generate roughly %.0f Mb of data\n\n", io);
         }
     }
 
     // Local state only becomes valid now.
     std::unique_ptr<t_state> stateInstance;
-    t_state *                state;
+    t_state                state;
 
     if (DOMAINDECOMP(cr))
     {
@@ -260,11 +258,8 @@ void gmx::LegacySimulator::do_mimic()
         dd_init_local_state(cr->dd, state_global, state);
 
         /* Distribute the charge groups over the nodes from the master node */
-        dd_partition_system(fplog, mdlog, ir->init_step, cr, TRUE, 1,
-                            state_global, *top_global, ir, imdSession,
-                            pull_work,
-                            state, &f, mdAtoms, &top, fr,
-                            vsite, constr,
+        dd_partition_system(fplog, mdlog, ir->init_step, cr, TRUE, 1, state_global, *top_global, ir,
+                            imdSession, pull_work, state, &f, mdAtoms, &top, fr, vsite, constr,
                             nrnb, nullptr, FALSE);
         shouldCheckNumberOfBondedInteractions = true;
         gmx_bcast(sizeof(ir->nsteps), &ir->nsteps, cr);
@@ -279,8 +274,7 @@ void gmx::LegacySimulator::do_mimic()
         /* Copy the pointer to the global state */
         state = state_global;
 
-        mdAlgorithmsSetupAtomData(cr, ir, *top_global, &top, fr,
-                                  &graph, mdAtoms, constr, vsite, shellfc);
+        mdAlgorithmsSetupAtomData(cr, ir, *top_global, &top, fr, &graph, mdAtoms, constr, vsite, shellfc);
     }
 
     auto mdatoms = mdAtoms->mdatoms();
@@ -298,29 +292,27 @@ void gmx::LegacySimulator::do_mimic()
     }
 
     {
-        int    cglo_flags = (CGLO_GSTAT |
-                             (shouldCheckNumberOfBondedInteractions ?
-                              CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS : 0));
+        int cglo_flags =
+                (CGLO_GSTAT
+                 | (shouldCheckNumberOfBondedInteractions ? CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS : 0));
         bool   bSumEkinhOld = false;
-        t_vcm *vcm          = nullptr;
-        compute_globals(gstat, cr, ir, fr, ekind,
-                        state->x.rvec_array(), state->v.rvec_array(), state->box, state->lambda[efptVDW],
-                        mdatoms, nrnb, vcm,
-                        nullptr, enerd, force_vir, shake_vir, total_vir, pres, mu_tot,
-                        constr, &nullSignaller, state->box,
-                        &totalNumberOfBondedInteractions, &bSumEkinhOld, cglo_flags);
+        t_vcm* vcm          = nullptr;
+        compute_globals(gstat, cr, ir, fr, ekind, state->x.rvec_array(), state->v.rvec_array(),
+                        state->box, state->lambda[efptVDW], mdatoms, nrnb, vcm, nullptr, enerd,
+                        force_vir, shake_vir, total_vir, pres, mu_tot, constr, &nullSignaller,
+                        state->box, &totalNumberOfBondedInteractions, &bSumEkinhOld, cglo_flags);
     }
-    checkNumberOfBondedInteractions(mdlog, cr, totalNumberOfBondedInteractions,
-                                    top_global, &top, state->x.rvec_array(), state->box,
+    checkNumberOfBondedInteractions(mdlog, cr, totalNumberOfBondedInteractions, top_global, &top,
+                                    state->x.rvec_array(), state->box,
                                     &shouldCheckNumberOfBondedInteractions);
 
     if (MASTER(cr))
     {
-        fprintf(stderr, "starting MiMiC MD run '%s'\n\n",
-                *(top_global->name));
+        fprintf(stderr, "starting MiMiC MD run '%s'\n\n", *(top_global->name));
         if (mdrunOptions.verbose)
         {
-            fprintf(stderr, "Calculated time to finish depends on nsteps from "
+            fprintf(stderr,
+                    "Calculated time to finish depends on nsteps from "
                     "run input file,\nwhich may not correspond to the time "
                     "needed to process input trajectory.\n\n");
         }
@@ -339,18 +331,23 @@ void gmx::LegacySimulator::do_mimic()
 
     if (constr)
     {
-        GMX_LOG(mdlog.info).asParagraph().
-            appendText("Simulations has constraints. Constraints will "
-                       "be handled by CPMD.");
+        GMX_LOG(mdlog.info)
+                .asParagraph()
+                .appendText(
+                        "Simulations has constraints. Constraints will "
+                        "be handled by CPMD.");
     }
 
-    GMX_LOG(mdlog.info).asParagraph().
-        appendText("MiMiC does not report kinetic energy, total energy, temperature, virial and pressure.");
+    GMX_LOG(mdlog.info)
+            .asParagraph()
+            .appendText(
+                    "MiMiC does not report kinetic energy, total energy, temperature, virial and "
+                    "pressure.");
 
     auto stopHandler = stopHandlerBuilder->getStopHandlerMD(
-                compat::not_null<SimulationSignal*>(&signals[eglsSTOPCOND]), false,
-                MASTER(cr), ir->nstlist, mdrunOptions.reproducible, nstglobalcomm,
-                mdrunOptions.maximumHoursToRun, ir->nstlist == 0, fplog, step, bNS, walltime_accounting);
+            compat::not_null<SimulationSignal*>(&signals[eglsSTOPCOND]), false, MASTER(cr),
+            ir->nstlist, mdrunOptions.reproducible, nstglobalcomm, mdrunOptions.maximumHoursToRun,
+            ir->nstlist == 0, fplog, step, bNS, walltime_accounting);
 
     // we don't do counter resetting in rerun - finish will always be valid
     walltime_accounting_set_valid_finish(walltime_accounting);
@@ -384,7 +381,9 @@ void gmx::LegacySimulator::do_mimic()
             const bool constructVsites = ((vsite != nullptr) && mdrunOptions.rerunConstructVsites);
             if (constructVsites && DOMAINDECOMP(cr))
             {
-                gmx_fatal(FARGS, "Vsite recalculation with -rerun is not implemented with domain decomposition, "
+                gmx_fatal(FARGS,
+                          "Vsite recalculation with -rerun is not implemented with domain "
+                          "decomposition, "
                           "use a single rank");
             }
         }
@@ -393,14 +392,9 @@ void gmx::LegacySimulator::do_mimic()
         {
             /* Repartition the domain decomposition */
             const bool bMasterState = true;
-            dd_partition_system(fplog, mdlog, step, cr,
-                                bMasterState, nstglobalcomm,
-                                state_global, *top_global, ir, imdSession,
-                                pull_work,
-                                state, &f, mdAtoms, &top, fr,
-                                vsite, constr,
-                                nrnb, wcycle,
-                                mdrunOptions.verbose);
+            dd_partition_system(fplog, mdlog, step, cr, bMasterState, nstglobalcomm, state_global,
+                                *top_global, ir, imdSession, pull_work, state, &f, mdAtoms, &top,
+                                fr, vsite, constr, nrnb, wcycle, mdrunOptions.verbose);
             shouldCheckNumberOfBondedInteractions = true;
         }
 
@@ -414,31 +408,19 @@ void gmx::LegacySimulator::do_mimic()
             update_mdatoms(mdatoms, state->lambda[efptMASS]);
         }
 
-        force_flags = (GMX_FORCE_STATECHANGED |
-                       GMX_FORCE_DYNAMICBOX |
-                       GMX_FORCE_ALLFORCES |
-                       GMX_FORCE_VIRIAL |  // TODO: Get rid of this once #2649 is solved
-                       GMX_FORCE_ENERGY |
-                       (doFreeEnergyPerturbation ? GMX_FORCE_DHDL : 0));
+        force_flags = (GMX_FORCE_STATECHANGED | GMX_FORCE_DYNAMICBOX | GMX_FORCE_ALLFORCES
+                       | GMX_FORCE_VIRIAL | // TODO: Get rid of this once #2649 is solved
+                       GMX_FORCE_ENERGY | (doFreeEnergyPerturbation ? GMX_FORCE_DHDL : 0));
 
         if (shellfc)
         {
             /* Now is the time to relax the shells */
-            relax_shell_flexcon(fplog, cr, ms, mdrunOptions.verbose,
-                                enforcedRotation, step,
-                                ir, imdSession, pull_work, bNS, force_flags, &top,
-                                constr, enerd, fcd,
-                                state->natoms,
-                                state->x.arrayRefWithPadding(),
-                                state->v.arrayRefWithPadding(),
-                                state->box,
-                                state->lambda,
-                                &state->hist,
-                                f.arrayRefWithPadding(), force_vir, mdatoms,
-                                nrnb, wcycle, graph,
-                                shellfc, fr, runScheduleWork, t, mu_tot,
-                                vsite,
-                                ddBalanceRegionHandler);
+            relax_shell_flexcon(fplog, cr, ms, mdrunOptions.verbose, enforcedRotation, step, ir,
+                                imdSession, pull_work, bNS, force_flags, &top, constr, enerd, fcd,
+                                state->natoms, state->x.arrayRefWithPadding(),
+                                state->v.arrayRefWithPadding(), state->box, state->lambda, &state->hist,
+                                f.arrayRefWithPadding(), force_vir, mdatoms, nrnb, wcycle, graph,
+                                shellfc, fr, runScheduleWork, t, mu_tot, vsite, ddBalanceRegionHandler);
         }
         else
         {
@@ -447,16 +429,12 @@ void gmx::LegacySimulator::do_mimic()
              * This is parallellized as well, and does communication too.
              * Check comments in sim_util.c
              */
-            Awh       *awh = nullptr;
-            gmx_edsam *ed  = nullptr;
-            do_force(fplog, cr, ms, ir, awh, enforcedRotation, imdSession,
-                     pull_work,
-                     step, nrnb, wcycle, &top,
-                     state->box, state->x.arrayRefWithPadding(), &state->hist,
-                     f.arrayRefWithPadding(), force_vir, mdatoms, enerd, fcd,
-                     state->lambda, graph,
-                     fr, runScheduleWork, vsite, mu_tot, t, ed,
-                     GMX_FORCE_NS | force_flags,
+            Awh*       awh = nullptr;
+            gmx_edsam* ed  = nullptr;
+            do_force(fplog, cr, ms, ir, awh, enforcedRotation, imdSession, pull_work, step, nrnb,
+                     wcycle, &top, state->box, state->x.arrayRefWithPadding(), &state->hist,
+                     f.arrayRefWithPadding(), force_vir, mdatoms, enerd, fcd, state->lambda, graph,
+                     fr, runScheduleWork, vsite, mu_tot, t, ed, GMX_FORCE_NS | force_flags,
                      ddBalanceRegionHandler);
         }
 
@@ -467,13 +445,10 @@ void gmx::LegacySimulator::do_mimic()
             const bool isCheckpointingStep = false;
             const bool doRerun             = false;
             const bool bSumEkinhOld        = false;
-            do_md_trajectory_writing(fplog, cr, nfile, fnm, step, step_rel, t,
-                                     ir, state, state_global, observablesHistory,
-                                     top_global, fr,
-                                     outf, energyOutput, ekind, f,
-                                     isCheckpointingStep, doRerun, isLastStep,
-                                     mdrunOptions.writeConfout,
-                                     bSumEkinhOld);
+            do_md_trajectory_writing(fplog, cr, nfile, fnm, step, step_rel, t, ir, state,
+                                     state_global, observablesHistory, top_global, fr, outf,
+                                     energyOutput, ekind, f, isCheckpointingStep, doRerun,
+                                     isLastStep, mdrunOptions.writeConfout, bSumEkinhOld);
         }
 
         stopHandler->setSignal();
@@ -491,8 +466,8 @@ void gmx::LegacySimulator::do_mimic()
             {
                 shift_self(graph, state->box, as_rvec_array(state->x.data()));
             }
-            construct_vsites(vsite, as_rvec_array(state->x.data()), ir->delta_t, as_rvec_array(state->v.data()),
-                             top.idef.iparams, top.idef.il,
+            construct_vsites(vsite, as_rvec_array(state->x.data()), ir->delta_t,
+                             as_rvec_array(state->v.data()), top.idef.iparams, top.idef.il,
                              fr->ePBC, fr->bMolPBC, cr, state->box);
 
             if (graph != nullptr)
@@ -506,21 +481,18 @@ void gmx::LegacySimulator::do_mimic()
             const bool          doInterSimSignal = false;
             const bool          doIntraSimSignal = true;
             bool                bSumEkinhOld     = false;
-            t_vcm              *vcm              = nullptr;
+            t_vcm*              vcm              = nullptr;
             SimulationSignaller signaller(&signals, cr, ms, doInterSimSignal, doIntraSimSignal);
 
-            compute_globals(gstat, cr, ir, fr, ekind,
-                            state->x.rvec_array(), state->v.rvec_array(), state->box, state->lambda[efptVDW],
-                            mdatoms, nrnb, vcm,
-                            wcycle, enerd, nullptr, nullptr, nullptr, nullptr, mu_tot,
-                            constr, &signaller,
-                            state->box,
-                            &totalNumberOfBondedInteractions, &bSumEkinhOld,
+            compute_globals(gstat, cr, ir, fr, ekind, state->x.rvec_array(), state->v.rvec_array(),
+                            state->box, state->lambda[efptVDW], mdatoms, nrnb, vcm, wcycle, enerd,
+                            nullptr, nullptr, nullptr, nullptr, mu_tot, constr, &signaller,
+                            state->box, &totalNumberOfBondedInteractions, &bSumEkinhOld,
                             CGLO_GSTAT | CGLO_ENERGY
-                            | (shouldCheckNumberOfBondedInteractions ? CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS : 0)
-                            );
-            checkNumberOfBondedInteractions(mdlog, cr, totalNumberOfBondedInteractions,
-                                            top_global, &top, state->x.rvec_array(), state->box,
+                                    | (shouldCheckNumberOfBondedInteractions ? CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS
+                                                                             : 0));
+            checkNumberOfBondedInteractions(mdlog, cr, totalNumberOfBondedInteractions, top_global,
+                                            &top, state->x.rvec_array(), state->box,
                                             &shouldCheckNumberOfBondedInteractions);
         }
 
@@ -546,7 +518,6 @@ void gmx::LegacySimulator::do_mimic()
         }
 
 
-
         /* Note: this is OK, but there are some numerical precision issues with using the convergence of
            the virial that should probably be addressed eventually. state->veta has better properies,
            but what we actually need entering the new cycle is the new shake_vir value. Ideally, we could
@@ -563,23 +534,20 @@ void gmx::LegacySimulator::do_mimic()
         if (MASTER(cr))
         {
             const bool bCalcEnerStep = true;
-            energyOutput.addDataAtEnergyStep(doFreeEnergyPerturbation, bCalcEnerStep,
-                                             t, mdatoms->tmass, enerd, state,
-                                             ir->fepvals, ir->expandedvals, state->box,
-                                             shake_vir, force_vir, total_vir, pres,
-                                             ekind, mu_tot, constr);
+            energyOutput.addDataAtEnergyStep(doFreeEnergyPerturbation, bCalcEnerStep, t,
+                                             mdatoms->tmass, enerd, state, ir->fepvals,
+                                             ir->expandedvals, state->box, shake_vir, force_vir,
+                                             total_vir, pres, ekind, mu_tot, constr);
 
             const bool do_ene = true;
             const bool do_log = true;
-            Awh       *awh    = nullptr;
+            Awh*       awh    = nullptr;
             const bool do_dr  = ir->nstdisreout != 0;
             const bool do_or  = ir->nstorireout != 0;
 
             energyOutput.printAnnealingTemperatures(do_log ? fplog : nullptr, groups, &(ir->opts));
             energyOutput.printStepToEnergyFile(mdoutf_get_fp_ene(outf), do_ene, do_dr, do_or,
-                                               do_log ? fplog : nullptr,
-                                               step, t,
-                                               fcd, awh);
+                                               do_log ? fplog : nullptr, step, t, fcd, awh);
 
             if (do_per_step(step, ir->nstlog))
             {
@@ -591,8 +559,7 @@ void gmx::LegacySimulator::do_mimic()
         }
 
         /* Print the remaining wall clock time for the run */
-        if (isMasterSimMasterRank(ms, MASTER(cr)) &&
-            (mdrunOptions.verbose || gmx_got_usr_signal()))
+        if (isMasterSimMasterRank(ms, MASTER(cr)) && (mdrunOptions.verbose || gmx_got_usr_signal()))
         {
             if (shellfc)
             {