# ale94mleon/bindflow architecture

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

- Interactive diagram: https://gitdiagram.com/ale94mleon/bindflow
- Repository: https://github.com/ale94mleon/bindflow

## Overview

#### Purpose and entry points
BindFlow is a Python/Snakemake workflow package for absolute binding free-energy (ABFE) calculations using GROMACS, with RDKit-backed molecular handling. The user-facing entry is the CLI in `src/bindflow/cli.py`; example execution scripts provide practical programmatic launch points, e.g. `examples/A2A/executor-fep.py` and `examples/A2A/executor-mmpbsa.py`.

#### Workflow construction and dispatch
`src/bindflow/orchestration/flow_builder.py` assembles a run from user configuration and selected calculation mode. `src/bindflow/orchestration/generate_scheduler.py` generates scheduler-facing execution setup, while `src/bindflow/runners.py` launches workflow execution. This layer separates configuration-driven planning from execution on local or scheduled compute resources.

#### Snakemake DAGs: the execution core
The packaged rule trees define the actual dependency graphs and file-producing stages:
- Equilibration: `src/bindflow/rules/equi/Snakefile`
- ABFE/FEP: `src/bindflow/rules/fep/Snakefile`
- MM/PBSA: `src/bindflow/rules/mmpbsa/Snakefile`
- End-to-end orchestration: `src/bindflow/rules/super_flow/Snakefile`

FEP branches separate ligand and complex legs, with distinct soluble versus membrane system rules, such as `src/bindflow/rules/fep/ligand/simulation.smk` and `src/bindflow/rules/fep/complex/membrane/simulation.smk`.

#### System preparation boundary
Preparation converts receptor, ligand, force-field, solvent, and optional membrane inputs into simulation-ready systems. `src/bindflow/preparation/system_builder.py` is the core builder; `src/bindflow/preparation/solvent.py` handles solvent-related setup; and `src/bindflow/preparation/boresch.py` supports Boresch restraint preparation. Inputs and generated topology/coordinate artifacts form the boundary between chemistry/system construction and MD execution.

#### Simulation parameter generation
`src/bindflow/mdp/mdp.py` materializes GROMACS MDP parameters from packaged templates, with path handling in `src/bindflow/mdp/_path_handler.py`. Templates encode protocol variants across equilibration, FEP decoupling stages, production, environment, and system type—for example `src/bindflow/mdp/templates/complex/soluble/fep` and `src/bindflow/mdp/templates/ligand/fep`.

#### Free-energy and MM/PBSA analysis
Post-simulation analysis is implemented in `src/bindflow/free_energy/fep_analysis.py`, `src/bindflow/free_energy/mmxbsa_analysis.py`, and `src/bindflow/free_energy/gather_results.py`. FEP rules run analysis for complex and ligand legs then gather receptor-level results (`src/bindflow/rules/fep/calculate_result.smk`); MM/PBSA has its own setup, simulation, analysis, and aggregation path (`src/bindflow/rules/mmpbsa/ana.smk`).

#### Packaged scientific assets and runtime dependencies
The runtime requires Python, Snakemake, GROMACS, and RDKit; scheduler integration is a material deployment concern. Packaged assets provide force fields and water-model definitions: `src/bindflow/data/gmx_ff`, `src/bindflow/data/gmx_water_models/water_models.yml`, and `src/bindflow/mmpbsa_in/templates`. Example configurations demonstrate amber/charmm and soluble/membrane variants under `examples/configs`.

