COLLECTIVE VARIABLES MODULE

Reference manual for LAMMPS


Code version: 2025-08-22

Updated versions of this manual: [GROMACS] [LAMMPS] [NAMD] [Tinker-HP] [VMD]

Colvars logo
Alejandro Bernardin, Haochuan Chen, Jeffrey R. Comer, Giacomo Fiorin, Haohao Fu, Jérôme Hénin, Axel Kohlmeyer, Fabrizio Marinelli, Hubert Santuz, Joshua V. Vermaas, Andrew D. White, Wei Zhang

(PDF version)

Contents

 1 Overview
 2 Writing a Colvars configuration: a crash course
 3 Enabling and controlling the Colvars module in LAMMPS
  3.1 Units in the Colvars module
  3.2 LAMMPS keywords
  3.3 Using the scripting interface to control the Colvars module
   3.3.1 Setting up the Colvars module
   3.3.2 Loading and saving the Colvars state and other information
   3.3.3 Accessing atomic data
   3.3.4 Managing collective variables
   3.3.5 Applying and analyzing forces on collective variables
   3.3.6 Managing collective variable biases
   3.3.7 Loading and saving the state of individual biases
  3.4 Configuration syntax used by the Colvars module
  3.5 Global keywords
  3.6 Input state file
   3.6.1 Restarting in LAMMPS.
   3.6.2 Changing configuration upon restarting.
  3.7 Output files
  3.8 File formats
   3.8.1 Configuration and state files.
   3.8.2 Index (NDX) files
   3.8.3 XYZ coordinate files
   3.8.4 Grid files: multicolumn text format
   3.8.5 Output trajectory files
 4 Defining collective variables
  4.1 Choosing a function
  4.2 Treatment of periodic boundary conditions
  4.3 Distances
   4.3.1 distance: center-of-mass distance between two groups.
   4.3.2 distanceZ: projection of a distance vector on an axis.
   4.3.3 distanceXY: modulus of the projection of a distance vector on a plane.
   4.3.4 distanceVec: distance vector between two groups.
   4.3.5 distanceDir: distance unit vector between two groups.
   4.3.6 distanceInv: mean distance between two groups of atoms.
  4.4 Angles
   4.4.1 angle: angle between three groups.
   4.4.2 dipoleAngle: angle between two groups and dipole of a third group.
   4.4.3 dihedral: torsional angle between four groups.
   4.4.4 polarTheta: polar angle in spherical coordinates.
   4.4.5 polarPhi: azimuthal angle in spherical coordinates.
  4.5 Contacts
   4.5.1 coordNum: coordination number between two groups.
   4.5.2 selfCoordNum: coordination number between atoms within a group.
   4.5.3 hBond: hydrogen bond between two atoms.
  4.6 Collective metrics
   4.6.1 rmsd: root mean square displacement (RMSD) from reference positions.
   4.6.2 Advanced usage of the rmsd component.
   4.6.3 eigenvector: projection of the atomic coordinates on a vector.
   4.6.4 gyration: radius of gyration of a group of atoms.
   4.6.5 inertia: total moment of inertia of a group of atoms.
   4.6.6 dipoleMagnitude: dipole magnitude of a group of atoms.
   4.6.7 inertiaZ: total moment of inertia of a group of atoms around a chosen axis.
  4.7 Rotations
   4.7.1 orientation: orientation from reference coordinates.
   4.7.2 orientationAngle: angle of rotation from reference coordinates.
   4.7.3 orientationProj: cosine of the angle of rotation from reference coordinates.
   4.7.4 spinAngle: angle of rotation around a given axis.
   4.7.5 tilt: cosine of the rotation orthogonal to a given axis.
   4.7.6 eulerPhi: Roll angle from references coordinates.
   4.7.7 eulerTheta: Pitch angle from references coordinates.
   4.7.8 eulerPsi: Yaw angle from references coordinates.
  4.8 Protein structure descriptors
   4.8.1 alpha: α-helix content of a protein segment.
   4.8.2 dihedralPC: protein dihedral principal component
  4.9 Raw data: building blocks for custom functions
   4.9.1 cartesian: vector of atomic Cartesian coordinates.
   4.9.2 distancePairs: set of pairwise distances between two groups.
  4.10 Geometric path collective variables
   4.10.1 gspath: progress along a path defined in atomic Cartesian coordinate space.
   4.10.2 gzpath: distance from a path defined in atomic Cartesian coordinate space.
   4.10.3 linearCombination: Helper CV to define a linear combination of other CVs
   4.10.4 customColvar: Helper CV to define a mathematical expression as CV from other CVs
   4.10.5 gspathCV: progress along a path defined in CV space.
   4.10.6 gzpathCV: distance from a path defined in CV space.
  4.11 Arithmetic path collective variables
   4.11.1 aspathCV: progress along a path defined in CV space.
   4.11.2 azpathCV: distance from a path defined in CV space.
   4.11.3 aspath: progress along a path defined in atomic Cartesian coordinate space.
   4.11.4 azpath: distance from a path defined in atomic Cartesian coordinate space.
  4.12 Dense neural network in CV space (MLCV)
  4.13 Torch-based collective variables
  4.14 Shared keywords for all components
  4.15 Periodic components
  4.16 Non-scalar components
   4.16.1 Calculating total forces
  4.17 Linear and polynomial combinations of components
  4.18 Custom functions
  4.19 Defining grid parameters for a colvar
  4.20 Trajectory output
  4.21 Extended Lagrangian
  4.22 Multiple time-step variables
  4.23 Backward-compatibility
  4.24 Statistical analysis
 5 Selecting atoms
  5.1 Atom selection keywords
  5.2 Moving frame of reference.
  5.3 Treatment of periodic boundary conditions.
  5.4 Performance of a Colvars calculation based on group size.
 6 Biasing and analysis methods
  6.1 Defining grids for biasing and analysis methods
  6.2 Thermodynamic integration
  6.3 Adaptive Biasing Force
   6.3.1 ABF requirements on collective variables
   6.3.2 Parameters for ABF
   6.3.3 Multiple-walker ABF
   Output files of multiple-walker ABF.
   6.3.4 Output files
   6.3.5 Multidimensional free energy surfaces
  6.4 Extended-system Adaptive Biasing Force (eABF)
   6.4.1 CZAR estimator of the free energy
  6.5 Adiabatic Bias Molecular Dynamics (ABMD)
  6.6 Metadynamics
   6.6.1 Treatment of the PMF boundaries
   6.6.2 Required metadynamics keywords
   6.6.3 Output files
   6.6.4 Performance optimization
   6.6.5 Ensemble-Biased Metadynamics
   6.6.6 Well-tempered metadynamics
   6.6.7 Multiple-walker metadynamics
  6.7 On-the-fly probability enhanced sampling (OPES)
   6.7.1 Implementation notes
   6.7.2 General options
   6.7.3 Multiple-walker options
   6.7.4 Output options
   6.7.5 Example input
  6.8 Harmonic restraints
   6.8.1 Moving restraints: steered molecular dynamics
   6.8.2 Moving restraints: umbrella sampling
   6.8.3 Changing force constant
  6.9 Computing the work of a changing restraint
  6.10 Harmonic wall restraints
  6.11 Linear restraints
  6.12 Adaptive Linear Bias/Experiment Directed Simulation
  6.13 Multidimensional histograms
   6.13.1 Output options for multi-dimensional histograms
   6.13.2 Histogramming vector variables
  6.14 Probability distribution-restraints
 7 fix_modify command-line interface: list of commands
  7.1 Commands to manage the Colvars module
  7.2 Commands to manage individual collective variables
  7.3 Commands to manage individual biases
 8 Syntax changes from older versions
 9 Compilation notes

