How michellab/a3fe works
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!