2021-03-27 Python根据vasp-dos数据绘制曲线并计算d带中心
声明:未经允许,不得擅自复制、转载。
欢迎引用:
Laser-Assisted Synthesis of Bi-Decorated Pt Aerogel for Efficient Methanol Oxidation Electrocatalysis
Applied Surface Science ( IF 6.707 ) Pub Date : 2022-04-01 , DOI: 10.1016/j.apsusc.2022.153219
Liye Zhu, Ran Zhang, Xuan Liu, Jiayin Zhu, Ziang Guo, Yan Zhao
Click Here!
VASP计算结果的后处理程序:用python类来管理不同的函数,加入了数据平滑功能。
Python 类 dos:
① dosRead方法: 用于读取数据(数据格式等同于VASPKIT 112功能导出的数据格式)。
② dosDraw方法: 用于作图,同时计算并绘制d带中心位置。
③ dosSmooth方法: 用于数据平滑处理。
④ dosDataWrite方法:用于导出平滑后的数据。
⑤ 输入数据格式:
#Energy s p d tot
-9.81844 0.00000 0.00000 0.00000 0.00000
-9.80644 0.00000 0.00000 0.00000 0.00000
-9.79544 0.00000 0.00000 0.00000 0.00000
-9.78344 0.00000 0.00000 0.00000 0.00000
-9.77144 0.00000 0.00000 0.00000 0.00000
-9.76044 0.00000 0.00000 0.00000 0.00000
-9.74844 0.00000 0.00000 0.00000 0.00000
-9.73644 0.00000 0.00000 0.00000 0.00000
-9.72544 0.00000 0.00000 0.00000 0.00000
-9.71344 0.00000 0.00000 0.00000 0.00000
-9.70144 0.00000 0.00000 0.00000 0.00000
-9.69044 0.00000 0.00000 0.00000 0.00000
-9.67844 0.00000 0.00000 0.00000 0.00000
...
25.14656 0.00000 0.00000 0.00000 0.00000
25.15856 0.00000 0.00000 0.00000 0.00000
25.16956 0.00000 0.00000 0.00000 0.00000
25.18156 0.00000 0.00000 0.00000 0.00000
#!/usr/bin/env python# Author: Liye Z
# Date:2019.08.18 14:30
from tkinter.filedialog import askopenfilename
import matplotlib.pylab as plt
import numpy as np
import scipy.signal
import sys
# self指的是类实例对象本身class dos:def __init__(self, dataPathAndName):self.dataPathAndName = dataPathAndNamedef dosRead(self):energyLevel = []; sOrbit = []; pOrbit = []; dOrbit = []; tot = []if self.dataPathAndName != '':with open(self.dataPathAndName, 'r')as f:line= f.readlines()[1:]for index, row in enumerate(line):row = row.strip(' ').split()if len(row) == 5:energyLevel.append(float(row[0]))sOrbit.append(float(row[1]))pOrbit.append(float(row[2]))dOrbit.append(float(row[3]))tot.append(float(row[4]))if index < 2:print("数据为空...")sys.exit(0)return [energyLevel, sOrbit, pOrbit, dOrbit, tot]else:print("读入数据已取消...")sys.exit(0)def dosDraw(self, input):if len(input[0]) != 0:[energyLevel, sOrbit, pOrbit, dOrbit, tot] = [input[0], input[1], input[2], input[3], input[4]]plt.plot(energyLevel, sOrbit, '-', color='green', label='s')plt.plot(energyLevel, pOrbit, '-', color='blue', label='p')plt.plot(energyLevel, dOrbit, '-', color='red', label='d')# 宏观设置plt.grid(True)plt.xlim(-10, 10)plt.ylim(-0.5, 10.5)plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=0, hspace=0.25)plt.rcParams['font.sans-serif'] = 'KaiTi'plt.rcParams['axes.unicode_minus'] = Falseplt.rcParams.update({'font.size': 10})plt.ylabel('态密度')plt.xlabel('能级/eV')plt.legend()if sum(dOrbit) > 0.01:print('检测到金属元素, 自动计算d带中心...')dBandCenter = np.dot(dOrbit, energyLevel) / sum(dOrbit)dBandCenterX= dBandCenter * np.ones(len(dOrbit))dBandCenterY= np.linspace(0, 10, len(dOrbit), endpoint=True)plt.plot(dBandCenterX, dBandCenterY, '--', color='gray', label='d-band-center')else:print('检测到非金属元素...')def dosSmooth(self, data):if data != '':dataSmooth = scipy.signal.savgol_filter(data, 5, 1)dataSmooth = [list(dataSmooth[0]),list(dataSmooth[1]),list(dataSmooth[2]),list(dataSmooth[3]),list(dataSmooth[4])]return dataSmoothelse:print("数据异常:无法平滑")sys.exit(0)def dosDataWrite(self, data):if data != '':data = list(map(list,zip(*data)))print('写入态密度数据...')file_output = self.dataPathAndName[0:self.dataPathAndName.rfind('.', 1)] + 'smooth.dat'np.savetxt(file_output, data, delimiter='\t')else:print("数据异常:无法写入")sys.exit(0)dataPathAndName = askopenfilename(title='Select a data', filetypes=[('DAT', '*.dat')],initialdir=r'C:\Users\Mr. Zhu\Desktop\dos')
dosExample = dos(dataPathAndName)
dosdata = dosExample.dosRead()# 原始数据
plt.figure(figsize=(8, 6), dpi=80)
plt.subplot(2,1,1)
dosExample.dosDraw(dosdata)
plt.title("态密度")
# # Smooth
SmoothedData = dosExample.dosSmooth(dosdata)
plt.subplot(2, 1, 2)
dosExample.dosDraw(SmoothedData)
plt.title("平滑态密度")
plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=0.5)
dosExample.dosDataWrite(SmoothedData)
output = dataPathAndName[0:dataPathAndName.rfind('.', 1)] + 'figure.jpg'
plt.savefig(output, dpi=600,bbox_inches = 'tight')
plt.show()
更新:写了人机交互, 区分了LDOS和PDOS
#!/usr/bin/env python# Author: Liye Z
# Date:2019.08.18 14:30
from tkinter.filedialog import askopenfilename
import matplotlib.pylab as plt
import numpy as np
import scipy.signal
import sys# self指的是类实例对象本身class dos:def __init__(self, dataPathAndName):self.dataPathAndName = dataPathAndNamedef dosRead(self):energyLevel = [];sOrbit = [];pOrbit = [];dOrbit = [];tot = []pxOrbit = [];pyOrbit = [];pzOrbit = [];dxyOrbit = [];dyzOrbit = [];dz2Orbit = [];dxzOrbit = [];dx2Orbit = [];if self.dataPathAndName != '':with open(self.dataPathAndName, 'r') as f:line = f.readlines()[1:]if len(line) < 2:print("数据为空...")return []else:for index, row in enumerate(line):row = row.strip(' ').split()if len(row) == 11:energyLevel.append(float(row[0]))sOrbit.append(float(row[1]))pxOrbit.append(float(row[2]))pyOrbit.append(float(row[3]))pzOrbit.append(float(row[4]))pOrbit.append(float(row[2])+float(row[3])+float(row[4]))dxyOrbit.append(float(row[5]))dyzOrbit.append(float(row[6]))dz2Orbit.append(float(row[7]))dxzOrbit.append(float(row[8]))dx2Orbit.append(float(row[9]))dOrbit.append(float(row[5])+float(row[6])+float(row[7])+float(row[8])+float(row[9]))tot.append(float(row[10]))elif len(row) == 5:energyLevel.append(float(row[0]))sOrbit.append(float(row[1]))pOrbit.append(float(row[2]))dOrbit.append(float(row[3]))tot.append(float(row[4]))else:row = []if len(row) == 11:return [energyLevel, sOrbit, pxOrbit, pyOrbit, pzOrbit, dxyOrbit, dyzOrbit, dz2Orbit, dxzOrbit,dx2Orbit, tot]elif len(row) == 5:return [energyLevel, sOrbit, pOrbit, dOrbit, tot]else:return []else:print("读入数据已取消...")sys.exit(0)def dosDraw(self, input):if len(input) == 5:print('检测到局域态密度,LDOS...')[energyLevel, sOrbit, pOrbit, dOrbit, tot] = [input[0], input[1], input[2], input[3], input[4]]plt.plot(energyLevel, sOrbit, '-', color='green', label='s', linewidth=1)plt.plot(energyLevel, pOrbit, '-', color='blue', label='p', linewidth=1)plt.plot(energyLevel, dOrbit, '-', color='red', label='d', linewidth=1)plt.plot(energyLevel, tot, '-', color='black', label='tot', linewidth=1)if sum(dOrbit) > 0.01:print('检测到金属元素, 自动计算d带中心...')dBandCenter = np.dot(dOrbit, energyLevel) / sum(dOrbit)dBandCenterX = dBandCenter * np.ones(len(dOrbit))dBandCenterY = np.linspace(0, 10, len(dOrbit), endpoint=True)plt.plot(dBandCenterX, dBandCenterY, '--', color='yellow', label='d-band-center')print('d带中心:', dBandCenterX[0])else:print('检测到非金属元素...')elif len(input) == 11:print('检测到投影态密度,PDOS...')[energyLevel, sOrbit, pxOrbit, pyOrbit, pzOrbit]= [input[0], input[1], input[2], input[3], input[4]][dxyOrbit, dyzOrbit, dz2Orbit, dxzOrbit, dx2Orbit]=[input[5], input[6], input[7], input[8], input[9]]tot = input[10]pOrbit = np.array(pxOrbit) +np.array(pyOrbit) + np.array(pzOrbit)dOrbit = np.array(dxyOrbit) + np.array(dyzOrbit) + np.array(dz2Orbit) + np.array(dxzOrbit) + np.array(dx2Orbit)pOrbit = list(pOrbit)dOrbit = list(dOrbit)plt.plot(energyLevel, sOrbit, '-', color='green', label='s', linewidth=1)plt.plot(energyLevel, pOrbit, '-', color='blue', label='p', linewidth=1)plt.plot(energyLevel, dOrbit, '-', color='red', label='d', linewidth=1)plt.plot(energyLevel, pxOrbit, '-', color='#FF00FF', label='px', linewidth=0.2)plt.plot(energyLevel, pyOrbit, '-', color='#FF7256', label='py', linewidth=0.2)plt.plot(energyLevel, pzOrbit, '-', color='#FF3E96', label='pz', linewidth=0.2)plt.plot(energyLevel, dxyOrbit, '-', color='#836FFF', label='dxy', linewidth=0.2)plt.plot(energyLevel, dxzOrbit, '-', color='#4876FF', label='dxz', linewidth=0.2)plt.plot(energyLevel, dyzOrbit, '-', color='#00BFFF', label='dyz', linewidth=0.2)plt.plot(energyLevel, dx2Orbit, '-', color='#8A2BE2', label='dx2', linewidth=0.2)plt.plot(energyLevel, dz2Orbit, '-', color='#00BFFF', label='dz2', linewidth=0.2)plt.plot(energyLevel, tot, '-', color='black', label='tot', linewidth=1)spdData = [energyLevel, sOrbit, pOrbit, dOrbit, tot]spdData = list(map(list, zip(*spdData)))print(spdData)file_output = self.dataPathAndName[0:self.dataPathAndName.rfind('.', 1)] + 'spd.dat'np.savetxt(file_output, spdData, delimiter='\t')if sum(dOrbit) > 0.01:print('检测到金属元素, 自动计算d带中心...')dBandCenter = np.dot(dOrbit, energyLevel) / sum(dOrbit)dBandCenterX = dBandCenter * np.ones(len(dOrbit))dBandCenterY = np.linspace(0, 10, len(dOrbit), endpoint=True)plt.plot(dBandCenterX, dBandCenterY, '--', color='yellow', label='d-band-center')print('d带中心:', dBandCenterX[0])else:print('检测到非金属元素...')else:print('数据异常')sys.exit(0)# 宏观设置plt.grid(True)plt.xlim(-10, 3)plt.ylim(-0.5, 5)plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=0, hspace=0.25)plt.rcParams['font.sans-serif'] = 'KaiTi'plt.rcParams['axes.unicode_minus'] = Falseplt.rcParams.update({'font.size': 9})plt.ylabel('态密度', fontdict={'size': 9})plt.xlabel('能级/eV', fontdict={'size': 9})plt.legend(prop={'family': 'Times New Roman', 'size': 7}, ncol=2)plt.yticks(fontproperties='Times New Roman', size=9)plt.xticks(fontproperties='Times New Roman', size=9)def dosSmooth(self, data):print('数据平滑...')if len(data) == 5:dataSmooth = scipy.signal.savgol_filter(data, 5, 3, mode = 'nearest')dataSmooth = [list(dataSmooth[0]), list(dataSmooth[1]), list(dataSmooth[2]),list(dataSmooth[3]), list(dataSmooth[4])]return dataSmoothelif len(data) == 11:dataSmooth = scipy.signal.savgol_filter(data, 5, 3, mode = 'nearest')dataSmooth = [list(dataSmooth[0]), list(dataSmooth[1]), list(dataSmooth[2]),list(dataSmooth[3]), list(dataSmooth[4]),list(dataSmooth[5]),list(dataSmooth[6]), list(dataSmooth[7]),list(dataSmooth[8]),list(dataSmooth[9]), list(dataSmooth[10])]return dataSmoothelse:print("数据异常:无法平滑")return []def dosDataWrite(self, data):if data != '':data = list(map(list, zip(*data)))print('写入态密度数据...')file_output = self.dataPathAndName[0:self.dataPathAndName.rfind('.', 1)] + 'smooth.dat'np.savetxt(file_output, data, delimiter='\t')else:print("数据异常")data = []print('写入态密度数据...')file_output = self.dataPathAndName[0:self.dataPathAndName.rfind('.', 1)] + 'smooth.dat'np.savetxt(file_output, data, delimiter='\t')continueRead = 1
# while continueRead:
# msg = input('是否读入数据([0] No/[1] Yes):')
# if msg == '1':
# print('读取数据...')
# dataPathAndName = askopenfilename(title='Select a data', filetypes=[('DAT', '*.dat')],
# initialdir=r'C:\Users\Mr. Zhu\Desktop\dos')
# dosExample = dos(dataPathAndName)
# dosdata = dosExample.dosRead()
# dosExample.dosDraw(dosdata)
# plt.subplot(2, 1, 1)
# dosExample.dosDraw(dosdata)
# plt.title("态密度")
#
# #Smooth
# SmoothedData = dosExample.dosSmooth(dosdata)
# plt.subplot(2, 1, 2)
# dosExample.dosDraw(SmoothedData)
# plt.title("平滑态密度")
# plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=0.5)
# dosExample.dosDataWrite(SmoothedData)
# output = dataPathAndName[0:dataPathAndName.rfind('.', 1)] + 'figure.jpg'
# plt.savefig(output, dpi=600, bbox_inches='tight')
# plt.show()
# elif msg == '0':
# print('停止读取数据...')
# continueRead = 0
# else:
# print('输入错误,请重试...')
while continueRead:msg = input('是否读入数据([0] No/[1] Yes):')if msg == '1':print('读取数据...')dataPathAndName = askopenfilename(title='Select a data', filetypes=[('DAT', '*.dat')],initialdir=r'C:\Users\Mr. Zhu\Desktop\dos')dosExample = dos(dataPathAndName)dosdata = dosExample.dosRead()dosExample.dosDraw(dosdata)plt.subplot(2, 1, 1)dosExample.dosDraw(dosdata)plt.title("态密度")#SmoothSmoothedData = dosExample.dosSmooth(dosdata)plt.subplot(2, 1, 2)dosExample.dosDraw(SmoothedData)plt.title("平滑态密度")plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=0.5)dosExample.dosDataWrite(SmoothedData)output = dataPathAndName[0:dataPathAndName.rfind('.', 1)] + 'figure.jpg'plt.savefig(output, dpi=600, bbox_inches='tight')plt.show()elif msg == '0':print('停止读取数据...')continueRead = 0else:print('输入错误,请重试...')
2021-03-27 Python根据vasp-dos数据绘制曲线并计算d带中心相关推荐
- 2021/03/27 K8S集群日志与监控
第1章 k8s日志收集 1.1 节点日志代理架构 官网对K8S整个日志架构相关的介绍 总体分为三种方式: 使用每个节点上运行的节点级日志记录代理 在应用程序的pod中,包含专门记录日志的sidecar ...
- 用Python玩转统计数据:取样、计算相关性、拆分训练模型和测试
导读:本文会介绍一些技术,帮你更好地理解数据,以及探索特征之间的关系. 本文使用Python建立对数据的理解.我们会分析变量的分布,捋清特征之间的关系.最后,你会学习给样本分层,并将数据集拆分成测试集 ...
- python写入excel表格数据绘制图表_(原创)xlsxwriter,python excel 写入数据\图表等操作_图表操作(二)...
前面分享了使用xlsxwriter创建excel和写入数据GUC:(原创)xlsxwriter,python excel 写入数据\图表等操作_创建.写入(一)zhuanlan.zhihu.com ...
- python筛选股票5日线以上_[python]沪深龙虎榜数据进一步处理,计算日后5日的涨跌幅...
1 #coding=utf-8 2 3 #读取'[wait]'开头的csv文件 4 #copyright @ WangXinsheng 5 #http://www.cnblogs.com/wangxi ...
- Python读取EXCEL省份数据绘制地图
文章目录 EXCEL数据表 读取 Excel 数据并绘图 EXCEL数据表 python操作excel主要用到 xlrd 和 xlwt 这两个库,即读写excel. 安装xlrd:在cmd窗口 pip ...
- python写入excel表格数据绘制图表,Python对数据写入Execl文件并生成图表
Python对数据写入Execl文件并生成图表 需求: 为了做测试或者对爬虫程序爬取数据进行分析汇总,我们时常会将数据生成报表,但是如果我们想将报表生成在Excel中,这时候就可以借助xlsxwrit ...
- python读excel表格数据绘制图表_Python读取Excel数据生成图表 v2.0
原博文 2020-06-15 15:09 − ## Python读取Excel数据生成图表 v2.0 ## 一.需求背景 自己一直在做一个周基金定投模拟,每周需要添加一行数据,并生成图表.以前一直是用 ...
- Python为输出的数据绘制表格
在Python开发环境中,输出数据时没有表格.没有对齐,当数据较多的情况下看起来非常的凌乱,估计很多人像我一样为这个事情而烦恼. 左图是我在PyCharm开发环境下输出的数据.下面我们通过Python ...
- Python基础与大数据应用实验——个人所得税计算
一.实验内容 设计个人所得税计算器,要求当劳资人员输入员工姓名和应纳税收入后,能够自动计算出该员工当月应交的个税. 计算公式:应纳个人所得税税额=应纳税所得额*适用税率-速算扣除数 二.实验目的 通过 ...
最新文章
- php yii orm,Yii中的sql查询的位置(或任何支持ORM的框架)?
- 现实给了梦想多少时间
- XamarinSQLite教程创建数据库
- ie支持css3圆角实现的俩种方式
- 顺便发现一bug??
- 如何提高软件可维护性
- 动态规划 dp02 最长非降子序列问题 c代码
- 浅析phpwind9.0之登陆机制
- vant显示日期格式_Vue+Vant ui实现日期时间选择
- 通讯中断 pc_S7程序RFID 与PC连接区别FB 65/UDT65
- hdu 2089 不要62【数位dp】
- AAAI'22 | 中稿的论文网友找出致命漏洞?
- Perl 学习手札之十三:building function
- Map集合之LinkedHashmap
- Java 打印100以内的所有奇数和偶数
- dilated convolution
- 查看windows系统默认编码 修改windows系统默认编码
- 从Windows过渡到Mac OS X上手使用经验谈
- sublime text3解决Gosublime无法自动补全代码
- 微信公众号开发整理(四)--音乐消息回复