diff --git a/emmet-core/emmet/core/symmetry.py b/emmet-core/emmet/core/symmetry.py index 4c27155efb..b76f0c3bd1 100644 --- a/emmet-core/emmet/core/symmetry.py +++ b/emmet-core/emmet/core/symmetry.py @@ -3,7 +3,12 @@ from pydantic import BaseModel, Field from pymatgen.core import Structure from pymatgen.core.structure import Molecule -from pymatgen.symmetry.analyzer import PointGroupAnalyzer, SpacegroupAnalyzer, spglib +from pymatgen.symmetry.analyzer import ( + PointGroupAnalyzer, + SpacegroupAnalyzer, + spglib, + SymmetryUndeterminedError, +) from emmet.core.settings import EmmetSettings from emmet.core.utils import ValueEnum @@ -139,29 +144,56 @@ class SymmetryData(BaseModel): symprec: Optional[float] = Field( None, title="Symmetry Finding Precision", - description="The precision given to spglib to determine the symmetry of this lattice.", + description="The precision provided to spglib to determine the symmetry of this structure.", ) - version: Optional[str] = Field(None, title="SPGLib version") + angle_tolerance: Optional[float] = Field( + None, + title="Angle Tolerance", + description="Angle tolerance provided to spglib to determine the symmetry of this structure.", + ) + + version: Optional[str] = Field(None, title="spglib version") @classmethod def from_structure(cls, structure: Structure) -> "SymmetryData": - symprec = SETTINGS.SYMPREC - sg = SpacegroupAnalyzer(structure, symprec=symprec) - symmetry: Dict[str, Any] = {"symprec": symprec} - if not sg.get_symmetry_dataset(): - sg = SpacegroupAnalyzer(structure, 1e-3, 1) - symmetry["symprec"] = 1e-3 + symmetry: Dict[str, Any] = { + "source": "spglib", + "symbol": None, + "number": None, + "point_group": None, + "crystal_system": None, + "hall": None, + "version": spglib.__version__, + "symprec": SETTINGS.SYMPREC, + "angle_tolerance": SETTINGS.ANGLE_TOL, + } + + try: + sg = SpacegroupAnalyzer( + structure, + symprec=symmetry["symprec"], + angle_tolerance=symmetry["angle_tolerance"], + ) + except SymmetryUndeterminedError: + try: + symmetry["symprec"] = 1e-3 + symmetry["angle_tolerance"] = 1 + sg = SpacegroupAnalyzer( + structure, + symprec=symmetry["symprec"], + angle_tolerance=symmetry["angle_tolerance"], + ) + except SymmetryUndeterminedError: + return SymmetryData(**symmetry) symmetry.update( { - "source": "spglib", "symbol": sg.get_space_group_symbol(), "number": sg.get_space_group_number(), "point_group": sg.get_point_group_symbol(), "crystal_system": CrystalSystem(sg.get_crystal_system().title()), "hall": sg.get_hall(), - "version": spglib.__version__, } ) diff --git a/emmet-core/setup.py b/emmet-core/setup.py index b0d8a3fdd5..7b989a6a1a 100644 --- a/emmet-core/setup.py +++ b/emmet-core/setup.py @@ -29,7 +29,7 @@ include_package_data=True, install_requires=[ "numpy<2", - "pymatgen", + "pymatgen>=2024.6.10", "monty>=2024.2.2", "pydantic>=2.0", "pydantic-settings>=2.0",