X

Search Results

Searching....

10.2 Wave Function Analysis

10.2.13 Earth Mover’s Distance Analysis

(July 4, 2026)

The Earth Mover’s Distance (EMD) provides a physically intuitive metric for comparing two charge distributions by quantifying the minimum transport cost required to transform one distribution into the other. 1432 Wang Z., Liang J., Head-Gordon M.
J. Chem. Theory Comput.
(2023), 19, pp. 7704.
Link
In the context of excited-state analysis, EMD offers a real-space measure of charge rearrangement and therefore complements more traditional descriptors of charge transfer and density redistribution. The exact evaluation of EMD requires solution of an optimal transport problem, which can become computationally expensive for large grids. To make this analysis practical for routine applications, Q-Chem provides an entropically regularized formulation based on the Sinkhorn–Knopp algorithm, together with a reduced-grid representation of the charge distribution, in order to obtain an efficient approximation to the exact EMD while retaining its essential physical interpretation.

10.2.13.1 Theory

Let 𝐫 and 𝐜 denote two discrete nonnegative distributions defined on a real-space grid, with equal total weight. In the EMD framework, these are interpreted as the source and target distributions, respectively. For a distance matrix 𝐌, whose elements Mij represent the distance between grid points i and j, the Earth Mover’s Distance is defined as

d𝐌(𝐫,𝐜)=min𝐏U(𝐫,𝐜)𝐏,𝐌=min𝐏U(𝐫,𝐜)ijPijMij, (10.37)

where 𝐏 is the transport plan and

U(𝐫,𝐜)={𝐏+d×d|𝐏𝟏=𝐫,𝐏T𝟏=𝐜}. (10.38)

The admissible transport plans are therefore constrained to reproduce the prescribed source and target marginals. In other words, each row sum of 𝐏 must equal the source distribution, and each column sum must equal the target distribution.

In the present application, the source and target distributions are constructed from the positive and negative parts of the real-space density difference associated with an excitation. Let

Δρ(𝐫)=ρES(𝐫)-ρGS(𝐫), (10.39)

where ρGS(𝐫) and ρES(𝐫) are the ground-state and excited-state densities, respectively. The positive and negative components of the density difference define the two charge distributions to be compared,

ρ+(𝐫)=max(Δρ(𝐫),0),ρ-(𝐫)=max(-Δρ(𝐫),0). (10.40)

After discretization on a grid with points {𝐫i} and quadrature weights {wi}, the effective charge associated with each grid point is

qi=wiρ(𝐫i), (10.41)

and the two nonnegative discrete distributions entering the EMD problem are obtained from the positive and negative components of the density difference. The total transferred charge is then

qCT=iqi+=jqj-, (10.42)

and the corresponding transport cost,

μEMD=min𝐏U(𝐫,𝐜)ijPijMij, (10.43)

has units of charge times distance. A corresponding length-like quantity may be defined as

dEMD=μEMDqCT. (10.44)

The exact EMD may be obtained by solving this constrained optimization problem using a transportation simplex algorithm. While this approach yields the exact optimal transport cost, its computational cost grows rapidly with grid size and can become prohibitive for large systems or dense real-space grids.

10.2.13.2 Grid Selection for Efficient EMD Calculations

A direct EMD calculation on the full quadrature grid used in a DFT or TDDFT calculation is generally impractical because the number of grid points may be very large. Since the optimal transport problem scales unfavorably with the size of the discrete distributions, the present implementation employs a reduced grid for the EMD evaluation.

In this procedure, the electronic density is first evaluated on the underlying quadrature grid used in the electronic-structure calculation. A smaller atom-centered grid is then introduced for the EMD analysis. Each grid point from the original quadrature grid is assigned to a point on the smaller EMD grid according to spatial proximity, and the effective charges from the original grid are accumulated onto the selected EMD grid. In this way, the fine-grid density is projected onto a smaller discrete representation that preserves the overall distribution while substantially reducing the number of points entering the transport problem.

Let {𝐫kbig,wkbig,ρkbig} denote the grid points, weights, and densities on the original quadrature grid, and let {𝐫ismall} denote the reduced grid used for the EMD evaluation. The effective charge assigned to point i on the reduced grid is constructed by accumulating the charges from all original grid points associated with that reduced point,

qismall=kΩiwkbigρkbig, (10.45)

where Ωi denotes the set of original grid points assigned to reduced grid point i. The resulting reduced-grid charges are then used to define the source and target distributions entering the EMD calculation.

This reduced-grid procedure greatly lowers the cost of both exact and regularized EMD calculations while retaining a physically meaningful representation of the density difference. The reduced grid is chosen from standard atom-centered quadrature grids in Q-Chem. The quality of the EMD result therefore depends on the quality of the reduced-grid representation of the density difference, and convergence with respect to the EMD grid should be checked whenever high quantitative accuracy is required.

