-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathphonon_dos.py
59 lines (46 loc) · 1.73 KB
/
phonon_dos.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
# %%
import json
from glob import glob
from monty.io import zopen
from monty.json import MontyDecoder
from pymatgen.phonon.dos import PhononDos
import pymatviz as pmv
from pymatviz.phonons.helpers 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"):
key = path.split("-", maxsplit=3)[-1].split(".")[0]
with zopen(path) as file:
docs[key] = json.loads(file.read(), cls=MontyDecoder)
ph_doses: dict[str, PhononDos] = {key: doc.phonon_dos for key, doc in docs.items()}
fig = pmv.phonon_dos(ph_doses)
fig.layout.title = dict(text=f"Phonon 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-dos-{mp_id}")
# %% plotting a phonopy TotalDos also works
try:
import phonopy
except ImportError:
raise SystemExit(0) from None # install phonopy to run this script
phonopy_nacl = phonopy.load(
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])
phonopy_nacl.run_total_dos()
plt = phonopy_nacl.plot_total_dos()
plt.title("NaCl DOS plotted by phonopy")
fig = pmv.phonon_dos(phonopy_nacl.total_dos)
fig.layout.title = dict(text="NaCl DOS plotted by pymatviz", x=0.5, y=0.97)
fig.layout.margin = dict(l=0, r=0, b=0, t=40)
fig.show()