-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract_susc.py
executable file
·47 lines (35 loc) · 1.37 KB
/
extract_susc.py
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
45
46
47
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
A script to extract simulated magnetic susceptibility data
from a SINGLE_ANISO/POLY_ANISO output file.
written 2019 by Michael Böhme
https://github.com/micb25/chemtools
"""
import sys, re
if ( (len(sys.argv) < 2) or (len(sys.argv) > 2) ):
sys.exit("Usage: %s poly_aniso.output" % ( sys.argv[0] ))
found_data = found_sep = False
try:
susc = open(sys.argv[1], 'r')
lines = susc.read().split("\n")
susc.close()
except:
sys.exit("Can't read SINGLE_ANISO/POLY_ANISO output file '%s'!" % ( sys.argv[1] ) )
try:
for line in lines:
if ( re.findall(r'^Units', line) ) and ( found_data == False ) and ( found_sep == False):
found_data = True
elif ( found_data == True ):
if re.findall(r'^----', line):
if ( found_sep == False ):
found_sep = True
else:
break
elif ( found_sep == True ) and ( line[0] == ' ' ):
chit_data = re.findall(r'([0-9]*\.[0-9]*)', line)
print("%12.6f %18.12f %18.12f" % ( float(chit_data[0]), float(chit_data[2]), float(chit_data[3]) ) )
else:
break
except:
sys.exit("SINGLE_ANISO/POLY_ANISO output file '%s' seems to be corrupt!" % ( sys.argv[1] ) )