> For the complete documentation index, see [llms.txt](https://ez-lab.gitbook.io/cryodrgn/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ez-lab.gitbook.io/cryodrgn/cryodrgn-ai-ab-initio-reconstruction/cryodrgn-ai-ab-initio-empiar-10076-tutorial.md).

# CryoDRGN-AI ab initio EMPIAR-10076 tutorial

ab initio reconstruction with the 50S dataset using cryoDRGN-AI volume reconstruction

Here we provide a walkthrough of an *ab initio* analysis of the **assembling ribosome dataset (EMPIAR-10076)** based on the results presented in Figure 2b of the [cryoDRGN-AI manuscript](https://www.nature.com/articles/s41592-025-02720-4). We will use the version of cryoDRGN-AI implemented with the `cryodrgn abinit` command — the original experiment was done using the [DRGN-AI package](https://github.com/ml-struct-bio/drgnai).

<figure><img src="https://3487200171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz7E99j3jJUSLJDvU43U6%2Fuploads%2F3J3KuJOM5hAJ7Zy2oGXb%2FScreenshot%202026-03-19%20at%2011.53.55%E2%80%AFAM.png?alt=media&amp;token=64c9162b-3ce7-4317-8ec4-44bcde285d2d" alt=""><figcaption><p><a href="https://www.nature.com/articles/s41592-025-02720-4/figures/2">Figure 2B</a> from the Nature Methods (2025) cryoDRGN-AI manuscript</p></figcaption></figure>

We will follow an abbreviated version of the **general recommended workflow** for cryoDRGN training:

1. First, train on lower resolution images (e.g. D=128) using the default architecture (fast) as an initial pass to sanity check results and remove junk particles.
2. After any particle filtering, then train a larger model or longer model with the `--dim 1024` and `--epochs-pose-search=5` arguments — these can potentially lead to learning more heterogeneity.

For a full step-by-step tutorial that includes all of the preprocessing steps required to prepare an input dataset for analysis with cryoDRGN, see the [original tutorial](/cryodrgn/cryodrgn-empiar-10076-tutorial.md), which is broadly similar to the material below but done using the `cryodrgn train_vae` command.

### 1) Initial CryoDRGN-AI training <a href="#id-1-initial-cryodrgn-ai-training" id="id-1-initial-cryodrgn-ai-training"></a>

We begin by running the default architecture, which is designed to run relatively quickly to provide an initial pass for checking results and filtering particles. We assume here that we have downsampled our particles to D=128 at `particles.128.txt` :

{% code title="" fullWidth="true" expandable="true" %}

```bash
cryodrgn abinit particles.128.mrcs --zdim 4 --lazy --ctf ctf.pkl -o 50S_abinit/001_defaults.128/ --uninvert-data
```

{% endcode %}

**Key arguments for the abinit command**

* **`particles.128.mrcs`** input particles (.mrcs, .star, .txt, or .cs) format
* **`--ctf ctf.pkl`** CTF parameters in a cryodrgn .pkl file
* **`--zdim 4`** to specify the dimension of the latent variable (i.e. each particle will get assigned an 4-dimensional vector as its *latent embedding*)
  * use **`--zdim 0`** for homogeneous *ab initio* reconstruction
* **`-o 50S_abinit/001_defaults.128/`**, a clean output directory (will get created if it does not already exist)
* **`--uninvert-data`** flag to flip the data sign of the particles dataset (this flag is not needed for most cryo-EM datasets)

With one H100 GPU we were able to finish training this model in a total of 2h 36min, with the pose search epochs taking roughly forty minutes each and the SGD epochs taking a little over a minute:

{% code title="50S\_abinit/001\_defaults.128/run.log" expandable="true" %}

```
...
# [Train Epoch: 30/30] [84992/131899 particles]
# [Train Epoch: 30/30] [94976/131899 particles]
# [Train Epoch: 30/30] [104960/131899 particles]
# [Train Epoch: 30/30] [114944/131899 particles]
# [Train Epoch: 30/30] [124928/131899 particles]
# =====> SGD Epoch: 30 finished in 0:01:07.818272; total loss = 0.643564
Finished in 2:36:14.061979 (0:05:12.468733 per epoch)
```

{% endcode %}

We use ChimeraX to examine the volumes reconstructed at each checkpoint epoch and saved as `reconstruct.<epoch>.mrc` in our output folder. By default cryoDRGN will create a checkpoint after every pretraining and HPS epoch as well as every 5th SGD epoch:

<figure><img src="https://3487200171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz7E99j3jJUSLJDvU43U6%2Fuploads%2FGQPIWEO6TsK5sbX3gBPG%2Freconstruct-vols.gif?alt=media&amp;token=621f793a-9bd2-4a95-b72c-6deb75154423" alt=""><figcaption></figcaption></figure>

#### Analyzing cryoDRGN-AI results <a href="#analyzing-cryodrgn-ai-results" id="analyzing-cryodrgn-ai-results"></a>

The `abinit` command — like the other reconstruction commands included in cryoDRGN — automatically runs `cryodrgn analyze` on the final output epoch once model training is complete. The output of these analyses can be found in our cryoDRGN experiments folder under `analyze.30/`:

<figure><img src="https://3487200171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz7E99j3jJUSLJDvU43U6%2Fuploads%2FCcvTb26gFa0uVTB7Qrfi%2FScreenshot%202026-03-18%20at%2010.53.14%E2%80%AFPM.png?alt=media&amp;token=e0926bf7-68e8-4a72-8dd6-4561b02923ca" alt=""><figcaption></figcaption></figure>

These outputs are the same as for commands such as `cryodrgn train_vae` and are fully described in our [main tutorial](https://ez-lab.gitbook.io/cryodrgn-v4.2.0-draft/cryodrgn-empiar-10076-tutorial#id-5-cryodrgn-analysis).

We can verify that our ab-initio model still identifies heterogeneity found when using fixed-pose reconstruction with the visualization `kmeans20/umap_hex.png` of the z-latent-space. This is generated using the model outputs along with the images found to be centroids using k-mean clustering on the z-latent-space:

<figure><img src="https://3487200171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz7E99j3jJUSLJDvU43U6%2Fuploads%2FcVaws1zJxDcsd6OEvwwM%2Fumap_hex.png?alt=media&amp;token=41c0e940-ebb5-4661-9a33-7d2550fb7609" alt=""><figcaption></figcaption></figure>

We can again use ChimeraX to visualize the corresponding volumes that have been reconstructed by cryoDRGN-AI for these centroid images and are saved in the same place:

<figure><img src="https://3487200171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz7E99j3jJUSLJDvU43U6%2Fuploads%2FdkHLUh4J0QjKCNlcKKEQ%2Fkmeans-vols.gif?alt=media&amp;token=7357afd0-4075-426f-a4e0-0896f3f1466b" alt=""><figcaption></figcaption></figure>

#### Restarting and extending training from a previous checkpoint

As with `train_vae`, if cryoDRGN-AI training was interrupted before completing or you would like to train a finished model for more epochs you can use the `--load` argument with a saved checkpoint `weights` file to resume training. By specifying a new value for `--num-epochs/-n`, you can also make the model train for more epochs — here we restart at the 25th epoch and train for a total of 40 epochs, thus using ten more epochs than the original training run:

{% code fullWidth="true" %}

```bash
cryodrgn abinit particles.128.mrcs --zdim 4 --lazy --ctf ctf.pkl --load 50S_abinit/001_defaults.128/weights.25.pkl -n 40 -o 50S_abinit/001_defaults.128/ --uninvert-data
```

{% endcode %}

Checkpoints will still be created as before, along with an analysis on the updated final epoch of training:

<figure><img src="https://3487200171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz7E99j3jJUSLJDvU43U6%2Fuploads%2Fhsx7q828VrWI3jaowoLi%2Freconstruct-vols.gif?alt=media&amp;token=9a09e237-d84f-4946-902f-384a36c8ceba" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3487200171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz7E99j3jJUSLJDvU43U6%2Fuploads%2FCW7BXTwOavJtx5IP8tGY%2Fumap_hex.png?alt=media&amp;token=3110da80-6b20-442e-8ebf-d3ac56917cd9" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3487200171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz7E99j3jJUSLJDvU43U6%2Fuploads%2FufG3uvs77L9d66M8jBdO%2Fkmeans-vols.gif?alt=media&amp;token=8e1b11fb-8302-41f0-8606-986dea741bf0" alt=""><figcaption></figcaption></figure>

### 2) Retraining cryoDRGN-AI with a larger model

Having confirmed that our method can reconstruct the space of 50S volumes using the default model parameters we now move on to trying a larger model to see if we can find more heterogeneity in this dataset or better-reconstructed volumes:

<pre class="language-bash" data-title="" data-full-width="true" data-expandable="true"><code class="lang-bash"><strong>cryodrgn abinit particles.128.mrcs --zdim 4 --dim 1024 --lazy --ctf ctf.pkl -o 50S_abinit/001_dim-1024.128/ --uninvert-data
</strong></code></pre>

This time training took a total of 13h 10min on a H100 GPU: pose search epochs took four hours and SGD epochs took 2.6 minutes.

We can once again look at the reconstructed volumes at checkpoint epochs, as well as the z-latent-space UMAP embedding produced by our analysis tool with the final training epoch:

<figure><img src="https://3487200171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz7E99j3jJUSLJDvU43U6%2Fuploads%2FONMvx5gf6m3iSad6C7rL%2Freconstruct-vols.gif?alt=media&amp;token=ff22cd62-f476-47f0-9700-a04b57e992d4" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3487200171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz7E99j3jJUSLJDvU43U6%2Fuploads%2Fzbu5bXoP4QT1eEFbx4a3%2Fumap_hex.png?alt=media&amp;token=702fccea-4b59-430b-9172-802453cdb500" alt=""><figcaption></figcaption></figure>
