The Script that Gracefully Exits Quantum ESPRESSO

According to PWscf User's Guide (v.6.2) on restarting:

Since QE 5.1 restarting from an arbitrary point of the code is no more supported.

The code must terminate properly in order for restart to be possible. A clean stop can be triggered by one the following three conditions:

  1. The amount of time specified by the input variable max_seconds is reached
  2. The user creates a file named "$prefix.EXIT" either in the working directory or in output directory "$outdir" (variables $outdir and $prefix as specified in the control namelist)
  3. (experimental) The code is compiled with signal-trapping support and one of the trapped signals is received (see the next section for details).

After the condition is met, the code will try to stop cleanly as soon as possible, which can take a while for large calculation. Writing the files to disk can also be a long process. In order to be safe you need to reserve sufficient time for the stop process to complete.

If the previous execution of the code has stopped properly, restarting is possible setting restart_mode=``restart'' in the control namelist.

According to PHonon User’s Guide (v. 6.2.1):

Since version 4.0 it is possible to safely stop execution of ph.x code using the same mechanism of the pw.x code, i.e. by creating a file prefix.EXIT in the working directory. Execution can be resumed by setting recover=.true. in the subsequent input data. Moreover the execution can be (cleanly) stopped after a given time is elapsed, using variable max seconds. See example/Recover example/.

You can create these files using the following script:

#!/bin/sh

echo -n "Enter the prefix and type [ENTER]: "
read prefix
echo -n "Re-enter the prefix and type [ENTER]: "
read prefix_confirmed
if [ "$prefix" == "$prefix_confirmed" ] 
then
    echo -n "Are you sure? [YES]: "
    read yes
    if [ "$yes" == "YES" ] 
    then
        for dirname in `ls -d scf*/`
        do
            cd $dirname
            echo "Killing $dirname..."
            touch $prefix.EXIT
            cd ..
        done
    fi
    echo "Done!"
fi