This is part of the function module

This function measures the Pythagorean distance from a particular structure measured in the space defined by some set of collective variables.

This collective variable can be used to calculate something akin to:

\[ d(X,X') = \vert X - X' \vert \]

where \( X \) is the instantaneous values for a set of collective variables for the system and \( X' \) is the values that these self-same set of collective variables take in some reference structure provided as input. If we call our set of collective variables \(\{s_i\}\) then this CV computes:

\[ d = \sqrt{ \sum_{i=1}^N (s_i - s_i^{(ref)})^2 } \]

where \(s_i^{(ref)}\) are the values of the CVs in the reference structure and \(N\) is the number of input CVs.

We can also calculate normalized euclidean differences using this action and the METRIC=NORM-EUCLIDEAN flag. In other words, we can compute:

\[ d = \sqrt{ \sum_{i=1}^N \sigma_i (s_i - s_i^{(ref)})^2 } \]

where \(\sigma_i\) is a vector of weights. Lastly, by using the METRIC=MAHALONOBIS we can compute Mahalonobis distances using:

\[ d = \left( \mathbf{s} - \mathbf{s}^{(ref)} \right)^T \mathbf{\Sigma} \left( \mathbf{s} - \mathbf{s}^{(ref)} \right) \]

where \(\mathbf{s}\) is a column vector containing the values of all the CVs and \(\mathbf{s}^{(ref)}\) is a column vector containing the values of the CVs in the reference configuration. \(\mathbf{\Sigma}\) is then an \(N \times N\) matrix that is specified in the input.

Compulsory keywords
TYPE ( default=EUCLIDEAN ) the manner in which the distance should be calculated
REFERENCE a file in pdb format containing the reference structure. In the PDB file the atomic coordinates and box lengths should be in Angstroms unless you are working with natural units. If you are working with natural units then the coordinates should be in your natural length unit. The charges and masses of the atoms (if required) should be inserted in the beta and occupancy columns respectively. For more details on the PDB file format visit

( default=off ) calculate the derivatives for these quantities numerically


The following input calculates the distance between a reference configuration and the instantaneous position of the system in the trajectory. The position of the reference configuration is specified by providing the values of the distance between atoms 1 and 2 and atoms 3 and 4.

PRINT ARG=t1 FILE=colvar

The contents of the file containing the reference structure (reference.pdb) is shown below. As you can see you must provide information on the labels of the CVs that are being used to define the position of the reference configuration in this file together with the values that these quantities take in the reference configuration.

DESCRIPTION: a reference point.
REMARK d1=1.0 d2=1.0