Add conformer-ensemble thermochemistry helpers - #80
Merged
Conversation
Introduce ThermoScreening.thermo.ensemble with three pure post-processing helpers that combine the absolute Gibbs free energies of several conformers of the same molecule (each computed with matching engine/conditions): - boltzmann_weights(thermos, temperature): normalised populations, computed with a min-energy shift for numerical stability. - ensemble_free_energy(thermos, temperature, unit): the Boltzmann-averaged free energy -k_B T ln(sum exp(-G_i / k_B T)), at or below the lowest conformer by the conformational mixing entropy. - lowest_gibbs(thermos): the single lowest-free-energy conformer. All three are exported from ThermoScreening.thermo. Factor the shared Hartree unit conversions out of reactions.py into a small _units module so both post-processing modules use one source of truth. Adds exact-math and edge-case tests, plus API-reference and usage documentation.
Address review nits: call G_ens the 'ensemble (Boltzmann) free energy' rather than a literal average, and cover a negative temperature (not just zero) in the guard test.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #80 +/- ##
==========================================
+ Coverage 96.85% 96.92% +0.06%
==========================================
Files 26 28 +2
Lines 1655 1689 +34
==========================================
+ Hits 1603 1637 +34
Misses 52 52
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
ThermoScreening.thermo.ensemble, three pure post-processing helpers that combine the absolute Gibbs free energies (Thermo.total_EeGtot(), in Hartree) of several conformers of the same molecule into ensemble properties. Compute each conformer with matching engine/conditions (generate→xtb_cli_thermo/…), then combine:boltzmann_weights(thermos, temperature=298.15)— normalised conformer populations, evaluated with a min-energy shift for numerical stability.ensemble_free_energy(thermos, temperature=298.15, unit="H")— the Boltzmann-averaged free energy-k_B T ln( Σ exp(-G_i / k_B T) ), which sits at or below the lowest conformer's free energy by the conformational mixing entropy. UnitsH/eV/kcal/kJ.lowest_gibbs(thermos)— the single lowest-free-energy conformer (to carry a dominant structure forward, e.g. intoreaction_free_energy).All three are exported from
ThermoScreening.thermo. This is the natural consumer of the existing conformer generation + screening features.Refactor
Factors the shared Hartree →
eV/kcal/kJconversions out ofreactions.pyinto a small private_unitsmodule (convert_from_hartree), so both post-processing modules use one source of truth.reactions.pypublic behaviour is unchanged.Tests
Exact-math and physics checks: degenerate populations (0.5/0.5), single-conformer identity, normalisation + ordering, a known
k_B*T-gap ratio (e:1), single-conformer ensemble = its own G, degenerate mixing entropy (G_ens = G - k_B T ln 2 < G), ensemble ≤ minimum, unit conversion, and edge cases (empty ensemble, non-positive temperature, unknown unit).Docs
API-reference entries plus a "Conformer ensembles" usage section with a worked n-butanol example.