Kvectors

torchpme.lib.get_ns_mesh(cell: Tensor, mesh_spacing: float)[source]

Computes the mesh size given a target mesh spacing and cell getting the closest powers of 2 to help with FFT.

Parameters:
  • cell (Tensor) – torch.tensor of shape (3, 3), where cell[i] is the i-th basis vector of the unit cell

  • mesh_spacing (float) – float

  • differentiable – boll

Returns:

torch.tensor of length 3 containing the mesh size

torchpme.lib.generate_kvectors_for_mesh(cell: Tensor, ns: Tensor) Tensor[source]

Compute all reciprocal space vectors for Fourier space sums.

This variant is used in combination with mesh based calculators using the fast fourier transform (FFT) algorithm.

Parameters:
  • cell (Tensor) – torch.tensor of shape (3, 3), where cell[i] is the i-th basis vector of the unit cell

  • ns (Tensor) – torch.tensor of shape (3,) and dtype int ns = [nx, ny, nz] contains the number of mesh points in the x-, y- and z-direction, respectively. For faster performance during the Fast Fourier Transform (FFT) it is recommended to use values of nx, ny and nz that are powers of 2.

Returns:

torch.tensor of shape (nx, ny, nz, 3) containing all reciprocal space vectors that will be used in the (FFT-based) mesh calculators. Note that k_vectors[0,0,0] = [0,0,0] always is the zero vector.

Return type:

Tensor

See also

generate_kvectors_for_ewald() for a function to be used for Ewald calculators.

torchpme.lib.generate_kvectors_for_ewald(cell: Tensor, ns: Tensor) Tensor[source]

Compute all reciprocal space vectors for Fourier space sums.

This variant is used with the Ewald calculator, in which the sum over the reciprocal space vectors is performed explicitly rather than using the fast Fourier transform (FFT) algorithm.

The main difference with generate_kvectors_for_mesh() is the shape of the output tensor (see documentation on return) and the fact that the full set of reciprocal space vectors is returned, rather than the FFT-optimized set that roughly contains only half of the vectors.

Parameters:
  • cell (Tensor) – torch.tensor of shape (3, 3), where cell[i] is the i-th basis vector of the unit cell

  • ns (Tensor) – torch.tensor of shape (3,) and dtype int ns = [nx, ny, nz] contains the number of mesh points in the x-, y- and z-direction, respectively.

Returns:

torch.tensor of shape (n, 3) containing all reciprocal space vectors that will be used in the Ewald calculator. Note that k_vectors[0] = [0,0,0] always is the zero vector.

Return type:

Tensor

See also

generate_kvectors_for_mesh() for a function to be used with mesh based calculators like PME.

Examples using Kvectors