Modernize atom enums
authorPaul Bauer <paul.bauer.q@gmail.com>
Tue, 2 Mar 2021 15:34:21 +0000 (15:34 +0000)
committerPaul Bauer <paul.bauer.q@gmail.com>
Tue, 2 Mar 2021 15:34:21 +0000 (15:34 +0000)
Use enum classes and enumeration array for particle and PDB record
types.

35 files changed:
api/legacy/include/gromacs/fileio/pdbio.h
src/gromacs/domdec/domdec_topology.cpp
src/gromacs/domdec/dump.cpp
src/gromacs/fileio/pdbio.cpp
src/gromacs/fileio/tpxio.cpp
src/gromacs/gmxana/gmx_anaeig.cpp
src/gromacs/gmxana/gmx_chi.cpp
src/gromacs/gmxana/gmx_confrms.cpp
src/gromacs/gmxana/gmx_order.cpp
src/gromacs/gmxpreprocess/editconf.cpp
src/gromacs/gmxpreprocess/gen_vsite.cpp
src/gromacs/gmxpreprocess/gpp_atomtype.cpp
src/gromacs/gmxpreprocess/gpp_atomtype.h
src/gromacs/gmxpreprocess/grompp.cpp
src/gromacs/gmxpreprocess/readir.cpp
src/gromacs/gmxpreprocess/topio.cpp
src/gromacs/gmxpreprocess/toppush.cpp
src/gromacs/gmxpreprocess/vsite_parm.cpp
src/gromacs/mdlib/calc_verletbuf.cpp
src/gromacs/mdlib/constr.cpp
src/gromacs/mdlib/mdatoms.cpp
src/gromacs/mdlib/update.cpp
src/gromacs/mdlib/vsite.cpp
src/gromacs/mdrun/md.cpp
src/gromacs/mdrun/shellfc.cpp
src/gromacs/mdrun/shellfc.h
src/gromacs/mdtypes/mdatom.h
src/gromacs/modularsimulator/statepropagatordata.cpp
src/gromacs/taskassignment/decidegpuusage.cpp
src/gromacs/tools/report_methods.cpp
src/gromacs/topology/atoms.cpp
src/gromacs/topology/atoms.h
src/gromacs/topology/mtop_util.cpp
src/gromacs/topology/mtop_util.h
src/gromacs/trajectoryanalysis/modules/sasa.cpp

index fee2ab1373b2d457b2d915120449164257b8a3af..c34562e095dd86d4fb0b72a812bd668e0cabf6fd 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
  * Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, 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.
@@ -51,6 +51,7 @@ struct t_atoms;
 struct t_symtab;
 struct t_topology;
 enum class PbcType : int;
+enum class PdbRecordType : int;
 
 typedef struct gmx_conect_t* gmx_conect;
 
@@ -58,21 +59,21 @@ typedef struct gmx_conect_t* gmx_conect;
  *
  * Returns the number of characters printed.
  */
-int gmx_fprintf_pdb_atomline(FILE*           fp,
-                             enum PDB_record record,
-                             int             atom_seq_number,
-                             const char*     atom_name,
-                             char            alternate_location,
-                             const char*     res_name,
-                             char            chain_id,
-                             int             res_seq_number,
-                             char            res_insertion_code,
-                             real            x,
-                             real            y,
-                             real            z,
-                             real            occupancy,
-                             real            b_factor,
-                             const char*     element);
+int gmx_fprintf_pdb_atomline(FILE*         fp,
+                             PdbRecordType record,
+                             int           atom_seq_number,
+                             const char*   atom_name,
+                             char          alternate_location,
+                             const char*   res_name,
+                             char          chain_id,
+                             int           res_seq_number,
+                             char          res_insertion_code,
+                             real          x,
+                             real          y,
+                             real          z,
+                             real          occupancy,
+                             real          b_factor,
+                             const char*   element);
 
 /* Enumerated value for indexing an uij entry (anisotropic temperature factors) */
 enum
