Repository navigation
Description
Description
In grid.coulomb.coulomb_gaussian_p, the analytical formula used to evaluate the electrostatic Coulomb potential of a coulomb_gaussian_p violates Poisson's equation:
The current implementation overestimates the potential near the origin, leading to a +150% error at the nucleus (coulomb_gaussian_p or coulomb_potential.
Mathematical Derivation & Proof of the Flaw
A normalized
For any spherically symmetric charge density
Evaluating each integral for
1. First Integral (Interior charge contribution):
Integrating by parts:
Multiplying through by
2. Second Integral (Exterior shell contribution):
Integrating by parts:
Multiplying through by
3. Summing Both Integrals:
Notice that the
And the
Therefore, the exact Coulomb potential is:
Where the Existing Code Differs
In src/grid/coulomb.py (lines 110-111 & 147-150):
# CURRENT IMPLEMENTATION (INCORRECT):
term2 = (4.0 / 3.0) * (sqrt_alpha / np.sqrt(np.pi)) * np.exp(-alpha * r**2)
out = term1 + term2
out[r < _R_ZERO_THRESHOLD] = (10.0 / 3.0) * (sqrt_alpha / np.sqrt(np.pi))The code omitted the
-
Wrong sign and magnitude for the Gaussian tail:
$+\frac{4}{3}$ instead of$-\frac{2}{3}$ . -
Severe discrepancy at the nucleus (
$r \to 0$ ):- Correct limit:
$\lim_{r\to 0} V_{\text{exact}}(r) = 2\sqrt{\frac{\alpha}{\pi}} - \frac{2}{3}\sqrt{\frac{\alpha}{\pi}} = \mathbf{\frac{4}{3}\sqrt{\frac{\alpha}{\pi}}}$ . - Current code:
$\lim_{r\to 0} V_{\text{code}}(r) = 2\sqrt{\frac{\alpha}{\pi}} + \frac{4}{3}\sqrt{\frac{\alpha}{\pi}} = \mathbf{\frac{10}{3}\sqrt{\frac{\alpha}{\pi}}}$ . - Relative error at the nucleus:
$\frac{10/3 - 4/3}{4/3} = \mathbf{+150%}$ .
- Correct limit:
-
Unnormalized case:
- Formula in docstring and code:
$\frac{3\pi^{3/2}}{2\alpha^{5/2}} \frac{\mathrm{erf}(\sqrt{\alpha}r)}{r} + \frac{2\pi}{\alpha^2} e^{-\alpha r^2}$ . - Correct physical formula:
$\frac{3\pi^{3/2}}{2\alpha^{5/2}} \frac{\mathrm{erf}(\sqrt{\alpha}r)}{r} - \frac{\pi}{\alpha^2} e^{-\alpha r^2}$ . - Correct
$r\to 0$ limit:$\frac{2\pi}{\alpha^2}$ (current code erroneously returned$\frac{5\pi}{\alpha^2}$ ).
- Formula in docstring and code:
Graphical Proof & Poisson Equation Verification
As demonstrated in the comparison plot above:
-
Left Panel: The current potential deviates significantly from the exact solution, with a large artificial spike at
$r=0$ . -
Center Panel: Discrepancy peaks directly at the nucleus with
$\Delta V(0) = 2 \sqrt{\frac{\alpha}{\pi}}$ Hartree. -
Right Panel: Evaluating the spherical Laplacian
$\nabla^2 V = \frac{d^2 V}{dr^2} + \frac{2}{r} \frac{dV}{dr}$ reveals that:-
$V_{\text{exact}}$ matches the target$-4\pi \rho(r)$ with numerical precision. -
$V_{\text{current}}$ violently violates Poisson's equation ($\max |\nabla^2 V - (-4\pi\rho)| \approx 18.9$ for$\alpha=2.0$ ).
-
Reproduction Script
import numpy as np
from scipy.special import erf
from grid.coulomb import coulomb_gaussian_p
alpha = 2.0
r = np.linspace(0.01, 3.0, 1000)
dr = r[1] - r[0]
# Density
rho = (2.0 / 3.0) * (alpha**2.5 / np.pi**1.5) * (r**2) * np.exp(-alpha * r**2)
target_laplacian = -4.0 * np.pi * rho
# Potential from grid.coulomb
v = coulomb_gaussian_p(r, alpha, normalized=True)
# Numerical Laplacian d2V/dr2 + (2/r)*dV/dr
dv_dr = np.gradient(v, dr)
d2v_dr2 = np.gradient(dv_dr, dr)
lap_computed = d2v_dr2 + (2.0 / r) * dv_dr
# Check error against Poisson equation
residual = np.max(np.abs(lap_computed[10:-10] - target_laplacian[10:-10]))
print("Max residual against -4*pi*rho:", residual)
# Output: 18.91989... (Violates Poisson's equation!)Solution
- In
coulomb_gaussian_p:- Change
term2 = -(2.0 / 3.0) * (sqrt_alpha / np.sqrt(np.pi)) * np.exp(-alpha * r**2). - Update
$r \to 0$ limit to(4.0 / 3.0) * (sqrt_alpha / np.sqrt(np.pi)).
- Change
- Update docstrings in
coulomb.pyfor both normalized and unnormalized definitions. - Update unit tests in
tests/test_coulomb.pywith the correct reference values and add an explicit test asserting$\nabla^2 V = -4\pi \rho$ .

Activity
PaulWAyers commentedon Oct 22, 2026
If you don't get the PR approved in the next week, ping on the issue and I'll get it done myself.
Ao-chuba commentedon Oct 22, 2026
@PaulWAyers since i dont have the access to approve.(only read) so either marco or you (or any one with the access) will have to approve. from my side i have approved and given my feedback in the PR discussion
PaulWAyers commentedon Oct 22, 2026
Thanks @Ao-chuba . I have upgraded your status on this repository, too.
alok-108 commentedon Oct 22, 2026
Thanks both. #343 is approved now, so it just needs a merge. Happy to rebase if needed.
Merge pull request #343 from alok-108/fix-342-coulomb-gaussian-p