Shortcut: MAHALANOBIS_DISTANCE
| Module | refdist |
|---|---|
| Description | Usage |
| Calculate the Mahalanobis distance between two points in CV space | |
| output value | type |
| the Mahalanobis distances between the input vectors | scalar/vector |
Details and examples
Calculate the Mahalanobis distance between two points in CV space
If we have two -dimensional vectors and we can calculate the Mahalanobis distance between the two points as
which can be expressed in matrix form as:
The inputs below shows an example where this is used to calculate the Mahalanobis distance
between the instaneous values of some torsional angles and some reference values
for these distances. The inverse covriance values are provided in the constant value with label m.
In this first example the input values are vectors:
m: CONSTANTCreate a constant value that can be passed to actions More details VALUESthe numbers that are in your constant value=2.45960237E-0001,-1.30615381E-0001,-1.30615381E-0001,2.40239117E-0001 NROWS the number of rows in your input matrix=2 NCOLS the number of columns in your matrix=2 c: 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,2 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 dd: MAHALANOBIS_DISTANCECalculate the Mahalanobis distance between two points in CV space This action is a shortcut. More details ARG1The point that we are calculating the distance from=c ARG2The point that we are calculating the distance to=d METRICThe inverse covariance matrix that should be used when calculating the distance=m PRINTPrint quantities to a file. More details ARGthe labels of the values that you would like to print to the file=dd FILEthe name of the file on which to output these quantities=colvar
while this second example does the same thing but uses scalars in input.
m: CONSTANTCreate a constant value that can be passed to actions More details VALUESthe numbers that are in your constant value=2.45960237E-0001,-1.30615381E-0001,-1.30615381E-0001,2.40239117E-0001 NROWS the number of rows in your input matrix=2 NCOLS the number of columns in your matrix=2 c1: 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=1 d1: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=1,2 c2: 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=2 d2: DISTANCECalculate the distance/s between pairs of atoms. More details ATOMSthe pair of atom that we are calculating the distance between=3,4 dd: MAHALANOBIS_DISTANCECalculate the Mahalanobis distance between two points in CV space This action is a shortcut. More details ARG1The point that we are calculating the distance from=c1,c2 ARG2The point that we are calculating the distance to=d1,d2 METRICThe inverse covariance matrix that should be used when calculating the distance=m PRINTPrint quantities to a file. More details ARGthe labels of the values that you would like to print to the file=dd FILEthe name of the file on which to output these quantities=colvar
Lastly, note that if you want to calculate the square of the distance rather than the distance you can use
the SQUARED flag as shown below:
m: CONSTANTCreate a constant value that can be passed to actions More details VALUESthe numbers that are in your constant value=2.45960237E-0001,-1.30615381E-0001,-1.30615381E-0001,2.40239117E-0001 NROWS the number of rows in your input matrix=2 NCOLS the number of columns in your matrix=2 c: 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,2 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 dd: MAHALANOBIS_DISTANCECalculate the Mahalanobis distance between two points in CV space This action is a shortcut. More details ARG1The point that we are calculating the distance from=c ARG2The point that we are calculating the distance to=d METRICThe inverse covariance matrix that should be used when calculating the distance=m SQUARED The squared distance should be calculated PRINTPrint quantities to a file. More details ARGthe labels of the values that you would like to print to the file=dd FILEthe name of the file on which to output these quantities=colvar
Calculating the square of the distance is slightly cheapter than computing the distance as you avoid taking the square root.
Dealing with periodic variables
When you are calculating a distance from a reference point you need to be careful when the input variables are periodic. If you are calculating the distance using the EUCLIDEAN_DISTANCE and NORMALIZED_EUCLIDEAN_DISTANCE commands this is not a problem. The problems are specific to the Mahalanobis distance command and have been resolved in the papers that are cited below by defining the following alternatative to the Mahalanobis distance:
In this expression, indicates the periodicity of the domain for variable . If you would like to compute this
distance with PLUMED you use the VON_MISSES shown below:
m: CONSTANTCreate a constant value that can be passed to actions More details VALUESthe numbers that are in your constant value=2.45960237E-0001,-1.30615381E-0001,-1.30615381E-0001,2.40239117E-0001 NROWS the number of rows in your input matrix=2 NCOLS the number of columns in your matrix=2 c: 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,2 d: TORSIONCalculate one or multiple torsional angles. More details ATOMS1the four atoms involved in the torsional angle=1,2,3,4 ATOMS2the four atoms involved in the torsional angle=5,6,7,8 dd: MAHALANOBIS_DISTANCECalculate the Mahalanobis distance between two points in CV space This action is a shortcut. More details ARG1The point that we are calculating the distance from=c ARG2The point that we are calculating the distance to=d METRICThe inverse covariance matrix that should be used when calculating the distance=m VON_MISSES Compute the mahalanobis distance in a way that is more sympathetic to the periodic boundary conditions PRINTPrint quantities to a file. More details ARGthe labels of the values that you would like to print to the file=dd FILEthe name of the file on which to output these quantities=colvar
Calculating multiple distances
Suppose that we now have reference configurations we can define the following distances from these reference configurations:
Lets suppose that we put the , -dimensional vectors in this expression into a matrix, , by using the DISPLACEMENT command. It is then straightforward to show that the values in the above expression are the diagonal elements of the matrix product .
We can use this idea to calculate multiple MAHALANOBIS_DISTANCE values in the following inputs. This first example calculates the three distances between the instaneoues values of two torsions and three reference configurations.
m: CONSTANTCreate a constant value that can be passed to actions More details VALUESthe numbers that are in your constant value=2.45960237E-0001,-1.30615381E-0001,-1.30615381E-0001,2.40239117E-0001 NROWS the number of rows in your input matrix=2 NCOLS the number of columns in your matrix=2 ref_psi: 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=2.25,1.3,-1.5 ref_phi: 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.91,-0.6,2.4
psi: TORSIONCalculate one or multiple torsional angles. More details ATOMSthe four atoms involved in the torsional angle=1,2,3,4 phi: TORSIONCalculate one or multiple torsional angles. More details ATOMSthe four atoms involved in the torsional angle=13,14,15,16 dd: MAHALANOBIS_DISTANCECalculate the Mahalanobis distance between two points in CV space This action is a shortcut. More details ARG2The point that we are calculating the distance to=psi,phi ARG1The point that we are calculating the distance from=ref_psi,ref_phi METRICThe inverse covariance matrix that should be used when calculating the distance=m PRINTPrint quantities to a file. More details ARGthe labels of the values that you would like to print to the file=dd FILEthe name of the file on which to output these quantities=colvar
This section example calculates the three distances between a single reference value for the two torsions and three instances of this pair of torsions.
m: CONSTANTCreate a constant value that can be passed to actions More details VALUESthe numbers that are in your constant value=2.45960237E-0001,-1.30615381E-0001,-1.30615381E-0001,2.40239117E-0001 NROWS the number of rows in your input matrix=2 NCOLS the number of columns in your matrix=2 ref_psi: 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=2.25 ref_phi: 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.91
psi: TORSIONCalculate one or multiple torsional angles. More details ATOMS1the four atoms involved in the torsional angle=1,2,3,4 ATOMS2the four atoms involved in the torsional angle=5,6,7,8 ATOMS3the four atoms involved in the torsional angle=9,10,11,12 phi: TORSIONCalculate one or multiple torsional angles. More details ATOMS1the four atoms involved in the torsional angle=13,14,15,16 ATOMS2the four atoms involved in the torsional angle=17,18,19,20 ATOMS3the four atoms involved in the torsional angle=21,22,23,24 dd: MAHALANOBIS_DISTANCECalculate the Mahalanobis distance between two points in CV space This action is a shortcut. More details ARG1The point that we are calculating the distance from=psi,phi ARG2The point that we are calculating the distance to=ref_psi,ref_phi METRICThe inverse covariance matrix that should be used when calculating the distance=m PRINTPrint quantities to a file. More details ARGthe labels of the values that you would like to print to the file=dd FILEthe name of the file on which to output these quantities=colvar
This final example then computes three distances between three pairs of torsional angles and threee reference values for these three values.
m: CONSTANTCreate a constant value that can be passed to actions More details VALUESthe numbers that are in your constant value=2.45960237E-0001,-1.30615381E-0001,-1.30615381E-0001,2.40239117E-0001 NROWS the number of rows in your input matrix=2 NCOLS the number of columns in your matrix=2 ref_psi: 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=2.25,1.3,-1.5 ref_phi: 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.91,-0.6,2.4
psi: TORSIONCalculate one or multiple torsional angles. More details ATOMS1the four atoms involved in the torsional angle=1,2,3,4 ATOMS2the four atoms involved in the torsional angle=5,6,7,8 ATOMS3the four atoms involved in the torsional angle=9,10,11,12 phi: TORSIONCalculate one or multiple torsional angles. More details ATOMS1the four atoms involved in the torsional angle=13,14,15,16 ATOMS2the four atoms involved in the torsional angle=17,18,19,20 ATOMS3the four atoms involved in the torsional angle=21,22,23,24 dd: MAHALANOBIS_DISTANCECalculate the Mahalanobis distance between two points in CV space This action is a shortcut. More details ARG1The point that we are calculating the distance from=psi,phi ARG2The point that we are calculating the distance to=ref_psi,ref_phi METRICThe inverse covariance matrix that should be used when calculating the distance=m PRINTPrint quantities to a file. More details ARGthe labels of the values that you would like to print to the file=dd FILEthe name of the file on which to output these quantities=colvar
Notice, finally, that you can also calculate multiple distances if you use the VON_MISSES option:
m: CONSTANTCreate a constant value that can be passed to actions More details VALUESthe numbers that are in your constant value=2.45960237E-0001,-1.30615381E-0001,-1.30615381E-0001,2.40239117E-0001 NROWS the number of rows in your input matrix=2 NCOLS the number of columns in your matrix=2 ref_psi: 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=2.25,1.3,-1.5 ref_phi: 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.91,-0.6,2.4
psi: TORSIONCalculate one or multiple torsional angles. More details ATOMS1the four atoms involved in the torsional angle=1,2,3,4 ATOMS2the four atoms involved in the torsional angle=5,6,7,8 ATOMS3the four atoms involved in the torsional angle=9,10,11,12 phi: TORSIONCalculate one or multiple torsional angles. More details ATOMS1the four atoms involved in the torsional angle=13,14,15,16 ATOMS2the four atoms involved in the torsional angle=17,18,19,20 ATOMS3the four atoms involved in the torsional angle=21,22,23,24 dd: MAHALANOBIS_DISTANCECalculate the Mahalanobis distance between two points in CV space This action is a shortcut. More details ARG1The point that we are calculating the distance from=psi,phi ARG2The point that we are calculating the distance to=ref_psi,ref_phi METRICThe inverse covariance matrix that should be used when calculating the distance=m VON_MISSES Compute the mahalanobis distance in a way that is more sympathetic to the periodic boundary conditions PRINTPrint quantities to a file. More details ARGthe labels of the values that you would like to print to the file=dd FILEthe name of the file on which to output these quantities=colvar
scalars must be specified in ARG2
If you use a mixture of vectors are scalars when specifying the input to to this action the vectors should be passed using the ARG1 keyword and the scalars must be passed in the ARG2 keyword as is done in the example inputs above.
Full list of keywords
The following table describes the keywords and options that can be used with this action
| Keyword | Type | Default | Description |
|---|---|---|---|
| ARG1 | compulsory | none | The point that we are calculating the distance from |
| ARG2 | compulsory | none | The point that we are calculating the distance to |
| METRIC | compulsory | none | The inverse covariance matrix that should be used when calculating the distance |
| SQUARED | optional | false | The squared distance should be calculated |
| VON_MISSES | optional | false | Compute the mahalanobis distance in a way that is more sympathetic to the periodic boundary conditions |
References
More information about how this action can be used is available in the following articles:
- G. A. Tribello, M. Ceriotti, M. Parrinello, A self-learning algorithm for biased molecular dynamics. Proceedings of the National Academy of Sciences. 107, 17509–17514 (2010)
- P. Gasparotto, R. H. Meißner, M. Ceriotti, Recognizing Local and Global Structural Motifs at the Atomic Scale. Journal of Chemical Theory and Computation. 14, 486–498 (2018)