66import sys
77from functools import partial
88from pathlib import Path
9- from typing import Any , Iterator , List , Optional , Protocol , Set , Tuple , Union
9+ from typing import Any , Iterator , Protocol
1010
1111import numpy as np
1212from numpy import ndarray
@@ -426,7 +426,7 @@ def rmsd(P: ndarray, Q: ndarray, **kwargs) -> float:
426426def kabsch_rmsd (
427427 P : ndarray ,
428428 Q : ndarray ,
429- W : Optional [ ndarray ] = None ,
429+ W : ndarray | None = None ,
430430 translate : bool = False ,
431431 ** kwargs : Any ,
432432) -> float :
@@ -487,7 +487,7 @@ def kabsch_rotate(P: ndarray, Q: ndarray) -> ndarray:
487487 return P
488488
489489
490- def kabsch_fit (P : ndarray , Q : ndarray , W : Optional [ ndarray ] = None ) -> ndarray :
490+ def kabsch_fit (P : ndarray , Q : ndarray , W : ndarray | None = None ) -> ndarray :
491491 """
492492 Rotate and translate matrix P unto matrix Q using Kabsch algorithm.
493493 An optional vector of weights W may be provided.
@@ -565,8 +565,8 @@ def kabsch(P: ndarray, Q: ndarray) -> ndarray:
565565
566566
567567def kabsch_weighted (
568- P : ndarray , Q : ndarray , W : Optional [ ndarray ] = None
569- ) -> Tuple [ndarray , ndarray , float ]:
568+ P : ndarray , Q : ndarray , W : ndarray | None = None
569+ ) -> tuple [ndarray , ndarray , float ]:
570570 """
571571 Using the Kabsch algorithm with two sets of paired point P and Q.
572572 Each vector set is represented as an NxD matrix, where D is the
@@ -651,9 +651,9 @@ def kabsch_weighted(
651651def kabsch_weighted_fit (
652652 P : ndarray ,
653653 Q : ndarray ,
654- W : Optional [ ndarray ] = None ,
654+ W : ndarray | None = None ,
655655 return_rmsd : bool = False ,
656- ) -> Tuple [ndarray , Optional [ float ] ]:
656+ ) -> tuple [ndarray , float | None ]:
657657 """
658658 Fit P to Q with optional weights W.
659659 Also returns the RMSD of the fit if return_rmsd=True.
@@ -685,7 +685,7 @@ def kabsch_weighted_fit(
685685 return (PNEW , None )
686686
687687
688- def kabsch_weighted_rmsd (P : ndarray , Q : ndarray , W : Optional [ ndarray ] = None ) -> float :
688+ def kabsch_weighted_rmsd (P : ndarray , Q : ndarray , W : ndarray | None = None ) -> float :
689689 """
690690 Calculate the RMSD between P and Q with optional weights W
691691
@@ -1112,7 +1112,7 @@ def reorder_inertia_hungarian(
11121112 return best_review
11131113
11141114
1115- def generate_permutations (elements : List [int ], n : int ) -> Iterator [List [int ]]:
1115+ def generate_permutations (elements : list [int ], n : int ) -> Iterator [list [int ]]:
11161116 """
11171117 Heap's algorithm for generating all n! permutations in a list
11181118 https://en.wikipedia.org/wiki/Heap%27s_algorithm
@@ -1235,10 +1235,10 @@ def check_reflections(
12351235 q_atoms : ndarray ,
12361236 p_coord : ndarray ,
12371237 q_coord : ndarray ,
1238- reorder_method : Optional [ ReorderCallable ] = None ,
1238+ reorder_method : ReorderCallable | None = None ,
12391239 rmsd_method : RmsdCallable = kabsch_rmsd ,
12401240 keep_stereo : bool = False ,
1241- ) -> Tuple [float , ndarray , ndarray , ndarray ]:
1241+ ) -> tuple [float , ndarray , ndarray , ndarray ]:
12421242 """
12431243 Minimize RMSD using reflection planes for molecule P and Q
12441244
@@ -1361,7 +1361,7 @@ def get_cm(atoms: ndarray, V: ndarray) -> ndarray:
13611361 The CM vector
13621362 """
13631363
1364- weights : Union [ List [ float ], ndarray ] = [ELEMENT_WEIGHTS [x ] for x in atoms ]
1364+ weights : list [ float ] | ndarray = [ELEMENT_WEIGHTS [x ] for x in atoms ]
13651365 weights = np .asarray (weights )
13661366 center_of_mass : ndarray = np .average (V , axis = 0 , weights = weights )
13671367
@@ -1483,7 +1483,7 @@ def set_coordinates(
14831483
14841484def get_coordinates (
14851485 filename : Path , fmt : str , is_gzip : bool = False , return_atoms_as_int : bool = False
1486- ) -> Tuple [ndarray , ndarray ]:
1486+ ) -> tuple [ndarray , ndarray ]:
14871487 """
14881488 Get coordinates from filename in format fmt. Supports XYZ and PDB.
14891489 Parameters
@@ -1529,7 +1529,7 @@ def _parse_pdb_alphacarbon_line(line: str) -> bool:
15291529 return False
15301530
15311531
1532- def _parse_pdb_atom_line (line : str ) -> Optional [ str ] :
1532+ def _parse_pdb_atom_line (line : str ) -> str | None :
15331533 """
15341534 Will try it best to find atom from an atom-line. The standard of PDB
15351535 *should* be column based, however, there are many examples of non-standard
@@ -1622,7 +1622,7 @@ def _parse_pdb_atom_line(line: str) -> Optional[str]:
16221622 return None
16231623
16241624
1625- def _parse_pdb_coord_line (line : str ) -> Optional [ ndarray ] :
1625+ def _parse_pdb_coord_line (line : str ) -> ndarray | None :
16261626 """
16271627 Try my best to coordinates from a PDB ATOM or HETATOM line
16281628
@@ -1647,7 +1647,7 @@ def _parse_pdb_coord_line(line: str) -> Optional[ndarray]:
16471647
16481648 tokens = line .split ()
16491649
1650- x_column : Optional [ int ] = None
1650+ x_column : int | None = None
16511651
16521652 # look for x column
16531653 for i , x in enumerate (tokens ):
@@ -1673,7 +1673,7 @@ def get_coordinates_pdb(
16731673 is_gzip : bool = False ,
16741674 return_atoms_as_int : bool = False ,
16751675 only_alpha_carbon : bool = False ,
1676- ) -> Tuple [ndarray , ndarray ]:
1676+ ) -> tuple [ndarray , ndarray ]:
16771677 """
16781678 Get coordinates from the first chain in a pdb file
16791679 and return a vectorset with all the coordinates.
@@ -1698,15 +1698,15 @@ def get_coordinates_pdb(
16981698 # Since the format doesn't require a space between columns, we use the
16991699 # above column indices as a fallback.
17001700
1701- V : Union [ List [ ndarray ], ndarray ] = list ()
1701+ V : list [ ndarray ] | ndarray = list ()
17021702 assert isinstance (V , list )
17031703
17041704 # Same with atoms and atom naming.
17051705 # The most robust way to do this is probably
17061706 # to assume that the atomtype is given in column 3.
17071707
1708- atoms : List [str ] = list ()
1709- alpha_carbons : List [bool ] = list ()
1708+ atoms : list [str ] = list ()
1709+ alpha_carbons : list [bool ] = list ()
17101710 assert isinstance (atoms , list )
17111711 openfunc : Any
17121712
@@ -1766,11 +1766,11 @@ def get_coordinates_pdb(
17661766
17671767
17681768def get_coordinates_xyz_lines (
1769- lines : List [str ], return_atoms_as_int : bool = False
1770- ) -> Tuple [ndarray , ndarray ]:
1769+ lines : list [str ], return_atoms_as_int : bool = False
1770+ ) -> tuple [ndarray , ndarray ]:
17711771
1772- V : Union [ List [ ndarray ], ndarray ] = list ()
1773- atoms : Union [ List [ str ], ndarray ] = list ()
1772+ V : list [ ndarray ] | ndarray = list ()
1773+ atoms : list [ str ] | ndarray = list ()
17741774 n_atoms = 0
17751775
17761776 assert isinstance (V , list )
@@ -1837,7 +1837,7 @@ def get_coordinates_xyz(
18371837 filename : Path ,
18381838 is_gzip : bool = False ,
18391839 return_atoms_as_int : bool = False ,
1840- ) -> Tuple [ndarray , ndarray ]:
1840+ ) -> tuple [ndarray , ndarray ]:
18411841 """
18421842 Get coordinates from filename and return a vectorset with all the
18431843 coordinates, in XYZ format.
@@ -1872,7 +1872,7 @@ def get_coordinates_xyz(
18721872 return atoms , V
18731873
18741874
1875- def parse_arguments (arguments : Optional [ Union [ str , List [str ]]] = None ) -> argparse .Namespace :
1875+ def parse_arguments (arguments : str | list [str ] | None = None ) -> argparse .Namespace :
18761876
18771877 version_msg = f"""
18781878rmsd { __version__ }
@@ -2093,7 +2093,7 @@ def parse_arguments(arguments: Optional[Union[str, List[str]]] = None) -> argpar
20932093 return args
20942094
20952095
2096- def main (args : Optional [ List [ str ]] = None ) -> str :
2096+ def main (args : list [ str ] | None = None ) -> str :
20972097
20982098 # Parse arguments
20992099 settings = parse_arguments (args )
@@ -2149,11 +2149,11 @@ def main(args: Optional[List[str]] = None) -> str:
21492149 sys .exit ()
21502150
21512151 # Typing
2152- index : Union [ Set [ int ], List [int ], ndarray ]
2152+ index : set [ int ] | list [int ] | ndarray
21532153
21542154 # Set local view
2155- p_view : Optional [ ndarray ] = None
2156- q_view : Optional [ ndarray ] = None
2155+ p_view : ndarray | None = None
2156+ q_view : ndarray | None = None
21572157 use_view : bool = True
21582158
21592159 if settings .ignore_hydrogen :
@@ -2192,7 +2192,7 @@ def main(args: Optional[List[str]] = None) -> str:
21922192 q_coord_sub -= q_cent_sub
21932193
21942194 rmsd_method : RmsdCallable
2195- reorder_method : Optional [ ReorderCallable ]
2195+ reorder_method : ReorderCallable | None
21962196
21972197 # set rotation method
21982198 if settings .rotation == METHOD_KABSCH :
@@ -2216,7 +2216,7 @@ def main(args: Optional[List[str]] = None) -> str:
22162216 reorder_method = reorder_distance
22172217
22182218 # Save the resulting RMSD
2219- result_rmsd : Optional [ float ] = None
2219+ result_rmsd : float | None = None
22202220
22212221 # Collect changes to be done on q coords
22222222 q_swap = None
0 commit comments