xnn.common.train.reactions.ReactionSet#

class xnn.common.train.reactions.ReactionSet(structures, reactions, units='eV')[source]#

Bases: object

Reactions over a list of species structures.

Parameters:
  • structures (sequence of dict) – The species, structure dicts as structure_to_graph() takes them, each with a "name" (and optionally a "subset", which together key the species).

  • reactions (sequence of dict) – One record per reaction: "species" (names), "stoichiometry" (signed coefficients), "reference" (the reaction energy), optionally "subset" (the species are looked up under it), "weight" and "scale" (see reaction_energy_loss()).

  • units (str, optional) – Units of the references: "eV" (default), "kcal/mol" or "hartree"; they are kept in eV.

Variables:
  • structures (list of dict) – The species.

  • members (list of tuple) – The species indices and coefficients of every reaction.

  • scale (reference, weight,) – Per-reaction references (eV), weights and error scales (R,).

  • labels (list) – (subset, index) of every reaction (index its position when the records carry none).

classmethod from_gmtkn55(data, wtmad2=False, scale=56.84)[source]#

The reactions of load_dataset("gmtkn55") (references in kcal/mol).

Parameters:
  • data (dict) – {"structures": [...], "reactions": [...]} as the dataset returns them.

  • wtmad2 (bool, optional) – Scale the errors of every set by scale / <|dE|> (its mean absolute reference energy), the weighting of WTMAD-2; default False.

  • scale (float, optional) – The constant of that weighting in kcal/mol; default 56.84 (the paper’s).

Return type:

ReactionSet

subset(reactions)[source]#

The given reactions with the species they need (in the order first met).

Parameters:

reactions (Sequence[int])

Return type:

ReactionSet

stoichiometry()[source]#

The coefficients (R, S) (float64).

Return type:

Tensor

graphs(cutoff)[source]#

The species as graphs with neighbor lists of radius cutoff (built once per radius).

Parameters:

cutoff (float)

Return type:

list[AtomicGraph]

batches(size, shuffle=True, seed=0)[source]#

Mini-batches of size reactions covering the set once (shuffled by seed), each a subset() with the species it needs.

Parameters:
Return type:

Iterator[ReactionSet]

species_energies(model, cutoff, batch_size=32, device=None)[source]#

The energies (S,) of the species from model(graph)["energy"], in batches of structures (differentiable in the model’s parameters when gradients are enabled).

Parameters:
Return type:

Tensor

loss(species_energy, huber_delta=0.0)[source]#

reaction_energy_loss() of these reactions for the species energies (S,).

Parameters:
Return type:

Tensor

errors(species_energy)[source]#

Predicted minus reference reaction energies (R,) in eV (unscaled).

Parameters:

species_energy (Tensor)

Return type:

Tensor