xnn.common.models.ops.whole_structure_sum#

xnn.common.models.ops.whole_structure_sum(src, index, dim_size)[source]#

scatter_sum() of per-atom rows into per-structure totals over every atom of a structure, also when the structure is split over several processes.

Under DomainParallel a process holds only part of the structure (its own atoms plus copies of their neighbors): the total is then summed over the owned atoms of every process, differentiably. Models whose energy depends on such a total (a charge constraint) call this instead of scatter_sum(). Scripted code takes the plain sum.

Parameters:
  • src (torch.Tensor) – Per-atom values (N, *feature_dims).

  • index (torch.Tensor) – Structure index of every atom (N,).

  • dim_size (int) – Number of structures.

Returns:

Per-structure totals (dim_size, *feature_dims).

Return type:

torch.Tensor