7
$\begingroup$

I'm a master's student and recently I started doing computational chemistry calculations using ORCA program.
This program works by command line and I saw that the majority of computational chemistry programs work in a similar way.

My question is: is it possible to make them work through a Python script?
I think it would be very convenient since it could be possible to create new files and organize them with Python.
I tried this code (very easy HF ( Hartree-Fock) calculation for Hydrogen molecule):

import os
folder_name = "D:\\prove_orca\\Orca_con_Python\\Hydrogen_molecule"
file_name = "H2"
os.chdir(folder_name)
os.system("D:\\ORCA\\orca" + " " + file_name + ".inp" + " " + ">" + " " + file_name + ".out")

Running the ORCA tool through Python gives me a memory error. However if I run the calculation directly from the command line everything is fine.

Here the code of the .inp file:

! HF def2-svp

%pal nprocs 16 # any number (positive integer)
end

* xyzfile 0 1 coord.xyz

The problem is not in the script, but in ORCA, that give me this error:

[file orca_tools/qcmem.cpp, line 1043, Process 5]:  OUT OF MEMORY ERROR! 

Do you have any advice or resources I can read?

$\endgroup$
4
  • $\begingroup$ Also please add the following: full error stack trace that you get in python and details of your PC specifications. And add .xyz file as a code block. This will help others to replicate your problem in order to solve it. I am basically asking for you to make your question to have a minimum reproducible example. $\endgroup$ Mar 7 at 7:50
  • 1
    $\begingroup$ Here is some resource on how to add MRE stackoverflow.com/help/minimal-reproducible-example $\endgroup$ Mar 7 at 7:52
  • 6
    $\begingroup$ If you run ORCA from command line and got no error, and then, when running from Python got an error, the problem is how Python is launching the job, not an ORCA issue. $\endgroup$
    – Camps
    Mar 7 at 11:02
  • 2
    $\begingroup$ Have you tried ASE as library? It allows you to run ORCA without using some deprecable lines (as os.system) and it can also be adjusted and tuned at your will $\endgroup$ Mar 8 at 8:32

3 Answers 3

11
$\begingroup$

I ran your script on my PC with Python and it ran perfectly fine.

Here are all of the required PC specifications:

System Specs

Windows 11 Pro
8 GB RAM
Intel(R) Core(TM) i5-10310U CPU @ 1.70GHz   2.21 GHz

Software specs:

Python version 3.10
ORCA 5.0.4, Windows, 64bit
PyCharm 2022.3.2 (Community Edition)

Detailed steps:

I list all the steps in detail here so you can reproduce them:

  1. Installed ORCA by downloading all the 3 zip files (ORCA 5.0.4, Windows, 64bit, .zip Archive, Part 1, 2 and 3 ) from the ORCA website and unzipping them into a folder : C:\orca

  2. Altered the input file to use the coordinates inline like this:

    ! HF def2-svp
    
    %pal nprocs 16 # any number (positive integer)
    end
    
    * xyzfile 0 1
    H 0.0 0.0 -0.37
    H 0.0 0.0  0.37
    *
    
  3. Added C:\orca folder to the PATH environment variable.

  4. Installed Microsoft MPI from here as per the orca manual

  1. Used the following Python code:

    import os
    
    os.system("C:\\ORCA\\orca" + " " + "C:\Vandan\codes\chemistry\orca\hydrogen\hydrogen.inp" + " " + ">" + " " + "C:\Vandan\codes\chemistry\orca\hydrogen\hydrogen.out")
    

It ran successfully and took about 4-5 seconds and creates an output file called hydrogen.out

So possible reasons why it could be failing on your PC:

  • Maybe you have a 32-bit Python on a 64-bit Windows machine
  • Maybe 16 processes are more than what your PC can accommodate, maybe try reducing it
$\endgroup$
6
  • 2
    $\begingroup$ One should avoid using os.system, it has been deprecated and the subprocess module is preferred. $\endgroup$ Mar 7 at 19:10
  • 3
    $\begingroup$ @JonathonVandezande os.system has not been deprecated. It's less powerful and flexible than subprocess, but if it works, it works. $\endgroup$
    – wizzwizz4
    Mar 7 at 23:55
  • 2
    $\begingroup$ I reduced the number of processors and then it worked fine. Thank you very much! $\endgroup$
    – Al1010
    Mar 8 at 3:16
  • 1
    $\begingroup$ @wizzwizz4, while os.system is not officially deprecated, the subprocess module states: This module intends to replace several older modules and functions: os.system os.spawn* $\endgroup$ Mar 8 at 15:25
  • $\begingroup$ But how to extract the energy from the Orca output file with Python $\endgroup$
    – Frank
    Oct 23 at 20:18
8
$\begingroup$

As the other answers and comments have suggested, the problem is probably coming from how Python is launching ORCA. Because I cannot see any reason the job should run from command line, but not from Python. Python's os.system() calls the command shell directly, and runs the string as a command there.

It might also be that you are running everything in a cluster (?). If that's the case, then the memory allocation needs to be fixed in the job submission script for the scheduler (like SLURM or SGE).

I would also recommend using softwares that can write ORCA input files and run them automatically. For example, https://github.com/duartegroup/autodE provides a high-level interface to run common calculations with ORCA or Gaussian or other QM softwares (even though the program can also do other more specialised things like transition state finding etc.)

import autode as ade

# set ORCA as the QM engine
ade.Config.hcode = "ORCA"
ade.Config.ORCA.keywords.sp = ['SP','HF','def2-SVP']
# use 16 cores
ade.Config.n_cores = 16

# read the molecule from xyz file
h2 = ade.Molecule("h2.xyz")
h2.single_point(method=ade.methods.ORCA())
print(h2.energy)  # gives -1.16401 Ha or something similar
$\endgroup$
3
$\begingroup$

What you are thinking of is a workflow manager. I have recently had some success with Signac -- it automates repetitive calculations over a parameter space, automatically saving state between subtasks that you can specify. Other similar packages include Snakemake and Fireworks, and you can always go back to good old CMake.

$\endgroup$

You must log in to answer this question.

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