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
scripts/preprocess.py
ADDED
@@ -0,0 +1,209 @@
|
|
1
|
+
#!python3
|
2
|
+
""" Preprocessing routines for template matching.
|
3
|
+
|
4
|
+
Copyright (c) 2023 European Molecular Biology Laboratory
|
5
|
+
|
6
|
+
Author: Valentin Maurer <valentin.maurer@embl-hamburg.de>
|
7
|
+
"""
|
8
|
+
import argparse
|
9
|
+
import numpy as np
|
10
|
+
|
11
|
+
from tme import Density, Structure
|
12
|
+
from tme.backends import backend as be
|
13
|
+
from tme.filters import BandPassFilter
|
14
|
+
|
15
|
+
|
16
|
+
def parse_args():
|
17
|
+
parser = argparse.ArgumentParser(
|
18
|
+
description="Perform template matching preprocessing.",
|
19
|
+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
20
|
+
)
|
21
|
+
|
22
|
+
io_group = parser.add_argument_group("Input / Output")
|
23
|
+
io_group.add_argument(
|
24
|
+
"-m",
|
25
|
+
"--data",
|
26
|
+
dest="data",
|
27
|
+
type=str,
|
28
|
+
required=True,
|
29
|
+
help="Path to a file in PDB/MMCIF, CCP4/MRC, EM, H5 or a format supported by "
|
30
|
+
"tme.density.Density.from_file "
|
31
|
+
"https://kosinskilab.github.io/pyTME/reference/api/tme.density.Density.from_file.html",
|
32
|
+
)
|
33
|
+
io_group.add_argument(
|
34
|
+
"-o",
|
35
|
+
"--output",
|
36
|
+
dest="output",
|
37
|
+
type=str,
|
38
|
+
required=True,
|
39
|
+
help="Path the output should be written to.",
|
40
|
+
)
|
41
|
+
|
42
|
+
box_group = parser.add_argument_group("Box")
|
43
|
+
box_group.add_argument(
|
44
|
+
"--box_size",
|
45
|
+
dest="box_size",
|
46
|
+
type=int,
|
47
|
+
required=False,
|
48
|
+
help="Box size of the output. Defaults to twice the required box size.",
|
49
|
+
)
|
50
|
+
box_group.add_argument(
|
51
|
+
"--sampling_rate",
|
52
|
+
dest="sampling_rate",
|
53
|
+
type=float,
|
54
|
+
required=True,
|
55
|
+
help="Sampling rate of the output file.",
|
56
|
+
)
|
57
|
+
box_group.add_argument(
|
58
|
+
"--input_sampling_rate",
|
59
|
+
dest="input_sampling_rate",
|
60
|
+
type=float,
|
61
|
+
required=False,
|
62
|
+
help="Sampling rate of the input file.",
|
63
|
+
)
|
64
|
+
|
65
|
+
modulation_group = parser.add_argument_group("Modulation")
|
66
|
+
modulation_group.add_argument(
|
67
|
+
"--invert_contrast",
|
68
|
+
dest="invert_contrast",
|
69
|
+
action="store_true",
|
70
|
+
required=False,
|
71
|
+
help="Inverts the template contrast.",
|
72
|
+
)
|
73
|
+
modulation_group.add_argument(
|
74
|
+
"--lowpass",
|
75
|
+
dest="lowpass",
|
76
|
+
type=float,
|
77
|
+
required=False,
|
78
|
+
default=None,
|
79
|
+
help="Lowpass filter the template to the given resolution. Nyquist by default. "
|
80
|
+
"A value of 0 disables the filter.",
|
81
|
+
)
|
82
|
+
modulation_group.add_argument(
|
83
|
+
"--no_centering",
|
84
|
+
dest="no_centering",
|
85
|
+
action="store_true",
|
86
|
+
help="Assumes the template is already centered and omits centering.",
|
87
|
+
)
|
88
|
+
modulation_group.add_argument(
|
89
|
+
"--backend",
|
90
|
+
dest="backend",
|
91
|
+
type=str,
|
92
|
+
default=None,
|
93
|
+
choices=be.available_backends(),
|
94
|
+
help="Determines more suitable box size for the given compute backend.",
|
95
|
+
)
|
96
|
+
|
97
|
+
alignment_group = parser.add_argument_group("Modulation")
|
98
|
+
alignment_group.add_argument(
|
99
|
+
"--align_axis",
|
100
|
+
dest="align_axis",
|
101
|
+
type=int,
|
102
|
+
required=False,
|
103
|
+
help="Align template to given axis, e.g. 2 for z-axis.",
|
104
|
+
)
|
105
|
+
alignment_group.add_argument(
|
106
|
+
"--align_eigenvector",
|
107
|
+
dest="align_eigenvector",
|
108
|
+
type=int,
|
109
|
+
required=False,
|
110
|
+
default=0,
|
111
|
+
help="Eigenvector to use for alignment. Defaults to 0, i.e. the eigenvector "
|
112
|
+
"with numerically largest eigenvalue.",
|
113
|
+
)
|
114
|
+
alignment_group.add_argument(
|
115
|
+
"--flip_axis",
|
116
|
+
dest="flip_axis",
|
117
|
+
action="store_true",
|
118
|
+
required=False,
|
119
|
+
help="Align the template to -axis instead of axis.",
|
120
|
+
)
|
121
|
+
|
122
|
+
args = parser.parse_args()
|
123
|
+
return args
|
124
|
+
|
125
|
+
|
126
|
+
def main():
|
127
|
+
args = parse_args()
|
128
|
+
|
129
|
+
try:
|
130
|
+
data = Structure.from_file(args.data)
|
131
|
+
sampling_rate = args.sampling_rate
|
132
|
+
if args.input_sampling_rate is not None:
|
133
|
+
sampling_rate = args.input_sampling_rate
|
134
|
+
|
135
|
+
if args.align_axis is not None:
|
136
|
+
rmat = data.align_to_axis(axis=args.align_axis, flip=args.flip_axis)
|
137
|
+
data = data.rigid_transform(
|
138
|
+
rotation_matrix=rmat, translation=0, use_geometric_center=True
|
139
|
+
)
|
140
|
+
data = Density.from_structure(data, sampling_rate=sampling_rate)
|
141
|
+
|
142
|
+
except NotImplementedError:
|
143
|
+
data = Density.from_file(args.data)
|
144
|
+
if args.input_sampling_rate is not None:
|
145
|
+
data.sampling_rate = args.input_sampling_rate
|
146
|
+
|
147
|
+
if args.align_axis is not None:
|
148
|
+
rmat = data.align_to_axis(axis=args.align_axis, flip=args.flip_axis)
|
149
|
+
data = data.rigid_transform(
|
150
|
+
rotation_matrix=rmat, translation=0, use_geometric_center=True
|
151
|
+
)
|
152
|
+
|
153
|
+
if not args.no_centering:
|
154
|
+
data, _ = data.centered(0)
|
155
|
+
|
156
|
+
if args.box_size is None:
|
157
|
+
scale = np.divide(data.sampling_rate, args.sampling_rate)
|
158
|
+
args.box_size = int(np.ceil(2 * np.max(np.multiply(scale, data.shape)))) + 1
|
159
|
+
|
160
|
+
default_backend = be._backend_name
|
161
|
+
for name in be.available_backends():
|
162
|
+
be.change_backend(name, device="cpu")
|
163
|
+
box = be.compute_convolution_shapes([args.box_size], [1])[1][0]
|
164
|
+
if box != args.box_size and args.backend is None:
|
165
|
+
print(f"Consider --box_size {box} instead of {args.box_size} for {name}.")
|
166
|
+
|
167
|
+
if args.backend is not None:
|
168
|
+
be.change_backend(args.backend, device="cpu")
|
169
|
+
|
170
|
+
box = be.compute_convolution_shapes([args.box_size], [1])[1][0]
|
171
|
+
if box != args.box_size:
|
172
|
+
print(f"Changed --box_size from {args.box_size} to {box}.")
|
173
|
+
args.box_size = box
|
174
|
+
|
175
|
+
be.change_backend(default_backend)
|
176
|
+
|
177
|
+
data.pad(
|
178
|
+
np.multiply(args.box_size, np.divide(args.sampling_rate, data.sampling_rate)),
|
179
|
+
center=True,
|
180
|
+
)
|
181
|
+
|
182
|
+
bpf_mask = 1
|
183
|
+
lowpass = 2 * args.sampling_rate if args.lowpass is None else args.lowpass
|
184
|
+
if args.lowpass != 0:
|
185
|
+
bpf_mask = BandPassFilter(
|
186
|
+
lowpass=lowpass,
|
187
|
+
highpass=None,
|
188
|
+
use_gaussian=True,
|
189
|
+
return_real_fourier=True,
|
190
|
+
shape_is_real_fourier=False,
|
191
|
+
sampling_rate=data.sampling_rate,
|
192
|
+
)(shape=data.shape)["data"]
|
193
|
+
bpf_mask = be.to_numpy_array(bpf_mask)
|
194
|
+
|
195
|
+
data_ft = np.fft.rfftn(data.data, s=data.shape)
|
196
|
+
data_ft = np.multiply(data_ft, bpf_mask, out=data_ft)
|
197
|
+
data.data = np.fft.irfftn(data_ft, s=data.shape).real
|
198
|
+
|
199
|
+
data = data.resample(args.sampling_rate, method="spline", order=3)
|
200
|
+
|
201
|
+
if args.invert_contrast:
|
202
|
+
data.data = data.data * -1
|
203
|
+
|
204
|
+
data.data = data.data.astype(np.float32)
|
205
|
+
data.to_file(args.output)
|
206
|
+
|
207
|
+
|
208
|
+
if __name__ == "__main__":
|
209
|
+
main()
|