10.2.13.3 Entropically Regularized Optimal Transport

To further reduce the cost of the EMD evaluation, one may replace the exact optimal transport problem by an entropically regularized one,

𝐏λ=argmin𝐏U(𝐫,𝐜)[𝐏,𝐌-1λh(𝐏)], (10.46)

where h(𝐏) is the entropy of the transport plan and λ is the regularization parameter. The corresponding regularized transport cost is

d𝐌λ(𝐫,𝐜)=𝐏λ,𝐌. (10.47)

The entropy term favors smoother transport plans and removes the need to solve the original linear programming problem directly. The parameter λ controls the balance between smoothness and fidelity to the exact EMD. Larger values of λ reduce the influence of the entropy term and drive the solution closer to the exact EMD, whereas smaller values of λ produce a smoother transport plan and generally improve numerical stability.

The regularized problem admits a factorized form for the optimal transport plan,

𝐏λ=diag(𝐮)𝐊diag(𝐯), (10.48)

where

Kij=e-λMij. (10.49)

The vectors 𝐮 and 𝐯 are positive scaling factors chosen such that the transport plan satisfies the marginal constraints,

𝐏λ𝟏=𝐫,(𝐏λ)T𝟏=𝐜. (10.50)

Substituting the factorized form into these constraints yields the coupled fixed-point equations

ui=ri(𝐊𝐯)i,vj=cj(𝐊T𝐮)j. (10.51)

These equations form the basis of the Sinkhorn–Knopp algorithm, which alternates updates of 𝐮 and 𝐯 until the marginal constraints are satisfied to within a specified threshold.

The computational steps of the method are therefore as follows. First, the density difference is evaluated on the underlying quadrature grid. Second, the associated charges are projected onto a smaller EMD grid. Third, the distance matrix 𝐌 is constructed on that reduced grid, and the kernel matrix 𝐊 is formed according to Eq. (10.49). Finally, the Sinkhorn iterations are performed to obtain the regularized transport plan and the corresponding transport cost. The dominant cost of the regularized method is associated with repeated matrix-vector products involving 𝐊 and 𝐊T, which is substantially less expensive than solving the exact transportation simplex problem for large grids.

In practice, the principal numerical parameter is the regularization strength λ. This parameter must be chosen large enough that the regularized transport cost remains close to the exact EMD, but not so large that the kernel matrix becomes severely ill-conditioned. If λMij is too large, the exponential kernel may underflow, leading to unstable scaling vectors and poor convergence behavior. The present implementation therefore exposes user-adjustable regularization and convergence parameters, where The user-specified regularization parameter is scaled by the maximum element of the distance matrix. In other words, the effective regularization strength used in the calculation is λeff=λinMijmax, where Mijmax=maxijMij. In general, increasing λeff improves agreement with the exact EMD, whereas decreasing λeff improves numerical stability and convergence behavior.

In summary, this feature evaluates the Earth Mover’s Distance between two discrete charge distributions on a real-space grid either using exact transport algorithm or using an entropically regularized optimal transport formulation solved by the Sinkhorn–Knopp algorithm, with a reduced atom-centered grid for the EMD calculation rather than the full quadrature grid employed in the underlying electronic-structure calculation. The quality of the result therefore depends both on the EMD grid and on the regularization parameters. The principal user-controlled options are the activation of EMD analysis itself EMD_ANALYSIS, the grid used for constructing the reduced real-space charge distributions EMD_FIT_GRID, the use of the Sinkhorn solver SINKHORN, the regularization strength for Sinkhorn solver SINKHORN_REG, the convergence threshold for Sinkhorn solver SINKHORN_THRESHOLD, and the maximum cycles MAX_SINKHORN_CYCLES. Larger regularization parameters generally improve agreement with the exact EMD but may lead to numerical instability if the kernel matrix becomes too sharply peaked. Smaller regularization parameters improve numerical robustness, but introduce a larger approximation error relative to the exact EMD.

EMD_ANALYSIS

EMD_ANALYSIS
       Controls whether Earth Mover’s Distance (EMD) analysis is performed.
TYPE:
       LOGICAL
DEFAULT:
       FALSE
OPTIONS:
       FALSE Do not perform EMD analysis. TRUE Perform EMD analysis.
RECOMMENDATION:
       This keyword activates the evaluation of the Earth Mover’s Distance between the positive and negative parts of the real-space density difference. The corresponding charge distributions are constructed on the grid specified by EMD_FIT_GRID.

EMD_FIT_GRID

