Skip to content

Shortcut: BETWEEN

Module function
Description Usage
Use a switching function to determine how many of the input variables are within a certain range. used in 0 tutorialsused in 0 eggs
output value type
a function that is one if the input falls within a particular range and zero otherwise scalar/vector/matrix

Details and examples

Use a switching function to determine how many of the input variables are within a certain range.

This action takes one argument, and evaluates the following function:

In this equation is a symmetric function that must integrate to one and that is often called a kernel function and is a smearing parameter. The above function can be used to evaluate whether is between and . The advantage of using the function above is that the resulting quantity has continuous derivatives. It can thus be used when calculating a collective variable upon which a simulation bias will be applied.

The following example, shows how we can apply the function above on the instantaneous value of the distance between atom 1 and 2. The BETWEEN action here is used to determine whether the input distance is between 0.1 and 0.2 nm.

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 ATOMSthe pair of atom that we are calculating the distance between=1,2
b: BETWEENUse a switching function to determine how many of the input variables are within a certain range. More details ARGthe values input to this function=d LOWERthe lower boundary for this particular bin=0.1 UPPERthe upper boundary for this particular bin=0.2 SMEAR the ammount to smear the Gaussian for each value in the distribution=0.5

The Kernel function

The values in the expressions above is calculated from the parameters , and that are provided using the LOWER, UPPER and SMEAR parameters respectively using the following function:

Also note that the Kernel function that is used in the first example is a Gaussian. The actual integral that is evaluated is thus:

You can achieve the same result as the first example input by 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 ATOMSthe pair of atom that we are calculating the distance between=1,2
b: BETWEENUse a switching function to determine how many of the input variables are within a certain range. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous function defined above={GAUSSIAN LOWER=0.1 UPPER=0.2 SMEAR=0.5}

The advantage of this syntax, however, is that you can replace the Gaussian kernel in the expression can be replaced by a triangular Kernel by changing the input to:

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 ATOMSthe pair of atom that we are calculating the distance between=1,2
b: BETWEENUse a switching function to determine how many of the input variables are within a certain range. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous function defined above={TRIANGULAR LOWER=0.1 UPPER=0.2 SMEAR=0.5}

With this input the integral is then evaluated using:

where:

Non rank zero arguments

Instead of passing a single scalar in the input to the BETWEEN action you can pass a single vector as shown here:

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=3,4 ATOMS3the pair of atom that we are calculating the distance between=5,6 ATOMS4the pair of atom that we are calculating the distance between=7,8
b: BETWEENUse a switching function to determine how many of the input variables are within a certain range. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous function defined above={GAUSSIAN LOWER=0.1 UPPER=0.2 SMEAR=0.5}

The input to the BETWEEN action here is a vector with four elements. The output from the action b is similarly a vector with four elements. In calculating the elements of this vector PLUMED applies the function described in the previous section on each of the distances in turn. The first element of b thus tells you if the distance between atoms 1 and 2 is between 0.1 and 0.2 nm, the second element tells you if the distance between atoms 3 and 4 is between 0.1 and 0.2 nm and so on.

You can use the commands in the above example input to evaluate the number of distances that are within the range of interest as follows:

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=3,4 ATOMS3the pair of atom that we are calculating the distance between=5,6 ATOMS4the pair of atom that we are calculating the distance between=7,8
b: BETWEENUse a switching function to determine how many of the input variables are within a certain range. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous function defined above={GAUSSIAN LOWER=0.1 UPPER=0.2 SMEAR=0.5}
s: SUMCalculate the sum of the arguments More details ARGthe vector/matrix/grid whose elements shuld be added together=b PERIODICif the output of your function is periodic then you should specify the periodicity of the function=NO
PRINTPrint quantities to a file. More details ARGthe labels of the values that you would like to print to the file=s FILEthe name of the file on which to output these quantities=colvar

The final scalar that is output here is evaluated using the following summation:

where the sum over here runs over the four distances in the above expression. This scalar tells you the number of distances that are between 0.1 and 0.2.

Notice that you can do something similar with a matrix as input as shown below:

