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

14 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-11-27 15:21 +0000

1""" 

2Execution of turbomole binaries and scripts: 

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

4""" 

5 

6import os 

7from subprocess import PIPE, Popen 

8 

9 

10def get_output_filename(basename): 

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

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

13 

14 

15def check_bad_output(stderr): 

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

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

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

19 

20 

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

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

23 

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

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

26 proc = Popen( 

27 args, stdin=PIPE, stderr=PIPE, stdout=stdout, encoding='ASCII' 

28 ) 

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

30 check_bad_output(stderr_txt) 

31 return stdout_file