Globals


Instance Methods

BCIF(bindata, ParserOptionsSpec)

Parameters

  • bindata — binary UInt8Array buffer or a base64 encoded string
  • ParserOptionsSpec

CDJSON(str: string, options: ParserOptionsSpec)

This parses the ChemDoodle json file format. Although this is registered
for the json file extension, other chemical json file formats exist that
this can not parse. Check which one you have and do not assume that
.json can be parsed

Parameters

CIF(str: string, options: ParserOptionsSpec)

Puts atoms specified in mmCIF fromat in str into atoms

Parameters

CUBE(str: string, options: ParserOptionsSpec)

Parameters

GRO( str: string, options: ParserOptionsSpec, ): Array.<Array.<AtomSpec>>

Parse a gro file from str and create atoms.
The optional box property contains orthorhombic box lengths in angstroms.

Parameters

Returns

MMTFparser(bindata, ParserOptionsSpec)

Parameters

  • bindata — binary UInt8Array buffer or a base64 encoded string
  • ParserOptionsSpec

MOL2(str: string, options: ParserOptionsSpec)

Parameters

PDB(str: string, options: ParserOptionsSpec)

Parse pdb file from str and create atoms if computeStruct is true will always perform secondary structure analysis,
otherwise only do analysis of SHEET/HELIX comments are missing

Parameters

  • str (string)
  • options (ParserOptionsSpec) — keepH (do not strip hydrogens), noSecondaryStructure,
    assignbonds (default true, calculate implicit bonds)
    (do not compute ss), altLoc (which alternate location to select, if present; '*' to load all)

PQR(str: string, options: ParserOptionsSpec)

Parse a pqr file from str and create atoms. A pqr file is assumed to be a whitespace delimited PDB with charge and radius fields.

Parameters

  • str (string)
  • options (ParserOptionsSpec) — noSecondaryStructure (do not compute ss)

PRMTOP(str: string, options: ParserOptionsSpec)

Parse a prmtop file from str and create atoms

Parameters

  • str (string)
  • options (ParserOptionsSpec) — noSecondaryStructure (do not compute ss)

SDF(str: string, options: ParserOptionsSpec)

Parameters

VASP(str: string, options: ParserOptionsSpec)

Parameters

XYZ(str: string, options: ParserOptionsSpec)

Read an XYZ file from str and return result

Parameters

addBond()

Add a bond between two atoms (bidirectional).

apply3DmolStyle()

Apply a 3DMOL_STYLE JSON block to atom bond styles and model data.

JSON format:
{"stick":{"radius":0.15},"bonds":{"1-5":{"color1":"red","color2":"blue"}}}

  • "bonds" maps "serial1-serial2" (1-based) to BondStyle properties,
    set on atom.bondStyles[] directly. Supported properties:

    • color1, color2: overall bond half-colors
    • dashedBondConfig: { solidColor, dashedColor } for fractional bond color overrides
    • dashedBondFlip: override which side gets the dashed line (boolean)
    • singleBond, radius, iswire
      When serials are given in reverse order, per-half color properties are swapped.
  • All other keys are AtomStyleSpec, stored on atoms.modelData for the frame.

assignPDBBonds(atomsarray: Array.<AtomSpec>)

Parameters

autoload(viewer?: GLViewer, callback?: function)

Create embedded viewers for elements with the viewer_3Dmoljs CSS class,
using their data attributes. Runs automatically when document.readyState
reaches "complete". Call after adding embedded-viewer elements dynamically;
each call processes all matching elements, including previously processed ones.
Loading remote data is asynchronous; use an element's data-callback attribute
to access its viewer after loading and initial styling.

Parameters

  • viewer (GLViewer, optional) — Existing viewer used by the render-test harness.
    Normally omit this argument to create a viewer for each element.
  • callback (function, optional) — Harness callback, called with each initialized viewer.
  • See:
    • @tutorial embeddable

base64ToArray(base64: string): Uint8Array

Decode base64 into bytes.

Parameters

  • base64 (string) — Base64 text without a data URI prefix.

Returns

  • Uint8Array — Decoded bytes.

conversionMatrix3( a: number, b: number, c: number, alpha: number, beta: number, gamma: number, ): Matrix3

Parameters

  • a (number)
  • b (number)
  • c (number)
  • alpha (number)
  • beta (number)
  • gamma (number)

Returns

copy()

Copy configuration objects without losing callbacks, colors or gradient instances.

createViewer( element: HTMLElement | Object | string, config?: ViewerSpec, ): GLViewer | undefined

