2021-03-27 Python calculates the center of the d-band based on the density of states data and draws the curve

from tkinter.filedialog import askopenfilename
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
tag = 1
while tag:
    data_file_path = askopenfilename(title='Select a data', filetypes=[('DAT', '*.dat')], initialdir='D:\\doc_E\\Pd5')
    df = pd.read_table(data_file_path, sep="\s+",
                       usecols=['#Energy', 's', 'py', 'pz', 'px', 'dxy', 'dyz', 'dz2', 'dxz', 'dx2', 'tot'])
    energy = df.iloc[:, 0]
    s = df.iloc[:, 1]
    py = df.iloc[:, 2]
    pz = df.iloc[:, 3]
    px = df.iloc[:, 4]
    dxy = df.iloc[:, 5]
    dyz = df.iloc[:, 6]
    dz2 = df.iloc[:, 7]
    dxz = df.iloc[:, 8]
    dx2 = df.iloc[:, 9]
    tot = df.iloc[:, 10]
    p = py + px + pz
    d = dxy + dyz + dz2 + dxz + dx2
# 采用大师兄的建议, 在0-10 噪音较强的时候,适当调整积分上限。
# Calculate d band center: https://www.bigbrosci.com/2018/02/10/ex41/#2-%E6%B1%82%E7%94%B5%E5%AD%90%E6%95%B0%E7%9B%AE
# d band center 的积分区间为整个d带:即从负无穷到正无穷。本例我们用区间 [-6, 2]作为例子!有时候大家会对积分
# 的区间产生疑问。一般来说积分区间是从负无穷到正无穷,但是:
# 1)如上图,[-9,-8]这个区间Density为0,积分从[-9,4.0] 和[-8,4.0]结果没什么区别。
# 2)如果我们关心的是[-6,4.0]这一部分的性质,倘若4.0以后的部分会产生很大的噪音,那么我们也可以只从-6积分到4.0。
# 所以,积分区间也不是很绝对,大家要根据自己的体系合理选择。
    tag1 = 1
    while tag1:
        ask = input('是否属于金属原子[y/n]:')
        if(ask == 'y'):
            plt.plot(energy, s, '-', color='green', label='s')
            plt.plot(energy, p, '-', color='blue', label='p')
            plt.plot(energy, d, '-', color='red', label='d')
            energy_end = 4
            energy[energy > energy_end] = 0
            d_center = np.dot(d, energy)/sum(d)
            d_center_X = d_center*np.ones(len(s))
            d_center_Y = np.linspace(0, 10, len(s), endpoint=True)
            plt.plot(d_center_X, d_center_Y, '--', color='gray', label='d-band-center')
            plt.grid(True)
            plt.xlabel('Energy/eV')
            plt.ylabel('DOS')
            plt.xlim(-10, 10)
            plt.ylim(-0.5, 10.5)
            plt.legend()
            title = input('请输入绘图的标题:')
            plt.title(title)
            plt.show()
            tag1 = 0
        elif (ask == 'n'):
            plt.plot(energy, s, '-', color='green', label='s')
            plt.plot(energy, p, '-', color='blue', label='p')
            plt.plot(energy, d, '-', color='red', label='d')
            energy_end = 4
            energy[energy > energy_end] = 0
            plt.grid(True)
            plt.xlabel('Energy/eV')
            plt.ylabel('DOS')
            plt.xlim(-10, 10)
            plt.ylim(-0.5, 10.5)
            plt.legend()
            title = input('请输入绘图的标题:')
            plt.title(title)
            plt.show()
            tag1 = 0
        else:
            print('输入错误,请重新输入')
            tag1 = 1

Guess you like

Origin blog.csdn.net/you_us/article/details/115262023