Skip to content

Add optional wrap_fractional to interpolate_path for unfolded k-paths#172

Merged
Alphaharrius merged 2 commits into
mainfrom
bugfix/optional-wrap
May 24, 2026
Merged

Add optional wrap_fractional to interpolate_path for unfolded k-paths#172
Alphaharrius merged 2 commits into
mainfrom
bugfix/optional-wrap

Conversation

@eyjafjallac

Copy link
Copy Markdown
Collaborator

Summary

  • Adds a new optional argument wrap_fractional: bool = True to qten.bands.interpolate_path.
  • Preserves current behavior by default (wrap_fractional=True), where rebased waypoints are wrapped into the canonical fractional cell.
  • Enables unfolded path construction with wrap_fractional=False, so rebased waypoint coordinates are kept as-is (no modulo-cell wrapping), which helps when plotting paths that should follow the original label sequence without collapsing equivalent points.

Why

When interpolating a path in a target reciprocal lattice different from the source KPointSet lattice, canonical fractional wrapping can cause distinct labeled waypoints to map onto the same folded point. This makes path ticks/labels appear merged in bandstructure plots.
This PR makes that wrapping behavior configurable without breaking existing callers.

API Change

  • interpolate_path(recip, waypoints, points, n_points=100, wrap_fractional=True) -> BzPath

Behavior:

  • wrap_fractional=True (default): uses rebased_wp.fractional() (existing behavior)
  • wrap_fractional=False: uses raw rebased_wp coordinates

Tests

  • Existing interpolation/path tests remain passing.
  • Added test:
    • test_interpolate_path_can_preserve_unwrapped_rebased_waypoints
    • Verifies that with wrap_fractional=False, an endpoint like (3/2, -1/4) is preserved instead of wrapped to (1/2, 3/4).

Validation

  • uv run pytest "tests/test_bands.py" -k "interpolate_path" passed
  • uv run pytest "tests/test_plots.py" -k "bandstructure and bz_path" passed

Example Usage

path = Q.interpolate_path(
    blocked_diamond.dual,
    ["Gamma", "L", "U", "X", "W", "L", "K", "Gamma", "U", "W", "Gamma", "X"],
    points=kpts,
    n_points=500,
    wrap_fractional=False,
)

…ndling

Enhance the `interpolate_path` function by introducing a `wrap_fractional` parameter, allowing users to control whether rebased waypoints are wrapped into the canonical fractional cell during interpolation. Update the documentation to reflect this new option and add a test to verify the preservation of unwrapped rebased waypoints, ensuring flexibility for visualization and debugging purposes.
@eyjafjallac eyjafjallac added this to the v0.4.1-qten milestone May 23, 2026
@eyjafjallac eyjafjallac requested a review from Alphaharrius May 23, 2026 19:22
@eyjafjallac eyjafjallac self-assigned this May 23, 2026
@eyjafjallac eyjafjallac added the bug Something isn't working label May 23, 2026
…path`

Clarify the behavior of the `wrap_fractional` parameter in the `interpolate_path` function documentation. The change ensures that the description accurately reflects the option to preserve raw rebased coordinates for visualization and debugging purposes.

@Alphaharrius Alphaharrius left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Alphaharrius Alphaharrius merged commit 0ad8d16 into main May 24, 2026
1 check passed
@Alphaharrius Alphaharrius deleted the bugfix/optional-wrap branch May 24, 2026 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants