-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathnist_partition.py
100 lines (65 loc) · 1.98 KB
/
nist_partition.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
86
87
88
89
90
91
92
93
94
95
96
97
98
#https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19700011342.pdf
'''
This script calculates the partition function from the Energy levels.
Date: November 2019
Author: Simon Grimm
'''
import numpy as np
import argparse
def gTot():
#This function calculates the total statistical weight for a quantum number n
for n in range(0, 15):
gtot = 0
for l in range(0, n):
g = 2 * l + 1
gtot += g * 2
#print(n, l, g)
print(n, gtot)
def partition(z, I):
file = ("NIST_ELevels%02d%02d.dat" % (z, I))
outfile = open('NIST%02d%02d.pf' % (z, I),'w')
Conf, Term, J, g, E = np.loadtxt(file, dtype='str', skiprows=1, usecols=(0, 1, 2, 3,4), delimiter='\t',unpack=True)
print('NIST%02d%02d.pf' % (z, I), len(Term))
#check if the Term is given, Note that for H I Energy levels are duplicated
#Duplicated levels can be filtered out by this check
noTerm = 0
for i in range(len(Term)):
#print(Conf[i], Term[i], J[i], g[i], E[i])
if Term[i] == '':
noTerm = 1
if(noTerm == 1):
print("no Term")
for t in range(10, 10000, 10):
T = float(t)
Z = 0.0
for i in range(len(g)):
try:
if((Conf[i].isnumeric() == True or Conf[i] == '1s') or z > 1):
#print(Conf[i], Term[i], J[i], '|',g[i],'|',E[i],'|')
if(g[i] != '' and E[i] != '' and E[i] != ' '):
# remove '[' and ']' from Energy
E[i] = E[i].replace('[', '')
E[i] = E[i].replace(']', '')
#print(Conf[i], Term[i], J[i], g[i], E[i])
gf = float(g[i])
Ef = float(E[i])
#exp(-h c E /(k_B T))
z0 = gf * np.exp(-1.4387770 * Ef/T)
if(t == 0):
print(i, gf, Ef, Z, z0)
Z += gf * np.exp(-1.4387770 * Ef/T)
except:
continue
print(T, Z, file = outfile)
outfile.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('-Z', '--Z', type=int,
help='Z', default = 1)
parser.add_argument('-I', '--I', type=int,
help='I', default = 0)
args = parser.parse_args()
Z = args.Z
I = args.I
#gTot()
partition(Z,I)