Skip to content

Commit 67b5f7a

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 58552d2 commit 67b5f7a

File tree

14 files changed

+117
-134
lines changed

14 files changed

+117
-134
lines changed

structuretoolkit/analyse/distance.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
from typing import Optional
2-
31
import numpy as np
42
from ase.atoms import Atoms
53

64

75
def get_distances_array(
86
structure: Atoms,
9-
p1: Optional[np.ndarray] = None,
10-
p2: Optional[np.ndarray] = None,
7+
p1: np.ndarray | None = None,
8+
p2: np.ndarray | None = None,
119
mic: bool = True,
1210
vectors: bool = False,
1311
) -> np.ndarray:

structuretoolkit/analyse/dscribe.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
from typing import Optional
2-
31
import numpy as np
42
from ase.atoms import Atoms
53

64

75
def soap_descriptor_per_atom(
86
structure: Atoms,
9-
r_cut: Optional[float] = None,
10-
n_max: Optional[int] = None,
11-
l_max: Optional[int] = None,
12-
sigma: Optional[float] = 1.0,
7+
r_cut: float | None = None,
8+
n_max: int | None = None,
9+
l_max: int | None = None,
10+
sigma: float | None = 1.0,
1311
rbf: str = "gto",
14-
weighting: Optional[np.ndarray] = None,
12+
weighting: np.ndarray | None = None,
1513
average: str = "off",
1614
compression: dict = None,
17-
species: Optional[list] = None,
15+
species: list | None = None,
1816
periodic: bool = True,
1917
sparse: bool = False,
2018
dtype: str = "float64",
21-
centers: Optional[np.ndarray] = None,
19+
centers: np.ndarray | None = None,
2220
n_jobs: int = 1,
2321
only_physical_cores: bool = False,
2422
verbose: bool = False,

structuretoolkit/analyse/neighbors.py

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import itertools
55
import warnings
6-
from typing import Optional, Union
76

87
import numpy as np
98
from ase.atoms import Atoms
@@ -149,8 +148,8 @@ def copy(self) -> "Tree":
149148
def _reshape(
150149
self,
151150
value: np.ndarray,
152-
key: Optional[str] = None,
153-
ref_vector: Optional[np.ndarray] = None,
151+
key: str | None = None,
152+
ref_vector: np.ndarray | None = None,
154153
) -> np.ndarray:
155154
"""
156155
Reshape the given value based on the specified key and reference vector.
@@ -258,7 +257,7 @@ def norm_order(self, value: int) -> None:
258257
+ " with the correct norm_order value"
259258
)
260259

261-
def _get_max_length(self, ref_vector: Optional[np.ndarray] = None) -> int:
260+
def _get_max_length(self, ref_vector: np.ndarray | None = None) -> int:
262261
"""
263262
Get the maximum length of the reference vector.
264263
@@ -279,7 +278,7 @@ def _get_max_length(self, ref_vector: Optional[np.ndarray] = None) -> int:
279278
return max(len(dd[dd < np.inf]) for dd in ref_vector)
280279

281280
def _contract(
282-
self, value: np.ndarray, ref_vector: Optional[np.ndarray] = None
281+
self, value: np.ndarray, ref_vector: np.ndarray | None = None
283282
) -> np.ndarray:
284283
"""
285284
Contract the given value based on the specified reference vector.
@@ -362,7 +361,7 @@ def _get_wrapped_positions(
362361
def _get_distances_and_indices(
363362
self,
364363
positions: np.ndarray,
365-
num_neighbors: Optional[int] = None,
364+
num_neighbors: int | None = None,
366365
cutoff_radius: float = np.inf,
367366
width_buffer: float = 1.2,
368367
) -> tuple[np.ndarray, np.ndarray]:
@@ -431,10 +430,10 @@ def numbers_of_neighbors(self) -> int:
431430
def _get_vectors(
432431
self,
433432
positions: np.ndarray,
434-
num_neighbors: Optional[int] = None,
433+
num_neighbors: int | None = None,
435434
cutoff_radius: float = np.inf,
436-
distances: Optional[np.ndarray] = None,
437-
indices: Optional[np.ndarray] = None,
435+
distances: np.ndarray | None = None,
436+
indices: np.ndarray | None = None,
438437
width_buffer: float = 1.2,
439438
) -> np.ndarray:
440439
"""
@@ -470,7 +469,7 @@ def _get_vectors(
470469

471470
def _estimate_num_neighbors(
472471
self,
473-
num_neighbors: Optional[int] = None,
472+
num_neighbors: int | None = None,
474473
cutoff_radius: float = np.inf,
475474
width_buffer: float = 1.2,
476475
) -> int:
@@ -515,7 +514,7 @@ def _estimate_num_neighbors(
515514

516515
def _estimate_width(
517516
self,
518-
num_neighbors: Optional[int] = None,
517+
num_neighbors: int | None = None,
519518
cutoff_radius: float = np.inf,
520519
width_buffer: float = 1.2,
521520
) -> float:
@@ -551,7 +550,7 @@ def _estimate_width(
551550
def get_neighborhood(
552551
self,
553552
positions: np.ndarray,
554-
num_neighbors: Optional[int] = None,
553+
num_neighbors: int | None = None,
555554
cutoff_radius: float = np.inf,
556555
width_buffer: float = 1.2,
557556
) -> "Tree":
@@ -647,7 +646,7 @@ def get_spherical_harmonics(
647646
l: np.ndarray,
648647
m: np.ndarray,
649648
cutoff_radius: float = np.inf,
650-
rotation: Optional[np.ndarray] = None,
649+
rotation: np.ndarray | None = None,
651650
) -> np.ndarray:
652651
"""
653652
Args:
@@ -868,8 +867,8 @@ def shells(self) -> np.ndarray:
868867

869868
def get_local_shells(
870869
self,
871-
mode: Optional[str] = None,
872-
tolerance: Optional[int] = None,
870+
mode: str | None = None,
871+
tolerance: int | None = None,
873872
cluster_by_distances: bool = False,
874873
cluster_by_vecs: bool = False,
875874
) -> np.ndarray:
@@ -947,8 +946,8 @@ def get_local_shells(
947946

948947
def get_global_shells(
949948
self,
950-
mode: Optional[str] = None,
951-
tolerance: Optional[int] = None,
949+
mode: str | None = None,
950+
tolerance: int | None = None,
952951
cluster_by_distances: bool = False,
953952
cluster_by_vecs: bool = False,
954953
) -> np.ndarray:
@@ -1008,7 +1007,7 @@ def get_global_shells(
10081007

10091008
def get_shell_matrix(
10101009
self,
1011-
chemical_pair: Optional[list[str]] = None,
1010+
chemical_pair: list[str] | None = None,
10121011
cluster_by_distances: bool = False,
10131012
cluster_by_vecs: bool = False,
10141013
):
@@ -1107,8 +1106,8 @@ def find_neighbors_by_vector(
11071106

11081107
def cluster_by_vecs(
11091108
self,
1110-
distance_threshold: Optional[float] = None,
1111-
n_clusters: Optional[int] = None,
1109+
distance_threshold: float | None = None,
1110+
n_clusters: int | None = None,
11121111
linkage: str = "complete",
11131112
metric: str = "euclidean",
11141113
):
@@ -1152,8 +1151,8 @@ def cluster_by_vecs(
11521151

11531152
def cluster_by_distances(
11541153
self,
1155-
distance_threshold: Optional[float] = None,
1156-
n_clusters: Optional[int] = None,
1154+
distance_threshold: float | None = None,
1155+
n_clusters: int | None = None,
11571156
linkage: str = "complete",
11581157
metric: str = "euclidean",
11591158
use_vecs: bool = False,
@@ -1225,7 +1224,7 @@ def reset_clusters(self, vecs: bool = True, distances: bool = True):
12251224

12261225
def cluster_analysis(
12271226
self, id_list: list, return_cluster_sizes: bool = False
1228-
) -> Union[dict[int, list[int]], tuple[dict[int, list[int]], list[int]]]:
1227+
) -> dict[int, list[int]] | tuple[dict[int, list[int]], list[int]]:
12291228
"""
12301229
Perform cluster analysis on a list of atom IDs.
12311230
@@ -1283,7 +1282,7 @@ def __probe_cluster(
12831282
def get_bonds(
12841283
self,
12851284
radius: float = np.inf,
1286-
max_shells: Optional[int] = None,
1285+
max_shells: int | None = None,
12871286
prec: float = 0.1,
12881287
) -> list[dict[str, list[list[int]]]]:
12891288
"""
@@ -1361,7 +1360,7 @@ def get_neighbors(
13611360
structure: Atoms,
13621361
num_neighbors: int = 12,
13631362
tolerance: int = 2,
1364-
id_list: Optional[list] = None,
1363+
id_list: list | None = None,
13651364
cutoff_radius: float = np.inf,
13661365
width_buffer: float = 1.2,
13671366
mode: str = "filled",
@@ -1400,12 +1399,12 @@ def _get_neighbors(
14001399
structure: Atoms,
14011400
num_neighbors: int = 12,
14021401
tolerance: int = 2,
1403-
id_list: Optional[list] = None,
1402+
id_list: list | None = None,
14041403
cutoff_radius: float = np.inf,
14051404
width_buffer: float = 1.2,
14061405
get_tree: bool = False,
14071406
norm_order: int = 2,
1408-
) -> Union[Neighbors, Tree]:
1407+
) -> Neighbors | Tree:
14091408
"""
14101409
Get the neighbors of atoms in a structure.
14111410

structuretoolkit/analyse/pyscal.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department
22
# Distributed under the terms of "New BSD License", see the LICENSE file.
33

4-
from typing import Any, Optional, Union
4+
from typing import Any
55

66
import numpy as np
77
from ase.atoms import Atoms
@@ -24,10 +24,10 @@ def get_steinhardt_parameters(
2424
structure: Atoms,
2525
neighbor_method: str = "cutoff",
2626
cutoff: float = 0.0,
27-
n_clusters: Optional[int] = 2,
28-
q: Optional[tuple] = None,
27+
n_clusters: int | None = 2,
28+
q: tuple | None = None,
2929
averaged: bool = False,
30-
) -> Union[tuple[np.ndarray], tuple[np.ndarray, np.ndarray]]:
30+
) -> tuple[np.ndarray] | tuple[np.ndarray, np.ndarray]:
3131
"""
3232
Calculate Steinhardts parameters
3333
@@ -80,7 +80,7 @@ def get_centro_symmetry_descriptors(
8080

8181
def get_diamond_structure_descriptors(
8282
structure: Atoms, mode: str = "total", ovito_compatibility: bool = False
83-
) -> Union[dict[str, int], np.ndarray]:
83+
) -> dict[str, int] | np.ndarray:
8484
"""
8585
Analyse diamond structure
8686
@@ -244,7 +244,7 @@ def find_solids(
244244
q: int = 6,
245245
right: bool = True,
246246
return_sys: bool = False,
247-
) -> Union[int, Any]:
247+
) -> int | Any:
248248
"""
249249
Get the number of solids or the corresponding pyscal system.
250250
Calls necessary pyscal methods as described in https://pyscal.org/en/latest/methods/03_solidliquid.html.

structuretoolkit/analyse/snap.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from ctypes import POINTER, c_double, c_int, cast
2-
from typing import Optional, Union
32

43
import numpy as np
54
from ase.atoms import Atoms
@@ -70,7 +69,7 @@ def get_snap_descriptors_per_atom(
7069
rmin0: float = 0.0,
7170
bzeroflag: bool = False,
7271
quadraticflag: bool = False,
73-
weights: Optional[Union[list, np.ndarray]] = None,
72+
weights: list | np.ndarray | None = None,
7473
cutoff: float = 10.0,
7574
) -> np.ndarray:
7675
"""
@@ -121,7 +120,7 @@ def get_snap_descriptor_derivatives(
121120
rmin0: float = 0.0,
122121
bzeroflag: bool = False,
123122
quadraticflag: bool = False,
124-
weights: Optional[Union[list, np.ndarray]] = None,
123+
weights: list | np.ndarray | None = None,
125124
cutoff: float = 10.0,
126125
):
127126
"""
@@ -659,7 +658,7 @@ def _get_default_parameters(
659658
rmin0: float = 0.0,
660659
bzeroflag: bool = False,
661660
quadraticflag: bool = False,
662-
weights: Optional[Union[list, np.ndarray]] = None,
661+
weights: list | np.ndarray | None = None,
663662
cutoff: float = 10.0,
664663
):
665664
"""

structuretoolkit/analyse/spatial.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department
22
# Distributed under the terms of "New BSD License", see the LICENSE file.
33

4-
from typing import Callable, Optional
4+
from collections.abc import Callable
55

66
import numpy as np
77
from ase.atoms import Atoms
@@ -225,7 +225,7 @@ def __init__(
225225
l_values: np.ndarray = np.arange(2, 13),
226226
q_eps: float = 0.3,
227227
var_ratio: float = 5.0,
228-
min_samples: Optional[int] = None,
228+
min_samples: int | None = None,
229229
neigh_args: dict = None,
230230
**kwargs,
231231
):
@@ -294,7 +294,7 @@ def __init__(
294294
self.structure = structure
295295

296296
def run_workflow(
297-
self, positions: Optional[np.ndarray] = None, steps: int = -1
297+
self, positions: np.ndarray | None = None, steps: int = -1
298298
) -> np.ndarray:
299299
"""
300300
Run the workflow to obtain the interstitial positions.
@@ -407,7 +407,7 @@ def get_interstitials(
407407
l_values: np.ndarray = np.arange(2, 13),
408408
q_eps: float = 0.3,
409409
var_ratio: float = 5.0,
410-
min_samples: Optional[int] = None,
410+
min_samples: int | None = None,
411411
neigh_args: dict = None,
412412
**kwargs,
413413
) -> Interstitials:
@@ -457,7 +457,7 @@ def get_interstitials(
457457
def get_layers(
458458
structure: Atoms,
459459
distance_threshold: float = 0.01,
460-
id_list: Optional[list[int]] = None,
460+
id_list: list[int] | None = None,
461461
wrap_atoms: bool = True,
462462
planes: np.ndarray = None,
463463
cluster_method: str = None,
@@ -690,9 +690,9 @@ def get_delaunay_neighbors(structure: Atoms, width_buffer: float = 10.0) -> np.n
690690

691691
def get_cluster_positions(
692692
structure: Atoms,
693-
positions: Optional[np.ndarray] = None,
693+
positions: np.ndarray | None = None,
694694
eps: float = 1.0,
695-
buffer_width: Optional[float] = None,
695+
buffer_width: float | None = None,
696696
return_labels: bool = False,
697697
) -> np.ndarray:
698698
"""

0 commit comments

Comments
 (0)