Drawing Commands¶
These methods are available on every Molvis instance,
regardless of host (script, notebook, or CDN-hosted page).
Scene¶
draw_frame(frame, style=None, atom_radius=None, bond_radius=None)¶
Draw a molecular frame, replacing the current scene content.
scene.draw_frame(frame)
scene.draw_frame(frame, style="spacefill")
scene.draw_frame(frame, style="ball_and_stick", atom_radius=0.3)
| Parameter | Type | Default | Description |
|---|---|---|---|
frame |
mp.Frame |
required | Frame to render |
style |
str \| None |
None |
"ball_and_stick", "spacefill", or "wireframe" |
atom_radius |
float \| None |
None |
Atom radius scale factor |
bond_radius |
float \| None |
None |
Bond radius scale factor |
draw_box(box)¶
Draw a simulation box wireframe.
draw_atoms(atoms, style=None)¶
Draw individual atoms (without bonds).
clear()¶
Clear all objects from the scene.
new_frame(clear=True)¶
Create an empty frame. If clear=True, clears the current scene.
Style¶
set_style(style=None, atom_radius=None, bond_radius=None)¶
Change the visual style without reloading the frame data.
| Parameter | Type | Default | Description |
|---|---|---|---|
style |
str \| None |
None |
"ball_and_stick", "spacefill", or "wireframe" |
atom_radius |
float \| None |
None |
Atom radius scale factor |
bond_radius |
float \| None |
None |
Bond radius scale factor |
set_theme(theme)¶
Switch the color theme.
| Value | Description |
|---|---|
"classic" |
CPK-based coloring |
"modern" |
Contemporary palette |
set_view_mode(mode)¶
Switch the interaction mode.
| Value | Description |
|---|---|
"view" |
Camera orbit / pan / zoom |
"select" |
Click to select atoms |
"edit" |
Add / delete atoms |
"manipulate" |
Transform selected groups |
"measure" |
Distance, angle, dihedral |
Pipeline¶
The modifier pipeline is the single source of truth for scene content:
every frame — whether loaded via the sidebar's Load File button or
pushed from Python with draw_frame / set_trajectory — flows through
a DataSourceModifier at the head, followed by user-added modifiers
(selection, hide, color, …). The GUI sidebar and these Python commands
manipulate the same pipeline, so toggling a modifier from Python is
indistinguishable from clicking it in the sidebar.
list_modifiers()¶
Snapshot the current pipeline, in execution order.
available_modifiers()¶
List every modifier type registered in the frontend's ModifierRegistry.
Use the name field with add_modifier.
add_modifier(name, *, parent_id=None, enabled=None)¶
Append a modifier to the pipeline.
scene.add_modifier("Hide Hydrogens")
sel = scene.add_modifier("Expression Select")
scene.add_modifier("Hide Selection", parent_id=sel.id)
Selection-sensitive modifiers must attach to a selection-producing
parent (via parent_id) or to an existing SelectModifier in the
pipeline.
remove_modifier(id) / clear_pipeline()¶
scene.remove_modifier(mod.id) # cascade-removes descendants
scene.clear_pipeline() # drop every modifier
reorder_modifier(id, new_index)¶
set_modifier_enabled(id, enabled) / set_modifier_parent(id, parent_id)¶
scene.set_modifier_enabled(mod.id, False)
scene.set_modifier_parent(mod.id, None) # detach
scene.set_modifier_parent(mod.id, selector.id) # reparent
Selection¶
get_selected()¶
Return the current selection state.
select_atom_by_id(ids)¶
Select atoms by their indices.
Export¶
snapshot()¶
Capture the current view as PNG bytes.
export_frame()¶
Read back the current frame data from the frontend.
Error handling¶
All commands communicate with the frontend via JSON-RPC. If the frontend rejects a command, Python raises MolvisRPCError: