33
44import itertools
55import warnings
6- from typing import Optional , Union
76
87import numpy as np
98from 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
0 commit comments