5 Selecting atoms

To define collective variables, atoms are usually selected as groups. Each group is defined using an identifying keyword that is unique in the context of the specific colvar component (e.g. for a distance component, the two groups are identified by the group1 and group2 keywords).

The group’s identifying keyword is followed by a brace-delimited block containing selection keywords and other parameters, one of which is name:

  • •

    name — Unique name for the atom group
    [ string, context: atom group ]

    This parameter defines a globally unique name for this atom group, which can be referred to in the definition of other atom groups (including in other colvars) by invoking atomsOfGroup as a selection keyword. This has two benefits: (1) it can make the configuration shorter and more legible, and (2) several related atom groups can be defined using a common set of atoms, so that this selection can be changed in one place, keeping all related groups synchronized with the same atom set.

Other keywords are documented in the following sections.

In the example below, the gyration component uses the identifying keyword atoms to define its associated group, which is defined based on the index group named “Protein-H”. Optionally, the group is also given the unique name “my_protein”, so that atom groups defined later in the Colvars configuration may refer to it.

colvar {
  name rgyr
  gyration {
    atoms {
      name my_protein
      indexGroup Protein-H
    }
  }
}

5.1 Atom selection keywords

Selection keywords may be used individually or in combination with each other, and each can be repeated any number of times. Selection is incremental: each keyword adds the corresponding atoms to the selection, so that different sets of atoms can be combined. However, atoms included by multiple keywords are only counted once. Below is an example configuration for an atom group called “atoms”. Note: this is an unusually varied combination of selection keywords, demonstrating how they can be combined together: most simulations only use one of them.

atoms {

  # add atoms 1 and 3 to this group (note: first atom in the system is 1)
  atomNumbers { 
    1 3
  }

  # add atoms starting from 20 up to and including 50
  atomNumbersRange  20-50

  # add index group (requires a .ndx file to be provided globally)
  indexGroup Water
}

The resulting selection includes atoms 1 and 3, those between 20 and 50, and those in the index group called “Water”. The indices of this group are read from the file provided by the global keyword indexFile.

The complete list of selection keywords available in LAMMPS is:

  • •

    atomNumbers — List of atom numbers
    [ space-separated list of positive integers, context: atom group ]

    This option adds to the group all the atoms whose numbers are in the list. The number of the first atom in the system is 1: to convert from a VMD selection, use “atomselect get serial”.

  • •

    indexGroup — Name of index group to be used (GROMACS format)
    [ string, context: atom group ]

    If the name of an index file has been provided by indexFile, this option allows to select one index group from that file: the atoms from that index group will be used to define the current group.

  • •

    atomsOfGroup — Name of group defined previously
    [ string, context: atom group ]

    Refers to a group defined previously using its user-defined name. This adds all atoms of that named group to the current group.

  • •

    atomNumbersRange — Atoms within a number range
    [ <Starting number>-<Ending number>, context: atom group ]

    This option includes in the group all atoms whose numbers are within the range specified. The number of the first atom in the system is 1.

  • •

    dummyAtom — Dummy atom position (length unit)
    [ (x, y, z) triplet, context: atom group ]

    Instead of selecting any atom, this option makes the group a virtual particle at a fixed position in space. This is useful e.g. to replace a group’s center of geometry with a user-defined position.

5.2 Moving frame of reference.

The following options define an automatic calculation of an optimal translation (centerToReference) or optimal rotation (rotateToReference), that superimposes the positions of this group to a provided set of reference coordinates. Alternately, centerToOrigin applies a translation to place the geometric center of the group at (0, 0, 0). This can allow, for example, to effectively remove from certain colvars the effects of molecular tumbling and of diffusion. Given the set of atomic positions 𝐱i, the colvar ξ can be defined on a set of roto-translated positions 𝐱i′=R⁢(𝐱i−𝐱C)+𝐱ref. 𝐱C is the geometric center of the 𝐱i, R is the optimal rotation matrix to the reference positions and 𝐱ref is the geometric center of the reference positions.

Components that are defined based on pairwise distances are naturally invariant under global roto-translations. Other components are instead affected by global rotations or translations: however, they can be made invariant if they are expressed in the frame of reference of a chosen group of atoms, using the centerToReference and rotateToReference options. Finally, a few components are defined by convention using a roto-translated frame (e.g. the minimal RMSD): for these components, centerToReference and rotateToReference are enabled by default. In typical applications, the default settings result in the expected behavior.

Warning on rotating frames of reference and periodic boundary conditions.

rotateToReference affects coordinates that depend on minimum-image distances in periodic boundary conditions (PBC). After rotation of the coordinates, the periodic cell vectors become irrelevant: the rotated system is effectively non-periodic. A safe way to handle this is to ensure that the relevant inter-group distance vectors remain smaller than the half-size of the periodic cell. If this is not desirable, one should avoid the rotating frame of reference, and apply orientational restraints to the reference group instead, in order to keep the orientation of the reference group consistent with the orientation of the periodic cell.

Warning on rotating frames of reference and ABF.

Note that centerToReference and rotateToReference may affect the Jacobian derivative of colvar components in a way that is not taken into account by default. Be careful when using these options in ABF simulations or when using total force values.

  • •

    centerToReference — Implicitly remove translations for this group
    Default: off [ boolean, context: atom group ]

    If this option is on, the center of geometry of the group will be aligned with that of the reference positions provided by refPositions or refPositionsFile. Colvar components will only have access to the aligned positions. Note: unless otherwise specified, rmsd and eigenvector set this option to on by default.

  • •

    centerToOrigin — Implicitly remove translations for this group by keeping its center at the origin
    Default: off [ boolean, context: atom group ]

    This option implies centerToReference. If this option is on, coordinates from the group will be translated so that the center of geometry of the group remains at (0, 0, 0), except if fittingGroup is enabled. In that case, the translation applied is the translation that brings the center of geometry of the fitting group to (0, 0, 0).

  • •

    rotateToReference — Implicitly remove rotations for this group
    Default: off [ boolean, context: atom group ]

    If this option is on, the coordinates of this group will be optimally superimposed to the reference positions provided by refPositions or refPositionsFile. The rotation will be performed around the center of geometry if centerToReference is on, or around the origin otherwise. The algorithm used is the same employed by the orientation colvar component Coutsias et al. (2004). Forces applied to the atoms of this group will also be implicitly rotated back to the original frame. Note: unless otherwise specified, rmsd and eigenvector set this option to on by default.

  • •

    refPositions — Reference positions for fitting (length unit)
    [ space-separated list of (x, y, z) triplets, context: atom group ]

    This option provides a list of reference coordinates for centerToReference and/or rotateToReference, and is mutually exclusive with refPositionsFile. If only centerToReference is on, the list may contain a single (x, y, z) triplet; if also rotateToReference is on, the list should be as long as the atom group, and its order must match the order in which atoms were defined.

  • •

    refPositionsFile — File containing the reference positions for fitting
    [ UNIX filename, context: atom group ]

    This option provides a list of reference coordinates for centerToReference and/or rotateToReference, and is mutually exclusive with refPositions. The acceptable file format is XYZ (3.8.3), which is read in double precision. .

  • •

    fittingGroup — Use an alternate set of atoms to define the roto-translation
    Default: This atom group itself [ Atom group, context: atom group ]

    If either centerToReference or rotateToReference is defined, this keyword defines an alternate atom group to calculate the optimal roto-translation. Use this option to define a continuous rotation if the structure of the group involved changes significantly (a typical symptom would be the message “Warning: discontinuous rotation!”).

5.2.1 Note on fit gradients

