-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsoc.py
55 lines (44 loc) · 1.22 KB
/
soc.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
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
"""
soc
===
This module contains functions which are useful to
process spin orbit coupling (SOC) data generated from by the RSPt software.
"""
import numpy as np
def represents_int(s):
"""
Return boolean about whether it is possible to
convert input parameter to an int.
"""
try:
int(s)
return True
except ValueError:
return False
def parse_core_energies(path):
"""
Return all the core energies stored in RSPt out file.
path - path to RSPt out file to parse.
"""
with open(path, 'r') as f:
data = f.readlines()
its = [] # indices for the different types
ts = [] # types
# For each type, find first row about core energies
for i, row in enumerate(data):
if 'type:' in row:
its.append(i)
t = int(row.split()[1])
ts.append(t)
es = {} # energies for the different types
# Loop over all types
for it, t in zip(its, ts):
# First row containing energies
i = it + 4
es[t] = []
while represents_int(data[i].split()[0]):
es[t].append(float(data[i].split()[2]))
i += 1
es[t] = np.array(es[t])
return es