Improve option initialization in traj. analysis.
authorTeemu Murtola <teemu.murtola@gmail.com>
Wed, 11 Jul 2012 08:25:03 +0000 (11:25 +0300)
committerTeemu Murtola <teemu.murtola@gmail.com>
Wed, 11 Jul 2012 08:31:58 +0000 (11:31 +0300)
All methods that add options to an options object now take an externally
provided options object.  This both simplifies the calling code,
allowing them to control the lifetime of the objects, as well as the
implementing code, since they no longer need to have an internal options
object just for the purpose of returning it.  With the old interface, it
was also impossible to get a reference to the options object more than
once; with the new, the caller has much more flexibility.

Change-Id: I8a2e539fa5abefe696a26919b8591691a1cccc61

18 files changed:
share/template/template.cpp
share/template/template_doc.cpp
src/gromacs/selection/selectioncollection-impl.h
src/gromacs/selection/selectioncollection.cpp
src/gromacs/selection/selectioncollection.h
src/gromacs/trajectoryanalysis/analysismodule.cpp
src/gromacs/trajectoryanalysis/analysismodule.h
src/gromacs/trajectoryanalysis/analysissettings.h
src/gromacs/trajectoryanalysis/cmdlinerunner.cpp
src/gromacs/trajectoryanalysis/modules/angle.cpp
src/gromacs/trajectoryanalysis/modules/angle.h
src/gromacs/trajectoryanalysis/modules/distance.cpp
src/gromacs/trajectoryanalysis/modules/distance.h
src/gromacs/trajectoryanalysis/modules/select.cpp
src/gromacs/trajectoryanalysis/modules/select.h
src/gromacs/trajectoryanalysis/runnercommon.cpp
src/gromacs/trajectoryanalysis/runnercommon.h
src/gromacs/trajectoryanalysis/tests/test_selection.cpp

index e2035598ea4b9aceec3bc8107f01c21ded37b60e..ef2321c320cd5a455dbeda2553041eacfdbc3028 100644 (file)
@@ -43,7 +43,8 @@ class AnalysisTemplate : public TrajectoryAnalysisModule
     public:
         AnalysisTemplate();
 
-        virtual Options &initOptions(TrajectoryAnalysisSettings *settings);
+        virtual void initOptions(Options *options,
+                                 TrajectoryAnalysisSettings *settings);
         virtual void initAnalysis(const TrajectoryAnalysisSettings &settings,
                                   const TopologyInformation &top);
 
@@ -59,8 +60,6 @@ class AnalysisTemplate : public TrajectoryAnalysisModule
     private:
         class ModuleData;
 
-        Options                          options_;
-
         std::string                      fnDist_;
         double                           cutoff_;
         Selection                        refsel_;
@@ -106,14 +105,16 @@ class AnalysisTemplate::ModuleData : public TrajectoryAnalysisModuleData
 
 
 AnalysisTemplate::AnalysisTemplate()
-    : options_("template", "Template options"), cutoff_(0.0)
+    : TrajectoryAnalysisModule("template", "Template analysis tool"),
+      cutoff_(0.0)
 {
     registerAnalysisDataset(&data_, "avedist");
 }
 
 
