Skip to content

Commit 307c43b

Browse files
committed
add bs/dos/force constants functions for phonon
1 parent d91ee27 commit 307c43b

File tree

1 file changed

+75
-2
lines changed

1 file changed

+75
-2
lines changed

mp_api/client/routes/materials/phonon.py

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from __future__ import annotations
22

3+
import json
34
from collections import defaultdict
45

5-
from emmet.core.phonon import PhononBSDOSDoc
6+
from monty.json import MontyDecoder
7+
from emmet.core.phonon import PhononBSDOSDoc, PhononBS, PhononDOS
68

7-
from mp_api.client.core import BaseRester
9+
from mp_api.client.core import BaseRester, MPRestError
810
from mp_api.client.core.utils import validate_ids
911

1012

@@ -61,3 +63,74 @@ def search(
6163
fields=fields,
6264
**query_params,
6365
)
66+
67+
def get_bandstructure_from_material_id(self, material_id: str, phonon_method: str):
68+
"""Get the phonon band structure pymatgen object associated with a given material ID and phonon method.
69+
70+
Arguments:
71+
material_id (str): Material ID for the phonon band structure calculation
72+
phonon_method (str): phonon method, i.e. pheasy or dfpt
73+
74+
Returns:
75+
bandstructure (PhononBS): PhononBS object
76+
"""
77+
decoder = MontyDecoder().decode if self.monty_decode else json.loads
78+
result = self._query_open_data(
79+
bucket="materialsproject-parsed",
80+
key=f"ph-bandstructures/{phonon_method}/{material_id}.json.gz",
81+
decoder=decoder,
82+
)[0]
83+
84+
if not result or not result[0]:
85+
raise MPRestError("No object found")
86+
87+
if self.use_document_model:
88+
return PhononBS(**result[0])
89+
90+
return result[0]
91+
92+
def get_dos_from_material_id(self, material_id: str, phonon_method: str):
93+
"""Get the phonon dos pymatgen object associated with a given material ID and phonon method.
94+
95+
Arguments:
96+
material_id (str): Material ID for the phonon dos calculation
97+
phonon_method (str): phonon method, i.e. pheasy or dfpt
98+
99+
Returns:
100+
dos (PhononDOS): PhononDOS object
101+
"""
102+
decoder = MontyDecoder().decode if self.monty_decode else json.loads
103+
result = self._query_open_data(
104+
bucket="materialsproject-parsed",
105+
key=f"ph-dos/{phonon_method}/{material_id}.json.gz",
106+
decoder=decoder,
107+
)[0]
108+
109+
if not result or not result[0]:
110+
raise MPRestError("No object found")
111+
112+
if self.use_document_model:
113+
return PhononDOS(**result[0])
114+
115+
return result[0]
116+
117+
def get_forceconstants_from_material_id(self, material_id: str):
118+
"""Get the force constants associated with a given material ID.
119+
120+
Arguments:
121+
material_id (str): Material ID for the force constants calculation
122+
123+
Returns:
124+
force constants (list[list[Matrix3D]]): PhononDOS object
125+
"""
126+
decoder = MontyDecoder().decode if self.monty_decode else json.loads
127+
result = self._query_open_data(
128+
bucket="materialsproject-parsed",
129+
key=f"ph-force-constants/{material_id}.json.gz",
130+
decoder=decoder,
131+
)[0]
132+
133+
if not result or not result[0]:
134+
raise MPRestError("No object found")
135+
136+
return result[0]

0 commit comments

Comments
 (0)