-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathcoordination_vs_cutoff_line.py
85 lines (68 loc) · 2.58 KB
/
coordination_vs_cutoff_line.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# %%
from glob import glob
from matminer.datasets import load_dataset
from pymatgen.core import Structure
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
import pymatviz as pmv
from pymatviz.enums import Key
from pymatviz.utils.testing import TEST_FILES
pmv.set_plotly_template("pymatviz_white")
df_phonon = load_dataset(data_name := "matbench_phonons")
# %%
formula_spg_str = (
lambda struct: f"{struct.formula} ({struct.get_space_group_info()[1]})"
)
structures = {
formula_spg_str(struct := Structure.from_file(file)): struct
for file in (
glob(f"{TEST_FILES}/structures/*.json.gz") + glob(f"{TEST_FILES}/xrd/*.cif")
)
}
key1, key2, key3, *_ = structures
for struct in structures.values():
spga = SpacegroupAnalyzer(struct)
sym_struct = spga.get_symmetrized_structure()
# add wyckoff symbols to each site
struct.add_oxidation_state_by_guess()
wyckoff_symbols = ["n/a"] * len(struct)
for indices, symbol in zip(
sym_struct.equivalent_indices, sym_struct.wyckoff_symbols, strict=True
):
for index in indices:
wyckoff_symbols[index] = symbol
if any(sym == "n/a" for sym in wyckoff_symbols):
raise ValueError(f"{struct.formula} has n/a {wyckoff_symbols=}")
struct.add_site_property("wyckoff", wyckoff_symbols)
# %% Coordination vs Cutoff example for a single structure
fig = pmv.coordination_vs_cutoff_line(structures[key1])
fig.layout.title = dict(text=f"Coordination vs Cutoff: {key1}", x=0.5, y=0.98)
fig.layout.margin.t = 50
fig.show()
pmv.io.save_and_compress_svg(fig, "coordination-vs-cutoff-single")
# %% Coordination vs Cutoff example for multiple structures
fig = pmv.coordination_vs_cutoff_line(
{key1: structures[key1], key2: structures[key2], key3: structures[key3]},
strategy=(1.0, 6.0),
num_points=100,
)
fig.layout.title = dict(
text="Coordination vs Cutoff: Multiple Structures", x=0.5, y=0.98
)
fig.layout.legend.update(x=0, y=1, bgcolor="rgba(0,0,0,0)")
fig.layout.margin.t = 50
fig.show()
pmv.io.save_and_compress_svg(fig, "coordination-vs-cutoff-multiple")
# %% Coordination vs Cutoff example with custom color scheme
custom_colors = {"Pd": "red", "Zr": "blue"}
fig = pmv.coordination_vs_cutoff_line(
structures[key1], element_color_scheme=custom_colors
)
fig.layout.margin.t = 25
fig.layout.legend.update(x=0, y=1)
fig.show()
pmv.io.save_and_compress_svg(fig, "coordination-vs-cutoff-custom-colors")
# %% plot first 10 structures
fig = pmv.coordination_vs_cutoff_line(df_phonon[Key.structure][:4].tolist())
fig.layout.margin.t = 25
fig.layout.legend.update(x=0, y=1)
fig.show()