Skip to content

Commit 9223c75

Browse files
committed
make PNG of WBM e_form hist in data/wbm/readme.md interactive plotly figure
1 parent 856c173 commit 9223c75

11 files changed

+62
-48
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ repos:
5555
hooks:
5656
- id: codespell
5757
stages: [commit, commit-msg]
58-
exclude_types: [csv, json]
58+
exclude_types: [csv, json, svg]
5959

6060
- repo: https://github.com/PyCQA/autoflake
6161
rev: v2.0.0

data/wbm/2022-12-07-hist-e-form-per-atom.svg

+1
Loading

data/wbm/fetch_process_wbm_dataset.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
from matbench_discovery import ROOT, today
2424
from matbench_discovery.energy import get_e_form_per_atom
25+
from matbench_discovery.plots import pio
2526

2627
try:
2728
import gdown
@@ -41,6 +42,8 @@
4142
module_dir = os.path.dirname(__file__)
4243
warnings.filterwarnings("ignore", category=UserWarning, module="pymatgen")
4344

45+
assert pio.templates.default == "plotly_dark+global"
46+
4447

4548
# %% links to google drive files received via email from 1st author Hai-Chen Wang
4649
# on 2021-06-15 containing initial and relaxed structures
@@ -429,7 +432,7 @@ def fix_bad_struct_index_mismatch(material_id: str) -> str:
429432
n_too_unstable = sum(df_summary.e_form_per_atom_wbm > e_form_cutoff)
430433
print(f"{n_too_unstable = }") # n_too_unstable = 22
431434

432-
fig = df_summary.hist(x="e_form_per_atom_wbm", bins=100, backend="plotly", log_y=True)
435+
fig = df_summary.hist(x="e_form_per_atom_wbm", backend="plotly", log_y=True)
433436
fig.add_vline(x=e_form_cutoff, line=dict(width=2, dash="dash", color="green"))
434437
fig.add_vline(x=-e_form_cutoff, line=dict(width=2, dash="dash", color="green"))
435438
fig.add_annotation(
@@ -441,8 +444,18 @@ def fix_bad_struct_index_mismatch(material_id: str) -> str:
441444
xaxis_title="WBM formation energy (eV/atom)", margin=dict(l=10, r=10, t=40, b=10)
442445
)
443446

