Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / selection / selectionoption.h
index 20c9083fb9f19aee22df10c33b7dc4402f19327b..0af37dddc73c36cb077d3446a9cbdc692321170a 100644 (file)
@@ -1,48 +1,51 @@
 /*
+ * This file is part of the GROMACS molecular simulation package.
  *
- *                This source code is part of
+ * Copyright (c) 2010,2011,2012,2013,2014, 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.
  *
- *                 G   R   O   M   A   C   S
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
  *
- *          GROningen MAchine for Chemical Simulations
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2009, The GROMACS development team,
- * check out http://www.gromacs.org for more information.
-
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
  *
- * If you want to redistribute modifications, please consider that
- * scientific software is very special. Version control is crucial -
- * bugs must be traceable. We will be happy to consider code for
- * inclusion in the official distribution, but derived work must not
- * be called official GROMACS. Details are found in the README & COPYING
- * files - if they are missing, get the official version at www.gromacs.org.
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
  *
  * To help us fund GROMACS development, we humbly ask that you cite
- * the papers on the package - you can find them in the top README file.
- *
- * For more info, check our website at http://www.gromacs.org
+ * the research papers on the package. Check out http://www.gromacs.org.
  */
 /*! \file
  * \brief
  * Declares gmx::SelectionOption and gmx::SelectionOptionInfo.
  *
- * \author Teemu Murtola <teemu.murtola@cbr.su.se>
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \inpublicapi
  * \ingroup module_selection
  */
 #ifndef GMX_SELECTION_SELECTIONOPTION_H
 #define GMX_SELECTION_SELECTIONOPTION_H
 
