2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2009,2010,2011,2012,2013 by the GROMACS development team.
5 * Copyright (c) 2014,2015,2016,2017,2018 by the GROMACS development team.
6 * Copyright (c) 2019,2020, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
39 * Implements internal selection methods for numeric and string keyword
42 * \author Teemu Murtola <teemu.murtola@gmail.com>
43 * \ingroup module_selection
53 #include "gromacs/utility/arraysize.h"
54 #include "gromacs/utility/cstringutil.h"
55 #include "gromacs/utility/exceptions.h"
56 #include "gromacs/utility/gmxassert.h"
57 #include "gromacs/utility/smalloc.h"
58 #include "gromacs/utility/stringutil.h"
61 #include "parsetree.h"
65 #include "selmethod.h"
68 * Allocates data for integer keyword evaluation.
70 * \param[in] npar Not used.
71 * \param param Not used.
72 * \returns Pointer to the allocated data (\ref t_methoddata_kwint).
74 * Allocates memory for a \ref t_methoddata_kwint structure.
76 static void* init_data_kwint(int npar, gmx_ana_selparam_t* param);
78 * Allocates data for real keyword evaluation.
80 * \param[in] npar Not used.
81 * \param param Not used.
82 * \returns Pointer to the allocated data (\ref t_methoddata_kwreal).
84 * Allocates memory for a \ref t_methoddata_kwreal structure.
86 static void* init_data_kwreal(int npar, gmx_ana_selparam_t* param);
88 * Allocates data for string keyword evaluation.
90 * \param[in] npar Not used.
91 * \param param Not used.
92 * \returns Pointer to the allocated data (t_methoddata_kwstr).
94 * Allocates memory for a t_methoddata_kwstr structure.
96 static void* init_data_kwstr(int npar, gmx_ana_selparam_t* param);
97 /** /brief Initializes data for integer keyword evaluation.
99 * \param[in] top Not used.
100 * \param[in] npar Not used (should be 2).
101 * \param[in] param Method parameters (should point to \ref smparams_keyword_int).
102 * \param[in] data Should point to \ref t_methoddata_kwint.
104 static void init_kwint(const gmx_mtop_t* top, int npar, gmx_ana_selparam_t* param, void* data);
106 * Initializes data for real keyword evaluation.
108 * \param[in] top Not used.
109 * \param[in] npar Not used (should be 2).
110 * \param[in] param Method parameters (should point to \ref smparams_keyword_real).
111 * \param[in] data Should point to \ref t_methoddata_kwreal.
112 * \returns 0 (the initialization always succeeds).
114 static void init_kwreal(const gmx_mtop_t* top, int npar, gmx_ana_selparam_t* param, void* data);
116 * Initializes data for string keyword evaluation.
118 * \param[in] top Not used.
119 * \param[in] npar Not used (should be 2).
120 * \param[in] param Method parameters (should point to \ref smparams_keyword_str).
121 * \param[in] data Should point to t_methoddata_kwstr.
123 static void init_kwstr(const gmx_mtop_t* top, int npar, gmx_ana_selparam_t* param, void* data);
124 /** Frees the memory allocated for string keyword evaluation. */
125 static void free_data_kwstr(void* data);
126 /** Evaluates integer selection keywords. */
127 static void evaluate_keyword_int(const gmx::SelMethodEvalContext& context,
129 gmx_ana_selvalue_t* out,
131 /** Evaluates real selection keywords. */
132 static void evaluate_keyword_real(const gmx::SelMethodEvalContext& context,
134 gmx_ana_selvalue_t* out,
136 /** Evaluates string selection keywords. */
137 static void evaluate_keyword_str(const gmx::SelMethodEvalContext& context,
139 gmx_ana_selvalue_t* out,
143 * Data structure for integer keyword expression evaluation.
145 typedef struct t_methoddata_kwint
147 /** Array of values for the keyword. */
149 /** Number of ranges in the \p r array. */
152 * Array of sorted integer ranges to match against.
154 * Each range is made of two integers, giving the endpoints (inclusive).
155 * This field stores the pointer to the ranges allocated by the
156 * parameter parser; see \ref SPAR_RANGES for more information.
159 } t_methoddata_kwint;
162 * Data structure for real keyword expression evaluation.
164 typedef struct t_methoddata_kwreal
166 /** Array of values for the keyword. */
168 /** Number of ranges in the \p r array. */
171 * Array of sorted ranges to match against.
173 * Each range is made of two values, giving the endpoints (inclusive).
174 * This field stores the pointer to the ranges allocated by the
175 * parameter parser; see \ref SPAR_RANGES for more information.
178 } t_methoddata_kwreal;
184 * Single item in the list of strings/regular expressions to match.
186 * \ingroup module_selection
188 class StringKeywordMatchItem
192 * Constructs a matcher from a string.
194 * \param[in] matchType String matching type.
195 * \param[in] str String to use for matching.
197 StringKeywordMatchItem(gmx::SelectionStringMatchType matchType, const char* str) : str_(str)
199 useRegExp_ = (matchType == gmx::eStringMatchType_RegularExpression);
200 if (matchType == gmx::eStringMatchType_Auto)
202 for (size_t j = 0; j < std::strlen(str); ++j)
204 if (std::ispunct(str[j]) && str[j] != '?' && str[j] != '*')
215 regex_.assign(str, std::regex::nosubs | std::regex::extended);
217 catch (const std::regex_error& /*ex*/)
219 // TODO: Better error messages.
220 GMX_THROW(gmx::InvalidInputError(
221 gmx::formatString("Error in regular expression \"%s\"", str)));
227 * Checks whether this item matches a string.
229 * \param[in] matchType String matching type.
230 * \param[in] value String to match.
231 * \returns true if this item matches \p value.
233 bool match(gmx::SelectionStringMatchType matchType, const char* value) const
235 if (matchType == gmx::eStringMatchType_Exact)
237 return str_ == value;
241 return std::regex_match(value, regex_);
245 return gmx_wcmatch(str_.c_str(), value) == 0;
250 //! The raw string passed for the matcher.
252 //! Whether a regular expression match is used.
254 //! Regular expression compiled from \p str_, if applicable.
259 * Data structure for string keyword expression evaluation.
261 struct t_methoddata_kwstr
263 /** Matching type for the strings. */
264 gmx::SelectionStringMatchType matchType;
265 /** Array of values for the keyword. */
267 /** Array of strings/regular expressions to match against.*/
268 std::vector<StringKeywordMatchItem> matches;
273 /** Parameters for integer keyword evaluation. */
274 static gmx_ana_selparam_t smparams_keyword_int[] = {
275 { nullptr, { INT_VALUE, -1, { nullptr } }, nullptr, SPAR_ATOMVAL },
276 { nullptr, { INT_VALUE, -1, { nullptr } }, nullptr, SPAR_RANGES | SPAR_VARNUM },
279 /** Parameters for real keyword evaluation. */
280 static gmx_ana_selparam_t smparams_keyword_real[] = {
281 { nullptr, { REAL_VALUE, -1, { nullptr } }, nullptr, SPAR_ATOMVAL | SPAR_DYNAMIC },
282 { nullptr, { REAL_VALUE, -1, { nullptr } }, nullptr, SPAR_RANGES | SPAR_VARNUM },
285 /** Parameters for string keyword evaluation. */
286 static gmx_ana_selparam_t smparams_keyword_str[] = {
287 { nullptr, { STR_VALUE, -1, { nullptr } }, nullptr, SPAR_ATOMVAL },
288 { nullptr, { STR_VALUE, -1, { nullptr } }, nullptr, SPAR_VARNUM },
291 /** Selection method data for integer keyword evaluation. */
292 gmx_ana_selmethod_t sm_keyword_int = {
296 asize(smparams_keyword_int),
297 smparams_keyword_int,
304 &evaluate_keyword_int,
306 { nullptr, nullptr, 0, nullptr },
309 /** Selection method data for real keyword evaluation. */
310 gmx_ana_selmethod_t sm_keyword_real = {
314 asize(smparams_keyword_real),
315 smparams_keyword_real,
322 &evaluate_keyword_real,
324 { nullptr, nullptr, 0, nullptr },
327 /** Selection method data for string keyword evaluation. */
328 gmx_ana_selmethod_t sm_keyword_str = {
332 asize(smparams_keyword_str),
333 smparams_keyword_str,
340 &evaluate_keyword_str,
342 { nullptr, nullptr, 0, nullptr },
346 * Initializes keyword evaluation for an arbitrary group.
348 * \param[in] top Not used.
349 * \param[in] npar Not used.
350 * \param[in] param Not used.
351 * \param[in] data Should point to \ref t_methoddata_kweval.
352 * \returns 0 on success, a non-zero error code on return.
354 * Calls the initialization method of the wrapped keyword.
356 static void init_kweval(const gmx_mtop_t* top, int npar, gmx_ana_selparam_t* param, void* data);
358 * Initializes output for keyword evaluation in an arbitrary group.
360 * \param[in] top Not used.
361 * \param[in,out] out Pointer to output data structure.
362 * \param[in,out] data Should point to \c t_methoddata_kweval.
363 * \returns 0 for success.
365 static void init_output_kweval(const gmx_mtop_t* top, gmx_ana_selvalue_t* out, void* data);
366 /** Frees the data allocated for keyword evaluation in an arbitrary group. */
367 static void free_data_kweval(void* data);
368 /** Initializes frame evaluation for keyword evaluation in an arbitrary group. */
369 static void init_frame_kweval(const gmx::SelMethodEvalContext& context, void* data);
371 * Evaluates keywords in an arbitrary group.
373 * See sel_updatefunc() for description of the parameters.
374 * \p data should point to a \c t_methoddata_kweval.
376 * Calls the evaluation function of the wrapped keyword with the given
377 * parameters, with the exception of using \c t_methoddata_kweval::g for the
380 static void evaluate_kweval(const gmx::SelMethodEvalContext& context,
382 gmx_ana_selvalue_t* out,
385 * Evaluates keywords in an arbitrary set of positions.
387 * See sel_updatefunc() for description of the parameters.
388 * \p data should point to a \c t_methoddata_kweval.
390 * Calls the evaluation function of the wrapped keyword with the given
391 * parameters, with the exception of using \c t_methoddata_kweval::p for the
392 * evaluation positions.
394 static void evaluate_kweval_pos(const gmx::SelMethodEvalContext& context,
396 gmx_ana_selvalue_t* out,
400 * Data structure for keyword evaluation in arbitrary groups.
402 struct t_methoddata_kweval
404 //! Initialize new keyword evaluator for the given keyword.
405 t_methoddata_kweval(gmx_ana_selmethod_t* method, void* data) : kwmethod(method), kwmdata(data)
407 gmx_ana_index_clear(&g);
409 ~t_methoddata_kweval() { _gmx_selelem_free_method(kwmethod, kwmdata); }
411 //! Wrapped keyword method for evaluating the values.
412 gmx_ana_selmethod_t* kwmethod;
413 //! Method data for \p kwmethod.
415 //! Group in which \p kwmethod should be evaluated.
417 //! Positions for which \p kwmethod should be evaluated.
421 /** Parameters for keyword evaluation in an arbitrary group. */
422 static gmx_ana_selparam_t smparams_kweval_group[] = {
423 { nullptr, { GROUP_VALUE, 1, { nullptr } }, nullptr, SPAR_DYNAMIC },
425 /** Parameters for keyword evaluation from positions. */
426 static gmx_ana_selparam_t smparams_kweval_pos[] = {
427 { nullptr, { POS_VALUE, 1, { nullptr } }, nullptr, SPAR_DYNAMIC },
431 /********************************************************************
432 * INTEGER KEYWORD EVALUATION
433 ********************************************************************/
435 static void* init_data_kwint(int /* npar */, gmx_ana_selparam_t* /* param */)
437 t_methoddata_kwint* data;
443 static void init_kwint(const gmx_mtop_t* /* top */, int /* npar */, gmx_ana_selparam_t* param, void* data)
445 t_methoddata_kwint* d = static_cast<t_methoddata_kwint*>(data);
447 d->v = param[0].val.u.i;
448 d->n = param[1].val.nr;
449 d->r = param[1].val.u.i;
453 * See sel_updatefunc() for description of the parameters.
454 * \p data should point to a \c t_methoddata_kwint.
456 * Does a binary search to find which atoms match the ranges in the
457 * \c t_methoddata_kwint structure for this selection.
458 * Matching atoms are stored in \p out->u.g.
460 static void evaluate_keyword_int(const gmx::SelMethodEvalContext& /*context*/,
462 gmx_ana_selvalue_t* out,
465 t_methoddata_kwint* d = static_cast<t_methoddata_kwint*>(data);
466 int n, i, j, jmin, jmax;
471 for (i = 0; i < g->isize; ++i)
474 if (d->r[0] > val || d->r[2 * n - 1] < val)
480 while (jmax - jmin > 1)
482 j = jmin + (jmax - jmin) / 2;
483 if (val < d->r[2 * j])
490 if (val <= d->r[2 * j + 1])
497 if (val <= d->r[2 * jmin + 1])
499 out->u.g->index[out->u.g->isize++] = g->index[i];
505 /********************************************************************
506 * REAL KEYWORD EVALUATION
507 ********************************************************************/
509 static void* init_data_kwreal(int /* npar */, gmx_ana_selparam_t* /* param */)
511 t_methoddata_kwreal* data;
517 static void init_kwreal(const gmx_mtop_t* /* top */, int /* npar */, gmx_ana_selparam_t* param, void* data)
519 t_methoddata_kwreal* d = static_cast<t_methoddata_kwreal*>(data);
521 d->v = param[0].val.u.r;
522 d->n = param[1].val.nr;
523 d->r = param[1].val.u.r;
527 * See sel_updatefunc() for description of the parameters.
528 * \p data should point to a \c t_methoddata_kwreal.
530 * Does a binary search to find which atoms match the ranges in the
531 * \c t_methoddata_kwreal structure for this selection.
532 * Matching atoms are stored in \p out->u.g.
534 static void evaluate_keyword_real(const gmx::SelMethodEvalContext& /*context*/,
536 gmx_ana_selvalue_t* out,
539 t_methoddata_kwreal* d = static_cast<t_methoddata_kwreal*>(data);
540 int n, i, j, jmin, jmax;
545 for (i = 0; i < g->isize; ++i)
548 if (d->r[0] > val || d->r[2 * n - 1] < val)
554 while (jmax - jmin > 1)
556 j = jmin + (jmax - jmin) / 2;
557 if (val < d->r[2 * j])
564 if (val <= d->r[2 * j + 1])
571 if (val <= d->r[2 * jmin + 1])
573 out->u.g->index[out->u.g->isize++] = g->index[i];
579 /********************************************************************
580 * STRING KEYWORD EVALUATION
581 ********************************************************************/
583 static void* init_data_kwstr(int /* npar */, gmx_ana_selparam_t* /* param */)
585 t_methoddata_kwstr* data = new t_methoddata_kwstr();
586 data->matchType = gmx::eStringMatchType_Auto;
591 * \param[in,out] sel Selection element to initialize.
592 * \param[in] matchType Method to use to match string values.
594 * Sets the string matching method for string keyword matching.
596 void _gmx_selelem_set_kwstr_match_type(const gmx::SelectionTreeElementPointer& sel,
597 gmx::SelectionStringMatchType matchType)
599 t_methoddata_kwstr* d = static_cast<t_methoddata_kwstr*>(sel->u.expr.mdata);
601 if (sel->type != SEL_EXPRESSION || !sel->u.expr.method
602 || sel->u.expr.method->name != sm_keyword_str.name)
606 d->matchType = matchType;
609 static void init_kwstr(const gmx_mtop_t* /* top */, int /* npar */, gmx_ana_selparam_t* param, void* data)
611 t_methoddata_kwstr* d = static_cast<t_methoddata_kwstr*>(data);
613 d->v = param[0].val.u.s;
614 /* Return if this is not the first time */
615 if (!d->matches.empty())
619 int n = param[1].val.nr;
620 d->matches.reserve(n);
621 for (int i = 0; i < n; ++i)
623 const char* s = param[1].val.u.s[i];
624 d->matches.emplace_back(d->matchType, s);
629 * \param data Data to free (should point to a t_methoddata_kwstr).
631 static void free_data_kwstr(void* data)
633 t_methoddata_kwstr* d = static_cast<t_methoddata_kwstr*>(data);
638 * See sel_updatefunc() for description of the parameters.
639 * \p data should point to a \c t_methoddata_kwstr.
641 * Does a linear search to find which atoms match the strings in the
642 * \c t_methoddata_kwstr structure for this selection.
643 * Wildcards are allowed in the strings.
644 * Matching atoms are stored in \p out->u.g.
646 static void evaluate_keyword_str(const gmx::SelMethodEvalContext& /*context*/,
648 gmx_ana_selvalue_t* out,
651 t_methoddata_kwstr* d = static_cast<t_methoddata_kwstr*>(data);
654 for (int i = 0; i < g->isize; ++i)
656 for (size_t j = 0; j < d->matches.size(); ++j)
658 if (d->matches[j].match(d->matchType, d->v[i]))
660 out->u.g->index[out->u.g->isize++] = g->index[i];
668 /********************************************************************
669 * KEYWORD EVALUATION FOR ARBITRARY GROUPS
670 ********************************************************************/
672 static void init_kweval(const gmx_mtop_t* top, int /* npar */, gmx_ana_selparam_t* /* param */, void* data)
674 t_methoddata_kweval* d = static_cast<t_methoddata_kweval*>(data);
676 d->kwmethod->init(top, 0, nullptr, d->kwmdata);
679 static void init_output_kweval(const gmx_mtop_t* /* top */, gmx_ana_selvalue_t* out, void* data)
681 t_methoddata_kweval* d = static_cast<t_methoddata_kweval*>(data);
683 out->nr = d->g.isize;
684 _gmx_selvalue_reserve(out, out->nr);
688 * \param data Data to free (should point to a \c t_methoddata_kweval).
690 * Frees the memory allocated for all the members of \c t_methoddata_kweval.
692 static void free_data_kweval(void* data)
694 t_methoddata_kweval* d = static_cast<t_methoddata_kweval*>(data);
700 * \param[in] context Evaluation context.
701 * \param data Should point to a \ref t_methoddata_kweval.
703 static void init_frame_kweval(const gmx::SelMethodEvalContext& context, void* data)
705 t_methoddata_kweval* d = static_cast<t_methoddata_kweval*>(data);
707 d->kwmethod->init_frame(context, d->kwmdata);
710 static void evaluate_kweval(const gmx::SelMethodEvalContext& context,
711 gmx_ana_index_t* /* g */,
712 gmx_ana_selvalue_t* out,
715 t_methoddata_kweval* d = static_cast<t_methoddata_kweval*>(data);
717 d->kwmethod->update(context, &d->g, out, d->kwmdata);
720 static void evaluate_kweval_pos(const gmx::SelMethodEvalContext& context,
721 gmx_ana_index_t* /* g */,
722 gmx_ana_selvalue_t* out,
725 t_methoddata_kweval* d = static_cast<t_methoddata_kweval*>(data);
727 d->kwmethod->pupdate(context, &d->p, out, d->kwmdata);
731 * Initializes a selection element for evaluating a keyword in a given group.
733 * \param[in] method Keyword selection method to evaluate.
734 * \param[in] params Parameters to pass to initialization (the child group).
735 * \param[in] scanner Scanner data structure.
736 * \returns Pointer to the created selection element.
738 * Implements _gmx_sel_init_keyword_evaluator() for \ref GROUP_VALUE input
741 static gmx::SelectionTreeElementPointer init_evaluator_group(gmx_ana_selmethod_t* method,
742 const gmx::SelectionParserParameterList& params,
745 if ((method->flags & (SMETH_SINGLEVAL | SMETH_VARNUMVAL)) || method->outinit || method->pupdate)
747 std::string message =
748 gmx::formatString("Keyword '%s' cannot be evaluated in this context", method->name);
749 GMX_THROW(gmx::InvalidInputError(message));
752 // TODO: For same ... as ..., some other location could be more intuitive.
753 gmx::SelectionTreeElementPointer sel(new gmx::SelectionTreeElement(
754 SEL_EXPRESSION, _gmx_sel_lexer_get_current_location(scanner)));
755 _gmx_selelem_set_method(sel, method, scanner);
757 t_methoddata_kweval* data = new t_methoddata_kweval(sel->u.expr.method, sel->u.expr.mdata);
759 snew(sel->u.expr.method, 1);
760 sel->u.expr.method->name = data->kwmethod->name;
761 sel->u.expr.method->type = data->kwmethod->type;
762 sel->u.expr.method->flags = data->kwmethod->flags | SMETH_VARNUMVAL;
763 sel->u.expr.method->init_data = nullptr;
764 sel->u.expr.method->set_poscoll = nullptr;
765 sel->u.expr.method->init = method->init ? &init_kweval : nullptr;
766 sel->u.expr.method->outinit = &init_output_kweval;
767 sel->u.expr.method->free = &free_data_kweval;
768 sel->u.expr.method->init_frame = method->init_frame ? &init_frame_kweval : nullptr;
769 sel->u.expr.method->update = &evaluate_kweval;
770 sel->u.expr.method->pupdate = nullptr;
771 sel->u.expr.method->nparams = asize(smparams_kweval_group);
772 sel->u.expr.method->param = smparams_kweval_group;
773 _gmx_selelem_init_method_params(sel, scanner);
774 sel->u.expr.mdata = data;
776 sel->u.expr.method->param[0].val.u.g = &data->g;
778 _gmx_sel_parse_params(params, sel->u.expr.method->nparams, sel->u.expr.method->param, sel, scanner);
783 * Initializes a selection element for evaluating a keyword in given positions.
785 * \param[in] method Keyword selection method to evaluate.
786 * \param[in] params Parameters to pass to initialization (the child positions).
787 * \param[in] scanner Scanner data structure.
788 * \returns Pointer to the created selection element.
790 * Implements _gmx_sel_init_keyword_evaluator() for \ref POS_VALUE input
793 static gmx::SelectionTreeElementPointer init_evaluator_pos(gmx_ana_selmethod_t* method,
794 const gmx::SelectionParserParameterList& params,
797 if ((method->flags & (SMETH_SINGLEVAL | SMETH_VARNUMVAL)) || method->outinit || method->pupdate == nullptr)
799 std::string message =
800 gmx::formatString("Keyword '%s' cannot be evaluated in this context", method->name);
801 GMX_THROW(gmx::InvalidInputError(message));
804 gmx::SelectionTreeElementPointer sel(new gmx::SelectionTreeElement(
805 SEL_EXPRESSION, _gmx_sel_lexer_get_current_location(scanner)));
806 _gmx_selelem_set_method(sel, method, scanner);
808 t_methoddata_kweval* data = new t_methoddata_kweval(sel->u.expr.method, sel->u.expr.mdata);
810 snew(sel->u.expr.method, 1);
811 sel->u.expr.method->name = data->kwmethod->name;
812 sel->u.expr.method->type = data->kwmethod->type;
813 sel->u.expr.method->flags = data->kwmethod->flags | SMETH_SINGLEVAL;
814 sel->u.expr.method->init_data = nullptr;
815 sel->u.expr.method->set_poscoll = nullptr;
816 sel->u.expr.method->init = method->init ? &init_kweval : nullptr;
817 sel->u.expr.method->outinit = nullptr;
818 sel->u.expr.method->free = &free_data_kweval;
819 sel->u.expr.method->init_frame = method->init_frame ? &init_frame_kweval : nullptr;
820 sel->u.expr.method->update = &evaluate_kweval_pos;
821 sel->u.expr.method->pupdate = nullptr;
822 sel->u.expr.method->nparams = asize(smparams_kweval_pos);
823 sel->u.expr.method->param = smparams_kweval_pos;
824 _gmx_selelem_init_method_params(sel, scanner);
825 sel->u.expr.mdata = data;
827 sel->u.expr.method->param[0].val.u.p = &data->p;
829 _gmx_sel_parse_params(params, sel->u.expr.method->nparams, sel->u.expr.method->param, sel, scanner);
833 gmx::SelectionTreeElementPointer _gmx_sel_init_keyword_evaluator(gmx_ana_selmethod_t* method,
834 const gmx::SelectionTreeElementPointer& child,
837 gmx::SelectionParserParameterList params;
838 params.push_back(gmx::SelectionParserParameter::createFromExpression(nullptr, child));
839 if (child->v.type == GROUP_VALUE)
841 return init_evaluator_group(method, params, scanner);
843 else if (child->v.type == POS_VALUE)
845 return init_evaluator_pos(method, params, scanner);
849 std::string text(_gmx_sel_lexer_get_text(scanner, child->location()));
850 std::string message =
851 gmx::formatString("Expression '%s' cannot be used to evaluate keywords", text.c_str());
852 GMX_THROW(gmx::InvalidInputError(message));