unit-cell-gui 0.2.2__tar.gz → 0.2.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. unit_cell_gui-0.2.5/CHANGELOG.md +225 -0
  2. {unit_cell_gui-0.2.2 → unit_cell_gui-0.2.5}/CITATION.cff +2 -2
  3. unit_cell_gui-0.2.5/MANIFEST.in +15 -0
  4. unit_cell_gui-0.2.5/PKG-INFO +336 -0
  5. unit_cell_gui-0.2.5/README.md +318 -0
  6. unit_cell_gui-0.2.5/RELEASE_NOTES_0.2.3.md +53 -0
  7. unit_cell_gui-0.2.5/RELEASE_NOTES_0.2.4.md +77 -0
  8. unit_cell_gui-0.2.5/RELEASE_NOTES_0.2.5.md +113 -0
  9. unit_cell_gui-0.2.5/docs/hybrid-transparency.md +143 -0
  10. unit_cell_gui-0.2.5/docs/partial-updates.md +139 -0
  11. unit_cell_gui-0.2.5/examples/partial_updates.py +60 -0
  12. {unit_cell_gui-0.2.2 → unit_cell_gui-0.2.5}/pyproject.toml +1 -1
  13. {unit_cell_gui-0.2.2 → unit_cell_gui-0.2.5}/src/unit_cell_gui/__init__.py +1 -1
  14. unit_cell_gui-0.2.5/src/unit_cell_gui/_contacts.py +80 -0
  15. unit_cell_gui-0.2.5/src/unit_cell_gui/_numeric.py +138 -0
  16. unit_cell_gui-0.2.5/src/unit_cell_gui/_scene_updates.py +135 -0
  17. unit_cell_gui-0.2.5/src/unit_cell_gui/_spatial.py +84 -0
  18. unit_cell_gui-0.2.5/src/unit_cell_gui/_transparency_sort.py +371 -0
  19. unit_cell_gui-0.2.5/src/unit_cell_gui/_weighted_oit.py +256 -0
  20. {unit_cell_gui-0.2.2 → unit_cell_gui-0.2.5}/src/unit_cell_gui/gl_geometry.py +28 -1
  21. {unit_cell_gui-0.2.2 → unit_cell_gui-0.2.5}/src/unit_cell_gui/hatching.py +2 -4
  22. {unit_cell_gui-0.2.2 → unit_cell_gui-0.2.5}/src/unit_cell_gui/models.py +26 -11
  23. unit_cell_gui-0.2.5/src/unit_cell_gui/opengl_viewer.py +3402 -0
  24. unit_cell_gui-0.2.5/src/unit_cell_gui.egg-info/PKG-INFO +336 -0
  25. unit_cell_gui-0.2.5/src/unit_cell_gui.egg-info/SOURCES.txt +58 -0
  26. unit_cell_gui-0.2.5/tests/render_test_helpers.py +26 -0
  27. {unit_cell_gui-0.2.2 → unit_cell_gui-0.2.5}/tests/test_unit_cell_gui.py +7 -0
  28. {unit_cell_gui-0.2.2 → unit_cell_gui-0.2.5}/tests/test_visibility_cache.py +26 -7
  29. unit_cell_gui-0.2.5/tests/test_z_atom_instancing.py +188 -0
  30. unit_cell_gui-0.2.5/tests/test_z_audit.py +340 -0
  31. unit_cell_gui-0.2.5/tests/test_z_contact_colours.py +112 -0
  32. unit_cell_gui-0.2.5/tests/test_z_opacities.py +139 -0
  33. unit_cell_gui-0.2.5/tests/test_z_outline_instancing.py +171 -0
  34. unit_cell_gui-0.2.5/tests/test_z_scene_instancing.py +201 -0
  35. unit_cell_gui-0.2.5/tests/test_z_transparency_sort.py +218 -0
  36. unit_cell_gui-0.2.5/tests/test_z_updates.py +225 -0
  37. unit_cell_gui-0.2.5/tests/test_z_weighted_oit.py +423 -0
  38. unit_cell_gui-0.2.5/validation/README.md +130 -0
  39. unit_cell_gui-0.2.5/validation/benchmark_dense_sort.py +39 -0
  40. unit_cell_gui-0.2.5/validation/benchmark_sort.py +112 -0
  41. unit_cell_gui-0.2.5/validation/benchmark_transparency.py +101 -0
  42. unit_cell_gui-0.2.5/validation/benchmark_updates.py +132 -0
  43. unit_cell_gui-0.2.5/validation/benchmark_weighted_oit.py +191 -0
  44. unit_cell_gui-0.2.5/validation/check_installed.py +67 -0
  45. unit_cell_gui-0.2.5/validation/prototype_weighted_oit.py +79 -0
  46. unit_cell_gui-0.2.5/validation/render_regression_scenes.py +117 -0
  47. unit_cell_gui-0.2.2/CHANGELOG.md +0 -122
  48. unit_cell_gui-0.2.2/MANIFEST.in +0 -7
  49. unit_cell_gui-0.2.2/PKG-INFO +0 -177
  50. unit_cell_gui-0.2.2/README.md +0 -159
  51. unit_cell_gui-0.2.2/src/unit_cell_gui/opengl_viewer.py +0 -2170
  52. unit_cell_gui-0.2.2/src/unit_cell_gui.egg-info/PKG-INFO +0 -177
  53. unit_cell_gui-0.2.2/src/unit_cell_gui.egg-info/SOURCES.txt +0 -27
  54. {unit_cell_gui-0.2.2 → unit_cell_gui-0.2.5}/LICENSE +0 -0
  55. {unit_cell_gui-0.2.2 → unit_cell_gui-0.2.5}/RELEASE_NOTES_0.2.2.md +0 -0
  56. {unit_cell_gui-0.2.2 → unit_cell_gui-0.2.5}/THIRD_PARTY_NOTICES.txt +0 -0
  57. {unit_cell_gui-0.2.2 → unit_cell_gui-0.2.5}/setup.cfg +0 -0
  58. {unit_cell_gui-0.2.2 → unit_cell_gui-0.2.5}/src/unit_cell_gui/py.typed +0 -0
  59. {unit_cell_gui-0.2.2 → unit_cell_gui-0.2.5}/src/unit_cell_gui/qt_config.py +0 -0
  60. {unit_cell_gui-0.2.2 → unit_cell_gui-0.2.5}/src/unit_cell_gui/render_geometry.py +0 -0
  61. {unit_cell_gui-0.2.2 → unit_cell_gui-0.2.5}/src/unit_cell_gui/view_helpers.py +0 -0
  62. {unit_cell_gui-0.2.2 → unit_cell_gui-0.2.5}/src/unit_cell_gui/viewer.py +0 -0
  63. {unit_cell_gui-0.2.2 → unit_cell_gui-0.2.5}/src/unit_cell_gui.egg-info/dependency_links.txt +0 -0
  64. {unit_cell_gui-0.2.2 → unit_cell_gui-0.2.5}/src/unit_cell_gui.egg-info/requires.txt +0 -0
  65. {unit_cell_gui-0.2.2 → unit_cell_gui-0.2.5}/src/unit_cell_gui.egg-info/top_level.txt +0 -0
  66. {unit_cell_gui-0.2.2 → unit_cell_gui-0.2.5}/tests/test_gl_geometry.py +0 -0
  67. {unit_cell_gui-0.2.2 → unit_cell_gui-0.2.5}/tests/test_render_geometry.py +0 -0
