#include "gromacs/utility/pleasecite.h"
#include "gromacs/utility/strconvert.h"
#include "gromacs/utility/stringutil.h"
-#include "gromacs/utility/txtdump.h"
namespace gmx
{
const IInputRecExtension *field2,
real reltol,
real abstol);
- virtual void printParameters(FILE *fp, int indent);
virtual void initOutput(FILE *fplog, int nfile, const t_filenm fnm[],
bool bAppendFiles, const gmx_output_env_t *oenv);
virtual void finishOutput();
}
}
-void ElectricField::printParameters(FILE *fp, int indent)
-{
- const char *const dimension[DIM] = { "X", "Y", "Z" };
- indent = pr_title(fp, indent, "ElectricField");
- for (int m = 0; m < DIM; m++)
- {
- pr_indent(fp, indent);
- fprintf(fp, "-%s E0 = %g omega = %g t0 = %g sigma = %g\n",
- dimension[m], a(m), omega(m), t0(m), sigma(m));
- }
-}
-
void ElectricField::setFieldTerm(int dim, real a, real omega, real t0, real sigma)
{
range_check(dim, 0, DIM);
gmx::IInputRecExtension *eptr = inputrec->efield;
block_bc(cr, *inputrec);
inputrec->efield = eptr;
- inputrec->params = nullptr;
+ if (!SIMMASTER(cr))
+ {
+ inputrec->params = nullptr;
+ }
bc_grpopts(cr, &(inputrec->opts));
assignOptionsFromKeyValueTree(&moduleOptions, *impl_->ir_->params, nullptr);
}
+void MDModules::adjustInputrecBasedOnModules()
+{
+ gmx::Options options;
+ impl_->field_->initMdpOptions(&options);
+ std::unique_ptr<KeyValueTreeObject> params(impl_->ir_->params);
+ // Avoid double freeing if the next operation throws.
+ impl_->ir_->params = nullptr;
+ impl_->ir_->params = new KeyValueTreeObject(
+ gmx::adjustKeyValueTreeFromOptions(*params, options));
+}
+
} // namespace gmx
*/
void assignOptionsToModulesFromTpr();
+ /*! \brief
+ * Normalizes inputrec parameters to match current code version.
+ *
+ * This orders the parameters in inputrec to match the current code and
+ * adds any missing defaults.
+ */
+ void adjustInputrecBasedOnModules();
+
private:
class Impl;
#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/snprintf.h"
#include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/textwriter.h"
#include "gromacs/utility/txtdump.h"
//! Macro to select a bool name
pr_simtempvals(fp, indent, ir->simtempvals, ir->fepvals->n_lambda);
}
- /* ELECTRIC FIELDS */
- ir->efield->printParameters(fp, indent);
-
/* ION/WATER SWAPPING FOR COMPUTATIONAL ELECTROPHYSIOLOGY */
PS("swapcoords", ESWAPTYPE(ir->eSwapCoords));
if (ir->eSwapCoords != eswapNO)
PR("userreal3", ir->userreal3);
PR("userreal4", ir->userreal4);
+ if (!bMDPformat)
+ {
+ gmx::TextWriter writer(fp);
+ writer.wrapperSettings().setIndent(indent);
+ ir->params->writeUsing(&writer);
+ }
+
pr_grp_opts(fp, indent, "grpopts", &(ir->opts), bMDPformat);
}
}
real reltol,
real abstol) = 0;
- /*! \brief Print parameters belonging to this class to a file
- *
- * \param[in] fp File pointer
- * \param[in] indent Initial indentation level for printing
- */
- virtual void printParameters(FILE *fp, int indent) = 0;
-
/*! \brief Initiate output parameters
*
* \param[in] fplog File pointer for log messages
gmx_bool bShowNumbers,
gmx_bool bShowParameters,
const char *mdpfn,
- gmx_bool bSysTop)
+ gmx_bool bSysTop,
+ gmx_bool bOriginalInputrec)
{
FILE *gp;
int indent, i, j, **gcount, atot;
ir,
&state,
tpx.bTop ? &mtop : nullptr);
- if (tpx.bIr)
+ if (tpx.bIr && !bOriginalInputrec)
{
- mdModules.assignOptionsToModulesFromTpr();
+ mdModules.adjustInputrecBasedOnModules();
}
if (mdpfn && tpx.bIr)
gmx_output_env_t *oenv;
/* Command line options */
- static gmx_bool bShowNumbers = TRUE;
- static gmx_bool bShowParams = FALSE;
- static gmx_bool bSysTop = FALSE;
- t_pargs pa[] = {
+ gmx_bool bShowNumbers = TRUE;
+ gmx_bool bShowParams = FALSE;
+ gmx_bool bSysTop = FALSE;
+ gmx_bool bOriginalInputrec = FALSE;
+ t_pargs pa[] = {
{ "-nr", FALSE, etBOOL, {&bShowNumbers}, "Show index numbers in output (leaving them out makes comparison easier, but creates a useless topology)" },
{ "-param", FALSE, etBOOL, {&bShowParams}, "Show parameters for each bonded interaction (for comparing dumps, it is useful to combine this with -nonr)" },
- { "-sys", FALSE, etBOOL, {&bSysTop}, "List the atoms and bonded interactions for the whole system instead of for each molecule type" }
+ { "-sys", FALSE, etBOOL, {&bSysTop}, "List the atoms and bonded interactions for the whole system instead of for each molecule type" },
+ { "-orgir", FALSE, etBOOL, {&bOriginalInputrec}, "Show input parameters from tpr as they were written by the version that produced the file, instead of how the current version reads them" }
};
if (!parse_common_args(&argc, argv, 0, NFILE, fnm, asize(pa), pa,
if (ftp2bSet(efTPR, NFILE, fnm))
{
list_tpx(ftp2fn(efTPR, NFILE, fnm), bShowNumbers, bShowParams,
- ftp2fn_null(efMDP, NFILE, fnm), bSysTop);
+ ftp2fn_null(efMDP, NFILE, fnm), bSysTop, bOriginalInputrec);
}
else if (ftp2bSet(efTRX, NFILE, fnm))
{
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017, 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/utility/gmxassert.h"
#include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/textwriter.h"
namespace gmx
{
-/********************************************************************
- * KeyValueTreePath
- */
-
namespace
{
return splitDelimitedString(path.substr(1), '/');
}
+//! Helper function to format a simple KeyValueTreeValue.
+std::string formatSingleValue(const KeyValueTreeValue &value)
+{
+ if (value.isType<float>())
+ {
+ return formatString("%g", value.cast<float>());
+ }
+ else if (value.isType<double>())
+ {
+ return formatString("%g", value.cast<double>());
+ }
+ GMX_RELEASE_ASSERT(false, "Unknown value type");
+ return std::string();
+}
+
} // namespace
+/********************************************************************
+ * KeyValueTreePath
+ */
+
KeyValueTreePath::KeyValueTreePath(const std::string &path)
: path_(splitPathElements(path))
{
return "/" + joinStrings(path_, "/");
}
+/********************************************************************
+ * KeyValueTreeObject
+ */
+
+void KeyValueTreeObject::writeUsing(TextWriter *writer) const
+{
+ for (const auto &prop : properties())
+ {
+ const auto &value = prop.value();
+ if (value.isObject())
+ {
+ writer->writeString(prop.key());
+ writer->writeLine(":");
+ int oldIndent = writer->wrapperSettings().indent();
+ writer->wrapperSettings().setIndent(oldIndent + 2);
+ value.asObject().writeUsing(writer);
+ writer->wrapperSettings().setIndent(oldIndent);
+ }
+ else
+ {
+ int indent = writer->wrapperSettings().indent();
+ writer->writeString(formatString("%*s", -(33-indent), prop.key().c_str()));
+ writer->writeString(" = ");
+ if (value.isArray())
+ {
+ writer->writeString("[");
+ for (const auto &elem : value.asArray().values())
+ {
+ GMX_RELEASE_ASSERT(!elem.isObject() && !elem.isArray(),
+ "Arrays of objects not currently implemented");
+ writer->writeString(" ");
+ writer->writeString(formatSingleValue(elem));
+ }
+ writer->writeString(" ]");
+ }
+ else
+ {
+ writer->writeString(formatSingleValue(value));
+ }
+ writer->writeLine();
+ }
+ }
+}
+
} // namespace gmx
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017, 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.
class KeyValueTreeArray;
class KeyValueTreeObject;
+class TextWriter;
class KeyValueTreePath
{
return valueMap_.at(key);
}
+ void writeUsing(TextWriter *writer) const;
+
private:
KeyValueTreeValue &operator[](const std::string &key)
{
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2015, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2017, 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.
void writeWrappedString(const std::string &str)
{
- writeRawString(wrapper_.wrapToString(str));
+ if (newLineCount_ > 0)
+ {
+ writeRawString(wrapper_.wrapToString(str));
+ }
+ else
+ {
+ writeRawString(str);
+ }
}
TextOutputStreamPointer stream_;