Remove some typedefs.h dependencies
[alexxy/gromacs.git] / src / gromacs / selection / selmethod.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2009,2010,2011,2012,2013,2014, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*! \internal
36  * \page page_module_selection_custom Custom selection methods
37  *
38  * Custom selection methods are defined by creating a new instance of
39  * \c gmx_ana_selmethod_t and filling it with the necessary data for handling
40  * the selection.
41  * The structure contains callback pointers that define the actual behavior
42  * of the method.
43  * The following sections discuss how the structure should be filled and how
44  * to implement the callbacks.
45  *
46  *
47  * \section selmethods_define \c gmx_ana_selmethod_t data structure
48  *
49  * An example \c gmx_ana_selmethod_t definition could look like this:
50  *
51  * \code
52    gmx_ana_selmethod_t sm_example = {
53        "example", GROUP_VALUE, 0,
54        asize(sm_params_example), sm_params_example,
55        &init_data_example,
56         NULL,
57        &init_example,
58         NULL,
59        &free_data_example,
60        &init_frame_example,
61        &evaluate_example,
62         NULL,
63        {"example from POS_EXPR [cutoff REAL]", 0, NULL},
64    };
65  * \endcode
66  *
67  * The first value defines the name of the method.
68  * It is used mostly for informational purposes; the actual name(s) recognized
69  * by the selection parser are defined by the call to
70  * gmx_ana_selmethod_register() (see \ref selmethods_register).
71  *
72  * The second value defines the type of the value the method returns.
73  * Possible values are
74  *  - \ref NO_VALUE : This is allowed only for methods that have the flag
75  *    \ref SMETH_MODIFIER set (see \ref selmethods_modifiers).
76  *  - \ref INT_VALUE : The method returns one or more integer values.
77  *  - \ref REAL_VALUE : The method returns one or more floating-point values.
78  *  - \ref STR_VALUE : The method returns one or more strings.
79  *  - \ref POS_VALUE : The method returns one or more 3D vectors.
80  *  - \ref GROUP_VALUE : The method returns a single index group.
81  *
82  * The third value gives additional information about the method using
83  * a combination of flags.
84  * Possible flags are:
85  *  - \ref SMETH_REQTOP : If set, the topology information is always loaded
86  *    and the \p top pointer passed to the callbacks is guaranteed to be
87  *    non-NULL. Should be set if the method requires topology information
88  *    for evaluation.
89  *  - \ref SMETH_DYNAMIC : If set, the method can only be evaluated dynamically,
90  *    i.e., it requires data from the trajectory frame.
91  *  - \ref SMETH_MODIFIER : If set, the method is a selection modifier and
92  *    not an actual selection method.
93  *    For more details, see \ref selmethods_modifiers.
94  *
95  * There are two additional flags that specify the number of values the
96  * method returns. Only one of them can be set at a time.
97  * If neither is set, the default behavior is to evaluate a value for each
98  * input atom (except for \ref GROUP_VALUE methods, which always return a
99  * single group).
100  * Other behaviors can be specified with these flags:
101  *  - \ref SMETH_SINGLEVAL : If set, the method evaluates to a single value.
102  *    This is automatically set if the type is \ref GROUP_VALUE.
103  *  - \ref SMETH_VARNUMVAL : If set, the method evaluates to an arbitrary
104  *    number of values.
105  *    The number of values is determined based on the values given by the user
106  *    to the method parameters (see \ref selmethods_params).
107  *  .
108  * If either of these flags is specified (and the method type is not
109  * \ref GROUP_VALUE), the group passed to the evaluation callback should not
110  * be used as it can be NULL.
111  * Currently, the above flags only work (have been tested) for \ref POS_VALUE
112  * methods.
113  *
114  * There is one additional flag that can only be specified for \ref STR_VALUE
115  * methods: \ref SMETH_CHARVAL . It is meant for to ease implementation of
116  * methods that evaluate to strings consisting of single characters.
117  *
118  * The next two values determine the number of parameters and a pointer to
119  * the parameter array. The contents of the parameter array are described in
120  * \ref selmethods_params. If the method does not take parameters, the first
121  * value should be 0 and the second can be NULL.
122  * Currently, \ref STR_VALUE methods cannot take parameters, but this limitation
123  * should be easy to lift if required.
124  *
125  * These are followed by function callbacks that determine the
126  * actual behavior of the method. Any of these except the evaluation callback
127  * can be NULL (the evaluation callback can also be NULL if \ref NO_VALUE is
128  * specified for a selection modifier). However, the presence of parameters
129  * can require some of the callbacks to be implemented.
130  * The details are described in \ref selmethods_callbacks.
131  *
132  * Finally, there is a data structure that gives help texts for the method.
133  *
134  * The \c gmx_ana_selmethod_t variable should be declared as a global variable
135  * or it should be otherwise ensured that the structure is not freed: only a
136  * pointer to the structure is stored by the library.
137  *
138  *
139  * \section selmethods_params Defining parameters
140  *
141  * Parameters to selection methods are defined in a separate array of
142  * \c gmx_ana_selparam_t structures.
143  * The order of the parameters does not matter (except possibly for callback
144  * implementation), with one important exception:
145  * If the method evaluates to a \ref POS_VALUE, the first parameter should
146  * have \ref GROUP_VALUE and be the one that is used to calculate the
147  * positions.
148  *
149  * An example parameter definition:
150  * \code
151    static gmx_ana_selparam_t sm_params_example[] = {
152      {"cutoff", {REAL_VALUE, 1, {NULL}}, NULL, SPAR_OPTIONAL},
153      {"from",   {POS_VALUE, -1, {NULL}}, NULL, SPAR_DYNAMIC | SPAR_VARNUM},
154    };
155  * \endcode
156  *
157  * The first value gives the name of the parameter.
158  * The first parameter can have a NULL name, which means that the value should
159  * immediately follow the method name. This can be used to specify methods
160  * of the type 'within 5 of ...'.
161  *
162  * The second value specifies the type of the value that the parameter accepts.
163  * \ref NO_VALUE can be used to specify a boolean parameter, other possibilities
164  * are the same as for the selection method type.
165  *
166  * The third value gives the number of values that the parameter accepts.
167  * For boolean parameters (\ref NO_VALUE), it should be 0.
168  * For parameters with \ref SPAR_VARNUM of \ref SPAR_ATOMVAL, it should be set
169  * to -1 for consistency (it is not used).
170  * If \ref SPAR_RANGES is specified, it should be either 1 (to accept a single
171  * continuous range) or -1 (if combined with \ref SPAR_VARNUM).
172  * In all other cases, it should be a positive integer; in most cases, it
173  * should be 1.
174  *
175  * The nest two pointers should always be NULL (they should be initialized in
176  * the callbacks), except the first pointer in the case of \ref SPAR_ENUMVAL
177  * (see below).
178  *
179  * The final value gives additional information about the acceptable values
180  * for the parameter using a combination of flags.
181  * The possible flags are:
182  *  - \ref SPAR_OPTIONAL : If set, the user does not need to provide a value
183  *    for the parameter. If not set, an error is reported if the parameter
184  *    is not specified by the user.
185  *  - \ref SPAR_DYNAMIC : If set, the method can handle dynamic values for
186  *    the parameter, i.e., the value(s) can be given by an expression that
187  *    evaluates to different values for different frames.
188  *  - \ref SPAR_RANGES : Can be set only for \ref INT_VALUE and
189  *    \ref REAL_VALUE parameters,
190  *    and cannot be combined with \ref SPAR_DYNAMIC.
191  *    If set, the parameter accepts ranges of values.
192  *    The ranges are automatically sorted and compacted such that a minimum
193  *    amount of non-overlapping ranges are given for the method.
194  *  - \ref SPAR_VARNUM : If set, the parameter can have a variable number
195  *    of values. These can be provided by the user as a list of values, or
196  *    using a single \ref SMETH_VARNUMVAL (or a single \ref SMETH_SINGLEVAL)
197  *    method.
198  *  - \ref SPAR_ATOMVAL : If set, the parameter accepts either a single value
199  *    or an expression that evaluates to a value for each input atom.
200  *    The single input value is treated as if the same value was returned for
201  *    each atom.
202  *    Cannot be combined with \ref SPAR_RANGES or \ref SPAR_VARNUM.
203  *  - \ref SPAR_ENUMVAL : Can only be set for \ref STR_VALUE parameters that
204  *    take a single value, and cannot be combined with any other flag than
205  *    \ref SPAR_OPTIONAL. If set, the parameter only accepts one of predefined
206  *    string values. See \ref SPAR_ENUMVAL documentation for details on how
207  *    to specify the acceptable values.
208  *
209  *
210  * \section selmethods_callbacks Implementing callbacks
211  *
212  * There are eight differen callback functions that can be implemented for
213  * selection methods: sel_datafunc(), sel_posfunc(), sel_initfunc(),
214  * sel_outinitfunc(), sel_freefunc(), sel_framefunc(), and two update functions.
215  * They are in this order in the \c gmx_ana_selmethod_t data structure.
216  * In general, any of the callbacks can be NULL, but the presence of
217  * parameters or other callbacks imposes some restrictions:
218  *  - sel_datafunc() should be provided if the method takes parameters.
219  *  - sel_initfunc() should be provided if the method takes
220  *    any parameters with the \ref SPAR_VARNUM or \ref SPAR_ATOMVAL flags,
221  *    except if those parameters have a \ref POS_VALUE.
222  *  - sel_outinitfunc() should be provided for \ref POS_VALUE methods
223  *    and \ref SMETH_VARNUMVAL methods.
224  *  - sel_freefunc() should be provided if sel_datafunc() and/or
225  *    sel_initfunc() allocate any dynamic memory in addition to the data
226  *    structure itself (or allocates the data structure using some other means
227  *    than malloc()).
228  *  - sel_updatefunc_pos() only makes sense for methods with \ref SMETH_DYNAMIC
229  *    set.
230  *  - At least one update function should be provided unless the method type is
231  *    \ref NO_VALUE.
232  *
233  * The documentations for the function pointer types provide more information
234  * about how the callbacks should be implemented.
235  *
236  *
237  * \section selmethods_modifiers Selection modifiers
238  *
239  * Selection modifiers are a special kind of selection methods that can be
240  * appended to the end of a selection. They are specified by adding the
241  * \ref SMETH_MODIFIER flag to the \c gmx_ana_selmethod_t.
242  * They can have two different types:
243  *  - \ref POS_VALUE : These modifiers are given the final positions
244  *    as an input, and they can make modifications to the selection that are
245  *    not possible otherwise (e.g., permute the atoms).
246  *    The modifier should implement sel_updatefunc_pos() and also have
247  *    one NULL parameter in the beginning of the parameter list that takes
248  *    \ref POS_VALUE and is used to give the input positions.
249  *  - \ref NO_VALUE : These modifiers do not modify the final selection, but
250  *    can be used to implement per-selection options for analysis tools
251  *    or to control the default behavior of the selection engine
252  *    (currently, such a framework is not implemented, but should be easy to
253  *    implement if required).
254  *
255  * In addition to restricting the type of the method, selection modifiers
256  * do not allow the flags \ref SMETH_SINGLEVAL and \ref SMETH_VARNUMVAL
257  * (they would not make sense).
258  *
259  * Parameters and callbacks should be implemented as with normal selection
260  * method, but beware that very little of the functionality has been tested.
261  *
262  * \todo
263  * The modifier handling could be made more flexible and more generic;
264  * the current implementation does not allow many things which would be
265  * possible with slight changes in the internals of the library.
266  *
267  *
268  * \section selmethods_register Registering the method
269  *
270  * After defining the method with \c gmx_ana_selmethod_t, it should be
271  * registered with the selection engine.
272  * In analysis programs, this can be done by calling
273  * gmx_ana_selmethod_register().
274  * If adding the method to the library, you should add a pointer to the new
275  * method structure into the \c smtable_def array (in selmethod.cpp), and it is
276  * registered automatically.
277  * In both cases, gmx_ana_selmethod_register() does several checks on the
278  * structure and reports any errors or inconsistencies it finds.
279  */
280 /*! \internal \file
281  * \brief API for handling selection methods.
282  *
283  * There should be no need to use the data structures or call the
284  * functions in this file directly unless implementing a custom selection
285  * method.
286  *
287  * Instructions for implementing custom selection methods can be found
288  * on a separate page: \ref page_module_selection_custom
289  *
290  * \author Teemu Murtola <teemu.murtola@gmail.com>
291  * \ingroup module_selection
292  */
293 #ifndef GMX_SELECTION_SELMETHOD_H
294 #define GMX_SELECTION_SELMETHOD_H
295
296 #include "selparam.h"
297 #include "selvalue.h"
298
299 namespace gmx
300 {
301 class PositionCalculationCollection;
302 class SelectionParserSymbolTable;
303 } // namespace gmx
304
305 struct gmx_ana_index_t;
306 struct gmx_ana_pos_t;
307 struct gmx_ana_selcollection_t;
308 struct t_pbc;
309 struct t_topology;
310 struct t_trxframe;
311
312 /*! \name Selection method flags
313  * \anchor selmethod_flags
314  */
315 /*@{*/
316 /*! \brief
317  * If set, the method requires topology information.
318  */
319 #define SMETH_REQTOP     1
320 /*! \brief
321  * If set, the method can only be evaluated dynamically.
322  */
323 #define SMETH_DYNAMIC    2
324 /*! \brief
325  * If set, the method evaluates to a single value.
326  *
327  * The default is that the method evaluates to a value for each input atom.
328  * Cannot be combined with \ref SMETH_VARNUMVAL.
329  */
330 #define SMETH_SINGLEVAL  4
331 /*! \brief
332  * If set, the method evaluates to an arbitrary number of values.
333  *
334  * The default is that the method evaluates to a value for each input atom.
335  * Cannot be combined with \ref SMETH_SINGLEVAL or with \ref GROUP_VALUE.
336  */
337 #define SMETH_VARNUMVAL  8
338 /*! \brief
339  * If set, the method evaluates to single-character strings.
340  *
341  * This flag can only be set for \ref STR_VALUE methods. If it is set, the
342  * selection engine automatically allocates and frees the required strings.
343  * The evaluation function should store the character values as the first
344  * character in the strings in the output data structure and should not change
345  * the string pointers.
346  */
347 #define SMETH_CHARVAL    64
348 /*! \brief
349  * If set, the method is a selection modifier.
350  *
351  * The method type should be \ref GROUP_VALUE or \ref NO_VALUE .
352  * Cannot be combined with \ref SMETH_SINGLEVAL or \ref SMETH_VARNUMVAL .
353  */
354 #define SMETH_MODIFIER   256
355 /*@}*/
356
357 /*! \brief
358  * Allocates and initializes internal data and parameter values.
359  *
360  * \param[in]     npar  Number of parameters in \p param.
361  * \param[in,out] param Pointer to (a copy of) the method's
362  *   \c gmx_ana_selmethod_t::param.
363  * \returns       Pointer to method-specific data structure.
364  *   This pointer will be passed as the last parameter of all other function
365  *   calls.
366  * \throws        unspecified Any errors should be indicated by throwing an
367  *      exception.
368  *
369  * Should allocate and initialize any internal data required by the method.
370  * Should also initialize the value pointers (\c gmx_ana_selparam_t::val) in
371  * \p param to point to variables within the internal data structure,
372  * with the exception of parameters that specify the \ref SPAR_VARNUM or
373  * the \ref SPAR_ATOMVAL flag (these should be handled in sel_initfunc()).
374  * However, parameters with a position value should be initialized.
375  * It is also possible to initialize \ref SPAR_ENUMVAL statically outside
376  * this function (see \ref SPAR_ENUMVAL).
377  * The \c gmx_ana_selparam_t::nvalptr should also be initialized for
378  * non-position-valued parameters that have both \ref SPAR_VARNUM and
379  * \ref SPAR_DYNAMIC set (it can also be initialized for other parameters if
380  * desired, but the same information will be available through other means).
381  * For optional parameters, the default values can (and should) be initialized
382  * here, as the parameter values are not changed if the parameter is not
383  * provided.
384  *
385  * For boolean parameters (type equals \ref NO_VALUE), the default value
386  * should be set here. The user can override the value by giving the parameter
387  * either as 'NAME'/'noNAME', or as 'NAME on/off/yes/no'.
388  *
389  * If the method takes any parameters, this function must be provided.
390  */
391 typedef void *(*sel_datafunc)(int npar, gmx_ana_selparam_t *param);
392 /*! \brief
393  * Sets the position calculation collection for the method.
394  *
395  * \param[in]  pcc   Position calculation collection that the method should use
396  *   for position calculations.
397  * \param      data  Internal data structure from sel_datafunc().
398  *
399  * This function should be provided if the method uses the routines from
400  * poscalc.h for calculating positions.
401  * The pointer \p pcc should then be stored and used for initialization for
402  * any position calculation structures.
403  */
404 typedef void  (*sel_posfunc)(gmx::PositionCalculationCollection *pcc, void *data);
405 /*! \brief
406  * Does initialization based on topology and/or parameter values.
407  *
408  * \param[in]  top   Topology structure
409  *   (can be NULL if \ref SMETH_REQTOP is not set).
410  * \param[in]  npar  Number of parameters in \p param.
411  * \param[in]  param Pointer to (an initialized copy of) the method's
412  *   \c gmx_ana_selmethod_t::param.
413  * \param      data  Internal data structure from sel_datafunc().
414  * \returns    0 on success, a non-zero error code on failure.
415  *
416  * This function is called after the parameters have been processed:
417  * the values of the parameters are stored at the locations set in
418  * sel_datafunc().
419  * The flags \ref SPAR_DYNAMIC and \ref SPAR_ATOMVAL are cleared before
420  * calling the function if the value is static or single-valued, respectively.
421  * If a parameter had the \ref SPAR_VARNUM or \ref SPAR_ATOMVAL flag (and
422  * is not \ref POS_VALUE), a pointer to the memory allocated for the values is
423  * found in \c gmx_ana_selparam_t::val.
424  * The pointer should be stored by this function, otherwise the values
425  * cannot be accessed.
426  * For \ref SPAR_VARNUM parameters, the number of values can be accessed
427  * through \c gmx_ana_selparam_t::val. For parameters with \ref SPAR_DYNAMIC,
428  * the number is the maximum number of values (the actual number can be
429  * accessed in sel_framefunc() and in the update callback through the value
430  * pointed by \c gmx_ana_selparam_t::nvalptr).
431  * For \ref SPAR_ATOMVAL parameters, \c gmx_ana_selparam_t::val::nr is set to
432  * 1 if a single value was provided, otherwise it is set to the maximum number
433  * of values possibly passed to the method.
434  * The value pointed by \c gmx_ana_selparam_t::nvalptr always contains the same
435  * value as \c gmx_ana_selparam_t::val::nr.
436  *
437  * For dynamic \ref GROUP_VALUE parameters (\ref SPAR_DYNAMIC set), the value
438  * will be the largest possible selection that may occur during the
439  * evaluation. For other types of dynamic parameters, the values are
440  * undefined.
441  *
442  * If the method takes any parameters with the \ref SPAR_VARNUM or
443  * \ref SPAR_ATOMVAL flags, this function must be provided, except if these
444  * parameters all have \ref POS_VALUE.
445  *
446  * This function may be called multiple times for the same method if the
447  * method takes parameters with \ref SPAR_ATOMVAL set.
448  */
449 typedef void  (*sel_initfunc)(t_topology *top, int npar,
450                               gmx_ana_selparam_t *param, void *data);
451 /*! \brief
452  * Initializes output data structure.
453  *
454  * \param[in]     top   Topology structure
455  *   (can be NULL if \ref SMETH_REQTOP is not set).
456  * \param[in,out] out   Output data structure.
457  * \param[in]     data  Internal data structure from sel_datafunc().
458  * \returns       0 on success, an error code on error.
459  *
460  * This function is called immediately after sel_initfunc().
461  *
462  * If the method evaluates to a position (\ref POS_VALUE), this function
463  * should be provided, and it should initialize the \c gmx_ana_pos_t data
464  * structure pointed by \p out.p (the pointer is guaranteed to be non-NULL).
465  * The \p out.p->g pointer should be initialized to the group that is used
466  * to evaluate positions in sel_updatefunc() or sel_updatefunc_pos().
467  *
468  * The function should also be provided for non-position-valued
469  * \ref SMETH_VARNUMVAL methods. For these methods, it suffices to set the
470  * \p out->nr field to reflect the maximum number of values returned by the
471  * method.
472  *
473  * Currently, this function is not needed for other types of methods.
474  *
475  * This function may be called multiple times for the same method if the
476  * method takes parameters with \ref SPAR_ATOMVAL set.
477  */
478 typedef void  (*sel_outinitfunc)(t_topology *top, gmx_ana_selvalue_t *out,
479                                  void *data);
480 /*! \brief
481  * Frees the internal data.
482  *
483  * \param[in] data Internal data structure from sel_datafunc().
484  *
485  * This function should be provided if the internal data structure contains
486  * dynamically allocated data, and should free any such data.
487  * The data structure itself should also be freed.
488  * For convenience, if there is no dynamically allocated data within the
489  * structure and the structure is allocated using malloc()/snew(), this
490  * function is not needed: the selection engine automatically frees the
491  * structure using sfree().
492  * Any memory pointers received as values of parameters are managed externally,
493  * and should not be freed.
494  * Pointers set as the value pointer of \ref SPAR_ENUMVAL parameters should not
495  * be freed.
496  */
497 typedef void  (*sel_freefunc)(void *data);
498
499 /*! \brief
500  * Initializes the evaluation for a new frame.
501  *
502  * \param[in]  top  Topology structure
503  *   (can be NULL if \ref SMETH_REQTOP is not set).
504  * \param[in]  fr   Current frame.
505  * \param[in]  pbc  Initialized periodic boundary condition structure,
506  *   or NULL if PBC should not be used.
507  * \param      data Internal data structure from sel_datafunc().
508  * \returns    0 on success, a non-zero error code on failure.
509  *
510  * This function should be implemented if the selection method needs to
511  * do some preprocessing for each frame, and the preprocessing does not
512  * depend on the evaluation group.
513  * Because \p sel_updatefunc_* can be called more than once for a frame,
514  * it is inefficient do the preprocessing there.
515  * It is ensured that this function will be called before
516  * \p sel_updatefunc_* for each frame, and that it will be called at most
517  * once for each frame.
518  * For static methods, it is called once, with \p fr and \p pbc set to
519  * NULL.
520  */
521 typedef void  (*sel_framefunc)(t_topology *top, t_trxframe *fr, t_pbc *pbc,
522                                void *data);
523 /*! \brief
524  * Evaluates a selection method.
525  *
526  * \param[in]  top  Topology structure
527  *   (can be NULL if \ref SMETH_REQTOP is not set).
528  * \param[in]  fr   Current frame.
529  * \param[in]  pbc  Initialized periodic boundary condition structure,
530  *   or NULL if PBC should not be used.
531  * \param[in]  g    Index group for which the method should be evaluated.
532  * \param[out] out  Output data structure.
533  * \param      data Internal data structure from sel_datafunc().
534  * \returns    0 on success, a non-zero error code on error.
535  *
536  * This function should evaluate the method for each atom included in \p g,
537  * and write the output to \p out. The pointer in the union \p out->u that
538  * corresponds to the type of the method should be used.
539  * Enough memory has been allocated to store the output values.
540  * The number of values in \p out should also be updated if necessary.
541  * However, \ref POS_VALUE or \ref GROUP_VALUE methods should not touch
542  * \p out->nr (it should be 1 anyways).
543  *
544  * For \ref STR_VALUE methods, the pointers stored in \p out->s are discarded
545  * without freeing; it is the responsibility of this function to provide
546  * pointers that can be discarded without memory leaks.
547  */
548 typedef void  (*sel_updatefunc)(t_topology *top, t_trxframe *fr, t_pbc *pbc,
549                                 gmx_ana_index_t *g, gmx_ana_selvalue_t *out,
550                                 void *data);
551 /*! \brief
552  * Evaluates a selection method using positions.
553  *
554  * \param[in]  top  Topology structure
555  *   (can be NULL if \ref SMETH_REQTOP is not set).
556  * \param[in]  fr   Current frame.
557  * \param[in]  pbc  Initialized periodic boundary condition structure,
558  *   or NULL if PBC should not be used.
559  * \param[in]  pos  Positions for which the method should be evaluated.
560  * \param[out] out  Output data structure.
561  * \param      data Internal data structure from sel_datafunc().
562  * \returns    0 on success, a non-zero error code on error.
563  *
564  * This function should evaluate the method for each position in \p g,
565  * and write the output values to \p out. The pointer in the union \p out->u
566  * that corresponds to the type of the method should be used.
567  * Enough memory has been allocated to store the output values.
568  * The number of values in \p out should also be updated if necessary.
569  * However, \ref POS_VALUE or \ref GROUP_VALUE methods should not touch
570  * \p out->nr (it should be 1 anyways).
571  *
572  * For \ref STR_VALUE methods, the pointers stored in \p out->s are discarded
573  * without freeing; it is the responsibility of this function to provide
574  * pointers that can be discarded without memory leaks.
575  */
576 typedef void  (*sel_updatefunc_pos)(t_topology *top, t_trxframe *fr, t_pbc *pbc,
577                                     gmx_ana_pos_t *pos, gmx_ana_selvalue_t *out,
578                                     void *data);
579
580 /*! \internal
581  * \brief
582  * Help information for a selection method.
583  *
584  * If some information is not available, the corresponding field can be set to
585  * 0/NULL.
586  */
587 struct gmx_ana_selmethod_help_t
588 {
589     /*! \brief
590      * One-line description of the syntax of the method.
591      *
592      * If NULL, the name of the method is used.
593      */
594     const char         *syntax;
595     /*! \brief
596      * Number of strings in \p help.
597      *
598      * Set to 0 if \p help is NULL.
599      */
600     int                 nlhelp;
601     /*! \brief
602      * Detailed help for the method.
603      *
604      * If there is no help available in addition to \p syntax, this can be set
605      * to NULL.
606      */
607     const char        **help;
608 };
609
610 /*! \internal
611  * \brief
612  * Describes a selection method.
613  *
614  * Any of the function pointers except the update call can be NULL if the
615  * operation is not required or not supported. In this case,
616  * corresponding function calls are skipped.
617  *
618  * See the function pointer type documentation for details of how the
619  * functions should be implemented.
620  * More details on implementing new selection methods can be found on a
621  * separate page: \ref page_module_selection_custom.
622  */
623 struct gmx_ana_selmethod_t
624 {
625     /** Name of the method. */
626     const char         *name;
627     /** Type which the method returns. */
628     e_selvalue_t        type;
629     /*! \brief
630      * Flags to specify how the method should be handled.
631      *
632      * See \ref selmethod_flags for allowed values.
633      */
634     int                 flags;
635     /** Number of parameters the method takes. */
636     int                 nparams;
637     /** Pointer to the array of parameter descriptions. */
638     gmx_ana_selparam_t *param;
639
640     /** Function for allocating and initializing internal data and parameters. */
641     sel_datafunc        init_data;
642     /** Function to set the position calculation collection. */
643     sel_posfunc         set_poscoll;
644     /** Function to do initialization based on topology and/or parameter values. */
645     sel_initfunc        init;
646     /** Function to initialize output data structure. */
647     sel_outinitfunc     outinit;
648     /** Function to free the internal data. */
649     sel_freefunc        free;
650
651     /** Function to initialize the calculation for a new frame. */
652     sel_framefunc       init_frame;
653     /** Function to evaluate the value. */
654     sel_updatefunc      update;
655     /** Function to evaluate the value using positions. */
656     sel_updatefunc_pos  pupdate;
657
658     /** Help data for the method. */
659     gmx_ana_selmethod_help_t help;
660 };
661
662 /** Registers a selection method. */
663 int
664 gmx_ana_selmethod_register(gmx::SelectionParserSymbolTable *symtab,
665                            const char *name, gmx_ana_selmethod_t *method);
666 /** Registers all selection methods in the library. */
667 int
668 gmx_ana_selmethod_register_defaults(gmx::SelectionParserSymbolTable *symtab);
669
670 /** Finds a parameter from a selection method by name. */
671 gmx_ana_selparam_t *
672 gmx_ana_selmethod_find_param(const char *name, gmx_ana_selmethod_t *method);
673
674 #endif