1 Overview

In molecular dynamics simulations, it is often useful to reduce the large number of degrees of freedom of a physical system into few parameters whose statistical distributions can be analyzed individually, or used to define biasing potentials to alter the dynamics of the system in a controlled manner. These have been called ‘order parameters', ‘collective variables', ‘(surrogate) reaction coordinates', and many other terms.

Here we use primarily the term ‘collective variable', often shortened to colvar, to indicate any differentiable function of atomic Cartesian coordinates, xi, with i between 1 and N, the total number of atoms:

ξ(t) = ξ(X(t)) = ξ (xi(t),xj(t),xk(t), ⁡),1 i,j,k ⁡ N (1)

This manual documents the collective variables module (Colvars), a software that provides an implementation for the functions ξ(X) with a focus on flexibility, robustness and high performance. The module is designed to perform multiple tasks concurrently during or after a simulation, the most common of which are:

Detailed explanations of the design of the Colvars module are provided in reference [1]. Please cite this reference whenever publishing work that makes use of this module, alongside any other publications for specific features being, according to the usage summary printed when running a Colvars-enabled MD simulation or analysis.

2 Writing a Colvars configuration: a crash course

The Colvars configuration is a plain text file or string that defines collective variables, biases, and general parameters of the Colvars module. It is passed to the module using back-end-specific commands documented in section 3.

