In the lower version of GROMACS, when calculating the distance, g_distance needs to select two groups, and then the program will automatically calculate the distance between the pair of atoms of these two groups, and it can also calculate the distance between the centroids of the two groups. Possibly Since version 4.x, the index group method used by gmx distance has changed. Multiple index groups can be provided, each group is independent, and the atom pairs to be calculated are listed in it. Therefore, the total number of atoms in the group for calculating the distance must be an even number, otherwise it will give an error that the number of atoms is not even. For instance, if we want to calculate the distance between atom 3 and 5, 9, 13, 19 in the system, then we can define it in the index file the following groups.
Number pairs can also be placed in multiple lines, with one atomic pair number per line. But it is worth noting that at least in the 2016.4 version, GROMACS has an error when handling these number pairs. For number pairs like 1 2 2 3, It will first merge the repeated numbers in the middle into one, and become 1 2 3, which makes it impossible to calculate. The solution is also very simple, which is to change the order to ensure that there is no duplication between adjacent numbers. As in the above example, change it to 1 2 3 3 can be calculated normally. In this mode, we need to provide the atom pairs to be calculated. When the number of atoms is small, it is not difficult, but as the number of atoms increases, there are more combinations. Handwriting is not realistic, so we wrote a piece of code to deal with this problem.
Run the script, specify the name of the output file and the names of the two groups. This code will generate the atomic pair combination of the two groups, and name it as a new group and append it to the original index file. Then rungmx distance -s- f -n -oav -oall, select this new group, and you can get the distance file you want. It is worth noting that the number of atom pairs in the group should not be too many, otherwise GROMACS requires too much memory when running, which may cause failure.
Using this mode to calculate the distance between atoms is very simple, but to calculate the distance between the centroids of the two groups is a bit cumbersome, you need to use the selection syntax to complete. For example, we want to calculate residues 1-4 and 7 The distance between -9 centroids, you can use the following methods:
gmx distance -s -f -select "com of resnr 1 to 4 plus com of resnr 7 to 9" -oav -oall