.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_experiments/save_simulation_relion_reconstruct.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_experiments_save_simulation_relion_reconstruct.py: Simulated Stack to RELION Reconstruction ======================================== This experiment shows how to: 1. build a synthetic dataset with ASPIRE, 2. write the stack via ``ImageSource.save`` so RELION can consume it, and 3. call :code:`relion_reconstruct` on the saved STAR file. .. GENERATED FROM PYTHON SOURCE LINES 13-15 Imports ------- .. GENERATED FROM PYTHON SOURCE LINES 15-29 .. code-block:: Python import logging from pathlib import Path import numpy as np from aspire.downloader import emdb_2660 from aspire.noise import WhiteNoiseAdder from aspire.operators import RadialCTFFilter from aspire.source import Simulation logger = logging.getLogger(__name__) .. GENERATED FROM PYTHON SOURCE LINES 30-35 Configuration ------------- We set a few parameters to initialize the Simulation. You can safely alter ``n_particles`` (or change the defocus values, etc.) when trying this interactively; the defaults here are chosen for demonstrative purposes. .. GENERATED FROM PYTHON SOURCE LINES 35-47 .. code-block:: Python output_dir = Path("relion_save_demo") output_dir.mkdir(exist_ok=True) n_particles = 512 snr = 0.5 defocus = np.linspace( 15000, 25000, 7 ) # defocus values for the radial CTF filters (angstroms) star_file = f"sim_n{n_particles}.star" star_path = output_dir / star_file .. GENERATED FROM PYTHON SOURCE LINES 48-52 Volume and Filters ------------------ Start from the EMDB-2660 ribosome map and build a small set of radial CTF filters that RELION will recover as optics groups. .. GENERATED FROM PYTHON SOURCE LINES 52-57 .. code-block:: Python vol = emdb_2660() ctf_filters = [RadialCTFFilter(defocus=d) for d in defocus] .. GENERATED FROM PYTHON SOURCE LINES 58-63 Simulate, Add Noise, Save ------------------------- Initialize the Simulation: mix the CTFs across the stack, add white noise at a target SNR, and write the particles and metadata to a RELION-compatible STAR/MRC stack. .. GENERATED FROM PYTHON SOURCE LINES 63-73 .. code-block:: Python sim = Simulation( n=n_particles, vols=vol, unique_filters=ctf_filters, noise_adder=WhiteNoiseAdder.from_snr(snr), ) sim.save(star_path, overwrite=True) .. GENERATED FROM PYTHON SOURCE LINES 74-79 Running ``relion_reconstruct`` ------------------------------ ``relion_reconstruct`` is an external RELION command, so we just show the call. Run this, from the output directory, in a RELION-enabled shell after generating the STAR file above. .. GENERATED FROM PYTHON SOURCE LINES 79-81 .. code-block:: Python logger.info(f"relion_reconstruct --i {star_file} " f"--o 'relion_recon.mrc' --ctf") .. _sphx_glr_download_auto_experiments_save_simulation_relion_reconstruct.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: save_simulation_relion_reconstruct.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: save_simulation_relion_reconstruct.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: save_simulation_relion_reconstruct.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_