|
| 1 | +""" |
| 2 | +Simulated Stack → RELION Reconstruction |
| 3 | +======================================= |
| 4 | +
|
| 5 | +This experiment shows how to: |
| 6 | +
|
| 7 | +1. build a synthetic dataset with ASPIRE, |
| 8 | +2. write the stack via ``ImageSource.save`` so RELION can consume it, and |
| 9 | +3. call :code:`relion_reconstruct` on the saved STAR file. |
| 10 | +""" |
| 11 | + |
| 12 | +# %% |
| 13 | +# Imports |
| 14 | +# ------- |
| 15 | + |
| 16 | +import logging |
| 17 | +from pathlib import Path |
| 18 | + |
| 19 | +import numpy as np |
| 20 | + |
| 21 | +from aspire.downloader import emdb_2660 |
| 22 | +from aspire.noise import WhiteNoiseAdder |
| 23 | +from aspire.operators import RadialCTFFilter |
| 24 | +from aspire.source import RelionSource, Simulation |
| 25 | + |
| 26 | +logger = logging.getLogger(__name__) |
| 27 | + |
| 28 | + |
| 29 | +# %% |
| 30 | +# Configuration |
| 31 | +# ------------- |
| 32 | +# We set a few parameters to initialize the Simulation. |
| 33 | +# You can safely alter ``n_particles`` (or change the voltages, etc.) when |
| 34 | +# trying this interactively; the defaults here are chosen for demonstrative purposes. |
| 35 | + |
| 36 | +output_dir = Path("relion_save_demo") |
| 37 | +output_dir.mkdir(exist_ok=True) |
| 38 | + |
| 39 | +n_particles = 512 |
| 40 | +snr = 0.25 |
| 41 | +voltages = np.linspace(200, 300, 3) # kV settings for the radial CTF filters |
| 42 | +star_path = output_dir / f"sim_n{n_particles}.star" |
| 43 | + |
| 44 | + |
| 45 | +# %% |
| 46 | +# Volume and Filters |
| 47 | +# ------------------ |
| 48 | +# Start from the EMDB-2660 ribosome map and build a small set of radial CTF filters |
| 49 | +# that RELION will recover as optics groups. |
| 50 | + |
| 51 | +vol = emdb_2660() |
| 52 | +ctf_filters = [RadialCTFFilter(voltage=kv) for kv in voltages] |
| 53 | + |
| 54 | + |
| 55 | +# %% |
| 56 | +# Simulate, Add Noise, Save |
| 57 | +# ------------------------- |
| 58 | +# Initialize the Simulation: |
| 59 | +# mix the CTFs across the stack, add white noise at a target SNR, |
| 60 | +# and write the particles and metadata to a RELION-compatible STAR/MRC stack. |
| 61 | + |
| 62 | +sim = Simulation( |
| 63 | + n=n_particles, |
| 64 | + vols=vol, |
| 65 | + unique_filters=ctf_filters, |
| 66 | + noise_adder=WhiteNoiseAdder.from_snr(snr), |
| 67 | +) |
| 68 | +sim.save(star_path, overwrite=True) |
| 69 | + |
| 70 | + |
| 71 | +# %% |
| 72 | +# Running ``relion_reconstruct`` |
| 73 | +# ------------------------------ |
| 74 | +# ``relion_reconstruct`` is an external RELION command, so we just show the call. |
| 75 | +# Run this in a RELION-enabled shell after generating the STAR file above. |
| 76 | + |
| 77 | +relion_cmd = [ |
| 78 | + "relion_reconstruct", |
| 79 | + "--i", |
| 80 | + str(star_path), |
| 81 | + "--o", |
| 82 | + str(output_dir / "relion_recon.mrc"), |
| 83 | + "--ctf", |
| 84 | +] |
| 85 | + |
| 86 | +print(" ".join(relion_cmd)) |
| 87 | + |
0 commit comments