# rjpenic/rafo architecture

> Architecture diagram of the GitHub repository rjpenic/rafo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rjpenic/rafo
- Repository: https://github.com/rjpenic/rafo

## Overview

RAFO predicts RNA 3D structures from sequence and also provides dataset preparation, training, evaluation, inference, and structure-refinement workflows. The graph follows documented entry points and relationships visible in excerpts or the SOURCE INDEX; some internal wiring and unsampled capabilities are represented only at the subsystem level.

Main entry points: [`rafo/model/model.py`](https://github.com/rjpenic/rafo/blob/main/rafo/model/model.py) (RNA folding model), [`rafo/lightning/model_wrapper.py`](https://github.com/rjpenic/rafo/blob/main/rafo/lightning/model_wrapper.py) (Lightning model wrapper), [`run.py`](https://github.com/rjpenic/rafo/blob/main/run.py) (Run CLI), [`rafo/data/preparation/pipelines.py`](https://github.com/rjpenic/rafo/blob/main/rafo/data/preparation/pipelines.py) (Preparation pipelines)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_prep_pipeline["Preparation pipelines<br/>[pipelines.py]"]
  node_prep_steps["Preparation steps<br/>[steps.py]"]
  node_prep_filters["Quality filters<br/>[filters.py]"]
  node_data_access["Dataset paths<br/>[data_access.py]"]
  node_data_module["Data module<br/>[datamodule.py]"]
  node_dataset["Structure and sequence datasets<br/>[dataset.py]"]
end

subgraph group_runtime["Model runtime"]
  node_model["RNA folding model<br/>[model.py]"]
  node_embedders["Sequence embedders<br/>[embedders.py]"]
  node_evoformer["Evoformer blocks<br/>[evoformer.py]"]
  node_recycling["Recycling<br/>[recycling.py]"]
  node_heads["Prediction heads<br/>[heads.py]"]
  node_structure_module["Structure module"]
end

subgraph group_learning["Training and evaluation"]
  node_config["Model and loss presets<br/>[config.py]"]
  node_wrapper["Lightning model wrapper<br/>[model_wrapper.py]"]
  node_loss["Structure losses<br/>[loss.py]"]
  node_metrics["Evaluation metrics<br/>[metrics.py]"]
end

subgraph group_structure["Structure utilities"]
  node_sec_struct["Secondary-structure features<br/>[sec_struct.py]"]
  node_external_tools["Structure prediction tools<br/>[external_tools.py]"]
  node_structure_constructor["Atom construction"]
end

subgraph group_tools["User tools"]
  node_prepare_cli["Prepare data CLI<br/>[prepare_data.py]"]
  node_run_cli["Run CLI<br/>[run.py]"]
  node_refine["Structure refinement<br/>[refine_structs.py]"]
  node_eval_script["Structure evaluation script<br/>[eval.py]"]
end

node_researcher(("RNA researcher"))
node_external_db[("PDB / RNA 3D Hub")]
node_prediction_files["Predicted structures"]

node_researcher -->|"prepares data"| node_prepare_cli
node_prepare_cli -->|"selects pipeline"| node_prep_pipeline
node_prep_pipeline -->|"runs steps"| node_prep_steps
node_prep_pipeline -->|"configures filters"| node_prep_filters
node_prep_pipeline -->|"uses paths"| node_data_access
node_prep_steps -->|"reads and writes"| node_data_access
node_prep_steps -->|"downloads structures"| node_external_db
node_researcher -->|"runs workflow"| node_run_cli
node_run_cli -->|"selects preset"| node_config
node_run_cli -->|"configures data"| node_data_module
node_data_module -->|"resolves paths"| node_data_access
node_data_module -->|"loads examples"| node_dataset
node_dataset -->|"builds features"| node_sec_struct
node_wrapper -->|"invokes model"| node_model
node_wrapper -->|"computes loss"| node_loss
node_wrapper -->|"logs metrics"| node_metrics
node_model -->|"builds embeddings"| node_embedders
node_model -->|"updates representations"| node_evoformer
node_model -->|"recycles features"| node_recycling
node_model -->|"produces predictions"| node_heads
node_model -->|"predicts coordinates"| node_structure_module
node_structure_module -->|"constructs atoms"| node_structure_constructor
node_researcher -->|"requests predictions"| node_run_cli
node_run_cli -->|"runs fit test predict"| node_wrapper
node_wrapper -->|"saves structures"| node_prediction_files
node_researcher -->|"evaluates structures"| node_eval_script
node_eval_script -->|"scores predictions"| node_prediction_files
node_researcher -->|"refines predictions"| node_refine
node_refine -->|"writes refined structures"| node_prediction_files
node_prep_steps -->|"calculates features"| node_external_tools
node_external_tools -.->|"refines structures"| node_prediction_files

click node_prepare_cli "https://github.com/rjpenic/rafo/blob/main/prepare_data.py"
click node_prep_pipeline "https://github.com/rjpenic/rafo/blob/main/rafo/data/preparation/pipelines.py"
click node_prep_steps "https://github.com/rjpenic/rafo/blob/main/rafo/data/preparation/steps.py"
click node_prep_filters "https://github.com/rjpenic/rafo/blob/main/rafo/data/preparation/filters.py"
click node_data_access "https://github.com/rjpenic/rafo/blob/main/rafo/data/data_access.py"
click node_data_module "https://github.com/rjpenic/rafo/blob/main/rafo/data/datamodule.py"
click node_dataset "https://github.com/rjpenic/rafo/blob/main/rafo/data/dataset.py"
click node_run_cli "https://github.com/rjpenic/rafo/blob/main/run.py"
click node_config "https://github.com/rjpenic/rafo/blob/main/rafo/config.py"
click node_wrapper "https://github.com/rjpenic/rafo/blob/main/rafo/lightning/model_wrapper.py"
click node_model "https://github.com/rjpenic/rafo/blob/main/rafo/model/model.py"
click node_embedders "https://github.com/rjpenic/rafo/blob/main/rafo/model/embedders.py"
click node_evoformer "https://github.com/rjpenic/rafo/blob/main/rafo/model/evoformer.py"
click node_recycling "https://github.com/rjpenic/rafo/blob/main/rafo/model/recycling.py"
click node_heads "https://github.com/rjpenic/rafo/blob/main/rafo/model/heads.py"
click node_structure_module "https://github.com/rjpenic/rafo/blob/main/rafo/model/structure_module.py"
click node_loss "https://github.com/rjpenic/rafo/blob/main/rafo/utils/loss.py"
click node_metrics "https://github.com/rjpenic/rafo/blob/main/rafo/utils/metrics.py"
click node_sec_struct "https://github.com/rjpenic/rafo/blob/main/rafo/utils/sec_struct.py"
click node_external_tools "https://github.com/rjpenic/rafo/blob/main/rafo/utils/external_tools.py"
click node_structure_constructor "https://github.com/rjpenic/rafo/blob/main/rafo/utils/spatial/struct_constructor.py"
click node_refine "https://github.com/rjpenic/rafo/blob/main/scripts/refine_structs.py"
click node_eval_script "https://github.com/rjpenic/rafo/blob/main/scripts/eval.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_prep_pipeline,node_prep_steps,node_prep_filters,node_data_access,node_data_module,node_dataset toneBlue
class node_model,node_embedders,node_evoformer,node_recycling,node_heads,node_structure_module,node_external_db toneAmber
class node_config,node_wrapper,node_loss,node_metrics toneMint
class node_sec_struct,node_external_tools,node_structure_constructor toneRose
class node_prepare_cli,node_run_cli,node_refine,node_eval_script,node_researcher,node_prediction_files toneIndigo
```

## Components

### Data preparation

- [Preparation pipelines](https://github.com/rjpenic/rafo/blob/main/rafo/data/preparation/pipelines.py): `rafo/data/preparation/pipelines.py`
- [Preparation steps](https://github.com/rjpenic/rafo/blob/main/rafo/data/preparation/steps.py): `rafo/data/preparation/steps.py`
- [Quality filters](https://github.com/rjpenic/rafo/blob/main/rafo/data/preparation/filters.py): `rafo/data/preparation/filters.py`
- [Dataset paths](https://github.com/rjpenic/rafo/blob/main/rafo/data/data_access.py): `rafo/data/data_access.py`
- [Data module](https://github.com/rjpenic/rafo/blob/main/rafo/data/datamodule.py): `rafo/data/datamodule.py`
- [Structure and sequence datasets](https://github.com/rjpenic/rafo/blob/main/rafo/data/dataset.py): `rafo/data/dataset.py`

### Model runtime

- [RNA folding model](https://github.com/rjpenic/rafo/blob/main/rafo/model/model.py): `rafo/model/model.py`
- [Sequence embedders](https://github.com/rjpenic/rafo/blob/main/rafo/model/embedders.py): `rafo/model/embedders.py`
- [Evoformer blocks](https://github.com/rjpenic/rafo/blob/main/rafo/model/evoformer.py): `rafo/model/evoformer.py`
- [Recycling](https://github.com/rjpenic/rafo/blob/main/rafo/model/recycling.py): `rafo/model/recycling.py`
- [Prediction heads](https://github.com/rjpenic/rafo/blob/main/rafo/model/heads.py): `rafo/model/heads.py`
- [Structure module](https://github.com/rjpenic/rafo/blob/main/rafo/model/structure_module.py): `rafo/model/structure_module.py`

### Training and evaluation

- [Model and loss presets](https://github.com/rjpenic/rafo/blob/main/rafo/config.py): `rafo/config.py`
- [Lightning model wrapper](https://github.com/rjpenic/rafo/blob/main/rafo/lightning/model_wrapper.py): `rafo/lightning/model_wrapper.py`
- [Structure losses](https://github.com/rjpenic/rafo/blob/main/rafo/utils/loss.py): `rafo/utils/loss.py`
- [Evaluation metrics](https://github.com/rjpenic/rafo/blob/main/rafo/utils/metrics.py): `rafo/utils/metrics.py`

### Structure utilities

- [Secondary-structure features](https://github.com/rjpenic/rafo/blob/main/rafo/utils/sec_struct.py): `rafo/utils/sec_struct.py`
- [Structure prediction tools](https://github.com/rjpenic/rafo/blob/main/rafo/utils/external_tools.py): `rafo/utils/external_tools.py`
- [Atom construction](https://github.com/rjpenic/rafo/blob/main/rafo/utils/spatial/struct_constructor.py): `rafo/utils/spatial/struct_constructor.py`

### User tools

- [Prepare data CLI](https://github.com/rjpenic/rafo/blob/main/prepare_data.py): `prepare_data.py`
- [Run CLI](https://github.com/rjpenic/rafo/blob/main/run.py): `run.py`
- [Structure refinement](https://github.com/rjpenic/rafo/blob/main/scripts/refine_structs.py): `scripts/refine_structs.py`
- [Structure evaluation script](https://github.com/rjpenic/rafo/blob/main/scripts/eval.py): `scripts/eval.py`

### Other components

- **RNA researcher**
- **PDB / RNA 3D Hub**
- **Predicted structures**

## Connections

- RNA researcher → Prepare data CLI: prepares data
- Prepare data CLI → Preparation pipelines: selects pipeline (evidence: `prepare_data.py`)
- Preparation pipelines → Preparation steps: runs steps (evidence: `rafo/data/preparation/pipelines.py`)
- Preparation pipelines → Quality filters: configures filters (evidence: `rafo/data/preparation/pipelines.py`)
- Preparation pipelines → Dataset paths: uses paths (evidence: `rafo/data/preparation/pipelines.py`)
- Preparation steps → Dataset paths: reads and writes (evidence: `rafo/data/preparation/steps.py`)
- Preparation steps → PDB / RNA 3D Hub: downloads structures (evidence: `rafo/data/preparation/steps.py`)
- RNA researcher → Run CLI: runs workflow
- Run CLI → Model and loss presets: selects preset (evidence: `run.py`)
- Run CLI → Data module: configures data (evidence: `run.py`)
- Data module → Dataset paths: resolves paths (evidence: `rafo/data/datamodule.py`)
- Data module → Structure and sequence datasets: loads examples (evidence: `rafo/data/datamodule.py`)
- Structure and sequence datasets → Secondary-structure features: builds features (evidence: `rafo/data/dataset.py`)
- Lightning model wrapper → RNA folding model: invokes model (evidence: `rafo/lightning/model_wrapper.py`)
- Lightning model wrapper → Structure losses: computes loss (evidence: `rafo/lightning/model_wrapper.py`)
- Lightning model wrapper → Evaluation metrics: logs metrics (evidence: `rafo/lightning/model_wrapper.py`)
- RNA folding model → Sequence embedders: builds embeddings (evidence: `rafo/model/model.py`)
- RNA folding model → Evoformer blocks: updates representations (evidence: `rafo/model/model.py`)
- RNA folding model → Recycling: recycles features (evidence: `rafo/model/model.py`)
- RNA folding model → Prediction heads: produces predictions (evidence: `rafo/model/model.py`)
- RNA folding model → Structure module: predicts coordinates (evidence: `rafo/model/model.py`)
- Structure module → Atom construction: constructs atoms (evidence: `rafo/model/structure_module.py`)
- RNA researcher → Run CLI: requests predictions
- Run CLI → Lightning model wrapper: runs fit test predict (evidence: `run.py`)
- Lightning model wrapper → Predicted structures: saves structures (evidence: `rafo/lightning/model_wrapper.py`)
- RNA researcher → Structure evaluation script: evaluates structures
- Structure evaluation script → Predicted structures: scores predictions
- RNA researcher → Structure refinement: refines predictions
- Structure refinement → Predicted structures: writes refined structures
- Preparation steps → Structure prediction tools: calculates features (evidence: `rafo/data/preparation/steps.py`)
- Structure prediction tools → Predicted structures: refines structures
