Regions and layers#
This page documents regions, layers, tags, and visibility semantics. These concepts are user-visible and must remain stable.
Naming and concepts#
Region: a structural subset (Mol* component) identified by
tag(user-provided or auto). It storesselectionandatom_indices.Layer: a tag-based group for non-structural visuals (shapes/overlays).
If you do not pass a tag, MolSysViewer assigns an auto-tag (
region1,layer1, …).
Python API (sketch)#
view.new_region(selection, tag=None, representation=None, **repr_params) -> Regionview.new_layer(kind=None, tag=None, **meta) -> LayerPublic registries:
view.regions/view.layers(example:view.regions["set1"].hide()).Region:set_representation(...),hide()/show(),delete(), complements (new_complementary_region()).Layer:hide()/show(),delete(),set_tag()(and possiblymerge()in the future).Whole:
view.whole(set_representation,hide()/show()), not deletable and not retaggable.Complements:
new_region(..., complement_of_regions=["tagA", ...] | "all")computes complements in Python.
JS responsibilities#
Source of truth for Mol* refs:
regions:
tag -> { componentRef, reprRefs[], atomIndices[], selection, hidden }layers:
tag -> { refs, kind/meta }global reps:
globalReprs
Handlers: create/set/show/hide/delete region; same for layers; set/hide/show global; clear/reset/load cleans registries and notifies Python.
Acks to Python:
region_ack(includesatom_indicesandselection),layer_ack,registry_cleared.Shapes: are tagged and registered as layers via
tagIndex.
Visibility (global vs regions vs viewer)#
region.hide()/show(): affects only that region; thehiddenstate is remembered.viewer.show()must not re-enable hidden regions.whole.hide()/show(): affects only the baseline/global reps (auto/preset/cartoon fromload). It does not touch regions. If invoked before the firstshow(), it is remembered and applied once the structure is loaded.viewer.hide()/show()withselection="all": updates the atom mask and sendshide_global/show_global target=all. It respects hidden regions and re-hides the global reps if they were marked as hidden.
Reference flows
Hide global before first show
view = viewer.demo.tctim
view.whole.hide()
view.show() # regions may be created; global stays hidden
Hide one region and preserve it across hide/show
view = viewer.demo.tctim
r1 = view.new_region("chain_id == 'A'", representation="sticks")
r2 = view.new_region("chain_id == 'B'", representation="sticks")
r2.hide()
view.hide()
view.show() # r1 visible, r2 still hidden; global follows its flag
Hide everything and restore only what should be visible
view.hide() # hides global + regions + atom mask
view.show() # hidden regions stay hidden; global follows its state
Ideas#
Helpers:
get_region/get_layer/list_*; a lightweight inspector for regions/layers and visibility.Preserve global style across
load.JS handler for selection strings when
atom_indicesare missing.JS → Python events if reps are modified outside the Python-driven flow.
Representation coexistence modes:
replace/exclusiveto avoid overlaps.Complement validation when
atom_indicesare not yet known (acks).Sync the visibility mask with regions if the user called
hide()globally first.