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/backends/__init__.py
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
""" pyTME backend manager.
|
2
|
+
|
3
|
+
Copyright (c) 2023 European Molecular Biology Laboratory
|
4
|
+
|
5
|
+
Author: Valentin Maurer <valentin.maurer@embl-hamburg.de>
|
6
|
+
"""
|
7
|
+
|
8
|
+
from typing import Dict, List
|
9
|
+
from importlib.util import find_spec
|
10
|
+
|
11
|
+
from .matching_backend import MatchingBackend
|
12
|
+
from .npfftw_backend import NumpyFFTWBackend
|
13
|
+
from .pytorch_backend import PytorchBackend
|
14
|
+
from .cupy_backend import CupyBackend
|
15
|
+
from .mlx_backend import MLXBackend
|
16
|
+
from .jax_backend import JaxBackend
|
17
|
+
|
18
|
+
|
19
|
+
class BackendManager:
|
20
|
+
"""
|
21
|
+
Manager for template matching backends.
|
22
|
+
|
23
|
+
This class serves as an interface to various computational backends (e.g.,
|
24
|
+
CPU, GPU). It allows users to seamlessly swap between different backend
|
25
|
+
implementations while preserving the consistency and functionality of the API.
|
26
|
+
Direct attribute and method calls to the manager are delegated to the current
|
27
|
+
active backend.
|
28
|
+
|
29
|
+
Examples
|
30
|
+
--------
|
31
|
+
>>> from tme.backends import backend
|
32
|
+
>>> backend.multiply(arr1, arr2)
|
33
|
+
# This will use the default NumpyFFTWBackend's multiply method
|
34
|
+
|
35
|
+
>>> backend.change_backend("pytorch")
|
36
|
+
>>> backend.multiply(arr1, arr2)
|
37
|
+
# This will use the pytorchs multiply method
|
38
|
+
|
39
|
+
>>> backend.available_backends()
|
40
|
+
# Backends available on your system
|
41
|
+
|
42
|
+
Notes
|
43
|
+
-----
|
44
|
+
The backend has to be reinitialzed when using fork-based parallelism.
|
45
|
+
"""
|
46
|
+
|
47
|
+
def __init__(self):
|
48
|
+
self._BACKEND_REGISTRY = {
|
49
|
+
"numpyfftw": NumpyFFTWBackend,
|
50
|
+
"pytorch": PytorchBackend,
|
51
|
+
"cupy": CupyBackend,
|
52
|
+
"mlx": MLXBackend,
|
53
|
+
"jax": JaxBackend,
|
54
|
+
}
|
55
|
+
self._backend = NumpyFFTWBackend()
|
56
|
+
self._backend_name = "numpyfftw"
|
57
|
+
self._backend_args = {}
|
58
|
+
|
59
|
+
def __repr__(self):
|
60
|
+
return f"<BackendManager: using {self._backend_name}>"
|
61
|
+
|
62
|
+
def __getattr__(self, name):
|
63
|
+
return getattr(self._backend, name)
|
64
|
+
|
65
|
+
def __dir__(self) -> List:
|
66
|
+
"""
|
67
|
+
Return a list of attributes available in this object,
|
68
|
+
including those from the backend.
|
69
|
+
|
70
|
+
Returns
|
71
|
+
-------
|
72
|
+
list
|
73
|
+
Sorted list of attributes.
|
74
|
+
"""
|
75
|
+
base_attributes = []
|
76
|
+
base_attributes.extend(dir(self.__class__))
|
77
|
+
base_attributes.extend(self.__dict__.keys())
|
78
|
+
base_attributes.extend(dir(self._backend))
|
79
|
+
return sorted(base_attributes)
|
80
|
+
|
81
|
+
def add_backend(self, backend_name: str, backend_class: type):
|
82
|
+
"""
|
83
|
+
Adds a custom backend to the registry.
|
84
|
+
|
85
|
+
Parameters
|
86
|
+
----------
|
87
|
+
backend_name : str
|
88
|
+
Name by which the backend can be referenced.
|
89
|
+
backend_class : :py:class:`MatchingBackend`
|
90
|
+
An instance of the backend to be added.
|
91
|
+
|
92
|
+
Examples
|
93
|
+
--------
|
94
|
+
>>> from tme.backends import backend as be
|
95
|
+
>>> from tme.backends import NumpyFFTWBackend
|
96
|
+
>>> be.add_backend("numpy2", NumpyFFTWBackend)
|
97
|
+
|
98
|
+
Raises
|
99
|
+
------
|
100
|
+
ValueError
|
101
|
+
If the provided backend_instance does not inherit from
|
102
|
+
:py:class:`MatchingBackend`.
|
103
|
+
"""
|
104
|
+
if not issubclass(backend_class, MatchingBackend):
|
105
|
+
raise ValueError("backend_class needs to inherit from MatchingBackend.")
|
106
|
+
self._BACKEND_REGISTRY[backend_name] = backend_class
|
107
|
+
|
108
|
+
def change_backend(self, backend_name: str, **backend_kwargs: Dict) -> None:
|
109
|
+
"""
|
110
|
+
Change the current computation backend.
|
111
|
+
|
112
|
+
Parameters
|
113
|
+
----------
|
114
|
+
backend_name : str
|
115
|
+
Name of the new backend that should be used.
|
116
|
+
**backend_kwargs : dict, optional
|
117
|
+
Parameters passed to __init__ method of backend.
|
118
|
+
|
119
|
+
Examples
|
120
|
+
--------
|
121
|
+
>>> from tme.backends import backend as be
|
122
|
+
>>> be.change_backend("cupy")
|
123
|
+
|
124
|
+
Raises
|
125
|
+
------
|
126
|
+
NotImplementedError
|
127
|
+
If no backend is found with the provided name.
|
128
|
+
"""
|
129
|
+
if backend_name not in self._BACKEND_REGISTRY:
|
130
|
+
available_backends = ", ".join(self.available_backends())
|
131
|
+
raise NotImplementedError(
|
132
|
+
f"Available backends are {available_backends} - not {backend_name}."
|
133
|
+
)
|
134
|
+
self._backend = self._BACKEND_REGISTRY[backend_name](**backend_kwargs)
|
135
|
+
self._backend_name = backend_name
|
136
|
+
self._backend_args = backend_kwargs
|
137
|
+
|
138
|
+
def available_backends(self) -> List[str]:
|
139
|
+
"""
|
140
|
+
Returns available computation backends.
|
141
|
+
|
142
|
+
Returns
|
143
|
+
-------
|
144
|
+
list of str
|
145
|
+
Available computation backends.
|
146
|
+
|
147
|
+
Examples
|
148
|
+
--------
|
149
|
+
>>> from tme.backends import backend as be
|
150
|
+
>>> be.available_backends()
|
151
|
+
"""
|
152
|
+
# This is an approximation but avoids runtime polution
|
153
|
+
_dependencies = {
|
154
|
+
"numpyfftw": "numpy",
|
155
|
+
"cupy": "cupy",
|
156
|
+
"pytorch": "torch",
|
157
|
+
"mlx": "mlx",
|
158
|
+
"jax": "jax",
|
159
|
+
}
|
160
|
+
available_backends = []
|
161
|
+
for name, backend in self._BACKEND_REGISTRY.items():
|
162
|
+
if name not in _dependencies:
|
163
|
+
continue
|
164
|
+
|
165
|
+
if find_spec(_dependencies[name]) is not None:
|
166
|
+
available_backends.append(name)
|
167
|
+
|
168
|
+
return available_backends
|
169
|
+
|
170
|
+
|
171
|
+
backend = BackendManager()
|