Skip to content

Add periodic bond wrapping support in plotting functions#149

Closed
eyjafjallac wants to merge 5 commits into
mainfrom
bugfix/plot-lattice
Closed

Add periodic bond wrapping support in plotting functions#149
eyjafjallac wants to merge 5 commits into
mainfrom
bugfix/plot-lattice

Conversation

@eyjafjallac
Copy link
Copy Markdown
Collaborator

Summary

  • Reworked compute_bonds in ext/plots/src/qten_plots/_utils.py to make periodic bond selection more robust and deterministic.
  • Updated both structure plot backends (_plotly_impl.py, _mpl_impl.py) to pass lattice/offset metadata into bond computation.
  • Added show_periodic_wrap_bonds (default False) to structure plotting so users can hide wrap-around seam bonds for cleaner finite-cell visuals, while still allowing torus-style wrap bonds when needed.

Why

  • Nearest-neighbor bond inference based only on geometric cutoff was fragile for periodic/multi-sublattice lattices (e.g. honeycomb/kagome), producing extra-looking seam artifacts.
  • Users need a clean default visualization and an explicit switch for periodic wrap connectivity display.

TODO

  • kagome.plot("structure") shows clean nearest-neighbor bonds without seam-wrap artifacts.
  • kagome.plot("structure") no longer shows spurious extra-looking bonds in default mode.
  • Verify both backends:
    • backend="plotly"
    • backend="matplotlib"
  • Quick performance sanity check on shape=(12, 12) honeycomb and kagome remains acceptable.

- Introduced `show_periodic_wrap_bonds` parameter in both `plot_structure_mpl` and `plot_structure` functions to control the visualization of bonds that cross periodic boundaries.
- Updated `compute_bonds` function to handle periodic boundary conditions more effectively, allowing for accurate bond representation in periodic lattices.
- Enhanced documentation and tests to cover the new functionality and ensure correct behavior in various scenarios.
@eyjafjallac eyjafjallac added this to the v0.2.1-qten-plots milestone May 11, 2026
@eyjafjallac eyjafjallac requested a review from Alphaharrius May 11, 2026 10:41
@eyjafjallac eyjafjallac self-assigned this May 11, 2026
@eyjafjallac eyjafjallac added the bug Something isn't working label May 11, 2026
…eadability

- Reformatted the assignment of `boundary_basis` in the `compute_bonds` function to enhance code clarity by breaking it into multiple lines.
- This change aims to maintain consistency in code style and improve maintainability.
- Introduced `show_periodic_wrap_bonds` and `periodic_image_opacity` parameters in `plot_structure_mpl` and `plot_structure` functions to enhance visualization of bonds in periodic lattices.
- Updated the `compute_bonds` function to improve handling of periodic boundary conditions, ensuring accurate bond representation.
- Enhanced documentation to reflect these new features and their usage.
- Added notes for `show_periodic_wrap_bonds` and `periodic_image_opacity` parameters in the documentation to clarify their effects on bond connectivity and periodic-image visibility in plotting functions.
- Enhanced the clarity of the documentation to ensure users understand the usage of these new features.
…ions

- Introduced `bond_mode` parameter in `plot_structure_mpl` and `plot_structure` functions to allow users to specify bond-neighbor selection modes: `auto`, `nearest`, or `periodic`.
- Updated the `compute_bonds` function to validate the `bond_mode` and ensure proper handling of periodic boundary conditions.
- Enhanced documentation to clarify the usage of the new `bond_mode` parameter and its implications for bond visualization.
- Added tests to verify the correct behavior of the new functionality and to ensure that invalid bond modes are properly rejected.
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.

Lattice structure plotting: Use topology-based bonds instead of geometric nearest-neighbor inference

1 participant