# kuhlman-lab/thermompnn architecture

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

- Interactive diagram: https://gitdiagram.com/kuhlman-lab/thermompnn
- Repository: https://github.com/kuhlman-lab/thermompnn

## Overview

##### Project Type and Purpose
- Type: A scientific/machine learning application for protein ddG prediction using a GNN.
- Purpose: It takes in protein structural (PDB) or CSV data, processes the input using a series of preprocessing scripts, executes training (or performs inference) via the GNN model, and outputs predictions about protein mutant stability changes.

##### Identifying Main Components
a. Data Management
- Raw datasets are stored in the "data_all" directory with separate folders for training and testing.
- Dataset splits (train/test partitions and clustering) are maintained under "dataset_splits".
- Configuration files like "local.yaml" and "config.yaml" specify where data is located and set hyperparameters for training.

b. Data Preprocessing
- The "preprocessing" directory includes scripts (and notebooks) for cleaning and aligning datasets, adding metadata, and splitting data.
- This module is responsible for converting raw data into the formats required for training and inference.

c. Model Training
- The "train_thermompnn.py" script is the entry point for training the GNN model.
- Scripts like "transfer_model.py" and utility functions (e.g., in "model_utils.py") support training operations.
- Training produces model weights which are stored in the "models" and "vanilla_model_weights" directories.

d. Inference and Analysis
- The "analysis" directory contains several scripts for various forms of inference (e.g., "custom_inference.py", "SSM.py", and benchmarking scripts).
- These scripts allow running predictions from single PDB inputs or bulk CSV datasets.

e. Utility Modules and Supporting Components
- Files such as "datasets.py", "protein_mpnn_utils.py", and "cache.py" support data handling, model inference, and caching.
- Examples are provided under the "examples" directory for running inference and training using SLURM scripts.
- Configuration/environment setup is supported by "environment.yaml" and ".gitignore"/".idea" for project hygiene.

##### Relationships/Interactions Between Components
- Data Flow:
→ Raw protein data and dataset splits (data_all and dataset_splits) are ingested.
→ Preprocessing scripts clean and prepare the data, which is then fed into the training pipeline.
→ The training module uses configuration files (config.yaml, local.yaml) and produces model weights.
→ Inference scripts (in analysis/) use these trained weights along with newly processed or provided input data to generate predictions.
- Dependency Relationships:
- The preprocessing module depends on proper dataset file availability.
- The training module relies on both processed data and experimental configuration parameters.
- The inference module utilizes both the trained models and any external protein or CSV input.

##### Architectural Patterns and Key Technologies
- Separation of Concerns: Clear division between data preprocessing, training, and inference analyses.
- Data Pipeline: A sequential flow from raw input → cleaning/processing → model training/inference.
- Use of Transfer Learning: The system is based on a pretrained GNN that is fine-tuned for stability prediction.
- Technologies: Python scripts, Conda-based environment management via environment.yaml, PyTorch (with GPU support), and job scheduling scripts (e.g., SLURM).