Example: steering two groups of atoms away from each other. Now let us look at a complete, non-trivial configuration. Suppose that we want to run a steered MD experiment where a small molecule is pulled away from a protein binding site. In Colvars terms, this is done by applying a moving restraint to the distance between the two objects. The configuration will contain two blocks, one defining the distance variable (see section 4 and 4.3.1), and the other the moving harmonic restraint (6.8).

indexFile index.ndx
colvar {
  name dist
  distance {
    group1 { atomNumbersRange 42-55 }
    group2 { indexGroup C-alpha_15-30 }
  }
}

harmonic {
  colvars dist
  forceConstant 20.0
  centers 4.0         # initial distance
  targetCenters 15.0  # final distance
  targetNumSteps 500000
}

Reading this input in plain English: the variable here named dist consists in a distance function between the centers of two groups: the ligand (atoms 42 to 55) and the α-carbon atoms of residues 15 to 30 in the protein (selected from the index group “C-alpha_15-30"). To the “dist" variable, we apply a harmonic potential of force constant 20 energy unit/length unit2, initially centered around a value of 4 length unit, which will increase to 15 length unit over 500,000 simulation steps.

The atom selection keywords are detailed in section 5. If the selection is too complex to implement only via internal keywords, an external index file may be created following the NDX format used in GROMACS (see 3.8.2) or by using the group2ndx LAMMPS command.

Example: using multiple variables and multiple biasing/analysis methods together. A more complex example configuration is included below, showing how a variable may be constructed by combining multiple existing functions, and how multiple variables or multiple biases may be used concurrently. The colvar indicated below as “d" is defined as the difference between two distances (see 4.3): the first distance (d1) is taken between the center of mass of atoms 1 and 2 and that of atoms 3 to 5, the second (d2) between atom 7 and the center of mass of atoms 8 to 10 (see 5). The difference d = d1 d2 is obtained by multiplying the two by a coefficient C = +1 or C = 1, respectively (see 4.17). The colvar called “c" is the coordination number calculated between atoms 1 to 10 and atoms 11 to 20. A harmonic restraint (see 6.8) is applied to both d and c: to allow using the same force constant K, both d and c are scaled by their respective fluctuation widths wd and wc. The values of “c" are also recorded throughout the simulation as a joint 2-dimensional histogram (see 6.13).

colvar {
  # difference of two distances
  name d 
  width 0.2  # estimated fluctuation width 
  distance {
    componentCoeff  1.0
    group1 { atomNumbers 1 2 }
    group2 { atomNumbers 3 4 5 }
  }
  distance {
    componentCoeff -1.0
    group1 { atomNumbers 7 }
    group2 { atomNumbers 8 9 10 }
  }
}

colvar {
  name c
  coordNum {
    cutoff 6.0
    group1 { atomNumbersRange  1-10 }
    group2 { atomNumbersRange 11-20 }
    tolerance 1.0e-6
    pairListFrequency 1000
  }
}

harmonic {
  colvars d c
  centers 3.0 4.0
  forceConstant 5.0
}

histogram {
  colvars c
}

3 Enabling and controlling the Colvars module in LAMMPS

Here, we document the syntax of the commands and parameters used to set up and use the Colvars module in LAMMPS [2]. One of these parameters is the configuration file or the configuration text for the module itself, whose syntax is described in 3.4 and in the following sections.

3.1 Units in the Colvars module

The “internal units" of the Colvars module are the units in which values are expressed in the configuration file, and in which collective variable values, energies, etc. are expressed in the output and colvars trajectory files. Generally the Colvars module uses internally the same units as its back-end MD engine, with the exception of VMD, where different unit sets are supported to allow for easy setup, visualization and analysis of Colvars simulations performed with any simulation engine.

Note that angles are expressed in degrees, and derived quantities such as force constants are based on degrees as well. Some colvar components have default values, expressed in Ångström (Å) in this documentation. They are converted to the current length unit, if different from Å. Atomic coordinates read from XYZ files (and PDB files where applicable) are expected to be expressed in Ångström, no matter what unit system is in use by the back-end (LAMMPS) or the Colvars Module. They are converted internally to the current length unit as needed. Note that force constants in harmonic and harmonicWalls biases (6.8) are rescaled according to the width parameter of colvars, so that they are formally in energy units, although if width is given its default value of 1.0, force constants are effectively expressed in energy unit/(colvar unit)2.

To avoid errors due to reading configuration files written in a different unit system, it can be specified within the input:

3.2 LAMMPS keywords

To enable a Colvars-based calculation, the following line must be added to the LAMMPS configuration file:

fix Colvars all colvars configfile [keyword value pairs ...] 

where the fix ID is here set to the string “Colvars", because there can only be one instance of fix colvars in a LAMMPS run.

The value of the configfile keyword is the name of the configuration file for the Colvars module. You may also provide the lowercase string “none" to create an empty module, and define the configuration via fix_modify (see 3.3).

Other optional keywords for fix colvars are:

All of the above keywords except for the name of the configuration file may also be given (or overridden) using fix_modify, as well as new Colvars configuration files (see 3.3 for more details).

3.3 Using the scripting interface to control the Colvars module

After the first initialization of the Colvars module, the internal state of Colvars objects may be queried or modified in a LAMMPS script (here, “Colvars" is the ID of the fix colvars instance):

fix_modify Colvars  <method > arg1 arg2 ...

where <method > is the name of a specific procedure and arg1, arg2, …are its required and/or optional arguments.

Each fix_modify command may be used in either one of two ways:

  1. Provide an updated value for the parameters of the fix listed in 3.2: this behavior is similar to that of several other LAMMPS fix styles, and follows the same argument parsing rules. For example, multiple keywords can be provided together:

    fix_modify Colvars seed 111111 tstat NPT 

  2. Use one of the scripting functions described in this section; the arguments provided as strings are passed to Colvars. LAMMPS variables referenced by their string representation, “${variable}", will be expanded immediately. Additionally, variable expansion will also happen within quotes, similar to what the mdi command provides in a LAMMPS script: this feature makes it possible to use the values of certain LAMMPS variables in Colvars configuration strings (see 3.3.1).

    variable freq index 10000
    dump myDump all atom/zstd ${freq} dump.atom.zstd
    fix_modify Colvars config "colvarsTrajFrequency ${freq}"

fix_modify can be run on a previously created instance of fix colvars at any time. However, because the fix is not fully initialized until the beginning of the next simulation step, only the variables and biases that were created prior to the most recent run or minimize command will be accessible. This fact is true even if a Colvars configuration file that defines those variables and biases was already given in the LAMMPS script. Should you want to trigger an immediate initialization of the Colvars module, consider running “run 0".

In the remainder of this section, the most frequently used commands of the Colvars scripting interface are discussed and exemplified. For a full list of scripting commands available, see section 7.

3.3.1 Setting up the Colvars module

To define new collective variables and/or biases for immediate use in the current session, configuration can be loaded from an external configuration file:

fix_modify Colvars configfile "colvars-file.in" 

This can in principle be called at any time, if only flags internal to Colvars are being modified. In practice, when new atoms or any new atomic properties (e.g. total forces) are being requested, initialization steps will be required that are not carried out during a simulation. Therefore, it is generally good practice in a simulation to change the Colvars configuration outside the scope between segments of the same computation.

To load the configuration directly from a string the “config" method may be used:

fix_modify Colvars config "keyword { ... }" 

This method is particularly useful to dynamically define the Colvars configuration within a LAMMPS script. For example, when running an ensemble of umbrella sampling simulations in LAMMPS, it may be convenient to use an identical script and define the specific window through environment variables.

In the following example, the environment variable “SLURM_ARRAY_TASK_ID" is set in a Slurm array job to increasing values starting at 0. The value of this variable is used to define the window's numeric index, and the umbrella restraint center beginning at 2.00 for the first window, and increasing in increments of 0.25 for all other windows:

variable window getenv SLURM_ARRAY_TASK_ID
fix_modify Colvars config """
harmonic {
  name us_${window}
  colvars xi
  centers [expr 2.0 + 0.25 * ${window}]
  ...
}"""

3.3.2 Loading and saving the Colvars state and other information

After a configuration is fully defined, the “load" method may be used to load a state file from a previous simulation that contains e.g. data from history-dependent biases), to either continue that simulation or analyze its results:

fix_modify Colvars load " <oldjob >.colvars.state"

or more simply using the prefix of the state file itself:

fix_modify Colvars load " <oldjob >"

Anything following the “.colvars.state" suffix will be stripped.

Note that the Colvars state is already loaded automatically as part of the LAMMPS restart file, when this is read via the LAMMPS read_restart command; the “load" method allows to load a different state file after the fact.

The “save" method, analogous to “load", allows to save all restart information to a state file. This is normally not required during a simulation if colvarsRestartFrequency is defined (either directly or indirectly by the LAMMPS restart frequency). Because not only a state file (used to continue simulations) but also other data files (used to analyze the trajectory) are written, it is generally recommended to call the save method using a prefix, rather than a complete file name:

fix_modify Colvars save " <job >"

3.3.3 Accessing atomic data

For computational efficiency the Colvars module keeps internal copies of the numeric IDs, masses, charges, positions, and optionally total forces of the atoms requested for a Colvars computation. At each simulation step, up-to-date versions of these properties are copied from the central memory of LAMMPS into the internal memory of the Colvars module. In a post-processing workflow or outside a simulation (e.g. when using VMD), this copy can be carried out as part of the update method:

fix_modify Colvars update   

which also performs the (re-)computation of all variables and biases defined in Colvars.

For example, the current sequence of numeric IDs of the atoms processed by Colvars can be obtained as:

fix_modify Colvars getatomids   

and their current positions as:

fix_modify Colvars getatompositions   

This may prove useful to test the correctness of the coordinates passed to Colvars, particularly in regard to periodic boundary conditions (5.3). There is currently no mechanism to modify the above fields via the scripting interface, but such capability will be added in the future.

While running a simulation, or when setting one up in VMD, it is possible to examine all the forces that were last applied by Colvars to the atoms, or are about to be applied:

fix_modify Colvars getatomappliedforces   

where the length and order of this sequence matches that provided by the getatomids method. A simpler way of testing the stability of a Colvars configuration before or during a simulation makes use of aggregated data, such as the energy:

fix_modify Colvars getenergy   

the root-mean-square of the Colvars applied forces:

fix_modify Colvars getatomappliedforcesrms   

or the maximum norm of the applied forces:

fix_modify Colvars getatomappliedforcesmax   

which can be matched to a specific atom via its numeric ID obtained as:

fix_modify Colvars getatomappliedforcesmaxid   

See 7.1 for a complete list of scripting commands used to manage atomic data and runtime parameters of the Colvars module.

3.3.4 Managing collective variables

After one or more collective variables are defined, they can be accessed with the following syntax.

fix_modify Colvars colvar " <name > <method > arg1 arg2 ...

where “ <name >" is the name of the variable.

For example, to recompute the collective variable “xi" after a change in its parameters, the following command can be used:

fix_modify Colvars colvar "xi" update  

This ordinarily is not needed during a simulation run, where all variables are recomputed at every step (along with biasing forces acting on them). However, when analyzing an existing trajectory, e.g. in VMD, a call to update is generally required.

While in all typical cases all configuration of the variables is done with the “config" or “configfile" methods, a limited set of changes can be enacted at runtime using:

fix_modify Colvars colvar " <name >" modifycvcs arg1 arg2 ...

where each argument is a string passed to the function or functions that are used to compute the variable, and are called colvar components, or CVCs (4.1). For example, a variable “DeltaZ" made of a single “distanceZ" component can be made periodic with a period equal to the unit cell dimension along the Z-axis:

fix_modify Colvars colvar "DeltaZ" modifycvcs "period ${Lz}" 

Please note that this option is currently limited to changing the values of the polynomial superposition parameters componentCoeff, or of the componentExp to update on the fly, of period, wrapAround or forceNoPBC options for components where it is relevant. Furthermore, because the call above uses an immediate expansion of the variable “${Lz}", its value will not be updated during a constant-pressure simulation.

If the variable is computed using many components, it is possible to selectively turn some of them on or off:

fix_modify Colvars colvar " <name >" cvcflags  <flags >

where “ <flags >" is a list of 0/1 values, one per component.

Important: None of the changes enacted by the “modifycvcs" or “cvcflags" methods will be saved to state files, and will be lost when restarting a simulation, deleting the corresponding collective variable, or resetting the module with the “reset" method.

3.3.5 Applying and analyzing forces on collective variables

As soon as a colvar “xi" and its associated biasing potentials are up to date (i.e. during a MD run, or after the respective “update" methods have been called), the force applied onto the colvar is known and may be accessed through the getappliedforce method:

fix_modify Colvars colvar "xi" getappliedforce  

See also the use of the outputAppliedForce option to have this force be saved to file during a simulation.

Aside from the biasing methods already implemented within Colvars (6) this force may be incremented ad hoc:

fix_modify Colvars colvar "xi" addforce  <force >

where “ <force >" is a scalar or a vector (depending on the type of variable “xi"). Although this would offer in principle a way to add custom forces to a variable, fix_modify is executed outside the run or minimize commands, and the given force will be reset during a simulation.

