-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathphonon_bands.py
80 lines (67 loc) · 2.52 KB
/
phonon_bands.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
# %%
import json
from glob import glob
import numpy as np
from monty.io import zopen
from monty.json import MontyDecoder
from pymatgen.phonon.bandstructure import PhononBandStructureSymmLine as PhononBands
import pymatviz as pmv
from pymatviz.phonons import PhononDBDoc
from pymatviz.utils.testing import TEST_FILES
try:
import atomate2 # noqa: F401
except ImportError:
raise SystemExit(0) from None # need atomate2 for MontyDecoder to load PhononDBDoc
# %% Plot phonon bands and DOS
for mp_id, formula in (
("mp-2758", "Sr4Se4"),
("mp-23907", "H2"),
):
docs: dict[str, PhononDBDoc] = {}
for path in glob(f"{TEST_FILES}/phonons/{mp_id}-{formula}-*.json.xz"):
model_label = (
"CHGNet"
if "chgnet" in path
else "MACE"
if "mace" in path
else "M3GNet"
if "m3gnet" in path
else "PBE"
)
with zopen(path) as file:
docs[model_label] = json.loads(file.read(), cls=MontyDecoder)
ph_bands: dict[str, PhononBands] = {
key: doc.phonon_bandstructure for key, doc in docs.items()
}
acoustic_lines: dict[str, str | float] = dict(width=1.5)
optical_lines: dict[str, str | float] = dict(width=1)
if len(ph_bands) == 1:
acoustic_lines |= dict(dash="dash", color="red", name="Acoustic")
optical_lines |= dict(dash="dot", color="blue", name="Optical")
fig = pmv.phonon_bands(
ph_bands, line_kwargs=dict(acoustic=acoustic_lines, optical=optical_lines)
)
fig.layout.title = dict(text=f"{formula} ({mp_id}) Phonon Bands", x=0.5, y=0.98)
fig.layout.margin = dict(l=0, r=0, b=0, t=40)
fig.show()
# pmv.io.save_and_compress_svg(fig, f"phonon-bands-{mp_id}")
# %% phonon bands
try:
import phonopy
except ImportError:
raise SystemExit(0) from None # install phonopy to run this script
phonopy_nacl: phonopy.Phonopy = phonopy.load(
phonopy_yaml=f"{TEST_FILES}/phonons/NaCl/phonopy_disp.yaml.xz",
force_sets_filename=f"{TEST_FILES}/phonons/NaCl/force_sets.dat",
)
phonopy_nacl.run_mesh([10, 10, 10])
bands = {
"L -> Γ": np.linspace([1 / 3, 1 / 3, 0], [0, 0, 0], 51),
"Γ -> X": np.linspace([0, 0, 0], [1 / 2, 0, 0], 51),
"X -> K": np.linspace([1 / 2, 0, 0], [1 / 2, 1 / 2, 0], 51),
"K -> Γ": np.linspace([1 / 2, 1 / 2, 0], [0, 0, 0], 51),
"Γ -> W": np.linspace([0, 0, 0], [1 / 3, 1 / 3, 1 / 2], 51),
}
phonopy_nacl.run_band_structure(paths=bands.values())
fig = pmv.phonon_bands({"NaCl (phonopy)": phonopy_nacl.band_structure})
fig.show()