# dauparas/ligandmpnn architecture

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

- Interactive diagram: https://gitdiagram.com/dauparas/ligandmpnn
- Repository: https://github.com/dauparas/ligandmpnn

## Overview

##### Main Components
- Command-Line Interface (CLI) Layer: Represented by the main entry points (run.py, score.py, run_examples.sh, sc_examples.sh) and shell scripts that execute various workflows.
- Input & Configuration Management: This consists of the “inputs” directory (PDB files, JSON files with residue biases/fixes), configuration scripts (openfold/config.py), and the get_model_params.sh script to download model weights.
- Data Parsing & Pipeline: Under the “openfold/data” subpackage, you have several modules handling parsing (pdb/mmcif parsing, residue indexing, template handling) and transformation logic that prepares the input for the model. Also include the “data_utils.py” at the top level.
- Model & Inference Core: Show the integration of the different MPNN models. This includes components for model loading and executing one of the available models (ligand_mpnn, protein_mpnn, soluble_mpnn, global_label_membrane_mpnn, per_residue_label_membrane_mpnn). The different checkpoints and settings (like noise level) are parameterized via the CLI.
- Side Chain Packing Module: Under “openfold/np/relax” and corresponding output directories (sc_default, sc_fixed_residues, etc.), denote the side chain packing and relaxation code that takes designed sequences and then performs structural refinement.
- Training & Testing Utilities: Include the “training” directory components which hold testing inputs and training JSON files, supporting a benchmark/validation mode.
- External Dependencies and Third Party Integrations: List external dependencies such as Prody (for PDB parsing), PyTorch and Numpy, and the use of parts of the Openfold code (for side chain packing and protein structure abstractions).

##### Relationships and Interactions
- User Interaction begins at the CLI where command line arguments determine which modules are activated (e.g., whether to run inference, design with fixed residues, apply ligand context for packing, etc.).
- The CLI then forwards the settings to the Input Processing/Parser that reads PDB files and any bias/fix JSONs.
- The Data Pipeline processes these inputs (via modules in openfold/data/) and outputs processed features (including residue indices and chain information) for the deep learning models.
- The Inference Core loads the selected model checkpoint and runs predictions based on the input features, generating sequence logits, probabilities, and design confidences.
- If side chain packing is enabled, the system invokes the side chain relaxation module that adjusts the atomic context based on ligand/dna inputs.
- Finally, results (designed sequences, packed PDB files, fasta outputs, and optional scoring statistics) are written out to the appropriate directories in “outputs/”.

##### Important Architectural Patterns
- Modularity: The system splits responsibilities among clear modules – parsing, data transformation, modeling, and output generation.
- Extensibility: The design allows for plug-and-play of different MPNN variants along with customizable options (fixed residues, redesigned residues, biases per residue, etc.).
- Dependency Injection: Configuration options (via CLI flags) dynamically determine which components are active and how they interact.

##### Relevant Technologies
- Python (with packages PyTorch, NumPy, Prody).
- Shell scripting for model parameter downloads.
- JSON-based configurations for biasing/fixing residues.
- Openfold library modules for structural operations (PDB parsing, side chain packing).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "CLI Layer"
        CLI1["Command: run.py"]:::cli
        CLI2["Command: score.py"]:::cli
        CLI3["Command: run_examples.sh"]:::cli
        CLI4["Command: sc_examples.sh"]:::cli
    end

    subgraph "Input & Configuration"
        IC1["Inputs Directory"]:::config
        IC2["Config Script"]:::config
        IC3["Model Params Script"]:::config
    end

    subgraph "Data Parsing & Pipeline"
        DP1["Data Module"]:::parser
        DP2["Data Utils"]:::parser
    end

    subgraph "Model & Inference Core"
        MI1["Model Utils"]:::model
    end

    subgraph "Side Chain Packing Module"
        SCP1["Relaxation Modules"]:::packing
    end

    subgraph "Output Processing"
        OP1["Outputs Directory"]:::output
    end

    subgraph "Training & Testing Utilities"
        TT1["Training Utilities"]:::training
    end

    External["External Dependencies (Prody, PyTorch, NumPy)"]:::external
    Decision{"Side Chain Packing?"}:::decision

    %% Flow connections
    CLI1 --> IC1
    CLI2 --> IC1
    CLI3 --> IC1
    CLI4 --> IC1
    IC1 --> IC2
    IC2 --> DP1
    DP1 --> DP2
    DP2 --> MI1
    MI1 --> Decision
    Decision -- "Yes" --> SCP1
    Decision -- "No" --> OP1
    SCP1 --> OP1
    %% Training branch
    CLI1 --> TT1

    %% External dependencies influence key modules (dashed lines)
    External -.-> IC2
    External -.-> DP1
    External -.-> MI1
    External -.-> SCP1

    %% Click Events for CLI Layer
    click CLI1 "https://github.com/dauparas/ligandmpnn/blob/main/run.py"
    click CLI2 "https://github.com/dauparas/ligandmpnn/blob/main/score.py"
    click CLI3 "https://github.com/dauparas/ligandmpnn/blob/main/run_examples.sh"
    click CLI4 "https://github.com/dauparas/ligandmpnn/blob/main/sc_examples.sh"

    %% Click Events for Input & Configuration
    click IC1 "https://github.com/dauparas/ligandmpnn/tree/main/inputs"
    click IC2 "https://github.com/dauparas/ligandmpnn/blob/main/openfold/config.py"
    click IC3 "https://github.com/dauparas/ligandmpnn/blob/main/get_model_params.sh"

    %% Click Events for Data Parsing & Pipeline
    click DP1 "https://github.com/dauparas/ligandmpnn/tree/main/openfold/data/"
    click DP2 "https://github.com/dauparas/ligandmpnn/blob/main/data_utils.py"

    %% Click Event for Model & Inference Core
    click MI1 "https://github.com/dauparas/ligandmpnn/blob/main/model_utils.py"

    %% Click Event for Side Chain Packing Module
    click SCP1 "https://github.com/dauparas/ligandmpnn/tree/main/openfold/np/relax/"

    %% Click Event for Output Processing
    click OP1 "https://github.com/dauparas/ligandmpnn/tree/main/outputs"

    %% Click Event for Training & Testing Utilities
    click TT1 "https://github.com/dauparas/ligandmpnn/tree/main/training"

    %% Styles
    classDef cli fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef config fill:#ffebcc,stroke:#cc6600,stroke-width:2px;
    classDef parser fill:#ffffcc,stroke:#999900,stroke-width:2px;
    classDef model fill:#ccffcc,stroke:#009900,stroke-width:2px;
    classDef packing fill:#cce5ff,stroke:#0066cc,stroke-width:2px;
    classDef output fill:#e5ccff,stroke:#6600cc,stroke-width:2px;
    classDef training fill:#ffccf2,stroke:#cc0099,stroke-width:2px;
    classDef external fill:#d9d9d9,stroke:#666666,stroke-width:2px;
    classDef decision fill:#ffd699,stroke:#cc8800,stroke-width:2px;
```
