pymatgen.optimization package — pymatgen 2025.1.24 documentation

# pymatgen.optimization package

Optimization utilities.

## Submodules

## pymatgen.optimization.linear_assignment module

This module contains the LAPJV algorithm to solve the Linear Assignment Problem.

class LinearAssignment(costs: np.ndarray, epsilon: float = 1e-13)

  Bases: `object`

  This class finds the solution to the Linear Assignment Problem. It finds a minimum cost matching between two sets, given a cost matrix.

  This class is an implementation of the LAPJV algorithm described in: R. Jonker, A. Volgenant. A Shortest Augmenting Path Algorithm for Dense and Sparse Linear Assignment Problems. Computing 38, 325-340 (1987)

  Parameters:

    - costs – The cost matrix of the problem. cost[i,j] should be the cost of matching x[i] to y[j]. The cost matrix may be rectangular

    - epsilon – Tolerance for determining if solution vector is < 0

  min_cost

    The minimum cost of the matching.

  solution

    The matching of the rows to columns. i.e solution = [1, 2, 0] would match row 0 to column 1, row 1 to column 2 and row 2 to column 0. Total cost would be c[0, 1] + c[1, 2] + c[2, 0].

## pymatgen.optimization.neighbors module

find_points_in_spheres(all_coords, center_coords, r, pbc, lattice, tol=1e-08, min_r=1.0)

  For each point in center_coords, get all the neighboring points in all_coords that are within the cutoff radius r. All the coordinates should be Cartesian.

  Parameters:

    - all_coords – (np.ndarray[double, dim=2]) all available points. When periodic boundary is considered, this is all the points in the lattice.

    - center_coords – (np.ndarray[double, dim=2]) all centering points

    - r – (float) cutoff radius

    - pbc – (np.ndarray[np.int64_t, dim=1]) whether to set periodic boundaries

    - lattice – (np.ndarray[double, dim=2]) 3x3 lattice matrix

    - tol – (float) numerical tolerance

    - min_r – (float) minimal cutoff to calculate the neighbor list directly. If the cutoff is less than this value, the algorithm will calculate neighbor list using min_r as cutoff and discard those that have larger distances.

  Returns:

    Indexes of center_coords. index2 (n, ): Indexes of all_coords that form the neighbor pair. offset_vectors (n, 3): The periodic image offsets for all_coords. distances (n, ).

  Return type:

    index1 (n, )