Click on the labels of the actions for more information on what each action computes
tested on2.11
d: DISTANCE_MATRIXCalculate a matrix of distances between atoms. This action has hidden defaults. More details GROUPAwhen you are calculating the adjacency matrix between two sets of atoms this keyword is used to specify the atoms along with the keyword GROUPB=1-10 GROUPBwhen you are calculating the adjacency matrix between two sets of atoms this keyword is used to specify the atoms along with the keyword GROUPA=11-20
b: BETWEENUse a switching function to determine how many of the input variables are within a certain range. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous function defined above={GAUSSIAN LOWER=0.1 UPPER=0.2 SMEAR=0.5}
s: SUMCalculate the sum of the arguments More details ARGthe vector/matrix/grid whose elements shuld be added together=b PERIODICif the output of your function is periodic then you should specify the periodicity of the function=NO
PRINTPrint quantities to a file. More details ARGthe labels of the values that you would like to print to the file=s FILEthe name of the file on which to output these quantities=colvar

This input tells PLUMED to calculate the 100 distances between the atoms in the two input groups. The final value that is printed to the colvar file then tells you how many of these distances are between 0.1 and 0.2 nm.

The MASK keyword

Consider the following input:

Click on the labels of the actions for more information on what each action computes
tested on2.11
# Fixed virtual atom which serves as the probe volume's center (pos. in nm)
center: FIXEDATOMAdd a virtual atom in a fixed position. This action has hidden defaults. More details ATcoordinates of the virtual atom=2.5,2.5,2.5
# Vector in which element i is one if atom i is in sphere of interest and zero otherwise
sphere: INSPHEREThis quantity can be used to calculate functions of the distribution of collective variables for the atoms that lie in a particular, user-specified part of of the cell. More details ATOMSthe group of atoms that you would like to investigate=1-400 CENTERthe atom whose vicinity we are interested in examining=center RADIUSthe switching function that tells us the extent of the sphereical region of interest. Options for this keyword are explained in the documentation for LESS_THAN.={GAUSSIAN D_0=0.5 R_0=0.01 D_MAX=0.52}
# Compute the coordination numbers
adj: CONTACT_MATRIXAdjacency matrix in which two atoms are adjacent if they are within a certain cutoff. More details GROUPspecifies the list of atoms that should be assumed indistinguishable=1-400 SWITCHthe input for the switching function that acts upon the distance between each pair of atoms. Options for this keyword are explained in the documentation for LESS_THAN.={RATIONAL R_0=0.3 D_MAX=1.0} MASKa vector that is used to used to determine which rows of the adjancency matrix to compute=sphere
ones: ONESCreate a constant vector with all elements equal to one This action is a shortcut. More details SIZEthe number of ones that you would like to create=400
coord: MATRIX_VECTOR_PRODUCTCalculate the product of the matrix and the vector More details ARGthe label for the matrix and the vector/scalar that are being multiplied=adj,ones
# Determine if coordination numbers are less than 4 or not
lt: BETWEENUse a switching function to determine how many of the input variables are within a certain range. More details ARGthe values input to this function=coord MASKthe label for a sparse vector/matrix that should be used to determine which elements of the vector/matrix should be computed=sphere SWITCHThis keyword is used if you want to employ an alternative to the continuous function defined above={GAUSSIAN LOWER=4.0 UPPER=6 SMEAR=0.5}
# And calculate how many atoms in the region of interst have a coordination number that is less than four
ltsphere: CUSTOMCalculate a combination of variables using a custom expression. More details ARGthe values input to this function=lt,sphere FUNCthe function you wish to evaluate=x*y PERIODICif the output of your function is periodic then you should specify the periodicity of the function=NO
cv: SUMCalculate the sum of the arguments More details ARGthe vector/matrix/grid whose elements shuld be added together=ltsphere PERIODICif the output of your function is periodic then you should specify the periodicity of the function=NO
PRINTPrint quantities to a file. More details ARGthe labels of the values that you would like to print to the file=cv FILEthe name of the file on which to output these quantities=colvar

This input calculates the total number of atoms that are within a spherical region that is centered on the point and have a coordination number that is between 4 and 6. Notice that to reduce the computational expense we use the MASK keyword in the input to CONTACT_MATRIX so PLUMED knows to not bother calculating the coordination numbers of atoms that are not within the spherical region of interest. Further notice that we have also used this MASK keyword in the input to BETWEEN to prevent PLUMED from transforming the coordination numbers that have not been calculated with the switching function to get a further speed up.

Using the MASK keyword in this way is necessary if the input argument is a vector. If the input argument is a matrix then you should never need to use the MASK keyword. PLUMED will use the sparsity pattern for the input matrix to reduce the number of transformations that are performed within BETWEEN.

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
LOWER compulsory none the lower boundary for this particular bin
UPPER compulsory none the upper boundary for this particular bin
SMEAR compulsory 0.5 the ammount to smear the Gaussian for each value in the distribution
SWITCH optional not used This keyword is used if you want to employ an alternative to the continuous function defined above