@@ -0,0 +1,225 @@
1
+ # Changelog
2
+
3
+ ## 0.2.5 - 2026-10-19
4
+
5
+ Changes since the published 0.2.4 release:
6
+
7
+ - Add indexed external polyhedron opacity updates without mesh rebuilds.
8
+ - Sort transparent faces and physical edges together using projected overlap
9
+ depth, preserving native Qt MSAA without depth peeling or supersampling.
10
+ - Add independent per-widget WBOIT-during-rotation and permanent WBOIT options
11
+ through Shift + right-button menu and trailing DisplayOptions fields.
12
+ - Permanent WBOIT takes priority; rotation-only mode returns to sorted rendering
13
+ on release or after 150 ms of external orientation inactivity. Preserve signals,
14
+ ordinary pan/zoom and engraving; include nonfatal fallback and resource limits.
15
+ - Cache world geometry/material keys/normals; prune projected candidates and
16
+ bound clipping batches. Index atoms/polyhedron bounds and cache contact frames.
17
+ - Make opacity-only state lazy, update host polyhedron styles locally and cache
18
+ legend entries using visible components.
19
+ - Validate integer indices, GPU float32 input/derived ranges and invertible,
20
+ well-conditioned orientations; stabilize very large occupancy weights.
21
+ - Free resources on shader failures and scene clear; restore normal close/show.
22
+ - Add state, fault, GL lifecycle and numerical regressions, plus separate CPU,
23
+ GPU, frame-interval and dense-graph diagnostics. Dependencies are unchanged.
24
+
25
+ See RELEASE_NOTES_0.2.5.md for the complete release relative to GitHub 0.2.4.
26
+
27
+ ## 0.2.4 - 2026-10-13
28
+
29
+ Changes since 0.2.3:
30
+
31
+ - Instance camera-facing atom outlines, coloured half-bonds, polyhedron fill
32
+ triangles, physical edges and engraving bonds using shared meshes.
33
+ - Keep geometry resident during camera changes; update edge sorting through
34
+ compact index lists and split large texture buffers at driver limits.
35
+ - Add atomic indexed external updates for atom positions/visibility and
36
+ polyhedron replacement, with effective-state getters and reset.
37
+ - Patch affected atom records and existing adjacent bonds; give modified
38
+ polyhedra independent buffers and refresh dependent section/hatch caches.
39
+ - Match atom/face intersection curves to the face colour in coloured mode,
40
+ including polyhedron colour overrides; retain black ink in engraving mode.
41
+ - Refresh contact colours after display-mode, style or polyhedron changes.
42
+ - Preserve input Scene, camera, existing API/models, line widths, intact-polygon
43
+ hatching and OpenGL 3.3 support. Add documentation and an external-control example.
44
+
45
+ ## 0.2.3.03 - 2026-10-13 (local experiment)
46
+
47
+ - Add atomic indexed `update_scene` packets, atom coordinate/visibility setters,
48
+ polyhedron updates, reset and effective-state getters.
49
+ - Keep original Scene data and camera unchanged; preserve host style restrictions.
50
+ - Patch only changed atom/outline rows and existing adjacent bond records.
51
+ - Give replaced polyhedra independent buffers; refresh only dependent sections
52
+ and hatching, preserving intact faces, transparency ordering and line styles.
53
+ - Retain clipped stable slots for hidden atoms and degenerate bonds.
54
+ - Coalesce GPU updates until paint and release dynamic resources with scene/context.
55
+ - Include an external-control example and preserve existing API signatures.
56
+ - Python packaging normalizes `0.2.3.03` to `0.2.3.3`.
57
+
58
+ ## 0.2.3.02 - 2026-10-12 (local experiment)
59
+
60
+ - Render coloured half-bonds with one shared indexed cylinder.
61
+ - Render polyhedron fill triangles, physical edges and engraving bonds
62
+ with shared primitives and compact instance records.
63
+ - Preserve face/edge transparency ordering, physical shared-edge deduplication,
64
+ lighting, line widths, antialiasing and depth offsets on OpenGL 3.3.
65
+ - Batch depth-sorted edges with a small integer order list while keeping
66
+ coordinates and colours resident.
67
+ - Split primitive instance storage at the driver's texture-buffer limit.
68
+ - Keep hatching and atom/face intersections unchanged; retain intact polygon
69
+ faces for hatching and preserve the public API.
70
+ - Extend GL resource cleanup and reinitialization for the new passes.
71
+ - Python packaging normalizes `0.2.3.02` to `0.2.3.2`.
72
+
73
+ ## 0.2.3.01 - 2026-10-08 (local experiment)
74
+
75
+ - Render camera-facing atom silhouettes with a shared instanced ring.
76
+ - Keep outline instance buffers resident during rotation, zoom and resize;
77
+ update camera transforms and cosmetic radius padding in the vertex shader.
78
+ - Preserve solid/dashed outlines, depth testing, antialiasing and the existing
79
+ order relative to opaque and transparent scene geometry.
80
+ - Clean up and recreate all new GL resources with the viewer context.
81
+ - Python distribution metadata normalizes this version to `0.2.3.1`.
82
+
83
+ ## 0.2.3 - 2026-10-06
84
+
85
+ ### Performance
86
+
87
+ - Render atoms with one indexed unit-sphere mesh and one compact instance
88
+ record per visible atom using `glDrawElementsInstanced`.
89
+ - Replace repeated per-vertex centre, radius, colour and occupancy data with
90
+ 144-byte instance records; keep the shared mesh and index buffers resident
91
+ during atom scale, colour, occupancy visibility and scene changes.
92
+ - Remove individual CPU sphere tessellation and the per-atom mesh cache.
93
+
94
+ ### Compatibility
95
+
96
+ - Preserve the public scene models, viewer aliases, display options, style
97
+ overrides, orientation synchronization and interaction signals.
98
+ - Keep OpenGL 3.3 core and GLSL 330 requirements, with 13 attribute locations
99
+ and no new dependencies or native extension.
100
+ - Preserve the original sphere triangles and normals, mixed/partial occupancy
101
+ materials, hidden occupancy sectors, external atoms, colour and engraving
102
+ modes, and the existing outline/intersection/hatching passes.
103
+ - Release and recreate mesh, index and instance buffers with viewer context
104
+ cleanup/reinitialization.
105
+
106
+ ## 0.2.2 - 2026-10-01
107
+
108
+ ### Fixed
109
+
110
+ - Individual polyhedron visibility changes now filter resident face, edge and
111
+ atom/face-intersection ranges at draw time, instead of rebuilding their
112
+ geometry and re-uploading the complete buffers.
113
+ - Apply the same visibility selection to opaque and transparent faces, edges,
114
+ hatching and intersection contours, including multiple polyhedra sharing a
115
+ site key.
116
+
117
+ ### Performance
118
+
119
+ - Cache engraving hatching separately for each polyhedron. Reuse GPU buffers
120
+ when the view and effective division count are unchanged; rebuild only the
121
+ affected polyhedra when visible depth extrema alter the density.
122
+ - Preserve the original hatching algorithms and density/GRIP normalization
123
+ over visible polyhedra. Keep at most four CPU density variants per polyhedron
124
+ for the current view; discard them when the view or scene changes.
125
+ - Vectorize finite-face clipping of sphere/face section segments while keeping
126
+ the original 160-sample circles and boundary tolerance.
127
+ - Defer intersection and hatching preparation until their layers are visible.
128
+ - Release per-polyhedron hatching GPU resources on scene replacement/clearing
129
+ and context cleanup; recreate them when needed.
130
+
131
+ ### Compatibility
132
+
133
+ - Keep all public scene models, display options, style overrides, viewer aliases
134
+ and orientation/interaction signals unchanged. Hosts using the existing
135
+ 0.2.x API do not need integration changes.
136
+
137
+ ## 0.2.1 - 2026-09-15
138
+
139
+ ### Fixed
140
+
141
+ - Configure one global OpenGL 3.3 surface format and enable shared OpenGL
142
+ contexts before `QApplication` construction. This prevents stale top-level
143
+ composition after moving or maximising a host window on mixed-DPI screens.
144
+ - Release GPU resources when Qt destroys a viewer context and rebuild every
145
+ buffer and shader when a new context is initialised.
146
+ - Reduce stair-stepping with 8-sample multisampling and pixel-coverage
147
+ antialiasing for polyhedron edges, hatching, bonds and atom contours.
148
+ - Double the period of the dashed unit-cell box while preserving the 2:1
149
+ dash-to-gap ratio.
150
+
151
+ ## 0.2.0 - 2026-09-14
152
+
153
+ ### Changed
154
+
155
+ - Replaced the legacy QPainter viewer backend with an OpenGL 3.3 renderer using
156
+ a real depth buffer while preserving the existing `UnitCellViewer` and
157
+ `CrystalCanvas` public API.
158
+ - `UnitCellViewer`, `CrystalCanvas` and `OpenGLUnitCellViewer` now resolve to
159
+ the same OpenGL-backed widget.
160
+ - Render coloured atoms as real 3D spheres and coloured bonds as 3D cylinders;
161
+ engraving bonds remain thin grayscale screen-space lines.
162
+ - Keep occupancy sectors camera-facing; unoccupied or hidden occupancy is shown
163
+ in white. Engraving atoms use flat monochrome fills, with dashed outlines for
164
+ partial occupancy.
165
+ - Render unit-cell edges with the original dashed style in both colour and
166
+ engraving modes.
167
+ - Render polyhedron edges from shared edge geometry and offset them along the
168
+ exterior dihedral bisector so outlines remain visible at obtuse face angles.
169
+ - Reduced coloured bond thickness by a factor of three for realistic crystal
170
+ structures.
171
+
172
+ ### Added
173
+
174
+ - Depth-buffered occlusion between atoms, bonds and polyhedron faces.
175
+ - Transparent polyhedron faces with stable screen-space outlines independent of
176
+ driver-specific wide-line support.
177
+ - Depth-tested atom outlines and atom/polyhedron-face intersection contours in
178
+ both colour and engraving modes.
179
+ - Dynamic engraving hatching that updates with rotation while reusing the
180
+ original 0.1.0 hatching algorithms.
181
+ - An explicit `OpenGLUnitCellViewer` name alongside the compatibility aliases.
182
+
183
+ ### Fixed
184
+
185
+ - Corrected local overlap between spheres, bonds and polyhedron faces that could
186
+ not be represented reliably by whole-primitive painter ordering.
187
+ - Fixed hatching disappearing on newly visible faces during rotation.
188
+ - Fixed z-fighting between hatching and its supporting face.
189
+ - Fixed polyhedron edge outlines becoming partially hidden, including at obtuse
190
+ dihedral angles.
191
+ - Fixed atom outlines and atom/face intersection contours appearing on top of
192
+ transparent faces instead of underneath them.
193
+ - Avoided unsupported `glLineWidth()` values by expanding important lines into
194
+ screen-space quads in a geometry shader.
195
+
196
+ ### Performance
197
+
198
+ - Cached sphere, cylinder and face tessellation instead of rebuilding geometry
199
+ during interactive rotation.
200
+ - Uploaded static geometry to GPU buffers and moved orientation changes to
201
+ shader uniforms.
202
+ - Split render caches so display switches do not rebuild the complete scene.
203
+ - Made polyhedron visibility a draw-only toggle instead of an expensive geometry
204
+ rebuild.
205
+ - Added broad-phase filtering for atom/face intersection calculations.
206
+
207
+ ### Compatibility
208
+
209
+ - Preserved scene models, display options, style overrides, orientation events,
210
+ interaction signals and existing construction/import paths.
211
+ - Moved the original hatching and screen-drag helper algorithms into shared
212
+ helpers and reused them directly from the OpenGL renderer.
213
+
214
+ ## 0.1.0 - 2026-09-11
215
+
216
+ - Added immutable input models for caller-supplied atoms, bonds, unit cells,
217
+ basis vectors and ready polyhedra.
218
+ - Added native PySide6 rendering with depth ordering, colour and monochrome
219
+ atoms, mixed occupancies, bonds, cell edges and basis arrows.
220
+ - Added polyhedron hatching, including intact quadrilateral faces with
221
+ `2x + 1` strokes and direction transport through real shared edges.
222
+ - Added left-button rotation with complete orientation-matrix events,
223
+ right-button panning, wheel zoom and a switch for disabling rotation.
224
+ - Added global display options and copied per-site style overrides.
225
+ - Set polyhedra to hidden by default.
@@ -8,7 +8,7 @@ authors:
8
8
  repository-code: https://github.com/ofussr/unit-cell-gui
