24小时热门版块排行榜    

查看: 2545  |  回复: 16
【奖励】 本帖被评价13次,作者锐利的碎片增加金币 10

锐利的碎片

木虫 (正式写手)


[资源] 【原创】处理elk能带的程序

自己写的用python处理elk能带的程序
回复此楼

» 收录本帖的淘帖专辑推荐

材料计算模拟实用技巧 第一性原理计算辅助工具

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

锐利的碎片

木虫 (正式写手)


用面向对象重新写了一遍程序,现在只写了elk的类,处理其他程序(比如vasp)结果的程序可以很方便的加进来。主程序部分没写,这个应该没有多难。
CODE:
class Band():
    def write_data(self):
        if self.nspin==1:
            fout=file('band.data','w')
            for i in range(self.ndiv):
                fout.write("%12.8f "%self.band[0][i])
                for j in range(self.nband):
                    fout.write("%12.8f "%self.band[j+1][i])
                fout.write('\n')
            fout.close()
        elif self.nspin==2:
            foutup=file('bandup.data','w')
            foutdn=file('banddn.data','w')
            for i in range(self.ndiv):
                foutup.write("%12.8f "%self.band[0][i])
                foutdn.write("%12.8f "%self.band[0][i])
                for j in range(self.nband/2):
                    foutup.write("%12.8f "%self.band[j+1][i])
                foutup.write('\n')
                for j in range(self.nband/2,self.nband):
                    foutdn.write("%12.8f "%self.band[j+1][i])
                foutdn.write('\n')
            foutup.close()
            foutdn.close()

    def view_band(self,emin,emax,title,xlabel,ylabel):
        import numpy as np
        import matplotlib.pyplot as plt
        #plot setup
        plt.title(title)
        plt.xlabel(xlabel)
        plt.ylabel(ylabel)
        plt.xlim(self.kpos[0],self.kpos[-1])
        plt.ylim(emin,emax)
        plt.xticks(self.kpos,self.kpname)
        plt.grid(linestyle='-')
        plt.gca().xaxis.grid(True)
        plt.gca().yaxis.grid(False)
        #plot bands
        for i in range(self.nband):
            x=self.band[0]
            y=self.band[i+1]
            if np.min(y)emax:
                continue
            else:
                if self.nspin==1:
                    plt.plot(x,y,'r-')
                elif self.nspin==2:
                    if i                         plt.plot(x,y,'r-')
                    else:
                        plt.plot(x,y,'b--')
        plt.plot([self.kpos[0],self.kpos[-1]],[0.0,0.0],\
                 color='black',linestyle='--')
        plt.text(0.0,0.1,r'$E_F$=%6.3f eV'%self.fermi)
        plt.show()

class ElkBand(Band):
    def __init__(self):
        import sys
        import numpy as np
        try:
            fmain=file('elk.in','r')
            fpos=file('BANDLINES.OUT','r')
            fband=file('BAND.OUT','r')
            ffermi=file('EFERMI.OUT','r')
        except IOError:
            print 'Error in open nessary inputs. Check your input file'
            sys.exit()
        # initalize
        self.kpname=[] #names of kpoints
        self.kpos=[] #positions of special kpoints in G space
        self.nspin=1 #number of spins
        self.nband=0 #number of band
        self.band=[] #banddata
        # get self.nspin self.kpname self.nkp(number of special kpoints)
        # self.ndiv
        while True:
            tmp=fmain.readline()
            if len(tmp)==0:
                break
            if tmp.strip()=='spinpol':
                if fmain.readline().strip()=='.true.':
                    self.nspin=2
            if tmp.strip()=='plot1d':
                self.nkp,self.ndiv=fmain.readline().split()[0:2]
                self.nkp=int(self.nkp)
                self.ndiv=int(self.ndiv)
                for i in range(self.nkp):
                    self.kpname.append('$'+str(fmain.readline().split()[3])+'$')
        # get self.kpos
        while True:
            tmp=fpos.readline()
            if len(tmp)==0:
                break
            self.kpos.append(float(tmp.split()[0]))
            fpos.readline()
            fpos.readline()
        # get self.fermi
        self.fermi=27.2114*float(ffermi.readline().strip())
        # get self.nband self.band
        while True:
            tmp=fband.readline()
            if len(tmp)==0:
                break
            if len(tmp.strip())==0 and len(tmp)!=0:
                self.nband=self.nband+1
        rawband=np.loadtxt('BAND.OUT')
        kp=rawband[0:self.ndiv,0]
        self.band.append(kp)
        for i in range(self.nband):
            eig=27.2114*rawband[i*self.ndiv:(i+1)*self.ndiv,1]
            self.band.append(eig)
        #close files
        fmain.close()
        fpos.close()
        fband.close()
        ffermi.close()

    def write_data(self):
        Band.write_data(self)

    def view_band(self,emin=-10.0,emax=15.0,title='Band Plot',\
                 xlabel='K-Path',ylabel='Energy / eV'):
        Band.view_band(self,emin,emax,title,xlabel,ylabel)

[ Last edited by 锐利的碎片 on 2011-2-26 at 12:17 ]
2楼2011-02-26 09:15:54
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

akakcolin

金虫 (著名写手)


★★★★★ 五星级,优秀推荐

赞赞
3楼2011-02-26 11:39:46
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
支持原创,赞一个,顶!!
4楼2011-02-26 13:26:03
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

lixiao85

银虫 (小有名气)


★★★★★ 五星级,优秀推荐

或许以后能用上
5楼2011-02-26 14:49:39
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

★★★★★ 五星级,优秀推荐

★★★★★ 五星级
6楼2011-02-26 16:30:45
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

liangpei

木虫 (职业作家)


★★★ 三星级,支持鼓励

这个程序是支持wien2k还是vasp的》》》
7楼2011-08-19 10:29:23
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

chambana

铁虫 (初入文坛)


支持原创,赞一个,顶!!
14楼2016-10-20 07:31:08
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

jzjy1994

新虫 (小有名气)


★★★★★ 五星级,优秀推荐

大佬
17楼2017-10-28 17:41:39
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
简单回复
xh5128楼
2012-01-06 07:17   回复  
五星好评  顶一下,感谢分享!
tanloer9楼
2012-02-13 15:28   回复  
五星好评  顶一下,感谢分享!
mink10楼
2014-06-18 07:40   回复  
五星好评  顶一下,感谢分享!
102424790011楼
2014-07-03 21:32   回复  
五星好评  顶一下,感谢分享!
zwynu12楼
2014-09-24 21:57   回复  
五星好评  顶一下,感谢分享!
Toapollo13楼
2015-03-28 20:58   回复  
三星好评  顶一下,感谢分享!
gooselin15楼
2016-11-23 14:11   回复  
五星好评  顶一下,感谢分享!
whyyzf572516楼
2017-10-27 17:10   回复  
五星好评  顶一下,感谢分享!
相关版块跳转 我要订阅楼主 锐利的碎片 的主题更新
☆ 无星级 ★ 一星级 ★★★ 三星级 ★★★★★ 五星级
普通表情 高级回复 (可上传附件)
信息提示
请填处理意见