Architecture#
Python layer:
MolSysView, loaders, and shape APIs send JSON-like messages to the frontend.Frontend: AnyWidget entry
js/src/index.tsinitializes Mol*, routes messages inmanagers/viewer-controller.ts, and builds shapes inshapes/.Shapes & tags: shape builders register Mol* state refs; tags allow selective clearing.
Data flow: Python → message → JS controller → Mol* state tree → renderer; visibility uses transparency over atom masks.
Generated artifacts:
viewer.js/.mapare produced fromjs/src/with esbuild; never edit them directly.Doc embeds: use
MolSysView.write_html(..., mode="lite")to export docs-light views andmolsysviewer.thirds.jupyter.load_html_in_notebookto embed them in docs notebooks.For a detailed architecture reference, see Architecture (full).
Developer-facing structure
molsysviewer/viewer.py: message queue, visibility masks, shape manager, exports.molsysviewer/shapes/: Python APIs; normalize inputs and send ops.molsysviewer/js/src/: Mol* plugin init, message routing, geometry builders (organized into managers/, shapes/, plugin/, messages/, index.ts).docs/: Sphinx site (pydata theme, MyST, notebooks off), static views under_static/views/.
Message flow (conceptual)
Python API call →
_sendbuilds a JSON-like message withop+options.JS controller (
viewer-controller.ts) handles theop, validates options, and callsadd*FromPythonhelpers.Mol* state tree is updated; refs are tracked per tag for selective clear.
Visibility updates are applied via transparency (hidden atoms become fully transparent).
WebGL boundary
MolSysViewer does not draw directly; Mol* owns WebGL. We prepare geometry/state; Mol* renders.
AnyWidget hosts the canvas; the Mol* plugin attaches to it and manages lifecycle.