From 8acd4bc2cde050eb58932b83ad89c7e8d4c9aa0d Mon Sep 17 00:00:00 2001 From: Paul Bauer Date: Tue, 2 Mar 2021 13:13:38 +0000 Subject: [PATCH] Use optional instead of magic numbers in preprocessing Replaced the NOTUSED magic numbers in the atom type preprocessing functions with optionals to indicate that an entry was found or not. Needed for modernizing the particle type and pdb record type enums further along. --- src/gromacs/gmxpreprocess/gen_vsite.cpp | 15 ++- src/gromacs/gmxpreprocess/gpp_atomtype.cpp | 80 +++++++------ src/gromacs/gmxpreprocess/gpp_atomtype.h | 56 ++++----- .../gmxpreprocess/gpp_bond_atomtype.cpp | 36 +++--- src/gromacs/gmxpreprocess/gpp_bond_atomtype.h | 14 ++- src/gromacs/gmxpreprocess/grompp.cpp | 8 +- src/gromacs/gmxpreprocess/nm2type.cpp | 11 +- src/gromacs/gmxpreprocess/resall.cpp | 18 +-- src/gromacs/gmxpreprocess/ter_db.cpp | 6 +- .../gmxpreprocess/tests/gpp_atomtype.cpp | 10 +- .../gmxpreprocess/tests/gpp_bond_atomtype.cpp | 10 +- src/gromacs/gmxpreprocess/tomorse.cpp | 6 +- src/gromacs/gmxpreprocess/toppush.cpp | 109 +++++++++--------- src/gromacs/gmxpreprocess/toputil.cpp | 28 ++--- src/gromacs/gmxpreprocess/vsite_parm.cpp | 6 +- src/gromacs/gmxpreprocess/x2top.cpp | 14 +-- 16 files changed, 230 insertions(+), 197 deletions(-) diff --git a/src/gromacs/gmxpreprocess/gen_vsite.cpp b/src/gromacs/gmxpreprocess/gen_vsite.cpp index fea34d8027..b6e77efd38 100644 --- a/src/gromacs/gmxpreprocess/gen_vsite.cpp +++ b/src/gromacs/gmxpreprocess/gen_vsite.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. @@ -45,6 +45,7 @@ #include #include +#include #include #include #include @@ -608,15 +609,13 @@ static int get_atype(int atom, t_atoms* at, gmx::ArrayRefatomTypeFromName(name); - if (tp == NOTSET) + auto tp = atype->atomTypeFromName(name); + if (!tp.has_value()) { gmx_fatal(FARGS, "Dummy mass type (%s) not found in atom type database", name); } - return tp; + return *tp; } static real get_amass(int atom, t_atoms* at, gmx::ArrayRef rtpFFDB, ResidueType* rt) @@ -1970,7 +1969,7 @@ void do_vsites(gmx::ArrayRef rtpFFDB, count_bonds(i, &plist[F_BONDS], at->atomname, &nrbonds, &nrHatoms, Hatoms, &Heavy, &nrheavies, heavies); /* get Heavy atom type */ tpHeavy = get_atype(Heavy, at, rtpFFDB, &rt); - strcpy(tpname, atype->atomNameFromAtomType(tpHeavy)); + strcpy(tpname, *atype->atomNameFromAtomType(tpHeavy)); bWARNING = FALSE; bAddVsiteParam = TRUE; @@ -2068,7 +2067,7 @@ void do_vsites(gmx::ArrayRef rtpFFDB, /* get dummy mass type from first char of heavy atom type (N or C) */ strcpy(nexttpname, - atype->atomNameFromAtomType(get_atype(heavies[0], at, rtpFFDB, &rt))); + *atype->atomNameFromAtomType(get_atype(heavies[0], at, rtpFFDB, &rt))); std::string ch = get_dummymass_name(vsiteconflist, tpname, nexttpname); std::string name; if (ch.empty()) diff --git a/src/gromacs/gmxpreprocess/gpp_atomtype.cpp b/src/gromacs/gmxpreprocess/gpp_atomtype.cpp index 404e4d77b4..1361ce2911 100644 --- a/src/gromacs/gmxpreprocess/gpp_atomtype.cpp +++ b/src/gromacs/gmxpreprocess/gpp_atomtype.cpp @@ -4,7 +4,7 @@ * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. * Copyright (c) 2011,2014,2015,2017,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. @@ -44,6 +44,7 @@ #include #include +#include #include "gromacs/gmxpreprocess/grompp_impl.h" #include "gromacs/gmxpreprocess/notset.h" @@ -93,19 +94,19 @@ bool PreprocessingAtomTypes::isSet(int nt) const return ((nt >= 0) && (nt < gmx::ssize(*this))); } -int PreprocessingAtomTypes::atomTypeFromName(const std::string& str) const +std::optional PreprocessingAtomTypes::atomTypeFromName(const std::string& str) const { /* Atom types are always case sensitive */ auto found = std::find_if(impl_->types.begin(), impl_->types.end(), [&str](const auto& type) { - return str == *type.name_; + return str == std::string(*type.name_); }); if (found == impl_->types.end()) { - return NOTSET; + return std::nullopt; } else { - return std::distance(impl_->types.begin(), found); + return std::make_optional(std::distance(impl_->types.begin(), found)); } } @@ -114,48 +115,48 @@ size_t PreprocessingAtomTypes::size() const return impl_->size(); } -const char* PreprocessingAtomTypes::atomNameFromAtomType(int nt) const +std::optional PreprocessingAtomTypes::atomNameFromAtomType(int nt) const { - return isSet(nt) ? *(impl_->types[nt].name_) : nullptr; + return isSet(nt) ? std::make_optional(*(impl_->types[nt].name_)) : std::nullopt; } -real PreprocessingAtomTypes::atomMassFromAtomType(int nt) const +std::optional PreprocessingAtomTypes::atomMassFromAtomType(int nt) const { - return isSet(nt) ? impl_->types[nt].atom_.m : NOTSET; + return isSet(nt) ? std::make_optional(impl_->types[nt].atom_.m) : std::nullopt; } -real PreprocessingAtomTypes::atomChargeFromAtomType(int nt) const +std::optional PreprocessingAtomTypes::atomChargeFromAtomType(int nt) const { - return isSet(nt) ? impl_->types[nt].atom_.q : NOTSET; + return isSet(nt) ? std::make_optional(impl_->types[nt].atom_.q) : std::nullopt; } -int PreprocessingAtomTypes::atomParticleTypeFromAtomType(int nt) const +std::optional PreprocessingAtomTypes::atomParticleTypeFromAtomType(int nt) const { - return isSet(nt) ? impl_->types[nt].atom_.ptype : NOTSET; + return isSet(nt) ? std::make_optional(impl_->types[nt].atom_.ptype) : std::nullopt; } -int PreprocessingAtomTypes::bondAtomTypeFromAtomType(int nt) const +std::optional PreprocessingAtomTypes::bondAtomTypeFromAtomType(int nt) const { - return isSet(nt) ? impl_->types[nt].bondAtomType_ : NOTSET; + return isSet(nt) ? std::make_optional(impl_->types[nt].bondAtomType_) : std::nullopt; } -int PreprocessingAtomTypes::atomNumberFromAtomType(int nt) const +std::optional PreprocessingAtomTypes::atomNumberFromAtomType(int nt) const { - return isSet(nt) ? impl_->types[nt].atomNumber_ : NOTSET; + return isSet(nt) ? std::make_optional(impl_->types[nt].atomNumber_) : std::nullopt; } -real PreprocessingAtomTypes::atomNonBondedParamFromAtomType(int nt, int param) const +std::optional PreprocessingAtomTypes::atomNonBondedParamFromAtomType(int nt, int param) const { if (!isSet(nt)) { - return NOTSET; + return std::nullopt; } gmx::ArrayRef forceParam = impl_->types[nt].nb_.forceParam(); if ((param < 0) || (param >= MAXFORCEPARAM)) { - return NOTSET; + return std::nullopt; } - return forceParam[param]; + return std::make_optional(forceParam[param]); } PreprocessingAtomTypes::PreprocessingAtomTypes() : impl_(new Impl) {} @@ -180,29 +181,37 @@ int PreprocessingAtomTypes::addType(t_symtab* tab, int bondAtomType, int atomNumber) { - int position = atomTypeFromName(name); - if (position == NOTSET) + auto position = atomTypeFromName(name); + if (!position.has_value()) { impl_->types.emplace_back(a, put_symtab(tab, name.c_str()), nb, bondAtomType, atomNumber); - return atomTypeFromName(name); + if (auto atomType = atomTypeFromName(name); atomType.has_value()) + { + return *atomType; + } + else + { + GMX_RELEASE_ASSERT(false, "Unhandled error in adding atom type."); + return 0; + } } else { - return position; + return *position; } } -int PreprocessingAtomTypes::setType(int nt, - t_symtab* tab, - const t_atom& a, - const std::string& name, - const InteractionOfType& nb, - int bondAtomType, - int atomNumber) +std::optional PreprocessingAtomTypes::setType(int nt, + t_symtab* tab, + const t_atom& a, + const std::string& name, + const InteractionOfType& nb, + int bondAtomType, + int atomNumber) { if (!isSet(nt)) { - return NOTSET; + return std::nullopt; } impl_->types[nt].atom_ = a; @@ -211,7 +220,7 @@ int PreprocessingAtomTypes::setType(int nt, impl_->types[nt].bondAtomType_ = bondAtomType; impl_->types[nt].atomNumber_ = atomNumber; - return nt; + return std::make_optional(nt); } void PreprocessingAtomTypes::printTypes(FILE* out) @@ -276,7 +285,8 @@ static int search_atomtypes(const PreprocessingAtomTypes* ga, /* Check atomnumber */ int tli = typelist[i]; - bFound = bFound && (ga->atomNumberFromAtomType(tli) == ga->atomNumberFromAtomType(thistype)); + bFound = bFound + && (*ga->atomNumberFromAtomType(tli) == *ga->atomNumberFromAtomType(thistype)); } if (bFound) { diff --git a/src/gromacs/gmxpreprocess/gpp_atomtype.h b/src/gromacs/gmxpreprocess/gpp_atomtype.h index 43c51b3c1a..47c41442ba 100644 --- a/src/gromacs/gmxpreprocess/gpp_atomtype.h +++ b/src/gromacs/gmxpreprocess/gpp_atomtype.h @@ -49,6 +49,7 @@ #include #include +#include #include #include "gromacs/utility/real.h" @@ -82,16 +83,16 @@ public: ~PreprocessingAtomTypes(); /*! \brief - * Get atom type index for atom type name if present in the database, or NOTSET. + * Get atom type index for atom type name if present in the database, or empty optional. * * \todo The code should be changed to instead use a gmx::compat version * of std::optional to return an iterator to the element being searched, * or an empty optional construct if the entry has not been found. * * \param[in] str Input string to search type for. - * \returns Atomtype as integer. + * \returns Optional atomtype as integer. */ - int atomTypeFromName(const std::string& str) const; + std::optional atomTypeFromName(const std::string& str) const; //! Get number of defined atom types. size_t size() const; @@ -100,58 +101,58 @@ public: * Get name of atom from internal atom type number. * * \param[in] nt Internal number of atom type. - * \returns The type name. + * \returns The optional type name. */ - const char* atomNameFromAtomType(int nt) const; + std::optional atomNameFromAtomType(int nt) const; /*! \brief * Get normal mass of atom from internal atom type number. * * \param[in] nt Internal number of atom type. - * \returns The mass for the atom or NOTSET. + * \returns The optional mass for the atom. */ - real atomMassFromAtomType(int nt) const; + std::optional atomMassFromAtomType(int nt) const; /*! \brief * Get normal charge of atom from internal atom type number. * * \param[in] nt Internal number of atom type. - * \returns The charge for the atom or NOTSET. + * \returns The optional charge for the atom. */ - real atomChargeFromAtomType(int nt) const; + std::optional atomChargeFromAtomType(int nt) const; /*! \brief * Get particle type for atom type \p nt * * \param[in] nt Internal number of atom type. - * \returns The particle type or NOTSET. + * \returns The optional particle type. */ - int atomParticleTypeFromAtomType(int nt) const; + std::optional atomParticleTypeFromAtomType(int nt) const; /*! \brief * Get bond atom parameter of atom from internal atom type number. * * \param[in] nt Internal number of atom type. - * \returns The bond atom parameter or NOTSET. + * \returns The optional bond atom parameter. */ - int bondAtomTypeFromAtomType(int nt) const; + std::optional bondAtomTypeFromAtomType(int nt) const; /*! \brief * Get atomic number of atom from internal atom type number. * * \param[in] nt Internal number of atom type. - * \returns The atomic number type or NOTSET. + * \returns The optional atomic number type. */ - int atomNumberFromAtomType(int nt) const; + std::optional atomNumberFromAtomType(int nt) const; /*! \brief * Get the value of \p param of type \p nt. * * \param[in] param The parameter value to find. * \param[in] nt The number of the type. - * \returns The value of the parameter or NOTSET. + * \returns The optional value of the parameter. */ - real atomNonBondedParamFromAtomType(int nt, int param) const; + std::optional atomNonBondedParamFromAtomType(int nt, int param) const; /*! \brief * If a value is within the range of the current types or not. @@ -178,18 +179,18 @@ public: * \param[in] nb Nonbonded parameters. * \param[in] bondAtomType What kind of bonded interactions are there. * \param[in] atomNumber Atomic number of the entry. - * \returns Number of the type set or NOTSET + * \returns Optional number of the type set. */ - int setType(int nt, - t_symtab* tab, - const t_atom& a, - const std::string& name, - const InteractionOfType& nb, - int bondAtomType, - int atomNumber); + std::optional setType(int nt, + t_symtab* tab, + const t_atom& a, + const std::string& name, + const InteractionOfType& nb, + int bondAtomType, + int atomNumber); /*! \brief - * Add new atom type to database. + * Add a unique type to the database. * * \param[in] tab Symbol table. * \param[in] a Atom information. @@ -197,7 +198,8 @@ public: * \param[in] nb Nonbonded parameters. * \param[in] bondAtomType What kind of bonded interactions are there. * \param[in] atomNumber Atomic number of the entry. - * \returns Number of entries in database. + * \returns Index to the type in the database. If the type shares + * a name with an existing type, return the index of that type. */ int addType(t_symtab* tab, const t_atom& a, diff --git a/src/gromacs/gmxpreprocess/gpp_bond_atomtype.cpp b/src/gromacs/gmxpreprocess/gpp_bond_atomtype.cpp index 887d54743a..c81d0ec11c 100644 --- a/src/gromacs/gmxpreprocess/gpp_bond_atomtype.cpp +++ b/src/gromacs/gmxpreprocess/gpp_bond_atomtype.cpp @@ -4,7 +4,7 @@ * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. * Copyright (c) 2011,2014,2015,2017,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. @@ -42,11 +42,11 @@ #include #include +#include #include #include "gromacs/gmxpreprocess/notset.h" #include "gromacs/topology/symtab.h" -#include "gromacs/utility/cstringutil.h" #include "gromacs/utility/smalloc.h" class PreprocessingBondAtomType::Impl @@ -56,25 +56,25 @@ public: std::vector typeNames; }; -int PreprocessingBondAtomType::bondAtomTypeFromName(const std::string& str) const +std::optional PreprocessingBondAtomType::bondAtomTypeFromName(const std::string& str) const { /* Atom types are always case sensitive */ - auto found = std::find_if(impl_->typeNames.begin(), impl_->typeNames.end(), [&str](const auto& type) { - return str == const_cast(*type); - }); + auto found = std::find_if(impl_->typeNames.begin(), + impl_->typeNames.end(), + [&str](const auto& type) { return str == std::string(*type); }); if (found == impl_->typeNames.end()) { - return NOTSET; + return std::nullopt; } else { - return std::distance(impl_->typeNames.begin(), found); + return std::make_optional(std::distance(impl_->typeNames.begin(), found)); } } -const char* PreprocessingBondAtomType::atomNameFromBondAtomType(int nt) const +std::optional PreprocessingBondAtomType::atomNameFromBondAtomType(int nt) const { - return isSet(nt) ? *impl_->typeNames[nt] : nullptr; + return isSet(nt) ? *impl_->typeNames[nt] : std::optional{}; } PreprocessingBondAtomType::PreprocessingBondAtomType() : impl_(new Impl) {} @@ -83,15 +83,23 @@ PreprocessingBondAtomType::~PreprocessingBondAtomType() {} int PreprocessingBondAtomType::addBondAtomType(t_symtab* tab, const std::string& name) { - int position = bondAtomTypeFromName(name); - if (position == NOTSET) + auto position = bondAtomTypeFromName(name); + if (!position.has_value()) { impl_->typeNames.emplace_back(put_symtab(tab, name.c_str())); - return bondAtomTypeFromName(name); + if (auto bondAtomType = bondAtomTypeFromName(name); bondAtomType.has_value()) + { + return *bondAtomType; + } + else + { + GMX_RELEASE_ASSERT(false, "Unhandled error in adding bond atom type"); + return 0; + } } else { - return position; + return *position; } } diff --git a/src/gromacs/gmxpreprocess/gpp_bond_atomtype.h b/src/gromacs/gmxpreprocess/gpp_bond_atomtype.h index c9644afdae..7226e30b94 100644 --- a/src/gromacs/gmxpreprocess/gpp_bond_atomtype.h +++ b/src/gromacs/gmxpreprocess/gpp_bond_atomtype.h @@ -49,6 +49,7 @@ #include #include +#include #include struct t_symtab; @@ -69,9 +70,9 @@ public: * Get name of atom from internal bond atom type number. * * \param[in] nt Internal number of atom type. - * \returns The type name. + * \returns The optional type name. */ - const char* atomNameFromBondAtomType(int nt) const; + std::optional atomNameFromBondAtomType(int nt) const; /*! \brief * Get bond atom type index for atom type name if present in the database, or NOTSET. @@ -81,16 +82,17 @@ public: * or an empty optional construct if the entry has not been found. * * \param[in] str Input string to search type for. - * \returns Atomtype as integer. + * \returns Optional atomtype as integer. */ - int bondAtomTypeFromName(const std::string& str) const; + std::optional bondAtomTypeFromName(const std::string& str) const; /*! \brief - * Add a complete new bond atom type. + * Add a unique type to the database. * * \param[in] tab Symbol table. * \param[in] name Atom name. - * \returns The number of entries in database or the type number of an already set type. + * \returns Index to the type in the database. If the type shares + * a name with an existing type, return the index of that type. */ int addBondAtomType(t_symtab* tab, const std::string& name); diff --git a/src/gromacs/gmxpreprocess/grompp.cpp b/src/gromacs/gmxpreprocess/grompp.cpp index 97d6d6ffcf..b8567d2a53 100644 --- a/src/gromacs/gmxpreprocess/grompp.cpp +++ b/src/gromacs/gmxpreprocess/grompp.cpp @@ -1149,13 +1149,17 @@ static void set_wall_atomtype(PreprocessingAtomTypes* at, } for (i = 0; i < ir->nwall; i++) { - ir->wall_atomtype[i] = at->atomTypeFromName(opts->wall_atomtype[i]); - if (ir->wall_atomtype[i] == NOTSET) + auto atomType = at->atomTypeFromName(opts->wall_atomtype[i]); + if (!atomType.has_value()) { std::string warningMessage = gmx::formatString( "Specified wall atom type %s is not defined", opts->wall_atomtype[i]); warning_error(wi, warningMessage.c_str()); } + else + { + ir->wall_atomtype[i] = *atomType; + } } } diff --git a/src/gromacs/gmxpreprocess/nm2type.cpp b/src/gromacs/gmxpreprocess/nm2type.cpp index e76a357e0a..5b54ef7f7f 100644 --- a/src/gromacs/gmxpreprocess/nm2type.cpp +++ b/src/gromacs/gmxpreprocess/nm2type.cpp @@ -4,7 +4,7 @@ * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2008, 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. @@ -334,14 +334,19 @@ int nm2type(int nnm, double mm = nm2t[best].m; const char* type = nm2t[best].type; - int k; - if ((k = atype->atomTypeFromName(type)) == NOTSET) + auto atomType = atype->atomTypeFromName(type); + int k; + if (!atomType.has_value()) { atoms->atom[i].qB = alpha; atoms->atom[i].m = atoms->atom[i].mB = mm; k = atype->addType( tab, atoms->atom[i], type, InteractionOfType({}, {}), atoms->atom[i].type, atomnr); } + else + { + k = *atomType; + } atoms->atom[i].type = k; atoms->atom[i].typeB = k; atoms->atom[i].q = qq; diff --git a/src/gromacs/gmxpreprocess/resall.cpp b/src/gromacs/gmxpreprocess/resall.cpp index 53c16f51c3..847623e22f 100644 --- a/src/gromacs/gmxpreprocess/resall.cpp +++ b/src/gromacs/gmxpreprocess/resall.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. @@ -112,16 +112,16 @@ static void print_resatoms(FILE* out, const PreprocessingAtomTypes& atype, const for (int j = 0; (j < rtpDBEntry.natom()); j++) { - int tp = rtpDBEntry.atom[j].type; - const char* tpnm = atype.atomNameFromAtomType(tp); - if (tpnm == nullptr) + int tp = rtpDBEntry.atom[j].type; + auto tpnm = atype.atomNameFromAtomType(tp); + if (!tpnm.has_value()) { gmx_fatal(FARGS, "Incorrect atomtype (%d)", tp); } fprintf(out, "%6s %6s %8.3f %6d\n", *(rtpDBEntry.atomname[j]), - tpnm, + *tpnm, rtpDBEntry.atom[j].q, rtpDBEntry.cgnr[j]); } @@ -147,8 +147,8 @@ static bool read_atoms(FILE* in, char* line, PreprocessResidue* r0, t_symtab* ta r0->atom.emplace_back(); r0->atom.back().q = q; r0->cgnr.push_back(cg); - int j = atype->atomTypeFromName(buf1); - if (j == NOTSET) + auto j = atype->atomTypeFromName(buf1); + if (!j.has_value()) { gmx_fatal(FARGS, "Atom type %s (residue %s) not found in atomtype " @@ -156,8 +156,8 @@ static bool read_atoms(FILE* in, char* line, PreprocessResidue* r0, t_symtab* ta buf1, r0->resname.c_str()); } - r0->atom.back().type = j; - r0->atom.back().m = atype->atomMassFromAtomType(j); + r0->atom.back().type = *j; + r0->atom.back().m = *atype->atomMassFromAtomType(*j); } return TRUE; diff --git a/src/gromacs/gmxpreprocess/ter_db.cpp b/src/gromacs/gmxpreprocess/ter_db.cpp index ee59938c25..c10ca620cf 100644 --- a/src/gromacs/gmxpreprocess/ter_db.cpp +++ b/src/gromacs/gmxpreprocess/ter_db.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,2017,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. @@ -137,7 +137,7 @@ static void read_atom(char* line, bool bAdd, std::string* nname, t_atom* a, Prep *nname = ""; } } - a->type = atype->atomTypeFromName(buf[i++]); + a->type = *atype->atomTypeFromName(buf[i++]); sscanf(buf[i++], "%lf", &m); a->m = m; sscanf(buf[i++], "%lf", &q); @@ -154,7 +154,7 @@ static void read_atom(char* line, bool bAdd, std::string* nname, t_atom* a, Prep static void print_atom(FILE* out, const t_atom& a, PreprocessingAtomTypes* atype) { - fprintf(out, "\t%s\t%g\t%g\n", atype->atomNameFromAtomType(a.type), a.m, a.q); + fprintf(out, "\t%s\t%g\t%g\n", *atype->atomNameFromAtomType(a.type), a.m, a.q); } static void print_ter_db(const char* ff, diff --git a/src/gromacs/gmxpreprocess/tests/gpp_atomtype.cpp b/src/gromacs/gmxpreprocess/tests/gpp_atomtype.cpp index 1c1f1a909c..99c7b888b6 100644 --- a/src/gromacs/gmxpreprocess/tests/gpp_atomtype.cpp +++ b/src/gromacs/gmxpreprocess/tests/gpp_atomtype.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2019, by the GROMACS development team, led by + * Copyright (c) 2019,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. @@ -124,20 +124,20 @@ TEST_F(PreprocessingAtomTypesTest, CorrectNameFound) TEST_F(PreprocessingAtomTypesTest, WrongNameNotFound) { EXPECT_EQ(addType("Foo", 1, 2), 0); - EXPECT_EQ(atypes_.atomTypeFromName("Bar"), NOTSET); + EXPECT_FALSE(atypes_.atomTypeFromName("Bar").has_value()); } TEST_F(PreprocessingAtomTypesTest, CorrectNameFromTypeNumber) { EXPECT_EQ(addType("Foo", 1, 2), 0); EXPECT_EQ(addType("Bar", 3, 4), 1); - EXPECT_STREQ(atypes_.atomNameFromAtomType(0), "Foo"); - EXPECT_STREQ(atypes_.atomNameFromAtomType(1), "Bar"); + EXPECT_STREQ(*atypes_.atomNameFromAtomType(0), "Foo"); + EXPECT_STREQ(*atypes_.atomNameFromAtomType(1), "Bar"); } TEST_F(PreprocessingAtomTypesTest, NoNameFromIncorrectTypeNumber) { - EXPECT_EQ(atypes_.atomNameFromAtomType(-1), nullptr); + EXPECT_FALSE(atypes_.atomNameFromAtomType(-1).has_value()); } } // namespace diff --git a/src/gromacs/gmxpreprocess/tests/gpp_bond_atomtype.cpp b/src/gromacs/gmxpreprocess/tests/gpp_bond_atomtype.cpp index 1f15b41d7d..3ed0452f56 100644 --- a/src/gromacs/gmxpreprocess/tests/gpp_bond_atomtype.cpp +++ b/src/gromacs/gmxpreprocess/tests/gpp_bond_atomtype.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2019, by the GROMACS development team, led by + * Copyright (c) 2019,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. @@ -135,18 +135,18 @@ TEST_F(PreprocessingBondAtomTypeTest, CorrectNameFound) TEST_F(PreprocessingBondAtomTypeTest, WrongNameNotFound) { EXPECT_EQ(addType("Foo"), 0); - EXPECT_EQ(bat_.bondAtomTypeFromName("Bar"), NOTSET); + EXPECT_FALSE(bat_.bondAtomTypeFromName("Bar").has_value()); } TEST_F(PreprocessingBondAtomTypeTest, CorrectNameFromTypeNumber) { EXPECT_EQ(addType("Foo"), 0); EXPECT_EQ(addType("Bar"), 1); - EXPECT_STREQ(bat_.atomNameFromBondAtomType(0), "Foo"); - EXPECT_STREQ(bat_.atomNameFromBondAtomType(1), "Bar"); + EXPECT_STREQ(*bat_.atomNameFromBondAtomType(0), "Foo"); + EXPECT_STREQ(*bat_.atomNameFromBondAtomType(1), "Bar"); } TEST_F(PreprocessingBondAtomTypeTest, NoNameFromIncorrectTypeNumber) { - EXPECT_EQ(bat_.atomNameFromBondAtomType(-1), nullptr); + EXPECT_FALSE(bat_.atomNameFromBondAtomType(-1).has_value()); } diff --git a/src/gromacs/gmxpreprocess/tomorse.cpp b/src/gromacs/gmxpreprocess/tomorse.cpp index 320911ea61..ed10591966 100644 --- a/src/gromacs/gmxpreprocess/tomorse.cpp +++ b/src/gromacs/gmxpreprocess/tomorse.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,2017,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. @@ -220,8 +220,8 @@ void convert_harmonics(gmx::ArrayRef mols, PreprocessingAto int nj = harmonic->aj(); real edis = search_e_diss(n2m, t2m, - atype->atomNameFromAtomType(mol.atoms.atom[ni].type), - atype->atomNameFromAtomType(mol.atoms.atom[nj].type)); + *atype->atomNameFromAtomType(mol.atoms.atom[ni].type), + *atype->atomNameFromAtomType(mol.atoms.atom[nj].type)); if (edis != 0) { real b0 = harmonic->c0(); diff --git a/src/gromacs/gmxpreprocess/toppush.cpp b/src/gromacs/gmxpreprocess/toppush.cpp index 27bc433640..ded1d521e7 100644 --- a/src/gromacs/gmxpreprocess/toppush.cpp +++ b/src/gromacs/gmxpreprocess/toppush.cpp @@ -96,8 +96,8 @@ void generate_nbparams(CombinationRule comb, { for (int nf = 0; (nf < nrfp); nf++) { - ci = atypes->atomNonBondedParamFromAtomType(i, nf); - cj = atypes->atomNonBondedParamFromAtomType(j, nf); + ci = *atypes->atomNonBondedParamFromAtomType(i, nf); + cj = *atypes->atomNonBondedParamFromAtomType(j, nf); c = std::sqrt(ci * cj); forceParam[nf] = c; } @@ -112,10 +112,10 @@ void generate_nbparams(CombinationRule comb, { for (int j = 0; (j < nr); j++) { - ci0 = atypes->atomNonBondedParamFromAtomType(i, 0); - cj0 = atypes->atomNonBondedParamFromAtomType(j, 0); - ci1 = atypes->atomNonBondedParamFromAtomType(i, 1); - cj1 = atypes->atomNonBondedParamFromAtomType(j, 1); + ci0 = *atypes->atomNonBondedParamFromAtomType(i, 0); + cj0 = *atypes->atomNonBondedParamFromAtomType(j, 0); + ci1 = *atypes->atomNonBondedParamFromAtomType(i, 1); + cj1 = *atypes->atomNonBondedParamFromAtomType(j, 1); forceParam[0] = (fabs(ci0) + fabs(cj0)) * 0.5; /* Negative sigma signals that c6 should be set to zero later, * so we need to propagate that through the combination rules. @@ -136,10 +136,10 @@ void generate_nbparams(CombinationRule comb, { for (int j = 0; (j < nr); j++) { - ci0 = atypes->atomNonBondedParamFromAtomType(i, 0); - cj0 = atypes->atomNonBondedParamFromAtomType(j, 0); - ci1 = atypes->atomNonBondedParamFromAtomType(i, 1); - cj1 = atypes->atomNonBondedParamFromAtomType(j, 1); + ci0 = *atypes->atomNonBondedParamFromAtomType(i, 0); + cj0 = *atypes->atomNonBondedParamFromAtomType(j, 0); + ci1 = *atypes->atomNonBondedParamFromAtomType(i, 1); + cj1 = *atypes->atomNonBondedParamFromAtomType(j, 1); forceParam[0] = std::sqrt(std::fabs(ci0 * cj0)); /* Negative sigma signals that c6 should be set to zero later, * so we need to propagate that through the combination rules. @@ -167,12 +167,12 @@ void generate_nbparams(CombinationRule comb, { for (int j = 0; (j < nr); j++) { - ci0 = atypes->atomNonBondedParamFromAtomType(i, 0); - cj0 = atypes->atomNonBondedParamFromAtomType(j, 0); - ci2 = atypes->atomNonBondedParamFromAtomType(i, 2); - cj2 = atypes->atomNonBondedParamFromAtomType(j, 2); - bi = atypes->atomNonBondedParamFromAtomType(i, 1); - bj = atypes->atomNonBondedParamFromAtomType(j, 1); + ci0 = *atypes->atomNonBondedParamFromAtomType(i, 0); + cj0 = *atypes->atomNonBondedParamFromAtomType(j, 0); + ci2 = *atypes->atomNonBondedParamFromAtomType(i, 2); + cj2 = *atypes->atomNonBondedParamFromAtomType(j, 2); + bi = *atypes->atomNonBondedParamFromAtomType(i, 1); + bj = *atypes->atomNonBondedParamFromAtomType(j, 1); forceParam[0] = std::sqrt(ci0 * cj0); if ((bi == 0) || (bj == 0)) { @@ -291,8 +291,8 @@ void push_at(t_symtab* symtab, { "B", eptBond }, { "V", eptVSite }, }; - int nr, nfields, j, pt, nfp0 = -1; - int batype_nr, nread; + int nfields, j, pt, nfp0 = -1; + int nread; char type[STRLEN], btype[STRLEN], ptype[STRLEN]; double m, q; double c[MAXFORCEPARAM]; @@ -553,9 +553,10 @@ void push_at(t_symtab* symtab, InteractionOfType interactionType({}, forceParam, ""); - batype_nr = bondAtomType->addBondAtomType(symtab, btype); + auto batype_nr = bondAtomType->addBondAtomType(symtab, btype); - if ((nr = at->atomTypeFromName(type)) != NOTSET) + auto atomType = at->atomTypeFromName(type); + if (atomType.has_value()) { auto message = gmx::formatString( "Atomtype %s was defined previously (e.g. in the forcefield files), " @@ -567,19 +568,16 @@ void push_at(t_symtab* symtab, "to suppress this warning with -maxwarn.", type); warning(wi, message); - if ((at->setType(nr, symtab, *atom, type, interactionType, batype_nr, atomnr)) == NOTSET) + auto newAtomType = at->setType(*atomType, symtab, *atom, type, interactionType, batype_nr, atomnr); + if (!newAtomType.has_value()) { auto message = gmx::formatString("Replacing atomtype %s failed", type); warning_error_and_exit(wi, message, FARGS); } } - else if ((at->addType(symtab, *atom, type, interactionType, batype_nr, atomnr)) == NOTSET) - { - auto message = gmx::formatString("Adding atomtype %s failed", type); - warning_error_and_exit(wi, message, FARGS); - } else { + at->addType(symtab, *atom, type, interactionType, batype_nr, atomnr); /* Add space in the non-bonded parameters matrix */ realloc_nb_params(at, nbparam, pair); } @@ -758,23 +756,23 @@ static std::vector atomTypesFromAtomNames(const PreprocessingAtomTypes* { if (atomTypes != nullptr) { - int atomType = atomTypes->atomTypeFromName(name); - if (atomType == NOTSET) + auto atomType = atomTypes->atomTypeFromName(name); + if (!atomType.has_value()) { auto message = gmx::formatString("Unknown atomtype %s\n", name); warning_error_and_exit(wi, message, FARGS); } - atomTypesFromAtomNames.emplace_back(atomType); + atomTypesFromAtomNames.emplace_back(*atomType); } else if (bondAtomTypes != nullptr) { - int atomType = bondAtomTypes->bondAtomTypeFromName(name); - if (atomType == NOTSET) + auto bondAtomType = bondAtomTypes->bondAtomTypeFromName(name); + if (!bondAtomType.has_value()) { auto message = gmx::formatString("Unknown bond_atomtype %s\n", name); warning_error_and_exit(wi, message, FARGS); } - atomTypesFromAtomNames.emplace_back(atomType); + atomTypesFromAtomNames.emplace_back(*bondAtomType); } } return atomTypesFromAtomNames; @@ -1013,13 +1011,13 @@ void push_dihedraltype(Directive d, } else { - int atomNumber; - if ((atomNumber = bondAtomType->bondAtomTypeFromName(alc[i])) == NOTSET) + auto atomNumber = bondAtomType->bondAtomTypeFromName(alc[i]); + if (!atomNumber.has_value()) { auto message = gmx::formatString("Unknown bond_atomtype %s", alc[i]); warning_error_and_exit(wi, message, FARGS); } - atoms.emplace_back(atomNumber); + atoms.emplace_back(*atomNumber); } } for (int i = 0; (i < nrfp); i++) @@ -1043,7 +1041,6 @@ void push_nbt(Directive d, t_nbparam** nbt, PreprocessingAtomTypes* atypes, char int i, f, n, ftype, nrfp; double c[4], dum; real cr[4]; - int ai, aj; t_nbparam* nbp; bool bId; @@ -1120,17 +1117,19 @@ void push_nbt(Directive d, t_nbparam** nbt, PreprocessingAtomTypes* atypes, char } /* Put the parameters in the matrix */ - if ((ai = atypes->atomTypeFromName(a0)) == NOTSET) + auto ai = atypes->atomTypeFromName(a0); + if (!ai.has_value()) { auto message = gmx::formatString("Atomtype %s not found", a0); warning_error_and_exit(wi, message, FARGS); } - if ((aj = atypes->atomTypeFromName(a1)) == NOTSET) + auto aj = atypes->atomTypeFromName(a1); + if (!aj.has_value()) { auto message = gmx::formatString("Atomtype %s not found", a1); warning_error_and_exit(wi, message, FARGS); } - nbp = &(nbt[std::max(ai, aj)][std::min(ai, aj)]); + nbp = &(nbt[std::max(*ai, *aj)][std::min(*ai, *aj)]); if (nbp->bSet) { @@ -1280,7 +1279,7 @@ void push_cmaptype(Directive d, { /* Assign a grid number to each cmap_type */ GMX_RELEASE_ASSERT(bondAtomType != nullptr, "Need valid PreprocessingBondAtomType object"); - bt[F_CMAP].cmapAtomTypes.emplace_back(bondAtomType->bondAtomTypeFromName(alc[i])); + bt[F_CMAP].cmapAtomTypes.emplace_back(*bondAtomType->bondAtomTypeFromName(alc[i])); } /* Assign a type number to this cmap */ @@ -1407,7 +1406,7 @@ 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, type, typeB, nscan; + int cgnumber, atomnr, nscan; char id[STRLEN], ctype[STRLEN], ctypeB[STRLEN], resnumberic[STRLEN], resname[STRLEN], name[STRLEN], check[STRLEN]; double m, q, mb, qb; @@ -1420,19 +1419,20 @@ void push_atom(t_symtab* symtab, t_atoms* at, PreprocessingAtomTypes* atypes, ch return; } sscanf(id, "%d", &atomnr); - if ((type = atypes->atomTypeFromName(ctype)) == NOTSET) + auto type = atypes->atomTypeFromName(ctype); + if (!type.has_value()) { auto message = gmx::formatString("Atomtype %s not found", ctype); warning_error_and_exit(wi, message, FARGS); } - ptype = atypes->atomParticleTypeFromAtomType(type); + ptype = *atypes->atomParticleTypeFromAtomType(*type); /* Set default from type */ - q0 = atypes->atomChargeFromAtomType(type); - m0 = atypes->atomMassFromAtomType(type); - typeB = type; - qB = q0; - mB = m0; + q0 = *atypes->atomChargeFromAtomType(*type); + m0 = *atypes->atomMassFromAtomType(*type); + auto typeB = type; + qB = q0; + mB = m0; /* Optional parameters */ nscan = sscanf(line, "%*s%*s%*s%*s%*s%*s%lf%lf%s%lf%lf%s", &q, &m, ctypeB, &qb, &mb, check); @@ -1446,13 +1446,14 @@ void push_atom(t_symtab* symtab, t_atoms* at, PreprocessingAtomTypes* atypes, ch m0 = mB = m; if (nscan > 2) { - if ((typeB = atypes->atomTypeFromName(ctypeB)) == NOTSET) + typeB = atypes->atomTypeFromName(ctypeB); + if (!typeB.has_value()) { auto message = gmx::formatString("Atomtype %s not found", ctypeB); warning_error_and_exit(wi, message, FARGS); } - qB = atypes->atomChargeFromAtomType(typeB); - mB = atypes->atomMassFromAtomType(typeB); + qB = *atypes->atomChargeFromAtomType(*typeB); + mB = *atypes->atomMassFromAtomType(*typeB); if (nscan > 3) { qB = qb; @@ -1472,8 +1473,8 @@ void push_atom(t_symtab* symtab, t_atoms* at, PreprocessingAtomTypes* atypes, ch push_atom_now(symtab, at, atomnr, - atypes->atomNumberFromAtomType(type), - type, + *atypes->atomNumberFromAtomType(*type), + *type, ctype, ptype, resnumberic, @@ -1481,7 +1482,7 @@ void push_atom(t_symtab* symtab, t_atoms* at, PreprocessingAtomTypes* atypes, ch name, m0, q0, - typeB, + *typeB, typeB == type ? ctype : ctypeB, mB, qB, diff --git a/src/gromacs/gmxpreprocess/toputil.cpp b/src/gromacs/gmxpreprocess/toputil.cpp index af5558b48e..eb5b53d5a7 100644 --- a/src/gromacs/gmxpreprocess/toputil.cpp +++ b/src/gromacs/gmxpreprocess/toputil.cpp @@ -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,2017,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. @@ -37,6 +37,7 @@ */ #include "gmxpre.h" +#include "gromacs/utility/strconvert.h" #include "toputil.h" #include @@ -55,6 +56,7 @@ #include "gromacs/utility/fatalerror.h" #include "gromacs/utility/gmxassert.h" #include "gromacs/utility/smalloc.h" +#include "gromacs/utility/stringutil.h" /* UTILITIES */ @@ -162,14 +164,14 @@ static void print_bt(FILE* out, { for (int j = 0; (j < nral); j++) { - fprintf(out, "%5s ", at->atomNameFromAtomType(atoms[j])); + fprintf(out, "%5s ", *at->atomNameFromAtomType(atoms[j])); } } else { for (int j = 0; (j < 2); j++) { - fprintf(out, "%5s ", at->atomNameFromAtomType(atoms[dihp[f][j]])); + fprintf(out, "%5s ", *at->atomNameFromAtomType(atoms[dihp[f][j]])); } } fprintf(out, "%5d ", bSwapParity ? -f - 1 : f + 1); @@ -247,7 +249,6 @@ void print_atoms(FILE* out, PreprocessingAtomTypes* atype, t_atoms* at, int* cgn int i, ri; int tpA, tpB; const char* as; - const char *tpnmA, *tpnmB; double qres, qtot; as = dir2str(Directive::d_atoms); @@ -292,8 +293,9 @@ void print_atoms(FILE* out, PreprocessingAtomTypes* atype, t_atoms* at, int* cgn } fprintf(out, "\n"); } - tpA = at->atom[i].type; - if ((tpnmA = atype->atomNameFromAtomType(tpA)) == nullptr) + tpA = at->atom[i].type; + auto tpnmA = atype->atomNameFromAtomType(tpA); + if (!tpnmA.has_value()) { gmx_fatal(FARGS, "tpA = %d, i= %d in print_atoms", tpA, i); } @@ -304,7 +306,7 @@ void print_atoms(FILE* out, PreprocessingAtomTypes* atype, t_atoms* at, int* cgn fprintf(out, "%6d %10s %6d%c %5s %6s %6d %10g %10g", i + 1, - tpnmA, + *tpnmA, at->resinfo[ri].nr, at->resinfo[ri].ic, bRTPresname ? *(at->resinfo[at->atom[i].resind].rtp) @@ -315,12 +317,13 @@ void print_atoms(FILE* out, PreprocessingAtomTypes* atype, t_atoms* at, int* cgn at->atom[i].m); if (PERTURBED(at->atom[i])) { - tpB = at->atom[i].typeB; - if ((tpnmB = atype->atomNameFromAtomType(tpB)) == nullptr) + tpB = at->atom[i].typeB; + auto tpnmB = atype->atomNameFromAtomType(tpB); + if (!tpnmB.has_value()) { gmx_fatal(FARGS, "tpB = %d, i= %d in print_atoms", tpB, i); } - fprintf(out, " %6s %10g %10g", tpnmB, at->atom[i].qB, at->atom[i].mB); + fprintf(out, " %6s %10g %10g", *tpnmB, at->atom[i].qB, at->atom[i].mB); } // Accumulate the total charge to help troubleshoot issues. qtot += static_cast(at->atom[i].q); @@ -357,9 +360,8 @@ void print_bondeds(FILE* out, int natoms, Directive d, int ftype, int fsubtype, open_symtab(&stab); for (int i = 0; (i < natoms); i++) { - char buf[12]; - sprintf(buf, "%4d", (i + 1)); - atype.addType(&stab, *a, buf, InteractionOfType({}, {}), 0, 0); + std::string name = gmx::toString(i + 1); + atype.addType(&stab, *a, name, InteractionOfType({}, {}), 0, 0); } print_bt(out, d, &atype, ftype, fsubtype, plist, TRUE); diff --git a/src/gromacs/gmxpreprocess/vsite_parm.cpp b/src/gromacs/gmxpreprocess/vsite_parm.cpp index 3ddd90b761..b681001137 100644 --- a/src/gromacs/gmxpreprocess/vsite_parm.cpp +++ b/src/gromacs/gmxpreprocess/vsite_parm.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,2017,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. @@ -385,7 +385,7 @@ static real get_angle(gmx::ArrayRef angles, t_iato static const char* get_atomtype_name_AB(t_atom* atom, PreprocessingAtomTypes* atypes) { - const char* name = atypes->atomNameFromAtomType(atom->type); + const char* name = *atypes->atomNameFromAtomType(atom->type); /* When using the decoupling option, atom types are changed * to decoupled for the non-bonded interactions, but the virtual @@ -399,7 +399,7 @@ static const char* get_atomtype_name_AB(t_atom* atom, PreprocessingAtomTypes* at */ if (strcmp(name, "decoupled") == 0) { - name = atypes->atomNameFromAtomType(atom->typeB); + name = *atypes->atomNameFromAtomType(atom->typeB); } return name; diff --git a/src/gromacs/gmxpreprocess/x2top.cpp b/src/gromacs/gmxpreprocess/x2top.cpp index 63c6007fe8..b439d0ca45 100644 --- a/src/gromacs/gmxpreprocess/x2top.cpp +++ b/src/gromacs/gmxpreprocess/x2top.cpp @@ -4,7 +4,7 @@ * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2008, 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. @@ -330,9 +330,8 @@ static void print_rtp(const char* filenm, PreprocessingAtomTypes* atypes, int cgnr[]) { - FILE* fp; - int i, tp; - const char* tpnm; + FILE* fp; + int i, tp; fp = gmx_fio_fopen(filenm, "w"); fprintf(fp, "; %s\n", title); @@ -342,12 +341,13 @@ static void print_rtp(const char* filenm, fprintf(fp, "[ atoms ]\n"); for (i = 0; (i < atoms->nr); i++) { - tp = atoms->atom[i].type; - if ((tpnm = atypes->atomNameFromAtomType(tp)) == nullptr) + tp = atoms->atom[i].type; + auto tpnm = atypes->atomNameFromAtomType(tp); + if (!tpnm.has_value()) { gmx_fatal(FARGS, "tp = %d, i = %d in print_rtp", tp, i); } - fprintf(fp, "%-8s %12s %8.4f %5d\n", *atoms->atomname[i], tpnm, atoms->atom[i].q, cgnr[i]); + fprintf(fp, "%-8s %12s %8.4f %5d\n", *atoms->atomname[i], *tpnm, atoms->atom[i].q, cgnr[i]); } print_pl(fp, plist, F_BONDS, "bonds", atoms->atomname); print_pl(fp, plist, F_ANGLES, "angles", atoms->atomname); -- 2.22.0