get_fractional_coordinates

torch_sim.transforms.get_fractional_coordinates(positions, cell)[source]

Convert Cartesian coordinates to fractional coordinates.

This function transforms atomic positions from Cartesian coordinates to fractional coordinates using the provided unit cell matrix. The fractional coordinates represent the position of each atom relative to the unit cell vectors.

Parameters:
  • positions (Tensor) – Atomic positions in Cartesian coordinates. Shape: […, 3] where … represents optional batch dimensions.

  • cell (Tensor) – Unit cell matrix with lattice vectors as rows. Shape: […, 3, 3] where … matches positions’ batch dimensions.

Returns:

Atomic positions in fractional coordinates with same shape as input

positions. Each component will be in range [0,1) for positions inside the cell.

Return type:

Tensor

Example

>>> pos = torch.tensor([[1.0, 1.0, 1.0], [2.0, 0.0, 0.0]])
>>> cell = torch.tensor([[4.0, 0.0, 0.0], [0.0, 4.0, 0.0], [0.0, 0.0, 4.0]])
>>> frac = get_fractional_coordinates(pos, cell)
>>> print(frac)
tensor([[0.25, 0.25, 0.25],
        [0.50, 0.00, 0.00]])