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.
Files changed (119) hide show
  1. pytme-0.2.9.data/scripts/estimate_ram_usage.py +97 -0
  2. pytme-0.2.9.data/scripts/match_template.py +1135 -0
  3. pytme-0.2.9.data/scripts/postprocess.py +622 -0
  4. pytme-0.2.9.data/scripts/preprocess.py +209 -0
  5. pytme-0.2.9.data/scripts/preprocessor_gui.py +1227 -0
  6. pytme-0.2.9.dist-info/METADATA +95 -0
  7. pytme-0.2.9.dist-info/RECORD +119 -0
  8. pytme-0.2.9.dist-info/WHEEL +5 -0
  9. pytme-0.2.9.dist-info/entry_points.txt +6 -0
  10. pytme-0.2.9.dist-info/licenses/LICENSE +153 -0
  11. pytme-0.2.9.dist-info/top_level.txt +3 -0
  12. scripts/__init__.py +0 -0
  13. scripts/estimate_ram_usage.py +97 -0
  14. scripts/match_template.py +1135 -0
  15. scripts/postprocess.py +622 -0
  16. scripts/preprocess.py +209 -0
  17. scripts/preprocessor_gui.py +1227 -0
  18. tests/__init__.py +0 -0
  19. tests/data/Blurring/blob_width18.npy +0 -0
  20. tests/data/Blurring/edgegaussian_sigma3.npy +0 -0
  21. tests/data/Blurring/gaussian_sigma2.npy +0 -0
  22. tests/data/Blurring/hamming_width6.npy +0 -0
  23. tests/data/Blurring/kaiserb_width18.npy +0 -0
  24. tests/data/Blurring/localgaussian_sigma0510.npy +0 -0
  25. tests/data/Blurring/mean_size5.npy +0 -0
  26. tests/data/Blurring/ntree_sigma0510.npy +0 -0
  27. tests/data/Blurring/rank_rank3.npy +0 -0
  28. tests/data/Maps/.DS_Store +0 -0
  29. tests/data/Maps/emd_8621.mrc.gz +0 -0
  30. tests/data/README.md +2 -0
  31. tests/data/Raw/em_map.map +0 -0
  32. tests/data/Structures/.DS_Store +0 -0
  33. tests/data/Structures/1pdj.cif +3339 -0
  34. tests/data/Structures/1pdj.pdb +1429 -0
  35. tests/data/Structures/5khe.cif +3685 -0
  36. tests/data/Structures/5khe.ent +2210 -0
  37. tests/data/Structures/5khe.pdb +2210 -0
  38. tests/data/Structures/5uz4.cif +70548 -0
  39. tests/preprocessing/__init__.py +0 -0
  40. tests/preprocessing/test_compose.py +76 -0
  41. tests/preprocessing/test_frequency_filters.py +178 -0
  42. tests/preprocessing/test_preprocessor.py +136 -0
  43. tests/preprocessing/test_utils.py +79 -0
  44. tests/test_analyzer.py +216 -0
  45. tests/test_backends.py +446 -0
  46. tests/test_density.py +503 -0
  47. tests/test_extensions.py +130 -0
  48. tests/test_matching_cli.py +283 -0
  49. tests/test_matching_data.py +162 -0
  50. tests/test_matching_exhaustive.py +124 -0
  51. tests/test_matching_memory.py +30 -0
  52. tests/test_matching_optimization.py +226 -0
  53. tests/test_matching_utils.py +189 -0
  54. tests/test_orientations.py +175 -0
  55. tests/test_parser.py +33 -0
  56. tests/test_rotations.py +153 -0
  57. tests/test_structure.py +247 -0
  58. tme/__init__.py +6 -0
  59. tme/__version__.py +1 -0
  60. tme/analyzer/__init__.py +2 -0
  61. tme/analyzer/_utils.py +186 -0
  62. tme/analyzer/aggregation.py +577 -0
  63. tme/analyzer/peaks.py +953 -0
  64. tme/backends/__init__.py +171 -0
  65. tme/backends/_cupy_utils.py +734 -0
  66. tme/backends/_jax_utils.py +188 -0
  67. tme/backends/cupy_backend.py +294 -0
  68. tme/backends/jax_backend.py +314 -0
  69. tme/backends/matching_backend.py +1270 -0
  70. tme/backends/mlx_backend.py +241 -0
  71. tme/backends/npfftw_backend.py +583 -0
  72. tme/backends/pytorch_backend.py +430 -0
  73. tme/data/__init__.py +0 -0
  74. tme/data/c48n309.npy +0 -0
  75. tme/data/c48n527.npy +0 -0
  76. tme/data/c48n9.npy +0 -0
  77. tme/data/c48u1.npy +0 -0
  78. tme/data/c48u1153.npy +0 -0
  79. tme/data/c48u1201.npy +0 -0
  80. tme/data/c48u1641.npy +0 -0
  81. tme/data/c48u181.npy +0 -0
  82. tme/data/c48u2219.npy +0 -0
  83. tme/data/c48u27.npy +0 -0
  84. tme/data/c48u2947.npy +0 -0
  85. tme/data/c48u3733.npy +0 -0
  86. tme/data/c48u4749.npy +0 -0
  87. tme/data/c48u5879.npy +0 -0
  88. tme/data/c48u7111.npy +0 -0
  89. tme/data/c48u815.npy +0 -0
  90. tme/data/c48u83.npy +0 -0
  91. tme/data/c48u8649.npy +0 -0
  92. tme/data/c600v.npy +0 -0
  93. tme/data/c600vc.npy +0 -0
  94. tme/data/metadata.yaml +80 -0
  95. tme/data/quat_to_numpy.py +42 -0
  96. tme/data/scattering_factors.pickle +0 -0
  97. tme/density.py +2263 -0
  98. tme/extensions.cpython-311-darwin.so +0 -0
  99. tme/external/bindings.cpp +332 -0
  100. tme/filters/__init__.py +6 -0
  101. tme/filters/_utils.py +311 -0
  102. tme/filters/bandpass.py +230 -0
  103. tme/filters/compose.py +81 -0
  104. tme/filters/ctf.py +393 -0
  105. tme/filters/reconstruction.py +160 -0
  106. tme/filters/wedge.py +542 -0
  107. tme/filters/whitening.py +191 -0
  108. tme/matching_data.py +863 -0
  109. tme/matching_exhaustive.py +497 -0
  110. tme/matching_optimization.py +1311 -0
  111. tme/matching_scores.py +1183 -0
  112. tme/matching_utils.py +1188 -0
  113. tme/memory.py +337 -0
  114. tme/orientations.py +598 -0
  115. tme/parser.py +685 -0
  116. tme/preprocessor.py +1329 -0
  117. tme/rotations.py +350 -0
  118. tme/structure.py +1864 -0
  119. tme/types.py +13 -0
@@ -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()