Skip to content

Commit 4005233

Browse files
committed
Cleanup.
1 parent 09c8e49 commit 4005233

File tree

4 files changed

+122
-122
lines changed

4 files changed

+122
-122
lines changed

src/pymatgen/analysis/adsorption.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class AdsorbateSiteFinder:
5757

5858
def __init__(
5959
self,
60-
slab: Slab,
60+
slab: Slab | Structure,
6161
selective_dynamics: bool = False,
6262
height: float = 0.9,
6363
mi_vec: ArrayLike | None = None,
@@ -613,8 +613,7 @@ def get_rot(slab: Slab) -> SymmOp:
613613
new_y = np.cross(new_z, new_x)
614614
x, y, z = np.eye(3)
615615
rot_matrix = np.array([np.dot(*el) for el in itertools.product([x, y, z], [new_x, new_y, new_z])]).reshape(3, 3)
616-
rot_matrix = np.transpose(rot_matrix)
617-
return SymmOp.from_rotation_and_translation(rot_matrix)
616+
return SymmOp.from_rotation_and_translation(np.transpose(rot_matrix))
618617

619618

620619
def put_coord_inside(lattice, cart_coordinate):

src/pymatgen/core/interface.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from numpy.typing import ArrayLike, NDArray
3232
from typing_extensions import Self
3333

34-
from pymatgen.core import Element
34+
from pymatgen.core import Element, Species
3535
from pymatgen.util.typing import CompositionLike
3636

3737
logger = logging.getLogger(__name__)
@@ -250,7 +250,7 @@ def bottom_grain(self) -> Structure:
250250
return Structure.from_sites(bottom_sites)
251251

252252
@property
253-
def coincidents(self) -> list[Site]:
253+
def coincidents(self) -> list[PeriodicSite]:
254254
"""A list of coincident sites."""
255255
coincident_sites = []
256256
for idx, tag in enumerate(self.site_properties["grain_label"]):
@@ -810,7 +810,7 @@ def gb_from_parameters(
810810
_rotation_axis,
811811
rotation_angle,
812812
_plane,
813-
join_plane,
813+
join_plane, # type: ignore[arg-type]
814814
self.initial_structure,
815815
vacuum_thickness,
816816
ab_shift,
@@ -2087,7 +2087,7 @@ def slab_from_csl(
20872087
trans_cry: NDArray,
20882088
max_search: int = 20,
20892089
quick_gen: bool = False,
2090-
) -> Sequence[Sequence[float, float, float], Sequence[float, float, float], Sequence[float, float, float]]:
2090+
) -> NDArray:
20912091
"""By linear operation of csl lattice vectors to get the best corresponding
20922092
slab lattice. That is the area of a,b vectors (within the surface plane)
20932093
is the smallest, the c vector first, has shortest length perpendicular
@@ -2159,14 +2159,14 @@ def slab_from_csl(
21592159
if len(miller_nonzero) > 1:
21602160
t_matrix[2] = csl[c_index]
21612161
index_len = len(miller_nonzero)
2162-
lcm_miller = []
2162+
lcm_miller = [] # type: ignore[assignment]
21632163
for i in range(index_len):
21642164
for j in range(i + 1, index_len):
21652165
com_gcd = math.gcd(miller_nonzero[i], miller_nonzero[j])
21662166
mil1 = round(miller_nonzero[i] / com_gcd)
21672167
mil2 = round(miller_nonzero[j] / com_gcd)
21682168
lcm_miller.append(max(abs(mil1), abs(mil2)))
2169-
lcm_sorted = sorted(lcm_miller)
2169+
lcm_sorted = sorted(lcm_miller) # type: ignore[call-overload]
21702170
max_j = lcm_sorted[0] if index_len == 2 else lcm_sorted[1]
21712171
else:
21722172
if not normal:
@@ -2576,7 +2576,7 @@ def substrate_indices(self) -> list[int]:
25762576
return [i for i, tag in enumerate(self.site_properties["interface_label"]) if "substrate" in tag]
25772577

25782578
@property
2579-
def substrate_sites(self) -> list[Site]:
2579+
def substrate_sites(self) -> list[PeriodicSite]:
25802580
"""The site objects in the substrate."""
25812581
return [
25822582
site for site, tag in zip(self, self.site_properties["interface_label"], strict=True) if "substrate" in tag
@@ -2593,7 +2593,7 @@ def film_indices(self) -> list[int]:
25932593
return [i for i, tag in enumerate(self.site_properties["interface_label"]) if "film" in tag]
25942594

25952595
@property
2596-
def film_sites(self) -> list[Site]:
2596+
def film_sites(self) -> list[PeriodicSite]:
25972597
"""The film sites of the interface."""
25982598
return [site for site, tag in zip(self, self.site_properties["interface_label"], strict=True) if "film" in tag]
25992599

@@ -2905,7 +2905,7 @@ def label_termination(slab: Structure, ftol: float = 0.25, t_idx: int | None = N
29052905
z = linkage(condensed_m)
29062906
clusters = fcluster(z, ftol, criterion="distance")
29072907

2908-
clustered_sites: dict[int, list[Site]] = {c: [] for c in clusters}
2908+
clustered_sites: dict[int, list[PeriodicSite]] = {c: [] for c in clusters}
29092909
for idx, cluster in enumerate(clusters):
29102910
clustered_sites[cluster].append(slab[idx])
29112911

@@ -2923,7 +2923,7 @@ def label_termination(slab: Structure, ftol: float = 0.25, t_idx: int | None = N
29232923
return f"{t_idx}_{form}_{sp_symbol}_{len(top_plane)}"
29242924

29252925

2926-
def count_layers(struct: Structure, el: Element | None = None) -> int:
2926+
def count_layers(struct: Structure, el: Element | Species | None = None) -> int:
29272927
"""Count the number of layers along the c-axis."""
29282928
el = el or struct.elements[0]
29292929
frac_coords = [site.frac_coords for site in struct if site.species_string == str(el)]

src/pymatgen/core/structure.py

Lines changed: 99 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -3191,109 +3191,109 @@ def from_file( # type:ignore[override]
31913191
fname = os.path.basename(filename)
31923192
with zopen(filename, mode="rt", errors="replace", encoding="utf-8") as file:
31933193
contents = file.read()
3194-
if fnmatch(fname.lower(), "*.cif*") or fnmatch(fname.lower(), "*.mcif*"):
3195-
return cls.from_str(
3196-
contents,
3197-
fmt="cif",
3198-
primitive=primitive,
3199-
sort=sort,
3200-
merge_tol=merge_tol,
3201-
**kwargs,
3202-
)
3203-
if fnmatch(fname, "*POSCAR*") or fnmatch(fname, "*CONTCAR*") or fnmatch(fname, "*.vasp"):
3204-
struct = cls.from_str(
3205-
contents,
3206-
fmt="poscar",
3207-
primitive=primitive,
3208-
sort=sort,
3209-
merge_tol=merge_tol,
3210-
**kwargs,
3211-
)
3194+
if fnmatch(fname.lower(), "*.cif*") or fnmatch(fname.lower(), "*.mcif*"):
3195+
return cls.from_str(
3196+
contents,
3197+
fmt="cif",
3198+
primitive=primitive,
3199+
sort=sort,
3200+
merge_tol=merge_tol,
3201+
**kwargs,
3202+
)
3203+
if fnmatch(fname, "*POSCAR*") or fnmatch(fname, "*CONTCAR*") or fnmatch(fname, "*.vasp"):
3204+
struct = cls.from_str(
3205+
contents,
3206+
fmt="poscar",
3207+
primitive=primitive,
3208+
sort=sort,
3209+
merge_tol=merge_tol,
3210+
**kwargs,
3211+
)
32123212

3213-
elif fnmatch(fname, "CHGCAR*") or fnmatch(fname, "LOCPOT*"):
3214-
from pymatgen.io.vasp import Chgcar
3215-
3216-
struct = Chgcar.from_file(filename, **kwargs).structure
3217-
elif fnmatch(fname, "vasprun*.xml*"):
3218-
from pymatgen.io.vasp import Vasprun
3219-
3220-
struct = Vasprun(filename, **kwargs).final_structure
3221-
elif fnmatch(fname.lower(), "*.cssr*"):
3222-
return cls.from_str(
3223-
contents,
3224-
fmt="cssr",
3225-
primitive=primitive,
3226-
sort=sort,
3227-
merge_tol=merge_tol,
3228-
**kwargs,
3229-
)
3230-
elif fnmatch(fname, "*.json*") or fnmatch(fname, "*.mson*"):
3231-
return cls.from_str(
3232-
contents,
3233-
fmt="json",
3234-
primitive=primitive,
3235-
sort=sort,
3236-
merge_tol=merge_tol,
3237-
**kwargs,
3238-
)
3239-
elif fnmatch(fname, "*.yaml*") or fnmatch(fname, "*.yml*"):
3240-
return cls.from_str(
3241-
contents,
3242-
fmt="yaml",
3243-
primitive=primitive,
3244-
sort=sort,
3245-
merge_tol=merge_tol,
3246-
**kwargs,
3247-
)
3248-
elif fnmatch(fname, "*.xsf"):
3249-
return cls.from_str(
3250-
contents,
3251-
fmt="xsf",
3252-
primitive=primitive,
3253-
sort=sort,
3254-
merge_tol=merge_tol,
3255-
**kwargs,
3256-
)
3257-
elif fnmatch(fname, "input*.xml"):
3258-
from pymatgen.io.exciting import ExcitingInput
3259-
3260-
return ExcitingInput.from_file(fname, **kwargs).structure
3261-
elif fnmatch(fname, "*rndstr.in*") or fnmatch(fname, "*lat.in*") or fnmatch(fname, "*bestsqs*"):
3262-
return cls.from_str(
3263-
contents,
3264-
fmt="mcsqs",
3265-
primitive=primitive,
3266-
sort=sort,
3267-
merge_tol=merge_tol,
3268-
**kwargs,
3269-
)
3270-
elif fnmatch(fname, "CTRL*"):
3271-
from pymatgen.io.lmto import LMTOCtrl
3272-
3273-
return LMTOCtrl.from_file(filename=filename, **kwargs).structure
3274-
elif fnmatch(fname, "geometry.in*"):
3275-
return cls.from_str(
3276-
contents,
3277-
fmt="aims",
3278-
primitive=primitive,
3279-
sort=sort,
3280-
merge_tol=merge_tol,
3281-
**kwargs,
3282-
)
3283-
elif fnmatch(fname, "inp*.xml") or fnmatch(fname, "*.in*") or fnmatch(fname, "inp_*"):
3284-
from pymatgen.io.fleur import FleurInput
3213+
elif fnmatch(fname, "CHGCAR*") or fnmatch(fname, "LOCPOT*"):
3214+
from pymatgen.io.vasp import Chgcar
3215+
3216+
struct = Chgcar.from_file(filename, **kwargs).structure
3217+
elif fnmatch(fname, "vasprun*.xml*"):
3218+
from pymatgen.io.vasp import Vasprun
3219+
3220+
struct = Vasprun(filename, **kwargs).final_structure
3221+
elif fnmatch(fname.lower(), "*.cssr*"):
3222+
return cls.from_str(
3223+
contents,
3224+
fmt="cssr",
3225+
primitive=primitive,
3226+
sort=sort,
3227+
merge_tol=merge_tol,
3228+
**kwargs,
3229+
)
3230+
elif fnmatch(fname, "*.json*") or fnmatch(fname, "*.mson*"):
3231+
return cls.from_str(
3232+
contents,
3233+
fmt="json",
3234+
primitive=primitive,
3235+
sort=sort,
3236+
merge_tol=merge_tol,
3237+
**kwargs,
3238+
)
3239+
elif fnmatch(fname, "*.yaml*") or fnmatch(fname, "*.yml*"):
3240+
return cls.from_str(
3241+
contents,
3242+
fmt="yaml",
3243+
primitive=primitive,
3244+
sort=sort,
3245+
merge_tol=merge_tol,
3246+
**kwargs,
3247+
)
3248+
elif fnmatch(fname, "*.xsf"):
3249+
return cls.from_str(
3250+
contents,
3251+
fmt="xsf",
3252+
primitive=primitive,
3253+
sort=sort,
3254+
merge_tol=merge_tol,
3255+
**kwargs,
3256+
)
3257+
elif fnmatch(fname, "input*.xml"):
3258+
from pymatgen.io.exciting import ExcitingInput
3259+
3260+
return ExcitingInput.from_file(fname, **kwargs).structure
3261+
elif fnmatch(fname, "*rndstr.in*") or fnmatch(fname, "*lat.in*") or fnmatch(fname, "*bestsqs*"):
3262+
return cls.from_str(
3263+
contents,
3264+
fmt="mcsqs",
3265+
primitive=primitive,
3266+
sort=sort,
3267+
merge_tol=merge_tol,
3268+
**kwargs,
3269+
)
3270+
elif fnmatch(fname, "CTRL*"):
3271+
from pymatgen.io.lmto import LMTOCtrl
3272+
3273+
return LMTOCtrl.from_file(filename=filename, **kwargs).structure
3274+
elif fnmatch(fname, "geometry.in*"):
3275+
return cls.from_str(
3276+
contents,
3277+
fmt="aims",
3278+
primitive=primitive,
3279+
sort=sort,
3280+
merge_tol=merge_tol,
3281+
**kwargs,
3282+
)
3283+
elif fnmatch(fname, "inp*.xml") or fnmatch(fname, "*.in*") or fnmatch(fname, "inp_*"):
3284+
from pymatgen.io.fleur import FleurInput
32853285

3286-
struct = FleurInput.from_file(filename, **kwargs).structure
3287-
elif fnmatch(fname, "*.res"):
3288-
from pymatgen.io.res import ResIO
3286+
struct = FleurInput.from_file(filename, **kwargs).structure
3287+
elif fnmatch(fname, "*.res"):
3288+
from pymatgen.io.res import ResIO
32893289

3290-
struct = ResIO.structure_from_file(filename, **kwargs)
3291-
elif fnmatch(fname.lower(), "*.config*") or fnmatch(fname.lower(), "*.pwmat*"):
3292-
from pymatgen.io.pwmat import AtomConfig
3290+
struct = ResIO.structure_from_file(filename, **kwargs)
3291+
elif fnmatch(fname.lower(), "*.config*") or fnmatch(fname.lower(), "*.pwmat*"):
3292+
from pymatgen.io.pwmat import AtomConfig
32933293

3294-
struct = AtomConfig.from_file(filename, **kwargs).structure
3295-
else:
3296-
raise ValueError(f"Unrecognized extension in {filename=}")
3294+
struct = AtomConfig.from_file(filename, **kwargs).structure
3295+
else:
3296+
raise ValueError(f"Unrecognized extension in {filename=}")
32973297
if sort:
32983298
struct = struct.get_sorted_structure()
32993299
if merge_tol:

0 commit comments

Comments
 (0)