xnn.common.config.coerce.coerce_per_species#

xnn.common.config.coerce.coerce_per_species(value, species, key, allow_scalar=True)[source]#

Coerce a per-species config value to a tensor aligned with species.

Accepts a list aligned with species, a {Z: value} or {symbol: value} dict, a single number (broadcast, when allow_scalar), or the string form of any of these.

Parameters:
  • value (Any) – The raw config value; None passes through.

  • species (sequence of int) – The atomic numbers the result is aligned with.

  • key (str) – Config key name (e.g. "atomic_energies (MACE E0s)"), used in error messages.

  • allow_scalar (bool, optional) – Whether a single number is broadcast to every species, by default True.

Returns:

One value per species (default dtype), or None when value is.

Return type:

torch.Tensor or None

Raises:

ValueError – If the value cannot be parsed, a species is missing from a dict, or a list length does not match species.