3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
9 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
10 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
11 * Copyright (c) 2001-2009, The GROMACS development team,
12 * check out http://www.gromacs.org for more information.
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * If you want to redistribute modifications, please consider that
20 * scientific software is very special. Version control is crucial -
21 * bugs must be traceable. We will be happy to consider code for
22 * inclusion in the official distribution, but derived work must not
23 * be called official GROMACS. Details are found in the README & COPYING
24 * files - if they are missing, get the official version at www.gromacs.org.
26 * To help us fund GROMACS development, we humbly ask that you cite
27 * the papers on the package - you can find them in the top README file.
29 * For more info, check our website at http://www.gromacs.org
33 * Declares gmx::SelectionOption and gmx::SelectionOptionInfo.
35 * \author Teemu Murtola <teemu.murtola@cbr.su.se>
37 * \ingroup module_selection
39 #ifndef GMX_SELECTION_SELECTIONOPTION_H
40 #define GMX_SELECTION_SELECTIONOPTION_H
42 #include "../options/abstractoption.h"
44 #include "selection.h"
45 #include "selectionenums.h"
50 class SelectionOptionInfo;
51 class SelectionOptionManager;
52 class SelectionOptionStorage;
55 * Specifies an option that provides selection(s).
57 * Public methods in this class do not throw.
60 * Support for specifying that an option accepts, e.g., two to four selections.
61 * Currently, only a fixed count or any number of selections is possible.
63 * In addition to allowing this in OptionTemplate, also SelectionOptionManager
64 * needs to be updated.
68 * \ingroup module_selection
70 class SelectionOption : public OptionTemplate<Selection, SelectionOption>
73 //! OptionInfo subclass corresponding to this option type.
74 typedef SelectionOptionInfo InfoType;
76 //! Initializes an option with the given name.
77 explicit SelectionOption(const char *name) : MyBase(name) { }
80 * Request velocity evaluation for output positions.
82 * Note that even with this flag set, velocities may not be available,
83 * in which case SelectionPosition::hasVelocity() returns false.
85 MyClass &evaluateVelocities()
86 { selectionFlags_.set(efSelection_EvaluateVelocities); return me(); }
88 * Request force evaluation for output positions.
90 * Note that even with this flag set, forces may not be available,
91 * in which case SelectionPosition::hasForce() returns false.
93 MyClass &evaluateForces()
94 { selectionFlags_.set(efSelection_EvaluateForces); return me(); }
96 * Only accept selections that evaluate to atom positions.
98 * TODO: This option is not yet implemented.
101 { selectionFlags_.set(efSelection_OnlyAtoms); return me(); }
103 * Only accept static selections for this option.
105 MyClass &onlyStatic()
106 { selectionFlags_.set(efSelection_OnlyStatic); return me(); }
108 * Handle dynamic selections for this option with position masks.
111 * \see SelectionPosition::selected()
113 MyClass &dynamicMask()
114 { selectionFlags_.set(efSelection_DynamicMask); return me(); }
116 * Disallow using atom coordinates as the reference positions.
118 * TODO: This option is not yet implemented.
120 MyClass &dynamicOnlyWhole()
121 { selectionFlags_.set(efSelection_DynamicOnlyWhole); return me(); }
124 // Disable possibility to allow multiple occurrences, since it isn't
126 using MyBase::allowMultiple;
127 // Disable default value because it is impossible to provide a
129 using MyBase::defaultValue;
130 using MyBase::defaultValueIfSet;
132 virtual AbstractOptionStoragePointer createStorage() const;
134 SelectionFlags selectionFlags_;
137 * Needed to initialize SelectionOptionStorage from this class without
138 * otherwise unnecessary accessors.
140 friend class SelectionOptionStorage;
144 * Wrapper class for accessing and modifying selection option information.
146 * Allows changes to a selection option after creation.
148 * This class provides the necessary interface for changing, e.g., the number
149 * of allowed selections for a selection option after the option has been
150 * created with Options::addOption(). This is needed if the number or other
151 * flags are only known after other options have been parsed. The main
152 * advantage of this class over custom checks is that if used before
153 * interactive selection prompt, the interactive prompt is updated accordingly.
155 * When using this class, the option should be initially created with the most
156 * permissive flags, and this class should be used to place restrictions where
157 * appropriate. Otherwise, values that are provided before adjustments will
158 * need to follow the more strict checks. In most cases in trajectory analysis
159 * (which is the main use case for selection options), the adjustments should
160 * be done in TrajectoryAnalysisModule::initOptionsDone() for them to take
161 * place before interactive selection prompts.
163 * An instance of this class for a selection option can be obtained with
164 * SelectionOption::getAdjuster() when the option is created.
169 Options options("example", "Example options");
170 SelectionOptionInfo *info;
171 info = options.addOption(SelectionOption("sel").storeVector(&sel)
173 // < ... assign values to options ...>
176 // Put limitations on the selections based on the condition,
177 // which can depend on other option values.
178 // Throws if input given so far violates the limitations.
179 info->setValueCount(2);
180 info->setOnlyStatic(true);
185 * \ingroup module_selection
187 class SelectionOptionInfo : public OptionInfo
191 * Creates option info object for given storage object.
195 explicit SelectionOptionInfo(SelectionOptionStorage *option);
198 * Set manager for handling interaction with other options and the
199 * selection collection.
201 * \param manager Selection manager to set.
203 * This must be called before the values are added.
205 * Typically it is called through setManagerForSelectionOptions(),
206 * which recursively sets the manager for all selection options in
211 void setManager(SelectionOptionManager *manager);
214 * Sets the number of selections allowed for the option.
216 * \param[in] count Number of allowed selections.
217 * \throws std::bad_alloc if out of memory.
218 * \throws InvalidInputError if values have already been provided
219 * and their count does not match.
221 void setValueCount(int count);
224 * Sets whether this option evaluates velocities for positions.
226 * \param[in] bEnabled If true, velocities are evaluated.
230 * \see SelectionOption::evaluateVelocities()
232 void setEvaluateVelocities(bool bEnabled);
234 * Sets whether this option evaluates forces for positions.
236 * \param[in] bEnabled If true, forces are evaluated.
240 * \see SelectionOption::evaluateForces()
242 void setEvaluateForces(bool bEnabled);
244 * Sets whether this option accepts positions that come from multiple
247 * \param[in] bEnabled If true, the option accepts only positions that
248 * evaluate to atom positions.
250 * TODO: This is not yet implemented.
252 * \see SelectionOption::onlyAtoms()
254 void setOnlyAtoms(bool bEnabled);
256 * Sets whether this option accepts dynamic selections.
258 * \param[in] bEnabled If true, the option accepts only static
260 * \throws std::bad_alloc if out of memory.
261 * \throws InvalidInputError if dynamic selections have already been
264 * Strong exception safety guarantee.
266 * \see SelectionOption::onlyStatic()
268 void setOnlyStatic(bool bEnabled);
270 * Sets whether this option uses position masks for dynamic selections.
272 * \param[in] bEnabled If true, the position masks are used.
276 * \see SelectionOption::dynamicMask()
278 void setDynamicMask(bool bEnabled);
280 * Sets whether atom coordinates are allowed as reference positions.
282 * \param[in] bEnabled If true, the option does not accept atom
283 * coordinates as reference positions.
285 * TODO: This is not yet implemented.
287 * \see SelectionOption::dynamicOnlyWhole()
289 void setDynamicOnlyWhole(bool bEnabled);
292 SelectionOptionStorage &option();
293 const SelectionOptionStorage &option() const;