Skip to content

PyMOL plugin: edit only the targeted object, and align console commands with the panel - #22

Open
AtharvaTilewale wants to merge 4 commits into
RosettaCommons:mainfrom
AtharvaTilewale:fix/pymol-object-targeting
Open

AtharvaTilewale wants to merge 4 commits into
RosettaCommons:mainfrom
AtharvaTilewale:fix/pymol-object-targeting

Conversation

@AtharvaTilewale

Copy link
Copy Markdown
Contributor

Builds on #20. The first commit here is #20 (CI fix); please review the commits after it. GitHub will drop it from this diff once #20 merges.

What this fixes

Edits could land on the wrong object. selection_to_indices mapped cmd.get_model(selection) atoms onto one object's index map by (chain, res_id, ins_code, atom_name). With two structures loaded, atoms selected in one were applied to the other. Reproduced: two copies of motif_scaffolding.cif, 3 atoms selected in objB, aw_delete with objA active → 3 atoms deleted from objA.

  • selection_to_indices takes the object it edits and evaluates (sel) and model <obj>. Every plugin caller passes it: panel delete and insert, charge, chain and bond wizards, editors and aw_* commands.
  • _selection_to_indices_for_active, which restricted to STATE.active and then fell back to the unrestricted selection, is removed.
  • The repro above now deletes nothing and prints selection 'sele' matched no atoms in 'objA'.

Other fixes

  • Console parity.
    • aw_load always used the rcsb preset, which discards saved annotations: 0 of 105 sequence-conditioned atoms kept on inverse_folding.cif. It now infers the preset like the Load dialog.
    • aw_insert_segment anchored an after insertion on the first selected atom; the panel uses the last.
    • aw_save now shares the GUI save path through a new Qt-free saving.py (chain_disambiguation, pre-save hooks, issue reporting), so homo-oligomer saves work. panel.register_pre_save_hook is re-exported, so providers are unchanged.
  • Load/combine into an existing name used to replace STATE before PyMOL. It now loads first and restores the previous structure on failure. A fresh load gets a fresh undo history.
  • Illegal object names are converted with cmd.get_legal_name instead of leaving a ghost entry in STATE. For example, first becomes first_.
  • Stale picks. Reset Res ID, chain edits and protonate now call STATE.set_array, which bumps the version, so atoms picked before the edit are rejected.
  • Deleted objects are forgotten rather than resurrected on the next sync. Version counters stay monotonic when a name is reused.
  • Bond/pair picking uses atom selection mode while picking and rejects a multi-atom sele. Previously it took the residue's first atom (N).
  • A missing sele shows the existing No selection warning instead of raising CmdException out of a Qt slot.
  • Test collection. The plugin test package ignores itself when PyMOL is missing. Its module-level importorskip ended the entire pytest session during collection.

Validation

Design choices to check

  • The new obj_name argument to selection_to_indices is optional, so existing tests that pass already-qualified selections work unchanged.
  • Loading into an existing name deletes any PyMOL object with that name first, including one the user loaded with plain cmd.load.
  • If the wizard window is closed mid-pick, mouse_selection_mode is not restored. This is the same lifetime gap the timer already has.

Copilot AI balanced review requested due to automatic review settings October 22, 2026 08:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved issues remain in shared picker-mode coordination, transactional restoration, assembly parity, deleted-object undo handling, and PyMOL import-collection guarding.

4 open issues

Review effort: Lite

Comment thread packages/pymol-plugin/tests/conftest.py Resolved
AtharvaTilewale added a commit to AtharvaTilewale/atomworks-studio that referenced this pull request Oct 22, 2026
- bridge.py: make _replace_pymol_object transactional for untracked objects
  (rename-load-delete) so a failed replacement restores an object the user
  loaded directly with cmd.load, not just plugin-tracked objects.
- commands.py: aw_load now uses build_load_config's default assembly ('1'),
  matching the GUI Load dialog, instead of assembly='first'.
- state.py: pop_snapshot refuses to resurrect an object deleted directly in
  PyMOL, mirroring get_synced_array's forget-on-delete behaviour.
- tests/conftest.py: guard the real 'import pymol' (not just find_spec) in
  try/except, setting collect_ignore_glob on any import failure.
- tests/test_review_fixes.py: add regression tests for each fix.
@AtharvaTilewale

Copy link
Copy Markdown
Contributor Author

Thanks — all four points addressed in the latest commit:

  • Untracked object replacement: loading into an existing name now renames the pre-existing PyMOL object to a backup, loads, and only deletes the backup on success (restoring it on failure), so an object loaded directly with cmd.load is no longer destroyed by a failed replacement.
  • Assembly parity: aw_load now uses build_load_config's default assembly ('1'), matching the Load dialog, instead of 'first'.
  • Undo after external deletion: pop_snapshot checks object existence and refuses to resurrect an object deleted directly in PyMOL.
  • conftest guard: it now guards the actual import pymol in try/except and sets collect_ignore_glob on failure, so a present-but-unimportable PyMOL no longer aborts collection.

