GROMACS script automation

GROMACS version: 2019.6
GROMACS modification: No

Hello everyone, I would like to submit a sequence of GROMACS commands to create separate index (.ndx) files. At present, I am using the schematic below to create the different index files.

However, I would be interested in simplifying the task to make it more efficient. Could someone please suggest an improved schematic to make it faster? More specifically, I would like to convert one block of code (from the gmx command till q invocation) into a single-line code. Thanks a lot for your kind assistance.

gmx make_ndx -f equilibration.gro -o seg1.ndx

> 4 & r 75-106
> name 16 SEG1 #for the just-created index
> del 0-15 #clearing the pre-existing indices
> q

gmx make_ndx -f equilibration.gro -o seg2.ndx

> 4 & r 111-140
> name 16 SEG2
> del 0-15
> q

gmx make_ndx -f equilibration.gro -o seg3.ndx

> 4 & r 146-181
> name 16 SEG3
> del 0-15
> q

After quite some trial and error, I was able to figure this out. The following worked, but I could not execute the echo commands via a SLURM script and had to run them on the local terminal instead.

(echo ‘4 & r 75-106’ && echo ‘name 16 SEG1’ && echo ‘del 0-15’ && echo ‘q’) | gmx make_ndx -f equilibration.gro -o seg1.ndx

You can use printf command with \n for enter. For example in your first code:

printf ‘4 & r 75-106\nname 16 SEG1\ndel 0-15\nq\n’ | gmx make_ndx -f equilibration.gro -o seg1.ndx

Unfortunately, it did not work despite multiple attempts.

Fatal error:
Error reading user input

For more information and tips for troubleshooting, please check the GROMACS
website at Common Errors — GROMACS webpage https://www.gromacs.org documentation

Abort(1) on node 0 (rank 0 in comm 0): application called > MPI_Abort(MPI_COMM_WORLD, 1) - process 0