torchref.base.electron_density.map_building module

Electron density map building functions.

Functions for adding atomic contributions to electron density maps using ITC92 Gaussian parameterization.

torchref.base.electron_density.map_building.scatter_add_nd_super_slow(source, index, map)[source]

Non-vectorized n-dimensional scatter add operation (slow reference implementation).

Parameters:
  • source (torch.Tensor) – Values to add to the map of shape (N,).

  • index (torch.Tensor) – Indices where values should be added of shape (N, ndim).

  • map (torch.Tensor) – N-dimensional tensor to add values into.

Returns:

Modified map with values added.

Return type:

torch.Tensor

torchref.base.electron_density.map_building.scatter_add_nd(source, index, map)[source]

Vectorized n-dimensional scatter add operation.

Parameters:
  • source (torch.Tensor) – Values to add to the map of shape (N,).

  • index (torch.Tensor) – Indices where values should be added of shape (N, ndim).

  • map (torch.Tensor) – N-dimensional tensor of shape (d1, d2, …, dn) to add values into.

Returns:

Modified map with values added.

Return type:

torch.Tensor

torchref.base.electron_density.map_building.vectorized_add_to_map(surrounding_coords, voxel_indices, map, xyz, b, inv_frac_matrix, frac_matrix, A, B, occ)[source]

Add atoms to density map using ITC92 Gaussian parameterization.

Parameters:
  • surrounding_coords (torch.Tensor) – Coordinates of voxels around each atom of shape (N_atoms, N_voxels, 3).

  • voxel_indices (torch.Tensor) – Indices of voxels in the map of shape (N_atoms, N_voxels, 3).

  • map (torch.Tensor) – Electron density map of shape (nx, ny, nz).

  • xyz (torch.Tensor) – Atom positions of shape (N_atoms, 3).

  • b (torch.Tensor) – B-factors (thermal parameters) in Angstroms squared of shape (N_atoms,).

  • inv_frac_matrix (torch.Tensor) – Inverse fractionalization matrix of shape (3, 3).

  • frac_matrix (torch.Tensor) – Fractionalization matrix of shape (3, 3).

  • A (torch.Tensor) – ITC92 amplitude coefficients for each atom of shape (N_atoms, 5).

  • B (torch.Tensor) – ITC92 width coefficients (b parameters) in Angstroms squared for each atom of shape (N_atoms, 5).

  • occ (torch.Tensor) – Occupancies for each atom of shape (N_atoms,).

Returns:

Updated electron density map.

Return type:

torch.Tensor

torchref.base.electron_density.map_building.vectorized_add_to_map_aniso(surrounding_coords, voxel_indices, map, xyz, U, inv_frac_matrix, frac_matrix, A, B, occ)[source]

Add anisotropic atoms to density map using ITC92 Gaussian parameterization.

Uses the same convention as the isotropic case for consistency: - B_total = (B_itc92 + B_atomic) / 4 - rho = A × (π/B_total)^(3/2) × exp(-π² r² / B_total)

For anisotropic atoms, this generalizes to: - B_atomic_ij = 8π² × U_atomic_ij (standard crystallographic conversion) - B_total_ij = (B_itc92 × δ_ij + 8π² × U_atomic_ij) / 4 - Normalization: (π³ / det(B_total))^(1/2) - Exponent: exp(-π² × r^T × B_total^(-1) × r)

Parameters:
  • surrounding_coords (torch.Tensor) – Coordinates of voxels around each atom of shape (N_atoms, N_voxels, 3).

  • voxel_indices (torch.Tensor) – Indices of voxels in the map of shape (N_atoms, N_voxels, 3).

  • map (torch.Tensor) – Electron density map of shape (nx, ny, nz).

  • xyz (torch.Tensor) – Atom positions in Cartesian coordinates of shape (N_atoms, 3).

  • U (torch.Tensor) – Anisotropic displacement parameters in Angstroms squared (u11, u22, u33, u12, u13, u23) of shape (N_atoms, 6).

  • inv_frac_matrix (torch.Tensor) – Inverse fractionalization matrix of shape (3, 3).

  • frac_matrix (torch.Tensor) – Fractionalization matrix of shape (3, 3).

  • A (torch.Tensor) – ITC92 amplitude coefficients for each atom of shape (N_atoms, 5).

  • B (torch.Tensor) – ITC92 width coefficients (b parameters) in Angstroms squared for each atom of shape (N_atoms, 5).

  • occ (torch.Tensor) – Occupancies for each atom of shape (N_atoms,).

Returns:

Updated electron density map.

Return type:

torch.Tensor