Skip to content

Unify duplicated PBC correction logic into correct_pbc() - #41

Merged
bjmorgan merged 6 commits into
mainfrom
pbc-correction-unification
Mar 1, 2026
Merged

Unify duplicated PBC correction logic into correct_pbc()#41
bjmorgan merged 6 commits into
mainfrom
pbc-correction-unification

Conversation

@bjmorgan

@bjmorgan bjmorgan commented Mar 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • Extracts a correct_pbc() utility function in pbc_utils.py that encapsulates the PBC unwrapping decision (reference centre vs legacy spread-based), replacing character-for-character identical if/else blocks in PolyhedralSite and DynamicVoronoiSite
  • Removes DynamicVoronoiSite._compute_corrected_coords entirely — calculate_centre and the batch fallback in the collection now call correct_pbc() directly, resolving the design smell where the method's primary effect was a side effect
  • Consolidates PBC delegation tests into TestCorrectPbc in test_pbc_utils.py; site-level tests verify correct_pbc is called with the correct arguments
  • Dissolves containment.py: moves HAS_NUMBA to a dedicated _compat.py module, relocates update_pbc_shifts (numpy + numba variants) to pbc_utils.py, and absorbs FaceTopologyCache with its numba helpers into polyhedral_site.py (their sole consumer)
  • All tests migrated from test_containment.py to test_pbc_utils.py and test_polyhedral_site.py respectively; containment.py was internal (not exported from __init__.py) so there is no public API change

bjmorgan added 4 commits March 1, 2026 06:55
Extract a correct_pbc() utility in pbc_utils.py that encapsulates the
unwrapping decision (reference centre vs legacy spread-based). Both
PolyhedralSite and DynamicVoronoiSite now call this instead of
duplicating the if/else block.

Remove DynamicVoronoiSite._compute_corrected_coords entirely —
calculate_centre and the batch fallback in the collection both call
correct_pbc() directly, resolving the design smell where the method's
primary effect was a side effect.

PBC delegation tests consolidated in TestCorrectPbc; site-level tests
verify correct_pbc is called with the right arguments.
- Fix missing trailing newlines in pbc_utils.py and test_pbc_utils.py
- Replace convoluted assertion with simple kwargs check
- Clarify lattice parameter docstrings in correct_pbc and
  _store_vertex_coords
- Add type hints and align parameter order on _reference_centre test
  helper to match correct_pbc(frac_coords, reference_center, lattice)
- Split int64 dtype test to cover both legacy and reference-centre paths
- Add empty array guard in correct_pbc for zero-size input
- Move test_reset_clears_centre into its own TestResetWithCalculatedCentre
  class
Move HAS_NUMBA into a dedicated _compat.py module as the single source
of truth for optional dependency detection. Relocate update_pbc_shifts
(numpy + numba variants) to pbc_utils.py where the other PBC utilities
live. Absorb FaceTopologyCache and its numba helpers into
polyhedral_site.py, their sole consumer. Delete containment.py and
test_containment.py, with all tests moved to test_pbc_utils.py and
test_polyhedral_site.py respectively.
Aligns the empty-array early return in
unwrap_vertices_to_reference_center with the int64 dtype used
consistently elsewhere in pbc_utils.

This comment was marked as resolved.

bjmorgan added 2 commits March 1, 2026 08:15
Fixes platform-dependent dtype in the image shifts returned by
unwrap_vertices_to_reference_center, guaranteeing the int64 contract
documented in correct_pbc on all platforms including Windows.
@bjmorgan
bjmorgan merged commit 2716e37 into main Mar 1, 2026
4 checks passed
@bjmorgan
bjmorgan deleted the pbc-correction-unification branch March 1, 2026 09:01
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.

2 participants