pytme 0.1.9__cp311-cp311-macosx_14_0_arm64.whl → 0.2.0__cp311-cp311-macosx_14_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 (42) hide show
  1. pytme-0.2.0.data/scripts/match_template.py +1019 -0
  2. pytme-0.2.0.data/scripts/postprocess.py +570 -0
  3. {pytme-0.1.9.data → pytme-0.2.0.data}/scripts/preprocessor_gui.py +244 -60
  4. {pytme-0.1.9.dist-info → pytme-0.2.0.dist-info}/METADATA +3 -1
  5. pytme-0.2.0.dist-info/RECORD +72 -0
  6. {pytme-0.1.9.dist-info → pytme-0.2.0.dist-info}/WHEEL +1 -1
  7. scripts/extract_candidates.py +218 -0
  8. scripts/match_template.py +459 -218
  9. pytme-0.1.9.data/scripts/match_template.py → scripts/match_template_filters.py +459 -218
  10. scripts/postprocess.py +380 -435
  11. scripts/preprocessor_gui.py +244 -60
  12. scripts/refine_matches.py +218 -0
  13. tme/__init__.py +2 -1
  14. tme/__version__.py +1 -1
  15. tme/analyzer.py +533 -78
  16. tme/backends/cupy_backend.py +80 -15
  17. tme/backends/npfftw_backend.py +35 -6
  18. tme/backends/pytorch_backend.py +15 -7
  19. tme/density.py +173 -78
  20. tme/extensions.cpython-311-darwin.so +0 -0
  21. tme/matching_constrained.py +195 -0
  22. tme/matching_data.py +76 -33
  23. tme/matching_exhaustive.py +354 -225
  24. tme/matching_memory.py +1 -0
  25. tme/matching_optimization.py +753 -649
  26. tme/matching_utils.py +152 -8
  27. tme/orientations.py +561 -0
  28. tme/preprocessing/__init__.py +2 -0
  29. tme/preprocessing/_utils.py +176 -0
  30. tme/preprocessing/composable_filter.py +30 -0
  31. tme/preprocessing/compose.py +52 -0
  32. tme/preprocessing/frequency_filters.py +322 -0
  33. tme/preprocessing/tilt_series.py +967 -0
  34. tme/preprocessor.py +35 -25
  35. tme/structure.py +2 -37
  36. pytme-0.1.9.data/scripts/postprocess.py +0 -625
  37. pytme-0.1.9.dist-info/RECORD +0 -61
  38. {pytme-0.1.9.data → pytme-0.2.0.data}/scripts/estimate_ram_usage.py +0 -0
  39. {pytme-0.1.9.data → pytme-0.2.0.data}/scripts/preprocess.py +0 -0
  40. {pytme-0.1.9.dist-info → pytme-0.2.0.dist-info}/LICENSE +0 -0
  41. {pytme-0.1.9.dist-info → pytme-0.2.0.dist-info}/entry_points.txt +0 -0
  42. {pytme-0.1.9.dist-info → pytme-0.2.0.dist-info}/top_level.txt +0 -0
tme/preprocessor.py CHANGED
@@ -47,7 +47,7 @@ class Preprocessor:
47
47
 
48
48
  def apply_method(self, method: str, parameters: Dict):
49
49
  """
50
- Apply a method on the atomic structure.
50
+ Invoke ``Preprocessor.method`` using ``parameters``.
51
51
 
52
52
  Parameters
53
53
  ----------
@@ -654,12 +654,9 @@ class Preprocessor:
654
654
  array = template.copy()
655
655
  interpolation_box = array.shape
656
656
 
657
- print(array.shape)
658
-
659
657
  for k in range(template.ndim):
660
658
  array = decimate(array, q=level, axis=k)
661
659
 
662
- print(array.shape)
663
660
  template = zoom(array, np.divide(template.shape, array.shape))
664
661
  template = self.interpolate_box(box=interpolation_box, arr=template)
665
662
 
@@ -768,21 +765,24 @@ class Preprocessor:
768
765
  sigma = sigma_factor * resolution
769
766
  sigma_grid = sigma / sampling_rate
770
767
  sigma_grid2 = sigma_grid * sigma_grid
771
- for index, point in enumerate(np.rollaxis(positions, 0)):
772
- starts = np.maximum(np.ceil(point - cutoff_value * sigma_grid), 0).astype(
773
- int
774
- )
775
- stops = np.minimum(
776
- np.floor(point + cutoff_value * sigma_grid), shape
777
- ).astype(int)
778
768
 
779
- grid_index = np.meshgrid(
780
- *[range(start, stop) for start, stop in zip(starts, stops)]
781
- )
782
- distances = np.einsum(
783
- "aijk->ijk",
784
- np.array([(grid_index[i] - point[i]) ** 2 for i in range(len(point))]),
785
- dtype=np.float64,
769
+ starts = np.maximum(np.ceil(positions - cutoff_value * sigma_grid), 0).astype(
770
+ int
771
+ )
772
+ stops = np.minimum(
773
+ np.floor(positions + cutoff_value * sigma_grid), shape
774
+ ).astype(int)
775
+ ranges = tuple(tuple(zip(start, stop)) for start, stop in zip(starts, stops))
776
+
777
+ positions = positions.reshape(
778
+ *positions.shape, *tuple(1 for _ in range(positions.shape[1]))
779
+ )
780
+ for index in range(positions.shape[0]):
781
+ grid_index = np.meshgrid(*[range(*coord) for coord in ranges[index]])
782
+ distances = np.sum(
783
+ np.square(np.subtract(grid_index, positions[index])),
784
+ dtype=np.float32,
785
+ axis=0,
786
786
  )
787
787
  np.add.at(
788
788
  out,
@@ -1131,9 +1131,11 @@ class Preprocessor:
1131
1131
  stop_tilt: float,
1132
1132
  tilt_step: float,
1133
1133
  shape: Tuple[int],
1134
+ tilt_angles: Tuple[float] = None,
1134
1135
  opening_axis: int = 0,
1135
1136
  tilt_axis: int = 2,
1136
1137
  sigma: float = 0,
1138
+ weights: float = 1,
1137
1139
  omit_negative_frequencies: bool = True,
1138
1140
  ) -> NDArray:
1139
1141
  """
@@ -1164,6 +1166,8 @@ class Preprocessor:
1164
1166
  - 2 for X-axis
1165
1167
  sigma : float, optional
1166
1168
  Standard deviation for Gaussian kernel used for smoothing the wedge.
1169
+ weights : float, tuple of float
1170
+ Weight of each element in the wedge. Defaults to one.
1167
1171
  omit_negative_frequencies : bool, optional
1168
1172
  Whether the wedge mask should omit negative frequencies, i.e. be
1169
1173
  applicable to symmetric Fourier transforms (see :obj:`numpy.fft.fftn`)
@@ -1184,17 +1188,20 @@ class Preprocessor:
1184
1188
  :py:meth:`Preprocessor.wedge_mask`
1185
1189
  :py:meth:`Preprocessor.continuous_wedge_mask`
