Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions mp_api/client/routes/materials/grain_boundaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Collaborator

@tsmathis tsmathis Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this really work as a union?

and also why is the union str | float? The data types in the db are all int:

db.grain_boundaries.aggregate([
  {
    $project: {
      _id: 0,
      init_axis: "$initial_structure.rotation_axis",
      final_axis: "$final_structure.rotation_axis",
    },
  },
  {
    $facet: {
      init_axis: [
        { $unwind: "$init_axis" },
        { $group: { _id: { $type: "$init_axis" }, count: { $sum: 1 } } },
      ],
      final_axis: [
        { $unwind: "$final_axis" },
        { $group: { _id: { $type: "$final_axis" }, count: { $sum: 1 } } },
      ],
    },
  },
]);

-----
[
  {
    init_axis: [ { _id: 'int', count: 1008 } ],
    final_axis: [ { _id: 'int', count: 1009 } ]
  }
]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obviously if this all "just works" since later on everything is cast to str and joined as a comma separated string then it's fine

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The str is a holdover from before, the float is wrong, I'll change that to int. To make the API request, it just needs to format into a str like you said, so it's OK

rotation_angle: tuple[float, float] | None = None,
separation_energy: tuple[float, float] | None = None,
sigma: int | None = None,
Expand All @@ -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.
Expand Down Expand Up @@ -84,6 +86,10 @@ def search(
)

if rotation_axis:
if len(rotation_axis) != 3:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are also instances of rotation_axis = [ 0, 0, 0, 1 ]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right - changed this overall just to use tuple[ int * 3] or tuple[int * 4] as the type hint and for the value check

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])}
)
Expand Down
4 changes: 2 additions & 2 deletions mp_api/client/routes/materials/phonon.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading