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:
- 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:
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]])