Gromacs  2024.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Typedefs
#include <memory>
#include <string>
#include "gromacs/selection/indexutil.h"
#include "gromacs/utility/classhelpers.h"
#include "gromacs/utility/real.h"
#include "selvalue.h"
+ Include dependency graph for selelem.h:
+ This graph shows which files directly or indirectly include this file:

Description

Declares gmx::SelectionTreeElement and related things.

The selection element trees constructed by the parser and the compiler are described on the respective pages: Selection parsing and Selection compilation.

This is an implementation header: there should be no need to use it outside this directory.

Author
Teemu Murtola teemu.nosp@m..mur.nosp@m.tola@.nosp@m.gmai.nosp@m.l.com

Enumerations for expression types

enum  e_selelem_t {
  SEL_CONST, SEL_EXPRESSION, SEL_BOOLEAN, SEL_ARITHMETIC,
  SEL_ROOT, SEL_SUBEXPR, SEL_SUBEXPRREF, SEL_GROUPREF,
  SEL_MODIFIER
}
 Defines the type of a gmx::SelectionTreeElement object. More...
 
enum  e_boolean_t { BOOL_NOT, BOOL_AND, BOOL_OR, BOOL_XOR }
 Defines the boolean operation of gmx::SelectionTreeElement objects with type SEL_BOOLEAN. More...
 
enum  e_arithmetic_t {
  ARITH_PLUS, ARITH_MINUS, ARITH_NEG, ARITH_MULT,
  ARITH_DIV, ARITH_EXP
}
 Defines the arithmetic operation of gmx::SelectionTreeElement objects with type SEL_ARITHMETIC. More...
 
const char * _gmx_selelem_type_str (const gmx::SelectionTreeElement &sel)
 Returns a string representation of the type of a gmx::SelectionTreeElement. More...
 
const char * _gmx_selelem_boolean_type_str (const gmx::SelectionTreeElement &sel)
 Returns a string representation of the boolean type of a SEL_BOOLEAN gmx::SelectionTreeElement. More...
 
const char * _gmx_sel_value_type_str (const gmx_ana_selvalue_t *val)
 Returns a string representation of the type of a gmx_ana_selvalue_t. More...
 

Classes

struct  gmx::SelectionLocation
 Stores the location of a selection element in the selection text. More...
 
class  gmx::SelectionTreeElement
 Represents an element of a selection expression. More...
 

Macros

Selection expression flags

#define SEL_FLAGSSET   1
 Selection value flags are set. More...
 
#define SEL_SINGLEVAL   2
 The element evaluates to a single value. More...
 
#define SEL_ATOMVAL   4
 The element evaluates to one value for each input atom.
 
#define SEL_VARNUMVAL   8
 The element evaluates to an arbitrary number of values.
 
#define SEL_DYNAMIC   16
 The element (or one of its children) is dynamic.
 
#define SEL_UNSORTED   32
 The element may contain atom indices in an unsorted order.
 
#define SEL_VALTYPEMASK   (SEL_SINGLEVAL | SEL_ATOMVAL | SEL_VARNUMVAL)
 Mask that covers the flags that describe the number of values.
 
#define SEL_VALFLAGMASK   (SEL_FLAGSSET | SEL_VALTYPEMASK | SEL_DYNAMIC)
 Mask that covers the flags that describe the value type.
 
#define SEL_ALLOCVAL   (1 << 8)
 Data has been allocated for the v.u union. More...
 
#define SEL_ALLOCDATA   (1 << 9)
 Data has been allocated for the group/position structure. More...
 
#define SEL_INITFRAME   (1 << 10)
 method->init_frame should be called for the frame.
 
#define SEL_EVALFRAME   (1 << 11)
 Parameter has been evaluated for the current frame. More...
 
#define SEL_METHODINIT   (1 << 12)
 method->init has been called.
 
#define SEL_OUTINIT   (1 << 13)
 method->outinit has been called. More...
 

Typedefs

typedef std::shared_ptr
< SelectionTreeElement > 
gmx::SelectionTreeElementPointer
 Smart pointer type for selection tree element pointers.
 