1186
1190
  """
1187
- tilt_angles = np.arange(-start_tilt, stop_tilt + tilt_step, tilt_step)
1191
+ if tilt_angles is None:
1192
+ tilt_angles = np.arange(-start_tilt, stop_tilt + tilt_step, tilt_step)
1193
+
1194
+ weights = np.asarray(weights)
1195
+ weights = np.repeat(weights, tilt_angles.size // weights.size)
1188
1196
  plane = np.zeros((shape[opening_axis], shape[tilt_axis]), dtype=np.float32)
1189
1197
  subset = tuple(
1190
1198
  slice(None) if i != 0 else slice(x // 2, x // 2 + 1)
1191
1199
  for i, x in enumerate(plane.shape)
1192
1200
  )
1193
- plane[subset] = 1
1194
1201
  plane_rotated, wedge_volume = np.zeros_like(plane), np.zeros_like(plane)
1195
1202
  for index in range(tilt_angles.shape[0]):
1196
1203
  plane_rotated.fill(0)
1197
-
1204
+ plane[subset] = weights[index]
1198
1205
  rotation_matrix = euler_to_rotationmatrix((tilt_angles[index], 0))
1199
1206
  rotation_matrix = rotation_matrix[np.ix_((0, 1), (0, 1))]
1200
1207
 
@@ -1207,10 +1214,13 @@ class Preprocessor:
1207
1214
  )
1208
1215
  wedge_volume += plane_rotated
1209
1216
 
1210
- wedge_volume = self.gaussian_filter(
1211
- template=wedge_volume, sigma=sigma, fourier=False
1212
- )
1213
- wedge_volume = np.where(wedge_volume > np.exp(-2), 1, 0)
1217
+ # Ramp filtering would be more accurate
1218
+ np.fmin(wedge_volume, np.max(weights), wedge_volume)
1219
+
1220
+ if sigma > 0:
1221
+ wedge_volume = self.gaussian_filter(
1222
+ template=wedge_volume, sigma=sigma, fourier=False
1223
+ )
1214
1224
 
1215
1225
  if opening_axis > tilt_axis:
1216
1226
  wedge_volume = np.moveaxis(wedge_volume, 1, 0)
tme/structure.py CHANGED
@@ -26,45 +26,10 @@ from .types import NDArray
26
26
 
27
27
  @dataclass(repr=False)
28
28
  class Structure:
29
- """Represents atomic structures in accordance with the Protein Data Bank (PDB)
29
+ """
30
+ Represents atomic structures in accordance with the Protein Data Bank (PDB)
30
31
  format specification.
31
32
 
32
- Attributes
33
- ----------
34
- record_type : NDArray
35
- Type of the record, e.g., ATOM, HETATM. Array shape = (n,)
36
- atom_serial_number : NDArray
37
- Serial number assigned to each atom. Array shape = (n,)
38
- atom_name : NDArray
39
- Standardized names for each atom. Array shape = (n,)
40
- atom_coordinate : NDArray
41
- The 3D Cartesian coordinates of each atom in x, y, z. Array shape = (n,3 )
42
- alternate_location_indicator : NDArray
43
- Indicator for alternate locations of an atom if it exists in multiple places.
44
- Array shape = (n,)
45
- residue_name : NDArray
46
- Standard residue names where each atom belongs. Array shape = (n,)
47
- chain_identifier : NDArray
48
- Identifier for the chain where each atom is located. Array shape = (n,)
49
- residue_sequence_number : NDArray
50
- Sequence number of the residue in the protein chain for each atom.
51
- Array shape = (n,)
52
- code_for_residue_insertion : NDArray
53
- Code to denote any residue insertion. Array shape = (n,)
54
- occupancy : NDArray
55
- Occupancy factor of each atom, indicating the fraction of time the atom
56
- is located at its position. Array shape = (n,)
57
- temperature_factor : NDArray
58
- Measure of the atomic displacement or B-factor for each atom. Array shape = (n,)
59
- segment_identifier : NDArray
60
- Identifier for the segment where each atom belongs. Array shape = (n,)
61
- element_symbol : NDArray
62
- Atomic element symbol for each atom. Array shape = (n,)
63
- charge : NDArray
64
- Charge on the atom. Array shape = (n,)
65
- details : dict
66
- Any additional or auxiliary details. Array shape = (n,)
67
-
68
33
  References
69
34
  ----------
70
35
  .. [1] https://www.cgl.ucsf.edu/chimera/docs/UsersGuide/tutorials/pdbintro.html