Create and initialize an appropriate viewer at supplied HTML element using specification in config

Parameters

  • element (HTMLElement | Object | string) — Container element, jQuery object,
    or element ID without a leading "#". Give the container a nonzero width and height.
  • config (ViewerSpec, optional) — Viewer configuration

Returns

  • GLViewer | undefined — The viewer, or undefined if the container element is not found.

Throws

  • string — If viewer construction fails.

Example

CODE
var viewer = $3Dmol.createViewer(
     'gldiv', //id of div to create canvas in
     {
       defaultcolors: $3Dmol.elementColors.rasmol,
       backgroundColor: 'black'
     }
   );

createViewerGrid( element: HTMLElement | Object | string, config?: ViewerGridSpec, viewer_config?: ViewerSpec, ): Array.<Array.<GLViewer>> | undefined

Create a grid of viewers that share one WebGL canvas.
Access panels as viewers[row][column], with row zero at the top and column
zero at the left. Supply positive integer rows and cols in config.
A PNG captured from any panel includes the whole shared canvas.

Parameters

  • element (HTMLElement | Object | string) — Container element, jQuery object,
    or element ID without a leading "#".
  • config (ViewerGridSpec, optional) — grid configuration
  • viewer_config (ViewerSpec, optional) — Viewer specification to apply to all subviewers

Returns

  • Array.<Array.<GLViewer>> | undefined — A 2D array of viewers, or undefined if the container is not found.

Example

CODE
var viewers = $3Dmol.createViewerGrid(
     'gldiv', //id of div to create canvas in
     {
       rows: 2,
       cols: 2,
       control_all: true  //mouse controls all viewers
     },
     { backgroundColor: 'lightgrey' }
   );
   $3Dmol.get('data/1jpy.cif', function(data) {
     var viewer = viewers[0][0];
     viewer.addModel(data,'cif');
     viewer.setStyle({sphere:{}});
     viewer.zoomTo();
     viewer.render( );

     viewer = viewers[0][1];
     viewer.addModel(data,'cif');
     viewer.setStyle({stick:{}});
     viewer.zoomTo();
     viewer.render( );

     viewer = viewers[1][0];
     viewer.addModel(data,'cif');
     viewer.setStyle({cartoon:{color:'spectrum'}});
     viewer.zoomTo();
     viewer.render( );

     viewer = viewers[1][1];
     viewer.addModel(data,'cif');
     viewer.setStyle({cartoon:{colorscheme:'chain'}});
     viewer.zoomTo();
     viewer.render();


   });

decode()

Fixed point, delta, RLE, integer packing adopted from https://github.com/rcsb/mmtf-javascript/
by Alexander Rose alexander.rose@weirdbyte.de, MIT License, Copyright (c) 2016

decodeSceneValue()

Restore data classes from a snapshot using an explicit type allowlist.

disposeObjectResources()

Release resources owned by a render tree; clones may share those resources.

download( query: string, viewer: GLViewer, options: ParserOptionsSpec, callback?: function, ): GLModel | Promise.<GLModel> | undefined

Load a PDB/PubChem structure or URL into an existing viewer. Calls zoomTo()
and render() after loading succeeds. An empty model is added immediately,
including when validation or loading later fails. Use the Promise form when
the caller needs to distinguish success from failure.

Parameters

  • query (string) — Structure query prefixed with "pdb:", "bcif:", "cid:",
    or "url:". Without a prefix, four characters imply a PDB ID, a numeric value
    implies a PubChem CID, and other strings are treated as URLs. The legacy
    "mmtf:" prefix is redirected to BCIF. Cross-origin URLs must permit browser access.
  • viewer (GLViewer) — Viewer to receive the new model.
  • options (ParserOptionsSpec) — Options passed to the model's parser,
    plus the download options below. Pass {} for defaults.
    • options.format (string, optional, default: "\"bcif\"") — Format requested for a "pdb:" query.
      Failed BCIF requests fall back to text PDB. For "url:" queries the URL supplies
      the format; use get()/getbin() and addModel() to specify a format explicitly.
    • options.pdbUri (string, optional, default: "\"https://files.rcsb.org/view/\"") — Base URI for
      text PDB downloads and BCIF fallback, including its trailing slash.
  • callback (function, optional) — Called with the model after the asynchronous load attempt, including failures. On failure, the error is logged before calling the callback.

Returns

  • GLModel | Promise.<GLModel> | undefined — With a callback, returns the model immediately. Otherwise returns a Promise that resolves to the loaded model or rejects with the load error. Invalid PDB or PubChem identifiers display an alert and return undefined before starting the request or calling the callback.

