1
1
#!/usr/bin/env python3
2
2
3
3
import os , sys
4
+ from io import BytesIO
4
5
import json
5
6
#from pprint import pprint
6
7
7
8
import numpy as np
8
9
import matplotlib .pyplot as plt
9
10
11
+ from PIL import Image
12
+ from ase .data import chemical_symbols
13
+
10
14
from aiida import load_profile
11
15
from aiida_crystal_dft .io .f9 import Fort9
12
- from mpds_aiida .common import get_template
13
- from mpds_aiida .properties import properties_run_direct , properties_export
16
+ from aiida_crystal_dft .utils .dos import get_dos_projections_atoms
17
+
18
+ from mpds_aiida .common import get_template , fix_label_names , formula_to_latex
19
+ from mpds_aiida .properties import properties_run_direct , properties_export , dos_colors
14
20
15
21
16
22
load_profile ()
50
56
f .close ()
51
57
52
58
print ("Writing e_props.png" )
59
+ bands .attributes ['labels' ] = fix_label_names (bands .attributes ['labels' ])
53
60
54
61
fig , (ax0 , ax1 ) = plt .subplots (1 , 2 , gridspec_kw = {'width_ratios' : [3 , 1 ]}, figsize = (10 , 8 ))
55
62
x = np .arange (bands .get_array ('kpoints' ).shape [0 ])
61
68
62
69
ax1 .set_xlim (0 , 2000 )
63
70
ax1 .set_ylim (- 10 , 20 )
71
+ ax1 .set_prop_cycle (color = dos_colors )
64
72
ax1 .plot (dos ['dos_up' ].T , (dos ['e' ] - dos ['e_fermi' ]))
65
73
66
- fig .suptitle (wf .get_ase ().get_chemical_formula (empirical = True ))
74
+ atsymbs = [chemical_symbols [x ] for x in wf .get_atomic_numbers ()]
75
+ count , padding = 0 , 70
76
+ for proj in get_dos_projections_atoms (wf .get_atomic_numbers ()):
77
+ ax1 .annotate (atsymbs [proj [0 ] - 1 ], xy = (count * padding , - 150 ), xycoords = 'axes pixels' , size = 7 , c = dos_colors [count ])
78
+ count += 1
79
+ ax1 .annotate ('Total' , xy = (count * padding , - 150 ), xycoords = 'axes pixels' , size = 7 , c = dos_colors [count ])
80
+
81
+ fig .suptitle (formula_to_latex (wf .get_ase ().get_chemical_formula (empirical = True )))
67
82
plt .margins (0.2 )
68
83
plt .subplots_adjust (bottom = 0.15 )
69
- plt .savefig ('e_props.png' , dpi = 250 )
84
+ #plt.savefig('e_props.png', dpi=250)
85
+
86
+ mem = BytesIO ()
87
+ plt .savefig (mem , format = 'png' , dpi = 250 )
88
+ mem .seek (0 )
89
+ im = Image .open (mem )
90
+ im2 = im .convert ('RGB' ).convert ('P' , palette = Image .ADAPTIVE )
91
+ im2 .save ('e_props.png' )
70
92
71
93
print ('E_dir, E_ind = ' , result ['direct_gap' ], result ['indirect_gap' ])
0 commit comments