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 <boost/scoped_ptr.hpp>
49 #include "../legacyheaders/typedefs.h"
51 #include "../onlinehelp/helptopicinterface.h"
52 #include "../utility/uniqueptr.h"
53 #include "indexutil.h"
55 #include "selection.h" // For gmx::SelectionList
56 #include "selectioncollection.h"
62 //! Smart pointer for managing an internal selection data object.
63 typedef gmx_unique_ptr<internal::SelectionData>::type SelectionDataPointer;
64 //! Container for storing a list of selections internally.
65 typedef std::vector<SelectionDataPointer> SelectionDataList;
67 class SelectionParserSymbolTable;
72 * Information for a collection of selections.
74 * \ingroup module_selection
76 struct gmx_ana_selcollection_t
78 //! Position calculation collection used for selection position evaluation.
79 gmx::PositionCalculationCollection pcc;
80 //! Root of the selection element tree.
81 gmx::SelectionTreeElementPointer root;
83 * Array of compiled selections.
85 * Has the responsibility of managing the memory for the contained objects,
86 * but note that gmx::Selection instances also hold pointers to the
89 gmx::SelectionDataList sel;
90 /** Number of variables defined. */
92 /** Selection strings for variables. */
95 /** Topology for the collection. */
97 /** Index group that contains all the atoms. */
98 struct gmx_ana_index_t gall;
99 /** Memory pool used for selection evaluation. */
100 struct gmx_sel_mempool_t *mempool;
101 //! Parser symbol table.
102 boost::scoped_ptr<gmx::SelectionParserSymbolTable> symtab;
103 //! Root of help topic tree (NULL is no help yet requested).
104 gmx::HelpTopicPointer rootHelp;
110 class MessageStringCollector;
113 * Private implemention class for SelectionCollection.
115 * \ingroup module_selection
117 class SelectionCollection::Impl
121 * Creates a new selection collection.
123 * \throws std::bad_alloc if out of memory.
129 * Clears the symbol table of the selection collection.
133 void clearSymbolTable();
135 * Replace group references by group contents.
137 * \param[in] root Root of selection tree to process.
138 * \param errors Object for reporting any error messages.
140 * Recursively searches the selection tree for unresolved external
141 * references. If one is found, finds the referenced group in
142 * \a grps_ and replaces the reference with a constant element that
143 * contains the atoms from the referenced group. Any failures to
144 * resolve references are reported to \p errors.
146 * Does not throw currently, but this is subject to change when more
147 * underlying code is converted to C++.
149 void resolveExternalGroups(const gmx::SelectionTreeElementPointer &root,
150 MessageStringCollector *errors);
152 //! Internal data, used for interfacing with old C code.
153 gmx_ana_selcollection_t sc_;
154 //! Default reference position type for selections.
156 //! Default output position type for selections.
159 * Debugging level for the collection.
163 * - 1: print selection trees after parsing and compilation
164 * - 2: like 1, also print intermediate compilation trees
165 * - 3: like 1, also print the tree after evaluation
166 * - 4: combine 2 and 3
169 //! Whether setIndexGroups() has been called.
170 bool bExternalGroupsSet_;
171 //! External index groups (can be NULL).
172 gmx_ana_indexgrps_t *grps_;
176 * Implements selection evaluation.
178 * This class is used to implement SelectionCollection::evaluate() and
179 * SelectionCollection::evaluateFinal().
181 * \ingroup module_selection
183 class SelectionEvaluator
186 SelectionEvaluator();
189 * Evaluates selections in a collection.
191 void evaluate(SelectionCollection *sc, t_trxframe *fr, t_pbc *pbc);
193 * Evaluates the final state for dynamic selections.
195 void evaluateFinal(SelectionCollection *sc, int nframes);