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 private implementation class for gmx::SelectionCollection.
35 * This header also defines ::gmx_ana_selcollection_t, which is used in the old
36 * C code for handling selection collections.
38 * \author Teemu Murtola <teemu.murtola@cbr.su.se>
39 * \ingroup module_selection
41 #ifndef GMX_SELECTION_SELECTIONCOLLECTION_IMPL_H
42 #define GMX_SELECTION_SELECTIONCOLLECTION_IMPL_H
47 #include "../legacyheaders/typedefs.h"
49 #include "../onlinehelp/helptopicinterface.h"
50 #include "../utility/uniqueptr.h"
51 #include "indexutil.h"
53 #include "selection.h" // For gmx::SelectionList
54 #include "selectioncollection.h"
58 //! Smart pointer for managing an internal selection data object.
59 typedef gmx_unique_ptr<internal::SelectionData>::type SelectionDataPointer;
60 //! Container for storing a list of selections internally.
61 typedef std::vector<SelectionDataPointer> SelectionDataList;
65 * Information for a collection of selections.
67 * \ingroup module_selection
69 struct gmx_ana_selcollection_t
71 /** Root of the selection element tree. */
72 struct t_selelem *root;
74 * Array of compiled selections.
76 * Has the responsibility of managing the memory for the contained objects,
77 * but note that gmx::Selection instances also hold pointers to the
80 gmx::SelectionDataList sel;
81 /** Number of variables defined. */
83 /** Selection strings for variables. */
86 /** Topology for the collection. */
88 /** Index group that contains all the atoms. */
89 struct gmx_ana_index_t gall;
90 /** Position calculation collection used for selection position evaluation. */
91 gmx::PositionCalculationCollection pcc;
92 /** Memory pool used for selection evaluation. */
93 struct gmx_sel_mempool_t *mempool;
94 /** Parser symbol table. */
95 struct gmx_sel_symtab_t *symtab;
96 //! Root of help topic tree (NULL is no help yet requested).
97 gmx::HelpTopicPointer rootHelp;
103 class MessageStringCollector;
106 * Private implemention class for SelectionCollection.
108 * \ingroup module_selection
110 class SelectionCollection::Impl
114 * Creates a new selection collection.
116 * \throws std::bad_alloc if out of memory.
122 * Clears the symbol table of the selection collection.
126 void clearSymbolTable();
128 * Replace group references by group contents.
130 * \param[in] root Root of selection tree to process.
131 * \param errors Object for reporting any error messages.
133 * Recursively searches the selection tree for unresolved external
134 * references. If one is found, finds the referenced group in
135 * \a grps_ and replaces the reference with a constant element that
136 * contains the atoms from the referenced group. Any failures to
137 * resolve references are reported to \p errors.
139 * Does not throw currently, but this is subject to change when more
140 * underlying code is converted to C++.
142 void resolveExternalGroups(struct t_selelem *root,
143 MessageStringCollector *errors);
145 //! Internal data, used for interfacing with old C code.
146 gmx_ana_selcollection_t sc_;
147 //! Default reference position type for selections.
149 //! Default output position type for selections.
152 * Debugging level for the collection.
156 * - 1: print selection trees after parsing and compilation
157 * - 2: like 1, also print intermediate compilation trees
158 * - 3: like 1, also print the tree after evaluation
159 * - 4: combine 2 and 3
162 //! Whether setIndexGroups() has been called.
163 bool bExternalGroupsSet_;
164 //! External index groups (can be NULL).
165 gmx_ana_indexgrps_t *grps_;
169 * Implements selection evaluation.
171 * This class is used to implement SelectionCollection::evaluate() and
172 * SelectionCollection::evaluateFinal().
174 * \ingroup module_selection
176 class SelectionEvaluator
179 SelectionEvaluator();
182 * Evaluates selections in a collection.
184 void evaluate(SelectionCollection *sc, t_trxframe *fr, t_pbc *pbc);
186 * Evaluates the final state for dynamic selections.
188 void evaluateFinal(SelectionCollection *sc, int nframes);