Skip to content

Encode structure viewer representation styles - #768

Open
cpignedoli wants to merge 4 commits into
fix/structure-viewer-representation-style-idfrom
feature/encoded-representation-style-ids
Open

Encode structure viewer representation styles#768
cpignedoli wants to merge 4 commits into
fix/structure-viewer-representation-style-idfrom
feature/encoded-representation-style-ids

Conversation

@cpignedoli

@cpignedoli cpignedoli commented Jun 24, 2026

Copy link
Copy Markdown
Member

Summary

This PR adds an extxyz-safe naming convention for structure-viewer representation arrays.

New representation arrays now encode their display style in the array name, for example:

_aiidalab_viewer_representation_spacefill_r3_element_<token>
_aiidalab_viewer_representation_ballstick_r4_red_<token>

The existing per-atom membership values remain unchanged (1 for included atoms, -1 for excluded atoms).

Backward compatibility

Old opaque representation names, such as _aiidalab_viewer_representation_nQ34..., are still accepted. If a name cannot be parsed, the viewer keeps the historical default style settings and does not rename it just by loading the structure.

Details

  • Adds encode_representation_style_id() for generating safe, style-aware representation array names.
  • Adds parse_representation_style_id() for restoring type, size, and color from encoded names.
  • Keeps a uniqueness token so two atom groups can share the same visual style without colliding.
  • Refreshes encoded array names on Apply when the representation type, size, or color has changed.
  • Imports multiple representation arrays as a batch, so loading one representation no longer prunes other representation arrays that have not been imported yet.

This PR is stacked on #766, which fixes importing representation arrays that are present in loaded structures.

Representation PR chain

Validation

  • python -m pytest tests/test_viewers.py::test_structure_data_viewer_representation tests/test_viewers.py::test_structure_data_viewer_imports_unknown_representation_array tests/test_viewers.py::test_structure_data_viewer_imports_encoded_representation_array tests/test_viewers.py::test_structure_data_viewer_imports_multiple_encoded_representation_arrays tests/test_viewers.py::test_structure_data_viewer_updates_encoded_representation_array_name
  • python -m pytest tests/test_viewers.py

Implemented with Codex.

@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.40%. Comparing base (42ac05e) to head (0ea73c4).
⚠️ Report is 1 commits behind head on fix/structure-viewer-representation-style-id.

Additional details and impacted files
@@                               Coverage Diff                                @@
##           fix/structure-viewer-representation-style-id     #768      +/-   ##
================================================================================
+ Coverage                                         85.03%   85.40%   +0.37%     
================================================================================
  Files                                                18       18              
  Lines                                              3335     3379      +44     
================================================================================
+ Hits                                               2836     2886      +50     
+ Misses                                              499      493       -6     
Flag Coverage Δ
python-3.12 85.38% <100.00%> (+0.43%) ⬆️
python-3.9 85.39% <100.00%> (+0.37%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cpignedoli
cpignedoli requested a review from yakutovicha June 25, 2026 08:38
@cpignedoli
cpignedoli marked this pull request as ready for review June 25, 2026 08:38
@cpignedoli
cpignedoli marked this pull request as draft June 25, 2026 08:45
@cpignedoli
cpignedoli marked this pull request as ready for review June 25, 2026 09:08
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