Removed obsolete selection code.
[gromacs/qmmm-gamess-us.git] / src / gmxlib / selection / selelem.h
blobe49edbef72341c573e0a92e3efc2b2b184873e0a
1 /*
3 * This source code is part of
5 * G R O M A C S
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
31 /*! \internal \file
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
39 * this directory.
41 #ifndef SELECTION_ELEMENT_H
42 #define SELECTION_ELEMENT_H
44 #include <types/simple.h>
46 #include <indexutil.h>
47 #include <selvalue.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;
54 struct gmx_sel_mempool_t;
55 struct t_selelem;
57 /********************************************************************/
58 /*! \name Enumerations for expression types
59 ********************************************************************/
60 /*@{*/
62 /** Defines the type of a \c t_selelem object. */
63 typedef enum
65 /** Constant-valued expression. */
66 SEL_CONST,
67 /** Method expression that requires evaluation. */
68 SEL_EXPRESSION,
69 /** Boolean expression. */
70 SEL_BOOLEAN,
71 /** Arithmetic expression. */
72 SEL_ARITHMETIC,
73 /** Root node of the evaluation tree. */
74 SEL_ROOT,
75 /** Subexpression that may be referenced several times. */
76 SEL_SUBEXPR,
77 /** Reference to a subexpression. */
78 SEL_SUBEXPRREF,
79 /** Post-processing of selection value. */
80 SEL_MODIFIER
81 } e_selelem_t;
83 /** Defines the boolean operation of \c t_selelem objects with type \ref SEL_BOOLEAN. */
84 typedef enum
86 BOOL_NOT, /**< Not */
87 BOOL_AND, /**< And */
88 BOOL_OR, /**< Or */
89 BOOL_XOR /**< Xor (not implemented). */
90 } e_boolean_t;
92 /** Defines the arithmetic operation of \c t_selelem objects with type \ref SEL_ARITHMETIC. */
93 typedef enum
95 ARITH_PLUS, /**< + */
96 ARITH_MINUS, /**< - */
97 ARITH_NEG, /**< Unary - */
98 ARITH_MULT, /**< * */
99 ARITH_DIV, /**< / */
100 ARITH_EXP, /**< ^ (to power) */
101 } e_arithmetic_t;
103 /** Returns a string representation of the type of a \c t_selelem. */
104 extern const char *
105 _gmx_selelem_type_str(struct t_selelem *sel);
106 /** Returns a string representation of the boolean type of a \ref SEL_BOOLEAN \c t_selelem. */
107 extern const char *
108 _gmx_selelem_boolean_type_str(struct t_selelem *sel);
109 /** Returns a string representation of the type of a \c gmx_ana_selvalue_t. */
110 extern const char *
111 _gmx_sel_value_type_str(gmx_ana_selvalue_t *val);
113 /*@}*/
116 /********************************************************************/
117 /*! \name Selection expression flags
118 * \anchor selelem_flags
119 ********************************************************************/
120 /*@{*/
121 /*! \brief
122 * Selection value flags are set.
124 * If this flag is set, the flags covered by \ref SEL_VALFLAGMASK
125 * have been set properly for the element.
127 #define SEL_FLAGSSET 1
128 /*! \brief
129 * The element evaluates to a single value.
131 * This flag is always set for \ref GROUP_VALUE elements.
133 #define SEL_SINGLEVAL 2
134 /*! \brief
135 * The element evaluates to one value for each input atom.
137 #define SEL_ATOMVAL 4
138 /*! \brief
139 * The element evaluates to an arbitrary number of values.
141 #define SEL_VARNUMVAL 8
142 /*! \brief
143 * The element (or one of its children) is dynamic.
145 #define SEL_DYNAMIC 16
146 /*! \brief
147 * Mask that covers the flags that describe the number of values.
149 #define SEL_VALTYPEMASK (SEL_SINGLEVAL | SEL_ATOMVAL | SEL_VARNUMVAL)
150 /*! \brief
151 * Mask that covers the flags that describe the value type.
153 #define SEL_VALFLAGMASK (SEL_FLAGSSET | SEL_VALTYPEMASK | SEL_DYNAMIC)
154 /*! \brief
155 * Data has been allocated for the \p v.u union.
157 * If not set, the \p v.u.ptr points to data allocated externally.
158 * This is the case if the value of the element is used as a parameter
159 * for a selection method or if the element evaluates the final value of
160 * a selection.
162 * Even if the flag is set, \p v.u.ptr can be NULL during initialization.
164 * \todo
165 * This flag overlaps with the function of \p v.nalloc field, and could
166 * probably be removed, making memory management simpler. Currently, the
167 * \p v.nalloc field is not kept up-to-date in all cases when this flag
168 * is changed and is used in places where this flag is not, so this would
169 * require a careful investigation of the selection code.
171 #define SEL_ALLOCVAL (1<<8)
172 /*! \brief
173 * Data has been allocated for the group/position structure.
175 * If not set, the memory allocated for fields in \p v.u.g or \p v.u.p is
176 * managed externally.
178 * This field has no effect if the value type is not \ref GROUP_VALUE or
179 * \ref POS_VALUE, but should not be set.
181 #define SEL_ALLOCDATA (1<<9)
182 /*! \brief
183 * \p method->init_frame should be called for the frame.
185 #define SEL_INITFRAME (1<<10)
186 /*! \brief
187 * Parameter has been evaluated for the current frame.
189 * This flag is set for children of \ref SEL_EXPRESSION elements (which
190 * describe method parameters) after the element has been evaluated for the
191 * current frame.
192 * It is not set for \ref SEL_ATOMVAL elements, because they may need to
193 * be evaluated multiple times.
195 #define SEL_EVALFRAME (1<<11)
196 /*! \brief
197 * \p method->init has been called.
199 #define SEL_METHODINIT (1<<12)
200 /*! \brief
201 * \p method->outinit has been called.
203 * This flag is also used for \ref SEL_SUBEXPRREF elements.
205 #define SEL_OUTINIT (1<<13)
206 /*@}*/
209 /********************************************************************/
210 /*! \name Selection expression data structures and functions
211 ********************************************************************/
212 /*@{*/
214 struct t_selelem;
216 /*! \brief
217 * Function pointer for evaluating a \c t_selelem.
219 typedef int (*sel_evalfunc)(struct gmx_sel_evaluate_t *data,
220 struct t_selelem *sel, gmx_ana_index_t *g);
222 /*! \internal \brief
223 * Represents an element of a selection expression.
225 typedef struct t_selelem
227 /*! \brief Name of the element.
229 * This field is only used for informative purposes.
230 * It is always either NULL or a pointer to a string.
231 * Memory is never allocated for it directly.
233 const char *name;
234 /** Type of the element. */
235 e_selelem_t type;
236 /*! \brief
237 * Value storage of the element.
239 * This field contains the evaluated value of the element, as well as
240 * the output value type.
242 gmx_ana_selvalue_t v;
243 /*! \brief
244 * Evaluation function for the element.
246 * Can be either NULL (if the expression is a constant and does not require
247 * evaluation) or point to one of the functions defined in evaluate.h.
249 sel_evalfunc evaluate;
250 /*! \brief
251 * Information flags about the element.
253 * Allowed flags are listed here:
254 * \ref selelem_flags "flags for \c t_selelem".
256 int flags;
257 /** Data required by the evaluation function. */
258 union {
259 /*! \brief Index group data for several element types.
261 * - \ref SEL_CONST : if the value type is \ref GROUP_VALUE,
262 * this field holds the unprocessed group value.
263 * - \ref SEL_ROOT : holds the group value for which the
264 * selection subtree should be evaluated.
265 * - \ref SEL_SUBEXPR : holds the group for which the subexpression
266 * has been evaluated.
268 gmx_ana_index_t cgrp;
269 /** Data for \ref SEL_EXPRESSION and \ref SEL_MODIFIER elements. */
270 struct {
271 /** Pointer the the method used in this expression. */
272 struct gmx_ana_selmethod_t *method;
273 /** Pointer to the data allocated by the method's \p init_data (see sel_datafunc()). */
274 void *mdata;
275 /** Pointer to the position data passed to the method. */
276 struct gmx_ana_pos_t *pos;
277 /** Pointer to the evaluation data for \p pos. */
278 struct gmx_ana_poscalc_t *pc;
279 } expr;
280 /** Operation type for \ref SEL_BOOLEAN elements. */
281 e_boolean_t boolt;
282 /** Operation type for \ref SEL_ARITHMETIC elements. */
283 struct {
284 /** Operation type. */
285 e_arithmetic_t type;
286 /** String representation. */
287 char *opstr;
288 } arith;
289 /** Associated selection parameter for \ref SEL_SUBEXPRREF elements. */
290 struct gmx_ana_selparam_t *param;
291 } u;
292 /** Memory pool to use for values, or NULL if standard memory handling. */
293 struct gmx_sel_mempool_t *mempool;
294 /** Internal data for the selection compiler. */
295 struct t_compiler_data *cdata;
297 /*! \brief The first child element.
299 * Other children can be accessed through the \p next field of \p child.
301 struct t_selelem *child;
302 /** The next sibling element. */
303 struct t_selelem *next;
304 /*! \brief Number of references to this element.
306 * Should be larger than one only for \ref SEL_SUBEXPR elements.
308 int refcount;
309 } t_selelem;
311 /** Allocates memory and performs some common initialization for a \c t_selelem. */
312 extern t_selelem *
313 _gmx_selelem_create(e_selelem_t type);
314 /** Sets the value type of a \c t_selelem. */
315 extern int
316 _gmx_selelem_set_vtype(t_selelem *sel, e_selvalue_t vtype);
317 /** Reserves memory for value of a \c t_selelem from a memory pool. */
318 extern int
319 _gmx_selelem_mempool_reserve(t_selelem *sel, int count);
320 /** Releases memory pool used for value of a \c t_selelem. */
321 extern void
322 _gmx_selelem_mempool_release(t_selelem *sel);
323 /** Frees the memory allocated for a \c t_selelem structure and all its children. */
324 extern void
325 _gmx_selelem_free(t_selelem *sel);
326 /** Frees the memory allocated for a \c t_selelem structure, all its children, and also all structures referenced through t_selelem::next fields. */
327 extern void
328 _gmx_selelem_free_chain(t_selelem *first);
330 /** Frees the memory allocated for the \c t_selelem::d union. */
331 extern void
332 _gmx_selelem_free_values(t_selelem *sel);
333 /** Frees the memory allocated for a selection method. */
334 extern void
335 _gmx_selelem_free_method(struct gmx_ana_selmethod_t *method, void *mdata);
336 /** Frees the memory allocated for the \c t_selelem::u field. */
337 extern void
338 _gmx_selelem_free_exprdata(t_selelem *sel);
339 /* In compiler.c */
340 /** Frees the memory allocated for the selection compiler. */
341 extern void
342 _gmx_selelem_free_compiler_data(t_selelem *sel);
344 /** Prints a human-readable version of a selection element subtree. */
345 extern void
346 _gmx_selelem_print_tree(FILE *fp, t_selelem *root, bool bValues, int level);
348 /** Returns TRUE if the selection element subtree requires topology information for evaluation. */
349 extern bool
350 _gmx_selelem_requires_top(t_selelem *root);
352 /* In sm_insolidangle.c */
353 /** Returns TRUE if the covered fraction of the selection can be calculated. */
354 extern bool
355 _gmx_selelem_can_estimate_cover(t_selelem *sel);
356 /** Returns the covered fraction of the selection for the current frame. */
357 extern real
358 _gmx_selelem_estimate_coverfrac(t_selelem *sel);
360 /*@}*/
362 #endif