22import sys
33import matplotlib .pyplot as plt
44from readvasp import *
5- import plotting2
5+ from plotting import plot_band , plot_dos , plot_band_dos
66import yaml
77import os
88
@@ -34,7 +34,7 @@ def from_input(config):
3434 config ["plotset" ]["plot_type" ] = type
3535 config ["groupinfo" ] = [None ]
3636 if type > 0 :
37- config ["Nbandpicture" ] = int (input ("How many bands ?\n " ))
37+ config ["Nbandpicture" ] = 1 if config [ "plotset" ][ "object" ] == "DOS" else int (input ("How many groups to plot the band ?\n " ))
3838 config ["groupinfo" ] = []
3939 for N in range (config ["Nbandpicture" ]):
4040 print ("next group\n " )
@@ -51,7 +51,7 @@ def from_input(config):
5151 if tmp :
5252 groups .append (tmp )
5353 config ["groupinfo" ].append (groups )
54- tmp = input ('Energy range, e.g -2 5 default is [-2 5]\n ' ) or "-2 5"
54+ tmp = input ('Energy range, e.g. -2 5; default is [-2 5]\n ' ) or "-2 5"
5555 config ["plotset" ]['Elim' ] = [float (i ) for i in tmp .split ()]
5656 config ["plotset" ]['fermi' ] = input ("Set 0eV to fermi? (VBM,CBM,band No. or any Energy)\n "
5757 "F or 0 will change nothing.\n "
@@ -65,38 +65,38 @@ def ini_config():
6565 plotset = {"plot_type" : 0 , "object" : "band" ,
6666 "scale" : 50 ,
6767 "Elim" : [- 2 , 5 ], "fermi" : "vbm" , "int" : 100 }
68- figset = {"figsize" : (7 , 6 ), "dpi" : 150 }
68+ figset = {"figsize" : (7 , 6 ), "dpi" : 300 , "format" : "png" }
6969 fontset = {"fontsize" : 16 , "font" : "Arial" }
7070 fileset = {"eigfile" : ["EIGENVAL" ], "dosfile" : "DOSCAR" , "prosfile" : [
7171 "PROCAR" ], "kptfile" : ["KPOINTS" ], "posfile" : "POSCAR" }
72+ paras = {"dos_paras" :{},"band_paras" :{},"dos_legend_paras" :{},"band_legend_paras" :{"loc" :"upper right" }}
7273 config = {"method" : method ,
7374 "plotset" : plotset ,
7475 "fileset" : fileset ,
7576 "figset" : figset ,
76- "fontset" : fontset }
77+ "fontset" : fontset ,
78+ "paras" :paras }
7779 return config
7880
7981
8082def read_config (file = 'cvasp.yml' ):
8183 with open (file ) as f :
82- data = yaml .load (f , Loader = yaml .FullLoader )
83- # print(data)
84- return data
84+ config = yaml .load (f , Loader = yaml .FullLoader )
85+ return config
8586
8687
8788def cvasp (config , axs = None ):
88- print (config ["plotset" ]["object" ].lower ())
8989 if config ["plotset" ]["object" ].lower () == "band" :
9090 KPT = from_kpoints .get_kpoints (config ["fileset" ]["kptfile" ])
9191 if config ["plotset" ]["plot_type" ] > 0 :
9292 eigdata = from_procar .get_procar (config ["fileset" ]["prosfile" ])
9393 else :
9494 eigdata = from_eigenval .get_eigenvalue (config ["fileset" ]["eigfile" ])
95- plotting2 . plot_band (KPT , eigdata , config , axs = axs )
95+ plot_band (KPT , eigdata , config , axs = axs )
9696
9797 if config ["plotset" ]["object" ].lower () == "dos" :
9898 dosdata = from_doscar .get_doscar (config ["fileset" ]["dosfile" ])
99- plotting2 . plot_dos (dosdata , config , axs = axs )
99+ plot_dos (dosdata , config , ax = axs )
100100
101101 if "band" in config ["plotset" ]["object" ].lower () and \
102102 "dos" in config ["plotset" ]["object" ].lower ():
@@ -106,15 +106,19 @@ def cvasp(config, axs=None):
106106 else :
107107 eigdata = from_eigenval .get_eigenvalue (config ["fileset" ]["eigfile" ])
108108 dosdata = from_doscar .get_doscar (config ["fileset" ]["dosfile" ])
109- plotting2 . plot_band_dos (KPT , eigdata , dosdata , config , axs = axs )
109+ plot_band_dos (KPT , eigdata , dosdata , config , axs = axs )
110110
111111
112112
113113if __name__ == "__main__" :
114+ import matplotlib as mpl
115+ # mpl.use("TkAgg")
114116 config = ini_config ()
115117 try :
116118 data = read_config ()
117119 config .update (data )
120+ with open ('cvasp.yml' , "w" , encoding = 'utf-8' ) as f :
121+ yaml .dump (config , f )
118122 except Exception as e :
119123 config = from_input (config )
120124 with open ('cvasp.yml' , "w" , encoding = 'utf-8' ) as f :
@@ -123,7 +127,6 @@ def cvasp(config, axs=None):
123127 ["font" ], size = config ["fontset" ]["fontsize" ])
124128 plt .rcParams ['font.serif' ] = [config ["fontset" ]
125129 ["font" ]] + plt .rcParams ['font.serif' ]
126- print (config ["plotset" ]["object" ].lower ())
127130 ispin = 1
128131 if "band" in config ["plotset" ]["object" ].lower ():
129132 if config ["plotset" ]["plot_type" ] > 0 :
@@ -135,12 +138,12 @@ def cvasp(config, axs=None):
135138 fig , axs = plt .subplots (1 , len (config ["groupinfo" ])* ispin ,
136139 figsize = config ["figset" ]["figsize" ], sharey = True )
137140 elif config ["plotset" ]["object" ].lower () == "dos" :
138- fig , ax = plt .subplots (1 , 1 ,
141+ fig , axs = plt .subplots (1 , 1 ,
139142 figsize = config ["figset" ]["figsize" ])
140143 elif "band" in config ["plotset" ]["object" ].lower () and \
141144 "dos" in config ["plotset" ]["object" ].lower ():
142145 fig , axs = plt .subplots (1 , len (config ["groupinfo" ])* ispin + 1 ,
143146 figsize = config ["figset" ]["figsize" ], sharey = True )
144147 cvasp (config , axs = axs )
145148 plt .show ()
146- fig .savefig ('band_dos.png' , dpi = 300 )
149+ fig .savefig (f' { config [ "plotset" ][ "object" ] } . { config [ "figset" ][ "format" ] } ' , format = config [ "figset" ][ "format" ], dpi = config [ "figset" ][ "dpi" ] )
0 commit comments