Data Set Math
Operations with data sets
As of version 15, CPPTRAJ can perform basic math operations, even on data sets (with some limitations). Currently recognized operations are:
Operation | Symbol |
Minus | – |
Plus | + |
Divide | / |
Multiply | * |
Power | ^ |
Negate | – |
Assign | + |
Several functions are also supported:
Function | Form |
Square Root | sqrt() |
Exponential | exp() |
Natural Logarith | ln() |
Absolute Value | abs() |
Sine | sin() |
Cosine | cos() |
Tangent | tan() |
Summation | sum() |
Average | avg() |
Standard Deviation | stdev() |
Minimum | min() |
Maximum | max() |
Numbers can be expressed in scientific notation using “E” notation, e.g. 1E-5 = 0.00001. The parser also recognizes PI as the number pi. Expressions can also be enclosed in parentheses. So for example, the following expression is valid:
> 1 - ln(sin(PI/4) * 2)^2
Result: 0.879887
Results of numerical calculations like the above can be assigned to a variable (essentially a data set of size 1) for use in subsequent calculations, e.g.
> R = 1 - ln(sin(PI/4) * 2)^2
Result stored in ’R’
> R + 1 Result: 1.879887
Data sets can be specified in expressions as well. Currently data sets in an expression must be of the same type and only 1D, 2D, and 3D data sets are supported. Functions are applied to each member of the data set. So for example, given two 1D data sets of the same size named D0 and D1, the following expression:
> D2 = sqrt( D0 ) + D1
would take the square root of each member of D0, add it to the corresponding member of D1, and assign the result to D2. The following table lists which operations are valid for data set types. If a type is not listed it is not supported:
Data Set Type | Supported Ops | Supported Functions | Notes |
1D (integer.double, float) | All | All | |
1D (vector) | +,-,*,/,= | None | ‘*’ is dot product |
2D (matrices) | +,-,*,/,= | sum, avg, stdev, min, mix | |
3D (grids) | +,-,*,/,= | sum, avg, stdev, min, mix |