typedef void(* gmx::sel_evalfunc )(struct gmx_sel_evaluate_t *data, const SelectionTreeElementPointer &sel, gmx_ana_index_t *g)
 Function pointer for evaluating a gmx::SelectionTreeElement.
 

Functions

Selection expression functions
void _gmx_sel_print_evalfunc_name (FILE *fp, gmx::sel_evalfunc evalfunc)
 Writes out a human-readable name for an evaluation function. More...
 
void _gmx_selelem_set_vtype (const gmx::SelectionTreeElementPointer &sel, e_selvalue_t vtype)
 Sets the value type of a gmx::SelectionTreeElement. More...
 
void _gmx_selelem_free_param (struct gmx_ana_selparam_t *param)
 Frees the memory allocated for a selection method parameter. More...
 
void _gmx_selelem_free_method (struct gmx_ana_selmethod_t *method, void *mdata)
 Frees the memory allocated for a selection method. More...
 
void _gmx_selelem_print_tree (FILE *fp, const gmx::SelectionTreeElement &sel, bool bValues, int level)
 Prints a human-readable version of a selection element subtree. More...
 
void _gmx_selelem_print_compiler_info (FILE *fp, const gmx::SelectionTreeElement &sel, int level)
 Prints a human-readable version of the internal compiler data structure. More...
 
bool _gmx_selelem_can_estimate_cover (const gmx::SelectionTreeElement &sel)
 Returns true if the covered fraction of the selection can be calculated. More...
 
real _gmx_selelem_estimate_coverfrac (const gmx::SelectionTreeElement &sel)
 Returns the covered fraction of the selection for the current frame. More...
 

Macro Definition Documentation

#define SEL_ALLOCDATA   (1 << 9)

Data has been allocated for the group/position structure.

If not set, the memory allocated for fields in v.u.g or v.u.p is managed externally.

This field has no effect if the value type is not GROUP_VALUE or POS_VALUE, but should not be set.

#define SEL_ALLOCVAL   (1 << 8)

Data has been allocated for the v.u union.

If not set, the v.u.ptr points to data allocated externally. This is the case if the value of the element is used as a parameter for a selection method or if the element evaluates the final value of a selection.

Even if the flag is set, v.u.ptr can be NULL during initialization.

Todo:
This flag overlaps with the function of v.nalloc field, and could probably be removed, making memory management simpler. Currently, the v.nalloc field is not kept up-to-date in all cases when this flag is changed and is used in places where this flag is not, so this would require a careful investigation of the selection code.
#define SEL_EVALFRAME   (1 << 11)

Parameter has been evaluated for the current frame.

This flag is set for children of SEL_EXPRESSION elements (which describe method parameters) after the element has been evaluated for the current frame. It is not set for SEL_ATOMVAL elements, because they may need to be evaluated multiple times.

#define SEL_FLAGSSET   1

Selection value flags are set.

If this flag is set, the flags covered by SEL_VALFLAGMASK have been set properly for the element.

#define SEL_OUTINIT   (1 << 13)

method->outinit has been called.

This flag is also used for SEL_SUBEXPRREF elements.

#define SEL_SINGLEVAL   2

The element evaluates to a single value.

This flag is always set for GROUP_VALUE elements.

Enumeration Type Documentation

Defines the arithmetic operation of gmx::SelectionTreeElement objects with type SEL_ARITHMETIC.

Enumerator
ARITH_PLUS 

Addition (+)

ARITH_MINUS 

Subtraction (-)

ARITH_NEG 

Unary -

ARITH_MULT 

Multiplication (*)

ARITH_DIV 

Division (/)

ARITH_EXP 

Power (^)

Defines the boolean operation of gmx::SelectionTreeElement objects with type SEL_BOOLEAN.

Enumerator
BOOL_NOT 

Not.

BOOL_AND 

And.

BOOL_OR 

Or.

BOOL_XOR 

Xor (not implemented).

Defines the type of a gmx::SelectionTreeElement object.

Enumerator
SEL_CONST 

Constant-valued expression.

SEL_EXPRESSION 

Method expression that requires evaluation.

SEL_BOOLEAN 

Boolean expression.

SEL_ARITHMETIC 

Arithmetic expression.

