Alchemical free energies: FEP, BAR and MBAR
The first v2.2 free-energy prototype implements the estimator layer for alchemical transformations. A caller supplies samples with reduced potentials at every alchemical state; the module returns dimensionless free-energy differences and, when a temperature is set, kcal/mol values.
Status. Implemented and exposed on the Rust, Python, WASM and CLI surfaces. This is the statistical estimator; the soft-core MD workflow and replicate exchange around it are still pending. See the v2.x roadmap.
Feature.
alpha-free-energy(included inalpha-v2).
Why an estimator layer
Alchemical free energy is a workflow:
- define the end states;
- run MD at several
λwindows; - collect reduced potentials;
- estimate
ΔFwith FEP, BAR or MBAR; - diagnose overlap and uncertainty.
This module implements step 4 and the overlap diagnostics. It does not create the λ windows or run the MD, so it can be tested against analytic samples independently of the force field.
Reduced potentials
For a sample n and state k,
u and the resulting Δf are dimensionless (kBT). With a temperature T, the result converts to
FEP
For samples drawn from state 0,
FEP is exact in the infinite-sample limit but biased when the forward and reverse work distributions do not overlap.
BAR and MBAR
BAR is the two-state optimum; MBAR generalises it to K states and samples from every state. The MBAR equations are
solved self-consistently with f_0 = 0. The result reports:
delta_f_kbtrelative to state 0;delta_g_kcal_molwhen the temperature is set;- the symmetric overlap matrix
O_kl = Σ_n W_nk W_nl; - the effective sample size
1 / Σ_n W_nk²; - convergence and iteration count.
Bar and Mbar share the same multistate solver; Bar is the two-state case.
API
use sci_form::free_energy::{
AlchemicalSample, FreeEnergyConfig, FreeEnergyEstimator, estimate_free_energy,
};
let samples = vec![
AlchemicalSample {
origin_state: 0,
reduced_potentials: vec![0.0, 1.5],
},
AlchemicalSample {
origin_state: 1,
reduced_potentials: vec![0.0, 1.5],
},
];
let result = estimate_free_energy(
&samples,
FreeEnergyEstimator::Mbar,
&FreeEnergyConfig::default(),
)?;
println!("Δf = {:.3} kBT", result.delta_f_kbt[1]);
println!("ΔG = {:.3} kcal/mol", result.delta_g_kcal_mol.unwrap()[1]);
println!("converged = {}", result.converged);Input rules
- Every sample has one reduced potential per state.
- Every state must contribute at least one sample.
origin_stateis inside0..n_states.- FEP requires exactly two states.
- No non-finite reduced potentials.
Violations are input errors: Python raises ValueError; WASM returns {"error": "..."}. This covers empty samples, wrong state counts, malformed sample arrays, unknown estimators and invalid tolerance, max_iterations, n_states or temperature_k.
Validation
| Gate | Observable | Result |
|---|---|---|
| FEP constant offset | Δf from u1-u0 = 1.5 | 1.5 kBT |
| MBAR constant offset | two states | 1.5 kBT |
| MBAR three states | offsets 0, 1, 2 | 1.0 and 2.0 kBT |
| Invalid shape | one state / wrong length | rejected |
These are analytic estimator tests. A soft-core MD benchmark and a hydration free-energy comparison are still required.
Bindings
| Surface | Entry point |
|---|---|
| CLI | sci-form free-energy '<samples-json>' --estimator mbar [--config ...] |
| WASM | estimate_free_energy(samples_json, estimator, config_json) |
| Python | estimate_free_energy(samples_json, estimator="mbar", config_json=None) |
Estimator names are fep, bar and mbar.
Limitations
- The module does not run MD or create λ windows.
- There is no soft-core potential, endpoint correction or Hamiltonian replica exchange yet.
- The overlap matrix is a diagnostic, not a proof that the estimate converged.
- Effective sample size is reported per state; it does not replace a block or correlation analysis.
- FEP requires state-0 samples and fails hard when none are supplied.
- The implementation assumes all samples are independent; correlated MD frames need subsampling or a correlation-aware estimator.
Next steps
- Add a soft-core λ scheduler on top of the existing dynamics.
- Add Hamiltonian replica exchange and overlap-driven λ refinement.
- Add block averaging and correlation-aware uncertainty.
- Add endpoint corrections for charge changes.
- Benchmark hydration free energies against experiment.
- Add a held-out hydration free-energy benchmark and error model.