Classes
Methods
addAtomSpecs(customAtomSpecs)
add atomSpecs to validAtomSelectionSpecs
| Name | Type | Description |
|---|---|---|
customAtomSpecs | Array | array of strings that can be used as atomSelectionSpecs What we should do is use something like https://github.com/woutervh-/typescript-is to do runtime |
- Deprecated
- Yes
- Source
addAtoms(newatoms)
Add list of new atoms to model. Adjusts bonds appropriately.
| Name | Type | Description |
|---|---|---|
newatoms | Array.<AtomSpec> |
- Source
var atoms = [{elem: 'C', x: 0, y: 0, z: 0, bonds: [1,2], bondOrder: [1,2]}, {elem: 'O', x: -1.5, y: 0, z: 0, bonds: [0]},{elem: 'O', x: 1.5, y: 0, z: 0, bonds: [0], bondOrder: [2]}];
viewer.setBackgroundColor(0xffffffff);
var m = viewer.addModel();
m.addAtoms(atoms);
m.setStyle({},{stick:{}});
viewer.zoomTo();
viewer.render();addFrame(atoms)
Add atoms as frames of model
| Name | Type | Description |
|---|---|---|
atoms | Array.<AtomSpec> | atoms to be added |
- Source
addMolData(data, format, options)
add atoms to this model from molecular data string
| Name | Type | Description |
|---|---|---|
data | string | | atom structure file input data string, for gzipped input use ArrayBuffer |
format | string | input file string format (e.g 'pdb', 'sdf', 'sdf.gz', etc.) |
options | ParserOptionsSpec | format dependent options. Attributes depend on the input format |
- Source
addPropertyLabels(prop, sel, options)
Create labels for atoms that show the value of the passed property.
| Name | Type | Description |
|---|---|---|
prop | String | property name |
sel | AtomSelectionSpec | |
options | LabelSpec |
- Source
addResLabels(sel, options, byframe)
Create labels for residues of selected atoms.
Will create a single label at the center of mass of all atoms
with the same chain,resn, and resi.
| Name | Type | Description |
|---|---|---|
sel | AtomSelectionSpec | |
options | LabelSpec | |
byframe | boolean | if true, create labels for every individual frame, not just current; frames must be loaded already |
- Source
assignBonds()
Assign bonds based on atomic coordinates.
This currently uses a primitive distance-based algorithm that does not
consider valence constraints and will only create single bonds.
- Source
atomIsSelected(atom, sel) → {boolean}
given a selection specification, return true if atom is selected.
Does not support context-aware selectors like expand/within/byres.
| Name | Type | Description |
|---|---|---|
atom | AtomSpec | |
sel | AtomSelectionSpec |
- Source
- Type:
- boolean
calculateDashes()
Calculate dashed line segments along a bond, with proper centering and two-color support.
The dashes are centered along the bond using the pattern:
[halfGap]-[dash]-[gap]-[dash]-[gap]-...-[dash]-[halfGap]
For two-color bonds, the first half of dashes use colors[0], second half use colors[1].
- Source
createMolObj()
param {AtomSpec[]} atoms
- Source
drawAtomClickSphere()
Register atom shaped click handlers
- Source
drawAtomCross(atom, geos)
| Name | Type | Description |
|---|---|---|
atom | AtomSpec | |
geos | Record.<number, Geometry> |
- Source
drawAtomSphere(atom, geo)
| Name | Type | Description |
|---|---|---|
atom | AtomSpec | |
geo | Geometry |
- Source
drawBondLines(atom, atoms, geos)
- Source
enableContextMenu(sel, contextMenuEnabled)
enable context menu of selected atoms
| Name | Type | Description |
|---|---|---|
sel | AtomSelectionSpec | atom selection to apply hoverable settings to |
contextMenuEnabled | boolean | whether contextMenu-handling is enabled for the selection |
- Source
expandAtomList()
returns a list of atoms in the expanded bounding box, but not in the current one
Bounding box:
[ [ xmin, ymin, zmin ],
[ xmax, ymax, zmax ],
[ xctr, yctr, zctr ] ]
- Source
exportVRML()
return a VRML string representation of the model. Does not include VRML header information
- Source
VRML
getCrystData()
Returns crystallographic information if present.
- Source
getID() → {number}
Returns model id number
- Source
Model ID
- Type:
- number
getInternalState()
Return object representing internal state of
the model appropriate for passing to setInternalState
- Source
getNumFrames() → {number}
Returns model's frames property, a list of atom lists
- Source
- Type:
- number
getRadiusFromStyle(atom, style) → {number}
| Name | Type | Description |
|---|---|---|
atom | AtomSpec | |
style | atomstyle |
- Source
- Type:
- number
getSymmetries() → {Array.<Matrix4>}
Returns list of rotational/translational matrices if there is BIOMT data
Otherwise returns a list of just the ID matrix
- Source
- Type:
- Array.<Matrix4>
getViewer()
Return viewer associated with this model.
- Source
GLViewer
globj(group, Object)
manage the globj for this model in the possed modelGroup - if it has to be regenerated, remove and add
| Name | Type | Description |
|---|---|---|
group | Object3D | |
Object | options |
- Source
hide()
Don't show this model in future renderings. Keep all styles and state
so it can be efficiencly shown again.
- @see GLModel#show
- Source
$3Dmol.download("pdb:3ucr",viewer,{},function(){
viewer.setStyle({},{stick:{}});
viewer.getModel().hide();
viewer.render();
});removeAtoms(badatoms)
Remove specified atoms from model
| Name | Type | Description |
|---|---|---|
badatoms | Array.<AtomSpec> | list of atoms |
- Source
removegl(group)
Remove any renderable mol object from scene
| Name | Type | Description |
|---|---|---|
group | Object3D |
- Source
selectedAtoms(sel) → {Array.<Object>}
return list of atoms selected by sel, this is specific to glmodel
| Name | Type | Description |
|---|---|---|
sel | AtomSelectionSpec |
- Source
- Type:
- Array.<Object>
$3Dmol.download("pdb:4wwy",viewer,{},function(){
var atoms = viewer.selectedAtoms({chain:'A'});
for(var i = 0, n = atoms.length; i < n; i++) {
atoms[i].b = 0.0;
}
viewer.setStyle({cartoon:{colorscheme:{prop:'b',gradient: 'roygb',min:0,max:30}}});
viewer.render();
});setClickable(sel, clickable, callback)
Set clickable and callback of selected atoms
| Name | Type | Description |
|---|---|---|
sel | AtomSelectionSpec | atom selection to apply clickable settings to |
clickable | boolean | whether click-handling is enabled for the selection |
callback | function | function called when an atom in the selection is clicked |
- Source
setColorByElement(sel, colors)
given a mapping from element to color, set atom colors
| Name | Type | Description |
|---|---|---|
sel | AtomSelectionSpec | |
colors | object |
- Source
setColorByFunction(sel, func)
| Name | Type | Description |
|---|---|---|
sel | AtomSelectionSpec | selection object |
func | function | function to be used to set the color |
- Deprecated
- use setStyle and colorfunc attribute
- Source
$3Dmol.download("pdb:4UAA",viewer,{},function(){
viewer.setBackgroundColor(0xffffffff);
var colorAsSnake = function(atom) {
return atom.resi % 2 ? 'white': 'green'
};
viewer.setStyle( {}, { cartoon: {colorfunc: colorAsSnake }});
viewer.render();
});setColorByProperty(sel, prop, scheme)
| Name | Type | Description |
|---|---|---|
sel | AtomSelectionSpec | |
prop | string | |
scheme | Gradient | |
- Source
setCoordinates(str, format)
Set coordinates for the atoms from provided trajectory file.
| Name | Type | Description |
|---|---|---|
str | string | | contains the data of the file |
format | string | contains the format of the file (mdcrd, inpcrd, pdb, netcdf, or array). Arrays should be TxNx3 where T is the number of timesteps and N the number of atoms. |
- Source
let m = viewer.addModel() //create an empty model
m.addAtoms([{x:0,y:0,z:0,elem:'C'},{x:2,y:0,z:0,elem:'C'}]) //provide a list of dictionaries representing the atoms
viewer.setStyle({'sphere':{}})
m.setCoordinates([[[0.0, 0.0, 0.0], [2.0, 0.0, 0.0]], [[0.0, 0.0, 0.0], [2.8888888359069824, 0.0, 0.0]], [[0.0, 0.0, 0.0], [3.777777671813965, 0.0, 0.0]], [[0.0, 0.0, 0.0], [4.666666507720947, 0.0, 0.0]], [[0.0, 0.0, 0.0], [5.55555534362793, 0.0, 0.0]], [[0.0, 0.0, 0.0], [6.44444465637207, 0.0, 0.0]], [[0.0, 0.0, 0.0], [7.333333492279053, 0.0, 0.0]], [[0.0, 0.0, 0.0], [8.222222328186035, 0.0, 0.0]], [[0.0, 0.0, 0.0], [9.11111068725586, 0.0, 0.0]], [[0.0, 0.0, 0.0], [10.0, 0.0, 0.0]]],'array');
viewer.animate({loop: "forward",reps: 1});
viewer.zoomTo();
viewer.zoom(0.5);
viewer.render();setCoordinatesFromURL(url, path) → {Promise}
Set coordinates from remote trajectory file.
| Name | Type | Description |
|---|---|---|
url | string | contains the url where mdsrv has been hosted |
path | string | contains the path of the file ( |
- Source
- Type:
- Promise
setCrystData(a, b, c, alpha, beta, gamma)
Set crystallographic information using three angles and three lengths
| Name | Type | Description |
|---|---|---|
a | number | length of unit cell side |
b | number | length of unit cell side |
c | number | length of unit cell side |
alpha | number | unit cell angle in degrees (default 90) |
beta | number | unit cell angle in degrees (default 90) |
gamma | number | unit cell angle in degrees (default 90) |
- Source
setCrystMatrix(matrix)
Set the crystallographic matrix to the given matrix.
This function removes a, b, c, alpha, beta, gamma from
the crystal data.
| Name | Type | Description |
|---|---|---|
matrix | Matrix3 | unit cell matrix |
- Source
setFrame(framenum, options) → {Promise}
Sets model's atomlist to specified frame
Sets to last frame if framenum out of range
| Name | Type | Description |
|---|---|---|
framenum | number | model's atoms are set to this index in frames list |
options | Object | {fast: true} replays the frame's coordinates into the existing |
- Source
- Type:
- Promise
setHoverable(sel, hoverable, hover_callback, unhover_callback)
Set hoverable and callback of selected atoms
| Name | Type | Description |
|---|---|---|
sel | AtomSelectionSpec | atom selection to apply hoverable settings to |
hoverable | boolean | whether hover-handling is enabled for the selection |
hover_callback | function | function called when an atom in the selection is hovered over |
unhover_callback | function | function called when the mouse moves out of the hover area |
- Source
setInternalState(state)
Overwrite the internal model state with the passed state.
| Name | Type | Description |
|---|---|---|
state |
- Source
setStyle(sel, style, add)
Set atom style of selected atoms
| Name | Type | Description |
|---|---|---|
sel | AtomSelectionSpec | |
style | AtomStyleSpec | |
add | boolean | if true, add to current style, don't replace |
- Source
$3Dmol.download("pdb:4UB9",viewer,{},function(){
viewer.setBackgroundColor(0xffffffff);
viewer.setStyle({chain:'A'},{line:{hidden:true,colorscheme:{prop:'b',gradient: new $3Dmol.Gradient.Sinebow($3Dmol.getPropertyRange(viewer.selectedAtoms(),'b'))}}});
viewer.setStyle({chain:'B'},{line:{colorscheme:{prop:'b',gradient: new $3Dmol.Gradient.Sinebow($3Dmol.getPropertyRange(viewer.selectedAtoms(),'b'))}}});
viewer.setStyle({chain:'C'},{cross:{hidden:true,colorscheme:{prop:'b',gradient: new $3Dmol.Gradient.Sinebow($3Dmol.getPropertyRange(viewer.selectedAtoms(),'b'))}}});
viewer.setStyle({chain:'D'},{cross:{colorscheme:{prop:'b',gradient: new $3Dmol.Gradient.RWB($3Dmol.getPropertyRange(viewer.selectedAtoms(),'b'))}}});
viewer.setStyle({chain:'E'},{cross:{radius:2.0,colorscheme:{prop:'b',gradient: new $3Dmol.Gradient.RWB($3Dmol.getPropertyRange(viewer.selectedAtoms(),'b'))}}});
viewer.setStyle({chain:'F'},{stick:{hidden:true,colorscheme:{prop:'b',gradient: new $3Dmol.Gradient.RWB($3Dmol.getPropertyRange(viewer.selectedAtoms(),'b'))}}});
viewer.setStyle({chain:'G'},{stick:{radius:0.8,colorscheme:{prop:'b',gradient: new $3Dmol.Gradient.ROYGB($3Dmol.getPropertyRange(viewer.selectedAtoms(),'b'))}}});
viewer.setStyle({chain:'H'},{stick:{singleBonds:true,colorscheme:{prop:'b',gradient: new $3Dmol.Gradient.ROYGB($3Dmol.getPropertyRange(viewer.selectedAtoms(),'b'))}}});
viewer.render();
});setSymmetries(list)
Sets symmetries based on specified matrices in list
| Name | Type | Description |
|---|---|---|
list | Array.<Matrix4> |
- Source
show()
Unhide a hidden model
- Source
- See
$3Dmol.download("pdb:3ucr",viewer,{},function(){
viewer.setStyle({},{stick:{}});
viewer.getModel().hide();
viewer.render( )
viewer.getModel().show()
viewer.render();
});syncAtomPositions(optsopt)
Push the atoms' current coordinates into the existing geometry without rebuilding it.
Intended for animation: mutate model.selectedAtoms() / model.atoms x/y/z however you
like (linear interpolation between two conformations, torsion-space folding, MD frames)
and then call this instead of setFrame/setCoordinates. Those go through globj, which
regenerates every geometry in the model from scratch each frame. Here only position data
changes, so colors, radii, per-atom alphas and face indices are left alone and the
renderer respecifies just the affected buffers.
Covers sphere imposters, stick imposters (including their joint caps and color-split
half-bonds) and lines. NOT covered: cartoon, cross, surface, instanced and non-imposter
(tessellated) geometry -- a model showing those still needs a full regeneration. Requires
that the model has already been rendered once, since there is otherwise no geometry to
update.
| Name | Type | Attributes | Description |
|---|---|---|---|
opts | object | <optional> |
- Source
true if positions were written. False means nothing was touched and the caller
should fall back to a full rebuild: either the model has not been rendered yet,
nothing trackable is styled, or the geometry contains something inexpressible as
a point on a bond axis (multi-bond side offsets), in which case a partial update
would leave visibly stale geometry behind.
syncSpherePositions() → {boolean}
- Deprecated
- Renamed to syncAtomPositions() once it grew beyond spheres.
- Source
- Type:
- boolean
syncSphereRadii(scale)
Rescale sphere-imposter radii in place, without rebuilding geometry.
scale is called once per sphere-styled atom and returns a multiplier on the radius that
atom was built with: 0 hides it, 1 is its natural size. Intended for entrance animations
(grow atoms in) and any effect that changes size without changing what is drawn.
This works because a sphere imposter has no radius uniform and no radius buffer of its
own -- the radius IS the billboard quad's extent, stored as the four corner offsets in the
normal array. Rewriting those corners resizes the sphere, and since only normals go dirty
the renderer respecifies one buffer instead of reallocating the group.
| Name | Type | Description |
|---|---|---|
scale | function |
- Source
true if radii were written, false if there is nothing to update (no prior render,
or no sphere-imposter atoms in this model).
toCDObject(whether) → {Object}
Convert the model into an object in the format of a ChemDoodle JSON model.
| Name | Type | Description |
|---|---|---|
whether | boolean | or not to include style information. Defaults to false. |
- Source
- Type:
- Object
vibrate(numFrames, amplitude, bothWays, arrowSpec)
If model atoms have dx, dy, dz properties (in some xyz files), vibrate populates the model's frame property based on parameters.
Model can then be animated
| Name | Type | Description |
|---|---|---|
numFrames | number | number of frames to be created, default to 10 |
amplitude | number | amplitude of distortion, default to 1 (full) |
bothWays | boolean | if true, extend both in positive and negative directions by numFrames |
arrowSpec | ArrowSpec | specification for drawing animated arrows. If color isn't specified, atom color (sphere, stick, line preference) is used. |
- Source
$3Dmol.download("pdb:4UAA",viewer,{},function(){
viewer.setStyle({},{stick:{}});
viewer.vibrate(10, 1);
viewer.animate({loop: "forward",reps: 1});
viewer.zoomTo();
viewer.render();
});