Skip navigation.

Heredocs with Gaussian and Slurm

Gaussian is a well-known computational chemistry package, and sometimes subject to debate over its license (e.g., the terms state researchers who develop competing software packages are not permitted to use the software, compare performance etc). Whilst I have some strong opinions about such a license, this will be elaborated at another time. The purpose here is to illustrate the use of heredocs with Slurm.

A here document ("heredoc") is simply a section of a code that is treated as if it was a separate file. Markers can be used to encapsulate here the heredoc begins or ends. They're a common feature in various programming languages, and of course in bash, where they're quite popular for message blocks.

One particular use I've found for them is the automatic generation of job submission scripts, such as Slurm. This is particularly handy when, for example with Gaussian, there is a large suite of test cases. With variable substitution following script generates a job submission script for each of the 1044 Gaussian tests that the software comes with. With minimal change it can be easily modified to suit other job submission applications (e.g., TORQUE/MOAB PBS, PBSPro, OGE etc) and (obviously) other applications. As mentioned in the comment, once the script is run a simple for loop can be used to submit all the jobs.

# This script generates slurm scripts for the standard Gaussian tests.
# To submit the jobs use the following loop:
# for test in {0001..1044}; do sbatch job${test}.slurm; done
# Enjoy submitting 1044 Gaussian test jobs!
# Lev Lafayette, 2017
for test in {0001..1044}
cat <<- EOF > job${test}.slurm
#SBATCH --job-name="Gaussian Test ${test}"
#SBATCH --partition=cloud
#SBATCH --ntasks=1
#SBATCH --time=00:30:00
# You will probably need to change the walltime for some of the later jobs.
# Principle for the heredoc remains the same, just change the loop range.
module load Gaussian/g09
g09 < test${test}.com > test${test}.log

Nota bene: For older versions of bash which don't recognize 0 prefixes something a bit stranger is required for the loops. e.g.,

for test in 000{1..9} 00{10..99} 0{100..999} {1000..1044}