Expression Syntax

This section explains the expressions syntax with text descriptions and examples. A formal expression syntax (in EBNF) can be found on the help page of the SelectMol command. The page also contains a number of examples of selection expressions.

Constants

There are three types of constants: integer, floating point, and string. Integer constants are automatically converted to floating point when required by the context, e. g. when they are added to a floating point value.

Values

Depending on the context, an expression can use values of a data item. When an expression is evaluated for a data item, it can use the values of this item directly by just using their names. Values for related data items can be accessed by using the form item.value. E. g. when evaluating an expression for an atom, name refers to the name of the atom, while res.name refers to the name of the residue that the atom is part of. The relationships between different data items is explained as part of the section about advanced selection topics.

A table of available values was given in a previous section.

Properties

Properties are similar to the values described in the previous section. One main difference is that they can be defined by the user, either with commands like DefPropAtom, or by adding them to the set of standard properties, as documented in the section about configuration. Another difference to values is that the type of properties is always boolean.

A table of predefined properties was given in a previous section.

Operators

Most common arithmetic and logical operators are supported in expressions. The following table lists all operators with the type of their operands and the type of the result, in order of precedence. Operators with higher precedence are evaluated before operators with lower precedence. Evaluation of operators with the same precedence is left to right. This evaluation order can be changed by using parantheses. The table also indicates whether an operator is unary (has one operand) or binary (has two operands).
operatorkindprecedence operandresultdescription
-unary6 integerintegernumerical negation
-unary6 floatfloatnumerical negation
sqrtunary6 floatfloatsquare root
logunary6 floatfloatnatural logarithm
!unary6 boolboollogical negation
notunary6 boolboollogical negation
*binary5 integerintegermultiplication
*binary5 floatfloatmultiplication
/binary5 integerintegerdivision
/binary5 floatfloatdivision
%binary5 integerintegerremainder
+binary4 integerintegeraddition
+binary4 floatfloataddition
-binary4 integerintegersubtraction
-binary4 floatfloatsubtraction
=binary3 integerboolequal
=binary3 floatboolequal
=binary3 stringboolequal (with wildcards)
!=binary3 integerboolnot equal
!=binary3 floatboolnot equal
!=binary3 stringboolnot equal (with wildcards)
<binary3 integerboolless
<binary3 floatboolless
<=binary3 integerboolless or equal
<=binary3 floatboolless or equal
>binary3 integerboolgreater
>binary3 floatboolgreater
>=binary3 integerboolgreater or equal
>=binary3 floatboolgreater or equal
&binary2 boolboollogical and
andbinary2 boolboollogical and
|binary1 boolboollogical or
orbinary1 boolboollogical or
Note that the string comparison operators support wildcards, ? matches one character, *matches any number of characters.
Last modified: Mon Jan 20 19:44:57 CST 2003

Reto Koradi, kor@mol.biol.ethz.ch