2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
37 * Implements internal selection methods for numeric and string keyword
40 * \author Teemu Murtola <teemu.murtola@gmail.com>
41 * \ingroup module_selection
51 #include "gromacs/utility/arraysize.h"
52 #include "gromacs/utility/cstringutil.h"
53 #include "gromacs/utility/exceptions.h"
54 #include "gromacs/utility/gmxassert.h"
55 #include "gromacs/utility/smalloc.h"
56 #include "gromacs/utility/stringutil.h"
59 #include "parsetree.h"
63 #include "selmethod.h"
66 * Allocates data for integer keyword evaluation.
68 * \param[in] npar Not used.
69 * \param param Not used.
70 * \returns Pointer to the allocated data (\ref t_methoddata_kwint).
72 * Allocates memory for a \ref t_methoddata_kwint structure.
74 static void* init_data_kwint(int npar, gmx_ana_selparam_t* param);
76 * Allocates data for real keyword evaluation.
78 * \param[in] npar Not used.
79 * \param param Not used.
80 * \returns Pointer to the allocated data (\ref t_methoddata_kwreal).
82 * Allocates memory for a \ref t_methoddata_kwreal structure.
84 static void* init_data_kwreal(int npar, gmx_ana_selparam_t* param);
86 * Allocates data for string keyword evaluation.
88 * \param[in] npar Not used.
89 * \param param Not used.
90 * \returns Pointer to the allocated data (t_methoddata_kwstr).
92 * Allocates memory for a t_methoddata_kwstr structure.
94 static void* init_data_kwstr(int npar, gmx_ana_selparam_t* param);
95 /** /brief Initializes data for integer keyword evaluation.
97 * \param[in] top Not used.
98 * \param[in] npar Not used (should be 2).
99 * \param[in] param Method parameters (should point to \ref smparams_keyword_int).
100 * \param[in] data Should point to \ref t_methoddata_kwint.
102 static void init_kwint(const gmx_mtop_t* top, int npar, gmx_ana_selparam_t* param, void* data);
104 * Initializes data for real keyword evaluation.
106 * \param[in] top Not used.
107 * \param[in] npar Not used (should be 2).
108 * \param[in] param Method parameters (should point to \ref smparams_keyword_real).
109 * \param[in] data Should point to \ref t_methoddata_kwreal.
110 * \returns 0 (the initialization always succeeds).
112 static void init_kwreal(const gmx_mtop_t* top, int npar, gmx_ana_selparam_t* param, void* data);
114 * Initializes data for string keyword evaluation.
116 * \param[in] top Not used.
117 * \param[in] npar Not used (should be 2).
118 * \param[in] param Method parameters (should point to \ref smparams_keyword_str).
119 * \param[in] data Should point to t_methoddata_kwstr.
121 static void init_kwstr(const gmx_mtop_t* top, int npar, gmx_ana_selparam_t* param, void* data);
122 /** Frees the memory allocated for string keyword evaluation. */
123 static void free_data_kwstr(void* data);
124 /** Evaluates integer selection keywords. */
125 static void evaluate_keyword_int(const gmx::SelMethodEvalContext& context,
127 gmx_ana_selvalue_t* out,
129 /** Evaluates real selection keywords. */
130 static void evaluate_keyword_real(const gmx::SelMethodEvalContext& context,
132 gmx_ana_selvalue_t* out,
134 /** Evaluates string selection keywords. */
135 static void evaluate_keyword_str(const gmx::SelMethodEvalContext& context,
137 gmx_ana_selvalue_t* out,
141 * Data structure for integer keyword expression evaluation.
143 typedef struct t_methoddata_kwint
145 /** Array of values for the keyword. */
147 /** Number of ranges in the \p r array. */
150 * Array of sorted integer ranges to match against.
152 * Each range is made of two integers, giving the endpoints (inclusive).
153 * This field stores the pointer to the ranges allocated by the
154 * parameter parser; see \ref SPAR_RANGES for more information.
157 } t_methoddata_kwint;
160 * Data structure for real keyword expression evaluation.
162 typedef struct t_methoddata_kwreal
164 /** Array of values for the keyword. */
166 /** Number of ranges in the \p r array. */
169 * Array of sorted ranges to match against.
171 * Each range is made of two values, giving the endpoints (inclusive).
172 * This field stores the pointer to the ranges allocated by the
173 * parameter parser; see \ref SPAR_RANGES for more information.
176 } t_methoddata_kwreal;
182 * Single item in the list of strings/regular expressions to match.
184 * \ingroup module_selection
186 class StringKeywordMatchItem
190 * Constructs a matcher from a string.
192 * \param[in] matchType String matching type.
193 * \param[in] str String to use for matching.
195 StringKeywordMatchItem(gmx::SelectionStringMatchType matchType, const char* str) : str_(str)
197 useRegExp_ = (matchType == gmx::eStringMatchType_RegularExpression);
198 if (matchType == gmx::eStringMatchType_Auto)
200 for (size_t j = 0; j < std::strlen(str); ++j)
202 if (std::ispunct(str[j]) && str[j] != '?' && str[j] != '*')
213 regex_.assign(str, std::regex::nosubs | std::regex::extended);
215 catch (const std::regex_error& /*ex*/)
217 // TODO: Better error messages.
218 GMX_THROW(gmx::InvalidInputError(
219 gmx::formatString("Error in regular expression \"%s\"", str)));
225 * Checks whether this item matches a string.
227 * \param[in] matchType String matching type.
228 * \param[in] value String to match.
229 * \returns true if this item matches \p value.
231 bool match(gmx::SelectionStringMatchType matchType, const char* value) const
233 if (matchType == gmx::eStringMatchType_Exact)
235 return str_ == value;
239 return std::regex_match(value, regex_);
243 return gmx_wcmatch(str_.c_str(), value) == 0;
248 //! The raw string passed for the matcher.
250 //! Whether a regular expression match is used.
252 //! Regular expression compiled from \p str_, if applicable.
257 * Data structure for string keyword expression evaluation.
259 struct t_methoddata_kwstr
261 /** Matching type for the strings. */
262 gmx::SelectionStringMatchType matchType;
263 /** Array of values for the keyword. */
265 /** Array of strings/regular expressions to match against.*/
266 std::vector<StringKeywordMatchItem> matches;
271 /** Parameters for integer keyword evaluation. */
272 static gmx_ana_selparam_t smparams_keyword_int[] = {
273 { nullptr, { INT_VALUE, -1, { nullptr } }, nullptr, SPAR_ATOMVAL },
274 { nullptr, { INT_VALUE, -1, { nullptr } }, nullptr, SPAR_RANGES | SPAR_VARNUM },
277 /** Parameters for real keyword evaluation. */
278 static gmx_ana_selparam_t smparams_keyword_real[] = {
279 { nullptr, { REAL_VALUE, -1, { nullptr } }, nullptr, SPAR_ATOMVAL | SPAR_DYNAMIC },
280 { nullptr, { REAL_VALUE, -1, { nullptr } }, nullptr, SPAR_RANGES | SPAR_VARNUM },
283 /** Parameters for string keyword evaluation. */
284 static gmx_ana_selparam_t smparams_keyword_str[] = {
285 { nullptr, { STR_VALUE, -1, { nullptr } }, nullptr, SPAR_ATOMVAL },
286 { nullptr, { STR_VALUE, -1, { nullptr } }, nullptr, SPAR_VARNUM },
289 /** Selection method data for integer keyword evaluation. */
290 gmx_ana_selmethod_t sm_keyword_int = {
294 asize(smparams_keyword_int),
295 smparams_keyword_int,
302 &evaluate_keyword_int,
304 { nullptr, nullptr, 0, nullptr },
307 /** Selection method data for real keyword evaluation. */
308 gmx_ana_selmethod_t sm_keyword_real = {
312 asize(smparams_keyword_real),
313 smparams_keyword_real,
320 &evaluate_keyword_real,
322 { nullptr, nullptr, 0, nullptr },
325 /** Selection method data for string keyword evaluation. */
326 gmx_ana_selmethod_t sm_keyword_str = {
330 asize(smparams_keyword_str),
331 smparams_keyword_str,
338 &evaluate_keyword_str,
340 { nullptr, nullptr, 0, nullptr },
344 * Initializes keyword evaluation for an arbitrary group.
346 * \param[in] top Not used.
347 * \param[in] npar Not used.
348 * \param[in] param Not used.
349 * \param[in] data Should point to \ref t_methoddata_kweval.
350 * \returns 0 on success, a non-zero error code on return.
352 * Calls the initialization method of the wrapped keyword.
354 static void init_kweval(const gmx_mtop_t* top, int npar, gmx_ana_selparam_t* param, void* data);
356 * Initializes output for keyword evaluation in an arbitrary group.
358 * \param[in] top Not used.
359 * \param[in,out] out Pointer to output data structure.
360 * \param[in,out] data Should point to \c t_methoddata_kweval.
361 * \returns 0 for success.
363 static void init_output_kweval(const gmx_mtop_t* top, gmx_ana_selvalue_t* out, void* data);
364 /** Frees the data allocated for keyword evaluation in an arbitrary group. */
365 static void free_data_kweval(void* data);
366 /** Initializes frame evaluation for keyword evaluation in an arbitrary group. */
367 static void init_frame_kweval(const gmx::SelMethodEvalContext& context, void* data);
369 * Evaluates keywords in an arbitrary group.
371 * See sel_updatefunc() for description of the parameters.
372 * \p data should point to a \c t_methoddata_kweval.
374 * Calls the evaluation function of the wrapped keyword with the given
375 * parameters, with the exception of using \c t_methoddata_kweval::g for the
378 static void evaluate_kweval(const gmx::SelMethodEvalContext& context,
380 gmx_ana_selvalue_t* out,
383 * Evaluates keywords in an arbitrary set of positions.
385 * See sel_updatefunc() for description of the parameters.
386 * \p data should point to a \c t_methoddata_kweval.
388 * Calls the evaluation function of the wrapped keyword with the given
389 * parameters, with the exception of using \c t_methoddata_kweval::p for the
390 * evaluation positions.
392 static void evaluate_kweval_pos(const gmx::SelMethodEvalContext& context,
394 gmx_ana_selvalue_t* out,
398 * Data structure for keyword evaluation in arbitrary groups.
400 struct t_methoddata_kweval
402 //! Initialize new keyword evaluator for the given keyword.
403 t_methoddata_kweval(gmx_ana_selmethod_t* method, void* data) : kwmethod(method), kwmdata(data)
405 gmx_ana_index_clear(&g);
407 ~t_methoddata_kweval() { _gmx_selelem_free_method(kwmethod, kwmdata); }
409 //! Wrapped keyword method for evaluating the values.
410 gmx_ana_selmethod_t* kwmethod;
411 //! Method data for \p kwmethod.
413 //! Group in which \p kwmethod should be evaluated.
415 //! Positions for which \p kwmethod should be evaluated.
419 /** Parameters for keyword evaluation in an arbitrary group. */
420 static gmx_ana_selparam_t smparams_kweval_group[] = {
421 { nullptr, { GROUP_VALUE, 1, { nullptr } }, nullptr, SPAR_DYNAMIC },
423 /** Parameters for keyword evaluation from positions. */
424 static gmx_ana_selparam_t smparams_kweval_pos[] = {
425 { nullptr, { POS_VALUE, 1, { nullptr } }, nullptr, SPAR_DYNAMIC },
429 /********************************************************************
430 * INTEGER KEYWORD EVALUATION
431 ********************************************************************/
433 static void* init_data_kwint(int /* npar */, gmx_ana_selparam_t* /* param */)
435 t_methoddata_kwint* data;
441 static void init_kwint(const gmx_mtop_t* /* top */, int /* npar */, gmx_ana_selparam_t* param, void* data)
443 t_methoddata_kwint* d = static_cast<t_methoddata_kwint*>(data);
445 d->v = param[0].val.u.i;
446 d->n = param[1].val.nr;
447 d->r = param[1].val.u.i;
451 * See sel_updatefunc() for description of the parameters.
452 * \p data should point to a \c t_methoddata_kwint.
454 * Does a binary search to find which atoms match the ranges in the
455 * \c t_methoddata_kwint structure for this selection.
456 * Matching atoms are stored in \p out->u.g.
458 static void evaluate_keyword_int(const gmx::SelMethodEvalContext& /*context*/,
460 gmx_ana_selvalue_t* out,
463 t_methoddata_kwint* d = static_cast<t_methoddata_kwint*>(data);
464 int n, i, j, jmin, jmax;
469 for (i = 0; i < g->isize; ++i)
472 if (d->r[0] > val || d->r[2 * n - 1] < val)
478 while (jmax - jmin > 1)
480 j = jmin + (jmax - jmin) / 2;
481 if (val < d->r[2 * j])
488 if (val <= d->r[2 * j + 1])
495 if (val <= d->r[2 * jmin + 1])
497 out->u.g->index[out->u.g->isize++] = g->index[i];
503 /********************************************************************
504 * REAL KEYWORD EVALUATION
505 ********************************************************************/
507 static void* init_data_kwreal(int /* npar */, gmx_ana_selparam_t* /* param */)
509 t_methoddata_kwreal* data;
515 static void init_kwreal(const gmx_mtop_t* /* top */, int /* npar */, gmx_ana_selparam_t* param, void* data)
517 t_methoddata_kwreal* d = static_cast<t_methoddata_kwreal*>(data);
519 d->v = param[0].val.u.r;
520 d->n = param[1].val.nr;
521 d->r = param[1].val.u.r;
525 * See sel_updatefunc() for description of the parameters.
526 * \p data should point to a \c t_methoddata_kwreal.
528 * Does a binary search to find which atoms match the ranges in the
529 * \c t_methoddata_kwreal structure for this selection.
530 * Matching atoms are stored in \p out->u.g.
532 static void evaluate_keyword_real(const gmx::SelMethodEvalContext& /*context*/,
534 gmx_ana_selvalue_t* out,
537 t_methoddata_kwreal* d = static_cast<t_methoddata_kwreal*>(data);
538 int n, i, j, jmin, jmax;
543 for (i = 0; i < g->isize; ++i)
546 if (d->r[0] > val || d->r[2 * n - 1] < val)
552 while (jmax - jmin > 1)
554 j = jmin + (jmax - jmin) / 2;
555 if (val < d->r[2 * j])
562 if (val <= d->r[2 * j + 1])
569 if (val <= d->r[2 * jmin + 1])
571 out->u.g->index[out->u.g->isize++] = g->index[i];
577 /********************************************************************
578 * STRING KEYWORD EVALUATION
579 ********************************************************************/
581 static void* init_data_kwstr(int /* npar */, gmx_ana_selparam_t* /* param */)
583 t_methoddata_kwstr* data = new t_methoddata_kwstr();
584 data->matchType = gmx::eStringMatchType_Auto;
589 * \param[in,out] sel Selection element to initialize.
590 * \param[in] matchType Method to use to match string values.
592 * Sets the string matching method for string keyword matching.
594 void _gmx_selelem_set_kwstr_match_type(const gmx::SelectionTreeElementPointer& sel,
595 gmx::SelectionStringMatchType matchType)
597 t_methoddata_kwstr* d = static_cast<t_methoddata_kwstr*>(sel->u.expr.mdata);
599 if (sel->type != SEL_EXPRESSION || !sel->u.expr.method
600 || sel->u.expr.method->name != sm_keyword_str.name)
604 d->matchType = matchType;
607 static void init_kwstr(const gmx_mtop_t* /* top */, int /* npar */, gmx_ana_selparam_t* param, void* data)
609 t_methoddata_kwstr* d = static_cast<t_methoddata_kwstr*>(data);
611 d->v = param[0].val.u.s;
612 /* Return if this is not the first time */
613 if (!d->matches.empty())
617 int n = param[1].val.nr;
618 d->matches.reserve(n);
619 for (int i = 0; i < n; ++i)
621 const char* s = param[1].val.u.s[i];
622 d->matches.emplace_back(d->matchType, s);
627 * \param data Data to free (should point to a t_methoddata_kwstr).
629 static void free_data_kwstr(void* data)
631 t_methoddata_kwstr* d = static_cast<t_methoddata_kwstr*>(data);
636 * See sel_updatefunc() for description of the parameters.
637 * \p data should point to a \c t_methoddata_kwstr.
639 * Does a linear search to find which atoms match the strings in the
640 * \c t_methoddata_kwstr structure for this selection.
641 * Wildcards are allowed in the strings.
642 * Matching atoms are stored in \p out->u.g.
644 static void evaluate_keyword_str(const gmx::SelMethodEvalContext& /*context*/,
646 gmx_ana_selvalue_t* out,
649 t_methoddata_kwstr* d = static_cast<t_methoddata_kwstr*>(data);
652 for (int i = 0; i < g->isize; ++i)
654 for (size_t j = 0; j < d->matches.size(); ++j)
656 if (d->matches[j].match(d->matchType, d->v[i]))
658 out->u.g->index[out->u.g->isize++] = g->index[i];
666 /********************************************************************
667 * KEYWORD EVALUATION FOR ARBITRARY GROUPS
668 ********************************************************************/
670 static void init_kweval(const gmx_mtop_t* top, int /* npar */, gmx_ana_selparam_t* /* param */, void* data)
672 t_methoddata_kweval* d = static_cast<t_methoddata_kweval*>(data);
674 d->kwmethod->init(top, 0, nullptr, d->kwmdata);
677 static void init_output_kweval(const gmx_mtop_t* /* top */, gmx_ana_selvalue_t* out, void* data)
679 t_methoddata_kweval* d = static_cast<t_methoddata_kweval*>(data);
681 out->nr = d->g.isize;
682 _gmx_selvalue_reserve(out, out->nr);
686 * \param data Data to free (should point to a \c t_methoddata_kweval).
688 * Frees the memory allocated for all the members of \c t_methoddata_kweval.
690 static void free_data_kweval(void* data)
692 t_methoddata_kweval* d = static_cast<t_methoddata_kweval*>(data);
698 * \param[in] context Evaluation context.
699 * \param data Should point to a \ref t_methoddata_kweval.
701 static void init_frame_kweval(const gmx::SelMethodEvalContext& context, void* data)
703 t_methoddata_kweval* d = static_cast<t_methoddata_kweval*>(data);
705 d->kwmethod->init_frame(context, d->kwmdata);
708 static void evaluate_kweval(const gmx::SelMethodEvalContext& context,
709 gmx_ana_index_t* /* g */,
710 gmx_ana_selvalue_t* out,
713 t_methoddata_kweval* d = static_cast<t_methoddata_kweval*>(data);
715 d->kwmethod->update(context, &d->g, out, d->kwmdata);
718 static void evaluate_kweval_pos(const gmx::SelMethodEvalContext& context,
719 gmx_ana_index_t* /* g */,
720 gmx_ana_selvalue_t* out,
723 t_methoddata_kweval* d = static_cast<t_methoddata_kweval*>(data);
725 d->kwmethod->pupdate(context, &d->p, out, d->kwmdata);
729 * Initializes a selection element for evaluating a keyword in a given group.
731 * \param[in] method Keyword selection method to evaluate.
732 * \param[in] params Parameters to pass to initialization (the child group).
733 * \param[in] scanner Scanner data structure.
734 * \returns Pointer to the created selection element.
736 * Implements _gmx_sel_init_keyword_evaluator() for \ref GROUP_VALUE input
739 static gmx::SelectionTreeElementPointer init_evaluator_group(gmx_ana_selmethod_t* method,
740 const gmx::SelectionParserParameterList& params,
743 if ((method->flags & (SMETH_SINGLEVAL | SMETH_VARNUMVAL)) || method->outinit || method->pupdate)
745 std::string message =
746 gmx::formatString("Keyword '%s' cannot be evaluated in this context", method->name);
747 GMX_THROW(gmx::InvalidInputError(message));
750 // TODO: For same ... as ..., some other location could be more intuitive.
751 gmx::SelectionTreeElementPointer sel(new gmx::SelectionTreeElement(
752 SEL_EXPRESSION, _gmx_sel_lexer_get_current_location(scanner)));
753 _gmx_selelem_set_method(sel, method, scanner);
755 t_methoddata_kweval* data = new t_methoddata_kweval(sel->u.expr.method, sel->u.expr.mdata);
757 snew(sel->u.expr.method, 1);
758 sel->u.expr.method->name = data->kwmethod->name;
759 sel->u.expr.method->type = data->kwmethod->type;
760 sel->u.expr.method->flags = data->kwmethod->flags | SMETH_VARNUMVAL;
761 sel->u.expr.method->init_data = nullptr;
762 sel->u.expr.method->set_poscoll = nullptr;
763 sel->u.expr.method->init = method->init ? &init_kweval : nullptr;
764 sel->u.expr.method->outinit = &init_output_kweval;
765 sel->u.expr.method->free = &free_data_kweval;
766 sel->u.expr.method->init_frame = method->init_frame ? &init_frame_kweval : nullptr;
767 sel->u.expr.method->update = &evaluate_kweval;
768 sel->u.expr.method->pupdate = nullptr;
769 sel->u.expr.method->nparams = asize(smparams_kweval_group);
770 sel->u.expr.method->param = smparams_kweval_group;
771 _gmx_selelem_init_method_params(sel, scanner);
772 sel->u.expr.mdata = data;
774 sel->u.expr.method->param[0].val.u.g = &data->g;
776 _gmx_sel_parse_params(params, sel->u.expr.method->nparams, sel->u.expr.method->param, sel, scanner);
781 * Initializes a selection element for evaluating a keyword in given positions.
783 * \param[in] method Keyword selection method to evaluate.
784 * \param[in] params Parameters to pass to initialization (the child positions).
785 * \param[in] scanner Scanner data structure.
786 * \returns Pointer to the created selection element.
788 * Implements _gmx_sel_init_keyword_evaluator() for \ref POS_VALUE input
791 static gmx::SelectionTreeElementPointer init_evaluator_pos(gmx_ana_selmethod_t* method,
792 const gmx::SelectionParserParameterList& params,
795 if ((method->flags & (SMETH_SINGLEVAL | SMETH_VARNUMVAL)) || method->outinit || method->pupdate == nullptr)
797 std::string message =
798 gmx::formatString("Keyword '%s' cannot be evaluated in this context", method->name);
799 GMX_THROW(gmx::InvalidInputError(message));
802 gmx::SelectionTreeElementPointer sel(new gmx::SelectionTreeElement(
803 SEL_EXPRESSION, _gmx_sel_lexer_get_current_location(scanner)));
804 _gmx_selelem_set_method(sel, method, scanner);
806 t_methoddata_kweval* data = new t_methoddata_kweval(sel->u.expr.method, sel->u.expr.mdata);
808 snew(sel->u.expr.method, 1);
809 sel->u.expr.method->name = data->kwmethod->name;
810 sel->u.expr.method->type = data->kwmethod->type;
811 sel->u.expr.method->flags = data->kwmethod->flags | SMETH_SINGLEVAL;
812 sel->u.expr.method->init_data = nullptr;
813 sel->u.expr.method->set_poscoll = nullptr;
814 sel->u.expr.method->init = method->init ? &init_kweval : nullptr;
815 sel->u.expr.method->outinit = nullptr;
816 sel->u.expr.method->free = &free_data_kweval;
817 sel->u.expr.method->init_frame = method->init_frame ? &init_frame_kweval : nullptr;
818 sel->u.expr.method->update = &evaluate_kweval_pos;
819 sel->u.expr.method->pupdate = nullptr;
820 sel->u.expr.method->nparams = asize(smparams_kweval_pos);
821 sel->u.expr.method->param = smparams_kweval_pos;
822 _gmx_selelem_init_method_params(sel, scanner);
823 sel->u.expr.mdata = data;
825 sel->u.expr.method->param[0].val.u.p = &data->p;
827 _gmx_sel_parse_params(params, sel->u.expr.method->nparams, sel->u.expr.method->param, sel, scanner);
831 gmx::SelectionTreeElementPointer _gmx_sel_init_keyword_evaluator(gmx_ana_selmethod_t* method,
832 const gmx::SelectionTreeElementPointer& child,
835 gmx::SelectionParserParameterList params;
836 params.push_back(gmx::SelectionParserParameter::createFromExpression(nullptr, child));
837 if (child->v.type == GROUP_VALUE)
839 return init_evaluator_group(method, params, scanner);
841 else if (child->v.type == POS_VALUE)
843 return init_evaluator_pos(method, params, scanner);
847 std::string text(_gmx_sel_lexer_get_text(scanner, child->location()));
848 std::string message =
849 gmx::formatString("Expression '%s' cannot be used to evaluate keywords", text.c_str());
850 GMX_THROW(gmx::InvalidInputError(message));