2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2009-2016, The GROMACS development team.
5 * Copyright (c) 2019, by the GROMACS development team, led by
6 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7 * and including many others, as listed in the AUTHORS file in the
8 * top-level source directory and at http://www.gromacs.org.
10 * GROMACS is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation; either version 2.1
13 * of the License, or (at your option) any later version.
15 * GROMACS is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with GROMACS; if not, see
22 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
23 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * If you want to redistribute modifications to GROMACS, please
26 * consider that scientific software is very special. Version
27 * control is crucial - bugs must be traceable. We will be happy to
28 * consider code for inclusion in the official distribution, but
29 * derived work must not be called official GROMACS. Details are found
30 * in the README & COPYING files - if they are missing, get the
31 * official version at http://www.gromacs.org.
33 * To help us fund GROMACS development, we humbly ask that you cite
34 * the research papers on the package. Check out http://www.gromacs.org.
38 * Declares private implementation class for gmx::SelectionCollection.
40 * This header also defines ::gmx_ana_selcollection_t, which is used in the old
41 * C code for handling selection collections.
43 * \author Teemu Murtola <teemu.murtola@gmail.com>
44 * \ingroup module_selection
46 #ifndef GMX_SELECTION_SELECTIONCOLLECTION_IMPL_H
47 #define GMX_SELECTION_SELECTIONCOLLECTION_IMPL_H
53 #include "gromacs/onlinehelp/ihelptopic.h"
54 #include "gromacs/selection/indexutil.h"
55 #include "gromacs/selection/selection.h" // For gmx::SelectionList
56 #include "gromacs/selection/selectioncollection.h"
62 struct gmx_sel_mempool_t;
69 //! Smart pointer for managing an internal selection data object.
70 typedef std::unique_ptr<internal::SelectionData> SelectionDataPointer;
71 //! Container for storing a list of selections internally.
72 typedef std::vector<SelectionDataPointer> SelectionDataList;
74 class SelectionParserSymbolTable;
75 struct SelectionTopologyProperties;
80 * Information for a collection of selections.
82 * \ingroup module_selection
84 struct gmx_ana_selcollection_t
86 //! Position calculation collection used for selection position evaluation.
87 gmx::PositionCalculationCollection pcc;
88 //! Root of the selection element tree.
89 gmx::SelectionTreeElementPointer root;
91 * Array of compiled selections.
93 * Has the responsibility of managing the memory for the contained objects,
94 * but note that gmx::Selection instances also hold pointers to the
97 gmx::SelectionDataList sel;
98 /** Number of variables defined. */
100 /** Selection strings for variables. */
103 /** Topology for the collection. */
104 const gmx_mtop_t* top;
105 /** Index group that contains all the atoms. */
106 gmx_ana_index_t gall;
107 /** Memory pool used for selection evaluation. */
108 gmx_sel_mempool_t* mempool;
109 //! Parser symbol table.
110 // Never releases ownership.
111 std::unique_ptr<gmx::SelectionParserSymbolTable> symtab;
112 //! Root of help topic tree (NULL is no help yet requested).
113 gmx::HelpTopicPointer rootHelp;
119 class ExceptionInitializer;
122 * Private implemention class for SelectionCollection.
124 * \ingroup module_selection
126 class SelectionCollection::Impl
130 * Creates a new selection collection.
132 * \throws std::bad_alloc if out of memory.
138 * Clears the symbol table of the selection collection.
142 void clearSymbolTable();
144 * Replace group references by group contents.
146 * \param[in] root Root of selection tree to process.
147 * \param errors Object for reporting any error messages.
148 * \throws std::bad_alloc if out of memory.
150 * Recursively searches the selection tree for unresolved external
151 * references. If one is found, finds the referenced group in
152 * \a grps_ and replaces the reference with a constant element that
153 * contains the atoms from the referenced group. Any failures to
154 * resolve references are reported to \p errors.
156 void resolveExternalGroups(const gmx::SelectionTreeElementPointer& root, ExceptionInitializer* errors);
158 //! Whether forces have been requested for some selection.
159 bool areForcesRequested() const;
161 * Returns topology properties needed for a certain position type.
163 SelectionTopologyProperties requiredTopologyPropertiesForPositionType(const std::string& post,
166 //! Internal data, used for interfacing with old C code.
167 gmx_ana_selcollection_t sc_;
168 //! Default reference position type for selections.
170 //! Default output position type for selections.
172 //! Atoms needed for evaluating the selections.
173 gmx_ana_index_t requiredAtoms_;
175 * Debugging level for the collection.
179 * - 1: print selection trees after parsing and compilation
180 * - 2: like 1, also print intermediate compilation trees
181 * - 3: like 1, also print the tree after evaluation
182 * - 4: combine 2 and 3
185 //! Whether setIndexGroups() has been called.
186 bool bExternalGroupsSet_;
187 //! External index groups (can be NULL).
188 gmx_ana_indexgrps_t* grps_;
193 * Implements selection evaluation.
195 * This class is used to implement SelectionCollection::evaluate() and
196 * SelectionCollection::evaluateFinal().
198 * \ingroup module_selection
200 class SelectionEvaluator
203 SelectionEvaluator();
206 * Evaluates selections in a collection.
208 void evaluate(SelectionCollection* sc, t_trxframe* fr, t_pbc* pbc);
210 * Evaluates the final state for dynamic selections.
212 void evaluateFinal(SelectionCollection* sc, int nframes);