From 079950eec4d7d7b9e119cda220f181e179e29326 Mon Sep 17 00:00:00 2001 From: Paul Bauer Date: Tue, 2 Mar 2021 15:34:21 +0000 Subject: [PATCH] Modernize atom enums Use enum classes and enumeration array for particle and PDB record types. --- api/legacy/include/gromacs/fileio/pdbio.h | 33 ++--- src/gromacs/domdec/domdec_topology.cpp | 2 +- src/gromacs/domdec/dump.cpp | 4 +- src/gromacs/fileio/pdbio.cpp | 133 +++++++++--------- src/gromacs/fileio/tpxio.cpp | 2 +- src/gromacs/gmxana/gmx_anaeig.cpp | 4 +- src/gromacs/gmxana/gmx_chi.cpp | 4 +- src/gromacs/gmxana/gmx_confrms.cpp | 6 +- src/gromacs/gmxana/gmx_order.cpp | 4 +- src/gromacs/gmxpreprocess/editconf.cpp | 6 +- src/gromacs/gmxpreprocess/gen_vsite.cpp | 6 +- src/gromacs/gmxpreprocess/gpp_atomtype.cpp | 2 +- src/gromacs/gmxpreprocess/gpp_atomtype.h | 4 +- src/gromacs/gmxpreprocess/grompp.cpp | 10 +- src/gromacs/gmxpreprocess/readir.cpp | 8 +- src/gromacs/gmxpreprocess/topio.cpp | 12 +- src/gromacs/gmxpreprocess/toppush.cpp | 75 +++++----- src/gromacs/gmxpreprocess/vsite_parm.cpp | 2 +- src/gromacs/mdlib/calc_verletbuf.cpp | 4 +- src/gromacs/mdlib/constr.cpp | 2 +- src/gromacs/mdlib/mdatoms.cpp | 2 +- src/gromacs/mdlib/update.cpp | 18 +-- src/gromacs/mdlib/vsite.cpp | 8 +- src/gromacs/mdrun/md.cpp | 2 +- src/gromacs/mdrun/shellfc.cpp | 30 ++-- src/gromacs/mdrun/shellfc.h | 3 +- src/gromacs/mdtypes/mdatom.h | 4 +- .../modularsimulator/statepropagatordata.cpp | 2 +- src/gromacs/taskassignment/decidegpuusage.cpp | 2 +- src/gromacs/tools/report_methods.cpp | 2 +- src/gromacs/topology/atoms.cpp | 17 ++- src/gromacs/topology/atoms.h | 66 ++++----- src/gromacs/topology/mtop_util.cpp | 6 +- src/gromacs/topology/mtop_util.h | 5 +- .../trajectoryanalysis/modules/sasa.cpp | 4 +- 35 files changed, 256 insertions(+), 238 deletions(-) diff --git a/api/legacy/include/gromacs/fileio/pdbio.h b/api/legacy/include/gromacs/fileio/pdbio.h index fee2ab1373..c34562e095 100644 --- a/api/legacy/include/gromacs/fileio/pdbio.h +++ b/api/legacy/include/gromacs/fileio/pdbio.h @@ -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 diff --git a/src/gromacs/domdec/domdec_topology.cpp b/src/gromacs/domdec/domdec_topology.cpp index 0f1f5462b0..c4a5ac2cd8 100644 --- a/src/gromacs/domdec/domdec_topology.cpp +++ b/src/gromacs/domdec/domdec_topology.cpp @@ -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); } diff --git a/src/gromacs/domdec/dump.cpp b/src/gromacs/domdec/dump.cpp index be9f0c77db..7a7324cd4a 100644 --- a/src/gromacs/domdec/dump.cpp +++ b/src/gromacs/domdec/dump.cpp @@ -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, ' ', diff --git a/src/gromacs/fileio/pdbio.cpp b/src/gromacs/fileio/pdbio.cpp index d2f373c63d..c46a2ccb2e 100644 --- a/src/gromacs/fileio/pdbio.cpp +++ b/src/gromacs/fileio/pdbio.cpp @@ -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 #include #include #include @@ -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 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(conect); - enum PDB_record type; - char altloc; - real occup, bfac; - gmx_bool bOccup; + gmx_conect_t* gc = static_cast(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(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; + 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, diff --git a/src/gromacs/fileio/tpxio.cpp b/src/gromacs/fileio/tpxio.cpp index 38c5335216..448bb9dd58 100644 --- a/src/gromacs/fileio/tpxio.cpp +++ b/src/gromacs/fileio/tpxio.cpp @@ -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()) diff --git a/src/gromacs/gmxana/gmx_anaeig.cpp b/src/gromacs/gmxana/gmx_anaeig.cpp index 94c2b4b040..76baee59ac 100644 --- a/src/gromacs/gmxana/gmx_anaeig.cpp +++ b/src/gromacs/gmxana/gmx_anaeig.cpp @@ -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", ' ', diff --git a/src/gromacs/gmxana/gmx_chi.cpp b/src/gromacs/gmxana/gmx_chi.cpp index 429f21a710..9cafe37eac 100644 --- a/src/gromacs/gmxana/gmx_chi.cpp +++ b/src/gromacs/gmxana/gmx_chi.cpp @@ -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", ' ', diff --git a/src/gromacs/gmxana/gmx_confrms.cpp b/src/gromacs/gmxana/gmx_confrms.cpp index dcd6adba8a..27714d8849 100644 --- a/src/gromacs/gmxana/gmx_confrms.cpp +++ b/src/gromacs/gmxana/gmx_confrms.cpp @@ -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) diff --git a/src/gromacs/gmxana/gmx_order.cpp b/src/gromacs/gmxana/gmx_order.cpp index bbf61e90b3..3a02b9f1a6 100644 --- a/src/gromacs/gmxana/gmx_order.cpp +++ b/src/gromacs/gmxana/gmx_order.cpp @@ -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; diff --git a/src/gromacs/gmxpreprocess/editconf.cpp b/src/gromacs/gmxpreprocess/editconf.cpp index 257f1bbb39..085907a90b 100644 --- a/src/gromacs/gmxpreprocess/editconf.cpp +++ b/src/gromacs/gmxpreprocess/editconf.cpp @@ -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", ' ', diff --git a/src/gromacs/gmxpreprocess/gen_vsite.cpp b/src/gromacs/gmxpreprocess/gen_vsite.cpp index b6e77efd38..8c6ac3352e 100644 --- a/src/gromacs/gmxpreprocess/gen_vsite.cpp +++ b/src/gromacs/gmxpreprocess/gen_vsite.cpp @@ -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 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'; diff --git a/src/gromacs/gmxpreprocess/gpp_atomtype.cpp b/src/gromacs/gmxpreprocess/gpp_atomtype.cpp index 1361ce2911..b832adf2d0 100644 --- a/src/gromacs/gmxpreprocess/gpp_atomtype.cpp +++ b/src/gromacs/gmxpreprocess/gpp_atomtype.cpp @@ -130,7 +130,7 @@ std::optional PreprocessingAtomTypes::atomChargeFromAtomType(int nt) const return isSet(nt) ? std::make_optional(impl_->types[nt].atom_.q) : std::nullopt; } -std::optional PreprocessingAtomTypes::atomParticleTypeFromAtomType(int nt) const +std::optional PreprocessingAtomTypes::atomParticleTypeFromAtomType(int nt) const { return isSet(nt) ? std::make_optional(impl_->types[nt].atom_.ptype) : std::nullopt; } diff --git a/src/gromacs/gmxpreprocess/gpp_atomtype.h b/src/gromacs/gmxpreprocess/gpp_atomtype.h index 47c41442ba..6d28b0c456 100644 --- a/src/gromacs/gmxpreprocess/gpp_atomtype.h +++ b/src/gromacs/gmxpreprocess/gpp_atomtype.h @@ -60,7 +60,7 @@ struct t_atomtypes; class InteractionOfType; struct InteractionsOfType; struct t_symtab; - +enum class ParticleType : int; namespace gmx { template @@ -127,7 +127,7 @@ public: * \param[in] nt Internal number of atom type. * \returns The optional particle type. */ - std::optional atomParticleTypeFromAtomType(int nt) const; + std::optional atomParticleTypeFromAtomType(int nt) const; /*! \brief * Get bond atom parameter of atom from internal atom type number. diff --git a/src/gromacs/gmxpreprocess/grompp.cpp b/src/gromacs/gmxpreprocess/grompp.cpp index b8567d2a53..fe22cd5b0f 100644 --- a/src/gromacs/gmxpreprocess/grompp.cpp +++ b/src/gromacs/gmxpreprocess/grompp.cpp @@ -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) { diff --git a/src/gromacs/gmxpreprocess/readir.cpp b/src/gromacs/gmxpreprocess/readir.cpp index 2276b84de2..c115cbeb9c 100644 --- a/src/gromacs/gmxpreprocess/readir.cpp +++ b/src/gromacs/gmxpreprocess/readir.cpp @@ -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) { diff --git a/src/gromacs/gmxpreprocess/topio.cpp b/src/gromacs/gmxpreprocess/topio.cpp index 54e15169ff..c4a84d8dd0 100644 --- a/src/gromacs/gmxpreprocess/topio.cpp +++ b/src/gromacs/gmxpreprocess/topio.cpp @@ -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, diff --git a/src/gromacs/gmxpreprocess/toppush.cpp b/src/gromacs/gmxpreprocess/toppush.cpp index ded1d521e7..ef613221ef 100644 --- a/src/gromacs/gmxpreprocess/toppush.cpp +++ b/src/gromacs/gmxpreprocess/toppush.cpp @@ -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 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 forceParam = { 0.0 }; nr = at->addType(symtab, atom, "decoupled", InteractionOfType({}, forceParam, ""), -1, 0); diff --git a/src/gromacs/gmxpreprocess/vsite_parm.cpp b/src/gromacs/gmxpreprocess/vsite_parm.cpp index b681001137..2c4133119b 100644 --- a/src/gromacs/gmxpreprocess/vsite_parm.cpp +++ b/src/gromacs/gmxpreprocess/vsite_parm.cpp @@ -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; } diff --git a/src/gromacs/mdlib/calc_verletbuf.cpp b/src/gromacs/mdlib/calc_verletbuf.cpp index 4cb664fa0b..e7cd5759d3 100644 --- a/src/gromacs/mdlib/calc_verletbuf.cpp +++ b/src/gromacs/mdlib/calc_verletbuf.cpp @@ -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 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]; } diff --git a/src/gromacs/mdlib/constr.cpp b/src/gromacs/mdlib/constr.cpp index a4b4acd9fe..c80e67eb82 100644 --- a/src/gromacs/mdlib/constr.cpp +++ b/src/gromacs/mdlib/constr.cpp @@ -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, ' ', diff --git a/src/gromacs/mdlib/mdatoms.cpp b/src/gromacs/mdlib/mdatoms.cpp index 5ca3166ab0..66e412cee3 100644 --- a/src/gromacs/mdlib/mdatoms.cpp +++ b/src/gromacs/mdlib/mdatoms.cpp @@ -155,7 +155,7 @@ std::unique_ptr 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; } diff --git a/src/gromacs/mdlib/update.cpp b/src/gromacs/mdlib/update.cpp index 84aa9a8305..6b695e5c52 100644 --- a/src/gromacs/mdlib/update.cpp +++ b/src/gromacs/mdlib/update.cpp @@ -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) { diff --git a/src/gromacs/mdlib/vsite.cpp b/src/gromacs/mdlib/vsite.cpp index 28190ef811..44c57af644 100644 --- a/src/gromacs/mdlib/vsite.cpp +++ b/src/gromacs/mdlib/vsite.cpp @@ -2686,7 +2686,7 @@ static void assignVsitesToThread(VsiteThread* tData, gmx::ArrayRef taskIndex, ArrayRef ilist, ArrayRef 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 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; diff --git a/src/gromacs/mdrun/md.cpp b/src/gromacs/mdrun/md.cpp index d35ff541ae..3c8663e92b 100644 --- a/src/gromacs/mdrun/md.cpp +++ b/src/gromacs/mdrun/md.cpp @@ -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]); } diff --git a/src/gromacs/mdrun/shellfc.cpp b/src/gromacs/mdrun/shellfc.cpp index ac079dacbd..cd008e3b9d 100644 --- a/src/gromacs/mdrun/shellfc.cpp +++ b/src/gromacs/mdrun/shellfc.cpp @@ -270,22 +270,21 @@ gmx_shellfc_t* init_shell_flexcon(FILE* fplog, #define NBT asize(bondtypes) const gmx_ffparams_t* ffparams; - const std::array numParticles = gmx_mtop_particletype_count(*mtop); + const gmx::EnumerationArray 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 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; diff --git a/src/gromacs/mdrun/shellfc.h b/src/gromacs/mdrun/shellfc.h index 3e44708c47..61bf701ff5 100644 --- a/src/gromacs/mdrun/shellfc.h +++ b/src/gromacs/mdrun/shellfc.h @@ -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 countPtypes(FILE* fplog, const gmx_mtop_t* mtop); +gmx::EnumerationArray countPtypes(FILE* fplog, const gmx_mtop_t* mtop); #endif diff --git a/src/gromacs/mdtypes/mdatom.h b/src/gromacs/mdtypes/mdatom.h index 55d457f0af..50787aee9f 100644 --- a/src/gromacs/mdtypes/mdatom.h +++ b/src/gromacs/mdtypes/mdatom.h @@ -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 diff --git a/src/gromacs/modularsimulator/statepropagatordata.cpp b/src/gromacs/modularsimulator/statepropagatordata.cpp index e4fbaa09b2..7baae2123f 100644 --- a/src/gromacs/modularsimulator/statepropagatordata.cpp +++ b/src/gromacs/modularsimulator/statepropagatordata.cpp @@ -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]); } diff --git a/src/gromacs/taskassignment/decidegpuusage.cpp b/src/gromacs/taskassignment/decidegpuusage.cpp index fdbf1b32bc..a2dd4b5d21 100644 --- a/src/gromacs/taskassignment/decidegpuusage.cpp +++ b/src/gromacs/taskassignment/decidegpuusage.cpp @@ -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"; } diff --git a/src/gromacs/tools/report_methods.cpp b/src/gromacs/tools/report_methods.cpp index 809c0f375c..af45b6005e 100644 --- a/src/gromacs/tools/report_methods.cpp +++ b/src/gromacs/tools/report_methods.cpp @@ -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; } diff --git a/src/gromacs/topology/atoms.cpp b/src/gromacs/topology/atoms.cpp index 3615ed3eab..eef9b6a9df 100644 --- a/src/gromacs/topology/atoms.cpp +++ b/src/gromacs/topology/atoms.cpp @@ -47,11 +47,18 @@ #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 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(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(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); diff --git a/src/gromacs/topology/atoms.h b/src/gromacs/topology/atoms.h index 513d1cf227..a8fba1dd6d 100644 --- a/src/gromacs/topology/atoms.h +++ b/src/gromacs/topology/atoms.h @@ -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. @@ -49,46 +49,48 @@ 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. diff --git a/src/gromacs/topology/mtop_util.cpp b/src/gromacs/topology/mtop_util.cpp index b159337037..add097ca32 100644 --- a/src/gromacs/topology/mtop_util.cpp +++ b/src/gromacs/topology/mtop_util.cpp @@ -353,9 +353,9 @@ int gmx_mtop_interaction_count(const gmx_mtop_t& mtop, const int unsigned if_fla return n; } -std::array gmx_mtop_particletype_count(const gmx_mtop_t& mtop) +gmx::EnumerationArray gmx_mtop_particletype_count(const gmx_mtop_t& mtop) { - std::array count = { { 0 } }; + gmx::EnumerationArray count = { { 0 } }; for (const auto& molblock : mtop.molblock) { @@ -1004,7 +1004,7 @@ std::vector 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); } diff --git a/src/gromacs/topology/mtop_util.h b/src/gromacs/topology/mtop_util.h index 7d0527e654..91683733e2 100644 --- a/src/gromacs/topology/mtop_util.h +++ b/src/gromacs/topology/mtop_util.h @@ -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 gmx_mtop_particletype_count(const gmx_mtop_t& mtop); +gmx::EnumerationArray 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); diff --git a/src/gromacs/trajectoryanalysis/modules/sasa.cpp b/src/gromacs/trajectoryanalysis/modules/sasa.cpp index a31a0ea09b..9ccc4c8f01 100644 --- a/src/gromacs/trajectoryanalysis/modules/sasa.cpp +++ b/src/gromacs/trajectoryanalysis/modules/sasa.cpp @@ -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++]; -- 2.22.0