Skip to content

Shortcut: SORT

Module function
Description Usage
This function can be used to sort colvars according to their magnitudes. used in 1 tutorialsused in 2 eggs
output value type
sorted vector

Details and examples

This function can be used to sort colvars according to their magnitudes.

This action sorts the input arguments according to their magnitudes. It will output the same number of values as it has arguments. The lowest argument input will be output as a value labelled label.1, the second lowest input argument will be output as a value labelled label.2 and so on. Thus, for example, the following input can be used to print the distance of the closest and of the farthest atoms to atom 1, chosen among atoms from 2 to 5

Click on the labels of the actions for more information on what each action computes
tested on2.11
d12:  DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=1,2
d13:  DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=1,3
d14:  DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=1,4
d15:  DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=1,5
sort: SORTThis function can be used to sort colvars according to their magnitudes. More details ARGthe values input to this function=d12,d13,d14,d15
PRINTPrint quantities to a file. More details ARGthe labels of the values that you would like to print to the file=sort.1,sort.4

Notice that you can also achieve the same result using the following input:

Click on the labels of the actions for more information on what each action computes
tested on2.11
d: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMS1the pair of atom that we are calculating the distance between=1,2 ATOMS2the pair of atom that we are calculating the distance between=1,3 ATOMS3the pair of atom that we are calculating the distance between=1,4 ATOMS4the pair of atom that we are calculating the distance between=1,5
sort: SORTThis function can be used to sort colvars according to their magnitudes. More details ARGthe values input to this function=d
PRINTPrint quantities to a file. More details ARGthe labels of the values that you would like to print to the file=sort.1,sort.4

In this second case the four distances are passed to the SORT action as a vector. The SORT action then outputs 4 components - the same number of components as there are elements in the input vector - that contain the elements of the input vector in order of increasing magnitude.

These examples are representative the only two ways you can use this action. In input it can accept either a list of scalars or a single vector. It does not accept matrices or a list of vectors in input.

Using multiple vectors in input

If you input multiple vectors with the same numbers of elements to this action, as shown below, the output will be a set of vectors.

Click on the labels of the actions for more information on what each action computes
tested on2.11
d1: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMS1the pair of atom that we are calculating the distance between=1,2 ATOMS2the pair of atom that we are calculating the distance between=3,4
d2: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMS1the pair of atom that we are calculating the distance between=5,6 ATOMS2the pair of atom that we are calculating the distance between=7,8
d3: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMS1the pair of atom that we are calculating the distance between=9,10 ATOMS2the pair of atom that we are calculating the distance between=11,12
sort: SORTThis function can be used to sort colvars according to their magnitudes. More details ARGthe values input to this function=d1,d2,d3
PRINTPrint quantities to a file. More details ARGthe labels of the values that you would like to print to the file=sort.1,sort.2,sort.3 FILEthe name of the file on which to output these quantities=colvar

The elements of the three output vector here are determined by doing an elementwise comparison of the elements in the input vectors. In the above input the first element of sort.1 is equal to the distance between atoms 1 and 2 if this distance is smaller than the distances between atoms 5 and 6 and the distance between atoms 9 and 10. By the same token the second element of sort.1 is equal to the distance between atoms 3 and 4 if this is smaller than the distance between atoms 7 and 8 and the distance between atoms 11 and 12. The elements of sort.2 are the second largest of these distances, while the elements of sort.3 are three largest distances

Notice that you can also use a combination of scalars and vectors in the input to this action as shown below:

Click on the labels of the actions for more information on what each action computes
tested on2.11
c: CONSTANTCreate a constant value that can be passed to actions This action has hidden defaults. More details VALUEthe single number that you would like to store=0.5
d: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMS1the pair of atom that we are calculating the distance between=1,2 ATOMS2the pair of atom that we are calculating the distance between=3,4
sort: SORTThis function can be used to sort colvars according to their magnitudes. More details ARGthe values input to this function=d,c
PRINTPrint quantities to a file. More details ARGthe labels of the values that you would like to print to the file=sort.1,sort.2 FILEthe name of the file on which to output these quantities=colvar

For the input above the SORT action outputs two vectors with two elements. The elements of sort.1 are equal to the distances between the pairs of atoms that are specified in the DISTANCE command as long as those distances are less than 0.5 nm. If either of the two input distances is more than 0.5 nm then the corresponding value in the vector h is set equal to 0.5 nm. Similarly, the elements of sort.2 are equal to the distances between of the atoms that are specified in the DISTANCE command as long as those distances are more than 0.5 nm.

The MASK keyword

You should only use the MASK keyword for this action if you are using multiple arguments and at least one vector in the input to this action. The following input illustrates how this keyword works:

Click on the labels of the actions for more information on what each action computes
tested on2.11
m: CONSTANTCreate a constant value that can be passed to actions This action has hidden defaults. More details VALUESthe numbers that are in your constant value=1,0
d1: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMS1the pair of atom that we are calculating the distance between=1,2 ATOMS2the pair of atom that we are calculating the distance between=3,4
d2: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMS1the pair of atom that we are calculating the distance between=5,6 ATOMS2the pair of atom that we are calculating the distance between=7,8
d3: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMS1the pair of atom that we are calculating the distance between=9,10 ATOMS2the pair of atom that we are calculating the distance between=11,12
sort: SORTThis function can be used to sort colvars according to their magnitudes. More details ARGthe values input to this function=d1,d2,d3 MASKthe label for a sparse vector/matrix that should be used to determine which elements of the vector/matrix should be computed=m

By using the MASK keyword here you ensure that only the first elements of the output vectors for sort is calculated. These elements of the output vectors are evaluated as the corresponding element of the vector that is passed in the input to the MASK keyword is one. By the same logic the second element of the output vectors are not computed because the corresponding element in the mask vector is 0.

The input above illustrates the key idea for the MASK keyword and is probably not very useful. To see an example where using a MASK for this type of action is useful you should look at the expanded shortcuts in the documentation for PARABETARMSD.

Input

The arguments that serve as the input for this action are specified using one or more of the keywords in the following table.

Keyword Type Description
ARG scalar/vector/matrix the values input to this function
MASK vector/matrix the label for a sparse vector/matrix that should be used to determine which elements of the vector/matrix should be computed

Full list of keywords

The following table describes the keywords and options that can be used with this action

Keyword Type Default Description
ARG input none the values input to this function
MASK input none the label for a sparse vector/matrix that should be used to determine which elements of the vector/matrix should be computed