# martinpacesa/bindcraft architecture

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

- Interactive diagram: https://gitdiagram.com/martinpacesa/bindcraft
- Repository: https://github.com/martinpacesa/bindcraft

## Overview

##### Project Type and Purpose
- BindCraft is a specialized bioinformatics pipeline for designing protein binders. It automates binder design through multiple stages of optimization and uses advanced protein modeling libraries.
- The README explains that the pipeline takes a protein target (provided via a JSON settings file) and runs a binder generation and validation process involving protein structure prediction, mutation sampling, and energy scoring.

##### File Structure
- Top-Level Files/Scripts:
- bindcraft.py: The main Python entry point for running the design pipeline.
- bindcraft.slurm: SLURM job script to run the pipeline on a high-performance cluster.
- install_bindcraft.sh: Installation script that sets up dependencies, including downloading AlphaFold2 weights and installing PyRosetta (taking into account licensing).
- Directories:
- functions: Contains all helper modules (e.g., biopython_utils.py, colabdesign_utils.py, pyrosetta_utils.py) that abstract common operations such as structure processing, interfacing with Colab design code, or PyRosetta energy evaluations.
- notebooks: Contains a Colab notebook (BindCraft.ipynb) to allow testing or demonstration of the pipeline.
- settings_advanced, settings_filters, settings_target: These hold multiple JSON configuration files that allow users to control binder design parameters (e.g., algorithm details, design iterations, weights), filter thresholds for design evaluations, and target-specific information.
- example: Provides a simple example target PDB file.

##### Key Architectural Components and Their Relationships
- Input/Configuration Manager:
- Uses JSON files from settings_target (protein target, chain specifications, lengths, etc.), settings_filters (post-design evaluation criteria), and settings_advanced (detailed algorithm parameters, iteration settings, and weights).

- Core Pipeline:
- Main Execution Script (bindcraft.py) orchestrates the process.
- Underlying functions (modules in the functions directory) are invoked to handle various tasks. For example:
- Preparation and preprocessing of protein structures.
- Execution of design iterations (soft, temporary, hard, greedy, etc.) as explained in the README.
- Interface to external libraries.
- This pipeline directs design trajectories through several stages: initial design with AlphaFold2, iterative design optimization (using AF2 recycles and MPNN for sequence mutations), and structure validation.

- External Dependencies and Libraries:
- AlphaFold2: Used in multimer mode or pTM mode for structure prediction and binder design. Indicate that AF2 processes are part of both design and validation stages.
- ProteinMPNN: Applied to generate or optimize binder sequences in parallel.
- PyRosetta: Utilized for final energy evaluation and relaxation of designed structures.
- CUDA & GPU Requirements: Mention that the pipeline requires a CUDA-compatible Nvidia GPU (the installation script addresses this).

- Execution Contexts:
- Local Execution: Executing via bindcraft.py directly with conda environment activation.
- Cluster/SLURM Execution: Running via bindcraft.slurm for high-throughput or GPU-heavy execution.
- Google Colab: A notebook-based interface provided for demonstration or testing.

- Output/Data Visualization:
- Final design PDB files, statistical CSV outputs, and possibly animated visualizations (noted by zipping of animations and plots).
- Filters applied to select designs based on AF2 confidence scores, Rosetta metrics, and MPNN outputs.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Configuration Subgraph
    subgraph "Input Configuration"
        A1("Target Settings"):::config
        A2("Filter Settings"):::config
        A3("Advanced Settings"):::config
    end

    %% Core Modules and Contexts
    B("Main Controller (bindcraft.py)"):::core
    C("Scheduler (bindcraft.slurm)"):::core
    D("Installation & Dependency Setup"):::setup
    L("Example Input Data"):::example

    %% Preprocessing Module Subgraph with Helper Functions
    subgraph "Preprocessing Module"
        E1("BioPython Utils"):::module
        E2("ColabDesign Utils"):::module
        E3("PyRosetta Utils"):::module
    end

    F("Design Iteration Engine"):::module
    G("Structure Prediction (AlphaFold2)"):::external
    H("Sequence Optimization (ProteinMPNN)"):::external
    I("Energy Evaluation & Relaxation (PyRosetta)"):::external
    J("Output Generation & Post-Processing"):::output
    K("User Interface (BindCraft Notebook)"):::ui

    %% Data and control flows
    A1 --> B
    A2 --> B
    A3 --> B
    D --> B
    L --> B
    B --> E1
    B --> E2
    B --> E3
    E1 --> F
    E2 --> F
    E3 --> F
    F --> G
    F --> H
    F --> I
    G --> J
    H --> J
    I --> J
    F -->|"iteration"| F
    B --- C
    B --- K

    %% Click Events
    click A1 "https://github.com/martinpacesa/bindcraft/blob/main/settings_target/PDL1.json"
    click A2 "https://github.com/martinpacesa/bindcraft/blob/main/settings_filters/default_filters.json"
    click A3 "https://github.com/martinpacesa/bindcraft/blob/main/settings_advanced/default_4stage_multimer.json"
    click B "https://github.com/martinpacesa/bindcraft/blob/main/bindcraft.py"
    click C "https://github.com/martinpacesa/bindcraft/blob/main/bindcraft.slurm"
    click D "https://github.com/martinpacesa/bindcraft/blob/main/install_bindcraft.sh"
    click E1 "https://github.com/martinpacesa/bindcraft/blob/main/functions/biopython_utils.py"
    click E2 "https://github.com/martinpacesa/bindcraft/blob/main/functions/colabdesign_utils.py"
    click E3 "https://github.com/martinpacesa/bindcraft/blob/main/functions/pyrosetta_utils.py"
    click K "https://github.com/martinpacesa/bindcraft/blob/main/notebooks/BindCraft.ipynb"
    click L "https://github.com/martinpacesa/bindcraft/blob/main/example/PDL1.pdb"

    %% Styles
    classDef config fill:#a8d5ba,stroke:#333,stroke-width:2px;
    classDef core fill:#9fc5e8,stroke:#333,stroke-width:2px;
    classDef module fill:#f9d29d,stroke:#333,stroke-width:2px;
    classDef external fill:#fce5cd,stroke:#333,stroke-width:2px;
    classDef output fill:#d5a6bd,stroke:#333,stroke-width:2px;
    classDef setup fill:#f4cccc,stroke:#333,stroke-width:2px;
    classDef ui fill:#d9ead3,stroke:#333,stroke-width:2px;
    classDef example fill:#c9daf8,stroke:#333,stroke-width:2px;
```
