# hr2d run config: every option, at its default value.
# Parameters marked with (*) are optional. Any option can also be set on the command line:
#   hr2d run config.yaml --set n_classes=20 --set search.psi_step=6

star: /path/to/particles.star          # RELION 3.0 or 3.1+ particle STAR file (only its CTF is read)
project_dir: /path/to/relion/project   # (*) image paths in the STAR file are relative to it
out_dir: runs/run                      # (*) created if missing

n_classes: 50                          # (*) K
iterations: 25                         # (*) full passes over the particles
algorithm: hartigan                    # (*) "hartigan" or "lloyd" (batch k-means, same search)
seed: 0                                # (*) initial classes, angles and visiting order

# Particle contrast in the raw images: "light-on-dark" (light particles on a dark background,
# RELION's convention) or "dark-on-light" (inverted on loading, as RELION's --invert_contrast).
# Check it on the raw pixels: a wrong sign gives classes that look like noise.
image_sign: light-on-dark              # (*)

particle_diameter: null                # (*) Å; default (box - 5) * pixel size, as RELION.
                                       #     Sets the Fourier radius of the coarse search pass
ini_high: null                         # (*) Å; first resolution, default box * apix / round(0.07 box)
incr_size: 10                          # (*) Fourier pixels added beyond the estimated resolution
tau2_fudge: 2.0                        # (*) T of the SSNR resolution rule (RELION --tau2_fudge)
full_resolution: false                 # (*) true: no frequency marching, always up to Nyquist

padding_factor: 2                      # (*) oversampling of the class reference grid (RELION --pad)
interpolation: bilinear                # (*) "bilinear" or "nearest"
gridding_correction: false             # (*) RELION's griddingCorrect on the class means
reference_mask: box                    # (*) "box" (circle at the box radius), "diameter"
                                       #     (soft circle of particle_diameter) or "none"
reference_mask_edge: 5.0               # (*) soft edge (px) of the "diameter" mask
center_classes: true                   # (*) move each class's centre of mass to the box centre

use_star_offsets: false                # (*) true: start the offsets from the STAR file's rlnOrigin
max_shift_fraction: 0.2                # (*) |shift| <= this fraction of the box size

half_set_resolution: true              # (*) per-class half-set FRC resolutions and a class gallery
                                       #     every iteration

# GPU memory. "auto" keeps every particle on the GPU when they fit in gpu_memory_fraction of the
# free GPU memory; otherwise particles are streamed in chunks, kept in host memory ("cpu") or
# re-read from the stacks every pass ("lazy"). Nothing is written to disk.
particles_on_gpu: auto                 # (*) "auto" or a number of particles per chunk
particle_storage: auto                 # (*) "auto", "gpu", "cpu" or "lazy"
gpu_memory_fraction: 0.4               # (*)
cpu_memory_fraction: 0.5               # (*)
device: cuda                           # (*)

preprocess:
  downsample_box: null                 # (*) Fourier-crop the images to this box (null: keep)
  window_inner: 0.85                   # (*) soft circular window: starts at this fraction of the
  window_outer: 0.99                   # (*)     box radius and reaches zero here
  whiten: true                         # (*) whiten with the noise spectrum of the box corners
  normalize: true                      # (*) rescale each image to unit corner-noise power
  max_images_for_noise: 5000           # (*) images used to estimate the noise spectrum
  chunk_size: 2048                     # (*) images preprocessed at once
  image_padding: 1                     # (*) zero-pad the images by this factor before the FFT

search:
  pose_search: relion                  # (*) "relion" or "hierarchical" (see below)
  psi_step: 12.0                       # (*) coarse in-plane angle step, degrees (RELION --psi_step)
  offset_range: 5.0                    # (*) translation search radius around the previous offset,
                                       #     pixels (RELION --offset_range)
  offset_step: 2.0                     # (*) translation step, pixels (RELION --offset_step)
  oversampling: 1                      # (*) fine pass: psi and shifts at step / 2 (0: no fine pass)
  n_candidate_poses: 2                 # (*) coarse poses kept per class for the fine pass
  n_candidate_classes: 5               # (*) classes refined in the fine pass (plus the own class)
  batch_size: 128                      # (*) images searched and moved at once (1: exact online
                                       #     Hartigan, one image at a time)
  images_per_block: 8                  # (*) images per matrix-product block in the coarse pass
  # pose_search: hierarchical only
  hierarchical_base_level: 2           # (*) base grid of 6 * 2**level angles (2: 24 angles, 15°)
  hierarchical_n_rounds: 5             # (*) refinements of the angle grid after the first
  hierarchical_n_angles_kept: 6        # (*) angles kept per class and level
  hierarchical_shift_range: null       # (*) px, square window around 0 (null: the max shift)

# cryoSPARC-style schedule, off by default (online_iterations: 0). When on, the run has
# online_iterations + full_iterations iterations and `iterations` is ignored.
minibatch:
  online_iterations: 0                 # (*) cryoSPARC's "number of online-EM iterations" is 20
  particles_per_class: 100             # (*) minibatch size = particles_per_class * n_classes
  full_iterations: 1                   # (*) full passes at the end