SEL_ROOT 

Root node of the evaluation tree.

SEL_SUBEXPR 

Subexpression that may be referenced several times.

SEL_SUBEXPRREF 

Reference to a subexpression.

SEL_GROUPREF 

Unresolved reference to an external group.

SEL_MODIFIER 

Post-processing of selection value.

Function Documentation

void _gmx_sel_print_evalfunc_name ( FILE *  fp,
gmx::sel_evalfunc  evalfunc 
)

Writes out a human-readable name for an evaluation function.

Parameters
[in]fpFile handle to receive the output.
[in]evalfuncFunction pointer to print.
const char* _gmx_sel_value_type_str ( const gmx_ana_selvalue_t val)

Returns a string representation of the type of a gmx_ana_selvalue_t.

Parameters
[in]valValue structore for which the string is requested.
Returns
Pointer to a string that corresponds to val->type, NULL if the type value is invalid.

The return value points to a string constant and should not be free'd.

const char* _gmx_selelem_boolean_type_str ( const gmx::SelectionTreeElement sel)

Returns a string representation of the boolean type of a SEL_BOOLEAN gmx::SelectionTreeElement.

Returns a string representation of the boolean type of a SEL_BOOLEAN gmx::SelectionTreeElement.

Parameters
[in]selSelection for which the string is requested
Returns
Pointer to a string that corresponds to sel->type.

The return value points to a string constant and should not be free'd.

The function returns NULL if sel->type is not one of the valid values.

bool _gmx_selelem_can_estimate_cover ( const gmx::SelectionTreeElement sel)

Returns true if the covered fraction of the selection can be calculated.

Parameters
[in]selSelection element to query.
Returns
true if the covered fraction can be estimated for sel with _gmx_selelem_estimate_coverfrac(), false otherwise.
real _gmx_selelem_estimate_coverfrac ( const gmx::SelectionTreeElement sel)

Returns the covered fraction of the selection for the current frame.

Parameters
[in]selSelection for which the fraction should be calculated.
Returns
Fraction of angles covered by the selection (between zero and one).

The return value is undefined if _gmx_selelem_can_estimate_cover() returns false. Should be called after gmx_ana_evaluate_selections() has been called for the frame.

void _gmx_selelem_free_method ( struct gmx_ana_selmethod_t method,
void *  mdata 
)

Frees the memory allocated for a selection method.

Parameters
[in]methodMethod to free.
[in]mdataMethod data to free.
void _gmx_selelem_free_param ( struct gmx_ana_selparam_t param)

Frees the memory allocated for a selection method parameter.

Parameters
[in]paramParameter to free.
void _gmx_selelem_print_compiler_info ( FILE *  fp,
const SelectionTreeElement sel,
int  level 
)

Prints a human-readable version of the internal compiler data structure.

Parameters
[in]fpFile handle to receive the output.
[in]selSelection element to print.
[in]levelIndentation level, starting from zero.
void _gmx_selelem_print_tree ( FILE *  fp,
const gmx::SelectionTreeElement sel,
bool  bValues,
int  level 
)

Prints a human-readable version of a selection element subtree.

Parameters
[in]fpFile handle to receive the output.
[in]selRoot of the selection subtree to print.
[in]bValuesIf true, the evaluated values of selection elements are printed as well.
[in]levelIndentation level, starting from zero.
void _gmx_selelem_set_vtype ( const gmx::SelectionTreeElementPointer sel,
e_selvalue_t  vtype 
)

Sets the value type of a gmx::SelectionTreeElement.

Parameters
[in,out]selSelection element to set the type for.
[in]vtypeValue type for the selection element.

If the new type is GROUP_VALUE or POS_VALUE, the SEL_ALLOCDATA flag is also set.

This function should only be called at most once for each element, preferably right after calling _gmx_selelem_create().

const char* _gmx_selelem_type_str ( const gmx::SelectionTreeElement sel)

Returns a string representation of the type of a gmx::SelectionTreeElement.

Parameters
[in]selSelection for which the string is requested
Returns
Pointer to a string that corresponds to sel->type.

The return value points to a string constant and should not be free'd.

The function returns NULL if sel->type is not one of the valid values.