2
2
import sys
3
3
import matplotlib .pyplot as plt
4
4
from readvasp import *
5
- import plotting2
5
+ from plotting import plot_band , plot_dos , plot_band_dos
6
6
import yaml
7
7
import os
8
8
@@ -34,7 +34,7 @@ def from_input(config):
34
34
config ["plotset" ]["plot_type" ] = type
35
35
config ["groupinfo" ] = [None ]
36
36
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 " ))
38
38
config ["groupinfo" ] = []
39
39
for N in range (config ["Nbandpicture" ]):
40
40
print ("next group\n " )
@@ -51,7 +51,7 @@ def from_input(config):
51
51
if tmp :
52
52
groups .append (tmp )
53
53
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"
55
55
config ["plotset" ]['Elim' ] = [float (i ) for i in tmp .split ()]
56
56
config ["plotset" ]['fermi' ] = input ("Set 0eV to fermi? (VBM,CBM,band No. or any Energy)\n "
57
57
"F or 0 will change nothing.\n "
@@ -65,38 +65,38 @@ def ini_config():
65
65
plotset = {"plot_type" : 0 , "object" : "band" ,
66
66
"scale" : 50 ,
67
67
"Elim" : [- 2 , 5 ], "fermi" : "vbm" , "int" : 100 }
68
- figset = {"figsize" : (7 , 6 ), "dpi" : 150 }
68
+ figset = {"figsize" : (7 , 6 ), "dpi" : 300 , "format" : "png" }
69
69
fontset = {"fontsize" : 16 , "font" : "Arial" }
70
70
fileset = {"eigfile" : ["EIGENVAL" ], "dosfile" : "DOSCAR" , "prosfile" : [
71
71
"PROCAR" ], "kptfile" : ["KPOINTS" ], "posfile" : "POSCAR" }
72
+ paras = {"dos_paras" :{},"band_paras" :{},"dos_legend_paras" :{},"band_legend_paras" :{"loc" :"upper right" }}
72
73
config = {"method" : method ,
73
74
"plotset" : plotset ,
74
75
"fileset" : fileset ,
75
76
"figset" : figset ,
76
- "fontset" : fontset }
77
+ "fontset" : fontset ,
78
+ "paras" :paras }
77
79
return config
78
80
79
81
80
82
def read_config (file = 'cvasp.yml' ):
81
83
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
85
86
86
87
87
88
def cvasp (config , axs = None ):
88
- print (config ["plotset" ]["object" ].lower ())
89
89
if config ["plotset" ]["object" ].lower () == "band" :
90
90
KPT = from_kpoints .get_kpoints (config ["fileset" ]["kptfile" ])
91
91
if config ["plotset" ]["plot_type" ] > 0 :
92
92
eigdata = from_procar .get_procar (config ["fileset" ]["prosfile" ])
93
93
else :
94
94
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 )
96
96
97
97
if config ["plotset" ]["object" ].lower () == "dos" :
98
98
dosdata = from_doscar .get_doscar (config ["fileset" ]["dosfile" ])
99
- plotting2 . plot_dos (dosdata , config , axs = axs )
99
+ plot_dos (dosdata , config , ax = axs )
100
100
101
101
if "band" in config ["plotset" ]["object" ].lower () and \
102
102
"dos" in config ["plotset" ]["object" ].lower ():
@@ -106,15 +106,19 @@ def cvasp(config, axs=None):
106
106
else :
107
107
eigdata = from_eigenval .get_eigenvalue (config ["fileset" ]["eigfile" ])
108
108
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 )
110
110
111
111
112
112
113
113
if __name__ == "__main__" :
114
+ import matplotlib as mpl
115
+ # mpl.use("TkAgg")
114
116
config = ini_config ()
115
117
try :
116
118
data = read_config ()
117
119
config .update (data )
120
+ with open ('cvasp.yml' , "w" , encoding = 'utf-8' ) as f :
121
+ yaml .dump (config , f )
118
122
except Exception as e :
119
123
config = from_input (config )
120
124
with open ('cvasp.yml' , "w" , encoding = 'utf-8' ) as f :
@@ -123,7 +127,6 @@ def cvasp(config, axs=None):
123
127
["font" ], size = config ["fontset" ]["fontsize" ])
124
128
plt .rcParams ['font.serif' ] = [config ["fontset" ]
125
129
["font" ]] + plt .rcParams ['font.serif' ]
126
- print (config ["plotset" ]["object" ].lower ())
127
130
ispin = 1
128
131
if "band" in config ["plotset" ]["object" ].lower ():
129
132
if config ["plotset" ]["plot_type" ] > 0 :
@@ -135,12 +138,12 @@ def cvasp(config, axs=None):
135
138
fig , axs = plt .subplots (1 , len (config ["groupinfo" ])* ispin ,
136
139
figsize = config ["figset" ]["figsize" ], sharey = True )
137
140
elif config ["plotset" ]["object" ].lower () == "dos" :
138
- fig , ax = plt .subplots (1 , 1 ,
141
+ fig , axs = plt .subplots (1 , 1 ,
139
142
figsize = config ["figset" ]["figsize" ])
140
143
elif "band" in config ["plotset" ]["object" ].lower () and \
141
144
"dos" in config ["plotset" ]["object" ].lower ():
142
145
fig , axs = plt .subplots (1 , len (config ["groupinfo" ])* ispin + 1 ,
143
146
figsize = config ["figset" ]["figsize" ], sharey = True )
144
147
cvasp (config , axs = axs )
145
148
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