444-
fig.write_image(
445-
f"{module_dir}/{today}-hist-e-form-per-atom.png", scale=5, width=800, height=300
447+
448+
# %%
449+
# no need to store all 250k x values in plot, leads to 1.7 MB file, subsample every 10th
450+
# point is enough to see the distribution
451+
fig.data[0].x = fig.data[0].x[::10]
452+
# recommended to upload to vecta.io/nano afterwards for compression
453+
fig.write_image(f"{module_dir}/{today}-hist-e-form-per-atom.svg", width=800, height=300)
454+
fig.write_html(
455+
f"{module_dir}/{today}-hist-e-form-per-atom.svelte",
456+
include_plotlyjs=False,
457+
full_html=False,
458+
config=dict(showTips=False, displayModeBar=False, scrollZoom=True),
446459
)
447460

448461

data/wbm/readme.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ The full set of processing steps used to curate the WBM test set from the raw da
2020
- correctly aligning initial structures to DFT-relaxed [`ComputedStructureEntries`](https://pymatgen.org/pymatgen.entries.computed_entries.html#pymatgen.entries.computed_entries.ComputedStructureEntry)
2121
- remove 6 pathological structures (with 0 volume)
2222
- remove formation energy outliers below -5 and above 5 eV/atom (502 and 22 crystals respectively out of 257,487 total, including an anomaly of 500 structures at exactly -10 eV/atom)
23-
![WBM formation energy histogram indicating outlier cutoffs](2022-12-07-hist-e-form-per-atom.png)
23+
24+
<slot name="hist-e-form-per-atom">
25+
<img src="./2022-12-07-hist-e-form-per-atom.svg" alt="WBM formation energy histogram indicating outlier cutoffs">
26+
</slot>
27+
2428
- apply the [`MaterialsProject2020Compatibility`](https://pymatgen.org/pymatgen.entries.compatibility.html#pymatgen.entries.compatibility.MaterialsProject2020Compatibility) energy correction scheme to the formation energies
2529
- compute energy to the Materials Project convex hull constructed from all MP `ComputedStructureEntries` queried on 2022-09-16 ([database release 2021.05.13](https://docs.materialsproject.org/changes/database-versions#v2021.05.13))
2630

scripts/cumulative_clf_metrics.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@
4848

4949

5050
# %%
51-
img_path = f"{ROOT}/figures/{today}-precision-recall-curves"
51+
img_path = f"{ROOT}/figures/{today}-cumulative-clf-metrics"
52+
# for trace in fig.data:
53+
# assert isinstance(trace.y[0], float)
54+
# trace.y = [round(y, 3) for y in trace.y]
55+
# fig
5256
# if hasattr(fig, "write_image"):
5357
# fig.write_image(f"{img_path}.pdf")
5458
# fig.write_html(

site/src/app.css

+4-6
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ body {
1919
color: var(--text-color);
2020
line-height: 1.5;
2121
}
22-
main {
23-
margin: auto;
24-
margin-bottom: 3em;
25-
width: 100%;
26-
max-width: 50em;
27-
}
2822
button {
2923
color: var(--text-color);
3024
cursor: pointer;
@@ -68,6 +62,10 @@ label {
6862
font-weight: bold;
6963
cursor: pointer;
7064
}
65+
img {
66+
max-width: 100%;
67+
margin: 1em auto;
68+
}
7169

7270
table {
7371
border-collapse: collapse;

site/src/routes/+layout.svelte

+16
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@
22
import { page } from '$app/stores'
33
import Nav from '$lib/Nav.svelte'
44
import { repository } from '$site/package.json'
5+
import { onMount } from 'svelte'
56
import GitHubCorner from 'svelte-github-corner'
67
import Toc from 'svelte-toc'
78
import '../app.css'
89
10+
onMount(() => {
11+
// make markdown links starting with site/src/routes/ files deployment-compatible
12+
for (const link of [
13+
...document.querySelectorAll(`a[href^='site/src/routes']`),
14+
] as HTMLAnchorElement[]) {
15+
link.href = link.href.replace(`/site/src/routes`, ``).split(`/+page`)[0]
16+
}
17+
})
18+
919
const routes = Object.keys(import.meta.glob(`./*/+page.{svx,svelte,md}`)).map(
1020
(filename) => `/` + filename.split(`/`)[1]
1121
)
@@ -30,6 +40,12 @@
3040
</main>
3141

3242
<style>
43+
main {
44+
margin: auto;
45+
margin-bottom: 3em;
46+
width: 100%;
47+
max-width: 50em;
48+
}
3349
a[href='/'] {
3450
font-size: 15pt;
3551
position: absolute;

site/src/routes/+page.svelte

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
<script lang="ts">
2-
import CumulativeMetricsPlot from '$root/figures/2022-12-25-precision-recall-curves.svelte'
2+
import CumulativeMetricsPlot from '$root/figures/2022-12-26-cumulative-clf-metrics.svelte'
33
import Readme from '$root/readme.md'
4-
import { onMount } from 'svelte'
5-
6-
onMount(() => {
7-
// make links to site/src/routes/ files deployment-compatible
8-
const site_links: NodeListOf<HTMLAnchorElement> = document.querySelectorAll(
9-
`a[href^='site/src/routes']`
10-
)
11-
for (const link of site_links) {
12-
link.href = link.href.replace(`/site/src/routes`, ``).split('/+page')[0]
13-
}
14-
})
154
</script>
165

176
<Readme />
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
11
<script lang="ts">
2+
import Plot from '$root/data/wbm/2022-12-07-hist-e-form-per-atom.svelte'
23
import DataReadme from '$root/data/wbm/readme.md'
3-
import { onMount } from 'svelte'
4-
5-
const figs = import.meta.glob(`$root/data/wbm/*.{png,svg,pdf}`, {
6-
eager: true,
7-
as: `url`,
8-
})
9-
10-
onMount(() => {
11-
for (const img of document.querySelectorAll(`img`)) {
12-
const src = `../data/wbm/${img.getAttribute(`src`)}`
13-
if (figs[src]) img.src = figs[src]
14-
}
15-
})
164
</script>
175

18-
<main>
19-
<DataReadme />
20-
</main>
21-
22-
<style>
23-
:global(img) {
24-
max-width: 100%;
25-
margin: 1em auto;
26-
}
27-
</style>
6+
<DataReadme>
7+
<svelte:fragment slot="hist-e-form-per-atom">
8+
{#if typeof document !== `undefined`}
9+
<Plot />
10+
{/if}
11+
</svelte:fragment>
12+
</DataReadme>

site/src/routes/api/+page.svelte

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!-- needed for /api page to show up -->

site/svelte.config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ export default {
2828

2929
preprocess: [
3030
preprocess(),
31-
mdsvex({ rehypePlugins, extensions: [`.svx`, `.md`] }),
31+
mdsvex({
32+
rehypePlugins,
33+
extensions: [`.svx`, `.md`],
34+
}),
3235
],
3336

3437
kit: {

0 commit comments

Comments
 (0)