Example

CODE
viewer.setBackgroundColor(0xffffffff);
       $3Dmol.download('pdb:2nbd',viewer,{onemol: true,multimodel: true},function(m) {
        m.setStyle({'cartoon':{colorscheme:{prop:'ss',map:$3Dmol.ssColors.Jmol}}});
       viewer.zoomTo();
       viewer.render(callback);
    });

encodeSceneValue()

Make a detached, JSON-safe copy of supported scene data.

extend()

Copy defined own properties from src1 onto obj1 and return obj1 (a shallow merge).

get(uri: string, callback?: function): Promise

Fetch data from URL

Parameters

  • uri (string) — URL to fetch.
  • callback (function, optional) — Called with the response text.

Returns

  • Promise — Resolves to the response text, or the callback return value when supplied. Rejects on request or callback failure.

getAtomProperty(atom: AtomSpec, prop: string): *

Read an atom property, first from atom.properties and then from the atom itself.

Parameters

  • atom (AtomSpec) — Atom to inspect.
  • prop (string) — Property name.

Returns

  • * — Property value, or null if neither location defines it.

getColorFromStyle(atom: AtomSpec, style: Object): Color

Return proper color for atom given style

Parameters

  • atom (AtomSpec)
  • style (Object) — Color options: color, colorscheme, or colorfunc.

Returns

getElement( element: HTMLElement | Object | string, ): HTMLElement | null

Resolve a viewer container.

Parameters

  • element (HTMLElement | Object | string) — Element, jQuery object, or element
    ID without a leading "#"; strings are not arbitrary CSS selectors.

Returns

  • HTMLElement | null — Container, or null when the ID is not found.

getExtent( atomlist: Array.<AtomSpec>, ignoreSymmetries?: boolean, ): Array.<Array.<number>>

Compute coordinate bounds and the arithmetic mean position of the supplied atoms.

Parameters

  • atomlist (Array.<AtomSpec>) — Atoms with finite x, y, and z coordinates.
  • ignoreSymmetries (boolean, optional, default: false) — Exclude transformed symmetry positions.

Returns

  • Array.<Array.<number>> — Minimum corner, maximum corner, and mean position, each as
    [x, y, z]. An empty atom list returns three [0, 0, 0] vectors.

getGradient()

Resolve a gradient description or preserve a custom gradient object.
Unknown names and non-gradient inputs warn and fall back to RWB over [-1, 1].

getPropertyRange( atomlist: Array.<AtomSpec>, prop: string, ): Array.<number>

Get the minimum and maximum values of an atom property.
Uses getAtomProperty, so entries in atom.properties take precedence
over same-named fields on the atom itself.

Parameters

  • atomlist (Array.<AtomSpec>) — Atoms to evaluate.
  • prop (string) — Numeric property name.

Returns

  • Array.<number> — [min, max]; [0, 0] when no finite range is available.

getbin( uri: string, callback?: function, request?: string, postdata?: string, ): Promise

Download binary data (e.g. a gzipped file) into an array buffer and provide
arraybuffer to callback.

Parameters

  • uri (string) — location of data
  • callback (function, optional) — Function to call with arraybuffer as argument.
  • request (string, optional) — Use "POST" to submit postdata; otherwise uses GET.
  • postdata (string, optional) — data for POST request

Returns

  • Promise — Resolves to the ArrayBuffer, or the callback return value when supplied. Rejects on request or callback failure.

objectSettings()

Portable UI object settings; core and UI bundles may have distinct Color classes.

parseSDProperties()

Parse SDF data items (property blocks) that follow M END.

Per the CTfile spec, each data item consists of:

  • A data header line starting with ">" containing a field name in < >
  • One or more data lines (up to 200 chars each per spec)
  • A blank line terminator

The record ends at the $$$$ delimiter.

Returns

  • offset past $$$$ (or end of lines if missing)

parseV3000( lines: Array.<string>, options: ParserOptionsSpec, ): Array.<!Array.<!Object>>

Parameters

Returns

  • Array.<!Array.<!Object>>

sameStyleValue()

Compare the values copied above, retaining identity for callbacks and class instances.

selectionSummary()

A readable description of the criteria, independent of the selection's name.

setSyncSurface(val: boolean)

Choose the calculation mode for subsequent molecular surfaces in all viewers.
Main-thread calculation can block interaction for large structures. This does
not change the completion contract of GLViewer.addSurface or wait for existing
surface jobs. Use addSurface's returned promise to wait for geometry.

