|
12 | 12 | )
|
13 | 13 | from pymatviz.utils import save_fig
|
14 | 14 |
|
15 |
| -from matbench_discovery import FIGS, PDF_FIGS, ROOT, STABILITY_THRESHOLD, today |
| 15 | +from matbench_discovery import FIGS, PDF_FIGS, ROOT, STABILITY_THRESHOLD |
16 | 16 | from matbench_discovery import plots as plots
|
17 | 17 | from matbench_discovery.data import DATA_FILES, df_wbm
|
18 | 18 | from matbench_discovery.energy import mp_elem_reference_entries
|
|
35 | 35 |
|
36 | 36 |
|
37 | 37 | # %%
|
38 |
| -for count_mode in ["occurrence", "composition"]: |
39 |
| - wbm_elem_counts = count_elements(df_wbm.formula, count_mode=count_mode).astype(int) |
| 38 | +wbm_occu_counts = count_elements(df_wbm.formula, count_mode="occurrence").astype(int) |
| 39 | +wbm_comp_counts = count_elements(df_wbm.formula, count_mode="composition") |
| 40 | + |
| 41 | +mp_occu_counts = count_elements(df_mp.formula_pretty, count_mode="occurrence").astype( |
| 42 | + int |
| 43 | +) |
| 44 | +mp_comp_counts = count_elements(df_mp.formula_pretty, count_mode="composition") |
| 45 | + |
| 46 | +all_counts = ( |
| 47 | + ("wbm", "occurrence", wbm_occu_counts), |
| 48 | + ("wbm", "composition", wbm_comp_counts), |
| 49 | + ("mp", "occurrence", mp_occu_counts), |
| 50 | + ("mp", "composition", mp_comp_counts), |
| 51 | +) |
40 | 52 |
|
41 |
| - wbm_elem_counts.to_json(f"{about_data_page}/wbm-element-counts-{count_mode}.json") |
42 |
| - mp_elem_counts = count_elements(df_mp.formula_pretty, count_mode=count_mode).astype( |
43 |
| - int |
44 |
| - ) |
45 |
| - mp_elem_counts.to_json(f"{about_data_page}/mp-element-counts-{count_mode}.json") |
| 53 | + |
| 54 | +# %% |
| 55 | +for dataset, count_mode, elem_counts in all_counts: |
| 56 | + elem_counts.to_json(f"{about_data_page}/{dataset}-element-counts-{count_mode}.json") |
46 | 57 |
|
47 | 58 |
|
48 | 59 | # %% export element counts by WBM step to JSON
|
|
64 | 75 |
|
65 | 76 |
|
66 | 77 | # %%
|
67 |
| -wbm_fig = ptable_heatmap_plotly( |
68 |
| - wbm_elem_counts.drop("Xe"), |
69 |
| - log=True, |
70 |
| - colorscale="RdBu", |
71 |
| - hover_props=dict(atomic_number="atomic number"), |
72 |
| - hover_data=wbm_elem_counts, |
73 |
| -) |
74 |
| - |
75 |
| -title = "WBM Elements" |
76 |
| -wbm_fig.update_layout( |
77 |
| - title=dict(text=title, x=0.35, y=0.9, font_size=20), |
78 |
| - xaxis=dict(fixedrange=True), |
79 |
| - yaxis=dict(fixedrange=True), |
80 |
| - paper_bgcolor="rgba(0,0,0,0)", |
81 |
| -) |
82 |
| -wbm_fig.show() |
83 |
| - |
84 |
| - |
85 |
| -# %% |
86 |
| -wbm_fig.write_image(f"{module_dir}/figs/wbm-elements.svg", width=1000, height=500) |
87 |
| -# save_fig(wbm_fig, f"{FIGS}/wbm-elements.svelte") |
88 |
| - |
89 |
| - |
90 |
| -# %% |
91 |
| -mp_fig = ptable_heatmap_plotly( |
92 |
| - mp_elem_counts[mp_elem_counts > 1], |
93 |
| - log=True, |
94 |
| - colorscale="RdBu", |
95 |
| - hover_props=dict(atomic_number="atomic number"), |
96 |
| - hover_data=mp_elem_counts, |
97 |
| -) |
98 |
| - |
99 |
| -title = "MP Elements" |
100 |
| -mp_fig.update_layout( |
101 |
| - title=dict(text=title, x=0.35, y=0.9, font_size=20), |
102 |
| - xaxis=dict(fixedrange=True), |
103 |
| - yaxis=dict(fixedrange=True), |
104 |
| - paper_bgcolor="rgba(0,0,0,0)", |
105 |
| -) |
106 |
| -mp_fig.show() |
107 |
| - |
| 78 | +for dataset, count_mode, elem_counts in all_counts: |
| 79 | + ptable = ptable_heatmap_plotly( |
| 80 | + elem_counts.drop("Xe")[elem_counts > 1], |
| 81 | + font_size=11, |
| 82 | + color_bar=dict(title=dict(text=f"WBM {count_mode} counts", font_size=24)), |
| 83 | + # log=True, |
| 84 | + # colorscale="cividis", |
| 85 | + hover_props=dict(atomic_number="atomic number"), |
| 86 | + hover_data=wbm_occu_counts, |
| 87 | + ) |
108 | 88 |
|
109 |
| -# %% |
110 |
| -mp_fig.write_image(f"{module_dir}/figs/{today}-mp-elements.svg", width=1000, height=500) |
111 |
| -# save_fig(mp_fig, f"{FIGS}/mp-elements.svelte") |
| 89 | + ptable.layout.margin = dict(l=0, r=0, b=0, t=0) |
| 90 | + ptable.show() |
| 91 | + # save_fig(ptable, f"{module_dir}/figs/wbm-elements.svg", width=1000, height=500) |
| 92 | + save_fig(ptable, f"{PDF_FIGS}/{dataset}-element-{count_mode}-counts.pdf") |
112 | 93 |
|
113 | 94 |
|
114 | 95 | # %% histogram of energy above MP convex hull for WBM
|
|
148 | 129 |
|
149 | 130 | fig.show()
|
150 | 131 |
|
151 |
| -save_fig(fig, f"{FIGS}/wbm-each-hist.svelte") |
152 |
| -save_fig(fig, "./figs/wbm-each-hist.svg", width=1000, height=500) |
| 132 | +# save_fig(fig, f"{FIGS}/hist-wbm-hull-dist.svelte") |
| 133 | +# save_fig(fig, "./figs/hist-wbm-hull-dist.svg", width=1000, height=500) |
| 134 | +save_fig(fig, f"{PDF_FIGS}/hist-wbm-hull-dist.pdf") |
153 | 135 |
|
154 | 136 |
|
155 | 137 | # %%
|
|
254 | 236 | # %%
|
255 | 237 | fig = spacegroup_sunburst(df_wbm[spg_col], width=350, height=350, show_counts="percent")
|
256 | 238 | fig.layout.title.update(text="WBM Spacegroup Sunburst", x=0.5, font_size=14)
|
| 239 | +fig.layout.margin = dict(l=0, r=0, t=30, b=0) |
257 | 240 | fig.show()
|
258 | 241 | save_fig(fig, f"{FIGS}/spacegroup-sunburst-wbm.svelte")
|
259 | 242 | save_fig(fig, f"{PDF_FIGS}/spacegroup-sunburst-wbm.pdf")
|
|
262 | 245 | # %%
|
263 | 246 | fig = spacegroup_sunburst(df_mp[spg_col], width=350, height=350, show_counts="percent")
|
264 | 247 | fig.layout.title.update(text="MP Spacegroup Sunburst", x=0.5, font_size=14)
|
| 248 | +fig.layout.margin = dict(l=0, r=0, t=30, b=0) |
265 | 249 | fig.show()
|
266 | 250 | save_fig(fig, f"{FIGS}/spacegroup-sunburst-mp.svelte")
|
267 | 251 | save_fig(fig, f"{PDF_FIGS}/spacegroup-sunburst-mp.pdf")
|
|
0 commit comments