torchref.base.coordinates.transforms_numpy module

NumPy implementations of coordinate transformation functions.

These functions provide CPU-based coordinate transformations for use when GPU acceleration is not needed or available.

torchref.base.coordinates.transforms_numpy.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 (numpy.ndarray or list) – 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:

numpy.ndarray

torchref.base.coordinates.transforms_numpy.get_inv_fractional_matrix(cell)[source]

Calculate the Cartesian-to-fractional transformation matrix.

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

Parameters:

cell (numpy.ndarray or list) – 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:

numpy.ndarray

torchref.base.coordinates.transforms_numpy.cartesian_to_fractional(xyz, cell)[source]

Convert Cartesian coordinates to fractional coordinates.

Parameters:
  • xyz (numpy.ndarray) – Cartesian coordinates with shape (N, 3).

  • cell (numpy.ndarray or list) – Unit cell parameters [a, b, c, alpha, beta, gamma] where lengths are in Angstroms and angles are in degrees.

Returns:

Fractional coordinates with shape (N, 3).

Return type:

numpy.ndarray

torchref.base.coordinates.transforms_numpy.fractional_to_cartesian(xyz_fractional, cell)[source]

Convert fractional coordinates to Cartesian coordinates.

Parameters:
  • xyz_fractional (numpy.ndarray) – Fractional coordinates with shape (N, 3).

  • cell (numpy.ndarray or list) – Unit cell parameters [a, b, c, alpha, beta, gamma] where lengths are in Angstroms and angles are in degrees.

Returns:

Cartesian coordinates with shape (N, 3).

Return type:

numpy.ndarray

torchref.base.coordinates.transforms_numpy.convert_coords_to_fractional(df, cell)[source]

Convert coordinates from a DataFrame to fractional coordinates.

Extracts x, y, z columns from a DataFrame and converts them from Cartesian to fractional coordinates.

Parameters:
  • df (pandas.DataFrame) – DataFrame containing ‘x’, ‘y’, ‘z’ columns with Cartesian coordinates.

  • cell (numpy.ndarray or list) – Unit cell parameters [a, b, c, alpha, beta, gamma] where lengths are in Angstroms and angles are in degrees.

Returns:

Fractional coordinates with shape (N, 3).

Return type:

numpy.ndarray