* 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.
struct t_symtab;
struct t_topology;
enum class PbcType : int;
+enum class PdbRecordType : int;
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
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);
}
cx[ZZ] = grid_r[i * 2 + z][ZZ];
mvmul(tric, cx, r);
gmx_fprintf_pdb_atomline(out,
- epdbATOM,
+ PdbRecordType::Atom,
a++,
"CA",
' ',
b = dd->comm->zones.n + 1;
}
gmx_fprintf_pdb_atomline(out,
- epdbATOM,
+ PdbRecordType::Atom,
ii + 1,
atomname,
' ',
* 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.
#include "gromacs/fileio/pdbio.h"
+#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#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"
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"
}
}
-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 */
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,
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());
{
gmx_pdbinfo_init_default(&pdbinfo);
}
- type = static_cast<enum PDB_record>(pdbinfo.type);
+ type = pdbinfo.type;
altloc = pdbinfo.altloc;
if (!isalnum(altloc))
{
sfree(index);
}
-static int line2type(const char* line)
+static PdbRecordType line2type(const char* line)
{
int k;
char type[8];
}
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)
}
}
-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;
gmx_bool bCOMPND;
gmx_bool bConnWarn = FALSE;
char line[STRLEN + 1];
- int line_type;
char * c, *d;
int natom, chainnum;
gmx_bool bStop = FALSE;
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;
}
break;
- case epdbCOMPND:
+ case PdbRecordType::Compound:
if ((!std::strstr(line, ": ")) || (std::strstr(line + 6, "MOLECULE:")))
{
if (!(c = std::strstr(line + 6, "MOLECULE:")))
}
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);
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");
}
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,
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())
* 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.
j = 0;
}
gmx_fprintf_pdb_atomline(out,
- epdbATOM,
+ PdbRecordType::Atom,
i + 1,
"C",
' ',
* 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.
for (i = 0; (i < 10); i++)
{
gmx_fprintf_pdb_atomline(fp,
- epdbATOM,
+ PdbRecordType::Atom,
atoms->nr + 1 + i,
"CA",
' ',
* 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.
/* 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)
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)
* 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.
/*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;
* 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.
for (i = 0; i < nat; i++)
{
gmx_fprintf_pdb_atomline(out,
- epdbATOM,
+ PdbRecordType::Atom,
a0 + i,
"C",
' ',
for (x = 0; x <= 1; x++)
{
gmx_fprintf_pdb_atomline(out,
- epdbATOM,
+ PdbRecordType::Atom,
a0 + i,
"C",
' ',
(*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';
(*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';
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';
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;
}
class InteractionOfType;
struct InteractionsOfType;
struct t_symtab;
-
+enum class ParticleType : int;
namespace gmx
{
template<typename>
* \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.
{
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]);
}
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++;
}
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++;
}
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)
{
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++)
*/
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)
{
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;
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,
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,
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;
{
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;
}
-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;
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];
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);
/* 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);
{
/* The virtual site */
int avsite = ia[i + 1];
- molt->atoms.atom[avsite].ptype = eptVSite;
+ molt->atoms.atom[avsite].ptype = ParticleType::VSite;
i += nra + 1;
}
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];
}
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];
}
}
mtopGetAtomAndResidueName(mtop, ii, &molb, &anm, &resnr, &resnm, nullptr);
gmx_fprintf_pdb_atomline(out,
- epdbATOM,
+ PdbRecordType::Atom,
ii + 1,
anm,
' ',
totalMassA += nmol * atom->m;
totalMassB += nmol * atom->mB;
- if (atom->ptype == eptVSite)
+ if (atom->ptype == ParticleType::VSite)
{
md->haveVsites = TRUE;
}
real dt,
const ivec nFreeze[],
const real invmass[],
- const unsigned short ptype[],
+ const ParticleType ptype[],
const unsigned short cFREEZE[],
rvec v[],
const rvec f[],
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]));
}
int nrend,
real dt,
const ivec nFreeze[],
- const unsigned short ptype[],
+ const ParticleType ptype[],
const unsigned short cFREEZE[],
const rvec x[],
rvec xprime[],
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]);
}
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[],
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)
{
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,
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,
}
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)
{
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++)
{
/* 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.
/* 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");
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;
/* 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]);
}
#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)
{
{
const t_atom& local = atomP.atom();
int i = atomP.globalAtomNumber();
- if (local.ptype == eptShell)
+ if (local.ptype == ParticleType::Shell)
{
shell_index[i] = nshell++;
}
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];
shells.clear();
for (int i = a0; i < a1; i++)
{
- if (md->ptype[i] == eptShell)
+ if (md->ptype[i] == ParticleType::Shell)
{
if (dd)
{
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))
{
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;
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;
#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;
* \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
#include "gromacs/utility/basedefinitions.h"
#include "gromacs/utility/real.h"
+enum class ParticleType : int;
+
typedef struct t_mdatoms
{
//! Total mass in state A
//! 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
// 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]);
}
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";
}
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;
}
#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)
{
void gmx_pdbinfo_init_default(t_pdbinfo* pdbinfo)
{
- pdbinfo->type = epdbATOM;
+ pdbinfo->type = PdbRecordType::Atom;
pdbinfo->atomnr = 0;
pdbinfo->altloc = ' ';
pdbinfo->atomnm[0] = '\0';
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,
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);
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);
* 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 */
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.
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)
{
{
const t_atom& local = atomP.atom();
int index = atomP.globalAtomNumber();
- if (local.ptype == eptAtom)
+ if (local.ptype == ParticleType::Atom)
{
atom_index.push_back(index);
}
* 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.
#include "gromacs/topology/topology.h"
#include "gromacs/utility/basedefinitions.h"
+#include "gromacs/utility/enumerationhelpers.h"
struct gmx_localtop_t;
struct t_atom;
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);
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;
{
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++];