moleculekit.viewer.molstar.inline module#

Inline (server-less) Mol* viewer for Jupyter notebooks. Emits an <iframe srcdoc> that loads Mol* from a CDN and renders the molecule entirely from data inlined into the cell output.

class moleculekit.viewer.molstar.inline.MolstarInlineView(*, height, mvsj=None, payload=None)#

Bases: object

Notebook cell output that renders a Mol* viewer inline.

Its _repr_html_ returns an <iframe srcdoc> that loads Mol* from a CDN and renders the inlined scene/data with no running server. Construct it with either a MolViewSpec mvsj string (single-frame path) or a payload dict (multi-frame trajectory path); exactly one is used.

moleculekit.viewer.molstar.inline.build_inline_view(mol, scene, *, height=420)#

Build a MolstarInlineView for mol.

A single-frame molecule takes the MVS path (custom representations from scene are applied); a multi-frame molecule takes the trajectory path.

Parameters:
  • mol (Molecule) – The molecule to render.

  • scene (dict) – Scene description with a representations list (as produced for the viewer). Used only on the single-frame path.

  • height (int) – Height of the rendered iframe in pixels. Defaults to DEFAULT_HEIGHT.

Returns:

view – A notebook cell output rendering the inline viewer.

Return type:

MolstarInlineView

moleculekit.viewer.molstar.inline.coords_to_dcd_bytes(mol)#

Encode all frames of mol.coords (Angstrom) into a CHARMM/NAMD DCD byte string in memory. Lossless float32, no unit cell, no temp file.

Parameters:

mol (Molecule) – The molecule whose coordinate frames are encoded.

Returns:

dcd – The in-memory DCD-format byte string for all frames of mol.

Return type:

bytes

moleculekit.viewer.molstar.inline.running_in_notebook()#

True only inside a Jupyter/IPython kernel (ZMQInteractiveShell).

Terminal IPython and plain Python return False, so view() falls back to the server there.

Returns:

in_notebook – True when running inside a Jupyter/IPython kernel, otherwise False.

Return type:

bool