Skip to main content

Hartigan 2D classification of cryo-EM particle images with a RELION-style pose search

Summary

hr2d is a GPU (PyTorch) program for cryo-EM 2D classification. It classifies particle images with an algorithm inspired by Hartigan's k-means algorithm. Our strategy is inspired by features in RELION's 2D classification. Specifically, we adapt their angle and shift search, frequency marching, and rotation operators; in addition to their starfile I/O interface and CTF definition.

Details and results are available in our paper (link coming soon). Instructions for reproducing the paper results are below.

Full documentation is available at https://lederman-group.github.io/HR2D/.

Installation

HR2D has been tested on Linux (RHEL 8) with NVIDIA V100, A100 and Quadro RTX 8000 GPUs, Python 3.11, PyTorch 2.5.1 and CUDA 12.4. An NVIDIA GPU is required for real datasets.

We recommend a python environment, with PyTorch installed first for your CUDA version. For example, with mamba:

mamba create -n hr2d python==3.11
mamba activate hr2d
pip install torch --index-url https://download.pytorch.org/whl/cu124   # insert your CUDA version!
pip install "hr2d @ git+https://github.com/Lederman-Group/HR2D.git"

Choose a PyTorch CUDA build compatible with your NVIDIA driver using the PyTorch installation instructions (https://pytorch.org/get-started/locally/). The command above uses CUDA 12.4.

Quick start

hr2d run config.yaml                                 # a RELION STAR file in, RELION outputs out
hr2d run config.yaml --set n_classes=20 --set search.psi_step=6
hr2d run config.yaml --resume                        # continue from out_dir/checkpoint.pt

A minimal config.yaml:

star: /path/to/particles.star          # RELION 3.0 or 3.1+ particle STAR file
project_dir: /path/to/relion/project   # image paths in the STAR file are relative to it
out_dir: ./hr2d_run
n_classes: 50
iterations: 25
image_sign: light-on-dark              # or dark-on-light: particles darker than the background

Tutorial

The tutorial classifies a small simulated dataset (four shapes at SNR 0.1, 26 MB) in under a minute.

2D classification input

See the input documentation: every option of the YAML file, the outputs, restarting, the cryoSPARC-style minibatch schedule and SLURM.

Analysis and comparison with other programs

See the analysis documentation: converting RELION, cryoSPARC and Xmipp results to one convention, and scoring every method with the same k-means loss, half-set resolutions and NMI.

The method

See the method page: what is taken from RELION, what is Hartigan, and a glossary from the code's names to the paper's symbols. The angle, origin and CTF conventions are in docs/relion_conventions.md.

Reproducing paper results

All the input STAR files, run scripts and config files, every method's results, the simulated datasets, the analysis scripts and the instructions to reproduce our results are available on Zenodo (DOI 10.5281/zenodo.24563010). The experimental particle images are public on EMPIAR (EMPIAR-10028, 10076, 10096 and 10180). These results were obtained with the version of HR2D tagged paper-runs.

LLM disclosure

Claude was used to assist in writing the HR2D code, adapting our preliminary implementation in JAX and reimplementing select RELION strategies.

Copyright (c) 2026 David Silva-Sánchez, Roy R. Lederman and Roey Yadgar. Upstream portions retain their respective copyright notices.

HR2D is free software, distributed under the GNU General Public License, version 3 or (at your option) any later version. See LICENSE.

HR2D reimplements selected RELION strategies in Python/PyTorch, including angle and shift search, rotation operators, CTF calculations, frequency marching and STAR-file conventions. RELION's source code was consulted during development.

When redistributing this code or modified versions, retain the applicable HR2D and upstream copyright, license and warranty notices, and comply with the GNU GPL.

The original RELION notice is reproduced below:

Author: "Sjors H.W. Scheres"
MRC Laboratory of Molecular Biology

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

This complete copyright notice must be included in any revised version of the
source code. Additional authorship citations may be added, but existing
author citations must be preserved.

The CTF code (src/hr2d/fourier/ctf.py) also carries a copyright notice from Xmipp (CSIC) authors. The complete notices for each adapted file are in its header.

Citation

If you use hr2d, please cite our paper:

@unpublished{hr2d,
  title  = {The Case for Greed in Cryo-EM 2D Classification},
  author = {Silva-S{\'a}nchez, David and Yadgar, Roey and Lederman, Roy R.},
  note   = {Under review},
  year   = {2026},
}

Contact

Please submit any bug reports, feature requests, or general feedback as a GitHub issue or discussion.

Contributing

If you are contributing to this project, please install the package with the following command:

pip install -e ".[dev]"

This installs the development dependencies, the most important being ruff, pre-commit and pytest. After installation, activate your environment and install the pre-commit hooks:

pre-commit install

Make sure that your code is formatted and passes the tests before opening a pull request:

pre-commit run --all-files
pytest tests

Metadata

Release files for hr2d 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hr2d 0.1.0
File Size Uploaded Provenance Actions
hr2d-0.1.0.tar.gz 403.0 kB With provenance Details for hr2d-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hr2d 0.1.0
File Interpreter ABI Platform Actions
hr2d-0.1.0-py3-none-any.whl Python 3 none any Details for hr2d-0.1.0-py3-none-any.whl

Total release size: 485.8 kB

Release files / hr2d-0.1.0.tar.gz

Download URL hr2d-0.1.0.tar.gz
Size 403.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a871f6fc630a0fa62dce93686dfe63348386f800ffbb87fd0cd1962a3c4a7fdc
BLAKE2b-256 checksum
How to use checksums
98593989bd169e7a10a701b85eb5ce4fdb62c2b952478ce7fd0d8ba96ae1e864
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / hr2d-0.1.0-py3-none-any.whl

Download URL hr2d-0.1.0-py3-none-any.whl
Size 82.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a3f860863be255b4a3c702fc62a6979d8293ef479606c38aa28686beb18b37ce
BLAKE2b-256 checksum
How to use checksums
cf83941206453fd09d06ead68ab7601ff4b6df212edbbbf66ada3f1f1d0bd87e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Security for hr2d 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for hr2d-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page