-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnatos.py
85 lines (64 loc) · 2.28 KB
/
natos.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
"""
Oxidation states “naturally”: A Natural Bond Orbital method
for determining transition metal oxidation states
Albert J.Webster, Chelsea M.Mueller, Neil P.Foegen,
Patrick H.-L.Sit, Erin D. Speetzen, Drew W.Cunningham,
Jason S. D’Acchiolia
Polyhedron, Volume 114, 16 August 2016, Pages 128-132
https://doi.org/10.1016/j.poly.2015.11.018
Reimplementation of their perl+octave combination to read the
NAO density matrix section to get the alpha and beta occupations.
"""
import sys
import re
import numpy as np
from numpy import linalg as LA
def getContent(filename):
with open(filename, "r") as file:
lines = file.readlines()
return lines
def getIndices(lines):
densitystart = []
densityend = []
index = []
for n in np.arange(len(lines)):
line = lines[n]
if "NAO density matrix:" in line:
densitystart.append(n)
if "NATURAL BOND ORBITAL ANALYSIS, alpha spin orbitals:" in line:
densityend.append(n)
if "NATURAL BOND ORBITAL ANALYSIS, beta spin orbitals:" in line:
densityend.append(n)
if re.search("Val\(\ [0-9]d\)", line):
sline = line.split()
index.append(sline[0])
index = index[:5]
return densitystart, densityend, index
def getOccupancies(blockstart, blockend, indices, lines):
n = int(blockstart) + 1
m = int(blockend)
templist = []
for j in np.arange(n, m):
line = lines[j]
if "NAO" in line:
nao = line.split()
nao = nao[1:]
for k in np.arange(len(nao)):
for index in indices:
if nao[k] == index:
for row in indices:
ii = j + int(row) + 1
array = lines[ii].split(")")
array2 = array[1].split()
templist.append(float(array2[k]))
mat = np.array(templist).reshape(5, 5)
occupancies = LA.eigvals(mat)
return occupancies
if __name__ == "__main__":
LINES = getContent(sys.argv[1])
START, END, INDICES = getIndices(LINES)
ALPHA = getOccupancies(START[-2], END[-2], INDICES, LINES)
BETA = getOccupancies(START[-1], END[-1], INDICES, LINES)
print(ALPHA)
print(BETA)