> 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.md).

# CryoDRGN-AI ab initio reconstruction

how to use the command \<cryodrgn abinit>

In cryoDRGN v4.2.0 we replaced the existing *ab initio* reconstruction commands `abinit_homo` and `abinit_het` which implemented the cryoDRGN2 method with the new cryoDRGN-AI *ab initio* method implemented under `cryodrgn abinit`, thus replacing separate commands for homogeneous and heterogeneous ab-initio models with a single command for both:

```bash
# cryoDRGN-AI ab initio reconstruction
(cryodrgn) $ cryodrgn abinit -h
```

## Getting started

The `cryodrgn abinit` command uses a similar interface as the `cryodrgn abinit_het` and `cryodrgn abinit_homo` reconstruction commands documented in the [cryoDRGN manual](https://ez-lab.gitbook.io/cryodrgn/), and relies on the same data pre-processing steps.

Required arguments for the command are:

* Extracted single particle images in a `.mrcs/.txt/.star/.cs` particle stack, ideally clean from edge, ice, or hot pixel artifacts.
* CTF parameters in a `.pkl` file.
* Path to an output folder where experiment results will be saved.
* The dimension of the z-latent-space (0 for homogeneous reconstruction)

The last three are passed to the command using the `--ctf`, `-o`, and `--zdim` flags respectively, so a typical command to run *ab initio* volume reconstruction would look like:

{% code overflow="wrap" %}

```bash
cryodrgn abinit particles_128.mrcs --ctf ctf.pkl -o 001_drgnai_abinit_zdim.4/ --zdim 4
```

{% endcode %}

### Important parameters

Additional parameters to the `abinit` command we recommend you consider using include:

* **`--lazy`** for lazy data processing, necessary when using large datasets in order to avoid out-of-memory issues at the expense of runtime performance
* **`--multigpu`** for using multiple GPU cores for training if available, speeding up runtimes
* **`--ind`** a `.pkl` file containing a 1-D numpy array of `0...n-1` indices used to filter particles in the input image stack
* **`--num-epochs`** the total number of epochs (pose search + SGD) to use when training; does not include the pretraining epoch
  * **`--epochs-pose-search`**, **`--epochs-sgd`**, and **`--n-imgs-pose-search`** for more fine-tuned control of epochs; default behavior is to use 2 epochs of pose search and 28 epochs of SGD
* **`--dim`** sets the number of dimensions cryoDRGN-AI uses to model the hypervolume
  * **`--layers`** number of layers in the neural net used to model the hypervolume
* **`--load`** used to point to a `.pkl` of saved model weights previously output by a cryoDRGN-AI model
  * **`--load-poses`** can be used to also point to a `poses.<epoch>.pkl` file output by a cryoDRGN-AI model; the default behavior when using `--load` is to look for `poses.<epoch>.pkl` in the same place
* **`--uninvert-data`** when the input image stack is dark-on-light instead of the usual light-on-dark, as is the case for e.g. EMPIAR-10076
* **`--datadir`** optional path to directory containing base `.mrcs` image stacks when using a `.star` file for the particle stack

See our [API](https://ez-lab.gitbook.io/cryodrgn/cryodrgn-ai-ab-initio-reconstruction/cryodrgn-abinit-command-api) for more detailed information about all the parameters available for use with cryoDRGN-AI.
