Datasets:
File size: 2,888 Bytes
e579e7e | 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 | """Core helpers for the TRIP50 dataset: alias resolution and reaction quantities.
Used by the release producer (`build_hf_release.py`), the round-trip verifier
(`examples/verify_release.py`), and the example MLIP evaluator
(`examples/evaluate_mlip.py`). Kept dependency-light so it ships with the
release without pulling in optional libraries.
"""
from __future__ import annotations
HARTREE_TO_KCAL = 627.5094740631
ROLES = ("R1", "R2", "TS", "P1", "P2")
def lookup(species_name, source, alias_map):
"""Energy for `species_name` in `source` (a Mapping or pandas Series indexed
by species id), with alias resolution. Returns None if not present."""
name = alias_map.get(species_name, species_name)
return source.get(name, None)
def required_roles(rxn_id, dlpno_source, alias_map):
"""Roles that the rxn definition requires (i.e., DLPNO has a non-null value
for that species). Unimolecular legs (R2 and/or P2 absent) drop out."""
return {role for role in ROLES
if lookup(f"{rxn_id}-{role}", dlpno_source, alias_map) is not None}
def reaction_quantities(source, dlpno_source, alias_map):
"""Compute ΔE_rxn, ΔE_fwd, ΔE_rev (kcal/mol) for every TRIP50 reaction
defined in `dlpno_source`. A reaction's quantity is included only when
every role required by the DLPNO definition is also resolvable in `source`.
Unimolecular legs (roles absent from DLPNO) contribute 0 H on both sides.
Returns three dicts {rxn_id: kcal_value}.
"""
rxn, fwd, rev = {}, {}, {}
for r in range(1, 51):
req = required_roles(r, dlpno_source, alias_map)
e = {role: (lookup(f"{r}-{role}", source, alias_map) or 0.0) for role in ROLES}
ok = lambda needed: all((lookup(f"{r}-{role}", source, alias_map) is not None)
for role in (needed & req))
if {"R1", "P1"} <= req and ok({"R1", "R2", "P1", "P2"}):
rxn[r] = ((e["P1"] + e["P2"]) - (e["R1"] + e["R2"])) * HARTREE_TO_KCAL
if {"R1", "TS"} <= req and ok({"R1", "R2", "TS"}):
fwd[r] = (e["TS"] - (e["R1"] + e["R2"])) * HARTREE_TO_KCAL
if {"P1", "TS"} <= req and ok({"P1", "P2", "TS"}):
rev[r] = (e["TS"] - (e["P1"] + e["P2"])) * HARTREE_TO_KCAL
return rxn, fwd, rev
def slugify_method(name):
"""Reversible slug for a method/theory name. Mapping is recorded in
methods.json at release time so consumers can recover the display name."""
s = name
s = s.replace("ω", "omega").replace("Ω", "omega")
s = s.replace("κ", "kappa").replace("Κ", "kappa")
s = s.lower()
out = []
for ch in s:
if ch.isalnum():
out.append(ch)
elif ch in "-/() ":
out.append("_")
# drop everything else
slug = "".join(out)
while "__" in slug:
slug = slug.replace("__", "_")
return slug.strip("_")
|