# Data and analysis scripts 
*Carlos Corral-Casas, Chiara Gattinoni, Mark Brewer, Alastair Smith, Daniele Dini, and James P. Ewen* (2026).

---

It is organised in two self-contained tracks:

- **Track A — Free energies** (`free_energy/`): adsorption PMFs — **Figs 3 and 8**.
- **Track B — Structure** (`structural_analyses/`): RDFs and hydrogen-bond analyses — **Figs 4–7 and 9–12**.

**Full MD trajectories are not deposited** (tens of GB per run). Together with the supplementary free-energy data (the PMF-convergence diagnostics of Section S1 and the temperature series of Fig S11), these are available from the corresponding author on reasonable request. To keep Track B runnable on download, one example trajectory (betaine, 5% ethanol) is included under `structural_analyses/example_trajectory/`: the base segment of each window, enough to drive the scripts end-to-end (trajectory to script to .npz).

## Directory layout

```
.
|-- README.md                 (this file)
|-- environment.yml           (pinned Python environment for Track B)
|
|-- free_energy/                        TRACK A -- adsorption free energies (Figs 3, 8)
|   |-- <system>/run_N/       abf_full.{count,grad,pmf}: stitched ABF output, one set per run
|   |                           betaine_{5,10,15}E (2 runs); mannich_{0,5,15,30,85}E (3 runs)
|   `-- template/             one LAMMPS script, one Colvars ABF config, and a betaine and a
|                               Mannich topology (.data); the protocol is shared across systems
|
`-- structural_analyses/                TRACK B -- RDFs and hydrogen bonds
    |-- scripts/              rdf.py, hbonds.py (analysis); figures.py (worked example)
    |-- example_trajectory/   betaine_5E base segments and two topology files (runnable demo)
    `-- results/              <system>_rdf_results.npz, <system>_hbond_results.npz
```

## Figures: where the data lives and how to regenerate it

- **Fig 3** — betaine adsorption PMFs. Data: `free_energy/betaine_*E/run_*/abf_full.pmf`. Each run is referenced to G = 0 at the unbound plateau (xi = 18 Angstrom), then averaged across runs and plotted as a +/- 1 SD band.
- **Fig 8** — Mannich-base PMFs. Data: `free_energy/mannich_*E/run_*/abf_full.pmf`. Same procedure.
- **Figs 4 and 9** — RDFs, g(r)*rho. Data: `structural_analyses/results/<system>_rdf_results.npz`. Reproduce with `rdf.py`, then `figures.py`.
- **Figs 5, 6, 10 and 11** — hydrogen-bond z-profiles. Data: `structural_analyses/results/<system>_hbond_results.npz`. Reproduce with `hbonds.py`, then `figures.py`.
- **Figs 7 and 12** — hydrogen-bond lifetimes. Data: the same `<system>_hbond_results.npz`. Reproduce with `hbonds.py`, then `figures.py`.

Each `abf_full.pmf` is accompanied by `abf_full.count` (sampling histogram) and `abf_full.grad` (mean force), so the PMF can be re-integrated and its sampling checked.

## Reproducing Track B (structure) — runs on download

```
cd structural_analyses/scripts
python rdf.py        # ethanol + iso-octane RDFs        -> rdf_results.npz
python hbonds.py     # H-bond counts, z-profile, C(t)   -> hbond_results.npz
python figures.py    # worked example: .npz -> plotted quantities
```

- The scripts are written for the betaine_5E example; the same analysis was applied to every system (betaine and Mannich, all concentrations) with the corresponding head-group selections; the deposited `.npz` in `results/` cover all eight.
- `example_trajectory/` holds the base segment of each window only (for size); the scripts pick up whatever segments are present, so they run unchanged. The published `.npz` were built from the full base+continuation trajectories (available on request).
- Only `st2` stores the (majority) iso-octane solvent (read against `qas_5E.data`); `st1/3/4/5` carry the DCA+deposit+ethanol subset (read against `topology_subset.lammpstrj`).
- Each `.npz` carries its own `schema` entry listing exactly what it holds, for example: `python -c "import numpy as np; print(str(np.load('structural_analyses/results/betaine_5E_rdf_results.npz')['schema']))"`.
- Strides default to the production values (`STEP_COUNT=5`, lifetime `WINDOW_STEP=1`); raise them for a faster, statistically equivalent run (see the comments in `hbonds.py`).

## Reproducing Track A (free energies)

Each `free_energy/<system>/run_N/` holds the stitched ABF output (`abf_full.count`, `abf_full.grad`, `abf_full.pmf`) for one independent run; Figs 3 and 8 are the run-averaged PMFs. The ABF protocol is identical across all systems, so `free_energy/template/` provides one representative set of inputs: a LAMMPS input script (`prod_script.lammps`), a Colvars/ABF window configuration (`col_abf.config`), and two pre-processed topologies (a betaine `qas_5E.data` and a Mannich `mannich_15E.data`). Only the per-window collective-variable range and the topology differ between systems. Re-running the sampling requires **LAMMPS** built with the **Colvars** module.

## Software

- LAMMPS, with the Colvars module
- Python 3.10.12
- MDAnalysis 2.9.0
- NumPy 1.26.4, SciPy 1.15.3

`environment.yml` pins the Python side used for Track B.

## Contact

Dr Carlos Corral-Casas — c.corral-casas@imperial.ac.uk — Imperial College London
