Merge "Allow 'atomname' and 'atomtype' in selections."
[alexxy/gromacs.git] / src / gromacs / selection / selectionoption.h
1 /*
2  *
3  *                This source code is part of
4  *
5  *                 G   R   O   M   A   C   S
6  *
7  *          GROningen MAchine for Chemical Simulations
8  *
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.
13
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.
18  *
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.
25  *
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.
28  *
29  * For more info, check our website at http://www.gromacs.org
30  */
31 /*! \file
32  * \brief
33  * Declares gmx::SelectionOption.
34  *
35  * \author Teemu Murtola <teemu.murtola@cbr.su.se>
36  * \inpublicapi
37  * \ingroup module_selection
38  */
39 #ifndef GMX_SELECTION_SELECTIONOPTION_H
40 #define GMX_SELECTION_SELECTIONOPTION_H
41
42 #include "../options/abstractoption.h"
43 #include "selection.h"
44 #include "selectionenums.h"
45 #include "selectionoptioninfo.h"
46
47 namespace gmx
48 {
49
50 class SelectionOptionInfo;
51 class SelectionOptionStorage;
52
53 /*! \brief
54  * Specifies an option that provides selection(s).
55  *
56  * Public methods in this class do not throw.
57  *
58  * \todo
59  * Support for specifying that an option accepts, e.g., two to four selections.
60  * Currently, only a fixed count or any number of selections is possible.
61  * \if internal
62  * In addition to allowing this in OptionTemplate, also SelectionOptionManager
63  * needs to be updated.
64  * \endif
65  *
66  * \inpublicapi
67  * \ingroup module_selection
68  */
69 class SelectionOption : public OptionTemplate<Selection, SelectionOption>
70 {
71     public:
72         //! OptionInfo subclass corresponding to this option type.
73         typedef SelectionOptionInfo InfoType;
74
75         //! Initializes an option with the given name.
76         explicit SelectionOption(const char *name) : MyBase(name) { }
77
78         /*! \brief
79          * Request velocity evaluation for output positions.
80          *
81          * Note that even with this flag set, velocities may not be available,
82          * in which case SelectionPosition::hasVelocity() returns false.
83          */
84         MyClass &evaluateVelocities()
85         { selectionFlags_.set(efSelection_EvaluateVelocities); return me(); }
86         /*! \brief
87          * Request force evaluation for output positions.
88          *
89          * Note that even with this flag set, forces may not be available,
90          * in which case SelectionPosition::hasForce() returns false.
91          */
92         MyClass &evaluateForces()
93         { selectionFlags_.set(efSelection_EvaluateForces); return me(); }
94         /*! \brief
95          * Only accept selections that evaluate to atom positions.
96          *
97          * TODO: This option is not yet implemented.
98          */
99         MyClass &onlyAtoms()
100         { selectionFlags_.set(efSelection_OnlyAtoms); return me(); }
101         /*! \brief
102          * Only accept static selections for this option.
103          */
104         MyClass &onlyStatic()
105         { selectionFlags_.set(efSelection_OnlyStatic); return me(); }
106         /*! \brief
107          * Handle dynamic selections for this option with position masks.
108          *
109          * \see Selection
110          * \see SelectionPosition::selected()
111          */
112         MyClass &dynamicMask()
113         { selectionFlags_.set(efSelection_DynamicMask); return me(); }
114         /*! \brief
115          * Disallow using atom coordinates as the reference positions.
116          *
117          * TODO: This option is not yet implemented.
118          */
119         MyClass &dynamicOnlyWhole()
120         { selectionFlags_.set(efSelection_DynamicOnlyWhole); return me(); }
121
122     private:
123         // Disable possibility to allow multiple occurrences, since it isn't
124         // implemented.
125         using MyBase::allowMultiple;
126         // Disable default value because it is impossible to provide a
127         // Selection object.
128         using MyBase::defaultValue;
129         using MyBase::defaultValueIfSet;
130
131         virtual AbstractOptionStoragePointer createStorage() const;
132
133         SelectionFlags          selectionFlags_;
134
135         /*! \brief
136          * Needed to initialize SelectionOptionStorage from this class without
137          * otherwise unnecessary accessors.
138          */
139         friend class SelectionOptionStorage;
140 };
141
142 } // namespace gmx
143
144 #endif