EMD_FIT_GRID
       Specifies the atom-centered grid used to construct the reduced real-space charge distributions for Earth Mover’s Distance (EMD) analysis.
TYPE:
       INTEGER
DEFAULT:
       0
OPTIONS:
       N Grid specification N is in the same format as XC_GRID.
RECOMMENDATION:
       This keyword defines the grid used for the reduced-grid representation of the density difference entering the EMD calculation. The input format is the same as for XC_GRID, but it should be equal or smaller than XC_GRID. A recommended choice is 19000026, and for larger molecules an even smaller grid may be used with only a small loss of accuracy. A denser grid generally improves the quality of the EMD result, but also increases the computational cost of the transport problem.

SINKHORN

SINKHORN
       Controls whether the entropically regularized Sinkhorn–Knopp algorithm is used for the EMD calculation.
TYPE:
       LOGICAL
DEFAULT:
       FALSE
OPTIONS:
       FALSE Use the exact transportation simplex algorithm. TRUE Use the entropically regularized Sinkhorn–Knopp algorithm.
RECOMMENDATION:
       The Sinkhorn–Knopp algorithm provides an efficient approximation to the exact Earth Mover’s Distance and is generally preferable for large grids. The corresponding regularization strength is controlled by SINKHORN_REG.

MAX_SINKHORN_CYCLES

MAX_SINKHORN_CYCLES
       Controls the maximum number of Sinkhorn–Knopp iterations used in the EMD calculation.
TYPE:
       INTEGER
DEFAULT:
       50
OPTIONS:
       N Perform at most N Sinkhorn iterations.
RECOMMENDATION:
       Increase this value if the Sinkhorn iterations do not converge within the default number of cycles. This keyword is only relevant when SINKHORN is set to 1.

SINKHORN_THRESHOLD

SINKHORN_THRESHOLD
       Controls the convergence threshold for the Sinkhorn–Knopp iterations.
TYPE:
       INTEGER
DEFAULT:
       3
OPTIONS:
       N Converge the Sinkhorn iterations to a threshold of 10-N.
RECOMMENDATION:
       Smaller values of N correspond to a looser convergence criterion, while larger values correspond to tighter convergence. This keyword is only relevant when SINKHORN is set to 1.

SINKHORN_REG

SINKHORN_REG
       Controls the regularization strength used in the entropically regularized Sinkhorn EMD calculation.
TYPE:
       INTEGER
DEFAULT:
       100
OPTIONS:
       N Use a regularization parameter of N for the Sinkhorn kernel.
RECOMMENDATION:
       This keyword controls the strength of the entropic regularization in the Sinkhorn formulation of the EMD problem. Larger values generally yield results closer to the exact EMD, but may also lead to numerical instability or slower convergence. Smaller values are more numerically robust, but increase the deviation from the exact optimal transport solution. In the present implementation, the user-specified regularization parameter is internally scaled by the maximum element of the distance matrix before the Sinkhorn kernel is constructed. This keyword is only relevant when SINKHORN is set to 1.

Example 10.10  Basic TDDFT calculation with PBE functional for water molecule with EMD analysis for the first three excited singlet and triplet states with the accurate transportation simplex method algorithm.

$molecule
0 1
O   0.000000   0.000000   0.000000
H   0.758602   0.000000   0.504284
H  -0.758602   0.000000   0.504284
$end

$rem
METHOD PBE
BASIS aug-cc-pVDZ
CIS_N_ROOTS 3
CIS_SINGLETS TRUE
CIS_TRIPLETS TRUE
STATE_ANALYSIS TRUE
XC_GRID 50000194
EMD_ANALYSIS TRUE
EMD_FIT_GRID 19000026
SINKHORN FALSE
SCF_CONVERGENCE 8
THRESH 13
N_FROZEN_CORE 0
$end

Example 10.11  Basic TDDFT calculation with PBE functional for water molecule with EMD analysis for the first three excited singlet and triplet states with the approximate Sinkhorn–Knopp algorithm.

$molecule
0 1
O   0.000000   0.000000   0.000000
H   0.758602   0.000000   0.504284
H  -0.758602   0.000000   0.504284
$end

$rem
METHOD PBE
BASIS aug-cc-pVDZ
CIS_N_ROOTS 3
CIS_SINGLETS TRUE
CIS_TRIPLETS TRUE
STATE_ANALYSIS TRUE
XC_GRID 50000194
EMD_ANALYSIS TRUE
EMD_FIT_GRID 19000026
SINKHORN TRUE
SINKHORN_THRESHOLD 3
MAX_SINKHORN_CYCLES 30
SINKHORN_REG 200
SCF_CONVERGENCE 8
THRESH 13
N_FROZEN_CORE 0
$end