index 0f1f5462b065ed52dc1f63bbb658819dd17909aa..c4a5ac2cd82016b721712755274359af3b669881 100644 (file)
@@ -597,7 +597,7 @@ static int low_make_reverse_ilist(const InteractionLists&  il_mt,
                             r_il[r_index[a] + count[a] + 2 + nral] = 0;
                             for (int j = 2; j < 1 + nral; j++)
                             {
-                                if (atom[ia[j]].ptype == eptVSite)
+                                if (atom[ia[j]].ptype == ParticleType::VSite)
                                 {
                                     r_il[r_index[a] + count[a] + 2 + nral] |= (2 << j);
                                 }
index be9f0c77db34b8a949622960938ec26a1694af12..7a7324cd4ab68f4ea86d63f4cbae00c24a7b0475 100644 (file)
@@ -120,7 +120,7 @@ void write_dd_grid_pdb(const char* fn, int64_t step, gmx_domdec_t* dd, matrix bo
                         cx[ZZ] = grid_r[i * 2 + z][ZZ];
                         mvmul(tric, cx, r);
                         gmx_fprintf_pdb_atomline(out,
-                                                 epdbATOM,
+                                                 PdbRecordType::Atom,
                                                  a++,
                                                  "CA",
                                                  ' ',
@@ -208,7 +208,7 @@ void write_dd_pdb(const char*       fn,
             b = dd->comm->zones.n + 1;
         }
         gmx_fprintf_pdb_atomline(out,
-                                 epdbATOM,
+                                 PdbRecordType::Atom,
                                  ii + 1,
                                  atomname,
                                  ' ',
index d2f373c63d78b88e0e0497ac394ee0d82a04232b..c46a2ccb2ef8aafe898cc0f7b6c60f88e8688b0a 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
  * Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, 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.
@@ -39,6 +39,7 @@
 
 #include "gromacs/fileio/pdbio.h"
 
+#include <algorithm>
 #include <cctype>
 #include <cmath>
 #include <cstdlib>
@@ -57,6 +58,7 @@
 #include "gromacs/topology/topology.h"
 #include "gromacs/utility/coolstuff.h"
 #include "gromacs/utility/cstringutil.h"
+#include "gromacs/utility/enumerationhelpers.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
@@ -74,8 +76,14 @@ typedef struct gmx_conect_t
     gmx_conection_t* conect;
 } gmx_conect_t;
 
-static const char* pdbtp[epdbNR] = { "ATOM  ", "HETATM", "ANISOU", "CRYST1", "COMPND", "MODEL",
-                                     "ENDMDL", "TER",    "HEADER", "TITLE",  "REMARK", "CONECT" };
+const char* enumValueToString(PdbRecordType enumValue)
+{
+    static constexpr gmx::EnumerationArray<PdbRecordType, const char*> pdbRecordTypeName = {
+        "ATOM  ", "HETATM", "ANISOU", "CRYST1", "COMPND", "MODEL",
+        "ENDMDL", "TER",    "HEADER", "TITLE",  "REMARK", "CONECT"
+    };
+    return pdbRecordTypeName[enumValue];
+}
 
 #define REMARK_SIM_BOX "REMARK    THIS IS A SIMULATION BOX"
 
@@ -235,20 +243,20 @@ static void read_cryst1(char* line, PbcType* pbcType, matrix box)
     }
 }
 
-static int gmx_fprintf_pqr_atomline(FILE*           fp,
-                                    enum PDB_record record,
-                                    int             atom_seq_number,
-                                    const char*     atom_name,
-                                    const char*     res_name,
-                                    char            chain_id,
-                                    int             res_seq_number,
-                                    real            x,
-                                    real            y,
-                                    real            z,
-                                    real            occupancy,
-                                    real            b_factor)
+static int gmx_fprintf_pqr_atomline(FILE*         fp,
+                                    PdbRecordType record,
+                                    int           atom_seq_number,
+                                    const char*   atom_name,
+                                    const char*   res_name,
+                                    char          chain_id,
+                                    int           res_seq_number,
+                                    real          x,
+                                    real          y,
+                                    real          z,
+                                    real          occupancy,
+                                    real          b_factor)
 {
-    GMX_RELEASE_ASSERT(record == epdbATOM || record == epdbHETATM,
+    GMX_RELEASE_ASSERT(record == PdbRecordType::Atom || record == PdbRecordType::Hetatm,
                        "Can only print PQR atom lines as ATOM or HETATM records");
 
     /* Check atom name */
@@ -263,7 +271,7 @@ static int gmx_fprintf_pqr_atomline(FILE*           fp,
 
     int n = fprintf(fp,
                     "%-6s%5d %-4.4s%4.4s%c%4d %8.3f %8.3f %8.3f %6.2f %6.2f\n",
-                    pdbtp[record],
+                    enumValueToString(record),
                     atom_seq_number,
                     atom_name,
                     res_name,
@@ -291,11 +299,11 @@ void write_pdbfile_indexed(FILE*          out,
                            gmx_conect     conect,
                            bool           usePqrFormat)
 {
-    gmx_conect_t*   gc = static_cast<gmx_conect_t*>(conect);
-    enum PDB_record type;
-    char            altloc;
-    real            occup, bfac;
-    gmx_bool        bOccup;
+    gmx_conect_t* gc = static_cast<gmx_conect_t*>(conect);
+    PdbRecordType type;
+    char          altloc;
+    real          occup, bfac;
+    gmx_bool      bOccup;
 
 
     fprintf(out, "TITLE     %s\n", (title && title[0]) ? title : gmx::bromacs().c_str());
@@ -359,7 +367,7 @@ void write_pdbfile_indexed(FILE*          out,
         {
             gmx_pdbinfo_init_default(&pdbinfo);
         }
-        type   = static_cast<enum PDB_record>(pdbinfo.type);
+        type   = pdbinfo.type;
         altloc = pdbinfo.altloc;
         if (!isalnum(altloc))
         {
@@ -455,7 +463,7 @@ void write_pdbfile(FILE*          out,
     sfree(index);
 }
 
-static int line2type(const char* line)
+static PdbRecordType line2type(const char* line)
 {
     int  k;
     char type[8];
@@ -466,15 +474,12 @@ static int line2type(const char* line)
     }
     type[k] = '\0';
 
-    for (k = 0; (k < epdbNR); k++)
-    {
-        if (std::strncmp(type, pdbtp[k], strlen(pdbtp[k])) == 0)
-        {
-            break;
-        }
-    }
-
-    return k;
+    using PdbRecordArray = gmx::EnumerationArray<PdbRecordType, bool>;
+    auto entry           = std::find_if(
+            PdbRecordArray::keys().begin(), PdbRecordArray::keys().end(), [type](const auto& key) {
+                return std::strncmp(type, enumValueToString(key), strlen(enumValueToString(key))) == 0;
+            });
+    return (entry != PdbRecordArray::keys().end()) ? *entry : PdbRecordType::Count;
 }
 
 static void read_anisou(char line[], int natom, t_atoms* atoms)
@@ -602,7 +607,8 @@ void get_pdb_atomnumber(const t_atoms* atoms, AtomProperties* aps)
     }
 }
 
-static int read_atom(t_symtab* symtab, const char line[], int type, int natom, t_atoms* atoms, rvec x[], int chainnum)
+static int
+read_atom(t_symtab* symtab, const char line[], PdbRecordType type, int natom, t_atoms* atoms, rvec x[], int chainnum)
 {
     t_atom*       atomn;
     int           j, k;
@@ -861,7 +867,6 @@ int read_pdbfile(FILE*      in,
     gmx_bool      bCOMPND;
     gmx_bool      bConnWarn = FALSE;
     char          line[STRLEN + 1];
-    int           line_type;
     char *        c, *d;
     int           natom, chainnum;
     gmx_bool      bStop = FALSE;
@@ -888,26 +893,26 @@ int read_pdbfile(FILE*      in,
     chainnum = 0;
     while (!bStop && (fgets2(line, STRLEN, in) != nullptr))
     {
-        line_type = line2type(line);
+        PdbRecordType line_type = line2type(line);
 
         switch (line_type)
         {
-            case epdbATOM:
-            case epdbHETATM:
+            case PdbRecordType::Atom:
+            case PdbRecordType::Hetatm:
                 natom = read_atom(symtab, line, line_type, natom, atoms, x, chainnum);
                 break;
 
-            case epdbANISOU:
+            case PdbRecordType::Anisou:
                 if (atoms->havePdbInfo)
                 {
                     read_anisou(line, natom, atoms);
                 }
                 break;
 
-            case epdbCRYST1: read_cryst1(line, pbcType, box); break;
+            case PdbRecordType::Cryst1: read_cryst1(line, pbcType, box); break;
 
-            case epdbTITLE:
-            case epdbHEADER:
+            case PdbRecordType::Title:
+            case PdbRecordType::Header:
                 if (std::strlen(line) > 6)
                 {
                     c = line + 6;
@@ -933,7 +938,7 @@ int read_pdbfile(FILE*      in,
                 }
                 break;
 
-            case epdbCOMPND:
+            case PdbRecordType::Compound:
                 if ((!std::strstr(line, ": ")) || (std::strstr(line + 6, "MOLECULE:")))
                 {
                     if (!(c = std::strstr(line + 6, "MOLECULE:")))
@@ -975,17 +980,17 @@ int read_pdbfile(FILE*      in,
                 }
                 break;
 
-            case epdbTER: chainnum++; break;
+            case PdbRecordType::Ter: chainnum++; break;
 
-            case epdbMODEL:
+            case PdbRecordType::Model:
                 if (model_nr)
                 {
                     sscanf(line, "%*s%d", model_nr);
                 }
                 break;
 
-            case epdbENDMDL: bStop = TRUE; break;
-            case epdbCONECT:
+            case PdbRecordType::EndModel: bStop = TRUE; break;
+            case PdbRecordType::Conect:
                 if (gc)
                 {
                     gmx_conect_addline(gc, line);
@@ -1055,27 +1060,27 @@ gmx_conect gmx_conect_generate(const t_topology* top)
     return gc;
 }
 
-int gmx_fprintf_pdb_atomline(FILE*           fp,
-                             enum PDB_record record,
-                             int             atom_seq_number,
-                             const char*     atom_name,
-                             char            alternate_location,
-                             const char*     res_name,
-                             char            chain_id,
-                             int             res_seq_number,
-                             char            res_insertion_code,
-                             real            x,
-                             real            y,
-                             real            z,
-                             real            occupancy,
-                             real            b_factor,
-                             const char*     element)
+int gmx_fprintf_pdb_atomline(FILE*         fp,
+                             PdbRecordType record,
+                             int           atom_seq_number,
+                             const char*   atom_name,
+                             char          alternate_location,
+                             const char*   res_name,
+                             char          chain_id,
+                             int           res_seq_number,
+                             char          res_insertion_code,
+                             real          x,
+                             real          y,
+                             real          z,
+                             real          occupancy,
+                             real          b_factor,
+                             const char*   element)
 {
     char     tmp_atomname[6], tmp_resname[6];
     gmx_bool start_name_in_col13;
     int      n;
 
-    if (record != epdbATOM && record != epdbHETATM)
+    if (record != PdbRecordType::Atom && record != PdbRecordType::Hetatm)
     {
         gmx_fatal(FARGS, "Can only print PDB atom lines as ATOM or HETATM records");
     }
@@ -1120,7 +1125,7 @@ int gmx_fprintf_pdb_atomline(FILE*           fp,
 
     n = fprintf(fp,
                 "%-6s%5d %-4.4s%c%4.4s%c%4d%c   %8.3f%8.3f%8.3f%6.2f%6.2f          %2s\n",
-                pdbtp[record],
+                enumValueToString(record),
                 atom_seq_number,
                 tmp_atomname,
                 alternate_location,
index 38c5335216d5a135e89a0ad1e9780f81d0412516..448bb9dd58aef89cf2ee7c09cbf4fc0087bf7821 100644 (file)
@@ -2294,7 +2294,7 @@ static void do_atom(gmx::ISerializer* serializer, t_atom* atom)
     serializer->doReal(&atom->qB);
     serializer->doUShort(&atom->type);
     serializer->doUShort(&atom->typeB);
-    serializer->doInt(&atom->ptype);
+    serializer->doEnumAsInt(&atom->ptype);
     serializer->doInt(&atom->resind);
     serializer->doInt(&atom->atomnumber);
     if (serializer->reading())
index 94c2b4b04029b576a3b0031fe519e96be60edb8d..76baee59acfd4a85867abac9fbac432b272fe10e 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
  * Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, 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.
@@ -775,7 +775,7 @@ static void project(const char*             trajfile,
                     j = 0;
                 }
                 gmx_fprintf_pdb_atomline(out,
-                                         epdbATOM,
+                                         PdbRecordType::Atom,
                                          i + 1,
                                          "C",
                                          ' ',
index 429f21a71065c2185312d242cd3153fc038425ee..9cafe37eac0bc0e1ff6e12fec5d2fe752554d7e6 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
  * Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, 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.
@@ -1213,7 +1213,7 @@ static void order_params(FILE*                   log,
         for (i = 0; (i < 10); i++)
         {
             gmx_fprintf_pdb_atomline(fp,
-                                     epdbATOM,
+                                     PdbRecordType::Atom,
                                      atoms->nr + 1 + i,
                                      "CA",
                                      ' ',
index dcd6adba8a9130b0229a41e6acf8dd6d49189fe5..27714d884997d3904a552af6e00fe2d7ccf22d20 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
  * Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, 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.
@@ -758,7 +758,7 @@ int gmx_confrms(int argc, char* argv[])
                 /* Avoid segfaults when writing the pdb-file */
                 for (i = 0; i < atoms1->nr; i++)
                 {
-                    atoms1->pdbinfo[i].type         = eptAtom;
+                    atoms1->pdbinfo[i].type         = PdbRecordType::Atom;
                     atoms1->pdbinfo[i].occup        = 1.00;
                     atoms1->pdbinfo[i].bAnisotropic = FALSE;
                     if (bBfac)
@@ -787,7 +787,7 @@ int gmx_confrms(int argc, char* argv[])
 
                 for (i = 0; i < atoms2->nr; i++)
                 {
-                    atoms2->pdbinfo[i].type         = eptAtom;
+                    atoms2->pdbinfo[i].type         = PdbRecordType::Atom;
                     atoms2->pdbinfo[i].occup        = 1.00;
                     atoms2->pdbinfo[i].bAnisotropic = FALSE;
                     if (bBfac)
index bbf61e90b3118a3309d0c30b319af2c779cdc972..3a02b9f1a69a5070bb0786d17ce3edf0302f0b22 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
  * Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, 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.
@@ -928,7 +928,7 @@ static void write_bfactors(t_filenm*         fnm,
     /*initialize PDBinfo*/
     for (i = 0; i < useatoms.nr; ++i)
     {
-        useatoms.pdbinfo[i].type         = 0;
+        useatoms.pdbinfo[i].type         = PdbRecordType::Atom;
         useatoms.pdbinfo[i].occup        = 0.0;
         useatoms.pdbinfo[i].bfac         = 0.0;
         useatoms.pdbinfo[i].bAnisotropic = FALSE;
index 257f1bbb3945f4bdf2b3f3da9856d7e8e4028087..085907a90b20a49238e6b2df7e8ddb7e31a66fab 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
  * Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, 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.
@@ -417,7 +417,7 @@ static void visualize_box(FILE* out, int a0, int r0, matrix box, const rvec grid
         for (i = 0; i < nat; i++)
         {
             gmx_fprintf_pdb_atomline(out,
-                                     epdbATOM,
+                                     PdbRecordType::Atom,
                                      a0 + i,
                                      "C",
                                      ' ',
@@ -457,7 +457,7 @@ static void visualize_box(FILE* out, int a0, int r0, matrix box, const rvec grid
                 for (x = 0; x <= 1; x++)
                 {
                     gmx_fprintf_pdb_atomline(out,
-                                             epdbATOM,
+                                             PdbRecordType::Atom,
                                              a0 + i,
                                              "C",
                                              ' ',
index b6e77efd388757081b5a30310b28fc2266f01c78..8c6ac3352e215457bd484e1fc47cb38616023826 100644 (file)
@@ -1180,7 +1180,7 @@ static int gen_vsites_trp(PreprocessingAtomTypes*                  atype,
         (*newatom)[atM[j]].m = (*newatom)[atM[j]].mB = mM[j];
         (*newatom)[atM[j]].q = (*newatom)[atM[j]].qB = 0.0;
         (*newatom)[atM[j]].type = (*newatom)[atM[j]].typeB = tpM;
-        (*newatom)[atM[j]].ptype                           = eptAtom;
+        (*newatom)[atM[j]].ptype                           = ParticleType::Atom;
         (*newatom)[atM[j]].resind                          = at->atom[i0].resind;
         (*newatom)[atM[j]].elem[0]                         = 'M';
         (*newatom)[atM[j]].elem[1]                         = '\0';
@@ -1376,7 +1376,7 @@ static int gen_vsites_tyr(PreprocessingAtomTypes*                  atype,
     (*newatom)[atM].m = (*newatom)[atM].mB = mM;
     (*newatom)[atM].q = (*newatom)[atM].qB = 0.0;
     (*newatom)[atM].type = (*newatom)[atM].typeB = tpM;
-    (*newatom)[atM].ptype                        = eptAtom;
+    (*newatom)[atM].ptype                        = ParticleType::Atom;
     (*newatom)[atM].resind                       = at->atom[i0].resind;
     (*newatom)[atM].elem[0]                      = 'M';
     (*newatom)[atM].elem[1]                      = '\0';
@@ -2174,7 +2174,7 @@ void do_vsites(gmx::ArrayRef<const PreprocessResidue> rtpFFDB,
                         newatom[ni0 + j].m = newatom[ni0 + j].mB = mtot / NMASS;
                         newatom[ni0 + j].q = newatom[ni0 + j].qB = 0.0;
                         newatom[ni0 + j].type = newatom[ni0 + j].typeB = tpM;
-                        newatom[ni0 + j].ptype                         = eptAtom;
+                        newatom[ni0 + j].ptype                         = ParticleType::Atom;
                         newatom[ni0 + j].resind                        = at->atom[i0].resind;
                         newatom[ni0 + j].elem[0]                       = 'M';
                         newatom[ni0 + j].elem[1]                       = '\0';
index 1361ce29118efcda7c7375e4f835e143c0c4572f..b832adf2d0a3cbf00c3ddd8eac245f2853731c39 100644 (file)
@@ -130,7 +130,7 @@ std::optional<real> PreprocessingAtomTypes::atomChargeFromAtomType(int nt) const
     return isSet(nt) ? std::make_optional(impl_->types[nt].atom_.q) : std::nullopt;
 }
 
-std::optional<int> PreprocessingAtomTypes::atomParticleTypeFromAtomType(int nt) const
+std::optional<ParticleType> PreprocessingAtomTypes::atomParticleTypeFromAtomType(int nt) const
 {
     return isSet(nt) ? std::make_optional(impl_->types[nt].atom_.ptype) : std::nullopt;
 }
index 47c41442ba46b4d2f9959a004ad697df8aae9e18..6d28b0c456ed7b91aced5872cfc42dd0ab1518db 100644 (file)
@@ -60,7 +60,7 @@ struct t_atomtypes;
 class InteractionOfType;
 struct InteractionsOfType;
 struct t_symtab;
-
+enum class ParticleType : int;
 namespace gmx
 {
 template<typename>
@@ -127,7 +127,7 @@ public:
      * \param[in] nt Internal number of atom type.
      * \returns The optional particle type.
      */
-    std::optional<int> atomParticleTypeFromAtomType(int nt) const;
+    std::optional<ParticleType> atomParticleTypeFromAtomType(int nt) const;
 
     /*! \brief
      * Get bond atom parameter of atom from internal atom type number.
index b8567d2a5328d33cc1a0fcf94b424ee5f18fdf67..fe22cd5b0f253ab7b2bacd79efad186a8eb1f148 100644 (file)
@@ -468,7 +468,8 @@ static void check_vel(gmx_mtop_t* mtop, rvec v[])
     {
         const t_atom& local = atomP.atom();
         int           i     = atomP.globalAtomNumber();
-        if (local.ptype == eptShell || local.ptype == eptBond || local.ptype == eptVSite)
+        if (local.ptype == ParticleType::Shell || local.ptype == ParticleType::Bond
+            || local.ptype == ParticleType::VSite)
         {
             clear_rvec(v[i]);
         }
@@ -482,7 +483,7 @@ static void check_shells_inputrec(gmx_mtop_t* mtop, t_inputrec* ir, warninp* wi)
     for (const AtomProxy atomP : AtomRange(*mtop))
     {
         const t_atom& local = atomP.atom();
-        if (local.ptype == eptShell || local.ptype == eptBond)
+        if (local.ptype == ParticleType::Shell || local.ptype == ParticleType::Bond)
         {
             nshells++;
         }
@@ -1171,7 +1172,8 @@ static int nrdf_internal(const t_atoms* atoms)
     for (i = 0; i < atoms->nr; i++)
     {
         /* Vsite ptype might not be set here yet, so also check the mass */
-        if ((atoms->atom[i].ptype == eptAtom || atoms->atom[i].ptype == eptNucleus) && atoms->atom[i].m > 0)
+        if ((atoms->atom[i].ptype == ParticleType::Atom || atoms->atom[i].ptype == ParticleType::Nucleus)
+            && atoms->atom[i].m > 0)
         {
             nmass++;
         }
@@ -1454,7 +1456,7 @@ static void checkForUnboundAtoms(const gmx_moltype_t* molt, gmx_bool bVerbose, w
     int numDanglingAtoms = 0;
     for (int a = 0; a < atoms->nr; a++)
     {
-        if (atoms->atom[a].ptype != eptVSite && count[a] == 0)
+        if (atoms->atom[a].ptype != ParticleType::VSite && count[a] == 0)
         {
             if (bVerbose)
             {
index 2276b84de2ece6a26ab28878eefa816d00017318..c115cbeb9c385ca02cfdda484d985bfd2e868139 100644 (file)
@@ -2999,7 +2999,7 @@ static void calc_nrdf(const gmx_mtop_t* mtop, t_inputrec* ir, char** gnames)
         const t_atom& local = atomP.atom();
         int           i     = atomP.globalAtomNumber();
         nrdf2[i]            = 0;
-        if (local.ptype == eptAtom || local.ptype == eptNucleus)
+        if (local.ptype == ParticleType::Atom || local.ptype == ParticleType::Nucleus)
         {
             int g = getGroupType(groups, SimulationAtomGroupType::Freeze, i);
             for (int d = 0; d < DIM; d++)
@@ -3041,8 +3041,10 @@ static void calc_nrdf(const gmx_mtop_t* mtop, t_inputrec* ir, char** gnames)
                      */
                     int ai = as + ia[i + 1];
                     int aj = as + ia[i + 2];
-                    if (((atom[ia[i + 1]].ptype == eptNucleus) || (atom[ia[i + 1]].ptype == eptAtom))
-                        && ((atom[ia[i + 2]].ptype == eptNucleus) || (atom[ia[i + 2]].ptype == eptAtom)))
+                    if (((atom[ia[i + 1]].ptype == ParticleType::Nucleus)
+                         || (atom[ia[i + 1]].ptype == ParticleType::Atom))
+                        && ((atom[ia[i + 2]].ptype == ParticleType::Nucleus)
+                            || (atom[ia[i + 2]].ptype == ParticleType::Atom)))
                     {
                         if (nrdf2[ai] > 0)
                         {
index 54e15169ff25a1b52eba5f40c74a039dc0ccaca6..c4a84d8dd0b36de4db2467a4d6bb714b321a647a 100644 (file)
@@ -145,7 +145,7 @@ static void gen_pairs(const InteractionsOfType& nbs, InteractionsOfType* pairs,
 double check_mol(const gmx_mtop_t* mtop, warninp* wi)
 {
     char   buf[256];
-    int    i, ri, pt;
+    int    i, ri;
     double q;
     real   m, mB;
 
@@ -158,13 +158,13 @@ double check_mol(const gmx_mtop_t* mtop, warninp* wi)
         for (i = 0; (i < atoms->nr); i++)
         {
             q += molb.nmol * atoms->atom[i].q;
-            m  = atoms->atom[i].m;
-            mB = atoms->atom[i].mB;
-            pt = atoms->atom[i].ptype;
+            m               = atoms->atom[i].m;
+            mB              = atoms->atom[i].mB;
+            ParticleType pt = atoms->atom[i].ptype;
             /* If the particle is an atom or a nucleus it must have a mass,
              * else, if it is a shell, a vsite or a bondshell it can have mass zero
              */
-            if (((m <= 0.0) || (mB <= 0.0)) && ((pt == eptAtom) || (pt == eptNucleus)))
+            if (((m <= 0.0) || (mB <= 0.0)) && ((pt == ParticleType::Atom) || (pt == ParticleType::Nucleus)))
             {
                 ri = atoms->atom[i].resind;
                 sprintf(buf,
@@ -176,7 +176,7 @@ double check_mol(const gmx_mtop_t* mtop, warninp* wi)
                         mB);
                 warning_error(wi, buf);
             }
-            else if (((m != 0) || (mB != 0)) && (pt == eptVSite))
+            else if (((m != 0) || (mB != 0)) && (pt == ParticleType::VSite))
             {
                 ri = atoms->atom[i].resind;
                 sprintf(buf,
index ded1d521e7dcb9adf221a06d74f93d61eef9ffe5..ef613221efb7821bdd7a6d2b199d09e88f5ece07 100644 (file)
@@ -281,17 +281,19 @@ void push_at(t_symtab*                  symtab,
              t_nbparam***               pair,
              warninp*                   wi)
 {
-    typedef struct
-    {
-        const char* entry;
-        int         ptype;
-    } t_xlate;
-    t_xlate xl[eptNR] = {
-        { "A", eptAtom }, { "N", eptNucleus }, { "S", eptShell },
-        { "B", eptBond }, { "V", eptVSite },
+    struct t_xlate
+    {
+        const char*  entry;
+        ParticleType ptype;
     };
-
-    int     nfields, j, pt, nfp0 = -1;
+    gmx::EnumerationArray<ParticleType, t_xlate> xl;
+    xl[ParticleType::Atom]    = { "A", ParticleType::Atom };
+    xl[ParticleType::Nucleus] = { "N", ParticleType::Nucleus };
+    xl[ParticleType::Shell]   = { "S", ParticleType::Shell };
+    xl[ParticleType::Bond]    = { "B", ParticleType::Bond };
+    xl[ParticleType::VSite]   = { "V", ParticleType::VSite };
+
+    int     nfields, nfp0 = -1;
     int     nread;
     char    type[STRLEN], btype[STRLEN], ptype[STRLEN];
     double  m, q;
@@ -529,19 +531,15 @@ void push_at(t_symtab*                  symtab,
     {
         sprintf(ptype, "V");
     }
-    for (j = 0; (j < eptNR); j++)
-    {
-        if (gmx_strcasecmp(ptype, xl[j].entry) == 0)
-        {
-            break;
-        }
-    }
-    if (j == eptNR)
+    auto entry = std::find_if(xl.begin(), xl.end(), [ptype](const t_xlate& type) {
+        return gmx_strcasecmp(ptype, type.entry) == 0;
+    });
+    if (entry == xl.end())
     {
         auto message = gmx::formatString("Invalid particle type %s", ptype);
         warning_error_and_exit(wi, message, FARGS);
     }
-    pt = xl[j].ptype;
+    ParticleType pt = entry->ptype;
 
     atom->q     = q;
     atom->m     = m;
@@ -1303,23 +1301,23 @@ void push_cmaptype(Directive                         d,
 }
 
 
-static void push_atom_now(t_symtab* symtab,
-                          t_atoms*  at,
-                          int       atomnr,
-                          int       atomicnumber,
-                          int       type,
-                          char*     ctype,
-                          int       ptype,
-                          char*     resnumberic,
-                          char*     resname,
-                          char*     name,
-                          real      m0,
-                          real      q0,
-                          int       typeB,
-                          char*     ctypeB,
-                          real      mB,
-                          real      qB,
-                          warninp*  wi)
+static void push_atom_now(t_symtab*    symtab,
+                          t_atoms*     at,
+                          int          atomnr,
+                          int          atomicnumber,
+                          int          type,
+                          char*        ctype,
+                          ParticleType ptype,
+                          char*        resnumberic,
+                          char*        resname,
+                          char*        name,
+                          real         m0,
+                          real         q0,
+                          int          typeB,
+                          char*        ctypeB,
+                          real         mB,
+                          real         qB,
+                          warninp*     wi)
 {
     int           j, resind = 0, resnr;
     unsigned char ric;
@@ -1405,7 +1403,6 @@ static void push_atom_now(t_symtab* symtab,
 
 void push_atom(t_symtab* symtab, t_atoms* at, PreprocessingAtomTypes* atypes, char* line, warninp* wi)
 {
-    int  ptype;
     int  cgnumber, atomnr, nscan;
     char id[STRLEN], ctype[STRLEN], ctypeB[STRLEN], resnumberic[STRLEN], resname[STRLEN],
             name[STRLEN], check[STRLEN];
@@ -1425,7 +1422,7 @@ void push_atom(t_symtab* symtab, t_atoms* at, PreprocessingAtomTypes* atypes, ch
         auto message = gmx::formatString("Atomtype %s not found", ctype);
         warning_error_and_exit(wi, message, FARGS);
     }
-    ptype = *atypes->atomParticleTypeFromAtomType(*type);
+    ParticleType ptype = *atypes->atomParticleTypeFromAtomType(*type);
 
     /* Set default from type */
     q0         = *atypes->atomChargeFromAtomType(*type);
@@ -2649,7 +2646,7 @@ int add_atomtype_decoupled(t_symtab* symtab, PreprocessingAtomTypes* at, t_nbpar
     /* Type for decoupled atoms could be anything,
      * this should be changed automatically later when required.
      */
-    atom.ptype = eptAtom;
+    atom.ptype = ParticleType::Atom;
 
     std::array<real, MAXFORCEPARAM> forceParam = { 0.0 };
     nr = at->addType(symtab, atom, "decoupled", InteractionOfType({}, forceParam, ""), -1, 0);
index b681001137385dcb52acf151f89be6301cbc5957..2c4133119b4fde4aad3e7eff61d08a35a3a2e5d4 100644 (file)
@@ -931,7 +931,7 @@ void set_vsites_ptype(bool bVerbose, gmx_moltype_t* molt, const gmx::MDLogger& l
             {
                 /* The virtual site */
                 int avsite                     = ia[i + 1];
-                molt->atoms.atom[avsite].ptype = eptVSite;
+                molt->atoms.atom[avsite].ptype = ParticleType::VSite;
 
                 i += nra + 1;
             }
index 4cb664fa0ba8e362b1c4a28d660980924f3307f9..e7cd5759d3d6a9cef8a7248f3635cf90f82f37ba 100644 (file)
@@ -291,7 +291,7 @@ static void get_vsite_masses(const gmx_moltype_t&  moltype,
                     int  aj    = ilist.iatoms[i + j + 2];
                     real coeff = ffparams.iparams[ilist.iatoms[i + j]].vsiten.a;
                     real m_aj;
-                    if (moltype.atoms.atom[aj].ptype == eptVSite)
+                    if (moltype.atoms.atom[aj].ptype == ParticleType::VSite)
                     {
                         m_aj = vsite_m[aj];
                     }
@@ -397,7 +397,7 @@ static std::vector<VerletbufAtomtype> getVerletBufferAtomtypes(const gmx_mtop_t&
 
         for (a = 0; a < atoms->nr; a++)
         {
-            if (atoms->atom[a].ptype == eptVSite)
+            if (atoms->atom[a].ptype == ParticleType::VSite)
             {
                 prop[a].mass = vsite_m[a];
             }
index a4b4acd9fe45be4063243061597b50af0ab22e43..c80e67eb82b577c72055859d8ef92429b212bb13 100644 (file)
@@ -304,7 +304,7 @@ static void write_constr_pdb(const char*          fn,
         }
         mtopGetAtomAndResidueName(mtop, ii, &molb, &anm, &resnr, &resnm, nullptr);
         gmx_fprintf_pdb_atomline(out,
-                                 epdbATOM,
+                                 PdbRecordType::Atom,
                                  ii + 1,
                                  anm,
                                  ' ',
index 5ca3166ab0e4a3e6aacce8ddefb56f4d64c18813..66e412cee39e361828fc4294aeb43d0df88cd961 100644 (file)
@@ -155,7 +155,7 @@ std::unique_ptr<MDAtoms> makeMDAtoms(FILE* fp, const gmx_mtop_t& mtop, const t_i
         totalMassA += nmol * atom->m;
         totalMassB += nmol * atom->mB;
 
-        if (atom->ptype == eptVSite)
+        if (atom->ptype == ParticleType::VSite)
         {
             md->haveVsites = TRUE;
         }
index 84aa9a830543f1055d041cd2c258debbb6d8ae5e..6b695e5c52060bf75959b6f1bae386fdd43d647c 100644 (file)
@@ -753,7 +753,7 @@ static void do_update_vv_vel(int                  start,
                              real                 dt,
                              const ivec           nFreeze[],
                              const real           invmass[],
-                             const unsigned short ptype[],
+                             const ParticleType   ptype[],
                              const unsigned short cFREEZE[],
                              rvec                 v[],
                              const rvec           f[],
@@ -786,7 +786,7 @@ static void do_update_vv_vel(int                  start,
 
         for (d = 0; d < DIM; d++)
         {
-            if ((ptype[n] != eptShell) && !nFreeze[gf][d])
+            if ((ptype[n] != ParticleType::Shell) && !nFreeze[gf][d])
             {
                 v[n][d] = mv1 * (mv1 * v[n][d] + 0.5 * (w_dt * mv2 * f[n][d]));
             }
@@ -802,7 +802,7 @@ static void do_update_vv_pos(int                  start,
                              int                  nrend,
                              real                 dt,
                              const ivec           nFreeze[],
-                             const unsigned short ptype[],
+                             const ParticleType   ptype[],
                              const unsigned short cFREEZE[],
                              const rvec           x[],
                              rvec                 xprime[],
@@ -837,7 +837,7 @@ static void do_update_vv_pos(int                  start,
 
         for (d = 0; d < DIM; d++)
         {
-            if ((ptype[n] != eptShell) && !nFreeze[gf][d])
+            if ((ptype[n] != ParticleType::Shell) && !nFreeze[gf][d])
             {
                 xprime[n][d] = mr1 * (mr1 * x[n][d] + mr2 * dt * v[n][d]);
             }
@@ -974,7 +974,7 @@ static void doSDUpdateGeneral(const gmx_stochd_t&  sd,
                               real                 dt,
                               const ivec           nFreeze[],
                               const real           invmass[],
-                              const unsigned short ptype[],
+                              const ParticleType   ptype[],
                               const unsigned short cFREEZE[],
                               const unsigned short cTC[],
                               const rvec           x[],
@@ -1020,7 +1020,7 @@ static void doSDUpdateGeneral(const gmx_stochd_t&  sd,
 
         for (int d = 0; d < DIM; d++)
         {
-            if ((ptype[n] != eptShell) && !nFreeze[freezeGroup][d])
+            if ((ptype[n] != ParticleType::Shell) && !nFreeze[freezeGroup][d])
             {
                 if (updateType == SDUpdate::ForcesOnly)
                 {
@@ -1075,7 +1075,7 @@ static void do_update_sd(int         start,
                          const rvec* gmx_restrict f,
                          const ivec               nFreeze[],
                          const real               invmass[],
-                         const unsigned short     ptype[],
+                         const ParticleType       ptype[],
                          const unsigned short     cFREEZE[],
                          const unsigned short     cTC[],
                          int                      seed,
@@ -1120,7 +1120,7 @@ static void do_update_bd(int         start,
                          const rvec* gmx_restrict f,
                          const ivec               nFreeze[],
                          const real               invmass[],
-                         const unsigned short     ptype[],
+                         const ParticleType       ptype[],
                          const unsigned short     cFREEZE[],
                          const unsigned short     cTC[],
                          real                     friction_coefficient,
@@ -1160,7 +1160,7 @@ static void do_update_bd(int         start,
         }
         for (d = 0; (d < DIM); d++)
         {
-            if ((ptype[n] != eptShell) && !nFreeze[gf][d])
+            if ((ptype[n] != ParticleType::Shell) && !nFreeze[gf][d])
             {
                 if (friction_coefficient != 0)
                 {
index 28190ef8118497a6b73163e1ba0028b6852c1dc4..44c57af64486253c286ea41fd829da5adc0289d8 100644 (file)
@@ -2686,7 +2686,7 @@ static void assignVsitesToThread(VsiteThread*                    tData,
                                  gmx::ArrayRef<int>              taskIndex,
                                  ArrayRef<const InteractionList> ilist,
                                  ArrayRef<const t_iparams>       ip,
-                                 const unsigned short*           ptype)
+                                 const ParticleType*             ptype)
 {
     for (int ftype = c_ftypeVsiteStart; ftype < c_ftypeVsiteEnd; ftype++)
     {
@@ -2721,7 +2721,7 @@ static void assignVsitesToThread(VsiteThread*                    tData,
                     /* Do a range check to avoid a harmless race on taskIndex */
                     if (iat[j] < tData->rangeStart || iat[j] >= tData->rangeEnd || taskIndex[iat[j]] != thread)
                     {
-                        if (!tData->useInterdependentTask || ptype[iat[j]] == eptVSite)
+                        if (!tData->useInterdependentTask || ptype[iat[j]] == ParticleType::VSite)
                         {
                             /* At least one constructing atom is a vsite
                              * that is not assigned to the same thread.
@@ -2751,7 +2751,7 @@ static void assignVsitesToThread(VsiteThread*                    tData,
                     /* Do a range check to avoid a harmless race on taskIndex */
                     if (iat[j] < tData->rangeStart || iat[j] >= tData->rangeEnd || taskIndex[iat[j]] != thread)
                     {
-                        GMX_ASSERT(ptype[iat[j]] != eptVSite,
+                        GMX_ASSERT(ptype[iat[j]] != ParticleType::VSite,
                                    "A vsite to be assigned in assignVsitesToThread has a vsite as "
                                    "a constructing atom that does not belong to our task, such "
                                    "vsites should be assigned to the single 'master' task");
@@ -2944,7 +2944,7 @@ void ThreadingInfo::setVirtualSites(ArrayRef<const InteractionList> ilists,
         int thread = 0;
         for (int i = 0; i < mdatoms.nr; i++)
         {
-            if (mdatoms.ptype[i] == eptVSite)
+            if (mdatoms.ptype[i] == ParticleType::VSite)
             {
                 /* vsites are not assigned to a task yet */
                 taskIndex_[i] = -1;
index d35ff541aebde12b428aaecbb6fe50458654bec1..3c8663e92b062b75244ea594915065dc18592dfa 100644 (file)
@@ -552,7 +552,7 @@ void gmx::LegacySimulator::do_md()
             /* Set the velocities of vsites, shells and frozen atoms to zero */
             for (i = 0; i < mdatoms->homenr; i++)
             {
-                if (mdatoms->ptype[i] == eptShell)
+                if (mdatoms->ptype[i] == ParticleType::Shell)
                 {
                     clear_rvec(v[i]);
                 }
index ac079dacbde411e20223c24afdf144a3c62f12fd..cd008e3b9de0a9c5dc41892729b13cd850fb200a 100644 (file)
@@ -270,22 +270,21 @@ gmx_shellfc_t* init_shell_flexcon(FILE*             fplog,
 #define NBT asize(bondtypes)
     const gmx_ffparams_t* ffparams;
 
-    const std::array<int, eptNR> numParticles = gmx_mtop_particletype_count(*mtop);
+    const gmx::EnumerationArray<ParticleType, int> numParticles = gmx_mtop_particletype_count(*mtop);
     if (fplog)
     {
         /* Print the number of each particle type */
-        int pType = 0;
-        for (const auto& n : numParticles)
+        for (const auto entry : gmx::keysOf(numParticles))
         {
-            if (n != 0)
+            const int number = numParticles[entry];
+            if (number != 0)
             {
-                fprintf(fplog, "There are: %d %ss\n", n, ptype_str[pType]);
+                fprintf(fplog, "There are: %d %ss\n", number, enumValueToString(entry));
             }
-            pType++;
         }
     }
 
-    nshell = numParticles[eptShell];
+    nshell = numParticles[ParticleType::Shell];
 
     if (nshell == 0 && nflexcon == 0)
     {
@@ -328,7 +327,7 @@ gmx_shellfc_t* init_shell_flexcon(FILE*             fplog,
     {
         const t_atom& local = atomP.atom();
         int           i     = atomP.globalAtomNumber();
-        if (local.ptype == eptShell)
+        if (local.ptype == ParticleType::Shell)
         {
             shell_index[i] = nshell++;
         }
@@ -370,12 +369,12 @@ gmx_shellfc_t* init_shell_flexcon(FILE*             fplog,
                         case F_CUBICBONDS:
                         case F_POLARIZATION:
                         case F_ANHARM_POL:
-                            if (atom[ia[1]].ptype == eptShell)
+                            if (atom[ia[1]].ptype == ParticleType::Shell)
                             {
                                 aS = ia[1];
                                 aN = ia[2];
                             }
-                            else if (atom[ia[2]].ptype == eptShell)
+                            else if (atom[ia[2]].ptype == ParticleType::Shell)
                             {
                                 aS = ia[2];
                                 aN = ia[1];
@@ -584,7 +583,7 @@ void gmx::make_local_shells(const t_commrec* cr, const t_mdatoms* md, gmx_shellf
     shells.clear();
     for (int i = a0; i < a1; i++)
     {
-        if (md->ptype[i] == eptShell)
+        if (md->ptype[i] == ParticleType::Shell)
         {
             if (dd)
             {
@@ -853,9 +852,8 @@ static void init_adir(gmx_shellfc_t*            shfc,
                       ArrayRef<const real>      lambda,
                       real*                     dvdlambda)
 {
-    double          dt, w_dt;
-    int             n, d;
-    unsigned short* ptype;
+    double dt, w_dt;
+    int    n, d;
 
     if (DOMAINDECOMP(cr))
     {
@@ -872,7 +870,7 @@ static void init_adir(gmx_shellfc_t*            shfc,
     rvec* x_old = as_rvec_array(xOld.paddedArrayRef().data());
     rvec* x     = as_rvec_array(xCurrent.paddedArrayRef().data());
 
-    ptype = md->ptype;
+    const ParticleType* ptype = md->ptype;
 
     dt = ir->delta_t;
 
@@ -883,7 +881,7 @@ static void init_adir(gmx_shellfc_t*            shfc,
 
         for (d = 0; d < DIM; d++)
         {
-            if ((ptype[n] != eptVSite) && (ptype[n] != eptShell))
+            if ((ptype[n] != ParticleType::VSite) && (ptype[n] != ParticleType::Shell))
             {
                 xnold[n][d] = x[n][d] - (x_init[n][d] - x_old[n][d]);
                 xnew[n][d]  = 2 * x[n][d] - x_old[n][d] + f[n][d] * w_dt * dt;
index 3e44708c475d60c3b08342dc3db0c106e106af40..61bf701ff5f378c8278e5e0af5951b8f64572a3e 100644 (file)
@@ -43,6 +43,7 @@
 #include "gromacs/math/vectypes.h"
 #include "gromacs/timing/wallcycle.h"
 #include "gromacs/topology/atoms.h"
+#include "gromacs/utility/enumerationhelpers.h"
 
 class DDBalanceRegionHandler;
 struct gmx_enerdata_t;
@@ -135,6 +136,6 @@ void done_shellfc(FILE* fplog, gmx_shellfc_t* shellfc, int64_t numSteps);
  * \param[in]  mtop  Molecular topology.
  * \returns Array holding the number of particles of a type
  */
-std::array<int, eptNR> countPtypes(FILE* fplog, const gmx_mtop_t* mtop);
+gmx::EnumerationArray<ParticleType, int> countPtypes(FILE* fplog, const gmx_mtop_t* mtop);
 
 #endif
index 55d457f0af2b07c7a83bb9126988c73079a6c6f0..50787aee9fd6e4b74643e4eca72ea437dd1bd899 100644 (file)
@@ -48,6 +48,8 @@
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/real.h"
 
+enum class ParticleType : int;
+
 typedef struct t_mdatoms
 {
     //! Total mass in state A
@@ -111,7 +113,7 @@ typedef struct t_mdatoms
     //! Type of atom in the B state
     int* typeB;
     //! Particle type
-    unsigned short* ptype;
+    ParticleType* ptype;
     //! Group index for temperature coupling
     unsigned short* cTC;
     //! Group index for energy matrix
index e4fbaa09b2b081cd50acc7b92e669d2b315678f0..7baae2123f3e16c69fe7116f780f832ce0146f8a 100644 (file)
@@ -149,7 +149,7 @@ StatePropagatorData::StatePropagatorData(int                numAtoms,
             // Set the velocities of vsites, shells and frozen atoms to zero
             for (int i = 0; i < mdatoms->homenr; i++)
             {
-                if (mdatoms->ptype[i] == eptShell)
+                if (mdatoms->ptype[i] == ParticleType::Shell)
                 {
                     clear_rvec(v[i]);
                 }
index fdbf1b32bccdeb65b4bed880a23c19d2e74c73f1..a2dd4b5d211afca81adedc37f6f9286e7012a31a 100644 (file)
@@ -657,7 +657,7 @@ bool decideWhetherToUseGpuForUpdate(const bool                     isDomainDecom
         errorMessage += "Free energy perturbation for mass and constraints are not supported.\n";
     }
     const auto particleTypes = gmx_mtop_particletype_count(mtop);
-    if (particleTypes[eptShell] > 0)
+    if (particleTypes[ParticleType::Shell] > 0)
     {
         errorMessage += "Shells are not supported.\n";
     }
index 809c0f375c982fc88e5ab73cbc134ead6b2d6e12..af45b6005ee57dfc2a3625ce32b6bd1d1f6d4a0e 100644 (file)
@@ -79,7 +79,7 @@ void writeSystemInformation(TextWriter* writer, const gmx_mtop_t& top, bool writ
     aloop = gmx_mtop_atomloop_block_init(&top);
     while (gmx_mtop_atomloop_block_next(aloop, &atom, &nmol))
     {
-        if (atom->ptype == eptVSite)
+        if (atom->ptype == ParticleType::VSite)
         {
             nvsite += nmol;
         }
index 3615ed3eabeaf79957adc6f841f52f43de324931..eef9b6a9dfd8cb3a6a50b4c80411fc62f9c78374 100644 (file)
 #include "gromacs/topology/atomprop.h"
 #include "gromacs/topology/symtab.h"
 #include "gromacs/utility/compare.h"
+#include "gromacs/utility/enumerationhelpers.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
 #include "gromacs/utility/txtdump.h"
 
-const char* ptype_str[eptNR + 1] = { "Atom", "Nucleus", "Shell", "Bond", "VSite", nullptr };
+const char* enumValueToString(ParticleType enumValue)
+{
+    static constexpr gmx::EnumerationArray<ParticleType, const char*> particleTypeNames = {
+        "Atom", "Nucleus", "Shell", "Bond", "VSite"
+    };
+    return particleTypeNames[enumValue];
+}
 
 void init_atom(t_atoms* at)
 {
@@ -173,7 +180,7 @@ void init_t_atoms(t_atoms* atoms, int natoms, gmx_bool bPdbinfo)
 
 void gmx_pdbinfo_init_default(t_pdbinfo* pdbinfo)
 {
-    pdbinfo->type         = epdbATOM;
+    pdbinfo->type         = PdbRecordType::Atom;
     pdbinfo->atomnr       = 0;
     pdbinfo->altloc       = ' ';
     pdbinfo->atomnm[0]    = '\0';
@@ -268,7 +275,7 @@ static void pr_atom(FILE* fp, int indent, const char* title, const t_atom* atom,
                     i,
                     atom[i].type,
                     atom[i].typeB,
-                    ptype_str[atom[i].ptype],
+                    enumValueToString(atom[i].ptype),
                     atom[i].m,
                     atom[i].q,
                     atom[i].mB,
@@ -342,7 +349,7 @@ static void compareAtom(FILE* fp, int index, const t_atom* a1, const t_atom* a2,
     if (a2)
     {
         cmp_us(fp, "atom.type", index, a1->type, a2->type);
-        cmp_us(fp, "atom.ptype", index, a1->ptype, a2->ptype);
+        cmpEnum<ParticleType>(fp, "atom.ptype", a1->ptype, a2->ptype);
         cmp_int(fp, "atom.resind", index, a1->resind, a2->resind);
         cmp_int(fp, "atom.atomnumber", index, a1->atomnumber, a2->atomnumber);
         cmp_real(fp, "atom.m", index, a1->m, a2->m, relativeTolerance, absoluteTolerance);
@@ -386,7 +393,7 @@ static void comparePdbinfo(FILE*            fp,
                            real             absoluteTolerance)
 {
     fprintf(fp, "comparing t_pdbinfo\n");
-    cmp_int(fp, "type", pdb, pdb1.type, pdb2.type);
+    cmpEnum<PdbRecordType>(fp, "type", pdb1.type, pdb2.type);
     cmp_int(fp, "atomnr", pdb, pdb1.atomnr, pdb2.atomnr);
     cmp_uc(fp, "altloc", pdb, pdb1.altloc, pdb2.altloc);
     cmp_str(fp, "atomnm", pdb, pdb1.atomnm, pdb2.atomnm);
index 513d1cf22734425cb697a6054ae0fb17a666db2b..a8fba1dd6de7e9c10d166402ffeacd306a5de65f 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
  * Copyright (c) 2012,2014,2015,2016,2018 by the GROMACS development team.
- * Copyright (c) 2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2019,2020,2021, 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.
 struct t_symtab;
 
 /* The particle type */
-enum
+enum class ParticleType : int
 {
-    eptAtom,
-    eptNucleus,
-    eptShell,
-    eptBond,
-    eptVSite,
-    eptNR
+    Atom,
+    Nucleus,
+    Shell,
+    Bond,
+    VSite,
+    Count
 };
 
 /* The particle type names */
-extern const char* ptype_str[eptNR + 1];
+const char* enumValueToString(ParticleType enumValue);
 
 /* Enumerated type for pdb records. The other entries are ignored
  * when reading a pdb file
  */
-enum PDB_record
+enum class PdbRecordType : int
 {
-    epdbATOM,
-    epdbHETATM,
-    epdbANISOU,
-    epdbCRYST1,
-    epdbCOMPND,
-    epdbMODEL,
-    epdbENDMDL,
-    epdbTER,
-    epdbHEADER,
-    epdbTITLE,
-    epdbREMARK,
-    epdbCONECT,
-    epdbNR
+    Atom,
+    Hetatm,
+    Anisou,
+    Cryst1,
+    Compound,
+    Model,
+    EndModel,
+    Ter,
+    Header,
+    Title,
+    Remark,
+    Conect,
+    Count
 };
 
+const char* enumValueToString(PdbRecordType enumValue);
+
 typedef struct t_atom
 {
     real           m, q;       /* Mass and charge                      */
     real           mB, qB;     /* Mass and charge for Free Energy calc */
     unsigned short type;       /* Atom type                            */
     unsigned short typeB;      /* Atom type for Free Energy calc       */
-    int            ptype;      /* Particle type                        */
+    ParticleType   ptype;      /* Particle type                        */
     int            resind;     /* Index into resinfo (in t_atoms)      */
     int            atomnumber; /* Atomic Number or 0                   */
     char           elem[4];    /* Element name                         */
@@ -106,14 +108,14 @@ typedef struct t_resinfo
 
 typedef struct t_pdbinfo
 {
-    int      type;         /* PDB record name                      */
-    int      atomnr;       /* PDB atom number                      */
-    char     altloc;       /* Alternate location indicator         */
-    char     atomnm[6];    /* True atom name including leading spaces */
-    real     occup;        /* Occupancy                            */
-    real     bfac;         /* B-factor                             */
-    gmx_bool bAnisotropic; /* (an)isotropic switch                 */
-    int      uij[6];       /* Anisotropic B-factor                 */
+    PdbRecordType type;         /* PDB record name                      */
+    int           atomnr;       /* PDB atom number                      */
+    char          altloc;       /* Alternate location indicator         */
+    char          atomnm[6];    /* True atom name including leading spaces */
+    real          occup;        /* Occupancy                            */
+    real          bfac;         /* B-factor                             */
+    gmx_bool      bAnisotropic; /* (an)isotropic switch                 */
+    int           uij[6];       /* Anisotropic B-factor                 */
 } t_pdbinfo;
 
 //! Contains indices into group names for different groups.
index b159337037222ff73f40be6d1fa20d5dd10e6e27..add097ca32eaab29a21a5a44a30299f4e8fba9f2 100644 (file)
@@ -353,9 +353,9 @@ int gmx_mtop_interaction_count(const gmx_mtop_t& mtop, const int unsigned if_fla
     return n;
 }
 
-std::array<int, eptNR> gmx_mtop_particletype_count(const gmx_mtop_t& mtop)
+gmx::EnumerationArray<ParticleType, int> gmx_mtop_particletype_count(const gmx_mtop_t& mtop)
 {
-    std::array<int, eptNR> count = { { 0 } };
+    gmx::EnumerationArray<ParticleType, int> count = { { 0 } };
 
     for (const auto& molblock : mtop.molblock)
     {
@@ -1004,7 +1004,7 @@ std::vector<int> get_atom_index(const gmx_mtop_t* mtop)
     {
         const t_atom& local = atomP.atom();
         int           index = atomP.globalAtomNumber();
-        if (local.ptype == eptAtom)
+        if (local.ptype == ParticleType::Atom)
         {
             atom_index.push_back(index);
         }
index 7d0527e654cfa4f844f39acb30ed06111e7b1a91..91683733e2101dd06332a4cd9a456c62cd23e83c 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
  * Copyright (c) 2012,2013,2014,2015,2016 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, 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.
@@ -47,6 +47,7 @@
 
 #include "gromacs/topology/topology.h"
 #include "gromacs/utility/basedefinitions.h"
+#include "gromacs/utility/enumerationhelpers.h"
 
 struct gmx_localtop_t;
 struct t_atom;
@@ -207,7 +208,7 @@ int gmx_mtop_ftype_count(const gmx_mtop_t& mtop, int ftype);
 int gmx_mtop_interaction_count(const gmx_mtop_t& mtop, int unsigned if_flags);
 
 /* Returns the count of atoms for each particle type */
-std::array<int, eptNR> gmx_mtop_particletype_count(const gmx_mtop_t& mtop);
+gmx::EnumerationArray<ParticleType, int> gmx_mtop_particletype_count(const gmx_mtop_t& mtop);
 
 /* Returns a single t_atoms struct for the whole system */
 t_atoms gmx_mtop_global_atoms(const gmx_mtop_t* mtop);
index a31a0ea09b54bd475a96105ae06c45400c635a14..9ccc4c8f0194efef25f00b96195187c466350f2e 100644 (file)
@@ -242,7 +242,7 @@ void connolly_plot(const char*  fn,
             xnew[ii0][ZZ]           = dots[k++];
             if (atoms->pdbinfo != nullptr)
             {
-                atoms->pdbinfo[ii0].type   = epdbATOM;
+                atoms->pdbinfo[ii0].type   = PdbRecordType::Atom;
                 atoms->pdbinfo[ii0].atomnr = ii0;
                 atoms->pdbinfo[ii0].bfac   = 0.0;
                 atoms->pdbinfo[ii0].occup  = 0.0;
@@ -266,7 +266,7 @@ void connolly_plot(const char*  fn,
         {
             int ii0                 = i;
             aaa.atomname[ii0]       = put_symtab(symtab, atomnm);
-            aaa.pdbinfo[ii0].type   = epdbATOM;
+            aaa.pdbinfo[ii0].type   = PdbRecordType::Atom;
             aaa.pdbinfo[ii0].atomnr = ii0;
             aaa.atom[ii0].resind    = 0;
             xnew[ii0][XX]           = dots[k++];