torchref.base.coordinates.transforms_torch module

PyTorch implementations of coordinate transformation functions.

These functions are GPU-accelerated and support automatic differentiation for use in optimization and refinement.

torchref.base.coordinates.transforms_torch.cartesian_to_fractional_torch(xyz, cell, B_inv=None)[source]

Convert Cartesian coordinates to fractional coordinates.

Parameters:
  • xyz (torch.Tensor) – Cartesian coordinates of shape (N, 3).

  • cell (array-like) – Unit cell parameters [a, b, c, alpha, beta, gamma].

  • B_inv (torch.Tensor, optional) – Inverse fractionalization matrix. If None, it will be calculated from cell.

Returns:

Fractional coordinates of shape (N, 3).

Return type:

torch.Tensor

torchref.base.coordinates.transforms_torch.fractional_to_cartesian_torch(xyz_fractional, cell, B=None)[source]

Convert fractional coordinates to Cartesian coordinates.

Parameters:
  • xyz_fractional (torch.Tensor) – Fractional coordinates of shape (N, 3).

  • cell (array-like) – Unit cell parameters [a, b, c, alpha, beta, gamma].

  • B (torch.Tensor, optional) – Fractionalization matrix. If None, it will be calculated from cell.

Returns:

Cartesian coordinates of shape (N, 3).

Return type:

torch.Tensor

torchref.base.coordinates.transforms_torch.get_fractional_matrix(cell)[source]

Calculate the fractional-to-Cartesian transformation matrix.

Constructs the matrix B that transforms fractional coordinates to Cartesian coordinates based on the unit cell parameters.

Parameters:

cell (torch.Tensor) – Unit cell parameters [a, b, c, alpha, beta, gamma] where lengths are in Angstroms and angles are in degrees.

Returns:

3x3 transformation matrix B such that cart = frac @ B.T.

Return type:

torch.Tensor

torchref.base.coordinates.transforms_torch.get_inv_fractional_matrix_torch(cell)[source]

Calculate the Cartesian-to-fractional transformation matrix (PyTorch version).

Computes the inverse of the fractional matrix for converting Cartesian coordinates to fractional coordinates.

Parameters:

cell (torch.Tensor) – Unit cell parameters [a, b, c, alpha, beta, gamma] where lengths are in Angstroms and angles are in degrees.

Returns:

3x3 inverse transformation matrix B_inv such that frac = cart @ B_inv.T.

Return type:

torch.Tensor