-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathxrd_pattern.py
69 lines (55 loc) · 1.86 KB
/
xrd_pattern.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
# %%
from glob import glob
from pymatgen.analysis.diffraction.xrd import XRDCalculator
from pymatgen.core import Structure
import pymatviz as pmv
from pymatviz.utils.testing import TEST_FILES
pmv.set_plotly_template("pymatviz_white")
# %%
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}/xrd/*.cif")
+ glob(f"{TEST_FILES}/structures/*.json.gz")
}
xrd_patterns = {
key: XRDCalculator().get_pattern(struct) for key, struct in structures.items()
}
key1, key2, key3, *_ = xrd_patterns
# %%
fig = pmv.xrd_pattern(xrd_patterns[key1], annotate_peaks=5)
fig.layout.margin.t = 40
fig.layout.title = dict(text=key1, x=0.5, y=0.97)
fig.show()
pmv.io.save_and_compress_svg(fig, "xrd-pattern")
# %%
fig = pmv.xrd_pattern({key1: xrd_patterns[key1], key2: xrd_patterns[key2]})
fig.show()
pmv.io.save_and_compress_svg(fig, "xrd-pattern-multiple")
# %%
fig = pmv.xrd_pattern(
{key1: xrd_patterns[key1], key2: xrd_patterns[key2], key3: xrd_patterns[key3]},
stack="horizontal",
annotate_peaks=3,
show_angles=True,
)
fig.layout.title = dict(text="Horizontally Stacked XRD Patterns", x=0.5, y=0.97)
fig.layout.margin.t = 40
fig.show()
pmv.io.save_and_compress_svg(fig, "xrd-pattern-horizontal-stack")
# %% New example with vertical stacking and custom subplot titles
fig = pmv.xrd_pattern(
{f"{key1} {idx=}": structures[key1].copy().perturb(idx * 0.5) for idx in range(3)},
stack="vertical",
annotate_peaks=1,
show_angles=True,
subtitle_kwargs=dict(x=1, xanchor="right", font_size=14),
)
fig.layout.title = dict(
text="Vertically Stacked XRD Patterns with Custom Subplot Titles", x=0.5, y=0.97
)
fig.layout.margin.t = 40
fig.show()
pmv.io.save_and_compress_svg(fig, "xrd-pattern-vertical-stack")