PrevICM Language Reference
Arithmetics
Next

[ Assignment | Arithmetic operations | Logical_ops | Increments | Comparisons | Advanced ]

Most of the ICM-objects can be used in arithmetical, logical of comparison expressions. In this section we describe operations defined in the ICM-shell.
Members of the arithmetic, logical and comparison expressions
Abbreviations: integer ( i ), real ( r ), string ( s ), logical ( l ), iarray ( I ), rarray ( R ), sarray ( S ), matrix ( M ), sequence ( seq ), profile ( prf ). alignment ( ali ), map ( m ), graphics object (grob) ( g ), atom selections ( as ), selections of internal coordinates, for example torsion angles, ( vs ) , and table ( T ). Table arrays are abbreviated as T.I, T.R and T.S, depending on the type

Assignment


allows you to assign a value to a variable.
Syntax: ICM-shell-variable-name = Value or expression
If the name is new, a new ICM-shell variable is created , an object of the matching type will be overwritten.


Examples:

 
 a=1            # create new integer variable  a 
 b=a*a          # create variable b as product a*a 
 c=a*Sin(45.)   # create new real variable c     

Chain assignment for the logical system variables and semi-colon separated commands. Exressions like l_info=l_commands=l_warn=no are allowed for the logical system variables

Also, from version 3.6-1 several semi-colon separated commands can be specified in one line.

Assignment fo selected elements of an array:

array[I_indices] = Value

array[I_indices] = Matching_array_of_values

Several elements in integer, real and string arrays can be assigned at once to a single value , or, element-by-element to a matching array. Example:


a = {1 2 3}
a[{1 3}] = { 3 1 }
a[{1 3}] = 10

Unique name.To find a unique name for a new variable, use the Name( "nameRoot" , unique ) function.

Assignment and operations in place are also possible and it allows to modify an existing variable rather than create a new one. Example:

 
i += 1  # adds one to i, better than i = i + 1 
s += " and more .. " 
I //= 15  # append to an iarray 
R //= 1.5 # append to an rarray 
S //= "one more element" # append to an sarray 

Arithmetic operations


[ concatenation | alignment_merge ]

The following operations are defined in the ICM-shell:


Additionally, character arrays (strings) can be projected from sequence to alignment and back with the String (..) function and numerical residue properties can be projected from sequence via alignment with the Rarray (..) function.



Logical operations


Logical operations with table arrays are described separately (see table in Glossary).

In place operations.


ICM-shell variables can be modified in place by using the following operators:
operatorfunctiondata typesexample
+=add in placei,r,si += 1
-=subtract in placei,rr -= 2.2
*=multiply in placei,rr *= 2.
/=divide in placei,rr /= 2.
//=append an element to an arrayI,R,S,Pt.Name //= "Jack"

If a variable does not exist yet, this operation will create the variable and assign a type according to the right-hand operand.

Comparison operators


[ fuzzy-comparison ]

Most of them are true comparison operators and return logical yes or no. In comparisons of table arrays or string arrays with strings, the comparison returns a subtable or subarray, respectively. Comparison operations with the table arrays are described separately (see table in Glossary).

Advanced operations and some comments


[ conversions | string_plus_number | selection-precedence | selection-overlap | projected_alignment ]

  1. Integers are automatically converted to reals in binary operations containing both integers and reals. However, in expressions like integer1 / integer2 (the same for iarrays) they are not converted into reals and the result will be different from what you might expect. For example, 3/4 returns 0, but 3/4. returns 0.75.
  2. In s+i, s+r, S+I, S+R expression numbers are automatically converted into strings. In the s+s expression the second string is simply appended to the first one. Examples:
     
     show "one " + "two"  # result: "one two" 
     file = "aa"+ 4       # result: "aa4"  
     show {"a","bb"} + {1.2,3.2}  # result: {"a1.2","bb3.2"}  
    
  3. Selection arithmetics. The level of the expression as_1 & as_2 & as_3 ... or as_1 | as_2 | ... (the same with vs_ ) is defined by the lowest level selection in the chain ( atoms - the lowest < residues < molecules < objects ). For example, in an expression a_/10 | a_2/15/cg the second selection is an atom-level-selection and the first one is a residue-level one. The result is the atom selection of all atoms of residue 10 plus Cg atom from residue 15.
  4. Selection logically multiplied by string, array, or mask Multiplication of a selection to a string-mask or sequence. The resultant selection inherits level of the first argument. The mask is applied periodically to switch off some of the selected elements. For example mask "0001111" will switch off the first three elements in every seven. The 'switch off' characters may be the following: ' ' (space),'-','0'. Example masks to switch off the third element of five: "xx xx", "11011", "++-++" . Operations upon the sequence will select only the fragment with the specified sequence from the original selection. Multiplication by an array of 6 numbers {x,y,z,X,Y,Z} selects atoms within the specified box. Example:
     
     read object "crn"   # load crambin object  
     rs_ = a_/11:15      # define residue selection rs_  
     rs_ = rs_ & "xx xx" # switch off the third element (res. 13) 
     display cpk a_//* & {1. 0. 1. 5. 7. 6.} " # a box 
    
  5. Transitional (or projected) alignment Projected concatenation of two alignments sharing the same sequence. If two-sequence alignments share the same sequence, they may be merged with the shared sequence as a ruler. In the simplest case of three sequences a, b, c and alignments ab and bc, the operation ab//bc will create an alignment of three sequences a b c. The function Align(ab//bc,{1,3}) will extract the, so called, projected alignment of a and c through b.


Examples of expressions:
 
 i = i1/i2 + (i3-r4)*2.5/Pi 
 
 l_results=(l_beer & l_wine & !l_snacks) | l_vodka 
 if (l_results & n_glasses >= 4) print "Hangover.." 
 
 for i=1,215        # list streets of Manhattan north from Houston  
   print "Street " + i 
 endfor 
 
 prices = { 25. 6. 12.6 } 
 tips   = { 4.  1. 2.   } 
 print prices + tips        # the result is { 29. 7. 14.6 }  


Prev
Tree representatives
Home
Up
Next
Flow control