|
5 | 5 | from aviary.utils import as_dict_handler
|
6 | 6 | from aviary.wren.utils import get_aflow_label_from_spglib
|
7 | 7 | from mp_api.client import MPRester
|
8 |
| -from pymatviz import density_scatter |
| 8 | +from pymatviz.utils import annotate_mae_r2 |
9 | 9 | from tqdm import tqdm
|
10 | 10 |
|
11 | 11 | from matbench_discovery import today
|
|
57 | 57 |
|
58 | 58 | df["wyckoff_spglib"] = [get_aflow_label_from_spglib(x) for x in tqdm(df.structure)]
|
59 | 59 |
|
60 |
| -df.to_json(f"{module_dir}/{today}-mp-energies.json.gz", default_handler=as_dict_handler) |
| 60 | +df.reset_index().to_json( |
| 61 | + f"{module_dir}/{today}-mp-energies.json.gz", default_handler=as_dict_handler |
| 62 | +) |
61 | 63 |
|
62 | 64 | # df = pd.read_json(f"{module_dir}/2022-08-13-mp-energies.json.gz")
|
| 65 | +# df = pd.read_json(f"{module_dir}/2023-01-10-mp-energies.json.gz") |
63 | 66 |
|
64 | 67 |
|
65 | 68 | # %% reproduce fig. 1b from https://arxiv.org/abs/2001.10591 (as data consistency check)
|
|
70 | 73 | backend="matplotlib",
|
71 | 74 | xlim=[-5, 1],
|
72 | 75 | ylim=[-1, 1],
|
73 |
| - color=df.decomposition_enthalpy.map(lambda x: "red" if x > 0 else "blue"), |
| 76 | + color=(df.decomposition_enthalpy > 0).map({True: "red", False: "blue"}), |
74 | 77 | title=f"{today} - {len(df):,} MP entries",
|
75 | 78 | )
|
| 79 | + |
| 80 | +annotate_mae_r2(df.formation_energy_per_atom, df.decomposition_enthalpy) |
76 | 81 | # result on 2023-01-10: plots match. no correlation between formation energy and decomposition
|
77 | 82 | # enthalpy. R^2 = -1.571, MAE = 1.604
|
78 |
| -ax.figure.savefig(f"{module_dir}/{today}-mp-decomp-enth-vs-e-form.png", dpi=300) |
| 83 | +# ax.figure.savefig(f"{module_dir}/{today}-mp-decomp-enth-vs-e-form.png", dpi=300) |
| 84 | + |
79 | 85 |
|
80 |
| -ax = density_scatter( |
81 |
| - df.formation_energy_per_atom, |
82 |
| - df.decomposition_enthalpy, |
| 86 | +# %% scatter plot energy above convex hull vs decomposition enthalpy |
| 87 | +# https://berkeleytheory.slack.com/archives/C16RE1TUN/p1673887564955539 |
| 88 | +mask_above_line = df.energy_above_hull - df.decomposition_enthalpy.clip(0) > 0.1 |
| 89 | +ax = df.plot.scatter( |
| 90 | + x="decomposition_enthalpy", |
| 91 | + y="energy_above_hull", |
| 92 | + color=mask_above_line.map({True: "red", False: "blue"}) |
| 93 | + # backend="plotly", |
| 94 | + # hover_data=["index", "formula_pretty", "formation_energy_per_atom"], |
| 95 | +) |
| 96 | +# most points lie on line y=x for x > 0 and y = 0 for x < 0. |
| 97 | +n_above_line = sum(mask_above_line) |
| 98 | +ax.set( |
| 99 | + title=f"{n_above_line:,} / {len(df):,} = {n_above_line/len(df):.1%} " |
| 100 | + "MP materials with\nenergy_above_hull - decomposition_enthalpy.clip(0) > 0.1" |
83 | 101 | )
|
84 |
| -ax.set(xlim=[-5, 1], ylim=[-1, 1]) |
| 102 | +# ax.figure.savefig(f"{module_dir}/{today}-mp-e-above-hull-vs-decomp-enth.png", dpi=300) |
0 commit comments