Namespace: $3Dmol

$3Dmol

All of the functionality of $3Dmol.js is contained within the
$3Dmol global namespace

Classes

GLModel
GLShape
GLShape
GLViewer
Label
VolumeData

Namespaces

GLDraw

Members

<static> builtinColorSchemes

Properties:
Name Type Description
built

in color schemes
The user can pass all of these values directly as the colorscheme and they will use the respective colorscheme

<static, readonly> CAP :number

Enum for cylinder cap styles.

Type:
  • number
Properties:
Name Type Default Description
NONE number 0
FLAT number 1
ROUND number 2

<static> elementColors

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

<static> Parsers

$3Dmol.Parsers stores functions for parsing molecular data. They all take a string of molecular data
and options. The default behavior is to only read the first model in the case of multimodel files, and
all parsers return a list of atom list(s)

$3Dmol.Parsers. corresponds to the parsers for files with extension ext

<static> ssColors

Preset secondary structure color scheme

<static> SurfaceType :number

$3Dmol surface types

Type:
  • number
Properties:
Name Type Default Description
VDW number 1
MS number 2
SAS number 3
SES number 4

<static> syncSurface :boolean

Render surface synchronously if true

Type:
  • boolean

<static> viewers

Contains a dictionary of embedded viewers created from HTML elements
with a the viewer_3Dmoljs css class indexed by their id (or numerically
if they do not have an id).

Methods

<static> base64ToArray(base64)

Convert a base64 encoded string to a Uint8Array

Parameters:
Name Type Description
base64 string

encoded string

<static> createViewer(element, config) → {$3Dmol.GLViewer}

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

Parameters:
Name Type Description
element Object | string

Either HTML element or string identifier

config ViewerSpec

Viewer specification

Returns:

GLViewer, null if unable to instantiate WebGL

Type
$3Dmol.GLViewer
Example
1
2
3
4
5
6
7
8
var viewer = $3Dmol.createViewer(
     'gldiv', //id of div to create canvas in
     {
       defaultcolors: $3Dmol.elementColors.rasmol,
       backgroundColor: 'black'
     }
   );
                       

<static> createViewerGrid(element, grid, config)

Create and initialize an appropriate a grid of viewers that share a WebGL canvas

Parameters:
Name Type Description
element Object | string

Either HTML element or string identifier

grid GridSpec

configuration

config ViewerGridSpec

Viewer specification to apply to all subviewers

Returns:

[[$3Dmol.GLViewer]] 2D array of GLViewers

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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' }
   );
   $.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();
     
     
   });

<static> download(query, viewer, options, callback) → {$3Dmol.GLModel}

Load a PDB/PubChem structure into existing viewer. Automatically calls 'zoomTo' and 'render' on viewer after loading model

Parameters:
Name Type Description
query string

String specifying pdb or pubchem id; must be prefaced with "pdb: " or "cid: ", respectively

viewer $3Dmol.GLViewer

Add new model to existing viewer

options Object

Specify additional options
format: file format to download, if multiple are available, default format is pdb
pdbUri: URI to retrieve PDB files, default URI is http://www.rcsb.org/pdb/files/

callback function

Function to call with model as argument after data is loaded.

Returns:

GLModel, Promise if callback is not provided

Type
$3Dmol.GLModel
Example
1
2
3
4
5
6
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);
    });

<static> getbin(uri, callback, request) → {Promise}

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

Parameters:
Name Type Description
uri string

location of data

callback function

Function to call with arraybuffer as argument.

request string

type of request

Returns:
Type
Promise

<static> getColorFromStyle(atom, style) → {$3Dmol.Color}

Return proper color for atom given style

Parameters:
Name Type Description
atom AtomSpec
style AtomStyle
Returns:
Type
$3Dmol.Color

<static> getExtent(atomlist) → {Array}

computes the bounding box around the provided atoms

Parameters:
Name Type Description
atomlist Array.<AtomSpec>
Returns:
Type
Array

<static> mergeGeos(geometry, mesh) → {undefined}

Parameters:
Name Type Description
geometry $3Dmol.Geometry
mesh $3Dmol.Mesh
Returns:
Type
undefined

<static> specStringToObject((String)) → {Object}

Parse a string that represents a style or atom selection and convert it
into an object. The goal is to make it easier to write out these specifications
without resorting to json. Objects cannot be defined recursively.
; - delineates fields of the object
: - if the field has a value other than an empty object, it comes after a colon
, - delineates key/value pairs of a value object
If the value object consists of ONLY keys (no = present) the keys are
converted to a list. Otherwise a object of key/value pairs is created with
any missing values set to null
= OR ~ - separates key/value pairs of a value object, if not provided value is null
twiddle is supported since = has special meaning in URLs

Parameters:
Name Type Description
(String)

str

Returns:
Type
Object