When either centerToReference or rotateToReference is on, the gradients of some colvars include terms proportional to ∂R/∂𝐱i (rotational gradients) and ∂𝐱C/∂𝐱i (translational gradients). In practice, these terms are calculated as follows,
∇kζ⁢(𝐗)=∑l,main[∇lf⋅∇kR⁢(𝐱l−𝐱¯(fit))−1n(fit)⁢∇lf⋅R⁢𝟙]=(∑l,main∇lf⋅∂R∂q0(𝐱l−𝐱¯(fit)),∑l,main∇lf⋅∂R∂q1(𝐱l−𝐱¯(fit)),∑l,main∇lf⋅∂R∂q2(𝐱l−𝐱¯(fit)),∑l,main∇lf⋅∂R∂q3(𝐱l−𝐱¯(fit)))⋅(∇kq0,∇kq1,∇kq2,∇kq3)−1n(fit)R⊺∑l,main∇lf

In the case of a minimum RMSD component, the contributions of those derivatives to the gradients cancel out, so this term is not computed. Other types of variable require projecting each of the gradients of the variable onto each of the gradients of the roto-translation. When fittingGroup is enabled, the computation is a O⁢(n(fit)+n(main)) loop – that is, linear in both atom group sizes, for all variables including RMSDs.

5.3 Treatment of periodic boundary conditions.

In simulations with periodic boundary conditions (PBCs), Colvars computes all distances between two points following the nearest-image convention, using PBC parameters provided by LAMMPS. However, many common variables rely on a consistent definition of the center of mass or geometry of a group of atoms. This requires the use of unwrapped coordinates, which are not subject to “jumps” when they diffuse across periodic boundaries.

LAMMPS controls the internal availability of unwrapped coordinates using the unwrap keyword in 3.2, which defaults to yes. The user should determine whether it is appropriate to maintain the default value of unwrap, depending on the specifics of each system.

In general, internal coordinate wrapping by LAMMPS does not affect the calculation of colvars if each atom group satisfies one or more of the following:

  1. i)

    it is composed by only one atom;

  2. ii)

    it is used by a colvar component which does not make use of its center of geometry, but only of pairwise distances (distanceInv, coordNum, hBond, alpha, dihedralPC);

  3. iii)

    it is used by a colvar component that ignores the ill-defined Cartesian components of its center of mass (such as the x and y components of a membrane’s center of mass modeled with distanceZ).

5.4 Performance of a Colvars calculation based on group size.

In simulations performed with MD simulation engines such as GROMACS, LAMMPS or NAMD, the computation of energy and forces is distributed (i.e., parallelized) over multiple nodes, as well as over the CPU/GPU cores of each node. When Colvars is enabled, atomic coordinates are collected on a single CPU core, where collective variables and their biases are computed. This means that in the case of simulations that are already being run over large numbers of nodes, or inside a GPU, a Colvars calculation may produce a significant overhead. This overhead comes from the combined cost of two operation: transmitting atomic coordinates, and computing functions of the same.

Performance can be improved in multiple ways:

  • •

    As a general rule, the size of atom groups should be kept relatively small (up to a few thousands of atoms, depending on the size of the entire system in comparison). For example, restraining a protein through a RMSD colvar defined over all of its atoms is only marginally different than one defined over only the α carbon atoms, but the difference in computational cost is much higher. To gain an estimate of the computational cost of a specific Colvars configuration, one may use a test calculation of the same colvar in VMD (hint: use the time Tcl command to measure the cost of running cv update).

  • •

    The calculation of variables, components and biases can be distributed over the processor cores of the node where the Colvars module is executed. Currently, an equal weight is assigned to each colvar, or to each component of those colvars that include more than one component. The performance of simulations that use many colvars or components is improved automatically. For simulations that use a single large colvar, it may be advisable to partition it in multiple components, which will be then distributed across the available cores. In LAMMPS, this feature is supported automatically when LAMMPS is compiled with OpenMP support. The messages “SMP parallelism is available” or “SMP parallelism is enabled”, printed by Colvars at initialization time, indicate the availability or status of this feature. If available, the option is turned on by default, but may be disabled using the keyword smp if required for debugging or troubleshooting.