|
15 | 15 | import plotly.express as px
|
16 | 16 | from matplotlib.colors import SymLogNorm
|
17 | 17 | from pymatgen.core import Composition, Element
|
18 |
| -from pymatviz import count_elements, ptable_heatmap, ptable_heatmap_ratio, ptable_hists |
| 18 | +from pymatviz import ( |
| 19 | + count_elements, |
| 20 | + plot_histogram, |
| 21 | + ptable_heatmap, |
| 22 | + ptable_heatmap_ratio, |
| 23 | + ptable_hists, |
| 24 | +) |
19 | 25 | from pymatviz.io import save_fig
|
20 | 26 | from pymatviz.utils import si_fmt
|
21 | 27 | from tqdm import tqdm
|
@@ -321,91 +327,50 @@ def tile_count_anno(hist_vals: list[Any]) -> dict[str, Any]:
|
321 | 327 |
|
322 | 328 |
|
323 | 329 | # %% plot formation energy per atom distribution
|
| 330 | +# pdf_kwds defined to use the same figure size for all plots |
| 331 | +fig = plot_histogram(df_mp_trj[Key.e_form], bins=300) |
| 332 | +# fig.update_yaxes(type="log") |
| 333 | +fig.layout.xaxis.title = "E<sub>form</sub> (eV/atom)" |
324 | 334 | count_col = "Number of Structures"
|
325 |
| -axes_kwds = dict(linewidth=1, ticks="outside") |
326 |
| -pdf_kwds = dict(width=500, height=300) |
327 |
| - |
328 |
| -x_col, y_col = "E<sub>form</sub> (eV/atom)", count_col |
329 |
| -df_e_form = locals().get("df_e_form") |
330 |
| - |
331 |
| -if df_e_form is None: # only compute once for speed |
332 |
| - e_form_hist = np.histogram(df_mp_trj[Key.e_form], bins=300) |
333 |
| - df_e_form = pd.DataFrame(e_form_hist, index=[y_col, x_col]).T.round(3) |
334 |
| - |
335 |
| -fig = px.bar(df_e_form, x=x_col, y=count_col, log_y=True) |
336 |
| - |
337 |
| -bin_width = df_e_form[x_col].diff().iloc[-1] * 1.2 |
338 |
| -fig.update_traces(width=bin_width, marker_line_width=0) |
339 |
| -fig.layout.xaxis.update(**axes_kwds) |
340 |
| -fig.layout.yaxis.update(**axes_kwds) |
341 |
| -fig.layout.margin = dict(l=5, r=5, b=5, t=5) |
| 335 | +fig.layout.yaxis.title = count_col |
342 | 336 | fig.show()
|
343 |
| -save_fig(fig, f"{PDF_FIGS}/mp-trj-e-form-hist.pdf", **pdf_kwds) |
344 |
| -save_fig(fig, f"{SITE_FIGS}/mp-trj-e-form-hist.svelte") |
345 |
| - |
346 |
| - |
347 |
| -# %% plot forces distribution |
348 |
| -# use numpy to pre-compute histogram |
349 |
| -x_col, y_col = "|Forces| (eV/Å)", count_col |
350 |
| -df_forces = locals().get("df_forces") |
351 | 337 |
|
352 |
| -if df_forces is None: # only compute once for speed |
353 |
| - forces_hist = np.histogram( |
354 |
| - df_mp_trj[Key.forces].explode().explode().abs(), bins=300 |
355 |
| - ) |
356 |
| - df_forces = pd.DataFrame(forces_hist, index=[y_col, x_col]).T.round(3) |
| 338 | +pdf_kwds = dict(width=500, height=300) |
| 339 | +# save_fig(fig, f"{PDF_FIGS}/mp-trj-e-form-hist.pdf", **pdf_kwds) |
| 340 | +# save_fig(fig, f"{SITE_FIGS}/mp-trj-e-form-hist.svelte") |
357 | 341 |
|
358 |
| -fig = px.bar(df_forces, x=x_col, y=count_col, log_y=True) |
359 | 342 |
|
360 |
| -bin_width = df_forces[x_col].diff().iloc[-1] * 1.2 |
361 |
| -fig.update_traces(width=bin_width, marker_line_width=0) |
362 |
| -fig.layout.xaxis.update(**axes_kwds) |
363 |
| -fig.layout.yaxis.update(**axes_kwds) |
364 |
| -fig.layout.margin = dict(l=5, r=5, b=5, t=5) |
| 343 | +# %% plot forces distribution |
| 344 | +fig = plot_histogram(df_mp_trj[Key.forces].explode().explode().abs(), bins=300) |
| 345 | +fig.layout.xaxis.title = "|Forces| (eV/Å)" |
| 346 | +fig.layout.yaxis.title = count_col |
| 347 | +fig.update_yaxes(type="log") |
365 | 348 | fig.show()
|
366 |
| -save_fig(fig, f"{PDF_FIGS}/mp-trj-forces-hist.pdf", **pdf_kwds) |
367 |
| -save_fig(fig, f"{SITE_FIGS}/mp-trj-forces-hist.svelte") |
368 | 349 |
|
| 350 | +# save_fig(fig, f"{PDF_FIGS}/mp-trj-forces-hist.pdf", **pdf_kwds) |
| 351 | +# save_fig(fig, f"{SITE_FIGS}/mp-trj-forces-hist.svelte") |
369 | 352 |
|
370 |
| -# %% plot hydrostatic stress distribution |
371 |
| -x_col, y_col = "1/3 Tr(σ) (eV/ų)", count_col # noqa: RUF001 |
372 |
| -df_stresses = locals().get("df_stresses") |
373 |
| - |
374 |
| -if df_stresses is None: # only compute once for speed |
375 |
| - stresses_hist = np.histogram(df_mp_trj[Key.stress_trace], bins=300) |
376 |
| - df_stresses = pd.DataFrame(stresses_hist, index=[y_col, x_col]).T.round(3) |
377 | 353 |
|
378 |
| -fig = px.bar(df_stresses, x=x_col, y=y_col, log_y=True) |
379 |
| - |
380 |
| -bin_width = (df_stresses[x_col].diff().mean()) * 1.2 |
381 |
| -fig.update_traces(width=bin_width, marker_line_width=0) |
382 |
| -fig.layout.xaxis.update(**axes_kwds) |
383 |
| -fig.layout.yaxis.update(**axes_kwds) |
384 |
| -fig.layout.margin = dict(l=5, r=5, b=5, t=5) |
| 354 | +# %% plot hydrostatic stress distribution |
| 355 | +fig = plot_histogram(df_mp_trj[Key.stress_trace], bins=300) |
| 356 | +fig.layout.xaxis.title = "1/3 Tr(σ) (eV/ų)" # noqa: RUF001 |
| 357 | +fig.layout.yaxis.title = count_col |
| 358 | +fig.update_yaxes(type="log") |
385 | 359 | fig.show()
|
386 | 360 |
|
387 |
| -save_fig(fig, f"{PDF_FIGS}/mp-trj-stresses-hist.pdf", **pdf_kwds) |
388 |
| -save_fig(fig, f"{SITE_FIGS}/mp-trj-stresses-hist.svelte") |
| 361 | +# save_fig(fig, f"{PDF_FIGS}/mp-trj-stresses-hist.pdf", **pdf_kwds) |
| 362 | +# save_fig(fig, f"{SITE_FIGS}/mp-trj-stresses-hist.svelte") |
389 | 363 |
|
390 | 364 |
|
391 | 365 | # %% plot magmoms distribution
|
392 |
| -x_col, y_col = "Magmoms (μ<sub>B</sub>)", count_col |
393 |
| -df_magmoms = locals().get("df_magmoms") |
394 |
| - |
395 |
| -if df_magmoms is None: # only compute once for speed |
396 |
| - magmoms_hist = np.histogram(df_mp_trj[Key.magmoms].dropna().explode(), bins=300) |
397 |
| - df_magmoms = pd.DataFrame(magmoms_hist, index=[y_col, x_col]).T.round(3) |
398 |
| - |
399 |
| -fig = px.bar(df_magmoms, x=x_col, y=y_col, log_y=True) |
400 |
| - |
401 |
| -bin_width = df_magmoms[x_col].diff().iloc[-1] * 1.2 |
402 |
| -fig.update_traces(width=bin_width, marker_line_width=0) |
403 |
| -fig.layout.xaxis.update(**axes_kwds) |
404 |
| -fig.layout.yaxis.update(**axes_kwds) |
405 |
| -fig.layout.margin = dict(l=5, r=5, b=5, t=5) |
| 366 | +fig = plot_histogram(df_mp_trj[Key.magmoms].dropna().explode(), bins=300) |
| 367 | +fig.layout.xaxis.title = "Magmoms (μB)" |
| 368 | +fig.layout.yaxis.title = count_col |
| 369 | +fig.update_yaxes(type="log") |
406 | 370 | fig.show()
|
407 |
| -save_fig(fig, f"{PDF_FIGS}/mp-trj-magmoms-hist.pdf", **pdf_kwds) |
408 |
| -save_fig(fig, f"{SITE_FIGS}/mp-trj-magmoms-hist.svelte") |
| 371 | + |
| 372 | +# save_fig(fig, f"{PDF_FIGS}/mp-trj-magmoms-hist.pdf", **pdf_kwds) |
| 373 | +# save_fig(fig, f"{SITE_FIGS}/mp-trj-magmoms-hist.svelte") |
409 | 374 |
|
410 | 375 |
|
411 | 376 | # %%
|
|
0 commit comments