# eightmm/bapred architecture

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

- Interactive diagram: https://gitdiagram.com/eightmm/bapred
- Repository: https://github.com/eightmm/bapred

## Overview

##### Main Components
- Data Input/Preprocessing Module:
- Processing of input files (the receptor PDB and ligand SDF) that are read by the “data” components in the repository.
- The “data/atom_feature.py” extracts features per atom, “data/data.py” handles the loading and preprocessing of the data, and “data/utils.py” provides helper functions.
- Model/Inference Engine:
- The “inference.py” is the orchestration layer that ties together data preprocessing and model evaluation.
- Within the “model” directory, include the core model components:
▪ GatedGCNLSPE (graph convolution with gated mechanisms for learning local substructure patterns).
▪ GraphGPS (which likely adds global message passing or integration techniques).
▪ MHA (Multi-Head Attention module to better capture interactions).
▪ The “model/model.py” which wraps or interfaces the various submodules and controls overall model execution.
- Weights/Pretrained Model:
- “weight/BAPred.pth” file which contains the saved state dict of the pretrained model utilized during inference.
- Execution & Output:
- The inference script receives input parameters (paths to receptor and ligand, model weights, device selection) and outputs a CSV file containing the ligand names/indices and predicted affinity scores.

- In the Inference Engine, show internal interactions between the “model wrapper” and the different GNN components (GatedGCNLSPE, GraphGPS, MHA). Indicate that these components are organized either in series or parallel (depending on the model design) and that they collectively integrate to produce the output.

##### Architectural Patterns & Design Principles
- Modularity by clearly separating data handling, model execution, and output generation.
- How the inference script acts as the “glue” that communicates between the data modules, the actual model architecture, and file I/O.
- That although this tool is not a full-stack web application, its design aligns with common machine learning pipelines where the computation is split into distinct, loosely coupled components.

##### Technologies, Frameworks, and Dependencies
- Mention the Python environment managed via Conda (env.yaml) that includes all required packages.
- That the project employs GNNs and possibly deep learning libraries (e.g., PyTorch or another DL framework) to implement and run the model.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Files
    subgraph "Input Files"
        R("Receptor (PDB)"):::input
        L("Ligand (SDF)"):::input
    end

    %% Data Loading & Preprocessing Module
    subgraph "Data Loading & Preprocessing"
        D1("Data Loader"):::data
        D2("Atom Feature Extraction"):::data
        D3("Utility Functions"):::data
    end

    %% Model & Inference Engine
    subgraph "Model & Inference Engine"
        I1("Inference Script"):::inference
        I2("Model Wrapper"):::inference
        subgraph "GNN Modules"
            G1("GatedGCNLSPE"):::gnn
            G2("GraphGPS"):::gnn
            G3("Multi-Head Attention"):::gnn
        end
        W("Pretrained Weights"):::weight
    end

    %% Output Module
    subgraph "Output Module"
        O("Predicted Affinity CSV"):::output
    end

    %% Environment Setup & Dependencies
    E("Environment Setup"):::env

    %% Data Flow Connections
    R -->|"input"| D1
    L -->|"input"| D1
    E --> D1
    D1 --> D2
    D2 --> D3
    D3 -->|"processed_data"| I1
    E --> I1
    W -->|"weight_loading"| I1
    I1 --> I2
    I2 --> G1
    I2 --> G2
    I2 --> G3
    G1 -->|"contributes_to"| I2
    G2 -->|"contributes_to"| I2
    G3 -->|"contributes_to"| I2
    I2 -->|"inference_results"| O

    %% Click Events
    click D1 "https://github.com/eightmm/bapred/blob/main/data/data.py"
    click D2 "https://github.com/eightmm/bapred/blob/main/data/atom_feature.py"
    click D3 "https://github.com/eightmm/bapred/blob/main/data/utils.py"
    click I1 "https://github.com/eightmm/bapred/blob/main/inference.py"
    click I2 "https://github.com/eightmm/bapred/blob/main/model/model.py"
    click G1 "https://github.com/eightmm/bapred/blob/main/model/GatedGCNLSPE.py"
    click G2 "https://github.com/eightmm/bapred/blob/main/model/GraphGPS.py"
    click G3 "https://github.com/eightmm/bapred/blob/main/model/MHA.py"
    click W "https://github.com/eightmm/bapred/blob/main/weight/BAPred.pth"
    click E "https://github.com/eightmm/bapred/blob/main/env.yaml"

    %% Styles
    classDef input fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef data fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef inference fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef gnn fill:#F5B7B1,stroke:#E74C3C,stroke-width:2px;
    classDef weight fill:#FAD7A0,stroke:#E67E22,stroke-width:2px;
    classDef output fill:#D7BDE2,stroke:#8E44AD,stroke-width:2px;
    classDef env fill:#D6EAF8,stroke:#3498DB,stroke-width:2px;
```
