How do I enter numbers for prompts in my scripts

GROMACS version: 2018
GROMACS modification: No
Here post your question

I am writing a script to run our supercomputer. How do I enter a number that needs entered for a prompt. For example, I know to input a force field, I use the command -ff XXX.
Following Justin’s tutorial for Lysozyme for instance, how do I write in my script numbers that would normally be prompted. I’ve listed the commands for the queries I have below.

  • gmx genion -s ions.tpr -o 1AKI_solv_ions.gro -p -pname NA -nname CL -neutral
    When prompted, choose group 13 “SOL” for embedding ions

  • gmx energy -f em.edr -o potential.xvg
    At the prompt, type “10 0” to select Potential (10); zero (0) terminates input

  • gmx energy -f nvt.edr -o temperature.xvg
    Type “16 0” at the prompt to select the temperature of the system and exit

  • gmx energy -f npt.edr -o pressure.xvg
    Type “18 0” at the prompt to select the pressure of the system and exit

  • gmx energy -f npt.edr -o density.xvg
    24 0

  • gmx trjconv -s md_0_1.tpr -f md_0_1.xtc -o md_0_1_noPBC.xtc -pbc mol -center
    Select 1

  • gmx rms -s md_0_1.tpr -f md_0_1_noPBC.xtc -o rmsd.xvg -tu ns
    Choose 4

  • gmx gyrate -s md_0_1.tpr -f md_0_1_noPBC.xtc -o gyrate.xvg
    Choose group 1

You can always use ``| ''as to pipe multiple commands in shell, so that the out put of the first command is fed to the second command as input, such as:

command 1 | command 2 | command 3 | command 4

For example for choosing 24 0 for you gmx energy example you have
echo “24 0” as the first command and gmx energy as the second one, so that below gives out what you want:

echo "24 0 " | gmx energy -f npt.edr -o density.xvg


Adding to the above comment, you can also use the name of the group or option. You also do not need to end the selection with a 0 when using pipes. So:

echo SOL | gmx genion -s ions.tpr -o 1AKI_solv_ions.gro -p -pname NA -nname CL -neutral

selects the SOL group. And

echo 16          | gmx energy -f em.edr -o temperature.xvg
echo Temperature | gmx energy -f em.edr -o temperature.xvg
echo Temp        | gmx energy -f em.edr -o temperature.xvg

will all get the temperature, but 16 might not always be for the temperature so the latter two are preferable. Also, gromacs will get all matches that start with the string which is why Temp expands to Temperature. Similarly, echo Pres | gmx energy will calculate and display all the pressure terms.


Thank you so much! These worked beautifully.