lattice-sub 1.0.10__py3-none-any.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.
@@ -0,0 +1,324 @@
1
+ Metadata-Version: 2.4
2
+ Name: lattice-sub
3
+ Version: 1.0.10
4
+ Summary: Lattice subtraction for cryo-EM micrographs - removes periodic crystal signals to reveal non-periodic features
5
+ Author-email: George Stephenson <george.stephenson@colorado.edu>, Vignesh Kasinath <vignesh.kasinath@colorado.edu>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/gsstephenson/cryoem-lattice-subtraction
8
+ Project-URL: Documentation, https://github.com/gsstephenson/cryoem-lattice-subtraction#readme
9
+ Project-URL: Repository, https://github.com/gsstephenson/cryoem-lattice-subtraction
10
+ Keywords: cryo-em,electron-microscopy,lattice-subtraction,image-processing,fft
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
18
+ Classifier: Topic :: Scientific/Engineering :: Image Processing
19
+ Requires-Python: >=3.11
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: numpy>=1.24
23
+ Requires-Dist: scipy>=1.11
24
+ Requires-Dist: mrcfile>=1.4
25
+ Requires-Dist: pyyaml>=6.0
26
+ Requires-Dist: tqdm>=4.65
27
+ Requires-Dist: click>=8.1
28
+ Requires-Dist: scikit-image>=0.21
29
+ Requires-Dist: torch>=2.0
30
+ Requires-Dist: matplotlib>=3.7
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest>=7.4; extra == "dev"
33
+ Requires-Dist: pytest-cov; extra == "dev"
34
+ Requires-Dist: black; extra == "dev"
35
+ Requires-Dist: ruff; extra == "dev"
36
+ Requires-Dist: mypy; extra == "dev"
37
+ Provides-Extra: viz
38
+ Requires-Dist: matplotlib>=3.7; extra == "viz"
39
+ Dynamic: license-file
40
+
41
+ # Lattice Subtraction for Cryo-EM
42
+
43
+ ```
44
+ .__ __ __ .__ ___.
45
+ | | _____ _/ |__/ |_|__| ____ ____ ________ _\_ |__
46
+ | | \__ \\ __\ __\ |/ ___\/ __ \ ______ / ___/ | \ __ \
47
+ | |__/ __ \| | | | | \ \__\ ___/ /_____/ \___ \| | / \_\ \
48
+ |____(____ /__| |__| |__|\___ >___ > /____ >____/|___ /
49
+ \/ \/ \/ \/ \/
50
+ ```
51
+
52
+ [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
53
+ [![PyTorch](https://img.shields.io/badge/PyTorch-2.5+-ee4c2c.svg)](https://pytorch.org/)
54
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
55
+
56
+ **Remove periodic lattice patterns from cryo-EM micrographs to reveal non-periodic features.**
57
+
58
+ ![Example Result](docs/images/example_comparison.png)
59
+
60
+ ---
61
+
62
+ ## Installation
63
+
64
+ ```bash
65
+ pip install lattice-sub
66
+ ```
67
+
68
+ That's it! GPU acceleration works automatically if you have an NVIDIA GPU.
69
+
70
+ ---
71
+
72
+ ## Quick Start
73
+
74
+ ### Process a Single Image
75
+
76
+ ```bash
77
+ lattice-sub process your_image.mrc -o output.mrc --pixel-size 0.56
78
+ ```
79
+
80
+ ### Process a Folder of Images
81
+
82
+ ```bash
83
+ lattice-sub batch input_folder/ output_folder/ --pixel-size 0.56
84
+ ```
85
+
86
+ ### Generate Comparison Images
87
+
88
+ ```bash
89
+ lattice-sub batch input_folder/ output_folder/ --pixel-size 0.56 --vis comparisons/
90
+ ```
91
+
92
+ This creates side-by-side PNG images showing before/after/difference for each micrograph.
93
+
94
+ ---
95
+
96
+ ## Common Options
97
+
98
+ | Option | Description |
99
+ |--------|-------------|
100
+ | `-p, --pixel-size` | **Required.** Pixel size in Ångstroms |
101
+ | `-o, --output` | Output file path (default: `sub_<input>`) |
102
+ | `-t, --threshold` | Peak detection sensitivity (default: 1.42) |
103
+ | `--cpu` | Force CPU processing (GPU is used by default) |
104
+ | `-q, --quiet` | Hide the banner and progress messages |
105
+ | `-v, --verbose` | Show detailed processing information |
106
+
107
+ ### Example with Options
108
+
109
+ ```bash
110
+ # Process with custom threshold, verbose output
111
+ lattice-sub process image.mrc -o cleaned.mrc -p 0.56 -t 1.5 -v
112
+
113
+ # Batch process, force CPU with 8 parallel workers
114
+ lattice-sub batch raw/ processed/ -p 0.56 --cpu -j 8
115
+ ```
116
+
117
+ ---
118
+
119
+ ## Using a Config File
120
+
121
+ For reproducible processing, save your parameters in a YAML file:
122
+
123
+ ```yaml
124
+ # params.yaml
125
+ pixel_ang: 0.56
126
+ threshold: 1.42
127
+ inside_radius_ang: 90
128
+ unit_cell_ang: 116
129
+ ```
130
+
131
+ Then use it:
132
+
133
+ ```bash
134
+ lattice-sub process image.mrc -o output.mrc --config params.yaml
135
+ ```
136
+
137
+ Create a starter config file:
138
+
139
+ ```bash
140
+ lattice-sub init-config params.yaml --pixel-size 0.56
141
+ ```
142
+
143
+ ---
144
+
145
+ ## GPU Troubleshooting
146
+
147
+ GPU should work automatically. If it doesn't:
148
+
149
+ ```bash
150
+ # Check GPU status
151
+ lattice-sub setup-gpu
152
+
153
+ # Or verify manually
154
+ python -c "import torch; print(torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'No GPU')"
155
+ ```
156
+
157
+ **Requirements:** NVIDIA GPU with driver 525+ (RTX 20/30/40 series, A100, etc.)
158
+
159
+ ---
160
+
161
+ ## Python API
162
+
163
+ ```python
164
+ from lattice_subtraction import LatticeSubtractor, Config
165
+
166
+ # Configure and process
167
+ config = Config(pixel_ang=0.56)
168
+ subtractor = LatticeSubtractor(config)
169
+
170
+ result = subtractor.process("input.mrc")
171
+ result.save("output.mrc")
172
+ ```
173
+
174
+ ### Batch Processing
175
+
176
+ ```python
177
+ from lattice_subtraction import BatchProcessor, Config
178
+
179
+ config = Config(pixel_ang=0.56)
180
+ processor = BatchProcessor(config)
181
+
182
+ stats = processor.process_directory("raw/", "processed/")
183
+ print(f"Processed {stats.successful}/{stats.total} files")
184
+ ```
185
+
186
+ ---
187
+
188
+ ## What It Does
189
+
190
+ This tool removes the periodic "lattice" pattern from 2D crystal cryo-EM images:
191
+
192
+ 1. **Finds lattice peaks** in the Fourier transform (the repeating pattern)
193
+ 2. **Replaces them** with averaged local values (inpainting)
194
+ 3. **Preserves phase** so the image stays accurate
195
+ 4. **Returns** the cleaned image with non-periodic features visible
196
+
197
+ ### Key Parameters Explained
198
+
199
+ | Parameter | What it controls |
200
+ |-----------|------------------|
201
+ | `pixel_ang` | Your detector's pixel size (check your microscope settings) |
202
+ | `threshold` | How aggressively to detect peaks. Higher = fewer peaks removed |
203
+ | `inside_radius_ang` | Protect low-resolution features (default 90Å is good for nucleosomes) |
204
+ | `unit_cell_ang` | Crystal repeat distance (116Å for nucleosome arrays) |
205
+
206
+ ---
207
+
208
+ ## Need Help?
209
+
210
+ ```bash
211
+ # See all commands
212
+ lattice-sub --help
213
+
214
+ # See options for a specific command
215
+ lattice-sub process --help
216
+ lattice-sub batch --help
217
+ ```
218
+
219
+ ---
220
+
221
+ ## Citation
222
+
223
+ ```bibtex
224
+ @software{lattice_sub,
225
+ title = {Lattice Subtraction for Cryo-EM Micrographs},
226
+ author = {Stephenson, George and Kasinath, Vignesh},
227
+ year = {2026},
228
+ url = {https://github.com/gsstephenson/cryoem-lattice-subtraction}
229
+ }
230
+ ```
231
+
232
+ **Original MATLAB algorithm**: Vignesh Kasinath
233
+ **Python package**: George Stephenson
234
+ Kasinath Lab, BioFrontiers Institute, University of Colorado Boulder
235
+
236
+ ---
237
+
238
+ ## License
239
+
240
+ MIT License - see [LICENSE](LICENSE) for details.
241
+
242
+ ---
243
+
244
+ <details>
245
+ <summary><strong>📚 Advanced Topics</strong> (click to expand)</summary>
246
+
247
+ ### Algorithm Details
248
+
249
+ ```
250
+ Image → Pad → FFT → Detect Peaks → Create Mask → Inpaint → iFFT → Crop → Output
251
+ ```
252
+
253
+ The algorithm:
254
+ 1. Pads the image to reduce edge artifacts
255
+ 2. Applies 2D FFT to get frequency domain
256
+ 3. Detects lattice peaks via thresholding on log-power spectrum
257
+ 4. Creates a mask protecting inner (low-freq) and outer (high-freq) regions
258
+ 5. Inpaints peaks with local average amplitude from 4 shifted neighbors
259
+ 6. Preserves original phase information
260
+ 7. Inverse FFT returns to real space
261
+
262
+ ### Full Parameter Reference
263
+
264
+ | Parameter | Default | Description |
265
+ |-----------|---------|-------------|
266
+ | `pixel_ang` | *required* | Pixel size in Ångstroms |
267
+ | `threshold` | 1.42 | Peak detection threshold on log-amplitude |
268
+ | `inside_radius_ang` | 90 | Inner resolution limit (Å) - protects structural info |
269
+ | `outside_radius_ang` | auto | Outer resolution limit (Å) - protects near Nyquist |
270
+ | `expand_pixel` | 10 | Morphological expansion of peak mask (pixels) |
271
+ | `unit_cell_ang` | 116 | Crystal unit cell for inpaint shift calculation (Å) |
272
+ | `backend` | auto | `"auto"`, `"numpy"` (CPU), or `"pytorch"` (GPU) |
273
+
274
+ ### Supported Hardware
275
+
276
+ - **NVIDIA GPUs**: RTX 20/30/40 series, A100, H100
277
+ - **CUDA versions**: 11.8, 12.1, 12.4, 12.6, 12.8
278
+ - **CPU fallback**: Works on any system (just slower)
279
+
280
+ ### Development Setup
281
+
282
+ ```bash
283
+ git clone https://github.com/gsstephenson/cryoem-lattice-subtraction.git
284
+ cd cryoem-lattice-subtraction
285
+
286
+ conda create -n lattice_sub python=3.11 -y
287
+ conda activate lattice_sub
288
+
289
+ pip install -e ".[dev]"
290
+ pytest tests/ -v # Run tests
291
+ ```
292
+
293
+ ### Code Structure
294
+
295
+ ```
296
+ src/lattice_subtraction/
297
+ ├── __init__.py # Package exports
298
+ ├── cli.py # Command-line interface
299
+ ├── core.py # LatticeSubtractor main class
300
+ ├── batch.py # Parallel batch processing
301
+ ├── config.py # Configuration dataclass
302
+ ├── io.py # MRC file I/O
303
+ ├── masks.py # FFT mask generation
304
+ ├── processing.py # FFT helpers
305
+ ├── ui.py # Terminal UI
306
+ └── visualization.py # Comparison figures
307
+ ```
308
+
309
+ ### Migration from MATLAB
310
+
311
+ This is a modernized rewrite of legacy MATLAB code (`LAsub.m`, `bg_push_by_rot.m`, etc.) with:
312
+ - 10-100× faster processing via GPU
313
+ - Pip-installable package
314
+ - YAML config files instead of hardcoded values
315
+ - Command-line interface
316
+ - Automated testing
317
+
318
+ Convert a legacy PARAMETER file:
319
+
320
+ ```bash
321
+ lattice-sub convert-config PARAMETER params.yaml
322
+ ```
323
+
324
+ </details>
@@ -0,0 +1,16 @@
1
+ lattice_sub-1.0.10.dist-info/licenses/LICENSE,sha256=2kPoH0cbEp0cVEGqMpyF2IQX1npxdtQmWJB__HIRSb0,1101
2
+ lattice_subtraction/__init__.py,sha256=FkGThd0LyCu5WWJsyTNT1cjecysjHbXkEEL_3u_DabU,1464
3
+ lattice_subtraction/batch.py,sha256=sTDWEL5FlEx2HFaJsTZRXyzLQoNCgUqRo900eZ6kq68,12005
4
+ lattice_subtraction/cli.py,sha256=VVLMvtSbo3iEWRiUPBZJxvquSty7QHXmE8dxUy3jYm0,23200
5
+ lattice_subtraction/config.py,sha256=gziw2drMbuefTf7L5zGEnJljmjdMD_daGQE85NyOWHw,7427
6
+ lattice_subtraction/core.py,sha256=9ExoPVifc5OVBSh-wL_tp6z-CwuMYWfmg6PRWTL2mW0,14551
7
+ lattice_subtraction/io.py,sha256=uHku6rJ0jeCph7w-gOIDJx-xpNoF6PZcLfb5TBTOiw0,4594
8
+ lattice_subtraction/masks.py,sha256=HIamrACmbQDkaCV4kXhnjMDSwIig4OtQFLig9A8PMO8,11741
9
+ lattice_subtraction/processing.py,sha256=UnwEuuRLpffXVgDz8D56VlusXSCZ5NAABGZRvBe3VTs,6210
10
+ lattice_subtraction/ui.py,sha256=Sp_a-yNmBRZJxll8h9T_H5-_KsI13zGYmHcbcpVpbR8,9176
11
+ lattice_subtraction/visualization.py,sha256=7hAT19BWuw4l3JUTHFf29qwD1b2_fR9LS7p6x3BwEyA,5761
12
+ lattice_sub-1.0.10.dist-info/METADATA,sha256=09AlzyPDqh0vCjW2QNiTn_Elmld0wvAVoQb1mIm3pho,9251
13
+ lattice_sub-1.0.10.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
+ lattice_sub-1.0.10.dist-info/entry_points.txt,sha256=o8PzJR8kFnXlKZufoYGBIHpiosM-P4PZeKZXJjtPS6Y,61
15
+ lattice_sub-1.0.10.dist-info/top_level.txt,sha256=BOuW-sm4G-fQtsWPRdeLzWn0WS8sDYVNKIMj5I3JXew,20
16
+ lattice_sub-1.0.10.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ lattice-sub = lattice_subtraction.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kasinath Lab, University of Colorado Boulder
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ lattice_subtraction
@@ -0,0 +1,49 @@
1
+ """
2
+ Lattice Subtraction for Cryo-EM Micrographs
3
+
4
+ This package provides tools for computationally removing periodic crystal lattice
5
+ signals (Bragg spots) from cryo-EM micrographs to reveal non-periodic features
6
+ such as defects, individual particles, or molecular tags.
7
+
8
+ Main components:
9
+ - LatticeSubtractor: Core class for processing single images
10
+ - BatchProcessor: Parallel processing of multiple micrographs
11
+ - Config: Configuration management via YAML files
12
+ - generate_visualizations: Create comparison PNG images
13
+
14
+ Example:
15
+ >>> from lattice_subtraction import LatticeSubtractor, Config
16
+ >>> config = Config.from_yaml("params.yaml")
17
+ >>> subtractor = LatticeSubtractor(config)
18
+ >>> result = subtractor.process("micrograph.mrc")
19
+ >>> result.save("output.mrc")
20
+ """
21
+
22
+ __version__ = "1.0.10"
23
+ __author__ = "George Stephenson & Vignesh Kasinath"
24
+
25
+ from .config import Config
26
+ from .core import LatticeSubtractor
27
+ from .batch import BatchProcessor
28
+ from .io import read_mrc, write_mrc
29
+ from .visualization import (
30
+ generate_visualizations,
31
+ save_comparison_visualization,
32
+ create_comparison_figure,
33
+ )
34
+ from .ui import TerminalUI, get_ui, is_interactive
35
+
36
+ __all__ = [
37
+ "LatticeSubtractor",
38
+ "BatchProcessor",
39
+ "Config",
40
+ "read_mrc",
41
+ "write_mrc",
42
+ "generate_visualizations",
43
+ "save_comparison_visualization",
44
+ "create_comparison_figure",
45
+ "TerminalUI",
46
+ "get_ui",
47
+ "is_interactive",
48
+ "__version__",
49
+ ]