3Dmol molecular rendering
The workspace package @donkeyclip/motorcortex-3dmol renders molecular structures with 3Dmol.js in a browser with WebGL.
It supports inline structure data, a URL, or structured atom records, along with named atom selections, surfaces, labels, and multi-frame models.
import { loadPlugin } from "@donkeyclip/motorcortex";
import definition from "@donkeyclip/motorcortex-3dmol";
const Mol3D = loadPlugin(definition);
Mol3D.Clip hosts the viewer. RepresentationEffect, SelectionStyleEffect, StyleEffect, CameraEffect, SurfaceEffect, LabelEffect, and FrameEffect animate it on the MotorCortex timeline.
Structured atoms render as spheres by default. The plugin passes them to 3Dmol's GLModel.addAtoms method and does not infer bonds or secondary structure.
Set representation: "ribbon" to show cartoons from trusted source backbone and residue fields.
RepresentationEffect authors model-level ribbon, atoms, sticks, ball_and_stick, and surface views on the timeline.
Its representation attribute contains a mode and exact model-local indices. An empty index list targets the whole model.
Unselected atoms retain cartoon context. Sticks use supplied bonds without inferring missing connections, and unconnected atoms remain spheres.
Surfaces are derived van der Waals envelopes, not deposited scientific measurements.
Protein anchors carry properties.proteinBackbone: true. Standard DNA and RNA anchors carry properties.nucleicCartoon: true.
Supplied secondary-structure assignments determine helix and sheet shapes. Unassigned regions remain unassigned.
Multiple polymer chains use deterministic source-chain colours. A lone protein chain uses teal for helices and amber for sheets.
Multi-atom non-polymer components other than water use a separate ligand colour and source-component legend entry.
Explicit authored colours take precedence. Ungrouped ligands retain their automatic colour when custom polymer groups are active.
SelectionStyleEffect accepts labelled baseColors.groups independently of its exact selectionStyle highlight.
The highlight's optional label identifies the highlighted atoms in the colour key. Older effects without a label keep Highlighted.
Empty groups restore automatic colours. Partly coloured residues expose only their coloured member atoms as spheres.
Ribbon mode keeps ligands, ions, and exact highlighted members visible as spheres.
A highlight of whole residues, such as a whole chain, colours runs of three or more consecutive residues on the cartoon instead of adding spheres.
A highlight that covers any residue only partly, such as contact atoms, stays exact spheres. Source water is hidden by default,
except explicitly coloured or highlighted atoms. Atoms mode shows the full accepted inventory.
The display event supplies the evaluated legend and water visibility state for local controls.
Cartoons follow authored model visibility through seeking.
If atoms carry properties.secondaryStructureUnavailable: true, protein residues stay atoms and the display event
reports that source annotations could not be used. Independently usable nucleic cartoons remain available.
The Experience player shows a warning without disabling contact analysis.
Set interactive: true to enable rotation and zoom. Local exploration does not change authored camera endpoints.
resetMol3DView restores the authored camera. setMol3DRepresentation changes the local mode without moving the camera.
Local modes are ribbon, atoms, surface, sticks, and ball_and_stick. Stick modes require source bonds.
Choose original to restore the authored representation at the playhead, including mixed selection views, without seeking.
In atoms mode, partial highlights reduce and lighten surrounding spheres without hiding atoms or changing their coordinates.
Unhighlighted ligand atoms keep their base colours and scales.
Set framing: "context" at the root of a CameraEffect's attributes to frame a selection with nearby accepted non-water atoms.
Explicit camera position, zoom and rotation still take precedence. Effects without this directive keep their previous framing.
Targeted camera effects preserve the structure's depth clipping range. Highlight changes do not move the camera.
The highlight selection and label persist across ribbon, atoms, sticks, ball-and-stick, and surface views.
Applying a highlight before or after changing representation selects the same atoms. Replacement, clearing, and seeking update the active view without leaving the previous highlight behind.
Selected atom colours apply to spheres, supplied bond endpoints, and derived surfaces. Ribbon highlights keep the whole-residue and exact-atom rules above.
During a partial highlight, surrounding cartoons, bonds, and derived surfaces transition to half their authored opacity.
Selected spheres and whole highlighted cartoon runs retain the model's authored opacity. Bond views show a sphere at every selected atom because 3Dmol shares stick opacity across a model.
Surface view shows selected spheres or whole-residue cartoons inside the translucent surface.
Clearing restores the current base colours, scales, and authored opacity. Highlighting the whole model leaves context opacity unchanged.
Seeking from a partial highlight to a whole-model highlight or a cleared state also restores the captured sphere scales.
These display changes preserve the camera, atom coordinates, bonds, and exact selection membership.
The package README documents attributes, selectors, examples, and local demo commands.
Scientific contact analysis stays in the Experience molecule toolkit.
The workspace patches 3Dmol's main and ESM builds to reject callback strings instead of evaluating them. The callback and CSP reference describes the patch's scope and browser checks.