2020
2121import h5py
2222import numpy as np
23+ import numpy .typing as npt
2324import scipy .linalg as la
2425from scipy .special import factorial
2526from fsc .export import export
@@ -96,7 +97,7 @@ def __init__(
9697 dim : ty .Optional [int ] = None ,
9798 occ : ty .Optional [int ] = None ,
9899 pos : ty .Optional [ty .Sequence [ty .Sequence [float ]]] = None ,
99- uc : ty .Optional [np . ndarray ] = None ,
100+ uc : ty .Optional [npt . ArrayLike ] = None ,
100101 contains_cc : bool = True ,
101102 cc_check_tolerance : float = 1e-12 ,
102103 sparse : bool = False ,
@@ -638,14 +639,14 @@ def from_wannier_files( # pylint: disable=too-many-locals
638639 atom_pos_cartesian = np .array ([a .pos for a in atom_list_cartesian ])
639640 if pos_kind == "wannier" :
640641 pos_cartesian : ty .Union [
641- ty .List [np .ndarray ], np .ndarray
642+ ty .List [npt . NDArray [ np .float_ ]], npt . NDArray [ np .float_ ]
642643 ] = wannier_pos_cartesian
643644 elif pos_kind == "nearest_atom" :
644645 if distance_ratio_threshold < 1 :
645646 raise ValueError (
646647 "Invalid value for 'distance_ratio_threshold': must be >= 1."
647648 )
648- pos_cartesian = ty .cast (ty .List [np .ndarray ], [])
649+ pos_cartesian = ty .cast (ty .List [npt . NDArray [ np .float_ ] ], [])
649650 for p in wannier_pos_cartesian :
650651 p_reduced = la .solve (kwargs ["uc" ].T , np .array (p ).T ).T
651652 T_base = np .floor (p_reduced )
@@ -1079,7 +1080,7 @@ def hamilton(
10791080 self ,
10801081 k : ty .Union [ty .Sequence [float ], ty .Sequence [ty .Sequence [float ]]],
10811082 convention : int = 2 ,
1082- ) -> np .ndarray :
1083+ ) -> npt . NDArray [ np .complex_ ] :
10831084 """
10841085 Calculates the Hamilton matrix for a given k-point or list of
10851086 k-points.
@@ -1130,12 +1131,12 @@ def hamilton(
11301131 H = pos_exponential .conjugate ().transpose ((0 , 2 , 1 )) * H * pos_exponential
11311132
11321133 if single_point :
1133- return ty .cast (np .ndarray , H [0 ])
1134+ return ty .cast (npt . NDArray [ np .complex_ ] , H [0 ])
11341135 return H
11351136
11361137 def eigenval (
11371138 self , k : ty .Union [ty .Sequence [float ], ty .Sequence [ty .Sequence [float ]]]
1138- ) -> ty .Union [np .ndarray , ty .List [np .ndarray ]]:
1139+ ) -> ty .Union [npt . NDArray [ np .float_ ] , ty .List [npt . NDArray [ np .float_ ] ]]:
11391140 """
11401141 Returns the eigenvalues at a given k point, or list of k-points.
11411142
@@ -1149,7 +1150,7 @@ def eigenval(
11491150 hamiltonians = self .hamilton (k )
11501151 if hamiltonians .ndim == 3 :
11511152 return [la .eigvalsh (ham ) for ham in hamiltonians ]
1152- return ty .cast (np .ndarray , la .eigvalsh (hamiltonians ))
1153+ return ty .cast (npt . NDArray [ np .float_ ] , la .eigvalsh (hamiltonians ))
11531154
11541155 # -------------------MODIFYING THE MODEL ----------------------------#
11551156 def add_hop (
@@ -1442,12 +1443,12 @@ def _apply_operation( # pylint: disable=too-many-locals
14421443 ty .Tuple [int , ...], ty .Tuple [ty .List [int ], ty .List [int ]]
14431444 ] = co .defaultdict (lambda : ([], []))
14441445 for (i , Ti ), (j , Tj ) in itertools .product (enumerate (uc_shift ), repeat = 2 ):
1445- shift = tuple (np .array (Tj ) - np .array (Ti ))
1446+ shift_tuple = tuple (np .array (Tj ) - np .array (Ti ))
14461447 for idx1 , idx2 in itertools .product (
14471448 sublattices [i ].indices , sublattices [j ].indices
14481449 ):
1449- hop_shifts_idx [shift ][0 ].append (idx1 )
1450- hop_shifts_idx [shift ][1 ].append (idx2 )
1450+ hop_shifts_idx [shift_tuple ][0 ].append (idx1 )
1451+ hop_shifts_idx [shift_tuple ][1 ].append (idx2 )
14511452
14521453 # create hoppings with shifted R (by uc_shift[j] - uc_shift[i])
14531454 new_hop : HoppingType = co .defaultdict (self ._empty_matrix )
@@ -1456,8 +1457,8 @@ def _apply_operation( # pylint: disable=too-many-locals
14561457 np .rint (np .dot (symmetry_operation .rotation_matrix , R )),
14571458 dtype = int ,
14581459 )
1459- for shift , (idx1 , idx2 ) in hop_shifts_idx .items ():
1460- new_R = tuple (np .array (R_transformed ) + np .array (shift ))
1460+ for shift_tuple , (idx1 , idx2 ) in hop_shifts_idx .items ():
1461+ new_R = tuple (np .array (R_transformed ) + np .array (shift_tuple ))
14611462 new_hop [new_R ][idx1 , idx2 ] += mat [idx1 , idx2 ]
14621463
14631464 # apply D(g) ... D(g)^-1 (since D(g) is unitary: D(g)^-1 == D(g)^H)
@@ -1592,7 +1593,7 @@ def change_unit_cell( # pylint: disable=too-many-branches
15921593 )
15931594 # convert to reduced coordinates
15941595 if uc is None :
1595- new_uc : ty .Optional [np .ndarray ] = self .uc
1596+ new_uc : ty .Optional [npt . NDArray [ np .float_ ] ] = self .uc
15961597 uc_reduced = np .eye (self .dim )
15971598 else :
15981599 new_uc = np .array (uc )
@@ -1668,7 +1669,7 @@ def supercell( # pylint: disable=too-many-locals
16681669 new_uc = (self .uc .T * size_array ).T
16691670
16701671 # the new positions, normalized to the supercell
1671- new_pos : ty .List [np .ndarray ] = []
1672+ new_pos : ty .List [npt . NDArray [ np .float_ ] ] = []
16721673 reduced_pos = np .array ([p / size_array for p in self .pos ])
16731674 uc_offsets = list (
16741675 np .array (offset )
0 commit comments