# google-deepmind/alphafold architecture

> Architecture diagram of the GitHub repository google-deepmind/alphafold, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/google-deepmind/alphafold
- Repository: https://github.com/google-deepmind/alphafold

## Overview

##### Project Type and Purpose
- The project is an advanced machine learning system for protein structure prediction. It implements the inference pipeline of AlphaFold—both monomer and multimer modes—with additional support for structure relaxation and external data preparation.
- Its purpose is to take protein sequence information (FASTA) as input, search genetic databases to build multiple sequence alignments (MSAs), process these features through a deep neural network (with a central Evoformer module) to predict 3D protein structures, and finally refine the output using a relaxation procedure.

##### File Structure
- Top-Level Directories: There are directories for the core model (alphafold/model), data processing (alphafold/data), and relaxation (alphafold/relax). There are also utility directories (common, notebooks, scripts) and container setup (docker).
- “scripts” and “docker” directories that simplify installation and execution, while “data” manages genetic databases and feature extraction.

##### README for Architectural Details
- The README describes how the system uses Docker images for containerization, integrates multiple sequence alignment tools (HHblits, Jackhmmer, etc.), and explains the high-level steps from data acquisition through prediction and finally to structure relaxation.
- Installation steps indicate that the system is run using containerized commands and scripts, ensuring that every major pipeline stage—from genetic database downloads to the final output—is modular and clearly separated.

A. Main Components to Represent:
- Input / Data Acquisition:
⁃ Protein sequence input (FASTA files)
⁃ Genetic database downloads and multiple sequence alignment (MSA) tools (HHblits, Jackhmmer, etc.)
- Data & Feature Processing:
⁃ Processing and parsing of MSAs and template searches (modules under alphafold/data and alphafold/common)
- Core Neural Network & Evoformer:
⁃ The central model module contains several components:
▪ The Evoformer: the transformer-based engine that processes the MSA and pairwise features.
▪ Additional modules such as “all_atom”, “layer_stack”, “geometry”, and “modules” that further process data into structural predictions.
⁃ For the Evoformer, specifically illustrate:
▪ How it takes as inputs:
- The MSA representation (capturing evolutionary relationships) and pair representation.
▪ Its internal processing:
- Multiple transformer-like blocks that alternately update the MSA features and pair features.
- Attention mechanisms (possibly cross-attention) and gating operations that capture residue interactions.
▪ The output:
- A refined representation that is fed into subsequent structure prediction modules.
- Structure Module and Relaxation:
⁃ The predicted structure is output in PDB format.
⁃ The relaxation module (in alphafold/relax) refines local geometry using physics-based approaches (e.g., Amber minimization).
- Output / Postprocessing:
⁃ Generation of various output files (features.pkl, rankings, PDB models, etc.), with clear directory structure in the final output.
- Deployment & Container Infrastructure:
⁃ Docker containers and deployment scripts (in the docker/ and scripts/ directories) that wrap all of these components together.

B. Determine Relationships and Interactions:
1. From Protein Input → Data Acquisition & MSA Search Layer.
2. From MSA Search → Data/Feature Processing.
3. From Feature Processing → Neural Network – which is split into:
▪ Evoformer block (detailed separately) that ingests and refines MSA/pair features.
▪ Subsequent modules (geometry and structure formulation).
4. From Neural Network → Structure Assembly.
5. From Structure Assembly → Relaxation Module.
6. Finally, the output is stored in a structured output directory.
- You may also include a control/monitoring sub-system showing configuration management (from config.py, MODEL_PRESETS in config) and test/validation (unit tests under various directories).

C. Highlight Architectural Patterns and Technologies:
- Modular design: clear separation between data handling, neural network inference (with Evoformer as a key module), and post-prediction relaxation.
- Containerization: Docker-based encapsulation ensures that genetic database operations and GPU-enabled neural network computation remain isolated.
- Use of deep learning frameworks: TensorFlow is used (under alphafold/model/tf) alongside special modules for geometry handling.
- Integration with external services: Tools for genetic search (HHblits, Jackhmmer, etc.) relay information to the main prediction pipeline.

- For this full inference pipeline (effectively a specialized “full-stack” application in bioinformatics), stress the isolation between the frontend (data acquisition, command-line inputs, Docker orchestration) and the backend (heavy-duty neural network inference with the Evoformer core and structure prediction).
- API-like boundaries between major components to highlight potential scaling or independent improvement, particularly around the Evoformer block where tuning or architectural modifications are common research topics.

