Merge remote-tracking branch 'origin/release-4-6' into HEAD
[alexxy/gromacs.git] / src / gromacs / selection / selectioncollection-impl.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 /*! \internal \file
32  * \brief
33  * Declares private implementation class for gmx::SelectionCollection.
34  *
35  * This header also defines ::gmx_ana_selcollection_t, which is used in the old
36  * C code for handling selection collections.
37  *
38  * \author Teemu Murtola <teemu.murtola@cbr.su.se>
39  * \ingroup module_selection
40  */
41 #ifndef GMX_SELECTION_SELECTIONCOLLECTION_IMPL_H
42 #define GMX_SELECTION_SELECTIONCOLLECTION_IMPL_H
43
44 #include <string>
45 #include <vector>
46
47 #include <boost/scoped_ptr.hpp>
48
49 #include "../legacyheaders/typedefs.h"
50
51 #include "../onlinehelp/helptopicinterface.h"
52 #include "../utility/uniqueptr.h"
53 #include "indexutil.h"
54 #include "poscalc.h"
55 #include "selection.h" // For gmx::SelectionList
56 #include "selectioncollection.h"
57 #include "selelem.h"
58
59 namespace gmx
60 {
61
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;
66
67 class SelectionParserSymbolTable;
68
69 } // namespace gmx
70
71 /*! \internal \brief
72  * Information for a collection of selections.
73  *
74  * \ingroup module_selection
75  */
76 struct gmx_ana_selcollection_t
77 {
78     //! Position calculation collection used for selection position evaluation.
79     gmx::PositionCalculationCollection  pcc;
80     //! Root of the selection element tree.
81     gmx::SelectionTreeElementPointer    root;
82     /*! \brief
83      * Array of compiled selections.
84      *
85      * Has the responsibility of managing the memory for the contained objects,
86      * but note that gmx::Selection instances also hold pointers to the
87      * objects.
88      */
89     gmx::SelectionDataList         sel;
90     /** Number of variables defined. */
91     int                            nvars;
92     /** Selection strings for variables. */
93     char                         **varstrs;
94
95     /** Topology for the collection. */
96     t_topology                    *top;
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;
105 };
106
107 namespace gmx
108 {
109
110 class MessageStringCollector;
111
112 /*! \internal \brief
113  * Private implemention class for SelectionCollection.
114  *
115  * \ingroup module_selection
116  */
117 class SelectionCollection::Impl
118 {
119     public:
120         /*! \brief
121          * Creates a new selection collection.
122          *
123          * \throws  std::bad_alloc if out of memory.
124          */
125         Impl();
126         ~Impl();
127
128         /*! \brief
129          * Clears the symbol table of the selection collection.
130          *
131          * Does not throw.
132          */
133         void clearSymbolTable();
134         /*! \brief
135          * Replace group references by group contents.
136          *
137          * \param[in]    root    Root of selection tree to process.
138          * \param        errors  Object for reporting any error messages.
139          *
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.
145          *
146          * Does not throw currently, but this is subject to change when more
147          * underlying code is converted to C++.
148          */
149         void resolveExternalGroups(const gmx::SelectionTreeElementPointer &root,
150                                    MessageStringCollector *errors);
151
152         //! Internal data, used for interfacing with old C code.
153         gmx_ana_selcollection_t sc_;
154         //! Default reference position type for selections.
155         std::string             rpost_;
156         //! Default output position type for selections.
157         std::string             spost_;
158         /*! \brief
159          * Debugging level for the collection.
160          *
161          * Possible values:
162          *  - 0: no debugging
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
167          */
168         int                     debugLevel_;
169         //! Whether setIndexGroups() has been called.
170         bool                    bExternalGroupsSet_;
171         //! External index groups (can be NULL).
172         gmx_ana_indexgrps_t    *grps_;
173 };
174
175 /*! \internal \brief
176  * Implements selection evaluation.
177  *
178  * This class is used to implement SelectionCollection::evaluate() and
179  * SelectionCollection::evaluateFinal().
180  *
181  * \ingroup module_selection
182  */
183 class SelectionEvaluator
184 {
185     public:
186         SelectionEvaluator();
187
188         /*! \brief
189          * Evaluates selections in a collection.
190          */
191         void evaluate(SelectionCollection *sc, t_trxframe *fr, t_pbc *pbc);
192         /*! \brief
193          * Evaluates the final state for dynamic selections.
194          */
195         void evaluateFinal(SelectionCollection *sc, int nframes);
196 };
197
198 } // namespace gmx
199
200 #endif