From: Berk Hess Date: Thu, 1 Oct 2020 12:02:27 +0000 (+0000) Subject: Move computeSlowForces into stepWork X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=78202af9d68d043e48952f1cffa4fa43129bfb66;p=alexxy%2Fgromacs.git Move computeSlowForces into stepWork Also moved a flag into forcerec and fixed documentation. --- diff --git a/src/gromacs/fileio/readinp.cpp b/src/gromacs/fileio/readinp.cpp index 10797d31e7..5d497b8cd7 100644 --- a/src/gromacs/fileio/readinp.cpp +++ b/src/gromacs/fileio/readinp.cpp @@ -554,8 +554,11 @@ void printStringNoNewline(std::vector* inp, const char* line) tmp.append(line); get_estr(inp, tmp.c_str(), nullptr); } + void setStringEntry(std::vector* inp, const char* name, char* newName, const char* def) { + GMX_RELEASE_ASSERT(newName != nullptr, "Need a valid char buffer"); + const char* found = nullptr; found = get_estr(inp, name, def); if (found != nullptr) @@ -563,3 +566,10 @@ void setStringEntry(std::vector* inp, const char* name, char* newName std::strcpy(newName, found); } } + +std::string setStringEntry(std::vector* inp, const std::string& name, const std::string& def) +{ + GMX_RELEASE_ASSERT(!name.empty(), "Need a valid string"); + + return get_estr(inp, name.c_str(), def.c_str()); +} diff --git a/src/gromacs/fileio/readinp.h b/src/gromacs/fileio/readinp.h index 4ae78cb21a..b730248664 100644 --- a/src/gromacs/fileio/readinp.h +++ b/src/gromacs/fileio/readinp.h @@ -167,4 +167,12 @@ void printStringNoNewline(std::vector* inp, const char* line); //! Replace for macro STYPE, checks for existing string entry and if possible replaces it void setStringEntry(std::vector* inp, const char* name, char* newName, const char* def); +/*! Returns a string value and sets the value in \p inp + * + * The value is either from \p inp when \p name is found or \p def otherwise. + * + * \note this is a wrapper function for g_estr() + */ +std::string setStringEntry(std::vector* inp, const std::string& name, const std::string& def); + #endif diff --git a/src/gromacs/gmxpreprocess/grompp.cpp b/src/gromacs/gmxpreprocess/grompp.cpp index 6fb2264e27..6a20af125b 100644 --- a/src/gromacs/gmxpreprocess/grompp.cpp +++ b/src/gromacs/gmxpreprocess/grompp.cpp @@ -1762,7 +1762,6 @@ int gmx_grompp(int argc, char* argv[]) "interpret the output messages before attempting to bypass them with", "this option." }; - t_gromppopts* opts; std::vector mi; std::unique_ptr intermolecular_interactions; int nvsite, comb; @@ -1832,10 +1831,10 @@ int gmx_grompp(int argc, char* argv[]) gmx::MDModules mdModules; t_inputrec irInstance; t_inputrec* ir = &irInstance; - snew(opts, 1); + t_gromppopts optsInstance; + t_gromppopts* opts = &optsInstance; snew(opts->include, STRLEN); snew(opts->define, STRLEN); - snew(opts->mtsLevel2Forces, STRLEN); gmx::LoggerBuilder builder; builder.addTargetStream(gmx::MDLogger::LogLevel::Info, &gmx::TextOutputFile::standardOutput()); @@ -2390,8 +2389,6 @@ int gmx_grompp(int argc, char* argv[]) sfree(opts->wall_atomtype[0]); sfree(opts->wall_atomtype[1]); sfree(opts->include); - sfree(opts->mtsLevel2Forces); - sfree(opts); for (auto& mol : mi) { // Some of the contents of molinfo have been stolen, so diff --git a/src/gromacs/gmxpreprocess/readir.cpp b/src/gromacs/gmxpreprocess/readir.cpp index 835eb4c4c6..ad5ee440ff 100644 --- a/src/gromacs/gmxpreprocess/readir.cpp +++ b/src/gromacs/gmxpreprocess/readir.cpp @@ -1980,9 +1980,9 @@ void get_ir(const char* mdparin, opts->numMtsLevels = get_eint(&inp, "mts-levels", 2, wi); ir->mtsLevels.resize(2); gmx::MtsLevel& mtsLevel = ir->mtsLevels[1]; - setStringEntry(&inp, "mts-level2-forces", opts->mtsLevel2Forces, - "longrange-nonbonded nonbonded pair dihedral"); - mtsLevel.stepFactor = get_eint(&inp, "mts-level2-factor", 2, wi); + opts->mtsLevel2Forces = setStringEntry(&inp, "mts-level2-forces", + "longrange-nonbonded nonbonded pair dihedral"); + mtsLevel.stepFactor = get_eint(&inp, "mts-level2-factor", 2, wi); // We clear after reading without dynamics to not force the user to remove MTS mdp options if (!EI_DYNAMICS(ir->eI)) diff --git a/src/gromacs/gmxpreprocess/readir.h b/src/gromacs/gmxpreprocess/readir.h index a08b10810c..c4f0434e43 100644 --- a/src/gromacs/gmxpreprocess/readir.h +++ b/src/gromacs/gmxpreprocess/readir.h @@ -39,6 +39,8 @@ #ifndef GMX_GMXPREPROCESS_READIR_H #define GMX_GMXPREPROCESS_READIR_H +#include + #include "gromacs/fileio/readinp.h" #include "gromacs/math/vectypes.h" #include "gromacs/utility/real.h" @@ -82,23 +84,23 @@ enum struct t_gromppopts { - int warnings; - int nshake; - char* include; - char* define; - bool bGenVel; - bool bGenPairs; - real tempi; - int seed; - int numMtsLevels; - char* mtsLevel2Forces; - bool bOrire; - bool bMorse; - char* wall_atomtype[2]; - char* couple_moltype; - int couple_lam0; - int couple_lam1; - bool bCoupleIntra; + int warnings = 0; + int nshake = 0; + char* include = nullptr; + char* define = nullptr; + bool bGenVel = false; + bool bGenPairs = false; + real tempi = 0; + int seed = 0; + int numMtsLevels = 0; + std::string mtsLevel2Forces; + bool bOrire = false; + bool bMorse = false; + char* wall_atomtype[2] = { nullptr, nullptr }; + char* couple_moltype = nullptr; + int couple_lam0 = 0; + int couple_lam1 = 0; + bool bCoupleIntra = false; }; /*! \brief Initialise object to hold strings parsed from an .mdp file */ diff --git a/src/gromacs/gmxpreprocess/tests/readir.cpp b/src/gromacs/gmxpreprocess/tests/readir.cpp index 71771bcccb..e2591c7392 100644 --- a/src/gromacs/gmxpreprocess/tests/readir.cpp +++ b/src/gromacs/gmxpreprocess/tests/readir.cpp @@ -71,8 +71,7 @@ namespace test class GetIrTest : public ::testing::Test { public: - GetIrTest() : opts_(), wi_(init_warning(FALSE, 0)), wiGuard_(wi_) - + GetIrTest() : wi_(init_warning(FALSE, 0)), wiGuard_(wi_) { snew(opts_.include, STRLEN); snew(opts_.define, STRLEN);