Four regression tests, each failing before and passing after.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved moderate findings remain in state lifecycle handling, synchronization callers, and test-collection exception filtering.

1 open issue
4 resolved since last review

Review effort: Lite

Comment thread packages/pymol-plugin/tests/conftest.py Resolved
AtharvaTilewale added a commit to AtharvaTilewale/atomworks-studio that referenced this pull request Oct 22, 2026
- bridge.py: make _replace_pymol_object transactional for untracked objects
  (rename-load-delete) so a failed replacement restores an object the user
  loaded directly with cmd.load, not just plugin-tracked objects.
- commands.py: aw_load now uses build_load_config's default assembly ('1'),
  matching the GUI Load dialog, instead of assembly='first'.
- state.py: pop_snapshot refuses to resurrect an object deleted directly in
  PyMOL, mirroring get_synced_array's forget-on-delete behaviour.
- tests/conftest.py: guard the real 'import pymol' (not just find_spec) in
  try/except, setting collect_ignore_glob on any import failure.
- tests/test_review_fixes.py: add regression tests for each fix.
@AtharvaTilewale
AtharvaTilewale force-pushed the fix/pymol-object-targeting branch from 37d2459 to f2e87c8 Compare October 22, 2026 10:17
AtharvaTilewale added a commit to AtharvaTilewale/atomworks-studio that referenced this pull request Oct 22, 2026
Addresses the second review on RosettaCommons#22: the conftest caught every Exception, so a
regression in finish_launching() or in the plugin's own imports would quietly
ignore the whole PyMOL test package and give a false-green run. The guard now
covers only the dependency check (import pymol, from pymol import cmd) and only
the errors it raises (ImportError, OSError). Launch failures and plugin import
errors propagate and fail collection. Tests cover both kinds of unusable PyMOL
and both kinds of regression.
- aw_load always used the rcsb preset, which silently discards saved
  annotations (inverse_folding.cif: 0 of 105 sequence-conditioned atoms kept).
  It now infers the preset like the Load dialog.
- aw_insert_segment anchored an 'after' insertion on the first selected atom;
  the panel uses the last.
- The plugin test package now ignores itself when PyMOL is missing. Its
  module-level importorskip ended the whole pytest session during collection.
- selection_to_indices takes the target object and restricts the selection to
  it; every panel, wizard, editor and aw_* caller passes the object it edits,
  so atoms of another loaded object with the same identity keys are no longer
  mapped into the active document (F05). aw_delete/aw_insert_segment restrict
  to the target object and no longer fall back to the unrestricted selection
  (F06). A missing selection returns [] so buttons show "No selection" instead
  of raising CmdException (F32).
- load_structure and combine_visible load into PyMOL first (deleting any
  existing object of that name) and commit STATE only on success; a fresh load
  gets a new document and undo history (F07). Object names are converted with
  cmd.get_legal_name, so no ghost object is tracked (F14).
- Reset Res ID, chain assignment and protonation go through STATE.set_array so
  the structure version is bumped and stale picked keys are rejected (F15).
- aw_save uses the same validation, pre-save hooks and chain_iid writer as the
  GUI via a new Qt-free saving module (F16).
- Bond and pair atom picking switches PyMOL to atom selection mode while
  picking and rejects multi-atom or other-object selections (F18).
- An object deleted in PyMOL is forgotten instead of being reloaded (F22).
- bridge.py: make _replace_pymol_object transactional for untracked objects
  (rename-load-delete) so a failed replacement restores an object the user
  loaded directly with cmd.load, not just plugin-tracked objects.
- commands.py: aw_load now uses build_load_config's default assembly ('1'),
  matching the GUI Load dialog, instead of assembly='first'.
- state.py: pop_snapshot refuses to resurrect an object deleted directly in
  PyMOL, mirroring get_synced_array's forget-on-delete behaviour.
- tests/conftest.py: guard the real 'import pymol' (not just find_spec) in
  try/except, setting collect_ignore_glob on any import failure.
- tests/test_review_fixes.py: add regression tests for each fix.
Addresses the second review on RosettaCommons#22: the conftest caught every Exception, so a
regression in finish_launching() or in the plugin's own imports would quietly
ignore the whole PyMOL test package and give a false-green run. The guard now
covers only the dependency check (import pymol, from pymol import cmd) and only
the errors it raises (ImportError, OSError). Launch failures and plugin import
errors propagate and fail collection. Tests cover both kinds of unusable PyMOL
and both kinds of regression.
@AtharvaTilewale
AtharvaTilewale force-pushed the fix/pymol-object-targeting branch from f2e87c8 to df3ea24 Compare November 21, 2026 11:47
@AtharvaTilewale

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (d7b78e4, 0.0.12). The earlier red CI was GitHub expiring the Oct 22 runs after 30 days awaiting approval; no job had run. CI on the rebased branch is green. The only failing job is the non-blocking integration acceptance suite, which fails the same single check on main ("a plain mmCIF opens as an entry does"), 36/37 in both.

No conflicts; 23 of the 27 new tests fail against main's plugin code and pass here.

This branch has not been deployed

No deployments
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