-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathanalyse_37Conf8.py
More file actions
146 lines (118 loc) · 3.54 KB
/
Copy pathanalyse_37Conf8.py
File metadata and controls
146 lines (118 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
"""
Analyse 37Conf8 conformer energy benchmark.
10.1002/cphc.201801063.
"""
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_d3_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)
D3_MODEL_NAMES = build_d3_name_map(MODELS)
EV_TO_KCAL = units.mol / units.kcal
CALC_PATH = CALCS_ROOT / "conformers" / "37Conf8" / "outputs"
OUT_PATH = APP_ROOT / "data" / "conformers" / "37Conf8"
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_37conf8.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 barrier heights for all systems.
Returns
-------
dict[str, list]
Dictionary of all reference and predicted energies.
"""
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
@pytest.fixture
@build_table(
filename=OUT_PATH / "37conf8_metrics_table.json",
metric_tooltips=DEFAULT_TOOLTIPS,
thresholds=DEFAULT_THRESHOLDS,
mlip_name_map=D3_MODEL_NAMES,
)
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,
}
def test_37conf8(metrics: dict[str, dict]) -> None:
"""
Run 37Conf8 barriers test.
Parameters
----------
metrics
All new benchmark metric names and dictionary of values for each model.
"""
return