Repository navigation
Expand file tree
/
Copy pathorca_checker.py
More file actions
executable file
·44 lines (31 loc) · 1.46 KB
/
Copy pathorca_checker.py
File metadata and controls
executable file
·44 lines (31 loc) · 1.46 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/python
__author__ = 'RubiaLab'
__email__ = 'rubialab@rubialab.de'
__version__ = '1.0'
def main():
import sys
import os
for filename in sys.argv[1:]:
if not os.path.isfile(filename):
print(f'Specified file {filename} does not exist. Moving to next file...')
continue
print(f'Checking calculation output "{filename}" for completeness...')
with open(filename, 'r') as output:
calc_output = output.readlines()
normal_termination = any('****ORCA TERMINATED NORMALLY****' in line for line in calc_output)
if normal_termination:
print(f'Calculation in file {filename} terminated normally. Nothing to do.')
continue
print(f'Calculation in file {filename} did not terminate normally. Removing last unfinished geometry optimization cycle...')
cycle_start_indices = [i for i, line in enumerate(calc_output) if 'GEOMETRY OPTIMIZATION CYCLE' in line]
if not cycle_start_indices:
print(f'No geometry optimization cycles found in {filename}. Skipping.')
continue
last_cycle_index = cycle_start_indices[-1]
trim_index = max(0, last_cycle_index - 2)
cleaned_output = calc_output[:trim_index]
with open(filename, 'w') as output:
output.writelines(cleaned_output)
print(f'Removed lines from last incomplete cycle in file {filename}.')
if __name__ == '__main__':
main()