How to perform "gmx make_ndx" with single command line bypassing the interactive shell?

Upon creating the index file with gmx make_ndx, we are usually
prompted with interactive shell.

For example:

$ gmx make_ndx -f em.gro -o index.ndx

Will give:

  0 System              : 120070 atoms
  1 Protein             :  7132 atoms
  2 Protein-H           :  3818 atoms
  3 C-alpha             :   500 atoms
  4 Backbone            :  1500 atoms
  5 MainChain           :  2001 atoms
  6 MainChain+Cb        :  2463 atoms
  7 MainChain+H         :  2472 atoms
  8 SideChain           :  4660 atoms
  9 SideChain-H         :  1817 atoms
 10 Prot-Masses         :  7132 atoms
 11 non-Protein         : 112938 atoms
 12 Other               :   446 atoms
 13 PEP                 :   446 atoms
 14 NA                  :   156 atoms
 15 CL                  :   112 atoms
 16 Water               : 112224 atoms
 17 SOL                 : 112224 atoms
 18 non-Water           :  7846 atoms
 19 Ion                 :   268 atoms
 20 PEP                 :   446 atoms
 21 NA                  :   156 atoms
 22 CL                  :   112 atoms
 23 Water_and_ions      : 112492 atoms

 nr : group      '!': not  'name' nr name   'splitch' nr    Enter: list groups
 'a': atom       '&': and  'del' nr         'splitres' nr   'l': list residues
 't': atom type  '|': or   'keep' nr        'splitat' nr    'h': help
 'r': residue              'res' nr         'chain' char
 "name": group             'case': case sensitive           'q': save and quit
 'ri': residue index

Then manually I have to do this:

# Choosing "1 Protein" and "13 PEP" when prompted
> 1 | 13
> q

How can I by-pass that by issuing just one command line?
I tried this but failed:

$ echo "1 | 13" | gmx make_ndx -f em.gro -o index.ndx

You can use
-select ‘com of group “Protein” plus com of group “PEP”’ and put it in the bash if you want.

{ echo -e “1 | 13”; echo -e “q”; } | gmx make_ndx -f em.gro -o index.ndx

This should do what you’re looking to do.

…or alternatively (slightly shorter):

gmx make_ndx -f em.gro -o index.ndx<<EOF
1 | 13
q
EOF

Cheers,
D.

1 Like

In bash, adding a newline character (\n) works for me to separate the inputs. Not sure how cross-shell compatible that is, though.

echo -e "1 | 13 \n q" | gmx make_ndx -f em.gro -o index.ndx

Also, I would propose to select by group names, residues, etc. rather than group numbers when working non-interactively. Group names can be used by “quoting” them, residues with the r command.

echo -e '"Protein" | "PEP" \n q' | gmx make_ndx -f em.gro -o index.ndx

Regards,
Petter

1 Like