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
33 * Implements position evaluation selection methods.
35 * \author Teemu Murtola <teemu.murtola@cbr.su.se>
36 * \ingroup module_selection
46 #include "gromacs/selection/indexutil.h"
47 #include "gromacs/selection/poscalc.h"
48 #include "gromacs/selection/position.h"
49 #include "gromacs/selection/selmethod.h"
55 * Data structure for position keyword evaluation.
59 /** Position calculation collection to use. */
60 gmx_ana_poscalc_coll_t *pcc;
61 /** Index group for which the center should be evaluated. */
63 /** Position evaluation data structure. */
64 gmx_ana_poscalc_t *pc;
65 /** true if periodic boundary conditions should be used. */
67 /** Type of positions to calculate. */
69 /** Flags for the position calculation. */
73 /** Allocates data for position evaluation selection methods. */
75 init_data_pos(int npar, gmx_ana_selparam_t *param);
76 /** Sets the position calculation collection for position evaluation selection methods. */
78 set_poscoll_pos(gmx_ana_poscalc_coll_t *pcc, void *data);
79 /** Initializes position evaluation keywords. */
81 init_kwpos(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
82 /** Initializes the \p cog selection method. */
84 init_cog(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
85 /** Initializes the \p cog selection method. */
87 init_com(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
88 /** Initializes output for position evaluation selection methods. */
90 init_output_pos(t_topology *top, gmx_ana_selvalue_t *out, void *data);
91 /** Frees the data allocated for position evaluation selection methods. */
93 free_data_pos(void *data);
94 /** Evaluates position evaluation selection methods. */
96 evaluate_pos(t_topology *top, t_trxframe *fr, t_pbc *pbc,
97 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
99 /** Parameters for position keyword evaluation. */
100 static gmx_ana_selparam_t smparams_keyword_pos[] = {
101 {NULL, {GROUP_VALUE, 1, {NULL}}, NULL, SPAR_DYNAMIC},
104 /** Parameters for the \p cog and \p com selection methods. */
105 static gmx_ana_selparam_t smparams_com[] = {
106 {"of", {GROUP_VALUE, 1, {NULL}}, NULL, SPAR_DYNAMIC},
107 {"pbc", {NO_VALUE, 0, {NULL}}, NULL, 0},
110 /** \internal Selection method data for position keyword evaluation. */
111 gmx_ana_selmethod_t sm_keyword_pos = {
112 "kw_pos", POS_VALUE, SMETH_DYNAMIC | SMETH_VARNUMVAL,
113 asize(smparams_keyword_pos), smparams_keyword_pos,
125 /** \internal Selection method data for the \p cog method. */
126 gmx_ana_selmethod_t sm_cog = {
127 "cog", POS_VALUE, SMETH_DYNAMIC | SMETH_SINGLEVAL,
128 asize(smparams_com), smparams_com,
137 {"cog of ATOM_EXPR [pbc]", 0, NULL},
140 /** \internal Selection method data for the \p com method. */
141 gmx_ana_selmethod_t sm_com = {
142 "com", POS_VALUE, SMETH_REQTOP | SMETH_DYNAMIC | SMETH_SINGLEVAL,
143 asize(smparams_com), smparams_com,
152 {"com of ATOM_EXPR [pbc]", 0, NULL},
156 * \param[in] npar Should be 1 or 2.
157 * \param[in,out] param Method parameters (should point to
158 * \ref smparams_keyword_pos or \ref smparams_com).
159 * \returns Pointer to the allocated data (\c t_methoddata_pos).
161 * Allocates memory for a \c t_methoddata_pos structure and initializes
162 * the first parameter to define the value for \c t_methoddata_pos::g.
163 * If a second parameter is present, it is used for setting the
164 * \c t_methoddata_pos::bPBC flag.
167 init_data_pos(int npar, gmx_ana_selparam_t *param)
169 t_methoddata_pos *data;
172 param[0].val.u.g = &data->g;
175 param[1].val.u.b = &data->bPBC;
185 * \param[in] pcc Position calculation collection to use.
186 * \param[in,out] data Should point to \c t_methoddata_pos.
189 set_poscoll_pos(gmx_ana_poscalc_coll_t *pcc, void *data)
191 ((t_methoddata_pos *)data)->pcc = pcc;
195 * \param[in,out] sel Selection element to initialize.
196 * \param[in] type One of the enum values acceptable for
197 * gmx_ana_poscalc_type_from_enum().
199 * Initializes the reference position type for position evaluation.
200 * If called multiple times, the first setting takes effect, and later calls
204 _gmx_selelem_set_kwpos_type(t_selelem *sel, const char *type)
206 t_methoddata_pos *d = (t_methoddata_pos *)sel->u.expr.mdata;
208 if (sel->type != SEL_EXPRESSION || !sel->u.expr.method
209 || sel->u.expr.method->name != sm_keyword_pos.name)
213 if (!d->type && type)
215 d->type = strdup(type);
216 /* FIXME: It would be better not to have the string here hardcoded. */
219 sel->u.expr.method->flags |= SMETH_REQTOP;
225 * \param[in,out] sel Selection element to initialize.
226 * \param[in] flags Default completion flags
227 * (see gmx_ana_poscalc_type_from_enum()).
229 * Initializes the flags for position evaluation.
230 * If called multiple times, the first setting takes effect, and later calls
234 _gmx_selelem_set_kwpos_flags(t_selelem *sel, int flags)
236 t_methoddata_pos *d = (t_methoddata_pos *)sel->u.expr.mdata;
238 if (sel->type != SEL_EXPRESSION || !sel->u.expr.method
239 || sel->u.expr.method->name != sm_keyword_pos.name)
250 * \param[in] top Not used.
251 * \param[in] npar Not used.
252 * \param[in] param Not used.
253 * \param[in,out] data Should point to \c t_methoddata_pos.
254 * \returns 0 on success, a non-zero error code on error.
256 * The \c t_methoddata_pos::type field should have been initialized
257 * externally using _gmx_selelem_set_kwpos_type().
260 init_kwpos(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
262 t_methoddata_pos *d = (t_methoddata_pos *)data;
264 if (!(param[0].flags & SPAR_DYNAMIC))
266 d->flags &= ~(POS_DYNAMIC | POS_MASKONLY);
268 else if (!(d->flags & POS_MASKONLY))
270 d->flags |= POS_DYNAMIC;
272 gmx_ana_poscalc_create_enum(&d->pc, d->pcc, d->type, d->flags);
273 gmx_ana_poscalc_set_maxindex(d->pc, &d->g);
277 * \param[in] top Topology data structure.
278 * \param[in] npar Not used.
279 * \param[in] param Not used.
280 * \param[in,out] data Should point to \c t_methoddata_pos.
281 * \returns 0 on success, a non-zero error code on error.
284 init_cog(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
286 t_methoddata_pos *d = (t_methoddata_pos *)data;
288 d->flags = (param[0].flags & SPAR_DYNAMIC) ? POS_DYNAMIC : 0;
289 gmx_ana_poscalc_create(&d->pc, d->pcc, d->bPBC ? POS_ALL_PBC : POS_ALL,
291 gmx_ana_poscalc_set_maxindex(d->pc, &d->g);
295 * \param[in] top Topology data structure.
296 * \param[in] npar Not used.
297 * \param[in] param Not used.
298 * \param[in,out] data Should point to \c t_methoddata_pos.
299 * \returns 0 on success, a non-zero error code on error.
302 init_com(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
304 t_methoddata_pos *d = (t_methoddata_pos *)data;
306 d->flags = (param[0].flags & SPAR_DYNAMIC) ? POS_DYNAMIC : 0;
307 d->flags |= POS_MASS;
308 gmx_ana_poscalc_create(&d->pc, d->pcc, d->bPBC ? POS_ALL_PBC : POS_ALL,
310 gmx_ana_poscalc_set_maxindex(d->pc, &d->g);
314 * \param[in] top Topology data structure.
315 * \param[in,out] out Pointer to output data structure.
316 * \param[in,out] data Should point to \c t_methoddata_pos.
317 * \returns 0 for success.
320 init_output_pos(t_topology *top, gmx_ana_selvalue_t *out, void *data)
322 t_methoddata_pos *d = (t_methoddata_pos *)data;
324 gmx_ana_poscalc_init_pos(d->pc, out->u.p);
325 gmx_ana_pos_set_evalgrp(out->u.p, &d->g);
329 * \param data Data to free (should point to a \c t_methoddata_pos).
331 * Frees the memory allocated for \c t_methoddata_pos::g and
332 * \c t_methoddata_pos::pc.
335 free_data_pos(void *data)
337 t_methoddata_pos *d = (t_methoddata_pos *)data;
340 gmx_ana_poscalc_free(d->pc);
344 * See sel_updatefunc() for description of the parameters.
345 * \p data should point to a \c t_methoddata_pos.
347 * Calculates the positions using \c t_methoddata_pos::pc for the index group
348 * in \c t_methoddata_pos::g and stores the results in \p out->u.p.
351 evaluate_pos(t_topology *top, t_trxframe *fr, t_pbc *pbc,
352 gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
354 t_methoddata_pos *d = (t_methoddata_pos *)data;
356 gmx_ana_poscalc_update(d->pc, out->u.p, &d->g, fr, pbc);