torchref.base.direct_summation package

Structure factor calculation functions.

This submodule provides functions for computing structure factors from atomic models: - Isotropic structure factor calculations - Anisotropic structure factor calculations - Correction terms (anharmonic, core deformation)

torchref.base.direct_summation.iso_structure_factor_torched(hkl, s, xyz_fractional, occ, scattering_factors, adp, spacegroup, max_memory_gb=None, A=None, B_coeff=None)[source]

Calculate isotropic structure factors using PyTorch.

Parameters:
  • hkl (torch.Tensor) – Miller indices of shape (N_reflections, 3).

  • s (torch.Tensor) – Scattering vector magnitudes of shape (N_reflections,).

  • xyz_fractional (torch.Tensor) – Fractional coordinates of shape (N_atoms, 3).

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

  • scattering_factors (torch.Tensor or None) – Atomic scattering factors of shape (N_reflections, N_atoms). If None, must provide A and B_coeff to compute them in batches.

  • adp (torch.Tensor) – Atomic displacement parameters (isotropic) of shape (N_atoms,).

  • spacegroup (callable) – Space group symmetry operator function.

  • max_memory_gb (float, optional) – Maximum memory to use in GB. If None, no batching is applied.

  • A (torch.Tensor, optional) – ITC92 A coefficients (N_atoms, 5) for computing scattering factors. Required if scattering_factors is None and batching is needed.

  • B_coeff (torch.Tensor, optional) – ITC92 B coefficients (N_atoms, 5) for computing scattering factors. Required if scattering_factors is None and batching is needed.

Returns:

Complex structure factors of shape (N_reflections,).

Return type:

torch.Tensor

torchref.base.direct_summation.iso_structure_factor_torched_no_complex(hkl, s, fractional_coords, occ, scattering_factors, tempfactor, space_group)[source]

Calculate isotropic structure factors without complex numbers.

Returns real and imaginary parts as separate rows.

Parameters:
  • hkl (torch.Tensor) – Miller indices of shape (N_reflections, 3).

  • s (torch.Tensor) – Scattering vector magnitudes of shape (N_reflections,).

  • fractional_coords (torch.Tensor) – Fractional coordinates of shape (N_atoms, 3).

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

  • scattering_factors (torch.Tensor) – Atomic scattering factors of shape (N_reflections, N_atoms).

  • tempfactor (torch.Tensor) – Isotropic temperature factors (B-factors) of shape (N_atoms,).

  • space_group (callable) – Space group symmetry operator function.

Returns:

Structure factors as [real, imag] of shape (2, N_reflections).

Return type:

torch.Tensor

torchref.base.direct_summation.aniso_structure_factor_torched(hkl, s_vector, xyz_fractional, occ, scattering_factors, U, spacegroup, max_memory_gb=None, A=None, B_coeff=None)[source]

Calculate anisotropic structure factors using PyTorch.

Parameters:
  • hkl (torch.Tensor) – Miller indices of shape (N_reflections, 3).

  • s_vector (torch.Tensor) – Scattering vectors of shape (N_reflections, 3).

  • xyz_fractional (torch.Tensor) – Fractional coordinates of shape (N_atoms, 3).

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

  • scattering_factors (torch.Tensor or None) – Atomic scattering factors of shape (N_reflections, N_atoms). If None, must provide A and B_coeff to compute them in batches.

  • U (torch.Tensor) – Anisotropic displacement parameters of shape (N_atoms, 6).

  • spacegroup (callable) – Space group symmetry operator function.

  • max_memory_gb (float, optional) – Maximum memory to use in GB. If None, no batching is applied.

  • A (torch.Tensor, optional) – ITC92 A coefficients (N_atoms, 5) for computing scattering factors.

  • B_coeff (torch.Tensor, optional) – ITC92 B coefficients (N_atoms, 5) for computing scattering factors.

Returns:

Complex structure factors of shape (N_reflections,).

Return type:

torch.Tensor

torchref.base.direct_summation.aniso_structure_factor_torched_no_complex(hkl, s_vector, fractional_coords, occ, scattering_factors, U, space_group)[source]

Calculate anisotropic structure factors without complex numbers.

Returns real and imaginary parts as separate rows.

Parameters:
  • hkl (torch.Tensor) – Miller indices of shape (N_reflections, 3).

  • s_vector (torch.Tensor) – Scattering vectors of shape (N_reflections, 3).

  • fractional_coords (torch.Tensor) – Fractional coordinates of shape (N_atoms, 3).

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

  • scattering_factors (torch.Tensor) – Atomic scattering factors of shape (N_reflections, N_atoms).

  • U (torch.Tensor) – Anisotropic displacement parameters of shape (N_atoms, 6).

  • space_group (callable) – Space group symmetry operator function.

Returns:

Structure factors as [real, imag] of shape (2, N_reflections).

Return type:

torch.Tensor

torchref.base.direct_summation.anharmonic_correction(hkl, c)[source]

Apply anharmonic (third-order) correction to structure factors.

Parameters:
  • hkl (torch.Tensor) – Miller indices of shape (N_reflections, 3).

  • c (tuple or list) – Ten anharmonic coefficients (C111, C222, C333, C112, C122, C113, C133, C223, C233, C123).

Returns:

Complex anharmonic correction factors of shape (N_reflections,).

Return type:

torch.Tensor

torchref.base.direct_summation.anharmonic_correction_no_complex(hkl, c)[source]

Apply anharmonic (third-order) correction without complex numbers.

Returns real and imaginary parts as separate rows.

Parameters:
  • hkl (torch.Tensor) – Miller indices of shape (N_reflections, 3).

  • c (tuple or list) – Ten anharmonic coefficients (C111, C222, C333, C112, C122, C113, C133, C223, C233, C123).

Returns:

Correction factors as [cos, sin] of shape (2, N_reflections).

Return type:

torch.Tensor

torchref.base.direct_summation.core_deformation(core_correction, s)[source]

Apply core deformation correction to scattering.

Parameters:
Returns:

Core deformation correction factors.

Return type:

torch.Tensor

torchref.base.direct_summation.multiplication_quasi_complex_tensor(a, b)[source]

Multiply two quasi-complex tensors represented as [real, imag] rows.

Parameters:
  • a (torch.Tensor) – First quasi-complex tensor of shape (2, N).

  • b (torch.Tensor) – Second quasi-complex tensor of shape (2, N).

Returns:

Product as [real, imag] of shape (2, N).

Return type:

torch.Tensor

Submodules