##### Instructing the Principal Software Engineer
- Clear labels for each component: name the blocks “Input & MSA Search”, “Feature Extraction”, “Neural Network Inference (with Evoformer)”, “Structure Assembly & Relaxation”, and “Deployment/Monitoring”.
- Deep dive into the Evoformer component:
▪ Clearly specify that the Evoformer is responsible for reprocessing the MSA input and pair representations via multiple stacked transformer blocks.
▪ Illustrate input lines entering the Evoformer block (from feature extraction) and output lines leading to “geometry” and “structure assembly” modules.
▪ Annotate the internals with keywords such as “attention mechanism,” “pair update,” “MSA row-wise update,” and “residue interactions.”
▪ Emphasize that the Evoformer is iterative, possibly with loops indicating multiple recycles, which improves the accuracy of the predicted structure.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input & MSA Search Layer
    subgraph "Input & MSA Search"
        Pipeline["Protein Data Pipeline"]:::input
        Tools["MSA Tools"]:::input
    end

    %% Data & Feature Processing Layer
    subgraph "Data & Feature Processing"
        FProc["Feature Processing"]:::processing
        Common["Common Parsing"]:::processing
        Processed["Processed Features"]:::processing
    end

    %% Connect Input to Feature Processing
    Pipeline -->|"sends data"| FProc
    Pipeline -->|"sends data"| Common
    Tools -->|"provides MSA info"| FProc
    Tools -->|"provides MSA info"| Common
    FProc -->|"merges into"| Processed
    Common -->|"merges into"| Processed

    %% Neural Network Inference (with Evoformer)
    subgraph "Neural Network Inference (with Evoformer)"
        Evoformer["Evoformer Module"]:::network
        LS["Layer Stacking"]:::network
        Processed -->|"feeds features"| Evoformer
        Evoformer -->|"integrates results"| LS

        %% Deep Dive into Evoformer
        subgraph "Evoformer Deep Dive"
            MSA["MSA & Pair Representation"]:::deep
            TransBlock["Transformer Block<br>(attention, pair update, MSA update)"]:::deep
            Refined["Refined Features"]:::deep
            MSA -->|"processes"| TransBlock
            TransBlock -->|"iterative_recycling"| TransBlock
            TransBlock -->|"outputs"| Refined
        end
        Evoformer -->|"incorporates"| Refined
        LS -->|"applies stacking"| Evoformer
    end

    %% Geometry and Structure Prediction
    subgraph "Geometry & Structure Prediction"
        Geometry["Geometry Processing"]:::geometry
    end
    LS -->|"passes features"| Geometry

    %% Structure Assembly & Relaxation
    subgraph "Structure Assembly & Relaxation"
        Relax["Relaxation Module"]:::relax
    end
    Geometry -->|"feeds geometry"| Relax

    %% Output Generation
    Output["Output Generation<br>(PDB models, rankings, features)"]:::processing
    Relax -->|"finalizes structure"| Output

    %% Deployment & Monitoring
    subgraph "Deployment & Monitoring"
        Docker["Docker Container"]:::deploy
        Scripts["Deployment Scripts"]:::deploy
        Container["Container Deployment"]:::deploy
        Docker -->|"builds"| Container
        Scripts -->|"orchestrates"| Container
    end
    Output -->|"delivers results to"| Container

    %% Click Events
    click Pipeline "https://github.com/google-deepmind/alphafold/blob/main/alphafold/data/pipeline.py"
    click Tools "https://github.com/google-deepmind/alphafold/tree/main/alphafold/data/tools"
    click FProc "https://github.com/google-deepmind/alphafold/blob/main/alphafold/data/feature_processing.py"
    click Common "https://github.com/google-deepmind/alphafold/tree/main/alphafold/common"
    click Evoformer "https://github.com/google-deepmind/alphafold/blob/main/alphafold/model/modules.py"
    click LS "https://github.com/google-deepmind/alphafold/blob/main/alphafold/model/layer_stack.py"
    click Geometry "https://github.com/google-deepmind/alphafold/tree/main/alphafold/model/geometry"
    click Relax "https://github.com/google-deepmind/alphafold/tree/main/alphafold/relax"
    click Docker "https://github.com/google-deepmind/alphafold/tree/main/docker"
    click Scripts "https://github.com/google-deepmind/alphafold/tree/main/scripts"

    %% Styles
    classDef input fill:#f9c,stroke:#333,stroke-width:2px;
    classDef processing fill:#ccf,stroke:#333,stroke-width:2px;
    classDef network fill:#cfc,stroke:#333,stroke-width:2px;
    classDef deep fill:#fcf,stroke:#333,stroke-width:2px;
    classDef geometry fill:#ff9,stroke:#333,stroke-width:2px;
    classDef relax fill:#f99,stroke:#333,stroke-width:2px;
    classDef deploy fill:#9cf,stroke:#333,stroke-width:2px;
```
