# Colvars' distancePairs to get minimum distance between molecules

**URL:** <https://gromacs.bioexcel.eu/t/colvars-distancepairs-to-get-minimum-distance-between-molecules/13069>\
**Category:** User discussions\
**Tags:** mdrun, colvars\
**Created:** [December 29, 2025, 7:22pm UTC](https://gromacs.bioexcel.eu/t/colvars-distancepairs-to-get-minimum-distance-between-molecules/13069 "2025-12-29T19:22:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hhg7](https://avatars.discourse-cdn.com/v4/letter/h/54ee81/32.png) [@hhg7](https://gromacs.bioexcel.eu/u/hhg7)\
**Post date:** [December 29, 2025, 7:22pm UTC](https://gromacs.bioexcel.eu/t/colvars-distancepairs-to-get-minimum-distance-between-molecules/13069/1 "2025-12-29T19:22:34Z")

</div>

GROMACS version: 2025.3  
GROMACS modification: No

I am attempting to run a metadynamics simulation between two molecules with the following config file:

```auto

indexFile cpx.ndx
colvarsTrajFrequency 500

colvar {
name r
outputTotalForce yes
lowerBoundary 0.0 # smallest it can physically be
upperBoundary 4.0 # largest that it can physically be
width 0.05 # may need to alter this
extendedLagrangian yes
extendedFluctuation 0.01

# Replaced "distance" with "distancePairs"
distancePairs {
    group1 { indexGroup Ligand }
    group2 { indexGroup BindingSite }
    # "min" tracks the closest approach between any two atoms
    # Use forceVector if you need the direction, but min is standard for PMF
    mode min # suggested by Google Gemini, I can find no reference to this whatsoever on the internet
   }
}

harmonicWalls {
name wall_r
colvars r
outputEnergy yes
forceConstant 10.0
lowerWalls 0.2
upperWalls 2.8
}

metadynamics {
name metad_r
colvars r
outputEnergy yes
writeFreeEnergyFile yes
writeTIPMF yes
writeTISamples yes
hillWeight 1.0 # Suggestion: increase hillWeight for faster separation
gaussianSigmas 0.1
newHillFrequency 50
}

```

which is a modification of what “worked” for colvars’`distance`parameter. I wrote `mode min` while wishing to select the minimum distance between the two molecules.

However, the output doesn’t make sense:

```auto

step r r_r ft_r E_wall_r E_metad_r
       0 1.26825742960010e-04 1.26825742960010e-04 0.00000000000000e+00 0.00000000000000e+00 0.00000000000000e+00
     500 1.33747887346636e-04 4.40791848016283e-03 -1.04243672273210e+02 0.00000000000000e+00 9.70221158476317e-01

```

the distances are unreasonably small. `distancePairs` makes a matrix from what I understand, and I want the minimum within this matrix. I don’t know what `r` is, but that’s clearly not the minimum interatomic distance between the molecules.

The reference manual / documentation is very sparse on `distancePairs`

How can I use metadynamics to drive these two molecules apart from one another, so that I can set the minimum distance between the two molecules, analogous to the parameter that’s output from `gmx pairdist`?

---

<div class="post-metadata">

**Author:** ![giacomo.fiorin](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/giacomo.fiorin/32/2862_2.png) [@giacomo.fiorin](https://gromacs.bioexcel.eu/u/giacomo.fiorin)\
**Post date:** [December 30, 2025, 6:47pm UTC](https://gromacs.bioexcel.eu/t/colvars-distancepairs-to-get-minimum-distance-between-molecules/13069/2 "2025-12-30T18:47:14Z")

</div>

Hi, did you try running that config file? `distancePairs` is most likely not useful as is (it gives you a vector of values) and `mode min` does not exist: Google Gemini made it up. The doc is here:

> **[Collective Variables Module - Colvars Module - Reference Manual](https://colvars.github.io/gromacs-2025/colvars-refman-gromacs.html)**

I suggest using [`distanceInv`](https://colvars.github.io/gromacs-2025/colvars-refman-gromacs.html#sec:cvc_distanceInv) to have a “minimum distance” kind of variable. (Note that a true min() function would be discontinuous, and unsuitable as a collective variable).

From that input, remove the “writeTI” and “extended\*” keywords: you won’t need them.

Lastly, I strongly suggest adding `units gromacs` at the top and loading this input in the Colvars Dashboard VMD plugin (included in VMD 1.9.4 or later) to test it.

Giacomo
