Gmx distance using bash for loop

GROMACS version: 2019
GROMACS modification: No

Dear All,
I want to calculate com distance between two groups using gmx distance, using for loop bash scripting. My script

for (( i=26; i<35; i++ ))
do
gmx distance -s md.tpr -f traj.xtc -n ind1.ndx -oall dist${i}.xvg -tu ns -select ‘com of group “$i” plus com of group 24’
done

This gives the following error Message:


Program: gmx distance, version 2019
Source file: src/gromacs/selection/selectioncollection.cpp (line 666)
Function: void gmx::SelectionCollection::setIndexGroups(gmx_ana_indexgrps_t*)

Inconsistency in user input:
Invalid index group reference(s)
Cannot match ‘group “$i”’, because no such index group can be found.

Simply “i” gives wrong data and I tried several ways for denoting the number in the group section to overcome this, but I failed to solve this issue. I request you, kindly help me to fix this issue. Thanks in advance.

Hi,

Try using double quotes around your -select command. With single quotes $i does not evaluate to your variable.

If you need double quotes inside of the command you should escape them, e.g. -select "com of group \"$i\" plus com of group 24". (But you might not need to quote $i inside)

Regards,
Petter

1 Like

Thank you so much for your response, Sir.
I used the following command,

gmx distance -s md.tpr -f traj.xtc -n ind1.ndx -oall dist${i}.xvg -tu ns -select “com of group “$i” plus com of group 24”

gave me the required result. Thanks again, Sir.

Hello All, I have an index file (attached), having 0-37 groups to calculate the com distance via bash for loop. Using that, first 9 and last one (37th) groups are not considered for the analysis, citing the following reasons

Script

for (( j=2; j<=37; j++ ))
do
gmx distance -s md.tpr -f traj.xtc -n ind1.ndx -oall Dist${j}.xvg -tu ns -select "com of group “$j” plus com of group 0 " -b 99.995 -e 100
done

Error: Multiple groups '2' selected

-------------------------------------------------------
Program:     gmx distance, version 2019
Source file: src/gromacs/selection/selectioncollection.cpp (line 666)
Function:    void gmx::SelectionCollection::setIndexGroups(gmx_ana_indexgrps_t*)

Inconsistency in user input:
Invalid index group reference(s)
  Cannot match 'group "2"', because no such index group can be found.
=================
  gmx distance -s md.tpr -f traj.xtc -n ind1.ndx -oall Dist37.xvg -tu ns -select 'com of group "37" plus com of group 0 ' -b 99.995 -e 100


-------------------------------------------------------
Program:     gmx distance, version 2019
Source file: src/gromacs/selection/selectioncollection.cpp (line 666)
Function:    void gmx::SelectionCollection::setIndexGroups(gmx_ana_indexgrps_t*)

Inconsistency in user input:
Invalid index group reference(s)
  Cannot match 'group "37"', because no such index group can be found.

Index file

Kindly help me to solve this issue. Thanks in advance.

Do not enclose the variable $j in double quotes; these are used within selections to choose groups by name (string), e.g. group "Protein" is valid but group "1" is not.

1 Like

Thank you so much, Sir. Your advice helped a lot.