jaxrens.backends.hamiltonian¶
Hamiltonian — one energy model plus a flat tuple of additive energy terms.
The sampled Hamiltonian is composed, not nested:
H = U_model + sum_k E_term_k
where U_model is a bare EnergyBackend
(MACE, NeuralIL, LJ, …) and each term is a model-independent
EnergyTerm (soft-core repulsion, ensemble P·V − μ·N, …).
Every layer contributes its own energy and forces, which are summed:
the model uses its native
energy_and_forceswhen it has one (e.g. NeuralIL’scalc_potential_energy_and_forces), and autodiff of its energy otherwise — viaeval_energy_and_forces();each term returns
(energy, forces)fromEnergyTerm.energy_and_forces(), which defaults to autodiff of that term alone and can be overridden with analytic forces (e.g. zeros for the position-independent ensemble terms).
Nothing is differentiated through a layer it does not own.
There is deliberately no __getattr__ forwarding to the model.
Forwarding made earlier wrapper backends impersonate the model for every
attribute — including optional capabilities such as energy_and_forces,
whose meaning changes once a term is added on top — so a native-force
lookup on the wrapper silently skipped the wrapper’s own terms. Model
metadata (atomic_numbers, max_neighbors_for, is_ensemble, …)
is reached explicitly via hamiltonian.model or unwrap_model().
Usage:
from jaxrens.backends.ensemble import EnsembleTerm
from jaxrens.backends.softcore import SoftCoreTerm
H = Hamiltonian(model, [SoftCoreTerm(), EnsembleTerm(pressure=P)])
H(positions, species, cell, max_neighbors).energy # U + E_core + P·V
Functions
The bare energy model behind |
Classes
Additive, model-independent contribution to the Hamiltonian. |
|
Energy model plus additive terms; satisfies the EnergyBackend protocol. |