Physics Tools

Clebsch-Gordan Coefficients

class hamgnn.physics.Clebsch_Gordan_coefficients.ClebschGordanCoefficients(max_l=8)[source]

Bases: Module

A PyTorch module for pre-computing and storing Clebsch-Gordan coefficients, which can then be accessed during the forward pass.

forward(l1, l2, l3)[source]

Retrieve the pre-computed Clebsch-Gordan coefficient for the given angular momenta.

Parameters:
  • l1 – First angular momentum value.

  • l2 – Second angular momentum value.

  • l3 – Third angular momentum value.

Returns:

The Clebsch-Gordan coefficient tensor.

K-Points

class hamgnn.physics.kpoints.kpoints_generator(dim_k=3, lat=None, per=None)[source]

Bases: object

Used to generate K point path

k_path(kpts, nk, report=False)[source]

Interpolates a path in reciprocal space between specified k-points. In 2D or 3D the k-path can consist of several straight segments connecting high-symmetry points (“nodes”), and the results can be used to plot the bands along this path.

The interpolated path that is returned contains as equidistant k-points as possible.

Parameters:
  • kpts

    Array of k-vectors in reciprocal space between which interpolated path should be constructed. These k-vectors must be given in reduced coordinates. As a special case, in 1D k-space kpts may be a string:

    • ”full” – Implies [ 0.0, 0.5, 1.0] (full BZ)

    • ”fullc” – Implies [-0.5, 0.0, 0.5] (full BZ, centered)

    • ”half” – Implies [ 0.0, 0.5] (half BZ)

  • nk – Total number of k-points to be used in making the plot.

  • report – Optional parameter specifying whether printout is desired (default is True).

Returns:

  • k_vec – Array of (nearly) equidistant interpolated k-points. The distance between the points is calculated in the Cartesian frame, however coordinates themselves are given in dimensionless reduced coordinates! This is done so that this array can be directly passed to function pythtb.tb_model.solve_all().

  • k_dist – Array giving accumulated k-distance to each k-point in the path. Unlike array k_vec this one has dimensions! (Units are defined here so that for an one-dimensional crystal with lattice constant equal to for example 10 the length of the Brillouin zone would equal 1/10=0.1. In other words factors of \(2\pi\) are absorbed into k.) This array can be used to plot path in the k-space so that the distances between the k-points in the plot are exact.

  • k_node – Array giving accumulated k-distance to each node on the path in Cartesian coordinates. This array is typically used to plot nodes (typically special points) on the path in k-space.

Example usage:

# Construct a path connecting four nodal points in k-space
# Path will contain 401 k-points, roughly equally spaced
path = [[0.0, 0.0], [0.0, 0.5], [0.5, 0.5], [0.0, 0.0]]
(k_vec,k_dist,k_node) = my_model.k_path(path,401)
# solve for eigenvalues on that path
evals = tb.solve_all(k_vec)
# then use evals, k_dist, and k_node to plot bandstructure
# (see examples)
hamgnn.physics.kpoints.compute_reciprocal_lattice_vectors(lattice_vectors)[source]

Calculates the reciprocal lattice vectors for a given set of lattice vectors using PyTorch.

Parameters: lattice_vectors (torch.Tensor): A 2D tensor containing three lattice vectors

as rows.

Returns: torch.Tensor: A 2D tensor containing the reciprocal lattice vectors as rows.

hamgnn.physics.kpoints.generate_kpoint_grid(lattice_vectors, kpoint_density=0.04)[source]

Generate a k-point grid with density proportional to reciprocal lattice vectors.

Parameters: lattice_vectors (torch.Tensor): A 2D tensor with shape (3,3) containing lattice vectors as rows kpoint_density (float): Target k-point density in Å^-1 (typical values: 0.03-0.05)

Returns: torch.Tensor: A 1D tensor containing the number of k-points along each reciprocal lattice vector

Matrix Operations

class hamgnn.physics.matrix_operations.HamLayer(irreps_in, feature_irreps_hidden, irreps_out, nonlinearity_type='gate', resnet=True)[source]

Bases: Module

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class hamgnn.physics.matrix_operations.TensorExpansion(ham_type, nao_max)[source]

Bases: Module

forward(x)[source]

Forward pass to compute the expanded tensor.

Parameters:

x (torch.Tensor) – Input tensor of shape (*, row.dim, col.dim).

Returns:

Expanded tensor.

Return type:

torch.Tensor

class hamgnn.physics.matrix_operations.OverlapExpand(ham_type, nao_max)[source]

Bases: Module

forward(data)[source]

Forward pass to expand overlap data.

Parameters:

data – Object containing ‘Son’ and ‘Soff’ tensors to be expanded.

Returns:

Updated data object with expanded ‘Son’ and ‘Soff’.

class hamgnn.physics.matrix_operations.TensorMerge(irrep_in, irrep_out_1, irrep_out_2, internal_weights=False)[source]

Bases: Module

forward(x_in)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

get_expansion_path(irrep_in, irrep_out_1, irrep_out_2)[source]
property device