Main entry points: [`src/bindflow/preparation/system_builder.py`](https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/preparation/system_builder.py) (System builder), [`src/bindflow/rules/fep/Snakefile`](https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/rules/fep/Snakefile) (ABFE / FEP), [`src/bindflow/rules/super_flow/Snakefile`](https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/rules/super_flow/Snakefile) (End-to-end flow), [`src/bindflow/mdp/mdp.py`](https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/mdp/mdp.py) (MDP generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry &amp; Planning"]
  node_cli["BindFlow CLI<br/>Python CLI<br/>[cli.py]"]
  node_examples["Example executors<br/>Python scripts<br/>[executor-fep.py]"]
  node_flow_builder["Flow builder<br/>planner<br/>[flow_builder.py]"]
  node_scheduler["Scheduler setup<br/>scheduler generator"]
  node_runners["Workflow runner<br/>launcher<br/>[runners.py]"]
end

subgraph group_workflow["Snakemake Workflows"]
  node_superflow{{"End-to-end flow<br/>Snakemake DAG"}}
  node_equi{{"Equilibration<br/>Snakemake DAG"}}
  node_fep{{"ABFE / FEP<br/>Snakemake DAG"}}
  node_fep_ligand["Ligand FEP leg<br/>Snakemake rules<br/>[simulation.smk]"]
  node_fep_complex["Complex membrane leg<br/>Snakemake rules<br/>[simulation.smk]"]
  node_mmpbsa{{"MM/PBSA<br/>Snakemake DAG"}}
end

subgraph group_prep["System Preparation"]
  node_system_builder["System builder<br/>preparation<br/>[system_builder.py]"]
  node_solvent["Solvent setup<br/>preparation<br/>[solvent.py]"]
  node_boresch["Boresch restraints<br/>preparation<br/>[boresch.py]"]
  node_mdp["MDP generator<br/>parameter generator<br/>[mdp.py]"]
end

subgraph group_analysis["Analysis"]
  node_fep_analysis["FEP analysis<br/>free-energy analysis<br/>[fep_analysis.py]"]
  node_results["Result gathering<br/>aggregation<br/>[gather_results.py]"]
  node_mmpbsa_analysis["MM/PBSA analysis<br/>free-energy analysis<br/>[mmxbsa_analysis.py]"]
end

subgraph group_assets["Scientific Assets &amp; Runtime"]
  node_mdp_templates["MDP templates<br/>protocol assets"]
  node_force_fields["Force fields<br/>packaged assets"]
  node_water_models["Water models<br/>packaged assets<br/>[water_models.yml]"]
  node_runtime(("Scientific runtime"))
end

node_cli -->|"configures"| node_flow_builder
node_examples -->|"launches"| node_flow_builder
node_flow_builder -->|"plans scheduled runs"| node_scheduler
node_flow_builder -->|"selects execution"| node_runners
node_scheduler -->|"execution setup"| node_runners
node_runners -->|"runs"| node_superflow
node_superflow -->|"equilibrates"| node_equi
node_superflow -->|"ABFE mode"| node_fep
node_superflow -->|"MM/PBSA mode"| node_mmpbsa
node_system_builder -->|"simulation-ready systems"| node_equi
node_system_builder -->|"topology and coordinates"| node_fep
node_system_builder -->|"prepared system"| node_mmpbsa
node_solvent -->|"solvation"| node_system_builder
node_boresch -->|"restraints"| node_system_builder
node_force_fields -->|"parameters"| node_system_builder
node_water_models -->|"definitions"| node_solvent
node_mdp_templates -->|"protocol inputs"| node_mdp
node_mdp -->|"GROMACS parameters"| node_equi
node_mdp -->|"GROMACS parameters"| node_fep
node_mdp -->|"GROMACS parameters"| node_mmpbsa
node_fep -->|"ligand branch"| node_fep_ligand
node_fep -->|"complex branch"| node_fep_complex
node_fep_ligand -->|"trajectories"| node_fep_analysis
node_fep_complex -->|"trajectories"| node_fep_analysis
node_fep_analysis -->|"leg estimates"| node_results
node_mmpbsa -->|"simulation outputs"| node_mmpbsa_analysis
node_runtime -.->|"executes with"| node_runners

click node_cli "https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/cli.py"
click node_examples "https://github.com/ale94mleon/bindflow/blob/main/examples/A2A/executor-fep.py"
click node_flow_builder "https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/orchestration/flow_builder.py"
click node_scheduler "https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/orchestration/generate_scheduler.py"
click node_runners "https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/runners.py"
click node_superflow "https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/rules/super_flow/Snakefile"
click node_equi "https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/rules/equi/Snakefile"
click node_fep "https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/rules/fep/Snakefile"
click node_fep_ligand "https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/rules/fep/ligand/simulation.smk"
click node_fep_complex "https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/rules/fep/complex/membrane/simulation.smk"
click node_mmpbsa "https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/rules/mmpbsa/Snakefile"
click node_system_builder "https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/preparation/system_builder.py"
click node_solvent "https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/preparation/solvent.py"
click node_boresch "https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/preparation/boresch.py"
click node_mdp "https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/mdp/mdp.py"
click node_fep_analysis "https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/free_energy/fep_analysis.py"
click node_results "https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/free_energy/gather_results.py"
click node_mmpbsa_analysis "https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/free_energy/mmxbsa_analysis.py"
click node_mdp_templates "https://github.com/ale94mleon/bindflow/tree/main/src/bindflow/mdp/templates/complex/soluble/fep"
click node_force_fields "https://github.com/ale94mleon/bindflow/tree/main/src/bindflow/data/gmx_ff"
click node_water_models "https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/data/gmx_water_models/water_models.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_examples,node_flow_builder,node_scheduler,node_runners toneBlue
class node_superflow,node_equi,node_fep,node_fep_ligand,node_fep_complex,node_mmpbsa toneAmber
class node_system_builder,node_solvent,node_boresch,node_mdp toneMint
class node_fep_analysis,node_results,node_mmpbsa_analysis toneRose
class node_mdp_templates,node_force_fields,node_water_models,node_runtime toneIndigo
```

## Components

### Entry & Planning

- [BindFlow CLI](https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/cli.py): Python CLI · User-facing run entry point. · `src/bindflow/cli.py`
- [Example executors](https://github.com/ale94mleon/bindflow/blob/main/examples/A2A/executor-fep.py): Python scripts · Programmatic A2A launch examples. · `examples/A2A/executor-fep.py`
- [Flow builder](https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/orchestration/flow_builder.py): planner · Builds a run from configuration and calculation mode. · `src/bindflow/orchestration/flow_builder.py`
- [Scheduler setup](https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/orchestration/generate_scheduler.py): scheduler generator · Generates scheduled execution setup. · `src/bindflow/orchestration/generate_scheduler.py`
- [Workflow runner](https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/runners.py): launcher · Launches local or scheduled workflow execution. · `src/bindflow/runners.py`

### Snakemake Workflows

- [End-to-end flow](https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/rules/super_flow/Snakefile): Snakemake DAG · Top-level orchestration DAG. · `src/bindflow/rules/super_flow/Snakefile`
- [Equilibration](https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/rules/equi/Snakefile): Snakemake DAG · `src/bindflow/rules/equi/Snakefile`
- [ABFE / FEP](https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/rules/fep/Snakefile): Snakemake DAG · Branches into ligand and complex free-energy legs. · `src/bindflow/rules/fep/Snakefile`
- [Ligand FEP leg](https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/rules/fep/ligand/simulation.smk): Snakemake rules · `src/bindflow/rules/fep/ligand/simulation.smk`
- [Complex membrane leg](https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/rules/fep/complex/membrane/simulation.smk): Snakemake rules · Membrane-specific complex simulation branch. · `src/bindflow/rules/fep/complex/membrane/simulation.smk`
- [MM/PBSA](https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/rules/mmpbsa/Snakefile): Snakemake DAG · Dedicated setup, simulation, analysis, and aggregation path. · `src/bindflow/rules/mmpbsa/Snakefile`

### System Preparation

- [System builder](https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/preparation/system_builder.py): preparation · Creates simulation-ready topology and coordinates. · `src/bindflow/preparation/system_builder.py`
- [Solvent setup](https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/preparation/solvent.py): preparation · `src/bindflow/preparation/solvent.py`
- [Boresch restraints](https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/preparation/boresch.py): preparation · `src/bindflow/preparation/boresch.py`
- [MDP generator](https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/mdp/mdp.py): parameter generator · Materializes GROMACS parameters from templates. · `src/bindflow/mdp/mdp.py`

### Analysis

- [FEP analysis](https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/free_energy/fep_analysis.py): free-energy analysis · Analyzes complex and ligand legs. · `src/bindflow/free_energy/fep_analysis.py`
- [Result gathering](https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/free_energy/gather_results.py): aggregation · Gathers receptor-level free-energy results. · `src/bindflow/free_energy/gather_results.py`
- [MM/PBSA analysis](https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/free_energy/mmxbsa_analysis.py): free-energy analysis · `src/bindflow/free_energy/mmxbsa_analysis.py`

### Scientific Assets & Runtime

- [MDP templates](https://github.com/ale94mleon/bindflow/tree/main/src/bindflow/mdp/templates/complex/soluble/fep): protocol assets · Protocol variants by environment and system type. · `src/bindflow/mdp/templates/complex/soluble/fep`
- [Force fields](https://github.com/ale94mleon/bindflow/tree/main/src/bindflow/data/gmx_ff): packaged assets · `src/bindflow/data/gmx_ff`
- [Water models](https://github.com/ale94mleon/bindflow/blob/main/src/bindflow/data/gmx_water_models/water_models.yml): packaged assets · `src/bindflow/data/gmx_water_models/water_models.yml`
- **Scientific runtime**: Python · Snakemake · GROMACS · RDKit · Scheduler integration supports deployed execution.

## Connections

- BindFlow CLI → Flow builder: configures
- Example executors → Flow builder: launches
- Flow builder → Scheduler setup: plans scheduled runs
- Flow builder → Workflow runner: selects execution
- Scheduler setup → Workflow runner: execution setup
- Workflow runner → End-to-end flow: runs
- End-to-end flow → Equilibration: equilibrates
- End-to-end flow → ABFE / FEP: ABFE mode
- End-to-end flow → MM/PBSA: MM/PBSA mode
- System builder → Equilibration: simulation-ready systems
- System builder → ABFE / FEP: topology and coordinates
- System builder → MM/PBSA: prepared system
- Solvent setup → System builder: solvation
- Boresch restraints → System builder: restraints
- Force fields → System builder: parameters
- Water models → Solvent setup: definitions
- MDP templates → MDP generator: protocol inputs
- MDP generator → Equilibration: GROMACS parameters
- MDP generator → ABFE / FEP: GROMACS parameters
- MDP generator → MM/PBSA: GROMACS parameters
- ABFE / FEP → Ligand FEP leg: ligand branch
- ABFE / FEP → Complex membrane leg: complex branch
- Ligand FEP leg → FEP analysis: trajectories
- Complex membrane leg → FEP analysis: trajectories
- FEP analysis → Result gathering: leg estimates
- MM/PBSA → MM/PBSA analysis: simulation outputs
- Scientific runtime → Workflow runner: executes with
