-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdos_non_periodic.py
124 lines (109 loc) · 3.77 KB
/
dos_non_periodic.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import numpy as np
import os,sys
import argparse
import matplotlib.pyplot as plt
def dos_plot(dat,fermi):
fig, ax = plt.subplots(1, 1)
ax.plot(dat[:, 0] - fermi, dat[:, 1])
ax.set_ylabel('density of states')
ax.set_xlabel('Energy (eV)')
ax.set_xlim(-1.0, 1.0)
ax.set_ylim(-0.5, 80.0)
# 在指定的 x 坐标上绘制一条虚线
x_coordinate = 0 # 你想要绘制虚线的 x 坐标
ax.axvline(x=x_coordinate, color='r', linestyle='--', linewidth=1)
# 保存图像
plt.savefig('dos_plot.png') # 你可以更改文件名和格式,如 'dos_plot.pdf'
def func_gaussian(E, En, sigma):
occu_probability = np.exp(-((E - En) / sigma) ** 2)
return occu_probability
def func_dos(E: np.array, En: np.array, sigma):
m, n = len(E), len(En)
dos = []
for i in range(m):
states = 0
for j in range(n):
state = func_gaussian(E[i], En[j], sigma)
states = states + state
# print(E[i],En[j],state,states)
dos_line = [E[i], states]
dos.append(dos_line)
return dos
def read_data(file: str):
assert os.path.isfile(file), f"File does not exist {file}"
print(f"File exists:{file}")
with open(file, "r") as f:
lines = f.readlines()
count = 0
eigen_values = []
print(len(lines))
for line in lines:
if not line.isspace():
parts = line.strip().split()
try:
eigen_value = float(parts[1])
eigen_values.append(eigen_value)
count += 1
except ValueError:
pass
else:
pass
print("the infomation of eigenvalues:", np.shape(eigen_values), type(eigen_values), "number of eigenvalues:",
count)
return eigen_values
def main(fermi:float,sigma:float,point_density:float,input:str,output:str):
energy_window=[-5.0,-3.0]
sampling_point=int((energy_window[1]-energy_window[0])/point_density)
#eigenvalues=np.array(read_data('./GeSe_90.0-kpoint-G.BANDDAT1'))+fermi
#eigenvalues=np.array(read_data('./GeSe_90.2.BANDDAT1'))
eigenvalues=np.array(read_data(input))+fermi
eigen_min,eigen_max=np.min(eigenvalues),np.max(eigenvalues)
#energy=np.linspace(eigen_min,eigen_max,sampling_point)
energy=np.linspace(energy_window[0],energy_window[1],sampling_point)
print(f'energy range from {eigen_min} to {eigen_max}')
dat=np.array(func_dos(energy,eigenvalues,sigma))
dos_plot(dat,fermi)
#print(energy[0],eigenvalues[0])
print(np.shape(dat))
np.savetxt(output,dat)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="calculate the DOS for non-periodic system!!")
parser.add_argument(
"--fermi",
"-f",
type=float,
required=True,
default= -4.048,
help="the fermi energy of the system, default -4.048 eV",
)
parser.add_argument(
"--sigma",
"-s",
type=float,
default=0.01,
required=True,
help="the smearing width of Gaussian method default 0.01 eV",
)
parser.add_argument(
"--point_density",
"-pd",
type=float,
default=0.001,
help="the sampling density of energy window (-5.0,-3.0)!!",
)
parser.add_argument(
"--input",
"-i",
type=str,
default="openmx.BANDDAT1",
help="the eigenvalue file of system!!",
)
parser.add_argument(
"--output",
"-o",
type=str,
default="dos.dat",
help="the output data file name!!",
)
args = parser.parse_args()
main(**vars(args))