* 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 <cstring>
#include <algorithm>
+#include <optional>
#include <string>
#include <utility>
#include <vector>
static int vsite_nm2type(const char* name, PreprocessingAtomTypes* atype)
{
- int tp;
-
- tp = atype->atomTypeFromName(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<const PreprocessResidue> rtpFFDB, ResidueType* rt)
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;
/* 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())
* 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.
#include <cstring>
#include <algorithm>
+#include <optional>
#include "gromacs/gmxpreprocess/grompp_impl.h"
#include "gromacs/gmxpreprocess/notset.h"
return ((nt >= 0) && (nt < gmx::ssize(*this)));
}
-int PreprocessingAtomTypes::atomTypeFromName(const std::string& str) const
+std::optional<int> 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));
}
}
return impl_->size();
}
-const char* PreprocessingAtomTypes::atomNameFromAtomType(int nt) const
+std::optional<const char*> 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<real> 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<real> 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<int> 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<int> 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<int> 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<real> PreprocessingAtomTypes::atomNonBondedParamFromAtomType(int nt, int param) const
{
if (!isSet(nt))
{
- return NOTSET;
+ return std::nullopt;
}
gmx::ArrayRef<const real> 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) {}
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<int> 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;
impl_->types[nt].bondAtomType_ = bondAtomType;
impl_->types[nt].atomNumber_ = atomNumber;
- return nt;
+ return std::make_optional(nt);
}
void PreprocessingAtomTypes::printTypes(FILE* out)
/* Check atomnumber */
int tli = typelist[i];
- bFound = bFound && (ga->atomNumberFromAtomType(tli) == ga->atomNumberFromAtomType(thistype));
+ bFound = bFound
+ && (*ga->atomNumberFromAtomType(tli) == *ga->atomNumberFromAtomType(thistype));
}
if (bFound)
{
#include <cstdio>
#include <memory>
+#include <optional>
#include <string>
#include "gromacs/utility/real.h"
~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<int> atomTypeFromName(const std::string& str) const;
//! Get number of defined atom types.
size_t size() const;
* 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<const char*> 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<real> 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<real> 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<int> 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<int> 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<int> 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<real> atomNonBondedParamFromAtomType(int nt, int param) const;
/*! \brief
* If a value is within the range of the current types or not.
* \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<int> 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.
* \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,
* 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.
#include <cstring>
#include <algorithm>
+#include <optional>
#include <vector>
#include "gromacs/gmxpreprocess/notset.h"
#include "gromacs/topology/symtab.h"
-#include "gromacs/utility/cstringutil.h"
#include "gromacs/utility/smalloc.h"
class PreprocessingBondAtomType::Impl
std::vector<char**> typeNames;
};
-int PreprocessingBondAtomType::bondAtomTypeFromName(const std::string& str) const
+std::optional<int> 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<const char*>(*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<const char*> PreprocessingBondAtomType::atomNameFromBondAtomType(int nt) const
{
- return isSet(nt) ? *impl_->typeNames[nt] : nullptr;
+ return isSet(nt) ? *impl_->typeNames[nt] : std::optional<const char*>{};
}
PreprocessingBondAtomType::PreprocessingBondAtomType() : impl_(new Impl) {}
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;
}
}
#include <cstdio>
#include <memory>
+#include <optional>
#include <string>
struct t_symtab;
* 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<const char*> atomNameFromBondAtomType(int nt) const;
/*! \brief
* Get bond atom type index for atom type name if present in the database, or NOTSET.
* 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<int> 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);
}
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;
+ }
}
}
* 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.
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;
* 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 (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]);
}
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 "
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;
* 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.
*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);
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,
/*
* 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.
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
/*
* 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.
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());
}
* 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.
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();
{
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;
}
{
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.
{
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.
{
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))
{
{ "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];
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), "
"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);
}
{
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;
}
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++)
int i, f, n, ftype, nrfp;
double c[4], dum;
real cr[4];
- int ai, aj;
t_nbparam* nbp;
bool bId;
}
/* 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)
{
{
/* 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 */
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;
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);
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;
push_atom_now(symtab,
at,
atomnr,
- atypes->atomNumberFromAtomType(type),
- type,
+ *atypes->atomNumberFromAtomType(*type),
+ *type,
ctype,
ptype,
resnumberic,
name,
m0,
q0,
- typeB,
+ *typeB,
typeB == type ? ctype : ctypeB,
mB,
qB,
* 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.
*/
#include "gmxpre.h"
+#include "gromacs/utility/strconvert.h"
#include "toputil.h"
#include <climits>
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/smalloc.h"
+#include "gromacs/utility/stringutil.h"
/* UTILITIES */
{
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);
int i, ri;
int tpA, tpB;
const char* as;
- const char *tpnmA, *tpnmB;
double qres, qtot;
as = dir2str(Directive::d_atoms);
}
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);
}
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)
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<double>(at->atom[i].q);
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);
* 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.
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
*/
if (strcmp(name, "decoupled") == 0)
{
- name = atypes->atomNameFromAtomType(atom->typeB);
+ name = *atypes->atomNameFromAtomType(atom->typeB);
}
return name;
* 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.
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);
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);