For certain types of variable, the force applied directly on a colvar may be combined with those acting indirectly on it via the interatomic force field, making up the total force. When the outputTotalForce keyword is enabled, or when a biasing method that makes explicit use of the total force is enabled, the total force may be obtained as:

fix_modify Colvars colvar "xi" gettotalforce  

Note that not all types of variable support total-force computation, and the value of the total force may not be available immediately within the same simulation step: see the documentation of outputTotalForce for more details.

See 7.2 for a complete list of scripting commands used to manage collective variables.

3.3.6 Managing collective variable biases

Because biases depend only upon data internal to the Colvars module (i.e. they do not need atomic coordinates from LAMMPS), it is generally easy to create them or update their configuration at any time. For example, given the most current value of the variable “xi", an already-defined harmonic restraint on it named “h_xi" can be updated as:

fix_modify Colvars bias "h_xi" update  

During a running simulation this step is not needed, because an automatic update of each bias is already carried out.

3.3.7 Loading and saving the state of individual biases

Some types of bias are history-dependent, and the magnitude of their forces depends not only on the values of their corresponding variables, but also on previous simulation history. It is thus useful to load information from a state file that contains information specifically for one bias only, for example:

fix_modify Colvars bias "metadynamics1" load "old.colvars.state" 

or alternatively, using the prefix of the file instead of its full name:

