2 * This file is part of the GROMACS molecular simulation package.
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.
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.
37 * \brief Evaluation functions for sel_evalfunc().
39 * This is an implementation header: there should be no need to use it outside
41 * Users should only use SelectionCollection::evaluate() to evaluate
44 * The functions defined in this header file are all the possible values
45 * for the gmx::SelectionTreeElement::evaluate field (in addition to NULL).
47 * \author Teemu Murtola <teemu.murtola@gmail.com>
48 * \ingroup module_selection
50 #ifndef GMX_SELECTION_EVALUATE_H
51 #define GMX_SELECTION_EVALUATE_H
55 struct gmx_ana_index_t
;
57 struct gmx_sel_mempool_t
;
62 * Data structure for passing information required during evaluation.
64 struct gmx_sel_evaluate_t
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
;
78 /*! \name Utility functions
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
,
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
,
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
,
98 /*! \name Misc. evaluation functions
102 * Evaluates a root selection element.
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.
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
115 * This function can be used as gmx::SelectionTreeElement::evaluate for
116 * \ref SEL_ROOT elements.
118 void _gmx_sel_evaluate_root(gmx_sel_evaluate_t
* data
,
119 const gmx::SelectionTreeElementPointer
& sel
,
122 * Evaluates a static group selection element.
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.
129 * Sets the value of \p sel to the intersection of \p g and \p sel->u.cgrp.
131 * This function can be used as gmx::SelectionTreeElement::evaluate for
132 * \ref SEL_CONST elements with value type \ref GROUP_VALUE.
134 void _gmx_sel_evaluate_static(gmx_sel_evaluate_t
* data
,
135 const gmx::SelectionTreeElementPointer
& sel
,
137 /** Evaluates an arithmetic expression element. */
138 void _gmx_sel_evaluate_arithmetic(gmx_sel_evaluate_t
* data
,
139 const gmx::SelectionTreeElementPointer
& sel
,
143 /*! \name Subexpression evaluation functions
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
,
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
,
154 /** Evaluates a subexpression. */
155 void _gmx_sel_evaluate_subexpr(gmx_sel_evaluate_t
* data
,
156 const gmx::SelectionTreeElementPointer
& sel
,
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
,
162 /** Evaluates a subexpression reference. */
163 void _gmx_sel_evaluate_subexprref(gmx_sel_evaluate_t
* data
,
164 const gmx::SelectionTreeElementPointer
& sel
,
168 /*! \name Method evaluation functions
172 /** Evaluates a method expression. */
173 void _gmx_sel_evaluate_method(gmx_sel_evaluate_t
* data
,
174 const gmx::SelectionTreeElementPointer
& sel
,
176 /** Evaluates a modifier expression. */
177 void _gmx_sel_evaluate_modifier(gmx_sel_evaluate_t
* data
,
178 const gmx::SelectionTreeElementPointer
& sel
,
182 /*! \name Boolean evaluation functions
185 /** Evaluates a boolean NOT element. */
186 void _gmx_sel_evaluate_not(gmx_sel_evaluate_t
* data
,
187 const gmx::SelectionTreeElementPointer
& sel
,
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
,
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
,