-Options &
-AnalysisTemplate::initOptions(TrajectoryAnalysisSettings *settings)
+void
+AnalysisTemplate::initOptions(Options *options,
+                              TrajectoryAnalysisSettings *settings)
 {
     static const char *const desc[] = {
         "This is a template for writing your own analysis tools for",
@@ -131,26 +132,24 @@ AnalysisTemplate::initOptions(TrajectoryAnalysisSettings *settings)
         "analysis groups."
     };
 
-    options_.setDescription(concatenateStrings(desc));
+    options->setDescription(concatenateStrings(desc));
 
-    options_.addOption(FileNameOption("o")
+    options->addOption(FileNameOption("o")
         .filetype(eftPlot).outputFile()
         .store(&fnDist_).defaultValueIfSet("avedist")
         .description("Average distances from reference group"));
 
-    options_.addOption(SelectionOption("reference")
+    options->addOption(SelectionOption("reference")
         .store(&refsel_).required()
         .description("Reference group to calculate distances from"));
-    options_.addOption(SelectionOption("select")
+    options->addOption(SelectionOption("select")
         .storeVector(&sel_).required().multiValue()
         .description("Groups to calculate distances to"));
 
-    options_.addOption(DoubleOption("cutoff").store(&cutoff_)
+    options->addOption(DoubleOption("cutoff").store(&cutoff_)
         .description("Cutoff for distance calculation (0 = no cutoff)"));
 
     settings->setFlag(TrajectoryAnalysisSettings::efRequireTop);
-
-    return options_;
 }
 
 
index 4825a60c36a2ce492717fef41c650a02fd1b6a9b..8cd5e3074f9eccb749c518633d2da8b774f42704 100644 (file)
  * to set up options understood by the module, as well as for setting up
  * different options through gmx::TrajectoryAnalysisSettings (see the
  * documentation of that class for more details):
- * \skip  Options &
- * \until return options_;
+ * \skip  void
+ * \until settings->
  * \until }
  * For the template, we first set a description text for the tool (used for
  * help text).  Then we declare an option to specify the output file name,
  *
  * To adjust settings or selection options (e.g., the number of accepted
  * selections) based on option values, you need to override
- * gmx::TrajectoryAnalysisModule::initOptionsDone().  For simplicity,
+ * gmx::TrajectoryAnalysisModule::optionsFinished().  For simplicity,
  * this is not done in the template.
  *
  *
index eacbd828e156123572fc076b6d4dd92e3cff5078..75187e4cf850f56b870aedec78dc92d4fa1c4095 100644 (file)
@@ -47,7 +47,6 @@
 #include "../legacyheaders/typedefs.h"
 
 #include "../onlinehelp/helptopicinterface.h"
-#include "../options/options.h"
 #include "../utility/uniqueptr.h"
 #include "indexutil.h"
 #include "poscalc.h"
@@ -145,8 +144,6 @@ class SelectionCollection::Impl
 
         //! Internal data, used for interfacing with old C code.
         gmx_ana_selcollection_t sc_;
-        //! Options object for setting global properties on the collection.
-        Options                 options_;
         //! Default reference position type for selections.
         std::string             rpost_;
         //! Default output position type for selections.
index 5a75e13a5c684c7f966190fd36c697b2e76b2d36..068ce141e3eaa7a1685a6b78d5f589f152b18bff 100644 (file)
@@ -76,8 +76,7 @@ namespace gmx
  */
 
 SelectionCollection::Impl::Impl()
-    : options_("selection", "Common selection control"),
-      debugLevel_(0), bExternalGroupsSet_(false), grps_(NULL)
+    : debugLevel_(0), bExternalGroupsSet_(false), grps_(NULL)
 {
     sc_.root      = NULL;
     sc_.nvars     = 0;
@@ -346,8 +345,8 @@ SelectionCollection::~SelectionCollection()
 }
 
 
-Options &
-SelectionCollection::initOptions()
+void
+SelectionCollection::initOptions(Options *options)
 {
     static const char * const debug_levels[]
         = {"no", "basic", "compile", "eval", "full", NULL};
@@ -361,23 +360,20 @@ SelectionCollection::initOptions()
     options.setDescription(desc);
     */
 
-    Options &options = impl_->options_;
     const char *const *postypes = PositionCalculationCollection::typeEnumValues;
-    options.addOption(StringOption("selrpos").enumValue(postypes)
-                          .store(&impl_->rpost_).defaultValue(postypes[0])
-                          .description("Selection reference positions"));
-    options.addOption(StringOption("seltype").enumValue(postypes)
-                          .store(&impl_->spost_).defaultValue(postypes[0])
-                          .description("Default selection output positions"));
+    options->addOption(StringOption("selrpos").enumValue(postypes)
+                           .store(&impl_->rpost_).defaultValue(postypes[0])
+                           .description("Selection reference positions"));
+    options->addOption(StringOption("seltype").enumValue(postypes)
+                           .store(&impl_->spost_).defaultValue(postypes[0])
+                           .description("Default selection output positions"));
     GMX_RELEASE_ASSERT(impl_->debugLevel_ >= 0 && impl_->debugLevel_ <= 4,
                        "Debug level out of range");
-    options.addOption(StringOption("seldebug").hidden(impl_->debugLevel_ == 0)
-                          .enumValue(debug_levels)
-                          .defaultValue(debug_levels[impl_->debugLevel_])
-                          .storeEnumIndex(&impl_->debugLevel_)
-                          .description("Print out selection trees for debugging"));
-
-    return impl_->options_;
+    options->addOption(StringOption("seldebug").hidden(impl_->debugLevel_ == 0)
+                           .enumValue(debug_levels)
+                           .defaultValue(debug_levels[impl_->debugLevel_])
+                           .storeEnumIndex(&impl_->debugLevel_)
+                           .description("Print out selection trees for debugging"));
 }
 
 
index 350c7439cd70ac0749354598702f9cefe48a56a0..508c827e1afb8821f0190fc52a761a708bd5491e 100644 (file)
@@ -122,14 +122,14 @@ class SelectionCollection
         /*! \brief
          * Initializes options for setting global properties on the collection.
          *
-         * \returns Initialized options object.
-         * \throws  std::bad_alloc if out of memory.
+         * \param[in,out] options Options object to initialize.
+         * \throws        std::bad_alloc if out of memory.
          *
-         * The returned options can be used to set the default position types
-         * (see setReferencePosType() and setOutputPosType()) and debugging
-         * options.
+         * Adds options to \p options that can be used to set the default
+         * position types (see setReferencePosType() and setOutputPosType())
+         * and debugging flags.
          */
-        Options &initOptions();
+        void initOptions(Options *options);
 
         /*! \brief
          * Sets the default reference position handling for a selection
index 6e73bb7b3d9a0240247e8c42aabe56b9223b227b..3370d3db26588561a2922e3f69c26d70b4d29122 100644 (file)
@@ -64,6 +64,16 @@ class TrajectoryAnalysisModule::Impl
         //! Container that associates a AnalysisData object with its name.
         typedef std::map<std::string, AnalysisData *> AnalysisDatasetContainer;
 
+        //! Initializes analysis module data with given name and description.
+        Impl(const char *name, const char *description)
+            : name_(name), description_(description)
+        {
+        }
+
+        //! Name of the module.
+        std::string                     name_;
+        //! Description of the module.
+        std::string                     description_;
         //! List of registered data set names.
         std::vector<std::string>        datasetNames_;
         /*! \brief
@@ -234,8 +244,9 @@ TrajectoryAnalysisModuleDataBasic::finish()
  * TrajectoryAnalysisModule
  */
 
-TrajectoryAnalysisModule::TrajectoryAnalysisModule()
-    : impl_(new Impl)
+TrajectoryAnalysisModule::TrajectoryAnalysisModule(const char *name,
+                                                   const char *description)
+    : impl_(new Impl(name, description))
 {
 }
 
@@ -245,7 +256,9 @@ TrajectoryAnalysisModule::~TrajectoryAnalysisModule()
 }
 
 
-void TrajectoryAnalysisModule::initOptionsDone(TrajectoryAnalysisSettings * /*settings*/)
+void TrajectoryAnalysisModule::optionsFinished(
+        Options * /*options*/,
+        TrajectoryAnalysisSettings * /*settings*/)
 {
 }
 
@@ -269,6 +282,18 @@ void TrajectoryAnalysisModule::finishFrames(TrajectoryAnalysisModuleData * /*pda
 }
 
 
+const char *TrajectoryAnalysisModule::name() const
+{
+    return impl_->name_.c_str();
+}
+
+
+const char *TrajectoryAnalysisModule::description() const
+{
+    return impl_->description_.c_str();
+}
+
+
 int TrajectoryAnalysisModule::datasetCount() const
 {
     return impl_->datasetNames_.size();
index 43c6f1a2f8e802e2a0270a173f5d93e964a7ac3c..aeaaf58135d1e664ebe632c539e04b94d48125bf 100644 (file)
@@ -178,7 +178,7 @@ typedef gmx_unique_ptr<TrajectoryAnalysisModuleData>::type
  *
  * Trajectory analysis methods should derive from this class and override the
  * necessary virtual methods to implement initialization (initOptions(),
- * initOptionsDone(), initAnalysis(), initAfterFirstFrame()), per-frame analysis
+ * optionsFinished(), initAnalysis(), initAfterFirstFrame()), per-frame analysis
  * (analyzeFrame()), and final processing (finishFrames(), finishAnalysis(),
  * writeOutput()).
  *
@@ -226,11 +226,11 @@ class TrajectoryAnalysisModule
         /*! \brief
          * Initializes options understood by the module.
          *
+         * \param[in,out] options  Options object to add the options to.
          * \param[in,out] settings Settings to pass to and from the module.
-         * \returns  Reference to options that are accepted by the module.
          *
-         * Typical implementation returns a reference to a member variable
-         * after first adding necessary options to that object.  Output values
+         * This method is called first after the constructor, and it should
+         * add options understood by the module to \p options.  Output values
          * from options (including selections) should be stored in member
          * variables.
          *
@@ -239,12 +239,14 @@ class TrajectoryAnalysisModule
          * \p settings object; see TrajectoryAnalysisSettings for more details.
          *
          * If settings depend on the option values provided by the user, see
-         * initOptionsDone().
+         * optionsFinished().
          */
-        virtual Options &initOptions(TrajectoryAnalysisSettings *settings) = 0;
+        virtual void initOptions(Options *options,
+                                 TrajectoryAnalysisSettings *settings) = 0;
         /*! \brief
          * Called after all option values have been set.
          *
+         * \param[in,out] options  Options object in which options are stored.
          * \param[in,out] settings Settings to pass to and from the module.
          *
          * This method is called after option values have been assigned (but
@@ -257,7 +259,8 @@ class TrajectoryAnalysisModule
          *
          * The default implementation does nothing.
          */
-        virtual void initOptionsDone(TrajectoryAnalysisSettings *settings);
+        virtual void optionsFinished(Options *options,
+                                     TrajectoryAnalysisSettings *settings);
         /*! \brief
          * Initializes the analysis.
          *
@@ -377,6 +380,18 @@ class TrajectoryAnalysisModule
          */
         virtual void writeOutput() = 0;
 
+        /*! \brief
+         * Returns the name of the analysis module.
+         *
+         * Does not throw.
+         */
+        const char *name() const;
+        /*! \brief
+         * Returns short description for the analysis module.
+         *
+         * Does not throw.
+         */
+        const char *description() const;
         /*! \brief
          * Returns the number of datasets provided by the module.
          *
@@ -424,9 +439,11 @@ class TrajectoryAnalysisModule
         /*! \brief
          * Initializes the dataset registration mechanism.
          *
-         * \throws std::bad_alloc if out of memory.
+         * \param[in] name         Name for the module.
+         * \param[in] description  One-line description for the module.
+         * \throws    std::bad_alloc if out of memory.
          */
-        TrajectoryAnalysisModule();
+        TrajectoryAnalysisModule(const char *name, const char *description);
 
         /*! \brief
          * Registers a dataset that exports data.
index 75ba031c268f97cd657e0d49a93ae57016fcf9dc..e6b6f9f20e6ba4edc6d176a075ea739b04a0ae0f 100644 (file)
@@ -132,7 +132,7 @@ class TrajectoryAnalysisSettings
          *
          * Returns the value set with setPBC() and/or overridden by the user.
          * The user-provided value can be accessed in
-         * TrajectoryAnalysisModule::initOptionsDone(), and can be overridden
+         * TrajectoryAnalysisModule::optionsFinished(), and can be overridden
          * with a call to setPBC().
          */
         bool hasPBC() const;
index b9dd52c7c9efc008b167dcb63efe7bd13446ece7..42566a1fc7fbd1e985de4b0cd9ad2ea963e0f68e 100644 (file)
@@ -78,8 +78,6 @@ class TrajectoryAnalysisCommandLineRunner::Impl
         bool parseOptions(TrajectoryAnalysisSettings *settings,
                           TrajectoryAnalysisRunnerCommon *common,
                           SelectionCollection *selections,
-                          SelectionOptionManager *seloptManager,
-                          Options *options,
                           int *argc, char *argv[]);
 
         TrajectoryAnalysisModule *module_;
@@ -123,47 +121,50 @@ TrajectoryAnalysisCommandLineRunner::Impl::parseOptions(
         TrajectoryAnalysisSettings *settings,
         TrajectoryAnalysisRunnerCommon *common,
         SelectionCollection *selections,
-        SelectionOptionManager *seloptManager,
-        Options *options,
         int *argc, char *argv[])
 {
-    Options &moduleOptions = module_->initOptions(settings);
-    Options &commonOptions = common->initOptions();
-    Options &selectionOptions = selections->initOptions();
+    Options options(NULL, NULL);
+    Options moduleOptions(module_->name(), module_->description());
+    Options commonOptions("common", "Common analysis control");
+    Options selectionOptions("selection", "Common selection control");
+    module_->initOptions(&moduleOptions, settings);
+    common->initOptions(&commonOptions);
+    selections->initOptions(&selectionOptions);
 
-    options->addSubSection(&commonOptions);
-    options->addSubSection(&selectionOptions);
-    options->addSubSection(&moduleOptions);
+    options.addSubSection(&commonOptions);
+    options.addSubSection(&selectionOptions);
+    options.addSubSection(&moduleOptions);
 
-    setManagerForSelectionOptions(options, seloptManager);
+    SelectionOptionManager seloptManager(selections);
+    setManagerForSelectionOptions(&options, &seloptManager);
 
     {
-        CommandLineParser  parser(options);
+        CommandLineParser  parser(&options);
         try
         {
             parser.parse(argc, argv);
         }
         catch (const UserInputError &ex)
         {
-            printHelp(*options, *settings, *common);
+            printHelp(options, *settings, *common);
             throw;
         }
-        printHelp(*options, *settings, *common);
-        common->scaleTimeOptions(options);
-        options->finish();
+        printHelp(options, *settings, *common);
+        common->scaleTimeOptions(&options);
+        options.finish();
     }
 
-    if (!common->initOptionsDone())
+    if (!common->optionsFinished(&commonOptions))
     {
         return false;
     }
-    module_->initOptionsDone(settings);
+    module_->optionsFinished(&moduleOptions, settings);
 
     common->initIndexGroups(selections);
 
     // TODO: Check whether the input is a pipe.
     bool bInteractive = true;
-    seloptManager->parseRequestedFromStdin(bInteractive);
+    seloptManager.parseRequestedFromStdin(bInteractive);
     common->doneIndexGroups(selections);
 
     return true;
@@ -212,14 +213,11 @@ TrajectoryAnalysisCommandLineRunner::run(int argc, char *argv[])
 
     SelectionCollection  selections;
     selections.setDebugLevel(impl_->debugLevel_);
-    SelectionOptionManager seloptManager(&selections);
 
     TrajectoryAnalysisSettings  settings;
     TrajectoryAnalysisRunnerCommon  common(&settings);
 
-    Options  options(NULL, NULL);
-    if (!impl_->parseOptions(&settings, &common, &selections, &seloptManager,
-                             &options, &argc, argv))
+    if (!impl_->parseOptions(&settings, &common, &selections, &argc, argv))
     {
         return 0;
     }
@@ -289,19 +287,23 @@ TrajectoryAnalysisCommandLineRunner::writeHelp(File *file)
     // TODO: This method duplicates some code from run() and Impl::printHelp().
     // See how to best refactor it to share the common code.
     SelectionCollection             selections;
-    SelectionOptionManager          seloptManager(&selections);
     TrajectoryAnalysisSettings      settings;
     TrajectoryAnalysisRunnerCommon  common(&settings);
-    Options                         options(NULL, NULL);
 
-    Options &moduleOptions    = impl_->module_->initOptions(&settings);
-    Options &commonOptions    = common.initOptions();
-    Options &selectionOptions = selections.initOptions();
+    Options options(NULL, NULL);
+    Options moduleOptions(impl_->module_->name(), impl_->module_->description());
+    Options commonOptions("common", "Common analysis control");
+    Options selectionOptions("selection", "Common selection control");
+
+    impl_->module_->initOptions(&moduleOptions, &settings);
+    common.initOptions(&commonOptions);
+    selections.initOptions(&selectionOptions);
 
     options.addSubSection(&commonOptions);
     options.addSubSection(&selectionOptions);
     options.addSubSection(&moduleOptions);
 
+    SelectionOptionManager seloptManager(&selections);
     setManagerForSelectionOptions(&options, &seloptManager);
 
     CommandLineHelpWriter(options)
index 3fe5510ac3b9e8bab925857ee040ad3ae369e092..1cab8811bd717f6271a57d0e65f7b66a0552a8e1 100644 (file)
@@ -68,7 +68,7 @@ const char Angle::shortDescription[] =
     "Calculate angles";
 
 Angle::Angle()
-    : options_(name, shortDescription),
+    : TrajectoryAnalysisModule(name, shortDescription),
       sel1info_(NULL), sel2info_(NULL),
       bSplit1_(false), bSplit2_(false), bMulti_(false), bAll_(false),
       bDumpDist_(false), natoms1_(0), natoms2_(0), vt0_(NULL)
@@ -83,8 +83,8 @@ Angle::~Angle()
 }
 
 
-Options &
-Angle::initOptions(TrajectoryAnalysisSettings *settings)
+void
+Angle::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/)
 {
     static const char *const desc[] = {
         "g_angle computes different types of angles between vectors.",
@@ -129,45 +129,43 @@ Angle::initOptions(TrajectoryAnalysisSettings *settings)
     static const char *const cGroup2TypeEnum[] =
         { "none", "vector", "plane", "t0", "z", "sphnorm", NULL };
 
-    options_.setDescription(concatenateStrings(desc));
+    options->setDescription(concatenateStrings(desc));
 
-    options_.addOption(FileNameOption("o").filetype(eftPlot).outputFile()
+    options->addOption(FileNameOption("o").filetype(eftPlot).outputFile()
                            .store(&fnAngle_).defaultValueIfSet("angle")
                            .description("Computed angles"));
-    options_.addOption(FileNameOption("od").filetype(eftPlot).outputFile()
+    options->addOption(FileNameOption("od").filetype(eftPlot).outputFile()
                            .store(&fnDump_).defaultValueIfSet("angdump")
                            .description("Individual angles on separate lines"));
 
-    options_.addOption(StringOption("g1").enumValue(cGroup1TypeEnum)
+    options->addOption(StringOption("g1").enumValue(cGroup1TypeEnum)
         .defaultEnumIndex(0).store(&g1type_)
         .description("Type of analysis/first vector group"));
-    options_.addOption(StringOption("g2").enumValue(cGroup2TypeEnum)
+    options->addOption(StringOption("g2").enumValue(cGroup2TypeEnum)
         .defaultEnumIndex(0).store(&g2type_)
         .description("Type of second vector group"));
-    options_.addOption(BooleanOption("split1").store(&bSplit1_)
+    options->addOption(BooleanOption("split1").store(&bSplit1_)
         .description("Each position of first group in separate selection"));
-    options_.addOption(BooleanOption("split2").store(&bSplit2_)
+    options->addOption(BooleanOption("split2").store(&bSplit2_)
         .description("Each position of second group in separate selection"));
-    options_.addOption(BooleanOption("multi").store(&bMulti_)
+    options->addOption(BooleanOption("multi").store(&bMulti_)
         .description("Analyze multiple sets of angles/dihedrals"));
-    options_.addOption(BooleanOption("all").store(&bAll_)
+    options->addOption(BooleanOption("all").store(&bAll_)
         .description("Print individual angles together with the average"));
-    options_.addOption(BooleanOption("dumpd").store(&bDumpDist_)
+    options->addOption(BooleanOption("dumpd").store(&bDumpDist_)
         .description("Write also distances with -od"));
 
-    options_.addOption(SelectionOption("group1").multiValue().required()
+    options->addOption(SelectionOption("group1").multiValue().required()
         .dynamicOnlyWhole().storeVector(&sel1_).getAdjuster(&sel1info_)
         .description("First analysis/vector selection"));
-    options_.addOption(SelectionOption("group2").multiValue()
+    options->addOption(SelectionOption("group2").multiValue()
         .dynamicOnlyWhole().storeVector(&sel2_).getAdjuster(&sel2info_)
         .description("Second analysis/vector selection"));
-
-    return options_;
 }
 
 
 void
-Angle::initOptionsDone(TrajectoryAnalysisSettings *settings)
+Angle::optionsFinished(Options *options, TrajectoryAnalysisSettings *settings)
 {
     // Validity checks.
     bool bSingle = (g1type_[0] == 'a' || g1type_[0] == 'd');
@@ -177,7 +175,7 @@ Angle::initOptionsDone(TrajectoryAnalysisSettings *settings)
         GMX_THROW(InconsistentInputError("Cannot use a second group (-g2) with "
                                          "-g1 angle or dihedral"));
     }
-    if (bSingle && options_.isSet("group2"))
+    if (bSingle && options->isSet("group2"))
     {
         GMX_THROW(InconsistentInputError("Cannot provide a second selection "
                                          "(-group2) with -g1 angle or dihedral"));
@@ -231,7 +229,7 @@ Angle::initOptionsDone(TrajectoryAnalysisSettings *settings)
         default:
             GMX_THROW(InternalError("invalid -g2 value"));
     }
-    if (natoms2_ == 0 && options_.isSet("group2"))
+    if (natoms2_ == 0 && options->isSet("group2"))
     {
         GMX_THROW(InconsistentInputError("Cannot provide a second selection (-group2) with -g2 t0 or z"));
     }
index 9ddcb24e43a6f92cc93a7115d143394dee76eb97..6cf7479b07f7963c2bdb0a33f4aef2d8b1564a53 100644 (file)
@@ -42,7 +42,6 @@
 
 #include "../analysismodule.h"
 #include "gromacs/analysisdata/analysisdata.h"
-#include "gromacs/options/options.h"
 #include "gromacs/selection/selection.h"
 
 namespace gmx
@@ -62,8 +61,10 @@ class Angle : public TrajectoryAnalysisModule
         Angle();
         virtual ~Angle();
 
-        virtual Options &initOptions(TrajectoryAnalysisSettings *settings);
-        virtual void initOptionsDone(TrajectoryAnalysisSettings *settings);
+        virtual void initOptions(Options *options,
+                                 TrajectoryAnalysisSettings *settings);
+        virtual void optionsFinished(Options *options,
+                                     TrajectoryAnalysisSettings *settings);
         virtual void initAnalysis(const TrajectoryAnalysisSettings &settings,
                                   const TopologyInformation &top);
 
@@ -77,8 +78,6 @@ class Angle : public TrajectoryAnalysisModule
         void checkSelections(const SelectionList &sel1,
                              const SelectionList &sel2) const;
 
-        Options                 options_;
-
         SelectionList           sel1_;
         SelectionList           sel2_;
         SelectionOptionInfo    *sel1info_;
index 65eeee25bf4e2c78c3838db00fd367c375840b73..423e831494938f5c21009e673831f6f1670d1e05 100644 (file)
@@ -66,7 +66,8 @@ const char Distance::shortDescription[] =
     "Calculate distances";
 
 Distance::Distance()
-    : options_(name, shortDescription), avem_(new AnalysisDataAverageModule())
+    : TrajectoryAnalysisModule(name, shortDescription),
+      avem_(new AnalysisDataAverageModule())
 {
     data_.setColumnCount(4);
     registerAnalysisDataset(&data_, "distance");
@@ -78,8 +79,8 @@ Distance::~Distance()
 }
 
 
-Options &
-Distance::initOptions(TrajectoryAnalysisSettings *settings)
+void
+Distance::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/)
 {
     static const char *const desc[] = {
         "g_dist can calculate the distance between two positions as",
@@ -87,14 +88,13 @@ Distance::initOptions(TrajectoryAnalysisSettings *settings)
         "x, y and z components are plotted."
     };
 
-    options_.setDescription(concatenateStrings(desc));
+    options->setDescription(concatenateStrings(desc));
 
-    options_.addOption(FileNameOption("o").filetype(eftPlot).outputFile()
+    options->addOption(FileNameOption("o").filetype(eftPlot).outputFile()
                            .store(&fnDist_).defaultValueIfSet("dist")
                            .description("Computed distances"));
-    options_.addOption(SelectionOption("select").required().valueCount(2)
+    options->addOption(SelectionOption("select").required().valueCount(2)
                            .store(sel_));
-    return options_;
 }
 
 
index 8071b7dc656e1f646fce03c37c9e4765562ab5f8..745df5a6bb537323b2970014116e333f106ebdb4 100644 (file)
@@ -43,7 +43,6 @@
 #include "../analysismodule.h"
 #include "gromacs/analysisdata/analysisdata.h"
 #include "gromacs/analysisdata/modules/average.h"
-#include "gromacs/options/options.h"
 #include "gromacs/selection/selection.h"
 
 namespace gmx
@@ -61,7 +60,8 @@ class Distance : public TrajectoryAnalysisModule
         Distance();
         virtual ~Distance();
 
-        virtual Options &initOptions(TrajectoryAnalysisSettings *settings);
+        virtual void initOptions(Options *options,
+                                 TrajectoryAnalysisSettings *settings);
         virtual void initAnalysis(const TrajectoryAnalysisSettings &settings,
                                   const TopologyInformation &top);
 
@@ -72,7 +72,6 @@ class Distance : public TrajectoryAnalysisModule
         virtual void writeOutput();
 
     private:
-        Options                          options_;
         std::string                      fnDist_;
         Selection                        sel_[2];
         AnalysisData                     data_;
index 8ba3ef86eba2d13cd678b0f85d6a134ddb7367a9..f54be0efb10d28e9fc5fa423bad41e1ed4cb6960 100644 (file)
@@ -244,7 +244,7 @@ const char Select::shortDescription[] =
     "Print general information about selections";
 
 Select::Select()
-    : options_(name, shortDescription),
+    : TrajectoryAnalysisModule(name, shortDescription),
       bDump_(false), bTotNorm_(false), bFracNorm_(false), bResInd_(false),
       top_(NULL)
 {
@@ -262,8 +262,8 @@ Select::~Select()
 }
 
 
-Options &
-Select::initOptions(TrajectoryAnalysisSettings *settings)
+void
+Select::initOptions(Options *options, TrajectoryAnalysisSettings * /*settings*/)
 {
     static const char *const desc[] = {
         "[TT]g_select[tt] writes out basic data about dynamic selections.",
@@ -313,40 +313,38 @@ Select::initOptions(TrajectoryAnalysisSettings *settings)
         "With [TT]-dump[tt], the frame time is omitted from the output."
     };
 
-    options_.setDescription(concatenateStrings(desc));
+    options->setDescription(concatenateStrings(desc));
 
-    options_.addOption(FileNameOption("os").filetype(eftPlot).outputFile()
+    options->addOption(FileNameOption("os").filetype(eftPlot).outputFile()
                            .store(&fnSize_).defaultValueIfSet("size")
                            .description("Number of positions in each selection"));
-    options_.addOption(FileNameOption("oc").filetype(eftPlot).outputFile()
+    options->addOption(FileNameOption("oc").filetype(eftPlot).outputFile()
                            .store(&fnFrac_).defaultValueIfSet("frac")
                            .description("Covered fraction for each selection"));
-    options_.addOption(FileNameOption("oi").filetype(eftGenericData).outputFile()
+    options->addOption(FileNameOption("oi").filetype(eftGenericData).outputFile()
                            .store(&fnIndex_).defaultValueIfSet("index")
                            .description("Indices selected by each selection"));
-    options_.addOption(FileNameOption("on").filetype(eftIndex).outputFile()
+    options->addOption(FileNameOption("on").filetype(eftIndex).outputFile()
                            .store(&fnNdx_).defaultValueIfSet("index")
                            .description("Index file from the selection"));
-    options_.addOption(FileNameOption("om").filetype(eftPlot).outputFile()
+    options->addOption(FileNameOption("om").filetype(eftPlot).outputFile()
                            .store(&fnMask_).defaultValueIfSet("mask")
                            .description("Mask for selected positions"));
 
-    options_.addOption(SelectionOption("select").storeVector(&sel_)
+    options->addOption(SelectionOption("select").storeVector(&sel_)
         .required().multiValue()
         .description("Selections to analyze"));
 
-    options_.addOption(BooleanOption("dump").store(&bDump_)
+    options->addOption(BooleanOption("dump").store(&bDump_)
         .description("Do not print the frame time (-om, -oi) or the index size (-oi)"));
-    options_.addOption(BooleanOption("norm").store(&bTotNorm_)
+    options->addOption(BooleanOption("norm").store(&bTotNorm_)
         .description("Normalize by total number of positions with -os"));
-    options_.addOption(BooleanOption("cfnorm").store(&bFracNorm_)
+    options->addOption(BooleanOption("cfnorm").store(&bFracNorm_)
         .description("Normalize by covered fraction with -os"));
     const char *const cResNumberEnum[] = { "number", "index", NULL };
-    options_.addOption(StringOption("resnr").store(&resNumberType_)
+    options->addOption(StringOption("resnr").store(&resNumberType_)
         .enumValue(cResNumberEnum).defaultEnumIndex(0)
         .description("Residue number output type"));
-
-    return options_;
 }
 
 
index 833d889edfa5e361e7867f37352468ca38abd0a9..d4ca4e2f9470580c87abbb49056be3f1a22d7697 100644 (file)
@@ -43,7 +43,6 @@
 
 #include "../analysismodule.h"
 #include "gromacs/analysisdata/analysisdata.h"
-#include "gromacs/options/options.h"
 #include "gromacs/selection/selection.h"
 
 namespace gmx
@@ -61,7 +60,8 @@ class Select : public TrajectoryAnalysisModule
         Select();
         virtual ~Select();
 
-        virtual Options &initOptions(TrajectoryAnalysisSettings *settings);
+        virtual void initOptions(Options *options,
+                                 TrajectoryAnalysisSettings *settings);
         virtual void initAnalysis(const TrajectoryAnalysisSettings &settings,
                                   const TopologyInformation &top);
 
@@ -72,7 +72,6 @@ class Select : public TrajectoryAnalysisModule
         virtual void writeOutput();
 
     private:
-        Options                  options_;
         SelectionList            sel_;
 
         std::string              fnSize_;
index f1882b2fb854772eacdbc55535b48a3465daabfd..838522f21909b73bb93f463960dc80766ab3de31 100644 (file)
@@ -74,7 +74,6 @@ class TrajectoryAnalysisRunnerCommon::Impl
         void finishTrajectory();
 
         TrajectoryAnalysisSettings &settings_;
-        Options                 options_;
         TopologyInformation     topInfo_;
 
         bool                    bHelp_;
@@ -102,7 +101,7 @@ class TrajectoryAnalysisRunnerCommon::Impl
 
 
 TrajectoryAnalysisRunnerCommon::Impl::Impl(TrajectoryAnalysisSettings *settings)
-    : settings_(*settings), options_("common", "Common analysis control"),
+    : settings_(*settings),
       bHelp_(false), bShowHidden_(false), bQuiet_(false),
       startTime_(0.0), endTime_(0.0), deltaTime_(0.0),
       grps_(NULL),
@@ -164,67 +163,64 @@ TrajectoryAnalysisRunnerCommon::~TrajectoryAnalysisRunnerCommon()
 }
 
 
-Options &
-TrajectoryAnalysisRunnerCommon::initOptions()
+void
+TrajectoryAnalysisRunnerCommon::initOptions(Options *options)
 {
     TrajectoryAnalysisSettings &settings = impl_->settings_;
-    Options &options = impl_->options_;
 
     // Add options for help.
-    options.addOption(BooleanOption("h").store(&impl_->bHelp_)
-                          .description("Print help and quit"));
-    options.addOption(BooleanOption("hidden").store(&impl_->bShowHidden_)
-                          .hidden()
-                          .description("Show hidden options"));
-    options.addOption(BooleanOption("quiet").store(&impl_->bQuiet_)
-                          .hidden()
-                          .description("Hide options in normal run"));
+    options->addOption(BooleanOption("h").store(&impl_->bHelp_)
+                           .description("Print help and quit"));
+    options->addOption(BooleanOption("hidden").store(&impl_->bShowHidden_)
+                           .hidden()
+                           .description("Show hidden options"));
+    options->addOption(BooleanOption("quiet").store(&impl_->bQuiet_)
+                           .hidden()
+                           .description("Hide options in normal run"));
 
     // Add common file name arguments.
-    options.addOption(FileNameOption("f")
-                          .filetype(eftTrajectory).inputFile()
-                          .store(&impl_->trjfile_)
-                          .defaultValueIfSet("traj")
-                          .description("Input trajectory or single configuration"));
-    options.addOption(FileNameOption("s")
-                          .filetype(eftTopology).inputFile()
-                          .store(&impl_->topfile_)
-                          .defaultValueIfSet("topol")
-                          .description("Input structure"));
-    options.addOption(FileNameOption("n")
-                          .filetype(eftIndex).inputFile()
-                          .store(&impl_->ndxfile_)
-                          .defaultValueIfSet("index")
-                          .description("Extra index groups"));
-    options.addOption(SelectionFileOption("sf"));
+    options->addOption(FileNameOption("f")
+                           .filetype(eftTrajectory).inputFile()
+                           .store(&impl_->trjfile_)
+                           .defaultValueIfSet("traj")
+                           .description("Input trajectory or single configuration"));
+    options->addOption(FileNameOption("s")
+                           .filetype(eftTopology).inputFile()
+                           .store(&impl_->topfile_)
+                           .defaultValueIfSet("topol")
+                           .description("Input structure"));
+    options->addOption(FileNameOption("n")
+                           .filetype(eftIndex).inputFile()
+                           .store(&impl_->ndxfile_)
+                           .defaultValueIfSet("index")
+                           .description("Extra index groups"));
+    options->addOption(SelectionFileOption("sf"));
 
     // Add options for trajectory time control.
-    options.addOption(DoubleOption("b").store(&impl_->startTime_).timeValue()
-                          .description("First frame (%t) to read from trajectory"));
-    options.addOption(DoubleOption("e").store(&impl_->endTime_).timeValue()
-                          .description("Last frame (%t) to read from trajectory"));
-    options.addOption(DoubleOption("dt").store(&impl_->deltaTime_).timeValue()
-                          .description("Only use frame if t MOD dt == first time (%t)"));
+    options->addOption(DoubleOption("b").store(&impl_->startTime_).timeValue()
+                           .description("First frame (%t) to read from trajectory"));
+    options->addOption(DoubleOption("e").store(&impl_->endTime_).timeValue()
+                           .description("Last frame (%t) to read from trajectory"));
+    options->addOption(DoubleOption("dt").store(&impl_->deltaTime_).timeValue()
+                           .description("Only use frame if t MOD dt == first time (%t)"));
 
     // Add time unit option.
-    settings.impl_->timeUnitManager.addTimeUnitOption(&options, "tu");
+    settings.impl_->timeUnitManager.addTimeUnitOption(options, "tu");
 
     // Add plot options.
-    settings.impl_->plotSettings.addOptions(&options);
+    settings.impl_->plotSettings.addOptions(options);
 
     // Add common options for trajectory processing.
     if (!settings.hasFlag(TrajectoryAnalysisSettings::efNoUserRmPBC))
     {
-        options.addOption(BooleanOption("rmpbc").store(&settings.impl_->bRmPBC)
-                              .description("Make molecules whole for each frame"));
+        options->addOption(BooleanOption("rmpbc").store(&settings.impl_->bRmPBC)
+                               .description("Make molecules whole for each frame"));
     }
     if (!settings.hasFlag(TrajectoryAnalysisSettings::efNoUserPBC))
     {
-        options.addOption(BooleanOption("pbc").store(&settings.impl_->bPBC)
-                              .description("Use periodic boundary conditions for distance calculation"));
+        options->addOption(BooleanOption("pbc").store(&settings.impl_->bPBC)
+                               .description("Use periodic boundary conditions for distance calculation"));
     }
-
-    return impl_->options_;
 }
 
 
@@ -236,7 +232,7 @@ TrajectoryAnalysisRunnerCommon::scaleTimeOptions(Options *options)
 
 
 bool
-TrajectoryAnalysisRunnerCommon::initOptionsDone()
+TrajectoryAnalysisRunnerCommon::optionsFinished(Options *options)
 {
     if (impl_->bHelp_)
     {
@@ -251,11 +247,11 @@ TrajectoryAnalysisRunnerCommon::initOptionsDone()
         GMX_THROW(InconsistentInputError("No trajectory or topology provided, nothing to do!"));
     }
 
-    if (impl_->options_.isSet("b"))
+    if (options->isSet("b"))
         setTimeValue(TBEGIN, impl_->startTime_);
-    if (impl_->options_.isSet("e"))
+    if (options->isSet("e"))
         setTimeValue(TEND, impl_->endTime_);
-    if (impl_->options_.isSet("dt"))
+    if (options->isSet("dt"))
         setTimeValue(TDELTA, impl_->deltaTime_);
 
     return true;
index 0f4e3ed033b6240b0255395e53b254c59f7cc579..a8a3e41c6c690cc968ac97dc50258bee59d4bbb0 100644 (file)
@@ -79,16 +79,21 @@ class TrajectoryAnalysisRunnerCommon
         explicit TrajectoryAnalysisRunnerCommon(TrajectoryAnalysisSettings *settings);
         ~TrajectoryAnalysisRunnerCommon();
 
-        //! Initializes common options for trajectory analysis.
-        Options &initOptions();
+        /*! \brief
+         * Initializes common options for trajectory analysis.
+         *
+         * \param[in,out] options  Options object to add the options to.
+         */
+        void initOptions(Options *options);
         //! Scales time option values according to the time unit set.
         void scaleTimeOptions(Options *options);
         /*! \brief
          * Processes common option values after they have been parsed.
          *
-         * \returns false if the tool should exit after printing help.
+         * \param[in,out] options Options object in which options are stored.
+         * \returns       false if the tool should exit after printing help.
          */
-        bool initOptionsDone();
+        bool optionsFinished(Options *options);
         //! Initialize index groups for selections.
         void initIndexGroups(SelectionCollection *selections);
         //! Free memory allocated for index groups.
index 795a9c6ec6fba2522df461c7a2f854f4bd6d2bdd..0701f6bca11281d63a537c9ac8ffc7f7865f5067 100644 (file)
@@ -53,7 +53,8 @@ class SelectionTester : public TrajectoryAnalysisModule
         SelectionTester();
         virtual ~SelectionTester();
 
-        virtual Options &initOptions(TrajectoryAnalysisSettings *settings);
+        virtual void initOptions(Options *options,
+                                 TrajectoryAnalysisSettings *settings);
         virtual void initAnalysis(const TrajectoryAnalysisSettings &settings,
                                   const TopologyInformation &top);
 
@@ -66,13 +67,12 @@ class SelectionTester : public TrajectoryAnalysisModule
     private:
         void printSelections();
 
-        Options                  options_;
         SelectionList            selections_;
         int                      nmaxind_;
 };
 
 SelectionTester::SelectionTester()
-    : options_("testing", "Selection testing and debugging"),
+    : TrajectoryAnalysisModule("testing", "Selection testing and debugging"),
       nmaxind_(20)
 {
 }
@@ -92,22 +92,21 @@ SelectionTester::printSelections()
     fprintf(stderr, "\n");
 }
 
-Options &
-SelectionTester::initOptions(TrajectoryAnalysisSettings * /*settings*/)
+void
+SelectionTester::initOptions(Options *options,
+                             TrajectoryAnalysisSettings * /*settings*/)
 {
     static const char *const desc[] = {
         "This is a test program for selections."
     };
 
-    options_.setDescription(concatenateStrings(desc));
+    options->setDescription(concatenateStrings(desc));
 
-    options_.addOption(SelectionOption("select").storeVector(&selections_)
+    options->addOption(SelectionOption("select").storeVector(&selections_)
                            .required().multiValue()
                            .description("Selections to test"));
-    options_.addOption(IntegerOption("pmax").store(&nmaxind_)
+    options->addOption(IntegerOption("pmax").store(&nmaxind_)
                            .description("Maximum number of indices to print in lists (-1 = print all)"));
-
-    return options_;
 }
 
 void