fix_modify Colvars bias "metadynamics1" load "old" 

A corresponding “save" function is also available:

fix_modify Colvars bias "metadynamics1" save "new" 

Please note that the file above must contain only the state information for that particular bias: loading a state file for the whole module is not allowed.

This pair of functions is also used internally by Colvars to implement e.g. multiple-walker metadynamics (6.6.7), but they can be called from a scripted function to implement alternative coupling schemes.

See 7.3 for a complete list of scripting commands used to manage biases.

3.4 Configuration syntax used by the Colvars module

Configuration for the Colvars module is passed using an external file. Configuration lines follow the format “keyword value" or “keyword { ... }", where the keyword and its value must be separated by one or more space characters. The following formatting rules apply:

3.5 Global keywords

The following keywords are available in the global context of the Colvars configuration, i.e. they are not nested inside other keywords:

3.6 Input state file

Several of the sampling methods implemented in Colvars are time- or history-dependent, i.e. they work by accumulating data as a simulation progresses, and use these data to determine their biasing forces. If the simulation engine uses a checkpoint or restart file (as GROMACS and LAMMPS do), any data needed by Colvars are embedded into that file. Otherwise, a dedicated state file can be loaded into Colvars directly.

When a dedicated Colvars state file is used, it may be in either one of two formats:

