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
32 * \brief Definition of \c t_selelem and related things.
34 * The selection element trees constructed by the parser and the compiler
35 * are described on the respective pages:
36 * \ref selparser and \ref selcompiler.
38 * This is an implementation header: there should be no need to use it outside
41 #ifndef SELECTION_ELEMENT_H
42 #define SELECTION_ELEMENT_H
44 #include <types/simple.h>
46 #include <indexutil.h>
49 struct gmx_ana_poscalc_t
;
50 struct gmx_ana_selparam_t
;
51 struct gmx_ana_selmethod_t
;
53 struct gmx_sel_evaluate_t
;
56 /********************************************************************/
57 /*! \name Enumerations for expression types
58 ********************************************************************/
61 /** Defines the type of a \c t_selelem object. */
64 /** Constant-valued expression. */
66 /** Method expression that requires evaluation. */
68 /** Boolean expression. */
70 /** Root node of the evaluation tree. */
72 /** Subexpression that may be referenced several times. */
74 /** Reference to a subexpression. */
76 /** Post-processing of selection value. */
80 /** Defines the boolean operation of \c t_selelem objects with type \ref SEL_BOOLEAN. */
86 BOOL_XOR
/**< Xor (not implemented). */
89 /** Returns a string representation of the type of a \c t_selelem. */
91 _gmx_selelem_type_str(struct t_selelem
*sel
);
92 /** Returns a string representation of the boolean type of a \ref SEL_BOOLEAN \c t_selelem. */
94 _gmx_selelem_boolean_type_str(struct t_selelem
*sel
);
95 /** Returns a string representation of the type of a \c gmx_ana_selvalue_t. */
97 _gmx_sel_value_type_str(gmx_ana_selvalue_t
*val
);
102 /********************************************************************/
103 /*! \name Selection expression flags
104 * \anchor selelem_flags
105 ********************************************************************/
108 * Selection value flags are set.
110 * If this flag is set, the flags covered by \ref SEL_VALFLAGMASK
111 * have been set properly for the element.
113 #define SEL_FLAGSSET 1
115 * The element evaluates to a single value.
117 * This flag is always set for \ref GROUP_VALUE elements.
119 #define SEL_SINGLEVAL 2
121 * The element evaluates to one value for each input atom.
123 #define SEL_ATOMVAL 4
125 * The element evaluates to an arbitrary number of values.
127 #define SEL_VARNUMVAL 8
129 * The element (or one of its children) is dynamic.
131 #define SEL_DYNAMIC 16
133 * Mask that covers the flags that describe the number of values.
135 #define SEL_VALTYPEMASK (SEL_SINGLEVAL | SEL_ATOMVAL | SEL_VARNUMVAL)
137 * Mask that covers the flags that describe the value type.
139 #define SEL_VALFLAGMASK (SEL_FLAGSSET | SEL_VALTYPEMASK | SEL_DYNAMIC)
141 * Data has been allocated for the \p v.u union.
143 * If not set, the \p v.u.ptr points to data allocated externally.
144 * This is the case if the value of the element is used as a parameter
145 * for a selection method or if the element evaluates the final value of
148 * Even if the flag is set, \p v.u.ptr can be NULL during initialization.
150 #define SEL_ALLOCVAL (1<<8)
152 * Data has been allocated for the group/position structure.
154 * If not set, the memory allocated for fields in \p v.u.g or \p v.u.p is
155 * managed externally.
157 * This field has no effect if the value type is not \ref GROUP_VALUE or
158 * \ref POS_VALUE, but should not be set.
160 #define SEL_ALLOCDATA (1<<9)
162 * \p method->init_frame should be called for the frame.
164 #define SEL_INITFRAME (1<<10)
166 * Parameter has been evaluated for the current frame.
168 * This flag is set for children of \ref SEL_EXPRESSION elements (which
169 * describe method parameters) after the element has been evaluated for the
171 * It is not set for \ref SEL_ATOMVAL elements, because they may need to
172 * be evaluated multiple times.
174 #define SEL_EVALFRAME (1<<11)
176 * \p method->init has been called.
178 #define SEL_METHODINIT (1<<12)
180 * \p method->outinit has been called.
182 * This flag is also used for \ref SEL_SUBEXPRREF elements.
184 #define SEL_OUTINIT (1<<13)
188 /********************************************************************/
189 /*! \name Selection expression data structures and functions
190 ********************************************************************/
196 * Function pointer for evaluating a \c t_selelem.
198 typedef int (*sel_evalfunc
)(struct gmx_sel_evaluate_t
*data
,
199 struct t_selelem
*sel
, gmx_ana_index_t
*g
);
202 * Represents an element of a selection expression.
204 typedef struct t_selelem
206 /*! \brief Name of the element.
208 * This field is only used for informative purposes.
209 * It is always either NULL or a pointer to a string.
210 * Memory is never allocated for it directly.
213 /** Type of the element. */
216 * Value storage of the element.
218 * This field contains the evaluated value of the element, as well as
219 * the output value type.
221 gmx_ana_selvalue_t v
;
223 * Evaluation function for the element.
225 * Can be either NULL (if the expression is a constant and does not require
226 * evaluation) or point to one of the functions defined in evaluate.h.
228 sel_evalfunc evaluate
;
230 * Information flags about the element.
232 * Allowed flags are listed here:
233 * \ref selelem_flags "flags for \c t_selelem".
236 /** Data required by the evaluation function. */
238 /*! \brief Index group data for several element types.
240 * - \ref SEL_CONST : if the value type is \ref GROUP_VALUE,
241 * this field holds the unprocessed group value.
242 * - \ref SEL_ROOT : holds the group value for which the
243 * selection subtree should be evaluated.
244 * - \ref SEL_SUBEXPR : holds the group for which the subexpression
245 * has been evaluated.
247 gmx_ana_index_t cgrp
;
248 /** Data for \ref SEL_EXPRESSION and \ref SEL_MODIFIER elements. */
250 /** Pointer the the method used in this expression. */
251 struct gmx_ana_selmethod_t
*method
;
252 /** Pointer to the data allocated by the method's \p init_data (see sel_datafunc()). */
254 /** Pointer to the position data passed to the method. */
255 struct gmx_ana_pos_t
*pos
;
256 /** Pointer to the evaluation data for \p pos. */
257 struct gmx_ana_poscalc_t
*pc
;
259 /** Operation type for \ref SEL_BOOLEAN elements. */
261 /** Associated selection parameter for \ref SEL_SUBEXPRREF elements. */
262 struct gmx_ana_selparam_t
*param
;
264 /** Internal data for the selection compiler. */
265 struct t_compiler_data
*cdata
;
267 /*! \brief The first child element.
269 * Other children can be accessed through the \p next field of \p child.
271 struct t_selelem
*child
;
272 /** The next sibling element. */
273 struct t_selelem
*next
;
274 /*! \brief Number of references to this element.
276 * Should be larger than one only for \ref SEL_SUBEXPR elements.
281 /** Allocates memory and performs some common initialization for a \c t_selelem. */
283 _gmx_selelem_create(e_selelem_t type
);
284 /** Sets the value type of a \c t_selelem. */
286 _gmx_selelem_set_vtype(t_selelem
*sel
, e_selvalue_t vtype
);
287 /** Frees the memory allocated for a \c t_selelem structure and all its children. */
289 _gmx_selelem_free(t_selelem
*sel
);
290 /** Frees the memory allocated for a \c t_selelem structure, all its children, and also all structures referenced through t_selelem::next fields. */
292 _gmx_selelem_free_chain(t_selelem
*first
);
294 /** Frees the memory allocated for the \c t_selelem::d union. */
296 _gmx_selelem_free_values(t_selelem
*sel
);
297 /** Frees the memory allocated for the \c t_selelem::u.expr field. */
299 _gmx_selelem_free_exprdata(t_selelem
*sel
);
301 /** Frees the memory allocated for the selection compiler. */
303 _gmx_selelem_free_compiler_data(t_selelem
*sel
);
305 /** Prints a human-readable version of a selection element subtree. */
307 _gmx_selelem_print_tree(FILE *fp
, t_selelem
*root
, bool bValues
, int level
);
309 /** Returns TRUE if the selection element subtree requires topology information for evaluation. */
311 _gmx_selelem_requires_top(t_selelem
*root
);
313 /* In sm_insolidangle.c */
314 /** Returns TRUE if the covered fraction of the selection can be calculated. */
316 _gmx_selelem_can_estimate_cover(t_selelem
*sel
);
317 /** Returns the covered fraction of the selection for the current frame. */
319 _gmx_selelem_estimate_coverfrac(t_selelem
*sel
);