File: executor.py

package info (click to toggle)
python-ase 3.26.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,484 kB
  • sloc: python: 148,112; xml: 2,728; makefile: 110; javascript: 47
file content (31 lines) | stat: -rw-r--r-- 981 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# fmt: off

"""
Execution of turbomole binaries and scripts:
define, dscf, grad, ridft, rdgrad, aoforce, jobex, NumForce
"""
import os
from subprocess import PIPE, Popen


def get_output_filename(basename):
    """return the output file name from the basename of the executable"""
    return 'ASE.TM.' + basename + '.out'


def check_bad_output(stderr):
    """check status written in stderr by turbomole executables"""
    if 'abnormally' in stderr or 'ended normally' not in stderr:
        raise OSError(f'Turbomole error: {stderr}')


def execute(args, input_str=''):
    """executes a turbomole executable and process the outputs"""

    stdout_file = get_output_filename(os.path.basename(args[0]))
    with open(stdout_file, 'w') as stdout:
        proc = Popen(args, stdin=PIPE, stderr=PIPE, stdout=stdout,
                     encoding='ASCII')
        _stdout_txt, stderr_txt = proc.communicate(input=input_str)
        check_bad_output(stderr_txt)
    return stdout_file