-
Notifications
You must be signed in to change notification settings - Fork 53
Feat/add folmsbee conformer benchmark #429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ElliottKasoar
merged 45 commits into
ddmms:main
from
lwehrhan:feat/add-folmsbee-conformer-benchmark
Jul 24, 2026
Merged
Changes from 3 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
b542fd3
feat: calc folmsbee
leonwehrhan e82bc26
fix: units
leonwehrhan cd4e9da
feat: add analysis script
leonwehrhan e03bf30
add flomsbee app and metrics.yml
joehart2001 e2ab058
feat: calc folmsbee
leonwehrhan 398fd9b
fix: units
leonwehrhan d682fb0
feat: add analysis script
leonwehrhan 894c1ef
add flomsbee app and metrics.yml
joehart2001 efb1ea1
s3 download for calc, calc analysis and app fixes
joehart2001 3fad5b7
add framework details
joehart2001 c484172
Merge branch 'feat/add-folmsbee-conformer-benchmark' of https://githu…
leonwehrhan caf5786
feat: use mlip audit benchmark classes
leonwehrhan e0a3fd2
docs: add folmsbee docs
leonwehrhan 7865726
chore: address comments
leonwehrhan c04d09b
feat: update MAE per molecule calculation
leonwehrhan be2a8af
feat: add logo
leonwehrhan d5dbfba
docs: update computational cost
leonwehrhan a52d70d
chore: revert data loading
leonwehrhan 45af22f
Merge remote-tracking branch 'origin/main' into feat/add-folmsbee-con…
leonwehrhan 355dbd6
fix: udate metrics to include mlip audit conformer score
leonwehrhan bddec04
fix: input filename and calculator precision
leonwehrhan 83d6314
feat: calc folmsbee
leonwehrhan cd07bb2
fix: units
leonwehrhan f50419a
feat: add analysis script
leonwehrhan ecf8db2
add flomsbee app and metrics.yml
joehart2001 70aa349
s3 download for calc, calc analysis and app fixes
joehart2001 ca8a18c
add framework details
joehart2001 7f5b8f4
feat: use mlip audit benchmark classes
leonwehrhan 6742dc5
docs: add folmsbee docs
leonwehrhan b40790b
chore: address comments
leonwehrhan 33e99de
feat: update MAE per molecule calculation
leonwehrhan f602153
feat: add logo
leonwehrhan 8809ee8
docs: update computational cost
leonwehrhan c565f2d
chore: revert data loading
leonwehrhan a5f95b8
fix: udate metrics to include mlip audit conformer score
leonwehrhan 364105d
fix: input filename and calculator precision
leonwehrhan 119ec4b
Fix mlipaudit dependency
ElliottKasoar 50943a5
Skip benchmark if mlipaudit not installed
ElliottKasoar f136529
Save info.json during analysis
ElliottKasoar 9d0d4e2
Make analysis robust to missing data
ElliottKasoar 7e1e9c1
Read info.json in app
ElliottKasoar 47bc551
Save data during calculation for analysis
ElliottKasoar 4f3270c
Handle data file with None/NaN values
ElliottKasoar 82ed5e9
Merge branch 'feat/add-folmsbee-conformer-benchmark' of https://githu…
lwehrhan 1859bf7
docs: update computational cost and metrics
lwehrhan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
134 changes: 134 additions & 0 deletions
134
ml_peg/analysis/conformers/Folmsbee/analyse_Folmsbee.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| """Analyse Folmsbee benchmark.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| from ase import units | ||
| from ase.io import read, write | ||
| import pytest | ||
|
|
||
| from ml_peg.analysis.utils.decorators import build_table, plot_parity | ||
| from ml_peg.analysis.utils.utils import ( | ||
| build_dispersion_name_map, | ||
| load_metrics_config, | ||
| mae, | ||
| ) | ||
| from ml_peg.app import APP_ROOT | ||
| from ml_peg.calcs import CALCS_ROOT | ||
| from ml_peg.models.get_models import load_models | ||
| from ml_peg.models.models import current_models | ||
|
|
||
| MODELS = load_models(current_models) | ||
| DISPERSION_NAME_MAP = build_dispersion_name_map(MODELS) | ||
|
|
||
| EV_TO_KCAL = units.mol / units.kcal | ||
| CALC_PATH = CALCS_ROOT / "conformers" / "Folmsbee" / "outputs" | ||
| OUT_PATH = APP_ROOT / "data" / "conformers" / "Folmsbee" | ||
|
|
||
| METRICS_CONFIG_PATH = Path(__file__).with_name("metrics.yml") | ||
| DEFAULT_THRESHOLDS, DEFAULT_TOOLTIPS, DEFAULT_WEIGHTS = load_metrics_config( | ||
| METRICS_CONFIG_PATH | ||
| ) | ||
|
|
||
|
|
||
| def labels() -> list: | ||
| """ | ||
| Get list of system names. | ||
|
|
||
| Returns | ||
| ------- | ||
| list | ||
| List of all system names. | ||
| """ | ||
| for model_name in MODELS: | ||
| labels_list = [path.stem for path in sorted((CALC_PATH / model_name).glob("*"))] | ||
| break | ||
| return labels_list | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| @plot_parity( | ||
| filename=OUT_PATH / "figure_folmsbee.json", | ||
| title="Energies", | ||
| x_label="Predicted energy / kcal/mol", | ||
| y_label="Reference energy / kcal/mol", | ||
| hoverdata={ | ||
| "Labels": labels(), | ||
| }, | ||
| ) | ||
| def conformer_energies() -> dict[str, list]: | ||
| """ | ||
| Get conformer energies for all systems. | ||
|
|
||
| Returns | ||
| ------- | ||
| dict[str, list] | ||
| Dictionary of all reference and predicted barrier heights. | ||
| """ | ||
| results = {"ref": []} | {mlip: [] for mlip in MODELS} | ||
| ref_stored = False | ||
|
|
||
| for model_name in MODELS: | ||
| for label in labels(): | ||
| atoms = read(CALC_PATH / model_name / f"{label}.xyz") | ||
|
|
||
| results[model_name].append(atoms.info["model_rel_energy"] * EV_TO_KCAL) | ||
| if not ref_stored: | ||
| results["ref"].append(atoms.info["ref_energy"] * EV_TO_KCAL) | ||
|
|
||
| # Write structures for app | ||
| structs_dir = OUT_PATH / model_name | ||
| structs_dir.mkdir(parents=True, exist_ok=True) | ||
| write(structs_dir / f"{label}.xyz", atoms) | ||
| ref_stored = True | ||
| return results | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def get_mae(conformer_energies) -> dict[str, float]: | ||
| """ | ||
| Get mean absolute error for conformer energies. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| conformer_energies | ||
| Dictionary of reference and predicted conformer energies. | ||
|
|
||
| Returns | ||
| ------- | ||
| dict[str, float] | ||
| Dictionary of predicted conformer energies errors for all models. | ||
| """ | ||
| results = {} | ||
| for model_name in MODELS: | ||
| results[model_name] = mae( | ||
| conformer_energies["ref"], conformer_energies[model_name] | ||
| ) | ||
| return results | ||
|
lwehrhan marked this conversation as resolved.
|
||
|
|
||
|
|
||
| @pytest.fixture | ||
| @build_table( | ||
| filename=OUT_PATH / "folmsbee_metrics_table.json", | ||
| metric_tooltips=DEFAULT_TOOLTIPS, | ||
| thresholds=DEFAULT_THRESHOLDS, | ||
| mlip_name_map=DISPERSION_NAME_MAP, | ||
| ) | ||
| def metrics(get_mae: dict[str, float]) -> dict[str, dict]: | ||
| """ | ||
| Get all metrics. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| get_mae | ||
| Mean absolute errors for all models. | ||
|
|
||
| Returns | ||
| ------- | ||
| dict[str, dict] | ||
| Metric names and values for all models. | ||
| """ | ||
| return { | ||
| "MAE": get_mae, | ||
| } | ||
|
lwehrhan marked this conversation as resolved.
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| """ | ||
| Compute the Folmsbee dataset of molecular conformers. | ||
|
|
||
| Assessing conformer energies using electronic structure and | ||
| machine learning methods | ||
|
|
||
| Dakota Folmsbee, Geoffrey Hutchinson | ||
| International Journal of Quantum Chemistry 2020 121 (1) e26381 | ||
| DOI: 10.1002/qua.26381 | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| from pathlib import Path | ||
| from typing import Any | ||
|
|
||
| from ase import Atoms, units | ||
| from ase.io import write | ||
| import pytest | ||
| from tqdm import tqdm | ||
|
|
||
| from ml_peg.models.get_models import load_models | ||
|
lwehrhan marked this conversation as resolved.
|
||
| from ml_peg.models.models import current_models | ||
|
|
||
| MODELS = load_models(current_models) | ||
|
|
||
| KCAL_TO_EV = units.kcal / units.mol | ||
|
|
||
| OUT_PATH = Path(__file__).parent / "outputs" | ||
|
|
||
|
|
||
| def get_relative_energies(energies: list[float], ref_idx: int) -> list[float]: | ||
| """ | ||
| Get energies relative to reference. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| energies | ||
| List of energy values. | ||
| ref_idx | ||
| Index of reference energy. | ||
|
|
||
| Returns | ||
| ------- | ||
| list[float] | ||
| Energies relative to the reference conformer. | ||
| """ | ||
| return [x - energies[ref_idx] for x in energies] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("mlip", MODELS.items()) | ||
| def test_folmsbee(mlip: tuple[str, Any]) -> None: | ||
| """ | ||
| Benchmark the Folmsbee dataset. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| mlip | ||
| Name of model use and model to get calculator. | ||
| """ | ||
| model_name, model = mlip | ||
| # Use double precision | ||
| model.default_dtype = "float64" | ||
|
lwehrhan marked this conversation as resolved.
Outdated
|
||
| calc = model.get_calculator() | ||
|
lwehrhan marked this conversation as resolved.
|
||
| # Add D3 calculator for this test | ||
| calc = model.add_d3_calculator(calc) | ||
|
|
||
| data_path = Path(__file__).parent / "data" / "folmsbee_dataset.json" | ||
|
lwehrhan marked this conversation as resolved.
Outdated
|
||
| out_path = OUT_PATH / model_name | ||
|
|
||
| with open(data_path) as f: | ||
| data = json.load(f) | ||
| progress = tqdm(total=len(data)) | ||
| for structure_data in data: | ||
| structure_name = structure_data["molecule_name"] | ||
| conformers = [] | ||
| model_energies = [] | ||
| raw_energies = structure_data["dft_energy_profile"] | ||
| ref_min_conformer_idx = raw_energies.index(min(raw_energies)) | ||
| ref_energies = get_relative_energies(raw_energies, ref_min_conformer_idx) | ||
| ref_energies *= KCAL_TO_EV | ||
|
|
||
| for i, conf_positions in enumerate(structure_data["conformer_coordinates"]): | ||
| conf_atoms = Atoms( | ||
| positions=conf_positions, symbols=structure_data["atom_symbols"] | ||
| ) | ||
| conf_atoms.calc = calc | ||
| conf_atoms.info.update({"charge": 0, "spin": 1}) | ||
| conf_atoms.info["ref_rel_energy"] = ref_energies[i] | ||
|
|
||
| conformers.append(conf_atoms) | ||
| model_energies.append(conf_atoms.get_potential_energy()) | ||
|
|
||
| model_energies = get_relative_energies(model_energies, ref_min_conformer_idx) | ||
| out_path.mkdir(parents=True, exist_ok=True) | ||
| for i, conf_atoms in enumerate(conformers): | ||
| conf_atoms.info["model_rel_energy"] = model_energies[i] | ||
| write(out_path / f"{structure_name}_conf{i}.xyz", conf_atoms) | ||
|
|
||
| progress.update() | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.