88import warnings
99from copy import deepcopy
1010from importlib .metadata import PackageNotFoundError
11- from typing import TYPE_CHECKING , TypeVar
11+ from typing import TYPE_CHECKING , Literal , TypeVar , overload
1212
1313import numpy as np
1414from monty .json import MontyDecoder , MSONable , jsanitize
@@ -48,8 +48,8 @@ def __init__(self, *args, **kwargs):
48484949__date__ = "Mar 8, 2012"
5050
51- StructT = TypeVar ("StructT " , bound = IStructure | IMolecule | Structure | Molecule )
52- MolT = TypeVar ("MolT " , bound = IMolecule )
51+ IMoleculeT = TypeVar ("IMoleculeT " , bound = IMolecule )
52+ StructOrMolT = TypeVar ("StructOrMolT " , bound = Structure | Molecule )
5353
5454
5555class MSONAtoms (Atoms , MSONable ):
@@ -86,6 +86,30 @@ def from_dict(cls, dct: dict[str, Any]) -> Self:
8686class AseAtomsAdaptor :
8787 """Adaptor serves as a bridge between ASE Atoms and pymatgen objects."""
8888
89+ @overload
90+ @staticmethod
91+ def get_atoms (
92+ structure : SiteCollection ,
93+ msonable : Literal [True ] = ...,
94+ ** kwargs : Any ,
95+ ) -> MSONAtoms : ...
96+
97+ @overload
98+ @staticmethod
99+ def get_atoms (
100+ structure : SiteCollection ,
101+ msonable : Literal [False ],
102+ ** kwargs : Any ,
103+ ) -> Atoms : ...
104+
105+ @overload
106+ @staticmethod
107+ def get_atoms (
108+ structure : SiteCollection ,
109+ msonable : bool = True ,
110+ ** kwargs : Any ,
111+ ) -> MSONAtoms | Atoms : ...
112+
89113 @staticmethod
90114 def get_atoms (
91115 structure : SiteCollection ,
@@ -239,9 +263,9 @@ def get_atoms(
239263 @staticmethod
240264 def get_structure (
241265 atoms : Atoms ,
242- cls = Structure ,
266+ cls : type [ StructOrMolT ] = Structure ,
243267 ** cls_kwargs ,
244- ) -> Structure | Molecule :
268+ ) -> StructOrMolT :
245269 """Get pymatgen structure from ASE Atoms.
246270
247271 Args:
@@ -392,7 +416,7 @@ def get_structure(
392416 return structure
393417
394418 @staticmethod
395- def get_molecule (atoms : Atoms , cls : type [MolT ] = Molecule , ** cls_kwargs ) -> Molecule | IMolecule : # type:ignore[assignment]
419+ def get_molecule (atoms : Atoms , cls : type [IMoleculeT ] = Molecule , ** cls_kwargs ) -> IMoleculeT :
396420 """Get pymatgen molecule from ASE Atoms.
397421
398422 Args:
@@ -401,7 +425,7 @@ def get_molecule(atoms: Atoms, cls: type[MolT] = Molecule, **cls_kwargs) -> Mole
401425 **cls_kwargs: Any additional kwargs to pass to the cls constructor
402426
403427 Returns:
404- (I)Molecule : Equivalent pymatgen (I)Molecule
428+ MolT : Equivalent pymatgen (I)Molecule
405429 """
406430 molecule = AseAtomsAdaptor .get_structure (atoms , cls = cls , ** cls_kwargs )
407431
0 commit comments