@@ -230,7 +230,7 @@ def __iter__(self) -> Iterator[PeriodicSite]:
230
230
return iter (self .sites )
231
231
232
232
# TODO return type needs fixing (can be Sequence[PeriodicSite] but raises lots of mypy errors)
233
- def __getitem__ (self , ind : int | slice ) -> PeriodicSite :
233
+ def __getitem__ (self , ind : int | slice ):
234
234
return self .sites [ind ] # type: ignore[return-value]
235
235
236
236
def __len__ (self ) -> int :
@@ -999,7 +999,7 @@ def from_ase_atoms(cls, atoms: Atoms, **kwargs) -> Self:
999
999
"""
1000
1000
from pymatgen .io .ase import AseAtomsAdaptor
1001
1001
1002
- return AseAtomsAdaptor .get_structure (atoms , cls = cls , ** kwargs )
1002
+ return AseAtomsAdaptor .get_structure (atoms , cls = cls , ** kwargs ) # type:ignore[type-var]
1003
1003
1004
1004
1005
1005
class IStructure (SiteCollection , MSONable ):
@@ -2764,7 +2764,7 @@ def get_orderings(
2764
2764
self ,
2765
2765
mode : Literal ["enum" , "sqs" ] = "enum" ,
2766
2766
** kwargs ,
2767
- ) -> list [Structure | IStructure ]:
2767
+ ) -> list [Structure ]:
2768
2768
"""Get list of orderings for a disordered structure. If structure
2769
2769
does not contain disorder, the default structure is returned.
2770
2770
@@ -2784,7 +2784,7 @@ def get_orderings(
2784
2784
List[Structure]
2785
2785
"""
2786
2786
if self .is_ordered :
2787
- return [self ]
2787
+ return [self ] # type:ignore[list-item]
2788
2788
if mode .startswith ("enum" ):
2789
2789
from pymatgen .command_line .enumlib_caller import EnumlibAdaptor
2790
2790
@@ -2903,7 +2903,7 @@ def from_dict(
2903
2903
if fmt == "abivars" :
2904
2904
from pymatgen .io .abinit .abiobjects import structure_from_abivars
2905
2905
2906
- return structure_from_abivars (cls = cls , ** dct )
2906
+ return structure_from_abivars (cls = cls , ** dct ) # type:ignore[return-value]
2907
2907
2908
2908
lattice = Lattice .from_dict (dct ["lattice" ])
2909
2909
sites = [PeriodicSite .from_dict (sd , lattice ) for sd in dct ["sites" ]]
@@ -3117,7 +3117,7 @@ def from_str( # type:ignore[override]
3117
3117
elif fmt_low == "xsf" :
3118
3118
from pymatgen .io .xcrysden import XSF
3119
3119
3120
- struct = XSF .from_str (input_string , ** kwargs ).structure
3120
+ struct = XSF .from_str (input_string , ** kwargs ).structure # type:ignore[assignment]
3121
3121
elif fmt_low == "mcsqs" :
3122
3122
from pymatgen .io .atat import Mcsqs
3123
3123
@@ -3257,7 +3257,7 @@ def from_file( # type:ignore[override]
3257
3257
elif fnmatch (fname , "input*.xml" ):
3258
3258
from pymatgen .io .exciting import ExcitingInput
3259
3259
3260
- return ExcitingInput .from_file (fname , ** kwargs ).structure # type:ignore[assignment]
3260
+ return ExcitingInput .from_file (fname , ** kwargs ).structure # type:ignore[assignment, return-value ]
3261
3261
elif fnmatch (fname , "*rndstr.in*" ) or fnmatch (fname , "*lat.in*" ) or fnmatch (fname , "*bestsqs*" ):
3262
3262
return cls .from_str (
3263
3263
contents ,
@@ -3270,7 +3270,7 @@ def from_file( # type:ignore[override]
3270
3270
elif fnmatch (fname , "CTRL*" ):
3271
3271
from pymatgen .io .lmto import LMTOCtrl
3272
3272
3273
- return LMTOCtrl .from_file (filename = filename , ** kwargs ).structure # type:ignore[assignment]
3273
+ return LMTOCtrl .from_file (filename = filename , ** kwargs ).structure # type:ignore[assignment,return-value ]
3274
3274
elif fnmatch (fname , "geometry.in*" ):
3275
3275
return cls .from_str (
3276
3276
contents ,
@@ -3496,7 +3496,7 @@ def __init__(
3496
3496
label = labels [idx ] if labels else None
3497
3497
sites .append (Site (species [idx ], coords [idx ], properties = prop , label = label ))
3498
3498
3499
- self ._sites = tuple (sites )
3499
+ self ._sites = tuple (sites ) # type:ignore[arg-type]
3500
3500
if validate_proximity and not self .is_valid ():
3501
3501
raise StructureError ("Molecule contains sites that are less than 0.01 Angstrom apart!" )
3502
3502
@@ -3785,7 +3785,7 @@ def get_distance(self, i: int, j: int) -> float:
3785
3785
"""
3786
3786
return self [i ].distance (self [j ])
3787
3787
3788
- def get_sites_in_sphere (self , pt : ArrayLike , r : float ) -> list [Neighbor ]:
3788
+ def get_sites_in_sphere (self , pt : NDArray , r : float ) -> list [Neighbor ]:
3789
3789
"""Find all sites within a sphere from a point.
3790
3790
3791
3791
Args:
@@ -3825,7 +3825,7 @@ def get_neighbors(self, site: Site, r: float) -> list[Neighbor]:
3825
3825
nns = self .get_sites_in_sphere (site .coords , r )
3826
3826
return [nn for nn in nns if nn != site ]
3827
3827
3828
- def get_neighbors_in_shell (self , origin : ArrayLike , r : float , dr : float ) -> list [Neighbor ]:
3828
+ def get_neighbors_in_shell (self , origin : NDArray , r : float , dr : float ) -> list [Neighbor ]:
3829
3829
"""Get all sites in a shell centered on origin (coords) between radii
3830
3830
r-dr and r+dr.
3831
3831
@@ -3925,7 +3925,7 @@ def get_boxed_structure(
3925
3925
break
3926
3926
distances = lattice .get_all_distances (
3927
3927
lattice .get_fractional_coords (new_coords ),
3928
- lattice .get_fractional_coords (all_coords ),
3928
+ lattice .get_fractional_coords (all_coords ), # type:ignore[arg-type]
3929
3929
)
3930
3930
if np .amin (distances ) > min_dist :
3931
3931
break
@@ -4104,7 +4104,7 @@ def from_file(cls, filename: PathLike) -> IMolecule | Molecule: # type:ignore[o
4104
4104
filename = str (filename )
4105
4105
4106
4106
with zopen (filename , mode = "rt" , encoding = "utf-8" ) as file :
4107
- contents : str = file .read ()
4107
+ contents : str = file .read () # type:ignore[assignment]
4108
4108
fname = filename .lower ()
4109
4109
if fnmatch (fname , "*.xyz*" ):
4110
4110
return cls .from_str (contents , fmt = "xyz" )
@@ -4134,9 +4134,9 @@ class Structure(IStructure, collections.abc.MutableSequence):
4134
4134
4135
4135
def __init__ (
4136
4136
self ,
4137
- lattice : ArrayLike | Lattice ,
4137
+ lattice : NDArray | Lattice ,
4138
4138
species : Sequence [CompositionLike ],
4139
- coords : Sequence [ArrayLike ] | np . ndarray ,
4139
+ coords : Sequence [NDArray ] | NDArray ,
4140
4140
charge : float | None = None ,
4141
4141
validate_proximity : bool = False ,
4142
4142
to_unit_cell : bool = False ,
@@ -4264,7 +4264,7 @@ def __setitem__(
4264
4264
else :
4265
4265
self ._sites [ii ].species = site [0 ] # type: ignore[assignment, index]
4266
4266
if len (site ) > 1 :
4267
- self ._sites [ii ].frac_coords = site [1 ] # type: ignore[index]
4267
+ self ._sites [ii ].frac_coords = site [1 ] # type: ignore[index,assignment ]
4268
4268
if len (site ) > 2 :
4269
4269
self ._sites [ii ].properties = site [2 ] # type: ignore[assignment, index]
4270
4270
@@ -4288,7 +4288,7 @@ def lattice(self, lattice: ArrayLike | Lattice) -> None:
4288
4288
def append ( # type:ignore[override]
4289
4289
self ,
4290
4290
species : CompositionLike ,
4291
- coords : ArrayLike ,
4291
+ coords : NDArray ,
4292
4292
coords_are_cartesian : bool = False ,
4293
4293
validate_proximity : bool = False ,
4294
4294
properties : dict | None = None ,
@@ -4320,7 +4320,7 @@ def insert( # type:ignore[override]
4320
4320
self ,
4321
4321
idx : int ,
4322
4322
species : CompositionLike ,
4323
- coords : ArrayLike ,
4323
+ coords : NDArray ,
4324
4324
coords_are_cartesian : bool = False ,
4325
4325
validate_proximity : bool = False ,
4326
4326
properties : dict | None = None ,
@@ -4358,7 +4358,7 @@ def replace(
4358
4358
self ,
4359
4359
idx : int ,
4360
4360
species : CompositionLike ,
4361
- coords : ArrayLike | None = None ,
4361
+ coords : NDArray | None = None ,
4362
4362
coords_are_cartesian : bool = False ,
4363
4363
properties : dict | None = None ,
4364
4364
label : str | None = None ,
@@ -4757,7 +4757,7 @@ def make_supercell(
4757
4757
scaling_matrix : ArrayLike ,
4758
4758
to_unit_cell : bool = True ,
4759
4759
in_place : bool = True ,
4760
- ) -> Self :
4760
+ ) -> Structure :
4761
4761
"""Create a supercell.
4762
4762
4763
4763
Args:
@@ -4793,7 +4793,7 @@ def make_supercell(
4793
4793
4794
4794
return struct
4795
4795
4796
- def scale_lattice (self , volume : float ) -> Self :
4796
+ def scale_lattice (self , volume : float ) -> Structure :
4797
4797
"""Perform scaling of the lattice vectors so that length proportions
4798
4798
and angles are preserved.
4799
4799
@@ -4920,7 +4920,7 @@ def relax(
4920
4920
Structure | tuple[Structure, Trajectory]: Relaxed structure or if return_trajectory=True,
4921
4921
2-tuple of Structure and matgl TrajectoryObserver.
4922
4922
"""
4923
- return self ._relax (
4923
+ return self ._relax ( # type:ignore[return-value]
4924
4924
calculator ,
4925
4925
relax_cell = relax_cell ,
4926
4926
optimizer = optimizer ,
@@ -5111,7 +5111,7 @@ def __init__(
5111
5111
charge_spin_check = charge_spin_check ,
5112
5112
properties = properties ,
5113
5113
)
5114
- self ._sites : list [Site ] = list (self ._sites )
5114
+ self ._sites : list [Site ] = list (self ._sites ) # type:ignore[assignment]
5115
5115
5116
5116
def __setitem__ (
5117
5117
self ,
@@ -5161,7 +5161,7 @@ def __delitem__(self, idx: SupportsIndex | slice) -> None:
5161
5161
def append ( # type:ignore[override]
5162
5162
self ,
5163
5163
species : CompositionLike ,
5164
- coords : ArrayLike ,
5164
+ coords : NDArray ,
5165
5165
validate_proximity : bool = False ,
5166
5166
properties : dict | None = None ,
5167
5167
) -> Self :
@@ -5250,9 +5250,9 @@ def insert( # type:ignore[override]
5250
5250
new_site = Site (species , coords , properties = properties , label = label )
5251
5251
if validate_proximity :
5252
5252
for site in self :
5253
- if site .distance (new_site ) < self .DISTANCE_TOLERANCE :
5253
+ if site .distance (new_site ) < self .DISTANCE_TOLERANCE : # type:ignore[arg-type]
5254
5254
raise ValueError ("New site is too close to an existing site!" )
5255
- cast ("list[PeriodicSite]" , self .sites ).insert (idx , new_site )
5255
+ cast ("list[PeriodicSite]" , self .sites ).insert (idx , new_site ) # type:ignore[arg-type]
5256
5256
5257
5257
return self
5258
5258
@@ -5278,7 +5278,7 @@ def remove_species(self, species: Sequence[SpeciesLike]) -> Self:
5278
5278
label = site .label ,
5279
5279
)
5280
5280
)
5281
- self .sites = new_sites
5281
+ self .sites = new_sites # type:ignore[assignment]
5282
5282
return self
5283
5283
5284
5284
def remove_sites (self , indices : Sequence [int ]) -> Self :
@@ -5466,7 +5466,7 @@ def substitute(
5466
5466
# Check whether the functional group is in database.
5467
5467
if func_group not in FunctionalGroups :
5468
5468
raise RuntimeError ("Can't find functional group in list. Provide explicit coordinate instead" )
5469
- functional_group = FunctionalGroups [func_group ]
5469
+ functional_group = FunctionalGroups [func_group ] # type:ignore[assignment]
5470
5470
5471
5471
# If a bond length can be found, modify func_grp so that the X-group
5472
5472
# bond length is equal to the bond length.
@@ -5536,7 +5536,7 @@ def relax(
5536
5536
Molecule | tuple[Molecule, Trajectory]: Relaxed Molecule or if return_trajectory=True,
5537
5537
2-tuple of Molecule and ASE TrajectoryObserver.
5538
5538
"""
5539
- return self ._relax (
5539
+ return self ._relax ( # type:ignore[return-value]
5540
5540
calculator ,
5541
5541
relax_cell = False ,
5542
5542
optimizer = optimizer ,
0 commit comments