# On computing distances between COMs

**URL:** <https://gromacs.bioexcel.eu/t/on-computing-distances-between-coms/10806>\
**Category:** User discussions\
**Created:** [December 13, 2024, 5:59am UTC](https://gromacs.bioexcel.eu/t/on-computing-distances-between-coms/10806 "2024-12-13T05:59:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![horlust](https://avatars.discourse-cdn.com/v4/letter/h/b2d939/32.png) [@horlust](https://gromacs.bioexcel.eu/u/horlust)\
**Post date:** [December 13, 2024, 5:59am UTC](https://gromacs.bioexcel.eu/t/on-computing-distances-between-coms/10806/1 "2024-12-13T05:59:48Z")

</div>

GROMACS version: 2024.4  
GROMACS modification: No

Hi everyone,

I have a simulation box containing water and two solutes. I want to compute the distance between the centers of mass of each solute. I did:

gmx traj -f prod.xtc -s prod.tpr -n index.ndx -ox com -com

for both molecules, and then used a script to compute the distances over time.  
I accounted for PBC effects with -pbc whole, -pbc nojump and, finally, -pbc mol.

Visualizing the simulation box, it seems the molecules are far away, but they are actually close because of PBC effects (see figure). However, the calculated distances are bigger than expected, because the calculation method doesn’t take into account PBC effects (I think).

Do you have any ideas on how to compute the smallest distance between these two solutes?

 ![to_ben](https://europe1.discourse-cdn.com/flex017/uploads/bioexcel1/original/2X/4/47bb1ae6aee64e48bcef74dccacd0e01495fbef1.jpeg)

Thank you!

---

<div class="post-metadata">

**Author:** ![MagnusL](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/magnusl/32/2380_2.png) [@MagnusL](https://gromacs.bioexcel.eu/u/MagnusL)\
**Post date:** [December 13, 2024, 9:07am UTC](https://gromacs.bioexcel.eu/t/on-computing-distances-between-coms/10806/2 "2024-12-13T09:07:56Z")

</div>

I think `gmx distance` or `gmx pairdist` will be useful for this.

---

<div class="post-metadata">

**Author:** ![obZehn](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/obzehn/32/2629_2.png) [@obZehn](https://gromacs.bioexcel.eu/u/obZehn)\
**Post date:** [December 13, 2024, 10:34am UTC](https://gromacs.bioexcel.eu/t/on-computing-distances-between-coms/10806/3 "2024-12-13T10:34:13Z")

</div>

> [@horlust](#):
>
> I accounted for PBC effects with -pbc whole, -pbc nojump and, finally, -pbc mol.

Where did you use these flags? Because I do not see them in `gmx traj`, not in my GROMACS 2024 at least.

If you used the flag `-pbc nojump` in preparing the trajectory (like with `gmx trjconv`), then you are letting the molecules diffuse around and leave the box. As such, I think you are following the “original” two molecules of solute that you have inside the box, and in principle they will diffuse everywhere, while what you are trying to compute is the minimum distance between a solute and another. With your code you are following the two original molecules and disregarding the “PBC copies” that will enter the box. You can try to visualize the trajectory after you modify it with your flags to be sure about this.

If you want the distance wrt to PBCs, then or you implement the PBCs in your code (i.e. rescale x y and z components for the corresponding length of the box, but this is tedious especially if you are coupling the volume), or as @MagnusL suggested you use one of the built in tools like `gmx distance`, `gmx pairdist`, or `gmx mindist`. The default behaviour of `gmx distance` has

```auto
 -[no]rmpbc (yes)
           Make molecules whole for each frame
 -[no]pbc (yes)
           Use periodic boundary conditions for distance calculation

```

which means that you already consider PBCs and whole molecules, so you do not need post-processing of the trajectory. I am not familiar with these tools, but I think you can work with the centre of masses by specifying `-selrpos mol_com` and `-seltype mol_com` or better with the select flag, something like `-select "com of group_1 plus com of group_2"` where `group_1` and `group_2` are the two groups defining your molecules of interest in the index file.
