moleculekit.viewer.molstar.scene module#
The rule that decides what a Mol* scene looks like, as plain data.
Both the interactive viewer and the headless renderer consume the dict this module produces, so they cannot drift: one decides, one applies. MolViewSpec is one possible encoding of the same description (see mvs.py) and is used by the notebook viewer and the docs theme, which cannot reach the shared bundle.
The vocabulary is MolViewSpec’s: selector names, representation type names and Mol* colour theme names are spelled exactly as MVS spells them, so translating in either direction is mechanical.
- moleculekit.viewer.molstar.scene.LABEL_STYLE_KEYS = ('border_width', 'border_color', 'bg_color', 'bg_opacity', 'bg_margin', 'offset_x', 'offset_y', 'offset_z')#
Cosmetic keys a
label_stylemay carry, and the label dict keys they become. Anything else is a typo, and a typo that draws a default-looking label is worse than one that says so.
- moleculekit.viewer.molstar.scene.build_scene(mol, reps=None, *, ball_and_stick_sel=None, highlight_bonds=None, focus_sel=None, rotate=None, zoom=None, background_color=None, fog=None, clip=None)#
Describe the scene for
molas a plain dict.When
repsis empty a cartoon is used for the polymer ifmolhas at leastMIN_CARTOON_RESIDUESstandard polymer residues, with ligands, ions, water, branched entities and non-standard residues as ball-and-stick, and ball-and-stick throughout otherwise. Whenrepsis non-empty those representations are the whole scene, matching how the VMD and NGL backends treatmol.reps.- Parameters:
mol (
Molecule) – The molecule whose topology and coordinates drive the scene. The frame used for label and tube positions ismol.frame.reps (
listorNone, optional) – Representations to render: normally the ones held inmol.reps, together with any one-off representation added byview()’ssel,styleandcolorarguments. An empty list or None gives the automatic scene.ball_and_stick_sel (
str|ndarray|None) – An extra atom selection to additionally draw as ball-and-stick. Ignored when it matches no atoms.highlight_bonds (
list[tuple[str,str]] |None) – Pairs of atom selections, each of which must pick exactly one atom. An orange tube is drawn between the two atoms of each pair.focus_sel (
str|ndarray|None) – An atom selection the camera frames on. Ignored when it matches no atoms.rotate (
str|tuple[float,float,float] |None) – Camera orientation, as a preset name or(rx, ry, rz)in degrees.zoom (
float|None) – Camera tightness. Larger values move the camera closer.background_color (
str|None) – Canvas background as an SVG colour name or hex string.fog (
float|None) – Depth cueing strength, from 0 for none to 100 for the strongest. Fog fades distant geometry into the background colour. None leaves Mol*’s own strength.clip (
float|None) – Half-thickness in Angstrom of the slab drawn around what the camera frames. Geometry nearer to or further from the camera than this is cut away. None draws the whole structure.
- Returns:
scene – The scene description, with
componentsalways present andlabels,tubes,cameraandcanvaspresent when they carry anything.- Return type:
- Raises:
ValueError – If every representation selection matches no atoms, if a
highlight_bondsselection does not pick exactly one atom, ifrotatenames no known orientation preset, iffogfalls outside 0 to 100, or ifclipis not positive.
- moleculekit.viewer.molstar.scene.default_representations(mol)#
The automatic scene written as representations any viewer can draw.
The automatic scene selects with Mol*’s builtin classifiers, which VMD and NGL have no equivalent of, so the split here is made with atom selection strings instead. It is a faithful starting point rather than a mirror: a residue moleculekit calls protein but that is spelled differently from the names in
STANDARD_POLYMER_RESNAMESlands in the cartoon here and in ball-and-stick there.- Parameters:
mol (
moleculekit.molecule.Molecule) – The molecule the scene would be built for.- Returns:
reps –
(sel, style, color)triples in drawing order.- Return type:
- moleculekit.viewer.molstar.scene.focus_sphere(mols, focus_sel=None)#
The sphere the camera should frame, across every object in the scene.
With one molecule the browser can work this out from the selected atoms itself, but a selection spanning several structures cannot be expressed as one set of atom indices, so it is computed here from the coordinates.
- Parameters:
mols (
list) – The molecules in the scene. The frame used is each molecule’s ownmol.frame.focus_sel (
strornumpy.ndarrayorNone, optional) – Atom selection to frame. None frames everything.
- Returns:
- moleculekit.viewer.molstar.scene.rotation_to_direction_up(rotate)#
Resolve a rotation into the MVS
directionandupvectors.- Parameters:
rotate (
strortupleoffloatorNone) – A preset name fromORIENTATION_PRESETS, a tuple of(rx, ry, rz)rotations in degrees applied about the x, y and z axes in that order, or None for the default view.- Returns:
- Raises:
ValueError – If
rotateis a string that names no known preset.