Repository navigation
fix: correct analytical Coulomb potential for p-type Gaussians (#342) - #343
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The corrected formulas are mathematically consistent and adequately covered by focused regression tests.
0 open findings
What changed in this PR
Corrects the analytical Coulomb potential for p-type Gaussian charge densities to satisfy Poisson’s equation.
Changes:
- Fixes normalized and unnormalized potential formulas and nuclear limits.
- Updates mathematical documentation.
- Adds direct, multi-center, and Poisson-equation tests.
| File | Description |
|---|---|
src/grid/coulomb.py |
Corrects the p-type Gaussian potential formula and limit. |
src/grid/tests/test_coulomb.py |
Updates expectations and adds regression coverage. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Ao-chuba
left a comment
There was a problem hiding this comment.
As per my understandings the fix (docstring, test ) and all updated mathematical values are correct and good to go.
One minor observation on test_coulomb_potential_with_p_gaussians, the expected value is built by calling coulomb_gaussian_s and coulomb_gaussian_p directly, which are the same functions coulomb_potential calls internally so the test cannot catch bugs internal to those functions themselves (though it does still test the aggregation/argument passing logic correctly). Consider using strict=True in the zip calls as well. but yes, these are optional changes.
What do you think, @marco-2023?
|
Thanks @PaulWAyers for merging, and @Ao-chuba for the review. |
|
Always good to add more tests. |
Description
Fixes #342.
This PR corrects a fundamental mathematical flaw in$p$ -type radial Gaussian charge densities violated Poisson's equation $\nabla^2 V(\mathbf{r}) = -4\pi \rho(\mathbf{r})$ .
grid.coulomb.coulomb_gaussian_pwhere the analytical electrostatic potential returned forRoot Cause & Mathematical Correction
For a normalized$p$ -type radial Gaussian charge density:
The exact solution to Poisson's equation with$V(\infty) = 0$ is obtained by radial integration of Gauss's law:
Evaluating the integrals:
Summing both integrals cancels the$r^2 e^{-\alpha r^2}$ terms identically and leaves:
The previous implementation in$-2\sqrt{\alpha/\pi} e^{-\alpha r^2}$ term from the interior integral, leaving an erroneous $+ \frac{4}{3} \sqrt{\frac{\alpha}{\pi}} e^{-\alpha r^2}$ . This caused:
coulomb_gaussian_phad omitted theGraphical Proof & Poisson Equation Verification
Commit Structure (5 Atomic Commits)
This PR is organized into 5 logical commits:
fix(coulomb): correct p-type Gaussian potential formula and nuclear limitterm2sign and magnitude todocs(coulomb): update p-type Gaussian Coulomb potential docstringstest(coulomb): update unit tests for corrected p-type Gaussian potentialtest_coulomb_gaussian_p()test expectations for both normalized and unnormalized cases.test(coulomb): add Poisson equation numerical validation for p-type Gaussianstest_coulomb_gaussian_p_poisson_equation()testingtest(coulomb): add multi-center p-type Gaussian tests in coulomb_potentialtest_coulomb_potential_with_p_gaussians()testing combined multi-centerVerification
All 11 tests in
tests/test_coulomb.pyand the complete test suite pass. Ruff formatting and linting pass without errors.