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 written in the usual decimal
notation.
Examples: 7, 395.
- Floating point constants are written in the ususal
notation, with a decimal point. The scientific
notation (indicated with the letter e
or E) is also supported, the decimal
point is optional for numbers with exponent.
Examples: 5.3, 23.478e17,
3.59E-5, 1E3.
- String constants are enclosed in double quotes.
If double quotes are used inside a string, they
have to be escaped by a \ (backslash).
If a string is used as part of a command argument,
single quotes also have to be escaped by a
\ because they are used for enclosing
each argument.
Examples: "hello", "Hello World!".
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).
operator | kind | precedence |
operand | result | description |
- | unary | 6 |
integer | integer | numerical negation |
- | unary | 6 |
float | float | numerical negation |
sqrt | unary | 6 |
float | float | square root |
log | unary | 6 |
float | float | natural logarithm |
! | unary | 6 |
bool | bool | logical negation |
not | unary | 6 |
bool | bool | logical negation |
* | binary | 5 |
integer | integer | multiplication |
* | binary | 5 |
float | float | multiplication |
/ | binary | 5 |
integer | integer | division |
/ | binary | 5 |
float | float | division |
% | binary | 5 |
integer | integer | remainder |
+ | binary | 4 |
integer | integer | addition |
+ | binary | 4 |
float | float | addition |
- | binary | 4 |
integer | integer | subtraction |
- | binary | 4 |
float | float | subtraction |
= | binary | 3 |
integer | bool | equal |
= | binary | 3 |
float | bool | equal |
= | binary | 3 |
string | bool | equal (with wildcards) |
!= | binary | 3 |
integer | bool | not equal |
!= | binary | 3 |
float | bool | not equal |
!= | binary | 3 |
string | bool | not equal (with wildcards) |
< | binary | 3 |
integer | bool | less |
< | binary | 3 |
float | bool | less |
<= | binary | 3 |
integer | bool | less or equal |
<= | binary | 3 |
float | bool | less or equal |
> | binary | 3 |
integer | bool | greater |
> | binary | 3 |
float | bool | greater |
>= | binary | 3 |
integer | bool | greater or equal |
>= | binary | 3 |
float | bool | greater or equal |
& | binary | 2 |
bool | bool | logical and |
and | binary | 2 |
bool | bool | logical and |
| | binary | 1 |
bool | bool | logical or |
or | binary | 1 |
bool | bool | logical 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