Use moltype directly for obtaining residueAtomRanges
[gromacs.git] / src / gromacs / selection / selectionoptionbehavior.h
blob16f1a572c221a91b9e4c4a7a7bf34ad0bb824d1b
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2015,2016,2018,2019, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
35 /*! \file
36 * \brief
37 * Declares gmx::SelectionOptionBehavior.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
40 * \inpublicapi
41 * \ingroup module_selection
43 #ifndef GMX_SELECTION_SELECTIONOPTIONBEHAVIOR_H
44 #define GMX_SELECTION_SELECTIONOPTIONBEHAVIOR_H
46 #include <string>
48 #include "gromacs/options/ioptionsbehavior.h"
49 #include "gromacs/utility/classhelpers.h"
51 struct gmx_mtop_t;
53 namespace gmx
56 class IOptionsContainer;
57 class Options;
58 class SelectionCollection;
60 /*! \brief
61 * Provides topology information to SelectionOptionBehavior.
63 * Modules that use SelectionOptionBehavior need to implement this interface
64 * to provide functionality to load topology information for use with the
65 * selections.
67 * If future need arises to use similar information elsewhere, this can be
68 * moved to, e.g., the topology module, but for now it is here for simplicity.
69 * Also, if/when there will be more modules that use this, we can identify
70 * common code from those users and possibly provide a shared implementation
71 * (e.g., in the form of another IOptionsBehavior), but currently there are too
72 * few users to identify any useful reusable functionality from the callers.
74 * \see SelectionCollection::setTopology().
76 * \inpublicapi
77 * \ingroup module_selection
79 class ITopologyProvider
81 public:
82 /*! \brief
83 * Returns the topology to use.
85 * \param[in] required Whether the topology is required by the caller.
87 * Can return NULL if \p required is `false` and the topology is not
88 * provided by the user.
89 * If \p required is `true`, should throw an error if the topology
90 * cannot be loaded.
92 * This method may get called multiple times, potentially with
93 * different values of \p required. Subsequent calls should just
94 * return the same topology that was loaded in the first call.
96 virtual gmx_mtop_t* getTopology(bool required) = 0;
97 /*! \brief
98 * Returns the number of atoms.
100 * This method is only called if getTopology() returns NULL.
101 * It should return the number of atoms that at most need to be
102 * selected by the selections.
104 virtual int getAtomCount() = 0;
106 protected:
107 virtual ~ITopologyProvider();
110 /*! \brief
111 * Options behavior to allow using SelectionOptions.
113 * This behavior wraps SelectionOptionManager, as well as all calls to
114 * SelectionCollection up to and including selection compilation.
116 * To use selections through SelectionOption options in a
117 * ICommandLineOptionsModule, you need to
118 * * create a SelectionCollection object,
119 * * implement ITopologyProvider to return the topology or number of atoms
120 * to be used with the selections,
121 * * create and add a SelectionOptionBehavior, and call initOptions() to add
122 * common options for selection control,
123 * * use SelectionOption options to specify the selections used, and
124 * * evaluate the selections when running the module for the desired sets of
125 * coordinates (see SelectionCollection::evaluate()).
127 * The SelectionOptionBehavior provides the following functionalities to the
128 * module:
129 * * Creates SelectionOptionManager and manages all calls to it.
130 * * Creates an option to provide an `ndx` file, and loads it when necessary.
131 * * Creates options to control general aspects of selections (see
132 * SelectionCollection::initOptions()), as well as a generic option to
133 * provide selections from a file.
134 * * After all options have been processed, provides an interactive
135 * command-line prompt for any missing selections.
136 * * Compiles the selections.
138 * The behavior needs to be added before any options are created.
140 * \inpublicapi
141 * \ingroup module_selection
143 class SelectionOptionBehavior : public IOptionsBehavior
145 public:
146 /*! \brief
147 * Creates a behavior to use selections.
149 * \param[in,out] selections Selection collection to use.
150 * \param[in] topologyProvider Callback to load/provide topology
151 * information to selections when required.
153 * The methods in \p topologyProvider are called after all options have
154 * been parsed and finished, so the caller can, e.g., load the topology
155 * from a file specified by a file option.
157 SelectionOptionBehavior(SelectionCollection* selections, ITopologyProvider* topologyProvider);
158 ~SelectionOptionBehavior() override;
160 /*! \brief
161 * Add common options for controlling selections.
163 * This method is separate from the constructor so that the caller can
164 * control the order of options better.
166 void initOptions(IOptionsContainer* options);
168 // From IOptionsBehavior
169 void initBehavior(Options* options) override;
170 void optionsFinishing(Options* /*options*/) override {}
171 void optionsFinished() override;
173 private:
174 class Impl;
176 PrivateImplPointer<Impl> impl_;
180 } // namespace gmx
182 #endif