Run consecutive Psi4 jobs via python

I am trying to run consecutive jobs with help from python. Below is the detailed problem.

In the parent directory, there are ~1500 subdirectories consisting of two input files in each subdirectory. So total I have to run 3000 separate calculations. This is the first time I am trying to automate the job process one after another using python. For the test run, I am just trying with two input files (1.in and 2.in) put in a rough directory. I am trying to use a script for this purpose as,

import os,glob
path='/home/prasantb/rough/'

inputs=[]
for files in glob.glob('*.in'):
    inputs.append(files)
print(inputs)

import subprocess
for i in inputs:
    subprocess.call(['psi4', i])

To run a psi4 job, I just have to use, psi4 abc.in which automatically writes abc.out and related files in the same directory. The message I am getting is,

Traceback (most recent call last):
  File "/home/prasantb/psi4conda/bin/psi4", line 217, in <module>
    raise KeyError("The file %s does not exist." % args["input"])
KeyError: 'The file input.dat does not exist.'
Traceback (most recent call last):
  File "/home/prasantb/psi4conda/bin/psi4", line 217, in <module>
    raise KeyError("The file %s does not exist." % args["input"])
KeyError: 'The file input.dat does not exist.'

Can I have anyones’ kind help? Thank you in advance.

Your script runs fine for me.

This needs more information.

  1. What directory is your script in, relative to your input files?
  2. What’s your Psi version? (We always need this information.)
  3. What’s your Python version?
  4. Can you simplify your script? For all that I know, a given i in input isn’t what you expect. Have you checked that i is what you expect?

You could try the following, (save it as a .py file in the directory that contains your parent_dir and it should work just fine. )

import os

folders_list = os.listdir('./parent_dir')
for folder in folders_list:
     files_list = os.listdir(folder)
     for file in files_list:
          os.system('psi4 ' + file)

But, I am curious, why aren’t you just running the calculation using psi4 python API ? wouldn’t that simplify the whole process?

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.