StateManager

Source: state.ts

Owns UI appearance layers without taking ownership of the rest of the scene.
Each enabled selection replaces the styles on its atoms, in list order; its
own styles are additive. Disabling/removing a layer restores earlier layers
or their underlying atom styles. Programmatic style changes on unaffected atoms
become their latest baseline; UI layers retain priority on atoms they restyle.
Coordinates, callbacks and labels are preserved.

Available from the optional 3Dmol.ui bundle, loaded after the core browser
bundle. Construction attaches controls and sets viewer.ui to this manager,
replacing any previous manager. Use StateManager#refresh after direct
model changes and StateManager#destroy to detach the controls.


Constructor

new StateManager(): StateManager

Instance Methods

addShape(spec: any, name): string

Add an editable annotation shape. Coordinates are in molecular angstroms.

Parameters

  • spec (any)
  • name

Returns

  • string

addSurface( type: number, style: SurfaceStyleSpec, spec: AtomSelectionSpec, name, calculationSpec: AtomSelectionSpec, ): Promise.<string>

Calculate with all calculationSpec atoms, showing only the surface for spec.

Parameters

Returns

  • Promise.<string>

addVolume( data: string | ArrayBuffer, format: string, spec: IsoSurfaceSpec, name, ): string

Parse a scalar grid once, retaining it for subsequent contour edits.

Parameters

  • data (string | ArrayBuffer)
  • format (string)
  • spec (IsoSurfaceSpec)
  • name

Returns

  • string

batch(callback: function): void

Apply related synchronous layer edits before rendering and notifying controls.

Parameters

  • callback (function)

Returns

  • void

createSelectionAndStyle( spec: AtomSelectionSpec, style: AtomStyleSpec, ): string

Import an appearance from an embedding's data-select/data-style options.

Parameters

Returns

  • string

destroy(): void

Detach controls, remove labels owned by UI selections, and release subscribers.
Leaves the viewer, models, styles, and completed surfaces in place. Pending
UI-created surfaces are discarded when their calculation finishes.
Safe to call repeatedly. Use GLViewer.destroy() to dispose the entire viewer.

Returns

  • void

exportObjects()

Portable source settings for editable objects in a viewer URL.

getViewSettings(): UIViewSettings

Application-readable appearance settings maintained by the view controls.

Returns

  • UIViewSettings

loadSurface( type: string | number, spec: AtomSelectionSpec, style: SurfaceStyleSpec, surfaceId: number, calculationSpec?: AtomSelectionSpec, ): string

Register a surface already created by autoload or an embedding.

Parameters

Returns

  • string

refresh(): void

Notify controls after models or coordinates are changed by application code.

Returns

  • void

registerSurface(entry: UISurface, surface: Surface)

Bind an entry to its current surface object, since numeric IDs can be reused.

Parameters

  • entry (UISurface) — UI entry that owns the surface.
  • surface (Surface) — Surface object returned by GLViewer.getSurface.

removeModel(model: GLModel): void

Remove model-dependent UI entries before the viewer can reuse its model ID.

Parameters

Returns

  • void

renameSelection(id: string, name: string): string

Rename a selection without changing its atom or representation settings.

Parameters

  • id (string)
  • name (string)

Returns

  • string

restoreObjects(): void

Restore data-only object settings without evaluating callback source.

Parameters

Returns

  • void

setControls(options: UIControlOptions): void

Enable the edit dialog and trajectory controls independently.

Parameters

Returns

  • void

setResidueLabels( id: string, enabled: boolean, style?: LabelSpec, ): void

Toggle residue labels owned by this selection, leaving other labels alone.

Parameters

  • id (string)
  • enabled (boolean)
  • style (LabelSpec, optional)

Returns

  • void

setSelectionAdditive(id: string, additive: boolean): void

Choose whether this layer replaces or adds to earlier representations.

Parameters

  • id (string)
  • additive (boolean)

Returns

  • void

setSelectionVisible(id: string, visible: boolean): void

One visibility control governs every representation and label in a selection.

Parameters

  • id (string)
  • visible (boolean)

Returns

  • void

setViewSettings(patch: Partial.<UIViewSettings>): void

Apply view settings and keep the corresponding UI controls in sync.

Parameters

  • patch (Partial.<UIViewSettings>)

Returns

  • void

subscribe(): function

Subscribe to state refreshes; returns a function that removes the subscription.

Returns

  • function

updateSurface(id: string, patch: SurfaceStyleSpec): void

Change colors or material settings without recomputing surface geometry.

Parameters

Returns

  • void