-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Charge density endpoint and client updates
- Loading branch information
Showing
3 changed files
with
46 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,72 @@ | ||
from mp_api.core.client import BaseRester, MPRestError | ||
from mp_api.routes.tasks.client import TaskRester | ||
from mp_api.routes.materials.client import MaterialsRester | ||
|
||
|
||
class ChargeDensityRester(BaseRester): | ||
|
||
suffix = "charge_density" | ||
|
||
def get_charge_density_from_material_id(self, material_id: str): | ||
def get_charge_density_from_calculation_id(self, task_id: str): | ||
""" | ||
Get charge density data for a given Materials Project ID. | ||
Get charge density data for a given calculation ID. | ||
Arguments: | ||
material_id (str): Materials project ID | ||
task_id (str): Calculation ID | ||
Returns: | ||
chgcar (dict): Pymatgen CHGCAR object. | ||
""" | ||
|
||
result = self._make_request( | ||
"{}/?fields=data&all_fields=false".format(material_id) | ||
) | ||
result = self.get_document_by_id(document_id=task_id) | ||
|
||
if result.get("data", None) is not None: | ||
return result["data"] | ||
else: | ||
raise MPRestError("No document found") | ||
raise MPRestError("No charge density found") | ||
|
||
def get_calculation_details(self, material_id: str): | ||
def get_calculation_details(self, task_id: str): | ||
""" | ||
Get charge density calculations details for a given Materials Project ID. | ||
Get charge density calculations details for a given calculation ID. | ||
Arguments: | ||
material_id (str): Materials project ID | ||
task_id (str): Calculation ID | ||
Returns: | ||
calc_details (dict): Dictionary containing INCAR, POSCAR, and KPOINTS data for the DFT calculation. | ||
""" | ||
|
||
base_endpoint = "/".join(self.endpoint.split("/")[0:3]) | ||
task_rester = TaskRester(api_key=self.api_key, endpoint=base_endpoint) # type: ignore | ||
task_rester = TaskRester(endpoint=self.base_endpoint, api_key=self.api_key) # type: ignore | ||
|
||
result = task_rester.get_task_from_material_id( # type: ignore | ||
material_id, fields=["task_id", "orig_inputs"] | ||
).get("data")[0] | ||
|
||
task_rester.session.close() # type: ignore | ||
result = task_rester.get_document_by_id( | ||
document_id=task_id, | ||
fields=["orig_inputs.incar", "orig_inputs.poscar", "orig_inputs.kpoints"], | ||
).orig_inputs | ||
|
||
return result | ||
|
||
def get_calculation_ids_from_material_id(self, material_id: str): | ||
""" | ||
Get charge density calculation ids associated with a given Materials Project ID. | ||
Arguments: | ||
material_id (str): Materials Project ID | ||
Returns: | ||
calculation_ids (List[str]): List of calculation ids. | ||
""" | ||
|
||
materials_rester = MaterialsRester( | ||
endpoint=self.base_endpoint, api_key=self.api_key | ||
) # type: ignore | ||
|
||
calculation_types = materials_rester.get_document_by_id( | ||
document_id=material_id, fields=["calc_types"] | ||
).calc_types | ||
|
||
calculation_ids = [] | ||
for calculation_id, calculation_type in calculation_types.items(): | ||
if "Static" in calculation_type: | ||
calculation_ids.append(calculation_id) | ||
|
||
return calculation_ids |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters