Skip to content

[PR-5] feat: integrate OS+HGP algorithm into electron_repulsion module#239

Draft
San1357 wants to merge 10 commits intotheochem:masterfrom
San1357:feat/electron-repulsion-improved
Draft

[PR-5] feat: integrate OS+HGP algorithm into electron_repulsion module#239
San1357 wants to merge 10 commits intotheochem:masterfrom
San1357:feat/electron-repulsion-improved

Conversation

@San1357
Copy link

@San1357 San1357 commented Mar 6, 2026

Summary

What Changed

File Lines What
gbasis/integrals/_two_elec_int_improved.py +732 Core OS+HGP pipeline: Boys → VRR → ETR → Contract → HRR, with _optimized_contraction, _get_factorial2_norm, and compute_two_electron_integrals_os_hgp
gbasis/integrals/electron_repulsion.py +248 Added ElectronRepulsionIntegralImproved class and electron_repulsion_integral_improved() public API integrating the pipeline into gbasis framework
tests/test_electron_repulsion.py +574 17 integration tests: matches old implementation, Horton reference values, symmetry checks, bra-ket reordering
tests/test_two_elec_int_improved.py +699 Unit tests for all pipeline stages: Boys, VRR, ETR, HRR, contraction, norm, and reordering

Mathematical Reference

The two-electron repulsion integral:

$$(\mu\nu|\lambda\sigma) = \int\int \phi_\mu(\mathbf{r}_1)\phi_\nu(\mathbf{r}_1) \frac{1}{r_{12}} \phi_\lambda(\mathbf{r}_2)\phi_\sigma(\mathbf{r}_2) , d\mathbf{r}_1 d\mathbf{r}_2$$

Pipeline steps:

  1. Boys function $F_m(T)$ — auxiliary integral
  2. VRR (Obara-Saika vertical recurrence) — builds primitive integrals
  3. ETR (Electron Transfer Recurrence) — reduces angular momentum
  4. Contraction — combines primitives with coefficients + norms
  5. HRR (Head-Gordon-Pople horizontal recurrence) — shifts angular momentum to bra/ket

How To Test

# Unit tests (pipeline stages)
python -m pytest tests/test_two_elec_int_improved.py -v

# Integration tests
python -m pytest tests/test_electron_repulsion.py -v -k "improved"

# Coverage
python -m pytest tests/test_two_elec_int_improved.py tests/test_electron_repulsion.py --cov=gbasis/integrals --cov-report=term-missing

Proof That It Works

Unit tests (pipeline stages)

image

Integration tests (full ERIs via gbasis framework)

image

All tests

image

Coverage

image

black & ruff test

image

First Checklist

  • Tests added for each new function
  • All 35 tests pass
  • Black formatted
  • Ruff linting clean
  • Existing tests not broken
  • Docstrings in numpydoc format
  • No new dependencies added (uses existing numpy)
  • Pure Python only (no C/Fortran)

Scope Of this PR

Second Checklist

  • Write a good description of what the PR does.
  • Add tests for each unit of code added (e.g. function, class)
  • Update documentation
  • Squash commits that can be grouped together
  • Rebase onto master

Type of Changes

Type
🐛 Bug fix
✨ New feature
🔨 Refactoring
📜 Docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant