Prepared t_mdatoms for using vector
authorMark Abraham <mark.j.abraham@gmail.com>
Wed, 8 Nov 2017 11:22:57 +0000 (12:22 +0100)
committerMark Abraham <mark.j.abraham@gmail.com>
Thu, 9 Nov 2017 08:57:57 +0000 (09:57 +0100)
Wrapped it in another C++ class because the group-scheme kernels
compile as plain C and this permits the contained t_mdatoms to
be unmodified. The class has responsibility for maintaining the
allocations for any of the fields of t_mdatoms that need to be
managed with a std::vector plus perhaps an allocator.

Change-Id: I6fef70beeb8d43f3e048cec02380f8ebf8153ecb

13 files changed:
src/gromacs/domdec/domdec.cpp
src/gromacs/domdec/domdec.h
src/gromacs/gmxana/gmx_disre.cpp
src/gromacs/gmxpreprocess/readpull.cpp
src/gromacs/mdlib/integrator.h
src/gromacs/mdlib/mdatoms.cpp
src/gromacs/mdlib/mdatoms.h
src/gromacs/mdlib/mdsetup.cpp
src/gromacs/mdlib/mdsetup.h
src/gromacs/mdlib/minimize.cpp
src/gromacs/mdlib/tpi.cpp
src/programs/mdrun/md.cpp
src/programs/mdrun/runner.cpp

index ee6d4e3e626378015ce646f2ee6bd291c6112eec..adf21588be4b85602180503ff5c02b123a92f265 100644 (file)
@@ -9169,7 +9169,7 @@ void dd_partition_system(FILE                *fplog,
                          const t_inputrec    *ir,
                          t_state             *state_local,
                          PaddedRVecVector    *f,
-                         t_mdatoms           *mdatoms,
+                         gmx::MDAtoms        *mdAtoms,
                          gmx_localtop_t      *top_local,
                          t_forcerec          *fr,
                          gmx_vsite_t         *vsite,
@@ -9726,13 +9726,14 @@ void dd_partition_system(FILE                *fplog,
 
     /* Update atom data for mdatoms and several algorithms */
     mdAlgorithmsSetupAtomData(cr, ir, top_global, top_local, fr,
-                              nullptr, mdatoms, vsite, nullptr);
+                              nullptr, mdAtoms, vsite, nullptr);
 
     if (ir->implicit_solvent)
     {
         make_local_gb(cr, fr->born, ir->gb_algorithm);
     }
 
+    auto mdatoms = mdAtoms->mdatoms();
     if (!thisRankHasDuty(cr, DUTY_PME))
     {
         /* Send the charges and/or c6/sigmas to our PME only node */
index c5d13a2a401ddcdb2391f257de6785f0abd72fca..5ae8947effaee1ab3780dc8dd9dae9e6c9ecd77b 100644 (file)
@@ -82,6 +82,11 @@ struct t_commrec;
 struct t_inputrec;
 class t_state;
 
+namespace gmx
+{
+class MDAtoms;
+} // namespace
+
 /*! \brief Returns the global topology atom number belonging to local atom index i.
  *
  * This function is intended for writing ASCII output
@@ -319,7 +324,7 @@ void dd_partition_system(FILE                *fplog,
                          const t_inputrec    *ir,
                          t_state             *state_local,
                          PaddedRVecVector    *f,
-                         t_mdatoms           *mdatoms,
+                         gmx::MDAtoms        *mdatoms,
                          gmx_localtop_t      *top_local,
                          t_forcerec          *fr,
                          gmx_vsite_t         *vsite,
index a8c56a57cd5429e7be4a7ebc67685b64375325a0..02064f658f4c05e1a9fbf0a4c6efa768153a3351 100644 (file)
@@ -711,7 +711,6 @@ int gmx_disre(int argc, char *argv[])
     t_dr_result       dr, *dr_clust = nullptr;
     char            **leg;
     real             *vvindex = nullptr, *w_rls = nullptr;
-    t_mdatoms        *mdatoms;
     t_pbc             pbc, *pbc_null;
     int               my_clust;
     FILE             *fplog;
@@ -841,9 +840,9 @@ int gmx_disre(int argc, char *argv[])
                          "Largest Violation", "Time (ps)", "nm", oenv);
     }
 
-    mdatoms = init_mdatoms(fplog, mtop, *ir);
-    atoms2md(&mtop, ir, -1, nullptr, mtop.natoms, mdatoms);
-    update_mdatoms(mdatoms, ir->fepvals->init_lambda);
+    auto mdAtoms = gmx::makeMDAtoms(fplog, mtop, *ir);
+    atoms2md(&mtop, ir, -1, nullptr, mtop.natoms, mdAtoms.get());
+    update_mdatoms(mdAtoms->mdatoms(), ir->fepvals->init_lambda);
     init_nrnb(&nrnb);
     if (ir->ePBC != epbcNONE)
     {
index 3d67cb3549f38af117f020ecd6c378831b3fe7b8..17b9074271a2d52285c3dc5692cb9d9b8c22460c 100644 (file)
@@ -508,15 +508,15 @@ pull_t *set_pull_init(t_inputrec *ir, const gmx_mtop_t *mtop,
 {
     pull_params_t *pull;
     pull_t        *pull_work;
-    t_mdatoms     *md;
     t_pbc          pbc;
     int            c;
     double         t_start;
 
     pull      = ir->pull;
     pull_work = init_pull(nullptr, pull, ir, 0, nullptr, mtop, nullptr, oenv, lambda, FALSE, ContinuationOptions());
-    md        = init_mdatoms(nullptr, *mtop, *ir);
-    atoms2md(mtop, ir, -1, nullptr, mtop->natoms, md);
+    auto mdAtoms = gmx::makeMDAtoms(nullptr, *mtop, *ir);
+    auto md      = mdAtoms->mdatoms();
+    atoms2md(mtop, ir, -1, nullptr, mtop->natoms, mdAtoms.get());
     if (ir->efep)
     {
         update_mdatoms(md, lambda);
index 9ac0b817305c23e527364e9d99bc391f0d40630a..272c69797e5c7a92893c02b73326c9c58ac418c2 100644 (file)
@@ -47,7 +47,6 @@
 #include "gromacs/mdlib/vsite.h"
 #include "gromacs/mdtypes/fcdata.h"
 #include "gromacs/mdtypes/forcerec.h"
-#include "gromacs/mdtypes/mdatom.h"
 #include "gromacs/timing/wallcycle.h"
 #include "gromacs/timing/walltime_accounting.h"
 #include "gromacs/utility/basedefinitions.h"
@@ -70,6 +69,7 @@ namespace gmx
 
 class IMDOutputProvider;
 class MDLogger;
+class MDAtoms;
 
 /*! \brief Integrator algorithm implementation.
  *
@@ -88,7 +88,7 @@ class MDLogger;
  * \param[in] fcd                 Force and constraint data
  * \param[in] state_global        The state (x, v, f, box etc.) of the whole system
  * \param[in] observablesHistory  The observables statistics history
- * \param[in] mdatoms             Structure containing atom information
+ * \param[in] mdAtoms             Atom information
  * \param[in] nrnb                Accounting for floating point operations
  * \param[in] wcycle              Wall cycle timing information
  * \param[in] fr                  Force record with cut-off information and more
@@ -106,7 +106,7 @@ typedef double integrator_t (FILE *fplog, t_commrec *cr, const gmx::MDLogger &md
                              gmx_mtop_t *top_global, t_fcdata *fcd,
                              t_state *state_global,
                              ObservablesHistory *observablesHistory,
-                             t_mdatoms *mdatoms,
+                             MDAtoms *mdatoms,
                              t_nrnb *nrnb, gmx_wallcycle_t wcycle,
                              t_forcerec *fr,
                              const ReplicaExchangeParameters &replExParams,
index 56d1ce798b8babe5bbca08286789e623326df70f..9f144e27ccaec8f5b64020a2c04ed15d9205dec5 100644 (file)
@@ -40,6 +40,9 @@
 
 #include <cmath>
 
+#include <memory>
+
+#include "gromacs/compat/make_unique.h"
 #include "gromacs/math/functions.h"
 #include "gromacs/mdlib/gmx_omp_nthreads.h"
 #include "gromacs/mdlib/qmmm.h"
 
 #define ALMOST_ZERO 1e-30
 
-t_mdatoms *init_mdatoms(FILE *fp, const gmx_mtop_t &mtop, const t_inputrec &ir)
+namespace gmx
+{
+
+MDAtoms::MDAtoms()
+    : mdatoms_(nullptr)
 {
+}
+
+std::unique_ptr<MDAtoms>
+makeMDAtoms(FILE *fp, const gmx_mtop_t &mtop, const t_inputrec &ir)
+{
+    auto       mdAtoms = compat::make_unique<MDAtoms>();
     t_mdatoms *md;
     snew(md, 1);
+    mdAtoms->mdatoms_.reset(md);
 
     md->nenergrp = mtop.groups.grps[egcENER].nr;
     md->bVCMgrps = (mtop.groups.grps[egcVCM].nr > 1);
@@ -116,13 +130,15 @@ t_mdatoms *init_mdatoms(FILE *fp, const gmx_mtop_t &mtop, const t_inputrec &ir)
 
     md->bOrires = gmx_mtop_ftype_count(&mtop, F_ORIRES);
 
-    return md;
+    return mdAtoms;
 }
 
+} // namespace
+
 void atoms2md(const gmx_mtop_t *mtop, const t_inputrec *ir,
               int nindex, const int *index,
               int homenr,
-              t_mdatoms *md)
+              gmx::MDAtoms *mdAtoms)
 {
     gmx_bool              bLJPME;
     const t_grpopts      *opts;
@@ -135,6 +151,7 @@ void atoms2md(const gmx_mtop_t *mtop, const t_inputrec *ir,
 
     groups = &mtop->groups;
 
+    auto md = mdAtoms->mdatoms();
     /* nindex>=0 indicates DD where we use an index */
     if (nindex >= 0)
     {
index 0355e5cad15aa47aff352501666a4c2cd13cb822..21771cbe90316eacf2d2f0729d53811e3fee28c1 100644 (file)
 
 #include <cstdio>
 
+#include <memory>
+#include <vector>
+
 #include "gromacs/mdtypes/mdatom.h"
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/real.h"
+#include "gromacs/utility/unique_cptr.h"
 
 struct gmx_mtop_t;
 struct t_inputrec;
 
-t_mdatoms *init_mdatoms(FILE *fp, const gmx_mtop_t &mtop, const t_inputrec &ir);
+namespace gmx
+{
+
+/*! \libinternal
+ * \brief Contains a C-style t_mdatoms while permitting future changes
+ * to manage some of its memory with C++ vectors with allocators.
+ *
+ * The group-scheme kernels need to use a plain C-style t_mdatoms, so
+ * this type combines that with the memory management needed e.g.for
+ * efficient PME on GPU transfers.
+ *
+ * \todo Refactor this class and rename MDAtoms once the group scheme
+ * is removed. */
+class MDAtoms
+{
+    //! C-style mdatoms struct.
+    unique_cptr<t_mdatoms> mdatoms_;
+    public:
+        // TODO make this private
+        //! Constructor.
+        MDAtoms();
+        //! Getter.
+        t_mdatoms *mdatoms()
+        {
+            return mdatoms_.get();
+        }
+        //! Builder function.
+        friend std::unique_ptr<MDAtoms>
+        makeMDAtoms(FILE *fp, const gmx_mtop_t &mtop, const t_inputrec &ir);
+};
+
+//! Builder function for MdAtomsWrapper.
+std::unique_ptr<MDAtoms>
+makeMDAtoms(FILE *fp, const gmx_mtop_t &mtop, const t_inputrec &ir);
+
+} // namespace
 
 void atoms2md(const gmx_mtop_t *mtop, const t_inputrec *ir,
               int nindex, const int *index,
               int homenr,
-              t_mdatoms *md);
+              gmx::MDAtoms *mdAtoms);
 /* This routine copies the atoms->atom struct into md.
  * If index!=NULL only the indexed atoms are copied.
  * For the masses the A-state (lambda=0) mass is used.
index 309c20e054f2fdbc2eca921dfd59deb5357264da..7ab1cb8c5eca634a75342c0b469221f2ddf37586 100644 (file)
@@ -65,7 +65,7 @@ void mdAlgorithmsSetupAtomData(t_commrec         *cr,
                                gmx_localtop_t    *top,
                                t_forcerec        *fr,
                                t_graph          **graph,
-                               t_mdatoms         *mdatoms,
+                               gmx::MDAtoms      *mdAtoms,
                                gmx_vsite_t       *vsite,
                                gmx_shellfc_t     *shellfc)
 {
@@ -86,8 +86,9 @@ void mdAlgorithmsSetupAtomData(t_commrec         *cr,
         atomIndex    = nullptr;
         numHomeAtoms = top_global->natoms;
     }
-    atoms2md(top_global, ir, numAtomIndex, atomIndex, numHomeAtoms, mdatoms);
+    atoms2md(top_global, ir, numAtomIndex, atomIndex, numHomeAtoms, mdAtoms);
 
+    auto mdatoms = mdAtoms->mdatoms();
     if (usingDomDec)
     {
         dd_sort_local_top(cr->dd, mdatoms, top);
index c261643a041ec036a122739a959318261f0c5a6b..4f435041daf92404ee1874defc07c87eb9e0863d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2016, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -57,7 +57,7 @@
  * \param[in,out] top        The local topology
  * \param[in,out] fr         The force calculation parameter/data record
  * \param[out]    graph      The molecular graph, can be NULL
- * \param[out]    mdatoms    The MD atom data
+ * \param[out]    mdAtoms    The MD atom data
  * \param[in,out] vsite      The virtual site data, can be NULL
  * \param[in,out] shellfc    The shell/flexible-constraint data, can be NULL
  */
@@ -67,7 +67,7 @@ void mdAlgorithmsSetupAtomData(t_commrec         *cr,
                                gmx_localtop_t    *top,
                                t_forcerec        *fr,
                                t_graph          **graph,
-                               t_mdatoms         *mdatoms,
+                               gmx::MDAtoms      *mdAtoms,
                                gmx_vsite_t       *vsite,
                                gmx_shellfc_t     *shellfc);
 
index 52e7b42a615c789bf651bc85ecb1e168f6058a83..16c8b2c8659aedb0725174b46c9d7e3571bb0d89 100644 (file)
@@ -329,7 +329,7 @@ static void init_em(FILE *fplog, const char *title,
                     em_state_t *ems, gmx_localtop_t **top,
                     t_nrnb *nrnb, rvec mu_tot,
                     t_forcerec *fr, gmx_enerdata_t **enerd,
-                    t_graph **graph, t_mdatoms *mdatoms, gmx_global_stat_t *gstat,
+                    t_graph **graph, gmx::MDAtoms *mdAtoms, gmx_global_stat_t *gstat,
                     gmx_vsite_t *vsite, gmx_constr_t constr, gmx_shellfc_t **shellfc,
                     int nfile, const t_filenm fnm[],
                     gmx_mdoutf_t *outf, t_mdebin **mdebin,
@@ -380,6 +380,7 @@ static void init_em(FILE *fplog, const char *title,
         }
     }
 
+    auto mdatoms = mdAtoms->mdatoms();
     if (DOMAINDECOMP(cr))
     {
         *top = dd_init_local_top(top_global);
@@ -389,7 +390,7 @@ static void init_em(FILE *fplog, const char *title,
         /* Distribute the charge groups over the nodes from the master node */
         dd_partition_system(fplog, ir->init_step, cr, TRUE, 1,
                             state_global, top_global, ir,
-                            &ems->s, &ems->f, mdatoms, *top,
+                            &ems->s, &ems->f, mdAtoms, *top,
                             fr, vsite, constr,
                             nrnb, nullptr, FALSE);
         dd_store_state(cr->dd, &ems->s);
@@ -409,7 +410,7 @@ static void init_em(FILE *fplog, const char *title,
 
         snew(*top, 1);
         mdAlgorithmsSetupAtomData(cr, ir, top_global, *top, fr,
-                                  graph, mdatoms,
+                                  graph, mdAtoms,
                                   vsite, shellfc ? *shellfc : nullptr);
 
         if (vsite)
@@ -418,7 +419,7 @@ static void init_em(FILE *fplog, const char *title,
         }
     }
 
-    update_mdatoms(mdatoms, ems->s.lambda[efptMASS]);
+    update_mdatoms(mdAtoms->mdatoms(), ems->s.lambda[efptMASS]);
 
     if (constr)
     {
@@ -694,7 +695,7 @@ static bool do_em_step(t_commrec *cr, t_inputrec *ir, t_mdatoms *md,
 static void em_dd_partition_system(FILE *fplog, int step, t_commrec *cr,
                                    gmx_mtop_t *top_global, t_inputrec *ir,
                                    em_state_t *ems, gmx_localtop_t *top,
-                                   t_mdatoms *mdatoms, t_forcerec *fr,
+                                   gmx::MDAtoms *mdAtoms, t_forcerec *fr,
                                    gmx_vsite_t *vsite, gmx_constr_t constr,
                                    t_nrnb *nrnb, gmx_wallcycle_t wcycle)
 {
@@ -702,7 +703,7 @@ static void em_dd_partition_system(FILE *fplog, int step, t_commrec *cr,
     dd_partition_system(fplog, step, cr, FALSE, 1,
                         nullptr, top_global, ir,
                         &ems->s, &ems->f,
-                        mdatoms, top, fr, vsite, constr,
+                        mdAtoms, top, fr, vsite, constr,
                         nrnb, wcycle, FALSE);
     dd_store_state(cr->dd, &ems->s);
 }
@@ -716,7 +717,7 @@ static void evaluate_energy(FILE *fplog, t_commrec *cr,
                             gmx_global_stat_t gstat,
                             gmx_vsite_t *vsite, gmx_constr_t constr,
                             t_fcdata *fcd,
-                            t_graph *graph, t_mdatoms *mdatoms,
+                            t_graph *graph, gmx::MDAtoms *mdAtoms,
                             t_forcerec *fr, rvec mu_tot,
                             gmx_enerdata_t *enerd, tensor vir, tensor pres,
                             gmx_int64_t count, gmx_bool bFirst)
@@ -756,7 +757,7 @@ static void evaluate_energy(FILE *fplog, t_commrec *cr,
     {
         /* Repartition the domain decomposition */
         em_dd_partition_system(fplog, count, cr, top_global, inputrec,
-                               ems, top, mdatoms, fr, vsite, constr,
+                               ems, top, mdAtoms, fr, vsite, constr,
                                nrnb, wcycle);
     }
 
@@ -767,7 +768,7 @@ static void evaluate_energy(FILE *fplog, t_commrec *cr,
     do_force(fplog, cr, inputrec,
              count, nrnb, wcycle, top, &top_global->groups,
              ems->s.box, &ems->s.x, &ems->s.hist,
-             &ems->f, force_vir, mdatoms, enerd, fcd,
+             &ems->f, force_vir, mdAtoms->mdatoms(), enerd, fcd,
              ems->s.lambda, graph, fr, vsite, mu_tot, t, nullptr, TRUE,
              GMX_FORCE_STATECHANGED | GMX_FORCE_ALLFORCES |
              GMX_FORCE_VIRIAL | GMX_FORCE_ENERGY |
@@ -815,7 +816,7 @@ static void evaluate_energy(FILE *fplog, t_commrec *cr,
         dvdl_constr = 0;
         rvec *f_rvec = as_rvec_array(ems->f.data());
         constrain(nullptr, FALSE, FALSE, constr, &top->idef,
-                  inputrec, cr, count, 0, 1.0, mdatoms,
+                  inputrec, cr, count, 0, 1.0, mdAtoms->mdatoms(),
                   as_rvec_array(ems->s.x.data()), f_rvec, f_rvec,
                   fr->bMolPBC, ems->s.box,
                   ems->s.lambda[efptBONDED], &dvdl_constr,
@@ -837,7 +838,7 @@ static void evaluate_energy(FILE *fplog, t_commrec *cr,
 
     if (EI_ENERGY_MINIMIZATION(inputrec->eI))
     {
-        get_state_f_norm_max(cr, &(inputrec->opts), mdatoms, ems);
+        get_state_f_norm_max(cr, &(inputrec->opts), mdAtoms->mdatoms(), ems);
     }
 }
 
@@ -983,7 +984,7 @@ namespace gmx
                            t_inputrec *inputrec,
                            gmx_mtop_t *top_global, t_fcdata *fcd,
                            t_state *state_global,
-                           t_mdatoms *mdatoms,
+                           gmx::MDAtoms *mdAtoms,
                            t_nrnb *nrnb, gmx_wallcycle_t wcycle,
                            gmx_edsam_t ed,
                            t_forcerec *fr,
@@ -1001,7 +1002,7 @@ double do_cg(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
              gmx_mtop_t *top_global, t_fcdata *fcd,
              t_state *state_global,
              ObservablesHistory *observablesHistory,
-             t_mdatoms *mdatoms,
+             gmx::MDAtoms *mdAtoms,
              t_nrnb *nrnb, gmx_wallcycle_t wcycle,
              t_forcerec *fr,
              const ReplicaExchangeParameters gmx_unused &replExParams,
@@ -1027,6 +1028,7 @@ double do_cg(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
     int               number_steps, neval = 0, nstcg = inputrec->nstcgsteep;
     gmx_mdoutf_t      outf;
     int               m, step, nminstep;
+    auto              mdatoms = mdAtoms->mdatoms();
 
     step = 0;
 
@@ -1043,7 +1045,7 @@ double do_cg(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
     /* Init em and store the local state in s_min */
     init_em(fplog, CG, cr, outputProvider, inputrec, mdrunOptions,
             state_global, top_global, s_min, &top,
-            nrnb, mu_tot, fr, &enerd, &graph, mdatoms, &gstat,
+            nrnb, mu_tot, fr, &enerd, &graph, mdAtoms, &gstat,
             vsite, constr, nullptr,
             nfile, fnm, &outf, &mdebin, wcycle);
 
@@ -1069,7 +1071,7 @@ double do_cg(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
     evaluate_energy(fplog, cr,
                     top_global, s_min, top,
                     inputrec, nrnb, wcycle, gstat,
-                    vsite, constr, fcd, graph, mdatoms, fr,
+                    vsite, constr, fcd, graph, mdAtoms, fr,
                     mu_tot, enerd, vir, pres, -1, TRUE);
     where();
 
@@ -1234,7 +1236,7 @@ double do_cg(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
         if (DOMAINDECOMP(cr) && s_min->s.ddp_count < cr->dd->ddp_count)
         {
             em_dd_partition_system(fplog, step, cr, top_global, inputrec,
-                                   s_min, top, mdatoms, fr, vsite, constr,
+                                   s_min, top, mdAtoms, fr, vsite, constr,
                                    nrnb, wcycle);
         }
 
@@ -1247,7 +1249,7 @@ double do_cg(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
         evaluate_energy(fplog, cr,
                         top_global, s_c, top,
                         inputrec, nrnb, wcycle, gstat,
-                        vsite, constr, fcd, graph, mdatoms, fr,
+                        vsite, constr, fcd, graph, mdAtoms, fr,
                         mu_tot, enerd, vir, pres, -1, FALSE);
 
         /* Calc derivative along line */
@@ -1343,7 +1345,7 @@ double do_cg(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
                 {
                     /* Reload the old state */
                     em_dd_partition_system(fplog, -1, cr, top_global, inputrec,
-                                           s_min, top, mdatoms, fr, vsite, constr,
+                                           s_min, top, mdAtoms, fr, vsite, constr,
                                            nrnb, wcycle);
                 }
 
@@ -1356,7 +1358,7 @@ double do_cg(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
                 evaluate_energy(fplog, cr,
                                 top_global, s_b, top,
                                 inputrec, nrnb, wcycle, gstat,
-                                vsite, constr, fcd, graph, mdatoms, fr,
+                                vsite, constr, fcd, graph, mdAtoms, fr,
                                 mu_tot, enerd, vir, pres, -1, FALSE);
 
                 /* p does not change within a step, but since the domain decomposition
@@ -1627,7 +1629,7 @@ double do_cg(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
                           t_inputrec *inputrec,
                           gmx_mtop_t *top_global, t_fcdata *fcd,
                           t_state *state_global,
-                          t_mdatoms *mdatoms,
+                          gmx::MDAtoms *mdAtoms,
                           t_nrnb *nrnb, gmx_wallcycle_t wcycle,
                           gmx_edsam_t ed,
                           t_forcerec *fr,
@@ -1645,7 +1647,7 @@ double do_lbfgs(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo
                 gmx_mtop_t *top_global, t_fcdata *fcd,
                 t_state *state_global,
                 ObservablesHistory *observablesHistory,
-                t_mdatoms *mdatoms,
+                gmx::MDAtoms *mdAtoms,
                 t_nrnb *nrnb, gmx_wallcycle_t wcycle,
                 t_forcerec *fr,
                 const ReplicaExchangeParameters gmx_unused &replExParams,
@@ -1673,6 +1675,7 @@ double do_lbfgs(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo
     gmx_mdoutf_t       outf;
     int                i, k, m, n, gf, step;
     int                mdof_flags;
+    auto               mdatoms = mdAtoms->mdatoms();
 
     if (PAR(cr))
     {
@@ -1711,7 +1714,7 @@ double do_lbfgs(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo
     /* Init em */
     init_em(fplog, LBFGS, cr, outputProvider, inputrec, mdrunOptions,
             state_global, top_global, &ems, &top,
-            nrnb, mu_tot, fr, &enerd, &graph, mdatoms, &gstat,
+            nrnb, mu_tot, fr, &enerd, &graph, mdAtoms, &gstat,
             vsite, constr, nullptr,
             nfile, fnm, &outf, &mdebin, wcycle);
 
@@ -1774,7 +1777,7 @@ double do_lbfgs(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo
     evaluate_energy(fplog, cr,
                     top_global, &ems, top,
                     inputrec, nrnb, wcycle, gstat,
-                    vsite, constr, fcd, graph, mdatoms, fr,
+                    vsite, constr, fcd, graph, mdAtoms, fr,
                     mu_tot, enerd, vir, pres, -1, TRUE);
     where();
 
@@ -1980,7 +1983,7 @@ double do_lbfgs(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo
         evaluate_energy(fplog, cr,
                         top_global, sc, top,
                         inputrec, nrnb, wcycle, gstat,
-                        vsite, constr, fcd, graph, mdatoms, fr,
+                        vsite, constr, fcd, graph, mdAtoms, fr,
                         mu_tot, enerd, vir, pres, step, FALSE);
 
         // Calc line gradient in position C
@@ -2071,7 +2074,7 @@ double do_lbfgs(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo
                 evaluate_energy(fplog, cr,
                                 top_global, sb, top,
                                 inputrec, nrnb, wcycle, gstat,
-                                vsite, constr, fcd, graph, mdatoms, fr,
+                                vsite, constr, fcd, graph, mdAtoms, fr,
                                 mu_tot, enerd, vir, pres, step, FALSE);
                 fnorm = sb->fnorm;
 
@@ -2392,7 +2395,7 @@ double do_lbfgs(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo
                           t_inputrec *inputrec,
                           gmx_mtop_t *top_global, t_fcdata *fcd,
                           t_state *state_global,
-                          t_mdatoms *mdatoms,
+                          gmx::MDAtoms *mdAtoms,
                           t_nrnb *nrnb, gmx_wallcycle_t wcycle,
                           gmx_edsam_t ed,
                           t_forcerec *fr,
@@ -2409,7 +2412,7 @@ double do_steep(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo
                 gmx_mtop_t *top_global, t_fcdata *fcd,
                 t_state *state_global,
                 ObservablesHistory *observablesHistory,
-                t_mdatoms *mdatoms,
+                gmx::MDAtoms *mdAtoms,
                 t_nrnb *nrnb, gmx_wallcycle_t wcycle,
                 t_forcerec *fr,
                 const ReplicaExchangeParameters gmx_unused &replExParams,
@@ -2431,6 +2434,7 @@ double do_steep(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo
     int               nsteps;
     int               count          = 0;
     int               steps_accepted = 0;
+    auto              mdatoms        = mdAtoms->mdatoms();
 
     /* Create 2 states on the stack and extract pointers that we will swap */
     em_state_t  s0 {}, s1 {};
@@ -2440,7 +2444,7 @@ double do_steep(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo
     /* Init em and store the local state in s_try */
     init_em(fplog, SD, cr, outputProvider, inputrec, mdrunOptions,
             state_global, top_global, s_try, &top,
-            nrnb, mu_tot, fr, &enerd, &graph, mdatoms, &gstat,
+            nrnb, mu_tot, fr, &enerd, &graph, mdAtoms, &gstat,
             vsite, constr, nullptr,
             nfile, fnm, &outf, &mdebin, wcycle);
 
@@ -2494,7 +2498,7 @@ double do_steep(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo
             evaluate_energy(fplog, cr,
                             top_global, s_try, top,
                             inputrec, nrnb, wcycle, gstat,
-                            vsite, constr, fcd, graph, mdatoms, fr,
+                            vsite, constr, fcd, graph, mdAtoms, fr,
                             mu_tot, enerd, vir, pres, count, count == 0);
         }
         else
@@ -2580,7 +2584,7 @@ double do_steep(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo
             {
                 /* Reload the old state */
                 em_dd_partition_system(fplog, count, cr, top_global, inputrec,
-                                       s_min, top, mdatoms, fr, vsite, constr,
+                                       s_min, top, mdAtoms, fr, vsite, constr,
                                        nrnb, wcycle);
             }
         }
@@ -2657,7 +2661,7 @@ double do_steep(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo
                           t_inputrec *inputrec,
                           gmx_mtop_t *top_global, t_fcdata *fcd,
                           t_state *state_global,
-                          t_mdatoms *mdatoms,
+                          gmx::MDAtoms *mdAtoms,
                           t_nrnb *nrnb, gmx_wallcycle_t wcycle,
                           gmx_edsam_t ed,
                           t_forcerec *fr,
@@ -2674,7 +2678,7 @@ double do_nm(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
              gmx_mtop_t *top_global, t_fcdata *fcd,
              t_state *state_global,
              ObservablesHistory gmx_unused *observablesHistory,
-             t_mdatoms *mdatoms,
+             gmx::MDAtoms *mdAtoms,
              t_nrnb *nrnb, gmx_wallcycle_t wcycle,
              t_forcerec *fr,
              const ReplicaExchangeParameters gmx_unused &replExParams,
@@ -2701,6 +2705,7 @@ double do_nm(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
     real                      der_range = 10.0*sqrt(GMX_REAL_EPS);
     real                      x_min;
     bool                      bIsMaster = MASTER(cr);
+    auto                      mdatoms   = mdAtoms->mdatoms();
 
     if (constr != nullptr)
     {
@@ -2714,7 +2719,7 @@ double do_nm(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
     /* Init em and store the local state in state_minimum */
     init_em(fplog, NM, cr, outputProvider, inputrec, mdrunOptions,
             state_global, top_global, &state_work, &top,
-            nrnb, mu_tot, fr, &enerd, &graph, mdatoms, &gstat,
+            nrnb, mu_tot, fr, &enerd, &graph, mdAtoms, &gstat,
             vsite, constr, &shellfc,
             nfile, fnm, &outf, nullptr, wcycle);
 
@@ -2794,7 +2799,7 @@ double do_nm(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
     evaluate_energy(fplog, cr,
                     top_global, &state_work, top,
                     inputrec, nrnb, wcycle, gstat,
-                    vsite, constr, fcd, graph, mdatoms, fr,
+                    vsite, constr, fcd, graph, mdAtoms, fr,
                     mu_tot, enerd, vir, pres, -1, TRUE);
     cr->nnodes = nnodes;
 
@@ -2868,7 +2873,7 @@ double do_nm(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                     evaluate_energy(fplog, cr,
                                     top_global, &state_work, top,
                                     inputrec, nrnb, wcycle, gstat,
-                                    vsite, constr, fcd, graph, mdatoms, fr,
+                                    vsite, constr, fcd, graph, mdAtoms, fr,
                                     mu_tot, enerd, vir, pres, atom*2+dx, FALSE);
                 }
 
index 5a68205f3564d8e7a0f40ad772b4b42d9457cf77..5ea806f6613cd9fffec6405f66d6ef70795ddc72 100644 (file)
@@ -136,7 +136,7 @@ namespace gmx
                            t_inputrec *inputrec,
                            gmx_mtop_t *top_global, t_fcdata *fcd,
                            t_state *state_global,
-                           t_mdatoms *mdatoms,
+                           gmx::MDAtoms *mdAtoms,
                            t_nrnb *nrnb, gmx_wallcycle_t wcycle,
                            gmx_edsam_t ed,
                            t_forcerec *fr,
@@ -154,7 +154,7 @@ double do_tpi(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
               gmx_mtop_t *top_global, t_fcdata *fcd,
               t_state *state_global,
               ObservablesHistory gmx_unused *observablesHistory,
-              t_mdatoms *mdatoms,
+              gmx::MDAtoms *mdAtoms,
               t_nrnb *nrnb, gmx_wallcycle_t wcycle,
               t_forcerec *fr,
               const ReplicaExchangeParameters gmx_unused &replExParams,
@@ -190,6 +190,7 @@ double do_tpi(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
     real             prescorr, enercorr, dvdlcorr;
     gmx_bool         bEnergyOutOfBounds;
     const char      *tpid_leg[2] = {"direct", "reweighted"};
+    auto             mdatoms     = mdAtoms->mdatoms();
 
     GMX_UNUSED_VALUE(outputProvider);
 
@@ -282,7 +283,7 @@ double do_tpi(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog,
         sscanf(dump_pdb, "%20lf", &dump_ener);
     }
 
-    atoms2md(top_global, inputrec, -1, nullptr, top_global->natoms, mdatoms);
+    atoms2md(top_global, inputrec, -1, nullptr, top_global->natoms, mdAtoms);
     update_mdatoms(mdatoms, inputrec->fepvals->init_lambda);
 
     snew(enerd, 1);
index 3903d3091fabc74102d4a388a8d0f07e02a4e727..0885f1e3eeb064b3746a24664a57167a69603fe0 100644 (file)
@@ -304,7 +304,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                   t_fcdata *fcd,
                   t_state *state_global,
                   ObservablesHistory *observablesHistory,
-                  t_mdatoms *mdatoms,
+                  gmx::MDAtoms *mdAtoms,
                   t_nrnb *nrnb, gmx_wallcycle_t wcycle,
                   t_forcerec *fr,
                   const ReplicaExchangeParameters &replExParams,
@@ -525,7 +525,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
 
         snew(top, 1);
         mdAlgorithmsSetupAtomData(cr, ir, top_global, top, fr,
-                                  &graph, mdatoms, vsite, shellfc);
+                                  &graph, mdAtoms, vsite, shellfc);
 
         update_realloc(upd, state->natoms);
     }
@@ -539,13 +539,15 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
         /* Distribute the charge groups over the nodes from the master node */
         dd_partition_system(fplog, ir->init_step, cr, TRUE, 1,
                             state_global, top_global, ir,
-                            state, &f, mdatoms, top, fr,
+                            state, &f, mdAtoms, top, fr,
                             vsite, constr,
                             nrnb, nullptr, FALSE);
         shouldCheckNumberOfBondedInteractions = true;
         update_realloc(upd, state->natoms);
     }
 
+    auto mdatoms = mdAtoms->mdatoms();
+
     // NOTE: The global state is no longer used at this point.
     // But state_global is still used as temporary storage space for writing
     // the global state to file and potentially for replica exchange.
@@ -1068,7 +1070,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                 dd_partition_system(fplog, step, cr,
                                     bMasterState, nstglobalcomm,
                                     state_global, top_global, ir,
-                                    state, &f, mdatoms, top, fr,
+                                    state, &f, mdAtoms, top, fr,
                                     vsite, constr,
                                     nrnb, wcycle,
                                     do_verbose && !bPMETunePrinting);
@@ -1802,7 +1804,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
         {
             dd_partition_system(fplog, step, cr, TRUE, 1,
                                 state_global, top_global, ir,
-                                state, &f, mdatoms, top, fr,
+                                state, &f, mdAtoms, top, fr,
                                 vsite, constr,
                                 nrnb, wcycle, FALSE);
             shouldCheckNumberOfBondedInteractions = true;
index 2e4b7237cc3a76e1062eab0a07595d6190943457..d9f098c5912d0ffd246f412259e931613811f56d 100644 (file)
@@ -437,7 +437,6 @@ int Mdrunner::mdrunner()
     int                       npme_major, npme_minor;
     t_nrnb                   *nrnb;
     gmx_mtop_t               *mtop          = nullptr;
-    t_mdatoms                *mdatoms       = nullptr;
     t_forcerec               *fr            = nullptr;
     t_fcdata                 *fcd           = nullptr;
     real                      ewaldcoeff_q  = 0;
@@ -977,6 +976,8 @@ int Mdrunner::mdrunner()
         membed = init_membed(fplog, nfile, fnm, mtop, inputrec, globalState.get(), cr, &mdrunOptions.checkpointOptions.period);
     }
 
+    std::unique_ptr<MDAtoms> mdAtoms;
+
     snew(nrnb, 1);
     if (thisRankHasDuty(cr, DUTY_PP))
     {
@@ -998,11 +999,11 @@ int Mdrunner::mdrunner()
             init_QMMMrec(cr, mtop, inputrec, fr);
         }
 
-        /* Initialize the mdatoms structure.
-         * mdatoms is not filled with atom data,
+        /* Initialize the mdAtoms structure.
+         * mdAtoms is not filled with atom data,
          * as this can not be done now with domain decomposition.
          */
-        mdatoms = init_mdatoms(fplog, *mtop, *inputrec);
+        mdAtoms = makeMDAtoms(fplog, *mtop, *inputrec);
 
         /* Initialize the virtual site communication */
         vsite = initVsite(*mtop, cr);
@@ -1081,12 +1082,12 @@ int Mdrunner::mdrunner()
      * either on all nodes or on dedicated PME nodes only. */
     if (EEL_PME(inputrec->coulombtype) || EVDW_PME(inputrec->vdwtype))
     {
-        if (mdatoms)
+        if (mdAtoms && mdAtoms->mdatoms())
         {
-            nChargePerturbed = mdatoms->nChargePerturbed;
+            nChargePerturbed = mdAtoms->mdatoms()->nChargePerturbed;
             if (EVDW_PME(inputrec->vdwtype))
             {
-                nTypePerturbed   = mdatoms->nTypePerturbed;
+                nTypePerturbed   = mdAtoms->mdatoms()->nTypePerturbed;
             }
         }
         if (cr->npmenodes > 0)
@@ -1172,7 +1173,7 @@ int Mdrunner::mdrunner()
                                      fcd,
                                      globalState.get(),
                                      &observablesHistory,
-                                     mdatoms, nrnb, wcycle, fr,
+                                     mdAtoms.get(), nrnb, wcycle, fr,
                                      replExParams,
                                      membed,
                                      walltime_accounting);