Merge branch 'master' of git@git.gromacs.org:gromacs
[gromacs/rigid-bodies.git] / include / selmethod.h
blob0fdcbf421452456a63f77d5a597c6b03bd7f66e4
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 * Currently, the above flags only work (have been tested) for \ref POS_VALUE
104 * methods.
106 * There is one additional flag that can only be specified for \ref STR_VALUE
107 * methods: \ref SMETH_CHARVAL . It is meant for to ease implementation of
108 * methods that evaluate to strings consisting of single characters.
110 * The next two values determine the number of parameters and a pointer to
111 * the parameter array. The contents of the parameter array are described in
112 * \ref selmethods_params. If the method does not take parameters, the first
113 * value should be 0 and the second can be NULL.
114 * Currently, \ref STR_VALUE methods cannot take parameters, but this limitation
115 * should be easy to lift if required.
117 * These are followed by function callbacks that determine the
118 * actual behavior of the method. Any of these except the evaluation callback
119 * can be NULL (the evaluation callback can also be NULL if \ref NO_VALUE is
120 * specified for a selection modifier). However, the presence of parameters
121 * can require some of the callbacks to be implemented.
122 * The details are described in \ref selmethods_callbacks.
124 * Finally, there is a data structure that gives help texts for the method.
126 * The \c gmx_ana_selmethod_t variable should be declared as a global variable
127 * or it should be otherwise ensured that the structure is not freed: only a
128 * pointer to the structure is stored by the library.
131 * \section selmethods_params Defining parameters
133 * Parameters to selection methods are defined in a separate array of
134 * \c gmx_ana_selparam_t structures.
135 * The order of the parameters does not matter (except possibly for callback
136 * implementation), with one important exception:
137 * If the method evaluates to a \ref POS_VALUE, the first parameter should
138 * have \ref GROUP_VALUE and be the one that is used to calculate the
139 * positions.
141 * An example parameter definition:
142 * \code
143 * static gmx_ana_selparam_t sm_params_example[] = {
144 * {"cutoff", {REAL_VALUE, 1, {NULL}}, NULL, SPAR_OPTIONAL},
145 * {"from", {POS_VALUE, -1, {NULL}}, NULL, SPAR_DYNAMIC | SPAR_VARNUM},
146 * };
147 * \endcode
149 * The first value gives the name of the parameter.
150 * The first parameter can have a NULL name, which means that the value should
151 * immediately follow the method name. This can be used to specify methods
152 * of the type 'within 5 of ...'.
154 * The second value specifies the type of the value that the parameter accepts.
155 * \ref NO_VALUE can be used to specify a boolean parameter, other possibilities
156 * are the same as for the selection method type.
158 * The third value gives the number of values that the parameter accepts.
159 * For boolean parameters (\ref NO_VALUE), it should be 0.
160 * For parameters with \ref SPAR_VARNUM of \ref SPAR_ATOMVAL, it should be set
161 * to -1 for consistency (it is not used).
162 * If \ref SPAR_RANGES is specified, it should be either 1 (to accept a single
163 * continuous range) or -1 (if combined with \ref SPAR_VARNUM).
164 * In all other cases, it should be a positive integer; in most cases, it
165 * should be 1.
167 * The nest two pointers should always be NULL (they should be initialized in
168 * the callbacks), except the first pointer in the case of \ref SPAR_ENUMVAL
169 * (see below).
171 * The final value gives additional information about the acceptable values
172 * for the parameter using a combination of flags.
173 * The possible flags are:
174 * - \ref SPAR_OPTIONAL : If set, the user does not need to provide a value
175 * for the parameter. If not set, an error is reported if the parameter
176 * is not specified by the user.
177 * - \ref SPAR_DYNAMIC : If set, the method can handle dynamic values for
178 * the parameter, i.e., the value(s) can be given by an expression that
179 * evaluates to different values for different frames.
180 * - \ref SPAR_RANGES : Can be set only for \ref INT_VALUE and
181 * \ref REAL_VALUE parameters,
182 * and cannot be combined with \ref SPAR_DYNAMIC.
183 * If set, the parameter accepts ranges of values.
184 * The ranges are automatically sorted and compacted such that a minimum
185 * amount of non-overlapping ranges are given for the method.
186 * - \ref SPAR_VARNUM : If set, the parameter can have a variable number
187 * of values. These can be provided by the user as a list of values, or
188 * using a single \ref SMETH_VARNUMVAL (or a single \ref SMETH_SINGLEVAL)
189 * method.
190 * - \ref SPAR_ATOMVAL : If set, the parameter accepts either a single value
191 * or an expression that evaluates to a value for each input atom.
192 * The single input value is treated as if the same value was returned for
193 * each atom.
194 * Cannot be combined with \ref SPAR_RANGES or \ref SPAR_VARNUM.
195 * - \ref SPAR_ENUMVAL : Can only be set for \ref STR_VALUE parameters that
196 * take a single value, and cannot be combined with any other flag than
197 * \ref SPAR_OPTIONAL. If set, the parameter only accepts one of predefined
198 * string values. See \ref SPAR_ENUMVAL documentation for details on how
199 * to specify the acceptable values.
202 * \section selmethods_callbacks Implementing callbacks
204 * There are eight differen callback functions that can be implemented for
205 * selection methods: sel_datafunc(), sel_posfunc(), sel_initfunc(),
206 * sel_outinitfunc(), sel_freefunc(), sel_framefunc(), and two update functions.
207 * They are in this order in the \c gmx_ana_selmethod_t data structure.
208 * In general, any of the callbacks can be NULL, but the presence of
209 * parameters or other callbacks imposes some restrictions:
210 * - sel_datafunc() should be provided if the method takes parameters.
211 * - sel_initfunc() and sel_freefunc() should be provided if the method takes
212 * any parameters with the \ref SPAR_VARNUM or \ref SPAR_ATOMVAL flags,
213 * except if those parameters have a \ref POS_VALUE.
214 * - sel_outinitfunc() should be provided for \ref POS_VALUE methods
215 * and \ref SMETH_VARNUMVAL methods.
216 * - sel_freefunc() should be provided if sel_datafunc() and/or
217 * sel_initfunc() allocate any dynamic memory in addition to the data
218 * structure itself.
219 * - sel_framefunc() and sel_updatefunc_pos() only make sense for methods with
220 * \ref SMETH_DYNAMIC set.
221 * - At least one update function should be provided unless the method type is
222 * \ref NO_VALUE.
224 * The documentations for the function pointer types provide more information
225 * about how the callbacks should be implemented.
228 * \section selmethods_modifiers Selection modifiers
230 * Selection modifiers are a special kind of selection methods that can be
231 * appended to the end of a selection. They are specified by adding the
232 * \ref SMETH_MODIFIER flag to the \c gmx_ana_selmethod_t.
233 * They can have two different types:
234 * - \ref POS_VALUE : These modifiers are given the final positions
235 * as an input, and they can make modifications to the selection that are
236 * not possible otherwise (e.g., permute the atoms).
237 * The modifier should implement sel_updatefunc_pos() and also have
238 * one NULL parameter in the beginning of the parameter list that takes
239 * \ref POS_VALUE and is used to give the input positions.
240 * - \ref NO_VALUE : These modifiers do not modify the final selection, but
241 * can be used to implement per-selection options for analysis tools
242 * or to control the default behavior of the selection engine
243 * (currently, such a framework is not implemented, but should be easy to
244 * implement if required).
246 * In addition to restricting the type of the method, selection modifiers
247 * do not allow the flags \ref SMETH_SINGLEVAL and \ref SMETH_VARNUMVAL
248 * (they would not make sense).
250 * Parameters and callbacks should be implemented as with normal selection
251 * method, but beware that very little of the functionality has been tested.
253 * \todo
254 * The modifier handling could be made more flexible and more generic;
255 * the current implementation does not allow many things which would be
256 * possible with slight changes in the internals of the library.
259 * \section selmethods_register Registering the method
261 * After defining the method with \c gmx_ana_selmethod_t, it should be
262 * registered with the selection engine.
263 * In analysis programs, this can be done by calling
264 * gmx_ana_selmethod_register().
265 * If adding the method to the library, you should add a pointer to the new
266 * method structure into the \c smtable_def array (in \ref selmethod.c
267 * "selmethod.c"), and it is registered automatically.
268 * In both cases, gmx_ana_selmethod_register() does several checks on the
269 * structure and reports any errors or inconsistencies it finds.
271 /*! \file
272 * \brief API for handling selection methods.
274 * There should be no need to use the data structures or call the
275 * functions in this file directly unless implementing a custom selection
276 * method.
278 * Instructions for implementing custom selection methods can be found
279 * on a separate page: \ref selmethods
281 #ifndef SELMETHOD_H
282 #define SELMETHOD_H
284 #include <typedefs.h>
286 #include <indexutil.h>
287 #include <selparam.h>
288 #include <selvalue.h>
290 #ifdef __cplusplus
291 extern "C"
293 #endif
295 struct gmx_ana_pos_t;
296 struct gmx_ana_poscalc_coll_t;
297 struct gmx_ana_selcollection_t;
299 /*! \name Selection method flags
300 * \anchor selmethod_flags
302 /*@{*/
303 /*! \brief
304 * If set, the method requires topology information.
306 #define SMETH_REQTOP 1
307 /*! \brief
308 * If set, the method can only be evaluated dynamically.
310 #define SMETH_DYNAMIC 2
311 /*! \brief
312 * If set, the method evaluates to a single value.
314 * The default is that the method evaluates to a value for each input atom.
315 * Cannot be combined with \ref SMETH_VARNUMVAL.
317 #define SMETH_SINGLEVAL 4
318 /*! \brief
319 * If set, the method evaluates to an arbitrary number of values.
321 * The default is that the method evaluates to a value for each input atom.
322 * Cannot be combined with \ref SMETH_SINGLEVAL or with \ref GROUP_VALUE.
324 #define SMETH_VARNUMVAL 8
325 /*! \brief
326 * If set, the method evaluates to single-character strings.
328 * This flag can only be set for \ref STR_VALUE methods. If it is set, the
329 * selection engine automatically allocates and frees the required strings.
330 * The evaluation function should store the character values as the first
331 * character in the strings in the output data structure and should not change
332 * the string pointers.
334 #define SMETH_CHARVAL 64
335 /*! \brief
336 * If set, the method is a selection modifier.
338 * The method type should be \ref GROUP_VALUE or \ref NO_VALUE .
339 * Cannot be combined with \ref SMETH_SINGLEVAL or \ref SMETH_VARNUMVAL .
341 #define SMETH_MODIFIER 256
342 /*@}*/
344 /*! \brief
345 * Allocates and initializes internal data and parameter values.
347 * \param[in] npar Number of parameters in \p param.
348 * \param[in,out] param Pointer to (a copy of) the method's
349 * \c gmx_ana_selmethod_t::param.
350 * \returns Pointer to method-specific data structure.
351 * This pointer will be passed as the last parameter of all other function
352 * calls.
353 * Should return NULL on error (only error that should occur is out of
354 * memory).
356 * Should allocate and initialize any internal data required by the method.
357 * Should also initialize the value pointers (\c gmx_ana_selparam_t::val) in
358 * \p param to point to variables within the internal data structure,
359 * with the exception of parameters that specify the \ref SPAR_VARNUM or
360 * the \ref SPAR_ATOMVAL flag (these should be handled in sel_initfunc()).
361 * However, parameters with a position value should be initialized.
362 * It is also possible to initialize \ref SPAR_ENUMVAL statically outside
363 * this function (see \ref SPAR_ENUMVAL).
364 * The \c gmx_ana_selparam_t::nvalptr should also be initialized for
365 * non-position-valued parameters that have both \ref SPAR_VARNUM and
366 * \ref SPAR_DYNAMIC set (it can also be initialized for other parameters if
367 * desired, but the same information will be available through other means).
368 * For optional parameters, the default values can (and should) be initialized
369 * here, as the parameter values are not changed if the parameter is not
370 * provided.
372 * For boolean parameters (type equals \ref NO_VALUE), the default value
373 * should be set here. The user can override the value by giving the parameter
374 * either as 'NAME'/'noNAME', or as 'NAME on/off/yes/no'.
376 * If the method takes any parameters, this function must be provided.
378 typedef void *(*sel_datafunc)(int npar, gmx_ana_selparam_t *param);
379 /*! \brief
380 * Sets the position calculation collection for the method.
382 * \param[in] pcc Position calculation collection that the method should use
383 * for position calculations.
384 * \param data Internal data structure from sel_datafunc().
386 * This function should be provided if the method uses the routines from
387 * poscalc.h for calculating positions.
388 * The pointer \p pcc should then be stored and used for initialization for
389 * any position calculation structures.
391 typedef void (*sel_posfunc)(struct gmx_ana_poscalc_coll_t *pcc, void *data);
392 /*! \brief
393 * Does initialization based on topology and/or parameter values.
395 * \param[in] top Topology structure
396 * (can be NULL if \ref SMETH_REQTOP is not set).
397 * \param[in] npar Number of parameters in \p param.
398 * \param[in] param Pointer to (an initialized copy of) the method's
399 * \c gmx_ana_selmethod_t::param.
400 * \param data Internal data structure from sel_datafunc().
401 * \returns 0 on success, a non-zero error code on failure.
403 * This function is called after the parameters have been processed:
404 * the values of the parameters are stored at the locations set in
405 * sel_datafunc().
406 * The flags \ref SPAR_DYNAMIC and \ref SPAR_ATOMVAL are cleared before
407 * calling the function if the value is static or single-valued, respectively.
408 * If a parameter had the \ref SPAR_VARNUM or \ref SPAR_ATOMVAL flag (and
409 * is not \ref POS_VALUE), a pointer to the memory allocated for the values is
410 * found in \c gmx_ana_selparam_t::val.
411 * The pointer should be stored by this function, otherwise the memory
412 * (and the values) are lost.
413 * For \ref SPAR_VARNUM parameters, the number of values can be accessed
414 * through \c gmx_ana_selparam_t::val. For parameters with \ref SPAR_DYNAMIC,
415 * the number is the maximum number of values (the actual number can be
416 * accessed in sel_framefunc() and in the update callback through the value
417 * pointed by \c gmx_ana_selparam_t::nvalptr).
418 * For \ref SPAR_ATOMVAL parameters, \c gmx_ana_selparam_t::val::nr is set to
419 * 1 if a single value was provided, otherwise it is set to the maximum number
420 * of values possibly passed to the method.
421 * The value pointed by \c gmx_ana_selparam_t::nvalptr always contains the same
422 * value as \c gmx_ana_selparam_t::val::nr.
424 * For dynamic \ref GROUP_VALUE parameters (\ref SPAR_DYNAMIC set), the value
425 * will be the largest possible selection that may occur during the
426 * evaluation. For other types of dynamic parameters, the values are
427 * undefined.
429 * If the method takes any parameters with the \ref SPAR_VARNUM or
430 * \ref SPAR_ATOMVAL flags, this function must be provided, except if these
431 * parameters all have \ref POS_VALUE.
433 * This function may be called multiple times for the same method if the
434 * method takes parameters with \ref SPAR_ATOMVAL set.
436 typedef int (*sel_initfunc)(t_topology *top, int npar,
437 gmx_ana_selparam_t *param, void *data);
438 /*! \brief
439 * Initializes output data structure.
441 * \param[in] top Topology structure
442 * (can be NULL if \ref SMETH_REQTOP is not set).
443 * \param[in,out] out Output data structure.
444 * \param[in] data Internal data structure from sel_datafunc().
445 * \returns 0 on success, an error code on error.
447 * This function is called immediately after sel_initfunc().
449 * If the method evaluates to a position (\ref POS_VALUE), this function
450 * should be provided, and it should initialize the \c gmx_ana_pos_t data
451 * structure pointed by \p out.p (the pointer is guaranteed to be non-NULL).
452 * The \p out.p->g pointer should be initialized to the group that is used
453 * to evaluate positions in sel_updatefunc() or sel_updatefunc_pos().
455 * The function should also be provided for non-position-valued
456 * \ref SMETH_VARNUMVAL methods. For these methods, it suffices to set the
457 * \p out->nr field to reflect the maximum number of values returned by the
458 * method.
460 * Currently, this function is not needed for other types of methods.
462 * This function may be called multiple times for the same method if the
463 * method takes parameters with \ref SPAR_ATOMVAL set.
465 typedef int (*sel_outinitfunc)(t_topology *top, gmx_ana_selvalue_t *out,
466 void *data);
467 /*! \brief
468 * Frees the internal data.
470 * \param[in] data Internal data structure from sel_datafunc().
472 * This function should be provided if the internal data structure contains
473 * dynamically allocated data, and should free any such data.
474 * The data structure itself should not be freed; this is handled automatically.
475 * If there is no dynamically allocated data within the structure,
476 * this function is not needed.
477 * The value pointers for \ref SPAR_VARNUM and \ref SPAR_ATOMVAL parameters
478 * stored in sel_initfunc() should also be freed.
479 * Pointers set as the value pointer of \ref SPAR_ENUMVAL parameters should not
480 * be freed.
482 typedef void (*sel_freefunc)(void *data);
484 /*! \brief
485 * Initializes the evaluation for a new frame.
487 * \param[in] top Topology structure
488 * (can be NULL if \ref SMETH_REQTOP is not set).
489 * \param[in] fr Current frame.
490 * \param[in] pbc Initialized periodic boundary condition structure,
491 * or NULL if PBC should not be used.
492 * \param data Internal data structure from sel_datafunc().
493 * \returns 0 on success, a non-zero error code on failure.
495 * This function should be implemented if the selection method needs to
496 * do some preprocessing for each frame, and the preprocessing does not
497 * depend on the evaluation group.
498 * Because \p sel_updatefunc_* can be called more than once for a frame,
499 * it is inefficient do the preprocessing there.
500 * It is ensured that this function will be called before
501 * \p sel_updatefunc_* for each frame, and that it will be called at most
502 * once for each frame.
504 typedef int (*sel_framefunc)(t_topology *top, t_trxframe *fr, t_pbc *pbc,
505 void *data);
506 /*! \brief
507 * Evaluates a selection method.
509 * \param[in] top Topology structure
510 * (can be NULL if \ref SMETH_REQTOP is not set).
511 * \param[in] fr Current frame.
512 * \param[in] pbc Initialized periodic boundary condition structure,
513 * or NULL if PBC should not be used.
514 * \param[in] g Index group for which the method should be evaluated.
515 * \param[out] out Output data structure.
516 * \param data Internal data structure from sel_datafunc().
517 * \returns 0 on success, a non-zero error code on error.
519 * This function should evaluate the method for each atom included in \p g,
520 * and write the output to \p out. The pointer in the union \p out->u that
521 * corresponds to the type of the method should be used.
522 * Enough memory has been allocated to store the output values.
523 * The number of values in \p out should also be updated if necessary.
524 * However, \ref POS_VALUE or \ref GROUP_VALUE methods should not touch
525 * \p out->nr (it should be 1 anyways).
527 * For \ref STR_VALUE methods, the pointers stored in \p out->s are discarded
528 * without freeing; it is the responsibility of this function to provide
529 * pointers that can be discarded without memory leaks.
531 typedef int (*sel_updatefunc)(t_topology *top, t_trxframe *fr, t_pbc *pbc,
532 gmx_ana_index_t *g, gmx_ana_selvalue_t *out,
533 void *data);
534 /*! \brief
535 * Evaluates a selection method using positions.
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] pos Positions 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 position in \p g,
548 * and write the output values to \p out. The pointer in the union \p out->u
549 * that 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 int (*sel_updatefunc_pos)(t_topology *top, t_trxframe *fr, t_pbc *pbc,
560 struct gmx_ana_pos_t *pos,
561 gmx_ana_selvalue_t *out,
562 void *data);
564 /*! \brief
565 * Help information for a selection method.
567 * If some information is not available, the corresponding field can be set to
568 * 0/NULL.
570 typedef struct gmx_ana_selmethod_help_t
572 /*! \brief
573 * One-line description of the syntax of the method.
575 * If NULL, the name of the method is used.
577 const char *syntax;
578 /*! \brief
579 * Number of strings in \p help.
581 * Set to 0 if \p help is NULL.
583 int nlhelp;
584 /*! \brief
585 * Detailed help for the method.
587 * If there is no help available in addition to \p syntax, this can be set
588 * to NULL.
590 const char **help;
591 } gmx_ana_selmethod_help_t;
593 /*! \brief
594 * Describes a selection method.
596 * Any of the function pointers except the update call can be NULL if the
597 * operation is not required or not supported. In this case,
598 * corresponding function calls are skipped.
600 * See the function pointer type documentation for details of how the
601 * functions should be implemented.
602 * More details on implementing new selection methods can be found on a
603 * separate page: \ref selmethods.
605 typedef struct gmx_ana_selmethod_t
607 /** Name of the method. */
608 const char *name;
609 /** Type which the method returns. */
610 e_selvalue_t type;
611 /*! \brief
612 * Flags to specify how the method should be handled.
614 * See \ref selmethod_flags for allowed values.
616 int flags;
617 /** Number of parameters the method takes. */
618 int nparams;
619 /** Pointer to the array of parameter descriptions. */
620 gmx_ana_selparam_t *param;
622 /** Function for allocating and initializing internal data and parameters. */
623 sel_datafunc init_data;
624 /** Function to set the position calculation collection. */
625 sel_posfunc set_poscoll;
626 /** Function to do initialization based on topology and/or parameter values. */
627 sel_initfunc init;
628 /** Function to initialize output data structure. */
629 sel_outinitfunc outinit;
630 /** Function to free the internal data. */
631 sel_freefunc free;
633 /** Function to initialize the calculation for a new frame. */
634 sel_framefunc init_frame;
635 /** Function to evaluate the value. */
636 sel_updatefunc update;
637 /** Function to evaluate the value using positions. */
638 sel_updatefunc_pos pupdate;
640 /** Help data for the method. */
641 gmx_ana_selmethod_help_t help;
642 } gmx_ana_selmethod_t;
644 /** Registers a selection method. */
645 extern int
646 gmx_ana_selmethod_register(struct gmx_ana_selcollection_t *sc,
647 const char *name, gmx_ana_selmethod_t *method);
648 /** Registers all selection methods in the library. */
649 extern int
650 gmx_ana_selmethod_register_defaults(struct gmx_ana_selcollection_t *sc);
652 /** Finds a parameter from a selection method by name. */
653 extern gmx_ana_selparam_t *
654 gmx_ana_selmethod_find_param(const char *name, gmx_ana_selmethod_t *method);
656 #ifdef __cplusplus
658 #endif
660 #endif