-#include "../options/abstractoption.h"
-
-#include "selection.h"
-#include "selectionenums.h"
+#include "gromacs/options/abstractoption.h"
+#include "gromacs/selection/selection.h"
+#include "gromacs/selection/selectionenums.h"
 
 namespace gmx
 {
@@ -56,6 +59,10 @@ class SelectionOptionStorage;
  *
  * Public methods in this class do not throw.
  *
+ * To use options of this type, SelectionOptionManager must first be added to
+ * the Options collection.  For trajectory analysis tools, the framework takes
+ * care of this.
+ *
  * \todo
  * Support for specifying that an option accepts, e.g., two to four selections.
  * Currently, only a fixed count or any number of selections is possible.
@@ -74,28 +81,28 @@ class SelectionOption : public OptionTemplate<Selection, SelectionOption>
         typedef SelectionOptionInfo InfoType;
 
         //! Initializes an option with the given name.
-        explicit SelectionOption(const char *name) : MyBase(name) { }
+        explicit SelectionOption(const char *name)
+            : MyBase(name), defaultText_(""),
+              selectionFlags_(efSelection_DisallowEmpty)
+        {
+        }
 
         /*! \brief
          * Request velocity evaluation for output positions.
          *
-         * Note that even with this flag set, velocities may not be available,
-         * in which case SelectionPosition::hasVelocity() returns false.
+         * \see Selection::setEvaluateVelocities()
          */
         MyClass &evaluateVelocities()
         { selectionFlags_.set(efSelection_EvaluateVelocities); return me(); }
         /*! \brief
          * Request force evaluation for output positions.
          *
-         * Note that even with this flag set, forces may not be available,
-         * in which case SelectionPosition::hasForce() returns false.
+         * \see Selection::setEvaluateForces()
          */
         MyClass &evaluateForces()
         { selectionFlags_.set(efSelection_EvaluateForces); return me(); }
         /*! \brief
          * Only accept selections that evaluate to atom positions.
-         *
-         * TODO: This option is not yet implemented.
          */
         MyClass &onlyAtoms()
         { selectionFlags_.set(efSelection_OnlyAtoms); return me(); }
@@ -113,12 +120,24 @@ class SelectionOption : public OptionTemplate<Selection, SelectionOption>
         MyClass &dynamicMask()
         { selectionFlags_.set(efSelection_DynamicMask); return me(); }
         /*! \brief
-         * Disallow using atom coordinates as the reference positions.
+         * Allow specifying an unconditionally empty selection for this option.
          *
-         * TODO: This option is not yet implemented.
+         * If this option is not set, selections that are unconditionally empty
+         * (i.e., can never match any atoms) result in errors.
+         * Note that even without this option, it is still possible that a
+         * dynamic selection evaluates to zero atoms for some frames.
          */
-        MyClass &dynamicOnlyWhole()
-        { selectionFlags_.set(efSelection_DynamicOnlyWhole); return me(); }
+        MyClass &allowEmpty()
+        { selectionFlags_.clear(efSelection_DisallowEmpty); return me(); }
+
+        /*! \brief
+         * Sets default selection text for the option.
+         *
+         * If the option is not set by the user, the provided text is parsed as
+         * the value of the selection.
+         */
+        MyClass &defaultSelectionText(const char *text)
+        { defaultText_ = text; return me(); }
 
     private:
         // Disable possibility to allow multiple occurrences, since it isn't
@@ -129,8 +148,10 @@ class SelectionOption : public OptionTemplate<Selection, SelectionOption>
         using MyBase::defaultValue;
         using MyBase::defaultValueIfSet;
 
-        virtual AbstractOptionStoragePointer createStorage() const;
+        virtual AbstractOptionStorage *createStorage(
+            const OptionManagerContainer &managers) const;
 
+        const char             *defaultText_;
         SelectionFlags          selectionFlags_;
 
         /*! \brief
@@ -165,20 +186,20 @@ class SelectionOption : public OptionTemplate<Selection, SelectionOption>
  *
  * Example use:
  * \code
-SelectionList sel;
-Options options("example", "Example options");
-SelectionOptionInfo *info;
-info = options.addOption(SelectionOption("sel").storeVector(&sel)
-                             .multiValue());
-// < ... assign values to options ...>
-if ( condition )
-{
-    // Put limitations on the selections based on the condition,
-    // which can depend on other option values.
-    // Throws if input given so far violates the limitations.
-    info->setValueCount(2);
-    info->setOnlyStatic(true);
-}
+   SelectionList sel;
+   Options options("example", "Example options");
+   SelectionOptionInfo *info;
+   info = options.addOption(SelectionOption("sel").storeVector(&sel)
+                                .multiValue());
+   // < ... assign values to options ...>
+   if ( condition )
+   {
+       // Put limitations on the selections based on the condition,
+       // which can depend on other option values.
+       // Throws if input given so far violates the limitations.
+       info->setValueCount(2);
+       info->setOnlyStatic(true);
+   }
  * \endcode
  *
  * \inpublicapi
@@ -194,22 +215,6 @@ class SelectionOptionInfo : public OptionInfo
          */
         explicit SelectionOptionInfo(SelectionOptionStorage *option);
 
-        /*! \brief
-         * Set manager for handling interaction with other options and the
-         * selection collection.
-         *
-         * \param   manager  Selection manager to set.
-         *
-         * This must be called before the values are added.
-         *
-         * Typically it is called through setManagerForSelectionOptions(),
-         * which recursively sets the manager for all selection options in
-         * an Options object.
-         *
-         * Does not throw.
-         */
-        void setManager(SelectionOptionManager *manager);
-
         /*! \brief
          * Sets the number of selections allowed for the option.
          *
@@ -227,7 +232,7 @@ class SelectionOptionInfo : public OptionInfo
          *
          * Does not throw.
          *
-         * \see SelectionOption::evaluateVelocities()
+         * \see Selection::setEvaluateVelocities()
          */
         void setEvaluateVelocities(bool bEnabled);
         /*! \brief
@@ -237,7 +242,7 @@ class SelectionOptionInfo : public OptionInfo
          *
          * Does not throw.
          *
-         * \see SelectionOption::evaluateForces()
+         * \see Selection::setEvaluateForces()
          */
         void setEvaluateForces(bool bEnabled);
         /*! \brief
@@ -247,8 +252,6 @@ class SelectionOptionInfo : public OptionInfo
          * \param[in] bEnabled  If true, the option accepts only positions that
          *      evaluate to atom positions.
          *
-         * TODO: This is not yet implemented.
-         *
          * \see SelectionOption::onlyAtoms()
          */
         void setOnlyAtoms(bool bEnabled);
@@ -276,17 +279,6 @@ class SelectionOptionInfo : public OptionInfo
          * \see SelectionOption::dynamicMask()
          */
         void setDynamicMask(bool bEnabled);
-        /*! \brief
-         * Sets whether atom coordinates are allowed as reference positions.
-         *
-         * \param[in] bEnabled  If true, the option does not accept atom
-         *      coordinates as reference positions.
-         *
-         * TODO: This is not yet implemented.
-         *
-         * \see SelectionOption::dynamicOnlyWhole()
-         */
-        void setDynamicOnlyWhole(bool bEnabled);
 
     private:
         SelectionOptionStorage &option();