9
9
  url: https://github.com/ofussr/unit-cell-gui
10
10
  orcid: https://orcid.org/0000-0002-5571-8525
11
- version: 0.2.2
12
- date-released: 2026-10-01
11
+ version: 0.2.5
12
+ date-released: 2026-10-19
13
13
  doi: 10.5281/zenodo.22714946
14
14
  license: MIT
@@ -0,0 +1,15 @@
1
+ include CHANGELOG.md
2
+ include CITATION.cff
3
+ include LICENSE
4
+ include README.md
5
+ include RELEASE_NOTES_0.2.2.md
6
+ include RELEASE_NOTES_0.2.3.md
7
+ include RELEASE_NOTES_0.2.4.md
8
+ include RELEASE_NOTES_0.2.5.md
9
+ include THIRD_PARTY_NOTICES.txt
10
+ recursive-include tests *.py
11
+ exclude LOCAL_NOTES_*.md
12
+ recursive-include docs *.md
13
+ recursive-include examples *.py
14
+ recursive-include validation *.py *.md
15
+ exclude RELEASE_NOTES_0.2.5.*.md
@@ -0,0 +1,336 @@
1
+ Metadata-Version: 2.4
2
+ Name: unit-cell-gui
3
+ Version: 0.2.5
4
+ Summary: PySide6 widget for rendering caller-supplied unit-cell scenes
5
+ Author-email: Mikhail Mirushchenko <miruschenko98@gmail.com>
6
+ License-Expression: MIT
7
+ Classifier: Development Status :: 3 - Alpha
8
+ Classifier: Environment :: X11 Applications :: Qt
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3 :: Only
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: numpy>=1.24
15
+ Requires-Dist: PySide6-Essentials<7,>=6.8
16
+ Requires-Dist: PyOpenGL<4,>=3.1.7
17
+ Dynamic: license-file
18
+
19
+ # unit-cell-gui
20
+
21
+ `unit-cell-gui` is a reusable PySide6 widget that draws complete unit-cell
22
+ scenes supplied by another program. It does not read CIF files, expand
23
+ symmetry, resolve atomic positions, infer bonds, construct polyhedra or
24
+ calculate diffraction.
25
+
26
+ The caller supplies ready Cartesian coordinates and presentation data:
27
+
28
+ - atoms and their styled occupancy components;
29
+ - bond indices;
30
+ - unit-cell vertices and edges;
31
+ - three basis vectors;
32
+ - optional polyhedron vertices, polygon faces and centres.
33
+
34
+ The package owns only display behaviour: camera projection, OpenGL depth buffering,
35
+ left-button rotation, right-button panning, wheel zoom, occupancy sectors,
36
+ colour and black-and-white drawing, and polyhedron hatching. Quadrilateral
37
+ hatching uses one intact polygon with `2x + 1` full parallel strokes. Hatch
38
+ directions on farther faces are refolded through real shared edges.
39
+
40
+ <table>
41
+ <tr>
42
+ <td align="center" width="50%">
43
+ <img src="https://raw.githubusercontent.com/ofussr/unit-cell-gui/main/docs/images/color-view.png" alt="Color view" width="100%">
44
+ <br>
45
+ <sub>Color view</sub>
46
+ </td>
47
+ <td align="center" width="50%">
48
+ <img src="https://raw.githubusercontent.com/ofussr/unit-cell-gui/main/docs/images/hatched-view.png" alt="Hatched view" width="100%">
49
+ <br>
50
+ <sub>Hatched view</sub>
51
+ </td>
52
+ </tr>
53
+ </table>
54
+
55
+ ## Installation
56
+
57
+ ```bash
58
+ python -m pip install unit-cell-gui
59
+ ```
60
+
61
+ Python 3.10 or newer, NumPy, PySide6 Essentials and PyOpenGL are required. The renderer requests an OpenGL 3.3 core-profile context.
62
+
63
+ Import `UnitCellViewer` or `CrystalCanvas` before constructing `QApplication`.
64
+ This lets the package establish one shared OpenGL format for every viewer and
65
+ keeps top-level Qt composition stable across screen and DPI changes. The basic
66
+ example below already uses this order.
67
+
68
+ ## Basic use
69
+
70
+ ```python
71
+ import numpy as np
72
+ from PySide6.QtWidgets import QApplication
73
+ from unit_cell_gui import Atom, AtomComponent, DisplayOptions, Scene, UnitCellViewer
74
+
75
+ silicon = AtomComponent(
76
+ key="Si:Si1", label="Si1", element="Si",
77
+ occupancy=1.0, colour="#f0c8a0", radius=0.30,
78
+ )
79
+ scene = Scene(
80
+ atoms=(Atom("Si:Si1", "Si1", (silicon,)),),
81
+ atom_centers=np.array([[0.0, 0.0, 0.0]]),
82
+ bonds=np.empty((0, 2), dtype=int),
83
+ cell_vertices=np.array([
84
+ [x, y, z]
85
+ for x in (-1.0, 1.0)
86
+ for y in (-1.0, 1.0)
87
+ for z in (-1.0, 1.0)
88
+ ]),
89
+ cell_edges=np.array([
90
+ [0, 1], [0, 2], [0, 4], [1, 3], [1, 5], [2, 3],
91
+ [2, 6], [3, 7], [4, 5], [4, 6], [5, 7], [6, 7],
92
+ ]),
93
+ basis_vectors=np.eye(3),
94
+ base_radius=2.0,
95
+ )
96
+
97
+ app = QApplication([])
98
+ viewer = UnitCellViewer()
99
+ viewer.set_scene(scene)
100
+ viewer.set_display_options(DisplayOptions(show_polyhedra=False))
101
+ viewer.show()
102
+ app.exec()
103
+ ```
104
+
105
+ `Scene` copies its arrays and makes them read-only. Later changes in the caller
106
+ therefore cannot alter an already submitted scene.
107
+
108
+ ## Orientation synchronization
109
+
110
+ `orientation` is a 3 by 3 world-to-camera matrix. For column vectors the
111
+ camera coordinate is `orientation @ world`; the renderer's row arrays use the
112
+ equivalent `world @ orientation.T`.
113
+
114
+ Matrices must be finite and float32-representable, remain invertible after
115
+ float32 rounding, and have condition number below 1e6. Their inverse and
116
+ conservative generated/transformed geometry bounds must also fit float32.
117
+ Reflections and general well-conditioned invertible matrices remain accepted;
118
+ SO(3) orthogonality is not required. Invalid input leaves the previous state
119
+ unchanged and does not emit a signal.
120
+
121
+ Programmatic changes are silent by default:
122
+
123
+ ```python
124
+ viewer.set_orientation(matrix, emit=False)
125
+ ```
126
+
127
+ Interactive rotation emits the complete new matrix through
128
+ `orientation_changed`. Connect that signal to a pole figure or another view,
129
+ then send changes from the other view back with silent `set_orientation` calls.
130
+ This supports bidirectional synchronization without a signal loop.
131
+
132
+ ```python
133
+ viewer.orientation_changed.connect(update_other_view)
134
+ other_view.orientation_changed.connect(
135
+ lambda matrix: viewer.set_orientation(matrix, emit=False)
136
+ )
137
+ ```
138
+
139
+ Set `rotation_enabled=False` when an application temporarily forbids left-button
140
+ rotation. Panning and zoom remain available. Polyhedra are hidden by default
141
+ and must be enabled with `show_polyhedra=True`.
142
+
143
+ Per-position colours, visibility and opaque-polyhedron selections are replaced
144
+ atomically with `viewer.set_style_overrides(StyleOverrides(...))`. The widget
145
+ copies these mappings, so the host can keep its own independent UI state.
146
+
147
+ ## Atom instancing
148
+
149
+ Atoms share one indexed sphere mesh with the same 16-by-24 tessellation as
150
+ previous releases. An OpenGL instance buffer stores each visible atom's
151
+ Cartesian centre, radius, eight RGB occupancy colours and cumulative occupancy
152
+ thresholds once, instead of repeating them for every triangle vertex. The atom
153
+ layer uses one `glDrawElementsInstanced` call.
154
+
155
+ The base sphere and its indices occupy 18,792 bytes per viewer; instance records
156
+ add 144 bytes per visible atom. For 1,000 atoms, these buffers total 162,792
157
+ bytes, compared with 328,320,000 bytes for the previous expanded atom buffer.
158
+ This comparison excludes bonds, outlines, polyhedra and Qt/driver overhead.
159
+ The number of sphere triangles is unchanged, so this is primarily a reduction
160
+ in geometry preparation and buffer storage, not a frame-rate guarantee.
161
+
162
+ OpenGL 3.3 core remains sufficient: the renderer uses 13 vertex attribute
163
+ locations, within the guaranteed minimum of 16. No C++ extension, new package
164
+ dependency or host-application API change is required.
165
+
166
+ ## Visibility and rendering caches
167
+
168
+ Both global and per-site polyhedron visibility filter already prepared geometry
169
+ at draw time. Faces, edges and atom/face intersection contours remain in GPU
170
+ buffers when a site is hidden or shown. This avoids rebuilding the full
171
+ polyhedron layer for each individual visibility change.
172
+
173
+ Engraving hatching is cached per polyhedron. Its density still follows the
174
+ depth range of the visible polyhedra: hiding the nearest or farthest object can
175
+ change other objects' effective division counts. Only affected hatch buffers
176
+ are updated. Rotation, zoom, panning and window-size changes keep the original
177
+ view-dependent hatching behaviour. CPU density variants are bounded and are
178
+ discarded when the view or scene changes.
179
+
180
+ Intersection contours and hatching are prepared when their layers are first
181
+ needed. The initial preparation still has a cost; subsequent site visibility
182
+ changes reuse the prepared data.
183
+
184
+
185
+ ## Renderer compatibility
186
+
187
+ `UnitCellViewer` and the legacy alias `CrystalCanvas` now use the OpenGL
188
+ renderer internally. Existing construction, scene submission, display-option,
189
+ style-override, orientation-synchronization and interaction calls remain the
190
+ same. `OpenGLUnitCellViewer` remains available as an explicit name and refers
191
+ to the same renderer class.
192
+
193
+ ## Used in
194
+
195
+ `unit-cell-gui` is used as the crystal-structure viewer in [XRD Combine](https://github.com/ofussr/XRD-Combine), where it is integrated with CIF processing, diffraction tools, and synchronized crystallographic views.
196
+
197
+ ## How to cite
198
+
199
+ If you use `unit-cell-gui` in academic work, please cite the Zenodo record:
200
+
201
+ [![DOI](https://img.shields.io/badge/DOI-10.5281%2Fzenodo.22714946-blue.svg)](https://doi.org/10.5281/zenodo.22714946)
202
+
203
+ You can also use the metadata provided in [`CITATION.cff`](CITATION.cff).
204
+
205
+ ## Shared GPU geometry (0.2.4)
206
+
207
+ Atoms, camera-facing outlines, coloured bonds, polyhedron fill triangles,
208
+ physical edges and engraving bonds use shared meshes and instance records.
209
+ Camera changes keep geometry resident; depth-sorted edges update compact
210
+ index lists. Large arrays are split at the driver's texture-buffer limit.
211
+ Sphere tessellation remains 720 triangles per atom; no LOD is applied.
212
+
213
+ Hatching uses intact polygons and the existing stroke algorithm. In coloured mode, atom/face
214
+ intersection curves use the corresponding face colour, including polyhedron
215
+ colour overrides. Engraving keeps black intersection ink.
216
+
217
+ ## External partial updates (0.2.4)
218
+
219
+ ```python
220
+ viewer.update_scene(
221
+ atom_positions={17: (x, y, z)},
222
+ atom_visibility={42: False},
223
+ polyhedra={3: updated_polyhedron},
224
+ polyhedron_opacities={3: 0.35},
225
+ )
226
+ ```
227
+
228
+ Original scene indices stay stable; positions are absolute Cartesian XYZ.
229
+ Packets are validated atomically, copied and uploaded on the next paint.
230
+ Only changed atoms, their existing adjacent bonds and affected polyhedra are
231
+ updated; dependent sections and hatching refresh as needed.
232
+
233
+ `set_atom_positions`, `set_atom_visibility` and `update_polyhedra` provide
234
+ individual setters. `reset_scene_updates()` restores input geometry and local
235
+ visibility while preserving camera and host styles. Effective-state getters
236
+ are `get_atom_positions()`, `get_atom_visibility()` and `get_polyhedra()`.
237
+
238
+ `viewer.scene` remains the original object; `set_scene()` clears the overrides.
239
+ Call updates on the GUI thread. The host supplies updated polyhedra and bond
240
+ topology; neither is inferred automatically. Local visibility respects host
241
+ component/external-atom switches. A changed state draws a new frame without
242
+ requiring a complete scene rebuild.
243
+
244
+ See [the API contract](docs/partial-updates.md),
245
+ [the external-control example](examples/partial_updates.py), and
246
+ [changes since 0.2.3](RELEASE_NOTES_0.2.4.md).
247
+
248
+ ## Transparency and opacity control (0.2.5)
249
+
250
+ Transparent faces and physical edges share a global back-to-front order computed
251
+ from depth over projected overlap. The default renderer draws directly into Qt's
252
+ MSAA framebuffer without depth peeling or whole-window supersampling. Opaque
253
+ atoms, bonds and faces write depth before transparent surfaces. The host supplies
254
+ planar convex faces without physical intersections or cyclic visibility. Shared
255
+ boundaries are supported; dense overlap can still produce quadratic graph memory.
256
+
257
+ External opacity updates reuse resident geometry:
258
+
259
+ ```python
260
+ viewer.set_polyhedron_opacities({3: 0.35, 7: 1.0})
261
+ viewer.update_scene(atom_positions={17: (x, y, z)},
262
+ polyhedron_opacities={3: 0.5})
263
+ viewer.set_polyhedron_opacities({3: None})
264
+ values = viewer.get_polyhedron_opacities()
265
+ ```
266
+
267
+ Use original scene indices and GUI-thread calls. Zero hides an object; one makes
268
+ it opaque; None restores its default. Invalid packets are rejected atomically.
269
+ Fill/edges change together and explicit opacity fades contacts. A separate table
270
+ normally uploads four bytes per changed object. Positive fractional values are
271
+ stored in engraving, whose displayed fills remain opaque; zero hides the object.
272
+ See the [complete contract](docs/partial-updates.md).
273
+
274
+ ## Optional WBOIT modes
275
+
276
+ **Shift + right mouse button** opens two independent checkboxes:
277
+
278
+ | Setting | Behavior |
279
+ | --- | --- |
280
+ | Weighted Blended OIT when rotate | Approximate during rotation, exact after release/external inactivity |
281
+ | Weighted Blended OIT always | Approximate also at rest and after mouse release; takes priority |
282
+
283
+ Both default to false, apply to one widget, are not saved to disk, and are
284
+ ignored by engraving. Ordinary right-button dragging still pans. The existing
285
+ external API controls both:
286
+
287
+ ```python
288
+ viewer.set_display_options(weighted_blended_oit=True) # permanent
289
+ viewer.set_display_options(weighted_blended_oit=False) # leave permanent mode
290
+ viewer.set_display_options(weighted_blended_oit_when_rotate=True)
291
+ # Both off: use sorted transparency throughout.
292
+ viewer.set_display_options(weighted_blended_oit=False,
293
+ weighted_blended_oit_when_rotate=False)
294
+ ```
295
+
296
+ The checkboxes retain their independent values. Disabling permanent mode restores
297
+ the rotation-only preference. With rotation-only enabled, external set_orientation
298
+ series request an exact frame after 150 ms without an effective change. Repeating
299
+ the same orientation does not restart the timer. Mouse-held rotation stays fast
300
+ until release/interruption. Permanent mode does not start an idle-to-exact timer.
301
+ Neither quality changes nor timer completion emit extra orientation signals;
302
+ emit=False keeps its meaning. Pan/zoom alone do not start rotation-only WBOIT.
303
+
304
+ WBOIT uses two GL 3.3 accumulation passes and per-sample composition with shared
305
+ owned MSAA depth. It skips exact sorting and reuses resident meshes. Edge
306
+ coverage participates in alpha; opaque edges are handled separately and
307
+ contours/contacts are depth-tested beneath transparency. The approximation can
308
+ change hues/edge emphasis. Permanent mode intentionally retains it after stopping.
309
+ Small scenes may be slower with WBOIT enabled.
310
+
311
+ Resources are lazy and reused. Additional attachments cost approximately
312
+ 20 bytes × physical width × physical height × actual samples: 23.4 MiB at
313
+ 640 × 480 × 4, or 158.2 MiB at 1920 × 1080 × 4. DPR 2 multiplies this by four.
314
+ Qt/geometry/driver padding is additional. Exceeding the 256 MiB per-widget budget
315
+ or GPU limits uses exact fallback without silently lowering MSAA. Allocation or
316
+ pass failures appear in the menu and weighted_oit_error, separately from the
317
+ main opengl_error; retry is permitted after context restoration or close/show.
318
+ Scene clear/cleanup releases attachments. The historical
319
+ transparency_supersampling=1/2 field remains an inert compatibility option.
320
+
321
+ ## Preparation and robustness (0.2.5)
322
+
323
+ World geometry, topology/material keys and normals are prepared once for camera
324
+ updates. Projected bounds prune sort candidates. Refittable spatial indices and
325
+ cached face frames reduce contact/local-update work. Opacity-only state is lazy;
326
+ host polyhedron style refreshes stay local. The legend uses cached visible
327
+ components. GPU ranges and derived geometry are validated, integer indices are
328
+ strict, unstable orientations are rejected atomically and huge finite occupancy
329
+ weights are normalized safely. Scene clear releases scene storage, shader-failure
330
+ cleanup is transactional, and ordinary close/show restores GPU resources.
331
+
332
+ See [release notes relative to GitHub 0.2.4](RELEASE_NOTES_0.2.5.md),
333
+ [transparency details](docs/hybrid-transparency.md),
334
+ [external-control example](examples/partial_updates.py), and
335
+ [validation commands](validation/README.md). Existing host calls/dependencies and
336
+ all 0.2.4 instancing/hatching features remain supported.