Shortcut: LESS_THAN
| Module | function |
|---|---|
| Description | Usage |
| Use a switching function to determine how many of the input variables are less than a certain cutoff. | |
| output value | type |
| a function that is one if the input is less than a threshold | scalar/vector/matrix |
Details and examples
Use a switching function to determine how many of the input variables are less than a certain cutoff.
This action takes one argument, and evaluates the following function:
The function here is a switching function so the output value is a number between 0 and 1. Switching functions are typically used to determine if an input value is less than some cutoff. The value of the switches smoothly from one to zero as the input value crosses the threshold of interest.
The following example, shows how we can apply a switching function on the instantaneous value of the distance between atom 1 and atom 2.
d: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=1,2 s: LESS_THANUse a switching function to determine how many of the input variables are less than a certain cutoff. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous swiching function defined above={RATIONAL R_0=0.2}
The output here is close to one when the distance between atoms 1 and 2 is less than 0.2 nm close to zero for values that are greater than 0.2.
Transforming squares of quantities
If you have computed the square of the distance you can use the flag SQUARED to indicate that the input quantity is the square of the distance as indicated below:
d: DISTANCECalculate the distance/s between pairs of atoms. More details COMPONENTS calculate the x, y and z components of the distance separately and store them as label ATOMSthe pair of atom that we are calculating the distance between=1,2 dm: CUSTOMCalculate a combination of variables using a custom expression. More details ARGthe values input to this function=d.x,d.y,d.z FUNCthe function you wish to evaluate=x*x+y*y+z*z PERIODICif the output of your function is periodic then you should specify the periodicity of the function=NO s: LESS_THANUse a switching function to determine how many of the input variables are less than a certain cutoff. More details ARGthe values input to this function=dm SQUARED is the input quantity the square of the value that you would like to apply the switching function to SWITCHThis keyword is used if you want to employ an alternative to the continuous swiching function defined above={RATIONAL R_0=0.2}
This option can be useful for improving performance by removing the expensive square root operations.
Non rank zero arguments
Instead of passing a single scalar in the input to the LESS_THAN action you can pass a single vector as shown here:
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: LESS_THANUse a switching function to determine how many of the input variables are less than a certain cutoff. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous swiching function defined above={RATIONAL R_0=0.2}
The input to the LESS_THAN 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 less than
0.2 nm, the second element tells you if the distance between atoms 3 and 4 is less than 0.2 nm and so on.
You can use the commands in the above example input to evaluate the number of distances that are less than a cutoff as follows:
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: LESS_THANUse a switching function to determine how many of the input variables are less than a certain cutoff. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous swiching function defined above={RATIONAL R_0=0.2} 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 less than 0.2 nm.
Notice that you can do something similar with a matrix as input as shown below:
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: LESS_THANUse a switching function to determine how many of the input variables are less than a certain cutoff. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous swiching function defined above={RATIONAL R_0=0.2} 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 less than 0.2 nm.
The MASK keyword
Consider the following input:
# 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: LESS_THANUse a switching function to determine how many of the input variables are less than a certain cutoff. 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 swiching function defined above={RATIONAL R_0=4.0} # 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 less than 4. 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 LESS_THAN 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 LESS_THAN.
Switching functions types
PLUMED allows you to use a range of different switching function types. Most of these require you to provide at least one input parameter . The switching function is then defined so that for while for the function decays smoothly to 0. By changing the switching function you are using you change the decay that occurs in the switching function for values that are greater that .
You can specify the value at which the the switching function goes to zero by using the D_MAX keyword. PLUMED will ensure that the swtiching function is definitely zero for for input values that are greater than or equal to D_MAX by by stretching and shifting the function using the following transformations.
The various expressions that are used for in the above expression are described in the following sections.
Scaling the switching function so that it is exactly zero at using the transformation described above
has been the default behaviour within PLUMED since version 2.2.
If you wish to use a D_MAX parameter and the functions described in the following sections directly you can use the
keyword NOSTRETCH. However, the advangage of performing the stretching and scaling in this way is that the function has
no discontinuities. If you use the NOSTRETCH option the switching function may have a discontinuity at .
Rational switching function
The rational switching function is the most commonly used of the switching functions. The implementation of this function within PLUMED has been carefully optimised so calculations using this switching function should be fast.
For this function has the following functional form:
The following example illustrates how you can use the rational switching function is used in practice:
d: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=1,2 s: LESS_THANUse a switching function to determine how many of the input variables are less than a certain cutoff. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous swiching function defined above={RATIONAL R_0=0.5 D_0=0.1 NN=8 MM=16 D_MAX=1.0}
As was discussed in earlier parts of this page, you can also specify a rational switching function using the following input:
d: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=1,2 s: LESS_THANUse a switching function to determine how many of the input variables are less than a certain cutoff. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous swiching function defined above={RATIONAL R_0=0.2}
In this case, the paramers , and are set to their default values of 0, 6 and 12 respectively. Meanwhile, if D_MAX is unset the stretching and scaling that was described in the previous section is not performed.
Notice that you can choose to set a subset of the switching function parameters and to use the default values for the unset parameters by using an input like this one:
d: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=1,2 s: LESS_THANUse a switching function to determine how many of the input variables are less than a certain cutoff. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous swiching function defined above={RATIONAL R_0=0.2 NN=8}
The input above sets and . Meanwhile, is set to its default value of 0.
Lastly, note that you can also specify the parameters for the rational switching function without using the SWITCH keyword as indicated below:
d: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=1,2 s: LESS_THANUse a switching function to determine how many of the input variables are less than a certain cutoff. More details ARGthe values input to this function=d D_0 The d_0 parameter of the switching function=0.1 R_0The r_0 parameter of the switching function=0.2 NN The n parameter of the switching function =6 MM The m parameter of the switching function; 0 implies 2*NN=12
The newer syntax using the SWITCH keyword is better than this option as there is no way to set the D_MAX parameter this way and because if you use this syntax you are forced to use the RATIONAL switching function type.
Exponential switching function
The way that the exponential switching function can be used is illustrated in the following example input:
d: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=1,2 s: LESS_THANUse a switching function to determine how many of the input variables are less than a certain cutoff. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous swiching function defined above={EXP D_0=0.1 R_0=0.2 D_MAX=1.0}
The that is used in this input is given by the following expression:
You can also specify that an exponential switching function is to be used by using the following input:
d: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=1,2 s: LESS_THANUse a switching function to determine how many of the input variables are less than a certain cutoff. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous swiching function defined above={EXP R_0=0.2}
For this input is set to its default value of 0. Furthermore, as D_MAX is unset the stretching and scaling that was described in the previous section is not performed.
Gaussian switching function
The way that the gaussian switching function can be used is illustrated in the following example input:
d: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=1,2 s: LESS_THANUse a switching function to determine how many of the input variables are less than a certain cutoff. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous swiching function defined above={GAUSSIAN D_0=0.1 R_0=0.2 D_MAX=1.0}
The that is used in this input is given by the following expression:
You can also specify that an gaussian switching function is to be used by using the following input:
d: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=1,2 s: LESS_THANUse a switching function to determine how many of the input variables are less than a certain cutoff. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous swiching function defined above={GAUSSIAN R_0=0.2}
For this input is set to its default value of 0. Furthermore, as D_MAX is unset the stretching and scaling that was described in the previous section is not performed.
Sketch-map switching function
You can specify that the sketch-map switching function is to be used by using the following input:
d: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=1,2 s: LESS_THANUse a switching function to determine how many of the input variables are less than a certain cutoff. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous swiching function defined above={SMAP D_0=1 R_0=4 A=3 B=2 D_MAX=10}
The that is used in this input is given by the following expression:
This type of swtiching function would be used with PLUMED's implementation of SKETCHMAP. If you are performing a sketch-map projection an input like the one below would be more common:
d: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=1,2 s: LESS_THANUse a switching function to determine how many of the input variables are less than a certain cutoff. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous swiching function defined above={SMAP R_0=4 A=3 B=2}
With this input is set to its default value of 0. Furthermore, as D_MAX is unset the stretching and scaling that was described in the previous section is not performed.
Q switching function
You can specify that the Q switching function is to be used by using the following input:
d: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=1,2 s: LESS_THANUse a switching function to determine how many of the input variables are less than a certain cutoff. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous swiching function defined above={Q D_0=0 REF=0.498366 BETA=50.0 LAMBDA=1.8 R_0=0.01 D_MAX=20}
The that is used in this input is given by the following expression:
The value of is specified in the above input by the REF keyword. Notice that you can also specify this type of switching function using
the following input:
d: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=1,2 s: LESS_THANUse a switching function to determine how many of the input variables are less than a certain cutoff. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous swiching function defined above={Q REF=0.498366 R_0=0.01 }
With this input , and are set equal to their default values of 0, 1.8 and 50 nm respectively. Furthermore, as D_MAX is unset the stretching and scaling that was described in the previous section is not performed. These default values for and are suitable if you are simulating all atom models. However, if you are using a coarse grainded models values of and are more appropriate.
Cubic switching function
You can specify that the cubic swtiching function is to be used by using the following input:
d: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=1,2 s: LESS_THANUse a switching function to determine how many of the input variables are less than a certain cutoff. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous swiching function defined above={CUBIC D_0=0.1 D_MAX=0.5}
If this type of expression is used then the is calculated as:
No stretching is required for this type of switching function as its functional form ensures that it is zero at .
Tanh switching function
You can specify that the cubic swtiching function is to be used by using the following input:
d: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=1,2 s: LESS_THANUse a switching function to determine how many of the input variables are less than a certain cutoff. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous swiching function defined above={TANH D_0=0.1 R_0=0.1 D_MAX=1.0}
The that is used in this input is given by the following expression:
You can also specify that a tanh switching function is to be used by using the following input:
d: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=1,2 s: LESS_THANUse a switching function to determine how many of the input variables are less than a certain cutoff. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous swiching function defined above={TANH R_0=0.2}
For this input is set to its default value of 0. Furthermore, as D_MAX is unset the stretching and scaling that was described in the previous section is not performed.
Cosinus switching function
You can specify that the cosinum function is to be used by using the following input:
d: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=1,2 s: LESS_THANUse a switching function to determine how many of the input variables are less than a certain cutoff. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous swiching function defined above={COSINUS D_0=0.1 R_0=0.1}
The that is used in this input is given by the following expression:
No stretching is required for this type of switching function as its functional form ensures that it is zero at
Custom switching function
If you want to use a switching function that is different to all of the functions listed above you can use the cusom option that is illustrated below:
d: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=1,2 s: LESS_THANUse a switching function to determine how many of the input variables are less than a certain cutoff. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous swiching function defined above={CUSTOM FUNC=1/(1+x^6) D_0=0.1 R_0=0.1 D_MAX=10}
This option allows you to use the lepton library that is used to implement the CUSTOM action to evaluate your switching function. With this
option you specify the functional form for by providing a function of x to the FUNC keyword. The x that enters the switching function
definition that you provide is given by:
Notice, that you can also express your switching function in terms of as illustrated in the input below:
d: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=1,2 s: LESS_THANUse a switching function to determine how many of the input variables are less than a certain cutoff. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous swiching function defined above={CUSTOM FUNC=1/(1+x2^3) D_0=0.1 R_0=0.1 D_MAX=10}
which is equivalent to the earlier input with the CUSTOM switching function. However, using x2 in place of x is often more computationally efficient
as you can avoid an expensive square root operation. Notice, lastly, that just as there is a MATHEVAL action that is equivalent to CUSTOM,
there is also a matheval equivalent that you can use here:
d: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=1,2 s: LESS_THANUse a switching function to determine how many of the input variables are less than a certain cutoff. More details ARGthe values input to this function=d SWITCHThis keyword is used if you want to employ an alternative to the continuous swiching function defined above={MATHEVAL FUNC=1/(1+x2^3) R_0=0.1}
For this input is set to its default value of 0. Furthermore, as D_MAX is unset the stretching and scaling that was described in the previous section is not performed.
performance of CUSTOM
With the default implementation CUSTOM is slower than other functions (e.g., it is slower than an equivalent RATIONAL function by approximately a factor 2). You can find information on how to improve its performance in the documenation for CUSTOM
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 |
| NN | compulsory | 6 | The n parameter of the switching function |
| MM | compulsory | 0 | The m parameter of the switching function; 0 implies 2*NN |
| D_0 | compulsory | 0.0 | The d_0 parameter of the switching function |
| R_0 | compulsory | none | The r_0 parameter of the switching function |
| SWITCH | optional | not used | This keyword is used if you want to employ an alternative to the continuous swiching function defined above |
| SQUARED | optional | false | is the input quantity the square of the value that you would like to apply the switching function to |