2 * This file is part of the GROMACS molecular simulation package.
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.
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.
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.
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.
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.
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.
36 * \page page_module_selection_custom Custom selection methods
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
41 * The structure contains callback pointers that define the actual behavior
43 * The following sections discuss how the structure should be filled and how
44 * to implement the callbacks.
47 * \section selmethods_define \c gmx_ana_selmethod_t data structure
49 * An example \c gmx_ana_selmethod_t definition could look like this:
52 gmx_ana_selmethod_t sm_example = {
53 "example", GROUP_VALUE, 0,
54 asize(sm_params_example), sm_params_example,
63 {"example from POS_EXPR [cutoff REAL]", 0, NULL},
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).
72 * The second value defines the type of the value the method returns.
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.
82 * The third value gives additional information about the method using
83 * a combination of flags.
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
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 * - \ref SMETH_ALLOW_UNSORTED : If set, the method supports unsorted atoms
95 * in its input parameters. \ref SMETH_MODIFIER methods are assumed to always
96 * support unsorted atoms, as their purpose is to affect the ordering.
98 * There are two additional flags that specify the number of values the
99 * method returns. Only one of them can be set at a time.
100 * If neither is set, the default behavior is to evaluate a value for each
101 * input atom (except for \ref GROUP_VALUE methods, which always return a
103 * Other behaviors can be specified with these flags:
104 * - \ref SMETH_SINGLEVAL : If set, the method evaluates to a single value.
105 * This is automatically set if the type is \ref GROUP_VALUE.
106 * - \ref SMETH_VARNUMVAL : If set, the method evaluates to an arbitrary
108 * The number of values is determined based on the values given by the user
109 * to the method parameters (see \ref selmethods_params).
111 * If either of these flags is specified (and the method type is not
112 * \ref GROUP_VALUE), the group passed to the evaluation callback should not
113 * be used as it can be NULL.
114 * Currently, the above flags only work (have been tested) for \ref POS_VALUE
117 * There is one additional flag that can only be specified for \ref STR_VALUE
118 * methods: \ref SMETH_CHARVAL . It is meant for to ease implementation of
119 * methods that evaluate to strings consisting of single characters.
121 * The next two values determine the number of parameters and a pointer to
122 * the parameter array. The contents of the parameter array are described in
123 * \ref selmethods_params. If the method does not take parameters, the first
124 * value should be 0 and the second can be NULL.
125 * Currently, \ref STR_VALUE methods cannot take parameters, but this limitation
126 * should be easy to lift if required.
128 * These are followed by function callbacks that determine the
129 * actual behavior of the method. Any of these except the evaluation callback
130 * can be NULL (the evaluation callback can also be NULL if \ref NO_VALUE is
131 * specified for a selection modifier). However, the presence of parameters
132 * can require some of the callbacks to be implemented.
133 * The details are described in \ref selmethods_callbacks.
135 * Finally, there is a data structure that gives help texts for the method.
137 * The \c gmx_ana_selmethod_t variable should be declared as a global variable
138 * or it should be otherwise ensured that the structure is not freed: only a
139 * pointer to the structure is stored by the library.
142 * \section selmethods_params Defining parameters
144 * Parameters to selection methods are defined in a separate array of
145 * \c gmx_ana_selparam_t structures.
146 * The order of the parameters does not matter (except possibly for callback
147 * implementation), with one important exception:
148 * If the method evaluates to a \ref POS_VALUE, the first parameter should
149 * have \ref GROUP_VALUE and be the one that is used to calculate the
152 * An example parameter definition:
154 static gmx_ana_selparam_t sm_params_example[] = {
155 {"cutoff", {REAL_VALUE, 1, {NULL}}, NULL, SPAR_OPTIONAL},
156 {"from", {POS_VALUE, -1, {NULL}}, NULL, SPAR_DYNAMIC | SPAR_VARNUM},
160 * The first value gives the name of the parameter.
161 * The first parameter can have a NULL name, which means that the value should
162 * immediately follow the method name. This can be used to specify methods
163 * of the type 'within 5 of ...'.
165 * The second value specifies the type of the value that the parameter accepts.
166 * \ref NO_VALUE can be used to specify a boolean parameter, other possibilities
167 * are the same as for the selection method type.
169 * The third value gives the number of values that the parameter accepts.
170 * For boolean parameters (\ref NO_VALUE), it should be 0.
171 * For parameters with \ref SPAR_VARNUM of \ref SPAR_ATOMVAL, it should be set
172 * to -1 for consistency (it is not used).
173 * If \ref SPAR_RANGES is specified, it should be either 1 (to accept a single
174 * continuous range) or -1 (if combined with \ref SPAR_VARNUM).
175 * In all other cases, it should be a positive integer; in most cases, it
178 * The nest two pointers should always be NULL (they should be initialized in
179 * the callbacks), except the first pointer in the case of \ref SPAR_ENUMVAL
182 * The final value gives additional information about the acceptable values
183 * for the parameter using a combination of flags.
184 * The possible flags are:
185 * - \ref SPAR_OPTIONAL : If set, the user does not need to provide a value
186 * for the parameter. If not set, an error is reported if the parameter
187 * is not specified by the user.
188 * - \ref SPAR_DYNAMIC : If set, the method can handle dynamic values for
189 * the parameter, i.e., the value(s) can be given by an expression that
190 * evaluates to different values for different frames.
191 * - \ref SPAR_RANGES : Can be set only for \ref INT_VALUE and
192 * \ref REAL_VALUE parameters,
193 * and cannot be combined with \ref SPAR_DYNAMIC.
194 * If set, the parameter accepts ranges of values.
195 * The ranges are automatically sorted and compacted such that a minimum
196 * amount of non-overlapping ranges are given for the method.
197 * - \ref SPAR_VARNUM : If set, the parameter can have a variable number
198 * of values. These can be provided by the user as a list of values, or
199 * using a single \ref SMETH_VARNUMVAL (or a single \ref SMETH_SINGLEVAL)
201 * - \ref SPAR_ATOMVAL : If set, the parameter accepts either a single value
202 * or an expression that evaluates to a value for each input atom.
203 * The single input value is treated as if the same value was returned for
205 * Cannot be combined with \ref SPAR_RANGES or \ref SPAR_VARNUM.
206 * - \ref SPAR_ENUMVAL : Can only be set for \ref STR_VALUE parameters that
207 * take a single value, and cannot be combined with any other flag than
208 * \ref SPAR_OPTIONAL. If set, the parameter only accepts one of predefined
209 * string values. See \ref SPAR_ENUMVAL documentation for details on how
210 * to specify the acceptable values.
213 * \section selmethods_callbacks Implementing callbacks
215 * There are eight differen callback functions that can be implemented for
216 * selection methods: sel_datafunc(), sel_posfunc(), sel_initfunc(),
217 * sel_outinitfunc(), sel_freefunc(), sel_framefunc(), and two update functions.
218 * They are in this order in the \c gmx_ana_selmethod_t data structure.
219 * In general, any of the callbacks can be NULL, but the presence of
220 * parameters or other callbacks imposes some restrictions:
221 * - sel_datafunc() should be provided if the method takes parameters.
222 * - sel_initfunc() should be provided if the method takes
223 * any parameters with the \ref SPAR_VARNUM or \ref SPAR_ATOMVAL flags,
224 * except if those parameters have a \ref POS_VALUE.
225 * - sel_outinitfunc() should be provided for \ref POS_VALUE methods
226 * and \ref SMETH_VARNUMVAL methods.
227 * - sel_freefunc() should be provided if sel_datafunc() and/or
228 * sel_initfunc() allocate any dynamic memory in addition to the data
229 * structure itself (or allocates the data structure using some other means
231 * - sel_updatefunc_pos() only makes sense for methods with \ref SMETH_DYNAMIC
233 * - At least one update function should be provided unless the method type is
236 * The documentations for the function pointer types provide more information
237 * about how the callbacks should be implemented.
240 * \section selmethods_modifiers Selection modifiers
242 * Selection modifiers are a special kind of selection methods that can be
243 * appended to the end of a selection. They are specified by adding the
244 * \ref SMETH_MODIFIER flag to the \c gmx_ana_selmethod_t.
245 * They can have two different types:
246 * - \ref POS_VALUE : These modifiers are given the final positions
247 * as an input, and they can make modifications to the selection that are
248 * not possible otherwise (e.g., permute the atoms).
249 * The modifier should implement sel_updatefunc_pos() and also have
250 * one NULL parameter in the beginning of the parameter list that takes
251 * \ref POS_VALUE and is used to give the input positions.
252 * - \ref NO_VALUE : These modifiers do not modify the final selection, but
253 * can be used to implement per-selection options for analysis tools
254 * or to control the default behavior of the selection engine
255 * (currently, such a framework is not implemented, but should be easy to
256 * implement if required).
258 * In addition to restricting the type of the method, selection modifiers
259 * do not allow the flags \ref SMETH_SINGLEVAL and \ref SMETH_VARNUMVAL
260 * (they would not make sense).
262 * Parameters and callbacks should be implemented as with normal selection
263 * method, but beware that very little of the functionality has been tested.
266 * The modifier handling could be made more flexible and more generic;
267 * the current implementation does not allow many things which would be
268 * possible with slight changes in the internals of the library.
271 * \section selmethods_register Registering the method
273 * After defining the method with \c gmx_ana_selmethod_t, it should be
274 * registered with the selection engine.
275 * In analysis programs, this can be done by calling
276 * gmx_ana_selmethod_register().
277 * If adding the method to the library, you should add a pointer to the new
278 * method structure into the \c smtable_def array (in selmethod.cpp), and it is
279 * registered automatically.
280 * In both cases, gmx_ana_selmethod_register() does several checks on the
281 * structure and reports any errors or inconsistencies it finds.
284 * \brief API for handling selection methods.
286 * There should be no need to use the data structures or call the
287 * functions in this file directly unless implementing a custom selection
290 * Instructions for implementing custom selection methods can be found
291 * on a separate page: \ref page_module_selection_custom
293 * \author Teemu Murtola <teemu.murtola@gmail.com>
294 * \ingroup module_selection
296 #ifndef GMX_SELECTION_SELMETHOD_H
297 #define GMX_SELECTION_SELMETHOD_H
299 #include "../legacyheaders/typedefs.h"
301 #include "indexutil.h"
302 #include "selparam.h"
303 #include "selvalue.h"
307 class PositionCalculationCollection;
308 class SelectionParserSymbolTable;
311 struct gmx_ana_pos_t;
312 struct gmx_ana_selcollection_t;
314 /*! \name Selection method flags
315 * \anchor selmethod_flags
319 * If set, the method requires topology information.
321 #define SMETH_REQTOP 1
323 * If set, the method can only be evaluated dynamically.
325 #define SMETH_DYNAMIC 2
327 * If set, the method evaluates to a single value.
329 * The default is that the method evaluates to a value for each input atom.
330 * Cannot be combined with \ref SMETH_VARNUMVAL.
332 #define SMETH_SINGLEVAL 4
334 * If set, the method evaluates to an arbitrary number of values.
336 * The default is that the method evaluates to a value for each input atom.
337 * Cannot be combined with \ref SMETH_SINGLEVAL or with \ref GROUP_VALUE.
339 #define SMETH_VARNUMVAL 8
341 * If set, the method evaluates to single-character strings.
343 * This flag can only be set for \ref STR_VALUE methods. If it is set, the
344 * selection engine automatically allocates and frees the required strings.
345 * The evaluation function should store the character values as the first
346 * character in the strings in the output data structure and should not change
347 * the string pointers.
349 #define SMETH_CHARVAL 64
351 * If set, the method accepts unsorted atoms in its input parameters.
353 * Currently, the support for this functionality is fairly limited, and only
354 * static index group references can actually contain unsorted atoms.
355 * But to make this single case work, the position evaluation must support
356 * unsorted atoms as well.
358 #define SMETH_ALLOW_UNSORTED 128
360 * If set, the method is a selection modifier.
362 * The method type should be \ref GROUP_VALUE or \ref NO_VALUE .
363 * Cannot be combined with \ref SMETH_SINGLEVAL or \ref SMETH_VARNUMVAL .
365 #define SMETH_MODIFIER 256
369 * Allocates and initializes internal data and parameter values.
371 * \param[in] npar Number of parameters in \p param.
372 * \param[in,out] param Pointer to (a copy of) the method's
373 * \c gmx_ana_selmethod_t::param.
374 * \returns Pointer to method-specific data structure.
375 * This pointer will be passed as the last parameter of all other function
377 * \throws unspecified Any errors should be indicated by throwing an
380 * Should allocate and initialize any internal data required by the method.
381 * Should also initialize the value pointers (\c gmx_ana_selparam_t::val) in
382 * \p param to point to variables within the internal data structure,
383 * with the exception of parameters that specify the \ref SPAR_VARNUM or
384 * the \ref SPAR_ATOMVAL flag (these should be handled in sel_initfunc()).
385 * However, parameters with a position value should be initialized.
386 * It is also possible to initialize \ref SPAR_ENUMVAL statically outside
387 * this function (see \ref SPAR_ENUMVAL).
388 * The \c gmx_ana_selparam_t::nvalptr should also be initialized for
389 * non-position-valued parameters that have both \ref SPAR_VARNUM and
390 * \ref SPAR_DYNAMIC set (it can also be initialized for other parameters if
391 * desired, but the same information will be available through other means).
392 * For optional parameters, the default values can (and should) be initialized
393 * here, as the parameter values are not changed if the parameter is not
396 * For boolean parameters (type equals \ref NO_VALUE), the default value
397 * should be set here. The user can override the value by giving the parameter
398 * either as 'NAME'/'noNAME', or as 'NAME on/off/yes/no'.
400 * If the method takes any parameters, this function must be provided.
402 typedef void *(*sel_datafunc)(int npar, gmx_ana_selparam_t *param);
404 * Sets the position calculation collection for the method.
406 * \param[in] pcc Position calculation collection that the method should use
407 * for position calculations.
408 * \param data Internal data structure from sel_datafunc().
410 * This function should be provided if the method uses the routines from
411 * poscalc.h for calculating positions.
412 * The pointer \p pcc should then be stored and used for initialization for
413 * any position calculation structures.
415 typedef void (*sel_posfunc)(gmx::PositionCalculationCollection *pcc, void *data);
417 * Does initialization based on topology and/or parameter values.
419 * \param[in] top Topology structure
420 * (can be NULL if \ref SMETH_REQTOP is not set).
421 * \param[in] npar Number of parameters in \p param.
422 * \param[in] param Pointer to (an initialized copy of) the method's
423 * \c gmx_ana_selmethod_t::param.
424 * \param data Internal data structure from sel_datafunc().
425 * \returns 0 on success, a non-zero error code on failure.
427 * This function is called after the parameters have been processed:
428 * the values of the parameters are stored at the locations set in
430 * The flags \ref SPAR_DYNAMIC and \ref SPAR_ATOMVAL are cleared before
431 * calling the function if the value is static or single-valued, respectively.
432 * If a parameter had the \ref SPAR_VARNUM or \ref SPAR_ATOMVAL flag (and
433 * is not \ref POS_VALUE), a pointer to the memory allocated for the values is
434 * found in \c gmx_ana_selparam_t::val.
435 * The pointer should be stored by this function, otherwise the values
436 * cannot be accessed.
437 * For \ref SPAR_VARNUM parameters, the number of values can be accessed
438 * through \c gmx_ana_selparam_t::val. For parameters with \ref SPAR_DYNAMIC,
439 * the number is the maximum number of values (the actual number can be
440 * accessed in sel_framefunc() and in the update callback through the value
441 * pointed by \c gmx_ana_selparam_t::nvalptr).
442 * For \ref SPAR_ATOMVAL parameters, \c gmx_ana_selparam_t::val::nr is set to
443 * 1 if a single value was provided, otherwise it is set to the maximum number
444 * of values possibly passed to the method.
445 * The value pointed by \c gmx_ana_selparam_t::nvalptr always contains the same
446 * value as \c gmx_ana_selparam_t::val::nr.
448 * For dynamic \ref GROUP_VALUE parameters (\ref SPAR_DYNAMIC set), the value
449 * will be the largest possible selection that may occur during the
450 * evaluation. For other types of dynamic parameters, the values are
453 * If the method takes any parameters with the \ref SPAR_VARNUM or
454 * \ref SPAR_ATOMVAL flags, this function must be provided, except if these
455 * parameters all have \ref POS_VALUE.
457 * This function may be called multiple times for the same method if the
458 * method takes parameters with \ref SPAR_ATOMVAL set.
460 typedef void (*sel_initfunc)(t_topology *top, int npar,
461 gmx_ana_selparam_t *param, void *data);
463 * Initializes output data structure.
465 * \param[in] top Topology structure
466 * (can be NULL if \ref SMETH_REQTOP is not set).
467 * \param[in,out] out Output data structure.
468 * \param[in] data Internal data structure from sel_datafunc().
469 * \returns 0 on success, an error code on error.
471 * This function is called immediately after sel_initfunc().
473 * If the method evaluates to a position (\ref POS_VALUE), this function
474 * should be provided, and it should initialize the \c gmx_ana_pos_t data
475 * structure pointed by \p out.p (the pointer is guaranteed to be non-NULL).
476 * The \p out.p->g pointer should be initialized to the group that is used
477 * to evaluate positions in sel_updatefunc() or sel_updatefunc_pos().
479 * The function should also be provided for non-position-valued
480 * \ref SMETH_VARNUMVAL methods. For these methods, it suffices to set the
481 * \p out->nr field to reflect the maximum number of values returned by the
484 * Currently, this function is not needed for other types of methods.
486 * This function may be called multiple times for the same method if the
487 * method takes parameters with \ref SPAR_ATOMVAL set.
489 typedef void (*sel_outinitfunc)(t_topology *top, gmx_ana_selvalue_t *out,
492 * Frees the internal data.
494 * \param[in] data Internal data structure from sel_datafunc().
496 * This function should be provided if the internal data structure contains
497 * dynamically allocated data, and should free any such data.
498 * The data structure itself should also be freed.
499 * For convenience, if there is no dynamically allocated data within the
500 * structure and the structure is allocated using malloc()/snew(), this
501 * function is not needed: the selection engine automatically frees the
502 * structure using sfree().
503 * Any memory pointers received as values of parameters are managed externally,
504 * and should not be freed.
505 * Pointers set as the value pointer of \ref SPAR_ENUMVAL parameters should not
508 typedef void (*sel_freefunc)(void *data);
511 * Initializes the evaluation for a new frame.
513 * \param[in] top Topology structure
514 * (can be NULL if \ref SMETH_REQTOP is not set).
515 * \param[in] fr Current frame.
516 * \param[in] pbc Initialized periodic boundary condition structure,
517 * or NULL if PBC should not be used.
518 * \param data Internal data structure from sel_datafunc().
519 * \returns 0 on success, a non-zero error code on failure.
521 * This function should be implemented if the selection method needs to
522 * do some preprocessing for each frame, and the preprocessing does not
523 * depend on the evaluation group.
524 * Because \p sel_updatefunc_* can be called more than once for a frame,
525 * it is inefficient do the preprocessing there.
526 * It is ensured that this function will be called before
527 * \p sel_updatefunc_* for each frame, and that it will be called at most
528 * once for each frame.
529 * For static methods, it is called once, with \p fr and \p pbc set to
532 typedef void (*sel_framefunc)(t_topology *top, t_trxframe *fr, t_pbc *pbc,
535 * Evaluates a selection method.
537 * \param[in] top Topology structure
538 * (can be NULL if \ref SMETH_REQTOP is not set).
539 * \param[in] fr Current frame.
540 * \param[in] pbc Initialized periodic boundary condition structure,
541 * or NULL if PBC should not be used.
542 * \param[in] g Index group for which the method should be evaluated.
543 * \param[out] out Output data structure.
544 * \param data Internal data structure from sel_datafunc().
545 * \returns 0 on success, a non-zero error code on error.
547 * This function should evaluate the method for each atom included in \p g,
548 * and write the output to \p out. The pointer in the union \p out->u that
549 * corresponds to the type of the method should be used.
550 * Enough memory has been allocated to store the output values.
551 * The number of values in \p out should also be updated if necessary.
552 * However, \ref POS_VALUE or \ref GROUP_VALUE methods should not touch
553 * \p out->nr (it should be 1 anyways).
555 * For \ref STR_VALUE methods, the pointers stored in \p out->s are discarded
556 * without freeing; it is the responsibility of this function to provide
557 * pointers that can be discarded without memory leaks.
559 typedef void (*sel_updatefunc)(t_topology *top, t_trxframe *fr, t_pbc *pbc,
560 gmx_ana_index_t *g, gmx_ana_selvalue_t *out,
563 * Evaluates a selection method using positions.
565 * \param[in] top Topology structure
566 * (can be NULL if \ref SMETH_REQTOP is not set).
567 * \param[in] fr Current frame.
568 * \param[in] pbc Initialized periodic boundary condition structure,
569 * or NULL if PBC should not be used.
570 * \param[in] pos Positions for which the method should be evaluated.
571 * \param[out] out Output data structure.
572 * \param data Internal data structure from sel_datafunc().
573 * \returns 0 on success, a non-zero error code on error.
575 * This function should evaluate the method for each position in \p g,
576 * and write the output values to \p out. The pointer in the union \p out->u
577 * that corresponds to the type of the method should be used.
578 * Enough memory has been allocated to store the output values.
579 * The number of values in \p out should also be updated if necessary.
580 * However, \ref POS_VALUE or \ref GROUP_VALUE methods should not touch
581 * \p out->nr (it should be 1 anyways).
583 * For \ref STR_VALUE methods, the pointers stored in \p out->s are discarded
584 * without freeing; it is the responsibility of this function to provide
585 * pointers that can be discarded without memory leaks.
587 typedef void (*sel_updatefunc_pos)(t_topology *top, t_trxframe *fr, t_pbc *pbc,
588 struct gmx_ana_pos_t *pos,
589 gmx_ana_selvalue_t *out,
594 * Help information for a selection method.
596 * If some information is not available, the corresponding field can be set to
599 typedef struct gmx_ana_selmethod_help_t
602 * One-line description of the syntax of the method.
604 * If NULL, the name of the method is used.
608 * Number of strings in \p help.
610 * Set to 0 if \p help is NULL.
614 * Detailed help for the method.
616 * If there is no help available in addition to \p syntax, this can be set
620 } gmx_ana_selmethod_help_t;
624 * Describes a selection method.
626 * Any of the function pointers except the update call can be NULL if the
627 * operation is not required or not supported. In this case,
628 * corresponding function calls are skipped.
630 * See the function pointer type documentation for details of how the
631 * functions should be implemented.
632 * More details on implementing new selection methods can be found on a
633 * separate page: \ref page_module_selection_custom.
635 typedef struct gmx_ana_selmethod_t
637 /** Name of the method. */
639 /** Type which the method returns. */
642 * Flags to specify how the method should be handled.
644 * See \ref selmethod_flags for allowed values.
647 /** Number of parameters the method takes. */
649 /** Pointer to the array of parameter descriptions. */
650 gmx_ana_selparam_t *param;
652 /** Function for allocating and initializing internal data and parameters. */
653 sel_datafunc init_data;
654 /** Function to set the position calculation collection. */
655 sel_posfunc set_poscoll;
656 /** Function to do initialization based on topology and/or parameter values. */
658 /** Function to initialize output data structure. */
659 sel_outinitfunc outinit;
660 /** Function to free the internal data. */
663 /** Function to initialize the calculation for a new frame. */
664 sel_framefunc init_frame;
665 /** Function to evaluate the value. */
666 sel_updatefunc update;
667 /** Function to evaluate the value using positions. */
668 sel_updatefunc_pos pupdate;
670 /** Help data for the method. */
671 gmx_ana_selmethod_help_t help;
672 } gmx_ana_selmethod_t;
674 /** Registers a selection method. */
676 gmx_ana_selmethod_register(gmx::SelectionParserSymbolTable *symtab,
677 const char *name, gmx_ana_selmethod_t *method);
678 /** Registers all selection methods in the library. */
680 gmx_ana_selmethod_register_defaults(gmx::SelectionParserSymbolTable *symtab);
682 /** Finds a parameter from a selection method by name. */
684 gmx_ana_selmethod_find_param(const char *name, gmx_ana_selmethod_t *method);