In either format, the state file contains accumulated data as well as the step number at the end of the run. The step number read from a state file overrides any value that LAMMPS provides, and will be incremented if the simulation proceeds. This means that the step number used internally by Colvars may not always match the step number reported by LAMMPS.

3.6.1 Restarting in LAMMPS.

For continuing a Colvars-based simulation, the recommended method is using the standard LAMMPS read_restart command, which reads the Colvars state data from the LAMMPS restart file (in binary format).

read_restart filename 

Alternatively, restarting from a Colvars-specific state file is also possible by providing the input keyword to the fix colvars command:

fix Colvars all colvars configfile input input_prefix 

When the “input" keyword is used, the contents of the file <input_prefix >.colvar.state override the information read from the LAMMPS restart file. Finally, a state file may also be loaded after initialization through the “fix_modify" command:

fix_modify Colvars input new_input_prefix 

3.6.2 Changing configuration upon restarting.

In some cases, it is useful to modify the configuration of variables or biases between consecutive runs, for example by adding or removing a restraint. Some special provisions will happen in that case. When a state file is loaded, no information is available about any newly added variable or bias, which will thus remain uninitialized until the first compute step. Conversely, any information that the state file may contain about variables or biases that are no longer defined will be silently ignored. Please note that these checks are performed based only on the names of variables and biases: it is your responsibility to ensure that these names have consistent definitions between runs.

The flexibility just described carries some limitations: namely, it is only supported when reading text-format Colvars state files. Instead, restarting from binary files (such as the LAMMPS restart file) after a configuration change will trigger an error. It is also important to remind that when switching to a different build of LAMMPS, the binary format may change slightly, even if the release version is the same.

To work around the potential issues just described, a text-format Colvars state file should be loaded. This can be achieved by providing an explicit input keyword when initializing the Colvars fix (see 3.2), which will instruct Colvars to use the given filename, instead of the LAMMPS restart file. Furthermore, the fix_modify scripting command allows to load a Colvars file after initialization (3.3.2).

3.7 Output files

When the output prefix output is defined, the following output files are written during a simulation run:

3.8 File formats

This section summarizes the file formats of various files that Colvars may be reading or writing.

3.8.1 Configuration and state files.

Configuration files are text files that are generally read as input by LAMMPS. Starting from version 2017-02-01, changes in newline encodings are handled transparently, i.e. it is possible to typeset a configuration file in Windows (CR-LF newlines) and then use it with Linux or macOS (LF-only newlines).

