6
$\begingroup$

I want to run multiple Gaussian jobs (one after one). I have a folder which contains more than 30 molecules and I want my calculation to start with molecule 1 then when the job is finished, start the next job for molecule 2 automatically and so on ...

I know how to do it in Windows by using a batch file and executing in the utilities menu but, on Linux, I don't know how does it works.

$\endgroup$
3
  • $\begingroup$ Are you running on a cluster or on your own PC? because I think a simple bash script won't do if you are on a cluster $\endgroup$
    – S R Maiti
    Oct 26, 2022 at 16:13
  • $\begingroup$ I'm on my PC I'm not using a cluster $\endgroup$
    – diamond999
    Oct 26, 2022 at 16:15
  • 2
    $\begingroup$ As a comment: a) Get in touch with your colleagues already using Gaussian. Because some of the computations may take some long time to complete, their infrastructure where Gaussian is set up often is a a Linux cluster. b) Join the keywords gaussian batch job linux in a search engine of your preference and to retrieve documentations as e.g., by Gaussian (gaussian.com/running), HPC centres (hpc-uit.readthedocs.io/en/latest/applications/chemistry/…), or like Gaussian's video channel (youtube.com/watch?v=kcqnZb8Cyw8). $\endgroup$
    – Buttonwood
    Oct 26, 2022 at 21:32

3 Answers 3

7
$\begingroup$

Lets suppose that you have several Gaussian input files with extension gjf inside a folder.

Supposing you are in the folder where all the input files are and the command to run Gaussian is g16:

  • Open a plain text editor and create a file with the content below (Use nano, vim, gedit. Don't use LibreOffice, OpenOffice or similar).
  • Save the file, for example, as: run_gaussian_jobs.sh.
  • In the command prompt, turn the file an executable: chmod +x run_gaussian_jobs.sh.
  • Run the script as ./run_gaussian_jobs.sh. You can also move your script to a folder that is in your path (for example ~/bin). In that case you can use the script in any other folder where you have Gaussian input files running it as run_gaussian_jobs.sh.

Text to use:

#!/bin/bash

for file in *.gjf; do
  extension="${file##*.}"
  filename="${file%.*}"

  g16 < $file > $filename.log
done

Using this approach, you can add any number of Gaussian input files to the folder without the need to known the filenames, modify the script, etc.

An aside note: running as mention before, the jobs will be running in the terminal, so, you can not close it because you will end the jobs. A better approach is to add & at the end of the running command: ./run_gaussian_jobs &. Now the jobs will run in the background. You can use this if you are running the jobs in a remote computer.

$\endgroup$
1
  • 1
    $\begingroup$ Thank you so much sir $\endgroup$
    – diamond999
    Oct 27, 2022 at 12:32
3
$\begingroup$

Loops in Linux are possible, but I personally find it more convenient to make a batch-processing script. The following is an example for my PotFit program, in which the command to run the program is:

brdpot [input_filename]

For example, I would create a file called batch.x that looks like this:

brdpot input1
brdpot input2
brdpot input3
brdpot input4
brdpot input5
brdpot input6
brdpot input7
brdpot input8

By running the command chmod +x batch.x, it becomes an "executable" file. You can then execute it from the directory in which it lives, by running the command ./batch.x and this will get the computer to run the command brdpot input1, then when that job is complete it will get the computer to run the command brdpot input2, etc. In other words, the PotFit program will be run for several input files, one-after-the-other until all jobs have been run.

I've found this approach extremely helpful because in VIM, I can just "yank" a line in the batch.x file and repeat it hundreds of times, then change the number in the file name in a batch too.

$\endgroup$
4
  • $\begingroup$ Thank you so much for the answer . I have a question sir do I have to mention the name "file.out' like when I execute a basic calculus in Linux "g16 file.gjf file.out " or is it automatically and also the commend bedpost stands for what because It seems that I couldn't find it in Google thank you $\endgroup$
    – diamond999
    Oct 26, 2022 at 22:20
  • $\begingroup$ @ImeneYd I'm having a hard time understanding your comment. Perhaps you can ask it in this chat room so that we can communicate with longer comments. $\endgroup$ Oct 26, 2022 at 22:26
  • 3
    $\begingroup$ I suspect "commend bedpost" is what happens when the OPs spellchecker is thrown at "command brdpot" $\endgroup$
    – Ian Bush
    Oct 27, 2022 at 7:14
  • 2
    $\begingroup$ "Loops in Linux are possible" is a bit of an understatement :) $\endgroup$
    – Anyon
    Oct 27, 2022 at 13:56
3
$\begingroup$

You don't have to create a script. Let's say you want to run g16 on all Gaussian inputs in the current working directory, *.com. The shell command

$ for f in *.com; do g16 $f; done

accomplishes what you want to do.

$\endgroup$
1
  • $\begingroup$ Thank you so much sir $\endgroup$
    – diamond999
    Jul 5, 2023 at 6:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .