Merge branch 'release-4-5-patches' of git.gromacs.org:gromacs into release-4-5-patches
[gromacs/rigid-bodies.git] / include / selmethod.h
blobf47dc3777072df3e0419e7b8adfb5ba71c95f50c
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 /*! \page selmethods Custom selection methods
33 * Custom selection methods are defined by creating a new instance of
34 * \c gmx_ana_selmethod_t and filling it with the necessary data for handling
35 * the selection.
36 * The structure contains callback pointers that define the actual behavior
37 * of the method.
38 * The following sections discuss how the structure should be filled and how
39 * to implement the callbacks.
42 * \section selmethods_define \c gmx_ana_selmethod_t data structure
44 * An example \c gmx_ana_selmethod_t definition could look like this:
46 * \code
47 * gmx_ana_selmethod_t sm_example = {
48 * "example", GROUP_VALUE, 0,
49 * asize(sm_params_example), sm_params_example,
50 * &init_data_example,
51 * NULL,
52 * &init_example,
53 * NULL,
54 * &free_data_example,
55 * &init_frame_example,
56 * &evaluate_example,
57 * NULL,
58 * {"example from POS_EXPR [cutoff REAL]", 0, NULL},
59 * };
60 * \endcode
62 * The first value defines the name of the method.
63 * It is used mostly for informational purposes; the actual name(s) recognized
64 * by the selection parser are defined by the call to
65 * gmx_ana_selmethod_register() (see \ref selmethods_register).
67 * The second value defines the type of the value the method returns.
68 * Possible values are
69 * - \ref NO_VALUE : This is allowed only for methods that have the flag
70 * \ref SMETH_MODIFIER set (see \ref selmethods_modifiers).
71 * - \ref INT_VALUE : The method returns one or more integer values.
72 * - \ref REAL_VALUE : The method returns one or more floating-point values.
73 * - \ref STR_VALUE : The method returns one or more strings.
74 * - \ref POS_VALUE : The method returns one or more 3D vectors.
75 * - \ref GROUP_VALUE : The method returns a single index group.
77 * The third value gives additional information about the method using
78 * a combination of flags.
79 * Possible flags are:
80 * - \ref SMETH_REQTOP : If set, the topology information is always loaded
81 * and the \p top pointer passed to the callbacks is guaranteed to be
82 * non-NULL. Should be set if the method requires topology information
83 * for evaluation.
84 * - \ref SMETH_DYNAMIC : If set, the method can only be evaluated dynamically,
85 * i.e., it requires data from the trajectory frame.
86 * - \ref SMETH_MODIFIER : If set, the method is a selection modifier and
87 * not an actual selection method.
88 * For more details, see \ref selmethods_modifiers.
90 * There are two additional flags that specify the number of values the
91 * method returns. Only one of them can be set at a time.
92 * If neither is set, the default behavior is to evaluate a value for each
93 * input atom (except for \ref GROUP_VALUE methods, which always return a
94 * single group).
95 * Other behaviors can be specified with these flags:
96 * - \ref SMETH_SINGLEVAL : If set, the method evaluates to a single value.
97 * This is automatically set if the type is \ref GROUP_VALUE.
98 * - \ref SMETH_VARNUMVAL : If set, the method evaluates to an arbitrary
99 * number of values.
100 * The number of values is determined based on the values given by the user
101 * to the method parameters (see \ref selmethods_params).
103 * If either of these flags is specified (and the method type is not
104 * \ref GROUP_VALUE), the group passed to the evaluation callback should not
105 * be used as it can be NULL.
106 * Currently, the above flags only work (have been tested) for \ref POS_VALUE
107 * methods.
109 * There is one additional flag that can only be specified for \ref STR_VALUE
110 * methods: \ref SMETH_CHARVAL . It is meant for to ease implementation of
111 * methods that evaluate to strings consisting of single characters.
113 * The next two values determine the number of parameters and a pointer to
114 * the parameter array. The contents of the parameter array are described in
115 * \ref selmethods_params. If the method does not take parameters, the first
116 * value should be 0 and the second can be NULL.
117 * Currently, \ref STR_VALUE methods cannot take parameters, but this limitation
118 * should be easy to lift if required.
120 * These are followed by function callbacks that determine the
121 * actual behavior of the method. Any of these except the evaluation callback
122 * can be NULL (the evaluation callback can also be NULL if \ref NO_VALUE is
123 * specified for a selection modifier). However, the presence of parameters
124 * can require some of the callbacks to be implemented.
125 * The details are described in \ref selmethods_callbacks.
127 * Finally, there is a data structure that gives help texts for the method.
129 * The \c gmx_ana_selmethod_t variable should be declared as a global variable
130 * or it should be otherwise ensured that the structure is not freed: only a
131 * pointer to the structure is stored by the library.
134 * \section selmethods_params Defining parameters
136 * Parameters to selection methods are defined in a separate array of
137 * \c gmx_ana_selparam_t structures.
138 * The order of the parameters does not matter (except possibly for callback
139 * implementation), with one important exception:
140 * If the method evaluates to a \ref POS_VALUE, the first parameter should
141 * have \ref GROUP_VALUE and be the one that is used to calculate the
142 * positions.
144 * An example parameter definition:
145 * \code
146 * static gmx_ana_selparam_t sm_params_example[] = {
147 * {"cutoff", {REAL_VALUE, 1, {NULL}}, NULL, SPAR_OPTIONAL},
148 * {"from", {POS_VALUE, -1, {NULL}}, NULL, SPAR_DYNAMIC | SPAR_VARNUM},
149 * };
150 * \endcode
152 * The first value gives the name of the parameter.
153 * The first parameter can have a NULL name, which means that the value should
154 * immediately follow the method name. This can be used to specify methods
155 * of the type 'within 5 of ...'.
157 * The second value specifies the type of the value that the parameter accepts.
158 * \ref NO_VALUE can be used to specify a boolean parameter, other possibilities
159 * are the same as for the selection method type.
161 * The third value gives the number of values that the parameter accepts.
162 * For boolean parameters (\ref NO_VALUE), it should be 0.
163 * For parameters with \ref SPAR_VARNUM of \ref SPAR_ATOMVAL, it should be set
164 * to -1 for consistency (it is not used).
165 * If \ref SPAR_RANGES is specified, it should be either 1 (to accept a single
166 * continuous range) or -1 (if combined with \ref SPAR_VARNUM).
167 * In all other cases, it should be a positive integer; in most cases, it
168 * should be 1.
170 * The nest two pointers should always be NULL (they should be initialized in
171 * the callbacks), except the first pointer in the case of \ref SPAR_ENUMVAL
172 * (see below).
174 * The final value gives additional information about the acceptable values
175 * for the parameter using a combination of flags.
176 * The possible flags are:
177 * - \ref SPAR_OPTIONAL : If set, the user does not need to provide a value
178 * for the parameter. If not set, an error is reported if the parameter
179 * is not specified by the user.
180 * - \ref SPAR_DYNAMIC : If set, the method can handle dynamic values for
181 * the parameter, i.e., the value(s) can be given by an expression that
182 * evaluates to different values for different frames.
183 * - \ref SPAR_RANGES : Can be set only for \ref INT_VALUE and
184 * \ref REAL_VALUE parameters,
185 * and cannot be combined with \ref SPAR_DYNAMIC.
186 * If set, the parameter accepts ranges of values.
187 * The ranges are automatically sorted and compacted such that a minimum
188 * amount of non-overlapping ranges are given for the method.
189 * - \ref SPAR_VARNUM : If set, the parameter can have a variable number
190 * of values. These can be provided by the user as a list of values, or
191 * using a single \ref SMETH_VARNUMVAL (or a single \ref SMETH_SINGLEVAL)
192 * method.
193 * - \ref SPAR_ATOMVAL : If set, the parameter accepts either a single value
194 * or an expression that evaluates to a value for each input atom.
195 * The single input value is treated as if the same value was returned for
196 * each atom.
197 * Cannot be combined with \ref SPAR_RANGES or \ref SPAR_VARNUM.
198 * - \ref SPAR_ENUMVAL : Can only be set for \ref STR_VALUE parameters that
199 * take a single value, and cannot be combined with any other flag than
200 * \ref SPAR_OPTIONAL. If set, the parameter only accepts one of predefined
201 * string values. See \ref SPAR_ENUMVAL documentation for details on how
202 * to specify the acceptable values.
205 * \section selmethods_callbacks Implementing callbacks
207 * There are eight differen callback functions that can be implemented for
208 * selection methods: sel_datafunc(), sel_posfunc(), sel_initfunc(),
209 * sel_outinitfunc(), sel_freefunc(), sel_framefunc(), and two update functions.
210 * They are in this order in the \c gmx_ana_selmethod_t data structure.
211 * In general, any of the callbacks can be NULL, but the presence of
212 * parameters or other callbacks imposes some restrictions:
213 * - sel_datafunc() should be provided if the method takes parameters.
214 * - sel_initfunc() should be provided if the method takes
215 * any parameters with the \ref SPAR_VARNUM or \ref SPAR_ATOMVAL flags,
216 * except if those parameters have a \ref POS_VALUE.
217 * - sel_outinitfunc() should be provided for \ref POS_VALUE methods
218 * and \ref SMETH_VARNUMVAL methods.
219 * - sel_freefunc() should be provided if sel_datafunc() and/or
220 * sel_initfunc() allocate any dynamic memory in addition to the data
221 * structure itself.
222 * - sel_updatefunc_pos() only makes sense for methods with \ref SMETH_DYNAMIC
223 * set.
224 * - At least one update function should be provided unless the method type is
225 * \ref NO_VALUE.
227 * The documentations for the function pointer types provide more information
228 * about how the callbacks should be implemented.
231 * \section selmethods_modifiers Selection modifiers
233 * Selection modifiers are a special kind of selection methods that can be
234 * appended to the end of a selection. They are specified by adding the
235 * \ref SMETH_MODIFIER flag to the \c gmx_ana_selmethod_t.
236 * They can have two different types:
237 * - \ref POS_VALUE : These modifiers are given the final positions
238 * as an input, and they can make modifications to the selection that are
239 * not possible otherwise (e.g., permute the atoms).
240 * The modifier should implement sel_updatefunc_pos() and also have
241 * one NULL parameter in the beginning of the parameter list that takes
242 * \ref POS_VALUE and is used to give the input positions.
243 * - \ref NO_VALUE : These modifiers do not modify the final selection, but
244 * can be used to implement per-selection options for analysis tools
245 * or to control the default behavior of the selection engine
246 * (currently, such a framework is not implemented, but should be easy to
247 * implement if required).
249 * In addition to restricting the type of the method, selection modifiers
250 * do not allow the flags \ref SMETH_SINGLEVAL and \ref SMETH_VARNUMVAL
251 * (they would not make sense).
253 * Parameters and callbacks should be implemented as with normal selection
254 * method, but beware that very little of the functionality has been tested.
256 * \todo
257 * The modifier handling could be made more flexible and more generic;
258 * the current implementation does not allow many things which would be
259 * possible with slight changes in the internals of the library.
262 * \section selmethods_register Registering the method
264 * After defining the method with \c gmx_ana_selmethod_t, it should be
265 * registered with the selection engine.
266 * In analysis programs, this can be done by calling
267 * gmx_ana_selmethod_register().
268 * If adding the method to the library, you should add a pointer to the new
269 * method structure into the \c smtable_def array (in \ref selmethod.c
270 * "selmethod.c"), and it is registered automatically.
271 * In both cases, gmx_ana_selmethod_register() does several checks on the
272 * structure and reports any errors or inconsistencies it finds.
274 /*! \file
275 * \brief API for handling selection methods.
277 * There should be no need to use the data structures or call the
278 * functions in this file directly unless implementing a custom selection
279 * method.
281 * Instructions for implementing custom selection methods can be found
282 * on a separate page: \ref selmethods
284 #ifndef SELMETHOD_H
285 #define SELMETHOD_H
287 #include "typedefs.h"
289 #include "indexutil.h"
290 #include "selparam.h"
291 #include "selvalue.h"
293 #ifdef __cplusplus
294 extern "C"
296 #endif
298 struct gmx_ana_pos_t;
299 struct gmx_ana_poscalc_coll_t;
300 struct gmx_ana_selcollection_t;
302 /*! \name Selection method flags
303 * \anchor selmethod_flags
305 /*@{*/
306 /*! \brief
307 * If set, the method requires topology information.
309 #define SMETH_REQTOP 1
310 /*! \brief
311 * If set, the method can only be evaluated dynamically.
313 #define SMETH_DYNAMIC 2
314 /*! \brief
315 * If set, the method evaluates to a single value.
317 * The default is that the method evaluates to a value for each input atom.
318 * Cannot be combined with \ref SMETH_VARNUMVAL.
320 #define SMETH_SINGLEVAL 4
321 /*! \brief
322 * If set, the method evaluates to an arbitrary number of values.
324 * The default is that the method evaluates to a value for each input atom.
325 * Cannot be combined with \ref SMETH_SINGLEVAL or with \ref GROUP_VALUE.
327 #define SMETH_VARNUMVAL 8
328 /*! \brief
329 * If set, the method evaluates to single-character strings.
331 * This flag can only be set for \ref STR_VALUE methods. If it is set, the
332 * selection engine automatically allocates and frees the required strings.
333 * The evaluation function should store the character values as the first
334 * character in the strings in the output data structure and should not change
335 * the string pointers.
337 #define SMETH_CHARVAL 64
338 /*! \brief
339 * If set, the method is a selection modifier.
341 * The method type should be \ref GROUP_VALUE or \ref NO_VALUE .
342 * Cannot be combined with \ref SMETH_SINGLEVAL or \ref SMETH_VARNUMVAL .
344 #define SMETH_MODIFIER 256
345 /*@}*/
347 /*! \brief
348 * Allocates and initializes internal data and parameter values.
350 * \param[in] npar Number of parameters in \p param.
351 * \param[in,out] param Pointer to (a copy of) the method's
352 * \c gmx_ana_selmethod_t::param.
353 * \returns Pointer to method-specific data structure.
354 * This pointer will be passed as the last parameter of all other function
355 * calls.
356 * Should return NULL on error (only error that should occur is out of
357 * memory).
359 * Should allocate and initialize any internal data required by the method.
360 * Should also initialize the value pointers (\c gmx_ana_selparam_t::val) in
361 * \p param to point to variables within the internal data structure,
362 * with the exception of parameters that specify the \ref SPAR_VARNUM or
363 * the \ref SPAR_ATOMVAL flag (these should be handled in sel_initfunc()).
364 * However, parameters with a position value should be initialized.
365 * It is also possible to initialize \ref SPAR_ENUMVAL statically outside
366 * this function (see \ref SPAR_ENUMVAL).
367 * The \c gmx_ana_selparam_t::nvalptr should also be initialized for
368 * non-position-valued parameters that have both \ref SPAR_VARNUM and
369 * \ref SPAR_DYNAMIC set (it can also be initialized for other parameters if
370 * desired, but the same information will be available through other means).
371 * For optional parameters, the default values can (and should) be initialized
372 * here, as the parameter values are not changed if the parameter is not
373 * provided.
375 * For boolean parameters (type equals \ref NO_VALUE), the default value
376 * should be set here. The user can override the value by giving the parameter
377 * either as 'NAME'/'noNAME', or as 'NAME on/off/yes/no'.
379 * If the method takes any parameters, this function must be provided.
381 typedef void *(*sel_datafunc)(int npar, gmx_ana_selparam_t *param);
382 /*! \brief
383 * Sets the position calculation collection for the method.
385 * \param[in] pcc Position calculation collection that the method should use
386 * for position calculations.
387 * \param data Internal data structure from sel_datafunc().
389 * This function should be provided if the method uses the routines from
390 * poscalc.h for calculating positions.
391 * The pointer \p pcc should then be stored and used for initialization for
392 * any position calculation structures.
394 typedef void (*sel_posfunc)(struct gmx_ana_poscalc_coll_t *pcc, void *data);
395 /*! \brief
396 * Does initialization based on topology and/or parameter values.
398 * \param[in] top Topology structure
399 * (can be NULL if \ref SMETH_REQTOP is not set).
400 * \param[in] npar Number of parameters in \p param.
401 * \param[in] param Pointer to (an initialized copy of) the method's
402 * \c gmx_ana_selmethod_t::param.
403 * \param data Internal data structure from sel_datafunc().
404 * \returns 0 on success, a non-zero error code on failure.
406 * This function is called after the parameters have been processed:
407 * the values of the parameters are stored at the locations set in
408 * sel_datafunc().
409 * The flags \ref SPAR_DYNAMIC and \ref SPAR_ATOMVAL are cleared before
410 * calling the function if the value is static or single-valued, respectively.
411 * If a parameter had the \ref SPAR_VARNUM or \ref SPAR_ATOMVAL flag (and
412 * is not \ref POS_VALUE), a pointer to the memory allocated for the values is
413 * found in \c gmx_ana_selparam_t::val.
414 * The pointer should be stored by this function, otherwise the values
415 * cannot be accessed.
416 * For \ref SPAR_VARNUM parameters, the number of values can be accessed
417 * through \c gmx_ana_selparam_t::val. For parameters with \ref SPAR_DYNAMIC,
418 * the number is the maximum number of values (the actual number can be
419 * accessed in sel_framefunc() and in the update callback through the value
420 * pointed by \c gmx_ana_selparam_t::nvalptr).
421 * For \ref SPAR_ATOMVAL parameters, \c gmx_ana_selparam_t::val::nr is set to
422 * 1 if a single value was provided, otherwise it is set to the maximum number
423 * of values possibly passed to the method.
424 * The value pointed by \c gmx_ana_selparam_t::nvalptr always contains the same
425 * value as \c gmx_ana_selparam_t::val::nr.
427 * For dynamic \ref GROUP_VALUE parameters (\ref SPAR_DYNAMIC set), the value
428 * will be the largest possible selection that may occur during the
429 * evaluation. For other types of dynamic parameters, the values are
430 * undefined.
432 * If the method takes any parameters with the \ref SPAR_VARNUM or
433 * \ref SPAR_ATOMVAL flags, this function must be provided, except if these
434 * parameters all have \ref POS_VALUE.
436 * This function may be called multiple times for the same method if the
437 * method takes parameters with \ref SPAR_ATOMVAL set.
439 typedef int (*sel_initfunc)(t_topology *top, int npar,
440 gmx_ana_selparam_t *param, void *data);
441 /*! \brief
442 * Initializes output data structure.
444 * \param[in] top Topology structure
445 * (can be NULL if \ref SMETH_REQTOP is not set).
446 * \param[in,out] out Output data structure.
447 * \param[in] data Internal data structure from sel_datafunc().
448 * \returns 0 on success, an error code on error.
450 * This function is called immediately after sel_initfunc().
452 * If the method evaluates to a position (\ref POS_VALUE), this function
453 * should be provided, and it should initialize the \c gmx_ana_pos_t data
454 * structure pointed by \p out.p (the pointer is guaranteed to be non-NULL).
455 * The \p out.p->g pointer should be initialized to the group that is used
456 * to evaluate positions in sel_updatefunc() or sel_updatefunc_pos().
458 * The function should also be provided for non-position-valued
459 * \ref SMETH_VARNUMVAL methods. For these methods, it suffices to set the
460 * \p out->nr field to reflect the maximum number of values returned by the
461 * method.
463 * Currently, this function is not needed for other types of methods.
465 * This function may be called multiple times for the same method if the
466 * method takes parameters with \ref SPAR_ATOMVAL set.
468 typedef int (*sel_outinitfunc)(t_topology *top, gmx_ana_selvalue_t *out,
469 void *data);
470 /*! \brief
471 * Frees the internal data.
473 * \param[in] data Internal data structure from sel_datafunc().
475 * This function should be provided if the internal data structure contains
476 * dynamically allocated data, and should free any such data.
477 * The data structure itself should not be freed; this is handled automatically.
478 * If there is no dynamically allocated data within the structure,
479 * this function is not needed.
480 * Any memory pointers received as values of parameters are managed externally,
481 * and should not be freed.
482 * Pointers set as the value pointer of \ref SPAR_ENUMVAL parameters should not
483 * be freed.
485 typedef void (*sel_freefunc)(void *data);
487 /*! \brief
488 * Initializes the evaluation for a new frame.
490 * \param[in] top Topology structure
491 * (can be NULL if \ref SMETH_REQTOP is not set).
492 * \param[in] fr Current frame.
493 * \param[in] pbc Initialized periodic boundary condition structure,
494 * or NULL if PBC should not be used.
495 * \param data Internal data structure from sel_datafunc().
496 * \returns 0 on success, a non-zero error code on failure.
498 * This function should be implemented if the selection method needs to
499 * do some preprocessing for each frame, and the preprocessing does not
500 * depend on the evaluation group.
501 * Because \p sel_updatefunc_* can be called more than once for a frame,
502 * it is inefficient do the preprocessing there.
503 * It is ensured that this function will be called before
504 * \p sel_updatefunc_* for each frame, and that it will be called at most
505 * once for each frame.
506 * For static methods, it is called once, with \p fr and \p pbc set to
507 * NULL.
509 typedef int (*sel_framefunc)(t_topology *top, t_trxframe *fr, t_pbc *pbc,
510 void *data);
511 /*! \brief
512 * Evaluates a selection method.
514 * \param[in] top Topology structure
515 * (can be NULL if \ref SMETH_REQTOP is not set).
516 * \param[in] fr Current frame.
517 * \param[in] pbc Initialized periodic boundary condition structure,
518 * or NULL if PBC should not be used.
519 * \param[in] g Index group for which the method should be evaluated.
520 * \param[out] out Output data structure.
521 * \param data Internal data structure from sel_datafunc().
522 * \returns 0 on success, a non-zero error code on error.
524 * This function should evaluate the method for each atom included in \p g,
525 * and write the output to \p out. The pointer in the union \p out->u that
526 * corresponds to the type of the method should be used.
527 * Enough memory has been allocated to store the output values.
528 * The number of values in \p out should also be updated if necessary.
529 * However, \ref POS_VALUE or \ref GROUP_VALUE methods should not touch
530 * \p out->nr (it should be 1 anyways).
532 * For \ref STR_VALUE methods, the pointers stored in \p out->s are discarded
533 * without freeing; it is the responsibility of this function to provide
534 * pointers that can be discarded without memory leaks.
536 typedef int (*sel_updatefunc)(t_topology *top, t_trxframe *fr, t_pbc *pbc,
537 gmx_ana_index_t *g, gmx_ana_selvalue_t *out,
538 void *data);
539 /*! \brief
540 * Evaluates a selection method using positions.
542 * \param[in] top Topology structure
543 * (can be NULL if \ref SMETH_REQTOP is not set).
544 * \param[in] fr Current frame.
545 * \param[in] pbc Initialized periodic boundary condition structure,
546 * or NULL if PBC should not be used.
547 * \param[in] pos Positions for which the method should be evaluated.
548 * \param[out] out Output data structure.
549 * \param data Internal data structure from sel_datafunc().
550 * \returns 0 on success, a non-zero error code on error.
552 * This function should evaluate the method for each position in \p g,
553 * and write the output values to \p out. The pointer in the union \p out->u
554 * that corresponds to the type of the method should be used.
555 * Enough memory has been allocated to store the output values.
556 * The number of values in \p out should also be updated if necessary.
557 * However, \ref POS_VALUE or \ref GROUP_VALUE methods should not touch
558 * \p out->nr (it should be 1 anyways).
560 * For \ref STR_VALUE methods, the pointers stored in \p out->s are discarded
561 * without freeing; it is the responsibility of this function to provide
562 * pointers that can be discarded without memory leaks.
564 typedef int (*sel_updatefunc_pos)(t_topology *top, t_trxframe *fr, t_pbc *pbc,
565 struct gmx_ana_pos_t *pos,
566 gmx_ana_selvalue_t *out,
567 void *data);
569 /*! \brief
570 * Help information for a selection method.
572 * If some information is not available, the corresponding field can be set to
573 * 0/NULL.
575 typedef struct gmx_ana_selmethod_help_t
577 /*! \brief
578 * One-line description of the syntax of the method.
580 * If NULL, the name of the method is used.
582 const char *syntax;
583 /*! \brief
584 * Number of strings in \p help.
586 * Set to 0 if \p help is NULL.
588 int nlhelp;
589 /*! \brief
590 * Detailed help for the method.
592 * If there is no help available in addition to \p syntax, this can be set
593 * to NULL.
595 const char **help;
596 } gmx_ana_selmethod_help_t;
598 /*! \brief
599 * Describes a selection method.
601 * Any of the function pointers except the update call can be NULL if the
602 * operation is not required or not supported. In this case,
603 * corresponding function calls are skipped.
605 * See the function pointer type documentation for details of how the
606 * functions should be implemented.
607 * More details on implementing new selection methods can be found on a
608 * separate page: \ref selmethods.
610 typedef struct gmx_ana_selmethod_t
612 /** Name of the method. */
613 const char *name;
614 /** Type which the method returns. */
615 e_selvalue_t type;
616 /*! \brief
617 * Flags to specify how the method should be handled.
619 * See \ref selmethod_flags for allowed values.
621 int flags;
622 /** Number of parameters the method takes. */
623 int nparams;
624 /** Pointer to the array of parameter descriptions. */
625 gmx_ana_selparam_t *param;
627 /** Function for allocating and initializing internal data and parameters. */
628 sel_datafunc init_data;
629 /** Function to set the position calculation collection. */
630 sel_posfunc set_poscoll;
631 /** Function to do initialization based on topology and/or parameter values. */
632 sel_initfunc init;
633 /** Function to initialize output data structure. */
634 sel_outinitfunc outinit;
635 /** Function to free the internal data. */
636 sel_freefunc free;
638 /** Function to initialize the calculation for a new frame. */
639 sel_framefunc init_frame;
640 /** Function to evaluate the value. */
641 sel_updatefunc update;
642 /** Function to evaluate the value using positions. */
643 sel_updatefunc_pos pupdate;
645 /** Help data for the method. */
646 gmx_ana_selmethod_help_t help;
647 } gmx_ana_selmethod_t;
649 /** Registers a selection method. */
651 gmx_ana_selmethod_register(struct gmx_ana_selcollection_t *sc,
652 const char *name, gmx_ana_selmethod_t *method);
653 /** Registers all selection methods in the library. */
655 gmx_ana_selmethod_register_defaults(struct gmx_ana_selcollection_t *sc);
657 /** Finds a parameter from a selection method by name. */
658 gmx_ana_selparam_t *
659 gmx_ana_selmethod_find_param(const char *name, gmx_ana_selmethod_t *method);
661 #ifdef __cplusplus
663 #endif
665 #endif