Impl(TrajectoryAnalysisModule *module);
~Impl();
- bool parseOptions(TrajectoryAnalysisSettings *settings,
+ void parseOptions(TrajectoryAnalysisSettings *settings,
TrajectoryAnalysisRunnerCommon *common,
SelectionCollection *selections,
int *argc, char *argv[]);
TrajectoryAnalysisModule *module_;
+ bool bUseDefaultGroups_;
int debugLevel_;
};
TrajectoryAnalysisCommandLineRunner::Impl::Impl(
TrajectoryAnalysisModule *module)
- : module_(module), debugLevel_(0)
+ : module_(module), bUseDefaultGroups_(true), debugLevel_(0)
{
}
}
-bool
+void
TrajectoryAnalysisCommandLineRunner::Impl::parseOptions(
TrajectoryAnalysisSettings *settings,
TrajectoryAnalysisRunnerCommon *common,
common->optionsFinished(&commonOptions);
module_->optionsFinished(&moduleOptions, settings);
- common->initIndexGroups(selections);
+ common->initIndexGroups(selections, bUseDefaultGroups_);
// TODO: Check whether the input is a pipe.
- bool bInteractive = true;
+ const bool bInteractive = true;
seloptManager.parseRequestedFromStdin(bInteractive);
common->doneIndexGroups(selections);
- return true;
+ common->initTopology(selections);
+ selections->compile();
}
}
+void
+TrajectoryAnalysisCommandLineRunner::setUseDefaultGroups(bool bUseDefaults)
+{
+ impl_->bUseDefaultGroups_ = bUseDefaults;
+}
+
+
void
TrajectoryAnalysisCommandLineRunner::setSelectionDebugLevel(int debuglevel)
{
TrajectoryAnalysisSettings settings;
TrajectoryAnalysisRunnerCommon common(&settings);
- if (!impl_->parseOptions(&settings, &common, &selections, &argc, argv))
- {
- return 0;
- }
-
- common.initTopology(&selections);
- selections.compile();
+ impl_->parseOptions(&settings, &common, &selections, &argc, argv);
const TopologyInformation &topology = common.topologyInformation();
module->initAnalysis(settings, topology);
~TrajectoryAnalysisCommandLineRunner();
/*! \brief
- * Sets the default debugging level for selections.
+ * Sets whether default index groups are initialized.
*
- * This is intended only for use by internal debugging tools.
+ * This is intended only for internal unit testing purposes to avoid
+ * repeated, unnecessary initialization of the default groups, which
+ * can be expensive under, e.g., valgrind.
+ *
+ * Does not throw.
+ */
+ void setUseDefaultGroups(bool bUseDefaults);
+ /*! \brief
+ * Sets the default debugging level for selections.
*
* \param[in] debuglevel Level of debugging verbosity.
*
+ * This is intended only for use by internal debugging tools.
+ *
* Does not throw.
*
* \see SelectionCollection::setDebugLevel()
void
-TrajectoryAnalysisRunnerCommon::initIndexGroups(SelectionCollection *selections)
+TrajectoryAnalysisRunnerCommon::initIndexGroups(SelectionCollection *selections,
+ bool bUseDefaults)
{
if (impl_->ndxfile_.empty())
{
- // TODO: Initialize default selections
- selections->setIndexGroups(NULL);
- }
- else
- {
- gmx_ana_indexgrps_init(&impl_->grps_, NULL, impl_->ndxfile_.c_str());
- selections->setIndexGroups(impl_->grps_);
+ if (!bUseDefaults)
+ {
+ selections->setIndexGroups(NULL);
+ return;
+ }
+ initTopology(selections);
}
+ const char *const ndxfile
+ = (!impl_->ndxfile_.empty() ? impl_->ndxfile_.c_str() : NULL);
+ gmx_ana_indexgrps_init(&impl_->grps_, impl_->topInfo_.topology(), ndxfile);
+ selections->setIndexGroups(impl_->grps_);
}
void
TrajectoryAnalysisRunnerCommon::initTopology(SelectionCollection *selections)
{
+ // Return immediately if the topology has already been loaded.
+ if (impl_->topInfo_.hasTopology())
+ {
+ return;
+ }
+
const TrajectoryAnalysisSettings &settings = impl_->settings_;
- bool bRequireTop
+ const bool bRequireTop
= settings.hasFlag(TrajectoryAnalysisSettings::efRequireTop)
|| selections->requiresTopology();
if (bRequireTop && impl_->topfile_.empty())