##### Specific Elements
- Clear labels for each component:
- Data Input (Raw Datasets, Dataset Splits)
- Data Preprocessing Module
- Model Training Module (GNN/Transfer Learning)
- Inference & Analysis Module
- Supporting Utilities and Environment Configuration
- Visual Differentiation:
- Legends or annotations wherever necessary.
- Notations/Annotations:
- Annotations pointing out crucial configuration files (config.yaml, local.yaml) setting experimental parameters.
- Reliance on GPU for training and potential SLURM-managed deployments.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Management
    subgraph "Data Management"
        A1["Raw Datasets"]:::dataStyle
        A2["Dataset Splits"]:::dataStyle
        A3["config.yaml"]:::configStyle
        A4["local.yaml"]:::configStyle
    end

    %% Data Preprocessing
    subgraph "Data Preprocessing"
        B1["Data Preprocessing Module"]:::preprocessingStyle
    end

    %% Model Training
    subgraph "Model Training"
        C1["Training Entry (train_thermompnn.py)"]:::trainingStyle
        C2["Transfer Learning (transfer_model.py)"]:::trainingStyle
        C3["Training Utilities (model_utils.py)"]:::trainingStyle
        C4["Model Weights (models)"]:::trainingStyle
        C5["Vanilla Weights (vanilla_model_weights)"]:::trainingStyle
    end

    %% Inference & Analysis
    subgraph "Inference & Analysis"
        D1["Inference Scripts (analysis)"]:::inferenceStyle
    end

    %% Utility Modules
    subgraph "Utilities"
        E1["Data Utilities (datasets.py)"]:::utilityStyle
        E2["Protein Utilities (protein_mpnn_utils.py)"]:::utilityStyle
        E3["Caching (cache.py)"]:::utilityStyle
        E4["Examples (examples)"]:::utilityStyle
        E5["Environment Config (environment.yaml)"]:::utilityStyle
    end

    %% Connections between Data Management and Preprocessing
    A1 -->|"ingests"| B1
    A2 -->|"ingests"| B1

    %% Configuration files feeding into Training
    A3 -->|"configures"| C1
    A4 -->|"configures"| C1

    %% Data flow from Preprocessing to Training
    B1 -->|"processed_data"| C1

    %% Internal Training dependencies
    C2 -.->|"supports"| C1
    C3 -.->|"supports"| C1

    %% Training produces model artifacts used by Inference
    C1 -->|"produces"| C4
    C1 -->|"produces"| C5
    C4 -->|"feeds"| D1
    C5 -->|"feeds"| D1

    %% Utilities support both Training and Inference
    E1 -.-> D1
    E2 -.-> D1
    E3 -.-> D1
    E4 -.-> D1
    E5 -.-> D1

    E1 -.-> C1
    E2 -.-> C1
    E3 -.-> C1
    E4 -.-> C1
    E5 -.-> C1

    %% Click Events
    click A1 "https://github.com/kuhlman-lab/thermompnn/tree/main/data_all"
    click A2 "https://github.com/kuhlman-lab/thermompnn/tree/main/dataset_splits"
    click A3 "https://github.com/kuhlman-lab/thermompnn/blob/main/config.yaml"
    click A4 "https://github.com/kuhlman-lab/thermompnn/blob/main/local.yaml"
    click B1 "https://github.com/kuhlman-lab/thermompnn/tree/main/preprocessing"
    click C1 "https://github.com/kuhlman-lab/thermompnn/blob/main/train_thermompnn.py"
    click C2 "https://github.com/kuhlman-lab/thermompnn/blob/main/transfer_model.py"
    click C3 "https://github.com/kuhlman-lab/thermompnn/blob/main/model_utils.py"
    click C4 "https://github.com/kuhlman-lab/thermompnn/tree/main/models"
    click C5 "https://github.com/kuhlman-lab/thermompnn/tree/main/vanilla_model_weights"
    click D1 "https://github.com/kuhlman-lab/thermompnn/tree/main/analysis"
    click E1 "https://github.com/kuhlman-lab/thermompnn/blob/main/datasets.py"
    click E2 "https://github.com/kuhlman-lab/thermompnn/blob/main/protein_mpnn_utils.py"
    click E3 "https://github.com/kuhlman-lab/thermompnn/blob/main/cache.py"
    click E4 "https://github.com/kuhlman-lab/thermompnn/tree/main/examples"
    click E5 "https://github.com/kuhlman-lab/thermompnn/blob/main/environment.yaml"

    %% Styles
    classDef dataStyle fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef configStyle fill:#F5B7B1,stroke:#CB4335,stroke-width:2px;
    classDef preprocessingStyle fill:#D1F2EB,stroke:#138D75,stroke-width:2px;
    classDef trainingStyle fill:#ABEBC6,stroke:#27AE60,stroke-width:2px;
    classDef inferenceStyle fill:#FAD7A0,stroke:#F39C12,stroke-width:2px;
    classDef utilityStyle fill:#D7BDE2,stroke:#8E44AD,stroke-width:2px;
```
