11"""Running interaction calculations."""
2- from typing import TYPE_CHECKING , Any , Callable , Dict , Iterable , Mapping , Optional , Tuple , Union
2+ from typing import TYPE_CHECKING , Any
3+ from collections .abc import Callable , Iterable , Mapping
34from abc import ABC , abstractmethod
45from collections import defaultdict
56from functools import partial
2021
2122def _pair_msas (
2223 msa1 : MSA ,
23- msa2 : Optional [ MSA ] = None ,
24+ msa2 : MSA | None = None ,
2425 max_gap_fraction : float = 1. ,
2526 blocked : bool = False ,
26- interaction_map : Optional [ Union [ str , Mapping [str , Iterable [str ]]]] = None ,
27+ interaction_map : str | Mapping [str , Iterable [str ]] | None = None ,
2728 enforce_ref_match : bool = False
2829) -> PairedMSA :
2930 try :
@@ -51,7 +52,7 @@ def _calculate_interaction_blocks(
5152 use_sequences : bool = False ,
5253 use_id : bool = False ,
5354 ** kwargs
54- ) -> Tuple [ndarray , dict ]:
55+ ) -> tuple [ndarray , dict ]:
5556
5657 import numpy as np
5758 from tqdm .auto import tqdm
@@ -68,7 +69,7 @@ def _calculate_interaction_blocks(
6869 print_err (f"[INFO] Splitting MSA with { n_msa_columns } columns into pairs of { chunksize } -column chunks." )
6970 chunks = np .split (token_ids , list (range (chunksize , n_msa_columns , chunksize )), axis = - 1 )
7071 n_chunks = len (chunks )
71- n_blocks = n_chunks * (n_chunks - 1 ) // 2
72+ n_blocks = int ( n_chunks * (n_chunks + 1 ) / 2 )
7273 print_err (f"[INFO] Split MSA with { n_msa_columns } columns into { n_chunks } x { chunksize } -column chunks ({ n_blocks } blocks)." )
7374
7475 result = np .zeros (
@@ -147,30 +148,30 @@ def make_model(cpu=False, **kwargs):
147148 @abstractmethod
148149 def _run_chunk (
149150 paired_msa : PairedMSA ,
150- model : Optional [ Callable ] = None ,
151+ model : Callable | None = None ,
151152 ** kwargs
152153 ) -> Iterable [ArrayLike ]:
153154 ...
154155
155156 @staticmethod
156157 def post_run (
157158 paired_msa : PairedMSA ,
158- results : Dict [ Tuple , Any ],
159+ results : dict [ tuple , Any ],
159160 ** kwargs
160161 ) -> dict :
161162 return {}
162163
163164 def run (
164165 self ,
165166 msa1 : MSA ,
166- msa2 : Optional [ MSA ] = None ,
167+ msa2 : MSA | None = None ,
167168 max_gap_fraction : float = .9 ,
168- interaction_map : Optional [ Union [ str , Mapping [str , Iterable [str ]]]] = None ,
169+ interaction_map : str | Mapping [str , Iterable [str ]] | None = None ,
169170 cpu : bool = False ,
170- model : Optional [ Callable ] = None ,
171+ model : Callable | None = None ,
171172 chunksize : int = DEFAULT_CHUNKSIZE ,
172173 enforce_ref_match : bool = False ,
173- model_kwargs : Optional [ dict ] = None ,
174+ model_kwargs : dict | None = None ,
174175 ** kwargs
175176 ):
176177 paired_msa = _pair_msas (
@@ -224,7 +225,7 @@ class AF2Runner(Runner):
224225 def make_model (
225226 cpu = False ,
226227 max_recycles : int = 10 ,
227- param_dir : Optional [ str ] = None ,
228+ param_dir : str | None = None ,
228229 ** kwargs
229230 ):
230231 from .af2 .modelling import make_model_runner
@@ -239,8 +240,8 @@ def _run_chunk(
239240 paired_msa : ArrayLike ,
240241 chain_a_length : int ,
241242 _id : str ,
242- model : Optional [ Callable ] = None ,
243- seed : Optional [ int ] = None ,
243+ model : Callable | None = None ,
244+ seed : int | None = None ,
244245 ** kwargs
245246 ):
246247 from .af2 import run_af2
@@ -255,8 +256,8 @@ def _run_chunk(
255256 @staticmethod
256257 def post_run (
257258 paired_msa : PairedMSA ,
258- results : Dict [ Tuple , Any ],
259- seed : Optional [ int ] = None ,
259+ results : dict [ tuple , Any ],
260+ seed : int | None = None ,
260261 ** kwargs
261262 ):
262263 from .af2 import post_af2
@@ -271,7 +272,7 @@ class DCARunner(Runner):
271272 @staticmethod
272273 def _run_chunk (
273274 paired_msa : PairedMSA ,
274- model : Optional [ Callable ] = None ,
275+ model : Callable | None = None ,
275276 apc : bool = True ,
276277 ** kwargs
277278 ):
@@ -284,7 +285,7 @@ def _run_chunk(
284285 @staticmethod
285286 def post_run (
286287 paired_msa : PairedMSA ,
287- results : Dict [ Tuple , Any ],
288+ results : dict [ tuple , Any ],
288289 apc : bool = True ,
289290 ** kwargs
290291 ):
@@ -311,7 +312,7 @@ def make_model(cpu=False, **kwargs):
311312 def _run_chunk (
312313 paired_msa : PairedMSA ,
313314 chain_a_length : int ,
314- model : Optional [ Callable ] = None ,
315+ model : Callable | None = None ,
315316 ** kwargs
316317 ):
317318 result , cα_coords = model .predict (
0 commit comments