From caca6d8d260b7b16a2eb539e00d33978a4a7653d Mon Sep 17 00:00:00 2001 From: esoteric-ephemera Date: Wed, 9 Jul 2025 09:16:14 -0700 Subject: [PATCH 1/2] improve docstr for grain boundary and add check on rotation axis --- mp_api/client/routes/materials/grain_boundaries.py | 12 +++++++++--- mp_api/client/routes/materials/phonon.py | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/mp_api/client/routes/materials/grain_boundaries.py b/mp_api/client/routes/materials/grain_boundaries.py index 1c73ac970..64592a817 100644 --- a/mp_api/client/routes/materials/grain_boundaries.py +++ b/mp_api/client/routes/materials/grain_boundaries.py @@ -20,7 +20,7 @@ def search( gb_plane: list[str] | None = None, gb_energy: tuple[float, float] | None = None, pretty_formula: str | None = None, - rotation_axis: list[str] | None = None, + rotation_axis: tuple[str | float, str | float, str | float] | None = None, rotation_angle: tuple[float, float] | None = None, separation_energy: tuple[float, float] | None = None, sigma: int | None = None, @@ -40,8 +40,10 @@ def search( material_ids (List[str]): List of Materials Project IDs to query with. pretty_formula (str): Formula of the material. rotation_angle (Tuple[float,float]): Minimum and maximum rotation angle in degrees to consider. - rotation_axis(List[str]): The Miller index of rotation axis. e.g., [1, 0, 0], [1, 1, 0], and [1, 1, 1] - sigma (int): Sigma value of grain boundary. + rotation_axis(List[str]): The Miller index of rotation axis. + A three-tuple of either int or str: e.g., + [1, 0, 0], [1, 1, 0], ["1", "1", "1"] + sigma (int): Sigma value of grain boundary. separation_energy (Tuple[float,float]): Minimum and maximum work of separation energy in J/m³ to consider. sigma (int): Sigma value of the boundary. type (GBTypeEnum): Grain boundary type. @@ -84,6 +86,10 @@ def search( ) if rotation_axis: + if len(rotation_axis) != 3: + raise ValueError( + '`rotation_axis` should be a three-tuple of either int or str, ex: (1,1,0), ("0","0","1")' + ) query_params.update( {"rotation_axis": ",".join([str(n) for n in rotation_axis])} ) diff --git a/mp_api/client/routes/materials/phonon.py b/mp_api/client/routes/materials/phonon.py index f9d9ac9a5..4ce52950e 100644 --- a/mp_api/client/routes/materials/phonon.py +++ b/mp_api/client/routes/materials/phonon.py @@ -1,11 +1,11 @@ from __future__ import annotations import json -import numpy as np from collections import defaultdict +import numpy as np +from emmet.core.phonon import PhononBS, PhononBSDOSDoc, PhononDOS from monty.json import MontyDecoder -from emmet.core.phonon import PhononBSDOSDoc, PhononBS, PhononDOS from mp_api.client.core import BaseRester, MPRestError from mp_api.client.core.utils import validate_ids From 62623d5cf9e2cad181f984746c21bca72685aeb4 Mon Sep 17 00:00:00 2001 From: esoteric-ephemera Date: Wed, 9 Jul 2025 16:05:43 -0700 Subject: [PATCH 2/2] fix docstr / type hinting --- mp_api/client/routes/materials/grain_boundaries.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mp_api/client/routes/materials/grain_boundaries.py b/mp_api/client/routes/materials/grain_boundaries.py index 64592a817..1721ccd64 100644 --- a/mp_api/client/routes/materials/grain_boundaries.py +++ b/mp_api/client/routes/materials/grain_boundaries.py @@ -20,7 +20,7 @@ def search( gb_plane: list[str] | None = None, gb_energy: tuple[float, float] | None = None, pretty_formula: str | None = None, - rotation_axis: tuple[str | float, str | float, str | float] | None = None, + rotation_axis: tuple[int, int, int] | tuple[int, int, int, int] | None = None, rotation_angle: tuple[float, float] | None = None, separation_energy: tuple[float, float] | None = None, sigma: int | None = None, @@ -40,9 +40,9 @@ def search( material_ids (List[str]): List of Materials Project IDs to query with. pretty_formula (str): Formula of the material. rotation_angle (Tuple[float,float]): Minimum and maximum rotation angle in degrees to consider. - rotation_axis(List[str]): The Miller index of rotation axis. - A three-tuple of either int or str: e.g., - [1, 0, 0], [1, 1, 0], ["1", "1", "1"] + rotation_axis (tuple of 3 int or of 4 int): The Miller index of rotation axis. + A 3- or 4-tuple of int or str: e.g., + (0, 0, 0, 1), (1, 0, 0), (1, 1, 0), or (1, 1, 1) sigma (int): Sigma value of grain boundary. separation_energy (Tuple[float,float]): Minimum and maximum work of separation energy in J/m³ to consider. sigma (int): Sigma value of the boundary. @@ -86,9 +86,10 @@ def search( ) if rotation_axis: - if len(rotation_axis) != 3: + if len(rotation_axis) not in {3, 4}: raise ValueError( - '`rotation_axis` should be a three-tuple of either int or str, ex: (1,1,0), ("0","0","1")' + "`rotation_axis` should be a tuple of either " + "3 or 4 int values, ex: (0, 0, 0, 1) or (1, 0, 0)" ) query_params.update( {"rotation_axis": ",".join([str(n) for n in rotation_axis])}