Formatted state files, although not written manually, follow otherwise the same text format as configuration files. Binary state files can only be read by the Colvars code itself.

3.8.2 Index (NDX) files

For atom selections that cannot be specified only by using internal Colvars keywords, external index files may also be used following the NDX format used in GROMACS:

[ group_1_name ]
  i1  i2  i3  i4  ...
  ...             ...  iN
[ group_2_name ]
  ...

where i1 through iN are 1-based indices. Each group name may not contain spaces or tabs: otherwise, a parsing error will be raised.

Multiple index files may be provided to Colvars, each using the keyword indexFile. Two index files may contain groups with the same names, however these must also represent identical atom selections, i.e. the same sequence of indices including order.

Other than with GROMACS, an index group may also be generated from the VMD command-line interface, using the helper function write_index_group provided in the colvartools folder:

source colvartools/write_index_group.tcl
set sel [atomselect top "resname XXX and not hydrogen"]
write_index_group indexfile.ndx $sel "Ligand"

In LAMMPS, NDX files may also be generated from internal groups via the group2ndx command.

3.8.3 XYZ coordinate files

XYZ coordinate files are text files with the extension “.xyz". They are read by the Colvars module using an internal reader, and expect the following format:

N
Comment line
E 1 x1 y1 z1
E2 x2 y2 z2
EN xN yN zN

where N is the number of atomic coordinates in the file and Ei is the chemical element of the i-th atom. Because Ei is not used in Colvars, any string that does not contain tabs or spaces is acceptable.

Note: all XYZ coordinates are assumed to be expressed in Å units, regardless of the units currently used by LAMMPS.

An XYZ file may contain either one of the following scenarios:

  1. The file contains as many coordinates as the atoms that they are being read for: all coordinates will be read from the file following the same order as the atoms appear in the selection generated using the keywords listed in section 5. (Note that the order is guaranteed only if a single type of selection keyword is used one or more times, and not guaranteed when different types of selection keywords are used.)
  2. The file contains more coordinates than needed, and it is assumed to contain coordinates for the entire system: only coordinates that match the numeric indices of the selected atoms are read, in order of increasing number.

XYZ-file coordinates are read directly by Colvars and stored internally as double-precision floating point numbers.

3.8.4 Grid files: multicolumn text format

Many simulation methods and analysis tools write files that contain functions of the collective variables tabulated on a grid (e.g. potentials of mean force or multidimensional histograms) for the purpose of analyzing results. Such files are produced by ABF (6.3), metadynamics (6.6), multidimensional histograms (6.13), as well as any restraint with optional thermodynamic integration support (6.2).

In some cases, these files may also be read as input of a new simulation. Suitable input files for this purpose are typically generated as output files of previous simulations, or directly by the user in the specific case of ensemble-biased metadynamics (6.6.5). This section explains the “multicolumn" format used by these files. For a multidimensional function f(ξ1, ξ2, …) the multicolumn grid format is defined as follows:

# Ncv
# min(ξ1) width(ξ1) npoints(ξ1) periodic(ξ1)
# min(ξ2) width(ξ2) npoints(ξ2) periodic(ξ2)
#
# min(ξNcv) width(ξNcv) npoints(ξNcv) periodic(ξNcv)
ξ11 ξ21 ξNcv1 f(ξ11, ξ21, …, ξNcv1)
ξ11 ξ21 ξNcv2 f(ξ11, ξ21, …, ξNcv2)

Lines beginning with the character “#" are the header of the file. Ncv is the number of collective variables sampled by the grid. For each variable ξi, min(ξi) is the lowest value sampled by the grid (i.e. the left-most boundary of the grid along ξi), width(ξi) is the width of each grid step along ξi, npoints(ξi) is the number of points and periodic(ξi) is a flag whose value is 1 or 0 depending on whether the grid is periodic along ξi. In most situations:

How the grid's boundaries affect the sequence of points depends on how the contents of the file were computed. In many cases, such as histograms and PMFs computed by metadynamics (6.6.5), the values of ξi in the first few columns correspond to the midpoints of the corresponding bins, i.e. ξ11 = min(ξi)+width(ξi)2. However, there is a slightly different format in PMF files computed by ABF (6.3) or other biases that use thermodynamic integration (6.2). In these cases, it is free-energy gradients that are accumulated on an (npoints)-long grid along each variable ξ: after these gradients are integrated, the resulting PMF is discretized on a slightly larger grid with (npoints+1) points along ξ (unless the interval is periodic). Therefore, the grid's outer edges extend by width(ξi)2 above and below the specified boundaries, so that for instance min(ξi) in the header appears to be shifted back by width(ξi)2 compared to what would be expected. Please keep this difference in mind when comparing PMFs computed by different methods.

After the header, the rest of the file contains values of the tabulated function f(ξ1, ξ2, …ξNcv), one for each line. The first Ncv columns contain values of ξ1, ξ2, …ξNcv and the last column contains the value of the function f. Points are sorted in ascending order with the fastest-changing values at the right (“C-style" order). Each sweep of the right-most variable ξNcv is terminated by an empty line. For two dimensional grid files, this allows quick visualization by programs such as GNUplot.

Example 1: multicolumn text file for a one-dimensional histogram with lowerBoundary = 15, upperBoundary = 48 and width = 0.1.

# 1
# 15 0.1 330 0
15.05 6.14012e-07
15.15 7.47644e-07
47.85 1.65944e-06
47.95 1.46712e-06

Example 2: multicolumn text file for a two-dimensional histogram of two dihedral angles (periodic interval with 6 bins):

# 2
# -180.0 6.0 30 1
# -180.0 6.0 30 1
-177.0 -177.0 8.97117e-06
-177.0 -171.0 1.53525e-06
-177.0 177.0 2.442956-06
-171.0 -177.0 2.04702e-05

3.8.5 Output trajectory files

The Colvars trajectory file (with a suffix .colvars.traj) is a plain text file (scientific notation with 14-digit precision) whose columns represent quantities such as colvar values, applied forces, or individual restraints' energies. Under most scenarios, plotting or analyzing this file is straightforward: for example, the following contains a variable “A" and the energy of a restraint “rA":

#       step   A                     E_rA
           0    1.42467449615693e+01  6.30982865292123e+02
         100    1.42282559728026e+01  6.20640585041317e+02

Occasionally, if the Colvars configuration is changed mid-run certain quantities may be added or removed, changing the column layout. Labels in comment lines can assist in such cases: for example, consider the trajectory above with the addition of a second variable, “B", after 10,000 steps:

#       step   A                     E_rA
           0    1.42467449615693e+01  6.30982865292123e+02
         100    1.42282559728026e+01  6.20640585041317e+02

#       step   A                     B                     E_rA              
       10000    1.38136915830229e+01  9.99574098859265e-01  4.11184644791030e+02
       10100    1.36437184346326e+01  9.99574091957314e-01  3.37726286543895e+02

Analyzing the above file with standard tools is possible, but laborious: a convenience script is provided for this and related purposes. It may be used either as a command-line tool or as a Python module:

>>> from plot_colvars_traj import Colvars_traj
>>> traj = Colvars_traj('test.colvars.traj')
>>> print(traj['A'].steps, traj['A'].values)
[    0   100  ...  10000 10100] [14.246745 14.228256 ... 13.813692 13.643718]
>>> print(traj['B'].steps, traj['B'].values)
[10000 10100] [0.999574  0.9995741]

4 Defining collective variables

A collective variable is defined by the keyword colvar followed by its configuration options contained within curly braces:

colvar {
  name xi
   <other options >
  function_name {
     <parameters >
     <atom selection >
  }
}

There are multiple ways of defining a variable:

Choosing a component (function) is the only parameter strictly required to define a collective variable. It is also highly recommended to specify a name for the variable:

4.1 Choosing a function

In this context, the function that computes a colvar is called a component. A component's choice and definition consists of including in the variable's configuration a keyword indicating the type of function (e.g. rmsd), followed by a definition block specifying the atoms involved (see 5) and any additional parameters (cutoffs, “reference" values, …). At least one component must be chosen to define a variable: if none of the keywords listed below is found, an error is raised.

The following components implement functions with a scalar value (i.e. a real number):

Some components do not return scalar, but vector values:

The types of components used in a colvar (scalar or not) determine the properties of that colvar, and particularly which biasing or analysis methods can be applied.

What if “X" is not listed? If a function type is not available on this list, it may be possible to define it as a polynomial superposition of existing ones (see 4.17), a custom function (see 4.18).

In the rest of this section, all available component types are listed, along with their physical units and their ranges of values, if limited. Such ranges are often used to define automatically default sampling intervals, for example by setting the parameters lowerBoundary and upperBoundary in the parent colvar.

For each type of component, the available configurations keywords are listed: when two components share certain keywords, the second component references to the documentation of the first one that uses that keyword. The very few keywords that are available for all types of components are listed in a separate section 4.14.

4.2 Treatment of periodic boundary conditions

In all colvar components described below, the following rules apply concerning periodic boundary conditions (PBCs):

  1. Distance vectors between two coordinates di,j = (