-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathspacegroup_sunburst.py
65 lines (53 loc) · 2.1 KB
/
spacegroup_sunburst.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# %%
from matminer.datasets import load_dataset
from tqdm import tqdm
import pymatviz as pmv
from pymatviz.enums import Key
# %%
df_phonons = load_dataset("matbench_phonons")
df_phonons[Key.spg_num] = [
struct.get_symmetry_dataset(backend="moyopy", return_raw_dataset=True).number
for struct in tqdm(df_phonons[Key.structure])
]
df_phonons[Key.spg_symbol] = df_phonons[Key.spg_num].map(
pmv.utils.spg_num_to_from_symbol
)
# %% Sunburst Plots
fig = pmv.spacegroup_sunburst(df_phonons[Key.spg_num], show_counts="percent")
title = "Matbench Phonons Spacegroup Sunburst"
fig.layout.title = dict(text=f"<b>{title}</b>", x=0.5, y=0.96, font_size=18)
fig.show()
# pmv.io.save_and_compress_svg(fig, "spg-num-sunburst")
fig = pmv.spacegroup_sunburst(df_phonons[Key.spg_symbol], show_counts="percent")
title = "Matbench Phonons Spacegroup Symbols Sunburst"
fig.layout.title = dict(text=f"<b>{title}</b>", x=0.5, y=0.96, font_size=18)
fig.show()
# pmv.io.save_and_compress_svg(fig, "spg-symbol-sunburst")
# %% Demonstrate max_slices with "other" mode
# Show only top 3 space groups per crystal system, combine the rest into "Other"
max_slices = 6
fig = pmv.spacegroup_sunburst(
df_phonons[Key.spg_num],
show_counts="value+percent",
max_slices=max_slices,
max_slices_mode="other",
)
title = f"Matbench Phonons Space Groups - Top {max_slices} Crystal Systems (Other Mode)"
fig.layout.title = dict(text=f"<b>{title}</b>", x=0.5, y=0.96, font_size=18)
fig.layout.update(height=600)
fig.show()
# pmv.io.save_and_compress_svg(fig, "spg-num-sunburst-max-slices-other")
# %% Demonstrate max_slices with "drop" mode
# Show only top 2 space groups per crystal system, discard the rest
max_slices = 5
fig = pmv.spacegroup_sunburst(
df_phonons[Key.spg_num],
show_counts="value+percent",
max_slices=max_slices,
max_slices_mode="drop",
)
title = f"Matbench Phonons Space Groups - Top {max_slices} Crystal Systems (Drop Mode)"
fig.layout.title = dict(text=f"<b>{title}</b>", x=0.5, y=0.96, font_size=18)
fig.layout.update(height=600)
fig.show()
# pmv.io.save_and_compress_svg(fig, "spg-num-sunburst-max-slices-drop")