Parameters

  • val (boolean) — True for main-thread calculation; false to use Web Workers.

snapshotGeometry()

Snapshot only populated geometry buffers, without WebGL resources or spare capacity.

specStringToObject(str: string | Object | null | undefined): *

Parse a style or selection from JSON or the compact syntax used by embedded
viewers and viewer URLs. JSON supports nested specifications. Compact syntax
has one level of nesting: semicolons separate fields, a colon introduces a
value, commas separate list items or property assignments, and = or ~ assigns
a nested property. A field without a value becomes an empty object.
For example, "chain:A;resi:1,2" selects a chain and residue list, and
"stick:radius=0.2,color=blue" describes a stick style.
Numeric and boolean scalar values are converted; comma-separated list items
remain strings. Use JSON for nested selections such as and, or, and within.

Parameters

  • str (string | Object | null | undefined) — Specification. Objects, null, and
    undefined pass through unchanged; "all" becomes an empty selection object.

Returns

  • * — Parsed specification.

splitGroup()

Remove only a recognized atom-group clause, leaving imported predicates intact.

Instance Fields

syncSurface: boolean

Whether molecular surface geometry is calculated on the main thread instead
of in Web Workers. Defaults to false. Set through setSyncSurface.

viewers

Contains a dictionary of embedded viewers created from HTML elements
with the viewer_3Dmoljs CSS class, indexed by element ID or by an automatically
assigned number when no ID is present. Viewers created by createViewer() are
not added to this dictionary. Destroying an embedded viewer removes its entry.

Enums

CAP

enumreadonly
GLDraw.ts

Enum for cylinder cap styles.

Properties

  • NONE
  • FLAT
  • ROUND

SurfaceType: number

enumreadonly
ProteinSurface4.ts

Surface types

Properties

  • VDW — van der Waals surface
  • MS — Molecular surface
  • SAS — Solvent accessible surface
  • SES — Solvent excluded surface

Other

OFFSETS

Parameters

Parsers

Structure parser registry, keyed by format names from FileFormats.
Most applications should use GLViewer.addModel or GLModel.addMolData, which
initialize model defaults and handle compressed input. Direct parsers return
arrays of atom arrays, with format-specific metadata attached to the result.
See ParserOptionsSpec for format-dependent options.

buildInfo

Build metadata, available as $3Dmol.buildInfo or an ES module named export.
Direct source imports without the webpack definitions report an unknown version.

builtinColorSchemes

built in color schemes
The user can pass these strings directly as the colorscheme

Properties

  • ssPyMol — pymol secondary structure
  • ssJmol — jmol secondary structure
  • Jmol — jmol element defaults
  • amino — amino acid coloring
  • shapely — amino acid coloring
  • nucleic — nucleic acid coloring
  • chain — color by chain
  • rasmol — rasmol default element coloring
  • default — default element coloring
  • greenCarbon — default element coloring with green carbon
  • cyanCarbon — default element coloring with cyan carbon
  • magentaCarbon — default element coloring with magenta carbon
  • purpleCarbon — default element coloring with purple carbon
  • whiteCarbon — default element coloring with white carbon
  • orangeCarbon — default element coloring with orange carbon
  • yellowCarbon — default element coloring with yellow carbon
  • blueCarbon — default element coloring with blue carbon
  • chainHetatm — color chains

Example

CODE
window.$3Dmol.download("pdb:4UAA",viewer,{},function(){
   viewer.setBackgroundColor(0xffffffff);
   var colorAsSnake = function(atom) {
     return atom.resi % 2 ? 'white': 'green'
   };
   viewer.setStyle( {chain:'A'}, { cartoon: {colorfunc: colorAsSnake }});
   viewer.setStyle( {chain:'B'}, { stick: {colorscheme: 'yellowCarbon'}});
   viewer.render();
 });

builtinGradients

built in gradient schemes
Use these names as the gradient property of a GradientSpec.

Properties

  • rwb — red/white/blue, supports setting a mid point for white
  • roygb — rainbow
  • sinebow — rainbow with better saturation properties
  • linear — linearly maps between provided colors

dic

Parse a lammps trajectory file from str and create atoms

elementColors

Preset element coloring - from individual element colors to entire mappings (e.g. 'elementColors.Jmol' colors atoms with Jmol stylings)

ssColors

Preset secondary structure color scheme

uiStyles

Scoped styles for the optional viewer UI. No host-page CSS is required.