3 * This source code is part of
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
32 * \brief API for handling parameters used in selections.
34 * There should be no need to use the data structures or call the
35 * functions in this file directly unless implementing a custom selection
38 * More details can be found on the page discussing
39 * \ref selmethods "custom selection methods".
41 #ifndef GMX_SELECTION_SELPARAM_H
42 #define GMX_SELECTION_SELPARAM_H
44 #include "indexutil.h"
52 /*! \name Parameter flags
53 * \anchor selparam_flags
57 * This flag is set if the user has provided the parameter.
59 * This flag is set automatically, and should not be set by the user.
63 * If not set, an error is reported if the parameter is not specified by the
66 #define SPAR_OPTIONAL 2
68 * If set, the parameter value can be dynamic, i.e., be different for
71 * If set, the parameter value should only be accessed in the update function
72 * of \c gmx_ana_selmethod_t.
73 * The flag is cleared before sel_initfunc() if the value provided is actually
76 #define SPAR_DYNAMIC 4
78 * If set, the parameter value is parsed into sorted ranges.
80 * Can only be specified for integer parameters.
81 * If specified, the value of the parameter (\c gmx_ana_selparam_t::val)
82 * consists of sets of two integers, each specifying a range.
83 * The values give the endpoints of the ranges (inclusive).
84 * The ranges are sorted and overlapping/continuous ranges are merged into
85 * a single range to minimize the number of ranges.
87 * If this flag is specified, \c gmx_ana_selparam_t::nval gives the number of
88 * ranges. \p gmx_ana_selparam_t::nval should be 1 or \ref SPAR_VARNUM should be
89 * specified; other values would lead to unpredictable behavior.
93 * If set, the parameter can have any number of values.
95 * If specified, the data pointer in \c gmx_ana_selparam_t::val should be NULL;
96 * the memory is allocated by the parameter parser.
97 * The implementation of the method should ensure that the pointer to the
98 * allocated memory is stored somewhere in sel_initfunc();
99 * otherwise, the memory is lost.
101 * The initial value of \c gmx_ana_selparam_t::nval is not used with this flag.
102 * Instead, it will give the number of actual values provided by the user
103 * after the parameters have been parsed.
104 * For consistency, it should be initialized to -1.
106 * Cannot be combined with \ref GROUP_VALUE parameters.
108 #define SPAR_VARNUM 16
110 * If set, the parameter can have a separate value for each atom.
112 * The flag is cleared before sel_initfunc() if the value provided is actually
115 * Cannot be combined with \ref POS_VALUE or \ref GROUP_VALUE parameters.
117 #define SPAR_ATOMVAL 32
119 * If set, the parameter takes one of a set of predefined strings.
121 * Can only be specified for a \ref STR_VALUE parameter that takes a single
123 * The data pointer in \c gmx_ana_selparam_t::val should be initialized into an
124 * array of strings such that the first and last elements are NULL, and the
125 * rest give the possible values. For optional values, the second element in
126 * the array should give the default value. The string given by the user is
127 * matched against the beginnings of the given strings, and if a unique match
128 * is found, the first pointer in the array will be initialized to point to
129 * the matching string.
130 * The data pointer can be initialized as a static array; duplication of the
131 * array for multiple instances of the same method is automatically taken care
134 #define SPAR_ENUMVAL 128
138 * Describes a single parameter for a selection method.
140 typedef struct gmx_ana_selparam_t
142 /** Name of the parameter. */
145 * The parameter value.
147 * Type \ref NO_VALUE can be used to define a boolean parameter.
148 * The number of values should be 0 for boolean parameters.
150 * The value pointer be initialized to NULL in the definition of a
151 * \c gmx_ana_selmethod_t and initialized in the
152 * \c gmx_ana_selmethod_t::init_data call
153 * (see sel_datafunc()).
154 * However, if \ref SPAR_VARNUM is provided and the parameter is not
155 * \ref POS_VALUE, this field should not be initialized. Instead,
156 * sufficient memory is allocated automatically and the pointer should be
157 * stored in \c gmx_ana_selmethod_t::init
158 * (see sel_initfunc()).
160 * The values cannot be accessed outside these two functions: the compiler
161 * makes a copy of the parameter structure for each instance of the
162 * method, and the original parameter array is not changed.
164 gmx_ana_selvalue_t val;
166 * Pointer to store the number of values.
168 * If not NULL, the number of values for the parameter is stored in the
170 * Should be specified if \ref SPAR_VARNUM and \ref SPAR_DYNAMIC are both
173 * Should be initialized to NULL in the definition a \c gmx_ana_selmethod_t
174 * and initialized in sel_datafunc().
178 * Flags that alter the way the parameter is parsed/handled.
180 * See \ref selparam_flags for allowed values.
183 } gmx_ana_selparam_t;
185 /** Finds a parameter from an array by name. */
187 gmx_ana_selparam_find(const char *name, int nparam, gmx_ana_selparam_t *param);