Coverage for /builds/ase/ase/ase/calculators/turbomole/executor.py: 100.00%

14 statements  

« prev     ^ index     » next       coverage.py v7.5.3, created at 2025-08-02 00:12 +0000

1# fmt: off 

2 

3""" 

4Execution of turbomole binaries and scripts: 

5define, dscf, grad, ridft, rdgrad, aoforce, jobex, NumForce 

6""" 

7import os 

8from subprocess import PIPE, Popen 

9 

10 

11def get_output_filename(basename): 

12 """return the output file name from the basename of the executable""" 

13 return 'ASE.TM.' + basename + '.out' 

14 

15 

16def check_bad_output(stderr): 

17 """check status written in stderr by turbomole executables""" 

18 if 'abnormally' in stderr or 'ended normally' not in stderr: 

19 raise OSError(f'Turbomole error: {stderr}') 

20 

21 

22def execute(args, input_str=''): 

23 """executes a turbomole executable and process the outputs""" 

24 

25 stdout_file = get_output_filename(os.path.basename(args[0])) 

26 with open(stdout_file, 'w') as stdout: 

27 proc = Popen(args, stdin=PIPE, stderr=PIPE, stdout=stdout, 

28 encoding='ASCII') 

29 _stdout_txt, stderr_txt = proc.communicate(input=input_str) 

30 check_bad_output(stderr_txt) 

31 return stdout_file