pytme 0.2.9__cp311-cp311-macosx_15_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pytme-0.2.9.data/scripts/estimate_ram_usage.py +97 -0
- pytme-0.2.9.data/scripts/match_template.py +1135 -0
- pytme-0.2.9.data/scripts/postprocess.py +622 -0
- pytme-0.2.9.data/scripts/preprocess.py +209 -0
- pytme-0.2.9.data/scripts/preprocessor_gui.py +1227 -0
- pytme-0.2.9.dist-info/METADATA +95 -0
- pytme-0.2.9.dist-info/RECORD +119 -0
- pytme-0.2.9.dist-info/WHEEL +5 -0
- pytme-0.2.9.dist-info/entry_points.txt +6 -0
- pytme-0.2.9.dist-info/licenses/LICENSE +153 -0
- pytme-0.2.9.dist-info/top_level.txt +3 -0
- scripts/__init__.py +0 -0
- scripts/estimate_ram_usage.py +97 -0
- scripts/match_template.py +1135 -0
- scripts/postprocess.py +622 -0
- scripts/preprocess.py +209 -0
- scripts/preprocessor_gui.py +1227 -0
- tests/__init__.py +0 -0
- tests/data/Blurring/blob_width18.npy +0 -0
- tests/data/Blurring/edgegaussian_sigma3.npy +0 -0
- tests/data/Blurring/gaussian_sigma2.npy +0 -0
- tests/data/Blurring/hamming_width6.npy +0 -0
- tests/data/Blurring/kaiserb_width18.npy +0 -0
- tests/data/Blurring/localgaussian_sigma0510.npy +0 -0
- tests/data/Blurring/mean_size5.npy +0 -0
- tests/data/Blurring/ntree_sigma0510.npy +0 -0
- tests/data/Blurring/rank_rank3.npy +0 -0
- tests/data/Maps/.DS_Store +0 -0
- tests/data/Maps/emd_8621.mrc.gz +0 -0
- tests/data/README.md +2 -0
- tests/data/Raw/em_map.map +0 -0
- tests/data/Structures/.DS_Store +0 -0
- tests/data/Structures/1pdj.cif +3339 -0
- tests/data/Structures/1pdj.pdb +1429 -0
- tests/data/Structures/5khe.cif +3685 -0
- tests/data/Structures/5khe.ent +2210 -0
- tests/data/Structures/5khe.pdb +2210 -0
- tests/data/Structures/5uz4.cif +70548 -0
- tests/preprocessing/__init__.py +0 -0
- tests/preprocessing/test_compose.py +76 -0
- tests/preprocessing/test_frequency_filters.py +178 -0
- tests/preprocessing/test_preprocessor.py +136 -0
- tests/preprocessing/test_utils.py +79 -0
- tests/test_analyzer.py +216 -0
- tests/test_backends.py +446 -0
- tests/test_density.py +503 -0
- tests/test_extensions.py +130 -0
- tests/test_matching_cli.py +283 -0
- tests/test_matching_data.py +162 -0
- tests/test_matching_exhaustive.py +124 -0
- tests/test_matching_memory.py +30 -0
- tests/test_matching_optimization.py +226 -0
- tests/test_matching_utils.py +189 -0
- tests/test_orientations.py +175 -0
- tests/test_parser.py +33 -0
- tests/test_rotations.py +153 -0
- tests/test_structure.py +247 -0
- tme/__init__.py +6 -0
- tme/__version__.py +1 -0
- tme/analyzer/__init__.py +2 -0
- tme/analyzer/_utils.py +186 -0
- tme/analyzer/aggregation.py +577 -0
- tme/analyzer/peaks.py +953 -0
- tme/backends/__init__.py +171 -0
- tme/backends/_cupy_utils.py +734 -0
- tme/backends/_jax_utils.py +188 -0
- tme/backends/cupy_backend.py +294 -0
- tme/backends/jax_backend.py +314 -0
- tme/backends/matching_backend.py +1270 -0
- tme/backends/mlx_backend.py +241 -0
- tme/backends/npfftw_backend.py +583 -0
- tme/backends/pytorch_backend.py +430 -0
- tme/data/__init__.py +0 -0
- tme/data/c48n309.npy +0 -0
- tme/data/c48n527.npy +0 -0
- tme/data/c48n9.npy +0 -0
- tme/data/c48u1.npy +0 -0
- tme/data/c48u1153.npy +0 -0
- tme/data/c48u1201.npy +0 -0
- tme/data/c48u1641.npy +0 -0
- tme/data/c48u181.npy +0 -0
- tme/data/c48u2219.npy +0 -0
- tme/data/c48u27.npy +0 -0
- tme/data/c48u2947.npy +0 -0
- tme/data/c48u3733.npy +0 -0
- tme/data/c48u4749.npy +0 -0
- tme/data/c48u5879.npy +0 -0
- tme/data/c48u7111.npy +0 -0
- tme/data/c48u815.npy +0 -0
- tme/data/c48u83.npy +0 -0
- tme/data/c48u8649.npy +0 -0
- tme/data/c600v.npy +0 -0
- tme/data/c600vc.npy +0 -0
- tme/data/metadata.yaml +80 -0
- tme/data/quat_to_numpy.py +42 -0
- tme/data/scattering_factors.pickle +0 -0
- tme/density.py +2263 -0
- tme/extensions.cpython-311-darwin.so +0 -0
- tme/external/bindings.cpp +332 -0
- tme/filters/__init__.py +6 -0
- tme/filters/_utils.py +311 -0
- tme/filters/bandpass.py +230 -0
- tme/filters/compose.py +81 -0
- tme/filters/ctf.py +393 -0
- tme/filters/reconstruction.py +160 -0
- tme/filters/wedge.py +542 -0
- tme/filters/whitening.py +191 -0
- tme/matching_data.py +863 -0
- tme/matching_exhaustive.py +497 -0
- tme/matching_optimization.py +1311 -0
- tme/matching_scores.py +1183 -0
- tme/matching_utils.py +1188 -0
- tme/memory.py +337 -0
- tme/orientations.py +598 -0
- tme/parser.py +685 -0
- tme/preprocessor.py +1329 -0
- tme/rotations.py +350 -0
- tme/structure.py +1864 -0
- tme/types.py +13 -0
tme/memory.py
ADDED
@@ -0,0 +1,337 @@
|
|
1
|
+
""" Compute memory consumption of template matching components.
|
2
|
+
|
3
|
+
Copyright (c) 2023 European Molecular Biology Laboratory
|
4
|
+
|
5
|
+
Author: Valentin Maurer <valentin.maurer@embl-hamburg.de>
|
6
|
+
"""
|
7
|
+
|
8
|
+
from abc import ABC, abstractmethod
|
9
|
+
from typing import Tuple
|
10
|
+
|
11
|
+
import numpy as np
|
12
|
+
|
13
|
+
from .backends import backend as be
|
14
|
+
|
15
|
+
|
16
|
+
class MatchingMemoryUsage(ABC):
|
17
|
+
"""
|
18
|
+
Class specification for estimating the memory requirements of template matching.
|
19
|
+
|
20
|
+
Parameters
|
21
|
+
----------
|
22
|
+
fast_shape : tuple of int
|
23
|
+
Shape of the real array.
|
24
|
+
ft_shape : tuple of int
|
25
|
+
Shape of the complex array.
|
26
|
+
float_nbytes : int
|
27
|
+
Number of bytes of the used float, e.g. 4 for float32.
|
28
|
+
complex_nbytes : int
|
29
|
+
Number of bytes of the used complex, e.g. 8 for complex64.
|
30
|
+
integer_nbytes : int
|
31
|
+
Number of bytes of the used integer, e.g. 4 for int32.
|
32
|
+
|
33
|
+
Attributes
|
34
|
+
----------
|
35
|
+
real_array_size : int
|
36
|
+
Number of elements in real array.
|
37
|
+
complex_array_size : int
|
38
|
+
Number of elements in complex array.
|
39
|
+
float_nbytes : int
|
40
|
+
Number of bytes of the used float, e.g. 4 for float32.
|
41
|
+
complex_nbytes : int
|
42
|
+
Number of bytes of the used complex, e.g. 8 for complex64.
|
43
|
+
integer_nbytes : int
|
44
|
+
Number of bytes of the used integer, e.g. 4 for int32.
|
45
|
+
"""
|
46
|
+
|
47
|
+
def __init__(
|
48
|
+
self,
|
49
|
+
fast_shape: Tuple[int],
|
50
|
+
ft_shape: Tuple[int],
|
51
|
+
float_nbytes: int,
|
52
|
+
complex_nbytes: int,
|
53
|
+
integer_nbytes: int,
|
54
|
+
):
|
55
|
+
self.real_array_size = np.prod(fast_shape)
|
56
|
+
self.complex_array_size = np.prod(ft_shape)
|
57
|
+
self.float_nbytes = float_nbytes
|
58
|
+
self.complex_nbytes = complex_nbytes
|
59
|
+
self.integer_nbytes = integer_nbytes
|
60
|
+
|
61
|
+
@abstractmethod
|
62
|
+
def base_usage(self) -> int:
|
63
|
+
"""Return the base memory usage in bytes."""
|
64
|
+
|
65
|
+
@abstractmethod
|
66
|
+
def per_fork(self) -> int:
|
67
|
+
"""Return the memory usage per fork in bytes."""
|
68
|
+
|
69
|
+
|
70
|
+
class CCMemoryUsage(MatchingMemoryUsage):
|
71
|
+
"""
|
72
|
+
Memory usage estimation for CC scoring.
|
73
|
+
|
74
|
+
See Also
|
75
|
+
--------
|
76
|
+
:py:meth:`tme.matching_scores.cc_setup`.
|
77
|
+
"""
|
78
|
+
|
79
|
+
def base_usage(self) -> int:
|
80
|
+
float_arrays = self.real_array_size * self.float_nbytes
|
81
|
+
complex_arrays = self.complex_array_size * self.complex_nbytes
|
82
|
+
return float_arrays + complex_arrays
|
83
|
+
|
84
|
+
def per_fork(self) -> int:
|
85
|
+
float_arrays = self.real_array_size * self.float_nbytes
|
86
|
+
complex_arrays = self.complex_array_size * self.complex_nbytes
|
87
|
+
return float_arrays + complex_arrays
|
88
|
+
|
89
|
+
|
90
|
+
class LCCMemoryUsage(CCMemoryUsage):
|
91
|
+
"""
|
92
|
+
Memory usage estimation for LCC scoring.
|
93
|
+
|
94
|
+
See Also
|
95
|
+
--------
|
96
|
+
:py:meth:`tme.matching_scores.lcc_setup`.
|
97
|
+
"""
|
98
|
+
|
99
|
+
|
100
|
+
class CORRMemoryUsage(MatchingMemoryUsage):
|
101
|
+
"""
|
102
|
+
Memory usage estimation for CORR scoring.
|
103
|
+
|
104
|
+
See Also
|
105
|
+
--------
|
106
|
+
:py:meth:`tme.matching_scores.corr_setup`.
|
107
|
+
"""
|
108
|
+
|
109
|
+
def base_usage(self) -> int:
|
110
|
+
float_arrays = self.real_array_size * self.float_nbytes * 4
|
111
|
+
complex_arrays = self.complex_array_size * self.complex_nbytes
|
112
|
+
return float_arrays + complex_arrays
|
113
|
+
|
114
|
+
def per_fork(self) -> int:
|
115
|
+
float_arrays = self.real_array_size * self.float_nbytes
|
116
|
+
complex_arrays = self.complex_array_size * self.complex_nbytes
|
117
|
+
return float_arrays + complex_arrays
|
118
|
+
|
119
|
+
|
120
|
+
class CAMMemoryUsage(CORRMemoryUsage):
|
121
|
+
"""
|
122
|
+
Memory usage estimation for CAM scoring.
|
123
|
+
|
124
|
+
See Also
|
125
|
+
--------
|
126
|
+
:py:meth:`tme.matching_scores.cam_setup`.
|
127
|
+
"""
|
128
|
+
|
129
|
+
|
130
|
+
class FLCSphericalMaskMemoryUsage(CORRMemoryUsage):
|
131
|
+
"""
|
132
|
+
Memory usage estimation for FLCMSphericalMask scoring.
|
133
|
+
|
134
|
+
See Also
|
135
|
+
--------
|
136
|
+
:py:meth:`tme.matching_scores.flcSphericalMask_setup`.
|
137
|
+
"""
|
138
|
+
|
139
|
+
|
140
|
+
class FLCMemoryUsage(MatchingMemoryUsage):
|
141
|
+
"""
|
142
|
+
Memory usage estimation for FLC scoring.
|
143
|
+
|
144
|
+
See Also
|
145
|
+
--------
|
146
|
+
:py:meth:`tme.matching_scores.flc_setup`.
|
147
|
+
"""
|
148
|
+
|
149
|
+
def base_usage(self) -> int:
|
150
|
+
float_arrays = self.real_array_size * self.float_nbytes * 2
|
151
|
+
complex_arrays = self.complex_array_size * self.complex_nbytes * 2
|
152
|
+
return float_arrays + complex_arrays
|
153
|
+
|
154
|
+
def per_fork(self) -> int:
|
155
|
+
float_arrays = self.real_array_size * self.float_nbytes * 3
|
156
|
+
complex_arrays = self.complex_array_size * self.complex_nbytes * 2
|
157
|
+
return float_arrays + complex_arrays
|
158
|
+
|
159
|
+
|
160
|
+
class MCCMemoryUsage(MatchingMemoryUsage):
|
161
|
+
"""
|
162
|
+
Memory usage estimation for MCC scoring.
|
163
|
+
|
164
|
+
See Also
|
165
|
+
--------
|
166
|
+
:py:meth:`tme.matching_scores.mcc_setup`.
|
167
|
+
"""
|
168
|
+
|
169
|
+
def base_usage(self) -> int:
|
170
|
+
float_arrays = self.real_array_size * self.float_nbytes * 2
|
171
|
+
complex_arrays = self.complex_array_size * self.complex_nbytes * 3
|
172
|
+
return float_arrays + complex_arrays
|
173
|
+
|
174
|
+
def per_fork(self) -> int:
|
175
|
+
float_arrays = self.real_array_size * self.float_nbytes * 6
|
176
|
+
complex_arrays = self.complex_array_size * self.complex_nbytes
|
177
|
+
return float_arrays + complex_arrays
|
178
|
+
|
179
|
+
|
180
|
+
class MaxScoreOverRotationsMemoryUsage(MatchingMemoryUsage):
|
181
|
+
"""
|
182
|
+
Memory usage estimation MaxScoreOverRotations Analyzer.
|
183
|
+
|
184
|
+
See Also
|
185
|
+
--------
|
186
|
+
:py:class:`tme.analyzer.MaxScoreOverRotations`.
|
187
|
+
"""
|
188
|
+
|
189
|
+
def base_usage(self) -> int:
|
190
|
+
float_arrays = self.real_array_size * self.float_nbytes * 2
|
191
|
+
return float_arrays
|
192
|
+
|
193
|
+
def per_fork(self) -> int:
|
194
|
+
return 0
|
195
|
+
|
196
|
+
|
197
|
+
class PeakCallerMaximumFilterMemoryUsage(MatchingMemoryUsage):
|
198
|
+
"""
|
199
|
+
Memory usage estimation MaxScoreOverRotations Analyzer.
|
200
|
+
|
201
|
+
See Also
|
202
|
+
--------
|
203
|
+
:py:class:`tme.analyzer.PeakCallerMaximumFilter`.
|
204
|
+
"""
|
205
|
+
|
206
|
+
def base_usage(self) -> int:
|
207
|
+
float_arrays = self.real_array_size * self.float_nbytes
|
208
|
+
return float_arrays
|
209
|
+
|
210
|
+
def per_fork(self) -> int:
|
211
|
+
float_arrays = self.real_array_size * self.float_nbytes
|
212
|
+
return float_arrays
|
213
|
+
|
214
|
+
|
215
|
+
class CupyBackendMemoryUsage(MatchingMemoryUsage):
|
216
|
+
"""
|
217
|
+
Memory usage estimation for CupyBackend.
|
218
|
+
|
219
|
+
See Also
|
220
|
+
--------
|
221
|
+
:py:class:`tme.backends.CupyBackend`.
|
222
|
+
"""
|
223
|
+
|
224
|
+
def base_usage(self) -> int:
|
225
|
+
# FFT plans, overhead from assigning FFT result, rotation interpolation
|
226
|
+
complex_arrays = self.real_array_size * self.complex_nbytes * 3
|
227
|
+
float_arrays = self.complex_array_size * self.float_nbytes * 2
|
228
|
+
return float_arrays + complex_arrays
|
229
|
+
|
230
|
+
def per_fork(self) -> int:
|
231
|
+
return 0
|
232
|
+
|
233
|
+
|
234
|
+
MATCHING_MEMORY_REGISTRY = {
|
235
|
+
"CC": CCMemoryUsage,
|
236
|
+
"LCC": LCCMemoryUsage,
|
237
|
+
"CORR": CORRMemoryUsage,
|
238
|
+
"CAM": CAMMemoryUsage,
|
239
|
+
"MCC": MCCMemoryUsage,
|
240
|
+
"FLCSphericalMask": FLCSphericalMaskMemoryUsage,
|
241
|
+
"FLC": FLCMemoryUsage,
|
242
|
+
"MaxScoreOverRotations": MaxScoreOverRotationsMemoryUsage,
|
243
|
+
"PeakCallerMaximumFilter": PeakCallerMaximumFilterMemoryUsage,
|
244
|
+
"cupy": CupyBackendMemoryUsage,
|
245
|
+
"pytorch": CupyBackendMemoryUsage,
|
246
|
+
"batchFLCSpherical": FLCSphericalMaskMemoryUsage,
|
247
|
+
"batchFLC": FLCMemoryUsage,
|
248
|
+
}
|
249
|
+
|
250
|
+
|
251
|
+
def estimate_memory_usage(
|
252
|
+
shape1: Tuple[int],
|
253
|
+
shape2: Tuple[int],
|
254
|
+
matching_method: str,
|
255
|
+
ncores: int,
|
256
|
+
analyzer_method: str = None,
|
257
|
+
backend: str = None,
|
258
|
+
float_nbytes: int = 4,
|
259
|
+
complex_nbytes: int = 8,
|
260
|
+
integer_nbytes: int = 4,
|
261
|
+
) -> int:
|
262
|
+
"""
|
263
|
+
Estimate the memory usage for a given template matching operation.
|
264
|
+
|
265
|
+
Parameters
|
266
|
+
----------
|
267
|
+
shape1 : tuple
|
268
|
+
Shape of the target array.
|
269
|
+
shape2 : tuple
|
270
|
+
Shape of the template array.
|
271
|
+
matching_method : str
|
272
|
+
Matching method to estimate memory usage for.
|
273
|
+
analyzer_method : str, optional
|
274
|
+
The method used for score analysis.
|
275
|
+
backend : str, optional
|
276
|
+
Backend used for computation.
|
277
|
+
ncores : int
|
278
|
+
The number of CPU cores used for the operation.
|
279
|
+
float_nbytes : int
|
280
|
+
Number of bytes of the used float, defaults to 4 (float32).
|
281
|
+
complex_nbytes : int
|
282
|
+
Number of bytes of the used complex, defaults to 8 (complex64).
|
283
|
+
integer_nbytes : int
|
284
|
+
Number of bytes of the used integer, defaults to 4 (int32).
|
285
|
+
|
286
|
+
Returns
|
287
|
+
-------
|
288
|
+
int
|
289
|
+
The estimated memory usage for the operation in bytes.
|
290
|
+
|
291
|
+
Raises
|
292
|
+
------
|
293
|
+
ValueError
|
294
|
+
If an unsupported matching_method is provided.
|
295
|
+
"""
|
296
|
+
if matching_method not in MATCHING_MEMORY_REGISTRY:
|
297
|
+
raise ValueError(
|
298
|
+
f"Supported options are {','.join(MATCHING_MEMORY_REGISTRY.keys())}"
|
299
|
+
)
|
300
|
+
|
301
|
+
convolution_shape, fast_shape, ft_shape = be.compute_convolution_shapes(
|
302
|
+
shape1, shape2
|
303
|
+
)
|
304
|
+
|
305
|
+
memory_instance = MATCHING_MEMORY_REGISTRY[matching_method](
|
306
|
+
fast_shape=fast_shape,
|
307
|
+
ft_shape=ft_shape,
|
308
|
+
float_nbytes=float_nbytes,
|
309
|
+
complex_nbytes=complex_nbytes,
|
310
|
+
integer_nbytes=integer_nbytes,
|
311
|
+
)
|
312
|
+
|
313
|
+
nbytes = memory_instance.base_usage() + memory_instance.per_fork() * ncores
|
314
|
+
|
315
|
+
analyzer_instance = MATCHING_MEMORY_REGISTRY.get(analyzer_method, None)
|
316
|
+
if analyzer_instance is not None:
|
317
|
+
analyzer_instance = analyzer_instance(
|
318
|
+
fast_shape=fast_shape,
|
319
|
+
ft_shape=ft_shape,
|
320
|
+
float_nbytes=float_nbytes,
|
321
|
+
complex_nbytes=complex_nbytes,
|
322
|
+
integer_nbytes=integer_nbytes,
|
323
|
+
)
|
324
|
+
nbytes += analyzer_instance.base_usage() + analyzer_instance.per_fork() * ncores
|
325
|
+
|
326
|
+
backend_instance = MATCHING_MEMORY_REGISTRY.get(backend, None)
|
327
|
+
if backend_instance is not None:
|
328
|
+
backend_instance = backend_instance(
|
329
|
+
fast_shape=fast_shape,
|
330
|
+
ft_shape=ft_shape,
|
331
|
+
float_nbytes=float_nbytes,
|
332
|
+
complex_nbytes=complex_nbytes,
|
333
|
+
integer_nbytes=integer_nbytes,
|
334
|
+
)
|
335
|
+
nbytes += backend_instance.base_usage() + backend_instance.per_fork() * ncores
|
336
|
+
|
337
|
+
return nbytes
|