Split lines with many copyright years
[alexxy/gromacs.git] / src / gromacs / selection / evaluate.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2009,2010,2011,2012,2013 by the GROMACS development team.
5  * Copyright (c) 2014,2016,2019,2020, 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.
9  *
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.
14  *
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.
19  *
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.
24  *
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.
32  *
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.
35  */
36 /*! \internal \file
37  * \brief Evaluation functions for sel_evalfunc().
38  *
39  * This is an implementation header: there should be no need to use it outside
40  * this directory.
41  * Users should only use SelectionCollection::evaluate() to evaluate
42  * selections.
43  *
44  * The functions defined in this header file are all the possible values
45  * for the gmx::SelectionTreeElement::evaluate field (in addition to NULL).
46  *
47  * \author Teemu Murtola <teemu.murtola@gmail.com>
48  * \ingroup module_selection
49  */
50 #ifndef GMX_SELECTION_EVALUATE_H
51 #define GMX_SELECTION_EVALUATE_H
52
53 #include "selelem.h"
54
55 struct gmx_ana_index_t;
56 struct gmx_mtop_t;
57 struct gmx_sel_mempool_t;
58 struct t_pbc;
59 struct t_trxframe;
60
61 /*! \internal \brief
62  * Data structure for passing information required during evaluation.
63  */
64 struct gmx_sel_evaluate_t
65 {
66     /** Memory pool for intermediate values. */
67     gmx_sel_mempool_t* mp;
68     /** Index group that contains all the atoms. */
69     gmx_ana_index_t* gall;
70     /** Topology information. */
71     const gmx_mtop_t* top;
72     /** Current frame. */
73     t_trxframe* fr;
74     /** PBC data. */
75     t_pbc* pbc;
76 };
77
78 /*! \name Utility functions
79  */
80 /*@{*/
81 /** Initializes an evaluation data structure. */
82 void _gmx_sel_evaluate_init(gmx_sel_evaluate_t* data,
83                             gmx_sel_mempool_t*  mp,
84                             gmx_ana_index_t*    gall,
85                             const gmx_mtop_t*   top,
86                             t_trxframe*         fr,
87                             t_pbc*              pbc);
88 /** Evaluates the children of a general selection element. */
89 void _gmx_sel_evaluate_children(gmx_sel_evaluate_t*                     data,
90                                 const gmx::SelectionTreeElementPointer& sel,
91                                 gmx_ana_index_t*                        g);
92 /** Evaluates the children of a \ref SEL_EXPRESSION element. */
93 void _gmx_sel_evaluate_method_params(gmx_sel_evaluate_t*                     data,
94                                      const gmx::SelectionTreeElementPointer& sel,
95                                      gmx_ana_index_t*                        g);
96 /*@}*/
97
98 /*! \name Misc. evaluation functions
99  */
100 /*@{*/
101 /*! \brief
102  * Evaluates a root selection element.
103  *
104  * \param[in] data Data for the current frame.
105  * \param[in] sel Selection element being evaluated.
106  * \param[in] g   Group for which \p sel should be evaluated
107  *   (not used, can be NULL).
108  * \returns   0 on success, a non-zero error code on error.
109  *
110  * Evaluates the first child element in the group defined by \p sel->u.cgrp.
111  * If \p sel->u.cgrp is empty, nothing is done.
112  * The value of \p sel is not touched (root elements do not evaluate to
113  * values).
114  *
115  * This function can be used as gmx::SelectionTreeElement::evaluate for
116  * \ref SEL_ROOT elements.
117  */
118 void _gmx_sel_evaluate_root(gmx_sel_evaluate_t*                     data,
119                             const gmx::SelectionTreeElementPointer& sel,
120                             gmx_ana_index_t*                        g);
121 /*! \brief
122  * Evaluates a static group selection element.
123  *
124  * \param[in] data Data for the current frame.
125  * \param[in] sel Selection element being evaluated.
126  * \param[in] g   Group for which \p sel should be evaluated.
127  * \returns   0 for success.
128  *
129  * Sets the value of \p sel to the intersection of \p g and \p sel->u.cgrp.
130  *
131  * This function can be used as gmx::SelectionTreeElement::evaluate for
132  * \ref SEL_CONST elements with value type \ref GROUP_VALUE.
133  */
134 void _gmx_sel_evaluate_static(gmx_sel_evaluate_t*                     data,
135                               const gmx::SelectionTreeElementPointer& sel,
136                               gmx_ana_index_t*                        g);
137 /** Evaluates an arithmetic expression element. */
138 void _gmx_sel_evaluate_arithmetic(gmx_sel_evaluate_t*                     data,
139                                   const gmx::SelectionTreeElementPointer& sel,
140                                   gmx_ana_index_t*                        g);
141 /*@}*/
142
143 /*! \name Subexpression evaluation functions
144  */
145 /*@{*/
146 /** Evaluates a subexpression when there is only one reference. */
147 void _gmx_sel_evaluate_subexpr_simple(gmx_sel_evaluate_t*                     data,
148                                       const gmx::SelectionTreeElementPointer& sel,
149                                       gmx_ana_index_t*                        g);
150 /** Evaluates a subexpression when the evaluation group is static. */
151 void _gmx_sel_evaluate_subexpr_staticeval(gmx_sel_evaluate_t*                     data,
152                                           const gmx::SelectionTreeElementPointer& sel,
153                                           gmx_ana_index_t*                        g);
154 /** Evaluates a subexpression. */
155 void _gmx_sel_evaluate_subexpr(gmx_sel_evaluate_t*                     data,
156                                const gmx::SelectionTreeElementPointer& sel,
157                                gmx_ana_index_t*                        g);
158 /** Evaluates a subexpression reference when there are no other references. */
159 void _gmx_sel_evaluate_subexprref_simple(gmx_sel_evaluate_t*                     data,
160                                          const gmx::SelectionTreeElementPointer& sel,
161                                          gmx_ana_index_t*                        g);
162 /** Evaluates a subexpression reference. */
163 void _gmx_sel_evaluate_subexprref(gmx_sel_evaluate_t*                     data,
164                                   const gmx::SelectionTreeElementPointer& sel,
165                                   gmx_ana_index_t*                        g);
166 /*@}*/
167
168 /*! \name Method evaluation functions
169  */
170 /*@{*/
171
172 /** Evaluates a method expression. */
173 void _gmx_sel_evaluate_method(gmx_sel_evaluate_t*                     data,
174                               const gmx::SelectionTreeElementPointer& sel,
175                               gmx_ana_index_t*                        g);
176 /** Evaluates a modifier expression. */
177 void _gmx_sel_evaluate_modifier(gmx_sel_evaluate_t*                     data,
178                                 const gmx::SelectionTreeElementPointer& sel,
179                                 gmx_ana_index_t*                        g);
180 /*@}*/
181
182 /*! \name Boolean evaluation functions
183  */
184 /*@{*/
185 /** Evaluates a boolean NOT element. */
186 void _gmx_sel_evaluate_not(gmx_sel_evaluate_t*                     data,
187                            const gmx::SelectionTreeElementPointer& sel,
188                            gmx_ana_index_t*                        g);
189 /** Evaluates a boolean AND element with short-circuiting. */
190 void _gmx_sel_evaluate_and(gmx_sel_evaluate_t*                     data,
191                            const gmx::SelectionTreeElementPointer& sel,
192                            gmx_ana_index_t*                        g);
193 /** Evaluates a boolean OR element with short-circuiting. */
194 void _gmx_sel_evaluate_or(gmx_sel_evaluate_t*                     data,
195                           const gmx::SelectionTreeElementPointer& sel,
196                           gmx_ana_index_t*                        g);
197 /*@}*/
198
199 #endif