# michellab/a3fe architecture

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

- Interactive diagram: https://gitdiagram.com/michellab/a3fe
- Repository: https://github.com/michellab/a3fe

## Overview

##### Project’s Main Components
- Input/Preprocessing:
– The “data” directory (and the example_run_dir inside it) holds example inputs, configuration scripts (like run_somd.sh, template_config.cfg) and sample output directories. The “read” subpackage (with modules like _process_somd_files.py, process_pdbs.py, etc.) is responsible for importing and converting simulation files.
- Workflow/Calculation Management:
– The core logic is found in the “run” subpackage (with modules such as calc_set.py, calculation.py, simulation.py, stage.py, system_prep.py, and others) which defines the Calculation class. This component orchestrates the entire free energy calculation workflow (setting up simulations, managing lambda windows, coordinating ensembles, and collating outputs).
- Analysis:
– The “analyse” subpackage contains modules (e.g. analyse_set.py, autocorrelation.py, compare.py, plot.py, etc.) that perform post-processing of simulation outputs, compute MBAR free energies, RMSD, water analyses, and produce plots.
- External Integrations:
– The package clearly depends on external systems such as:
- The SLURM scheduling system (jobs are submitted and managed using SLURM – likely integrated via custom code in the “run/_virtual_queue.py” and related modules).
- GROMACS (used for initial equilibration; users are instructed to source a GMXRC file).
- SOMD software (distributed through Sire) for running the alchemical simulations.
- Build/Testing/Documentation:
– Standard config files (pyproject.toml, setup.cfg, environment.yaml) indicate that standard Python packaging and environment management are used.
– The “tests” directory holds unit tests for the components.

##### Relationships and Data Flow
– Input files are provided by the user or via example directories. They are parsed and validated by functionality in the “read” module.
- System Preparation:
– The “system_prep” and other preparatory functions generate the simulation system’s initial conditions.
- Workflow Management:
– A central Calculation object (from a3fe/run/calculation.py) uses a set of helper components to divide the work into simulation “Legs” and “Stages” (see modules like leg.py and stage.py).
– The Calculation object calls methods such as setup(), get_optimal_lam_vals(), run(), and wait(). It uses the “virtual_queue”, “simulation_runner”, and “restraint” modules to submit jobs.
– The run module interacts with SLURM by creating job scripts (see script examples in the “data/example_run_dir”) and monitoring the progress of simulation replicates.
- Simulation Execution:
– The actual simulation jobs (which call SOMD/ GROMACS executables) run in a distributed fashion on the SLURM cluster. Results are stored in hierarchical “output” directories that mimic the lambda window structure (see the detailed file tree structure under “a3fe/data/example_calc_set” and similar).
- Analysis:
– Once simulations finish, the Analysis modules in “a3fe/analyse” pick up the simulation outputs and perform specific calculations (e.g., MBAR free energy analysis, autocorrelation, RMSD, water analysis, and plotting).
- Result Storage and Reporting:
– Finally, the Calculation object collates results and saves them. The outputs (CSV files, plots, and overall statistical files) are written to the corresponding “output” directories.

##### Architectural Patterns and Design Principles
- Modular Design: The project is clearly separated into input reading, workflow orchestration, simulation running, and analysis. Each subpackage (“read”, “run”, “analyse”) has its own responsibilities.
- Plugin/Extensibility: The separation into “analyses” and “run” modules shows that it was designed to be extensible—new analysis routines or simulation protocols can be added in their respective submodules.
- Pipeline/Workflow-Oriented: The Calculation object models a pipeline: setup→execute simulations → wait for completion → post-process → save results.
- Use of Standard Build/Test/Docs Structures: Inclusion of configuration files (e.g. environment.yaml, setup.cfg) and directories such as tests, devtools, and docs.

– Start → Input Files → Read Module → System Preparation → Calculation Object → SLURM Job Submission → Simulation Execution → Output Files → Analysis Modules → Final Results.
- External dependencies (SLURM scheduling, GROMACS, SOMD) as nodes interacting with the Calculation/Run modules.

##### Additional Notes for the Principal Software Engineer
- Leverage the documented “a3fe_design.rst” in the docs directory as a potential starting point or cross-reference.
- That areas of adaptive workflow (parameter optimisation, ensemble management) are shown distinctly.
- Do not hesitate to split clusters or groups of functions into separate layers if it aids in clarity.

Happy diagramming!

## Diagram (Mermaid)

```mermaid
graph TD
    %% Input/Preprocessing layer
    subgraph "Input/Preprocessing"
        A1["Input Files (a3fe/data)"]
        A2["File Parsers (a3fe/read)"]
    end

    %% System Preparation layer
    subgraph "System Preparation"
        B1["System Prep (a3fe/run/system_prep.py)"]
    end

    %% Workflow Management layer
    subgraph "Workflow Management"
        C1["Calculation Object (a3fe/run/calculation.py)"]
        C2["Job Queue (a3fe/run/_virtual_queue.py)"]
    end

    %% Simulation Execution layer
    subgraph "Simulation Execution"
        D1["Simulation Jobs (GROMACS/SOMD)"]
    end

    %% Analysis layer
    subgraph "Analysis"
        E1["Analysis Modules (a3fe/analyse)"]
        E2["Final Results"]
    end

    %% Build/Testing/Documentation layer
    subgraph "Build/Testing/Documentation"
        F1["Tests (a3fe/tests)"]
        F2["Documentation (docs/a3fe_design.rst)"]
    end

    %% External Integrations (shown as separate nodes)
    X1["SLURM Scheduler"]
    X2["GROMACS Environment"]
    X3["SOMD Software"]

    %% Data Flow Connections
    A1 --> A2
    A2 --> B1
    B1 --> C1
    C1 --> C2
    C2 --> D1
    D1 --> E1
    E1 --> E2

    %% External Dependencies and Job Submission Connections
    C1 -->|"submit_job"| X1
    C2 -->|"schedule_jobs"| X1
    X2 -->|"equilibration"| D1
    X3 -->|"production"| D1

    %% Styling Classes Definitions
    class A1,A2 inputStyle
    class B1 prepStyle
    class C1,C2 workflowStyle
    class D1 simulationStyle
    class E1,E2 analysisStyle
    class F1,F2 docsStyle
    class X1,X2,X3 externalStyle

    %% Click Events for Component Mappings
    click A1 "https://github.com/michellab/a3fe/tree/main/a3fe/data"
    click A2 "https://github.com/michellab/a3fe/tree/main/a3fe/read"
    click C1 "https://github.com/michellab/a3fe/blob/main/a3fe/run/calculation.py"
    click C2 "https://github.com/michellab/a3fe/blob/main/a3fe/run/_virtual_queue.py"
    click E1 "https://github.com/michellab/a3fe/tree/main/a3fe/analyse"
    click F1 "https://github.com/michellab/a3fe/tree/main/a3fe/tests"
    click F2 "https://github.com/michellab/a3fe/blob/main/docs/a3fe_design.rst"

    %% Styles
    classDef inputStyle fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef prepStyle fill:#A9DFBF,stroke:#145A32,stroke-width:2px;
    classDef workflowStyle fill:#F9E79F,stroke:#7D6608,stroke-width:2px;
    classDef simulationStyle fill:#F5B7B1,stroke:#943126,stroke-width:2px;
    classDef analysisStyle fill:#D7BDE2,stroke:#6C3483,stroke-width:2px;
    classDef docsStyle fill:#FAD7A0,stroke:#7D6608,stroke-width:2px;
    classDef externalStyle fill:#D6EAF8,stroke:#1B4F72,stroke-width:2px;
```
