-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathphonon_bands_and_dos.py
More file actions
39 lines (32 loc) · 1.24 KB
/
phonon_bands_and_dos.py
File metadata and controls
39 lines (32 loc) · 1.24 KB
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
"""Phonon bands and DOS examples."""
# %%
import json
from glob import glob
from monty.io import zopen
from monty.json import MontyDecoder
from pymatgen.phonon.bandstructure import PhononBandStructureSymmLine as PhononBands
from pymatgen.phonon.dos import PhononDos
import pymatviz as pmv
from pymatviz.phonons import PhononDBDoc
from pymatviz.utils.testing import TEST_FILES
# %% 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"):
key = path.split("-")[-1].split(".")[0]
with zopen(path, mode="rt") as file:
docs[key] = json.loads(file.read(), cls=MontyDecoder)
ph_bands: dict[str, PhononBands] = {
key: doc.phonon_bandstructure for key, doc in docs.items()
}
ph_doses: dict[str, PhononDos] = {key: doc.phonon_dos for key, doc in docs.items()}
fig = pmv.phonon_bands_and_dos(ph_bands, ph_doses)
fig.layout.title = dict(
text=f"Phonon Bands and DOS of {formula} ({mp_id})", 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-and-dos-{mp_id}")