# What is the difference between gmx distance, gmx mindist and gmx pairdist?

Hi,
I am trying to compute distance between four residues of a protein involved in active site. I am getting confused in mindist, pairdist and gmx distance. What are the limits and differences in three?
Which analysis can be helpful in plotting distance between A-B, B-C, C-D and D-A residues over time, where ABCD are 4 residues forming bottleneck for ligand entry.

Hi,

gmx distance calculates distances between (fix) pairs of positions as a function of time. For example to calculate the distance between atom 1 and atom 2 , you should provide an index file with the following group
[ distance ]
1 2

gmx mindist computes the minimum distance or contact between one group and a number of other groups. A feature is that with option `-pi` the minimum distance of a group to its periodic image can be calculated

gmx pair-dist also calculates the minimum distances between one reference selection and one or more other selections. But it can also provide the max distance and has more advance options to define the selections.

I hope this is useful
Alessandra

hi alevilla
thankyou for your time and response.

If i have to compute time dependent distance change among four residues, should i keep a separate index for each amino acid*?*

Hi,
Yes, you could create an index file with a group for each the residues or you could use the selection option
Kind regards
Alessandra

Hi alevilla and Yogesh,
Suppose I have index of 128 Phosphorus atoms as ‘ref’ and index of 5 oxygen atoms as ‘sel’ , then does pairdist calculate (at each frame) the minimum distances out of 128*5 possible combinations?
Thanks and regards.
Anirban

Hi,
This extract from the help of gmx pairdist (gmx pairdist — GROMACS 2021 documentation) may answer to your question:
“Computed distances are written to the file specified with `-o` . If there are N groups in `-ref` and M groups in the first selection in `-sel` , then the output contains N*M columns for the first selection. The columns contain distances like this: r1-s1, r2-s1, …, r1-s2, r2-s2, …, where rn is the n’th group in `-ref` and sn is the n’th group in the other selection.”
Best regards
Alessandra

Thank you Alessandra to point this out . I will check it.
I am very sorry for my late response.
Regards
Anirban

Hi @Anirban12,

It looks like you want to find all the NxM distances, is that correct?

I think the answer is in using the -regrouping and -selgrouping arguments. I believe what that does is deaggregate the group so that you get your NxM array instead of a 1x1 array.

example - I believe this is finding all C-N distances:

`gmx pairdist -s simulation.tpr -f simulation.xtc -ref 'type C' -sel 'type N' -refgrouping none -selgrouping none`

Now, the \$64K question is: which numbers belong to which atom pairings. :). I believe @alevilla might have answered that above; the bit she quotes would seem to give the mapping algorithm.

It also seems convenient to use a pre-engineered index (.ndx) file if you know the groups you are looking for. For example, I created an ndx file where the group Protein-Heavy-Atoms is group #1. I added this to the pairdist command using -n (to include the ndx file) and the -ref and -sel arguments to select group #1.

`gmx pairdist -s simulation.tpr -f simulation.xtc -refgrouping none -selgrouping none -n protein.ndx -ref 1 -sel 1`

-denny-

p.s. let me know if you aren’t comfortable writing the ndx files. I believe there are ways to do it from gmx, but I just created them manually from python.

Hi @denny