# Making long trajectories with cryoDRGN graph\_traversal

CryoDRGN's graph traversal algorithm builds a nearest neighbor graph between all the latent embeddings, and then performs Dijkstra's algorithm to find the shortest path on the graph between the anchors nodes. The idea is to define a trajectory in latent space while remaining on the data manifold since we don't want to generate structures from unoccupied regions of the latent space.

The two commands to run are `cryodrgn graph_traversal` to create a latent space trajectory and `cryodrgn eval_vol` to generate volumes.

## 1) Create latent space trajectory

First, run `cryodrgn graph_traversal` to create a trajectory of z values. As a default, we recommend using the kmeans20 cluster centers as the anchor points:

```bash
(cryodrgn) $ cd analyze.50/ # assuming you've already run cryodrgn analyze on epoch 50
(cryodrgn) $ cryodrgn graph_traversal ../z.50.pkl --anchors $(cat kmeans20/centers_ind.txt) -o graph_traversal/z-path.txt --outind graph_traversal/ind-path.txt
```

Replace `z.50.pkl` with `z.N.pkl` where N is the epoch number you are analyzing.

Note that you can specify the indices of arbitrary particles as the anchor points of the trajectory. These indices can be retrieved from the interactive visualization sections of the jupyter notebook, or by using the annotation features of the interactive tool employed by the `cryodrgn filter` command.

## 2) Generate volumes

&#x20;`cryodrgn graph_traversal` will by default produce a text file containing a list of z values (`z-path.txt`). This may be converted to `.mrc` files with `cryodrgn eval_vol`:

```
(cryodrgn) $ cd graph_traversal
(cryodrgn) $ cryodrgn eval_vol ../../weights.50.pkl -c ../../config.yaml --zfile z-path.txt -o .
```

Replace `weights.50.pkl` with the epoch number you are analyzing.

{% hint style="info" %}
This may generate a few hundred density maps. To save disk space, you can generate downsampled volumes with `-d 128`.&#x20;
{% endhint %}

## 3) Create ChimeraX movie

In ChimeraX:

```
vol all level XYZ
vol all color cornflowerblue
mov record
mseries all
mov encode graph_traversal.isoXYZ.mp4 framerate 15
```

## 4) Create latent space movie

Scripts to help create a latent space movie of the associated trajectory (e.g. video, right) coming soon.&#x20;

{% embed url="<https://figshare.com/articles/media/S3_video_LSU_assembly/23574909>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ez-lab.gitbook.io/cryodrgn/making-long-trajectories-with-cryodrgn-graph_traversal.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
