|
6 | 6 | import yaml
|
7 | 7 | import os
|
8 | 8 |
|
| 9 | + |
9 | 10 | def from_input(config):
|
10 |
| - obj=["band","DOS","band & DOS","CHARGE"] |
11 |
| - str=''.join(['%s : [%d]\n' % (j,i) for i,j in enumerate(obj)]) |
12 |
| - tmp=int(input(str)) |
| 11 | + obj = ["band", "DOS", "band & DOS", "CHARGE"] |
| 12 | + str = ''.join(['%s : [%d]\n' % (j, i) for i, j in enumerate(obj)]) |
| 13 | + tmp = int(input(str)) |
13 | 14 | config["plotset"]["object"] = obj[tmp]
|
14 |
| - if tmp==0: |
15 |
| - type=int(input( |
| 15 | + if tmp == 0: |
| 16 | + type = int(input( |
16 | 17 | 'Type:\n'
|
17 | 18 | 'Normal band - 0\n'
|
18 | 19 | 'Fat band - 1\n'
|
19 | 20 | 'Colormap band - 2\n'
|
20 |
| - )) |
21 |
| - if tmp==1: |
22 |
| - type=int(input( |
| 21 | + )) |
| 22 | + if tmp == 1: |
| 23 | + type = int(input( |
23 | 24 | 'Type:\n'
|
24 | 25 | 'Normal DOS - 0\n'
|
25 | 26 | 'Projected DOS - 1\n'
|
26 |
| - )) |
27 |
| - if tmp==2: |
28 |
| - type=int(input( |
| 27 | + )) |
| 28 | + if tmp == 2: |
| 29 | + type = int(input( |
29 | 30 | 'Type:\n'
|
30 | 31 | 'Normal - 0\n'
|
31 | 32 | 'Projected - 1\n'
|
32 |
| - )) |
| 33 | + )) |
33 | 34 | config["plotset"]["plot_type"] = type
|
34 | 35 | config["groupinfo"] = [None]
|
35 | 36 | if type > 0:
|
36 |
| - config["Nbandpicture"]=int(input("How many bands?\n")) |
37 |
| - config["groupinfo"]=[] |
| 37 | + config["Nbandpicture"] = int(input("How many bands?\n")) |
| 38 | + config["groupinfo"] = [] |
38 | 39 | for N in range(config["Nbandpicture"]):
|
39 | 40 | print("next group\n")
|
40 |
| - groups=[] |
41 |
| - tmp=input( |
42 |
| - '[Element or atomic NO.] [label] [color/colormap] \n' |
43 |
| - 'specified orbital with "_" ,split with "," \n' |
44 |
| - 'e.g : Cu,Ag_py,1-3,6_py,8-10_d CuAnTag red \n' |
45 |
| - 'empty for end \n' |
46 |
| - ) |
| 41 | + groups = [] |
| 42 | + tmp = input( |
| 43 | + '[Element or atomic NO.] [label] [color/colormap] \n' |
| 44 | + 'specified orbital with "_" ,split with "," \n' |
| 45 | + 'e.g : Cu,Ag_py,1-3,6_py,8-10_d CuAnTag red \n' |
| 46 | + 'empty for end \n' |
| 47 | + ) |
47 | 48 | groups.append(tmp)
|
48 | 49 | while tmp:
|
49 |
| - tmp=input() |
| 50 | + tmp = input() |
50 | 51 | if tmp:
|
51 | 52 | groups.append(tmp)
|
52 | 53 | config["groupinfo"].append(groups)
|
53 | 54 | tmp = input('Energy range, e.g -2 5 default is [-2 5]\n') or "-2 5"
|
54 |
| - config["plotset"]['Elim']=[float(i) for i in tmp.split()] |
55 |
| - config["plotset"]['fermi']=input("Set 0eV to fermi? (VBM,CBM,band No. or any Energy)\n" |
56 |
| - "F or 0 will change nothing.\n" |
57 |
| - "e.g VBM/CBM/band_18/-2.5/F/0\n" |
58 |
| - "default is VBM") or "vbm" |
| 55 | + config["plotset"]['Elim'] = [float(i) for i in tmp.split()] |
| 56 | + config["plotset"]['fermi'] = input("Set 0eV to fermi? (VBM,CBM,band No. or any Energy)\n" |
| 57 | + "F or 0 will change nothing.\n" |
| 58 | + "e.g VBM/CBM/band_18/-2.5/F/0\n" |
| 59 | + "default is VBM") or "vbm" |
59 | 60 | return config
|
60 | 61 |
|
61 | 62 |
|
62 | 63 | def ini_config():
|
63 |
| - method = {"method" : "matplotlib"} |
64 |
| - plotset = {"plot_type": 0, "object" : "band","Elim":[-2,5],"fermi":"vbm","int":100} |
65 |
| - figset = {"figsize":(7,6),"dpi":150} |
66 |
| - fontset = {"fontsize" : 16,"font":"Arial"} |
67 |
| - fileset = {"eigfile":["EIGENVAL"],"dosfile":"DOSCAR","prosfile":["PROCAR"],"kptfile":["KPOINTS"],"posfile":"POSCAR"} |
68 |
| - config={"method" : method, |
69 |
| - "plotset" : plotset, |
70 |
| - "fileset" : fileset, |
71 |
| - "figset" : figset, |
72 |
| - "fontset" : fontset} |
| 64 | + method = {"method": "matplotlib"} |
| 65 | + plotset = {"plot_type": 0, "object": "band", |
| 66 | + "scale": 50, |
| 67 | + "Elim": [-2, 5], "fermi": "vbm", "int": 100} |
| 68 | + figset = {"figsize": (7, 6), "dpi": 150} |
| 69 | + fontset = {"fontsize": 16, "font": "Arial"} |
| 70 | + fileset = {"eigfile": ["EIGENVAL"], "dosfile": "DOSCAR", "prosfile": [ |
| 71 | + "PROCAR"], "kptfile": ["KPOINTS"], "posfile": "POSCAR"} |
| 72 | + config = {"method": method, |
| 73 | + "plotset": plotset, |
| 74 | + "fileset": fileset, |
| 75 | + "figset": figset, |
| 76 | + "fontset": fontset} |
73 | 77 | return config
|
74 | 78 |
|
| 79 | + |
75 | 80 | def read_config(file='cvasp.yml'):
|
76 | 81 | with open(file) as f:
|
77 | 82 | data = yaml.load(f, Loader=yaml.FullLoader)
|
78 |
| - #print(data) |
| 83 | + # print(data) |
79 | 84 | return data
|
80 | 85 |
|
81 | 86 |
|
82 |
| -def cvasp(config,axs=None): |
83 |
| - plt.rc('font',family=config["fontset"]["font"],size=config["fontset"]["fontsize"]) |
84 |
| - plt.rcParams['font.serif'] = [config["fontset"]["font"]] + plt.rcParams['font.serif'] |
| 87 | +def cvasp(config, axs=None): |
| 88 | + # plt.rc('font',family=config["fontset"]["font"],size=config["fontset"]["fontsize"]) |
| 89 | + # plt.rcParams['font.serif'] = [config["fontset"]["font"]] + plt.rcParams['font.serif'] |
85 | 90 | print(config["plotset"]["object"].lower())
|
86 |
| - if config["plotset"]["object"].lower() == "band" : |
87 |
| - if config["plotset"]["plot_type"] > 0 : |
| 91 | + if config["plotset"]["object"].lower() == "band": |
| 92 | + if config["plotset"]["plot_type"] > 0: |
88 | 93 | data = from_procar.get_procar(config["fileset"]["prosfile"])
|
89 | 94 | else:
|
90 | 95 | data = from_eigenval.get_eigenvalue(config["fileset"]["eigfile"])
|
91 | 96 | KPT = from_kpoints.get_kpoints(config["fileset"]["kptfile"])
|
92 |
| - plotting2.plot_band(KPT,data,config,axs=axs) |
93 |
| - |
94 |
| - if config["plotset"]["object"].lower() == "dos" : |
| 97 | + plotting2.plot_band(KPT, data, config, axs=axs) |
| 98 | + |
| 99 | + if config["plotset"]["object"].lower() == "dos": |
95 | 100 | data = from_doscar.get_doscar(config["fileset"]["dosfile"])
|
96 |
| - plotting2.plot_dos(data,config,axs=axs) |
| 101 | + plotting2.plot_dos(data, config, axs=axs) |
97 | 102 |
|
98 | 103 | if "band" in config["plotset"]["object"].lower() and \
|
99 |
| - "dos" in config["plotset"]["object"].lower() : |
| 104 | + "dos" in config["plotset"]["object"].lower(): |
100 | 105 | KPT = from_kpoints.get_kpoints(config["fileset"]["kptfile"])
|
101 |
| - if config["plotset"]["plot_type"] > 0 : |
| 106 | + if config["plotset"]["plot_type"] > 0: |
102 | 107 | eigdata = from_procar.get_procar(config["fileset"]["prosfile"])
|
103 | 108 | else:
|
104 |
| - eigdata = from_eigenval.get_eigenvalue(config["fileset"]["eigfile"]) |
| 109 | + eigdata = from_eigenval.get_eigenvalue( |
| 110 | + config["fileset"]["eigfile"]) |
105 | 111 | dosdata = from_doscar.get_doscar(config["fileset"]["dosfile"])
|
106 |
| - plotting2.plot_band_dos(KPT,eigdata,dosdata,config,axs=axs) |
| 112 | + plotting2.plot_band_dos(KPT, eigdata, dosdata, config, axs=axs) |
107 | 113 |
|
108 | 114 |
|
109 | 115 | if __name__ == "__main__":
|
110 |
| - config=ini_config() |
| 116 | + config = ini_config() |
111 | 117 | try:
|
112 |
| - data=read_config() |
| 118 | + data = read_config() |
113 | 119 | config.update(data)
|
114 | 120 | except Exception as e:
|
115 |
| - config=from_input(config) |
116 |
| - with open('cvasp.yml',"w",encoding='utf-8') as f: |
117 |
| - yaml.dump(config,f) |
118 |
| - plt.rc('font',family=config["fontset"]["font"],size=config["fontset"]["fontsize"]) |
119 |
| - plt.rcParams['font.serif'] = [config["fontset"]["font"]] + plt.rcParams['font.serif'] |
| 121 | + config = from_input(config) |
| 122 | + with open('cvasp.yml', "w", encoding='utf-8') as f: |
| 123 | + yaml.dump(config, f) |
| 124 | + plt.rc('font', family=config["fontset"] |
| 125 | + ["font"], size=config["fontset"]["fontsize"]) |
| 126 | + plt.rcParams['font.serif'] = [config["fontset"] |
| 127 | + ["font"]] + plt.rcParams['font.serif'] |
120 | 128 | print(config["plotset"]["object"].lower())
|
121 |
| - if config["plotset"]["object"].lower() == "band" : |
122 |
| - if config["plotset"]["plot_type"] > 0 : |
| 129 | + if config["plotset"]["object"].lower() == "band": |
| 130 | + if config["plotset"]["plot_type"] > 0: |
123 | 131 | data = from_procar.get_procar(config["fileset"]["prosfile"])
|
124 | 132 | else:
|
125 | 133 | data = from_eigenval.get_eigenvalue(config["fileset"]["eigfile"])
|
126 |
| - ispin=data.N_spin |
127 |
| - fig, axs = plt.subplots(1,len(config["groupinfo"])*ispin, |
128 |
| - figsize=config["figset"]["figsize"],sharey=True) |
| 134 | + ispin = data.N_spin |
| 135 | + fig, axs = plt.subplots(1, len(config["groupinfo"])*ispin, |
| 136 | + figsize=config["figset"]["figsize"], sharey=True) |
129 | 137 | KPT = from_kpoints.get_kpoints(config["fileset"]["kptfile"])
|
130 |
| - plotting2.plot_band(KPT,data,config,axs=axs) |
131 |
| - |
132 |
| - if config["plotset"]["object"].lower() == "dos" : |
133 |
| - fig , ax = plt.subplots(1, 1, |
134 |
| - figsize=config["figset"]["figsize"]) |
| 138 | + plotting2.plot_band(KPT, data, config, axs=axs) |
| 139 | + |
| 140 | + if config["plotset"]["object"].lower() == "dos": |
| 141 | + fig, ax = plt.subplots(1, 1, |
| 142 | + figsize=config["figset"]["figsize"]) |
135 | 143 | data = from_doscar.get_doscar(config["fileset"]["dosfile"])
|
136 |
| - plotting2.plot_dos(data,config,ax=ax) |
| 144 | + plotting2.plot_dos(data, config, ax=ax) |
137 | 145 |
|
138 | 146 | if "band" in config["plotset"]["object"].lower() and \
|
139 |
| - "dos" in config["plotset"]["object"].lower() : |
| 147 | + "dos" in config["plotset"]["object"].lower(): |
140 | 148 | KPT = from_kpoints.get_kpoints(config["fileset"]["kptfile"])
|
141 |
| - if config["plotset"]["plot_type"] > 0 : |
| 149 | + if config["plotset"]["plot_type"] > 0: |
142 | 150 | eigdata = from_procar.get_procar(config["fileset"]["prosfile"])
|
143 | 151 | else:
|
144 |
| - eigdata = from_eigenval.get_eigenvalue(config["fileset"]["eigfile"]) |
145 |
| - ispin=eigdata.N_spin |
146 |
| - fig, axs = plt.subplots(1,len(config["groupinfo"])*ispin + 1, |
147 |
| - figsize=config["figset"]["figsize"],sharey=True) |
| 152 | + eigdata = from_eigenval.get_eigenvalue( |
| 153 | + config["fileset"]["eigfile"]) |
| 154 | + ispin = eigdata.N_spin |
| 155 | + fig, axs = plt.subplots(1, len(config["groupinfo"])*ispin + 1, |
| 156 | + figsize=config["figset"]["figsize"], sharey=True) |
148 | 157 | dosdata = from_doscar.get_doscar(config["fileset"]["dosfile"])
|
149 |
| - plotting2.plot_band_dos(KPT,eigdata,dosdata,config,axs=axs) |
150 |
| - plt.show() |
151 |
| - fig.savefig('band_dos.png',dpi=300) |
152 |
| - |
| 158 | + plotting2.plot_band_dos(KPT, eigdata, dosdata, config, axs=axs) |
| 159 | + plt.show() |
| 160 | + fig.savefig('band_dos.png', dpi=300) |
0 commit comments