Methods
-
AlertBox(config)
-
Add alert messages to different panels
Parameters:
Name Type Description configObject Configuraiton for alert box display
-
ContextMenu()
-
Creates the panel for manipulation of labels on the viewport
-
ModelToolbar()
-
ModelToolbar is part of $3Dmol.UI to edit or change the model loaded into the viewer
-
Property(key, value)
-
Property object used in property menu
Parameters:
Name Type Description keyString Name of the atom property
value* Value of the property
-
Selection()
-
Card for manipulation of a selection form and related styles
-
SelectionBox(icon) → {Object}
-
Selection box creates the UI panel to manipulate selections and style that are drawn
on the viewportParameters:
Name Type Description icon$3Dmol.UI.Icons takes the svg code for the icon that is to be used to display
selection boxReturns:
Jquery element of div
- Type
- Object
-
setLocation(parent, child, x_type, y_type, x_offset, y_offset)
-
Sets the location of the element relative to the parseInt
as per position typesParameters:
Name Type Description parentObject jquery object
childObject jquery object
x_typeString 'left|right'
y_typeString 'top|bottom'
x_offsetNumber Offset x values in pixels
y_offsetNumber Offset y values in pixels
-
setPosition(jquery, left, top)
-
Sets the css position property left and top for the element
Parameters:
Name Type Description jqueryobject html element
leftnumber : css left property
topnumber : css top peroperty
-
StyleBox(selId, side)
-
Creates StyleBox for listing out different styles inside the selection
Parameters:
Name Type Description selIdString Id of the selection for which the style box is created
sideString Alignment of text inside the box
-
Surface()
-
Creates cards for manipulation of surface
-
SurfaceMenu()
-
Creates UI panel for surface manipulations
Type Definitions
-
ArrowSpec
-
Arrow shape specification. Extends ShapeSpec
Properties:
Name Type Description start$3Dmol.Vector3 end$3Dmol.Vector3 radiusnumber colorColorSpec hiddenboolean radiusRationumber ratio of arrow base to cylinder (1.618034 default)
midnumber relative position of arrow base (0.618034 default)
midposnumber position of arrow base in length units, if negative positioned from end instead of start. Overrides mid.
-
AtomSelectionSpec
-
Atom selection object. Used to specify what atoms should be selected. Can include
any field from AtomSpec in which case atoms must equal the specified value.
All fields must match for the selection to hold. If values
are provided as a list, then only one value of the list must match.Properties:
Name Type Description ...AtomSpec any field from AtomSpec, values may be singletons or lists. Integer numerical ranges are supported as strings.
modelGLModel a single model or list of models from which atoms should be selected. Can also specify by numerical creation order. Reverse indexing is allowed (-1 specifies last added model).
bondsnumber overloaded to select number of bonds, e.g. {bonds: 0} will select all nonbonded atoms
predicatefunction user supplied function that gets passed an {AtomSpec} and should return true if the atom should be selected
invertboolean if set, inverts the meaning of the selection
byresboolean if set, expands the selection to include all atoms of any residue that has any atom selected
expandnumber expands the selection to include all atoms within a given distance from the selection
withinWithinSelectionSpec intersects the selection with the set of atoms within a given distance from another selection
andArray.<AtomSelectionSpec> take the intersection of the provided lists of {AtomSelectionSpec}s
orArray.<AtomSelectionSpec> take the union of the provided lists of {AtomSelectionSpec}s
notAtomSelectionSpec take the inverse of the provided {AtomSelectionSpec}
Example
$3Dmol.download("pdb:2EJ0",viewer,{},function(){ viewer.setStyle({chain:'B'},{cartoon:{color:'spectrum'}}); viewer.setStyle({chain:'B',invert:true},{cartoon:{}}); viewer.setStyle({bonds: 0},{sphere:{radius:0.5}}); //water molecules viewer.setStyle({resn:'PMP',byres:true,expand:5},{stick:{colorscheme:"greenCarbon"}}); viewer.setStyle({resi:["91-95","42-50"]},{cartoon:{color:"green",thickness:1.0}}); viewer.render(); }); -
AtomSpec
-
Atom representation. Depending on the input file format, not all fields may be defined.
Properties:
Name Type Description resnstring Parent residue name
xnumber Atom's x coordinate
ynumber Atom's y coordinate
znumber Atom's z coordinate
colorColorSpec Atom's color, as hex code or built-in color string
surfaceColorColorSpec Hex code for color to be used for surface patch over this atom
elemstring Element abbreviation (e.g. 'H', 'Ca', etc)
hetflagboolean Set to true if atom is a heteroatom
chainstring Chain this atom belongs to, if specified in input file (e.g 'A' for chain A)
resinumber Residue number
icodenumber rescodenumber serialnumber Atom's serial id number
atomstring Atom name; may be more specific than 'elem' (e.g 'CA' for alpha carbon)
bondsArray.<number> Array of atom ids this atom is bonded to
ssstring Secondary structure identifier (for cartoon render; e.g. 'h' for helix)
singleBondsboolean true if this atom forms only single bonds or no bonds at all
bondOrderArray.<number> Array of this atom's bond orders, corresponding to bonds identfied by 'bonds'
propertiesObject Optional mapping of additional properties
bnumber Atom b factor data
pdblinestring If applicable, this atom's record entry from the input PDB file (used to output new PDB from models)
clickableboolean Set this flag to true to enable click selection handling for this atom
callbackfunction Callback click handler function to be executed on this atom and its parent viewer
invertboolean for selection, inverts the meaning of the selection
-
AtomStyleSpec
-
Properties:
Name Type Description lineLineStyleSpec draw bonds as lines
crossCrossStyleSpec draw atoms as crossed lines (aka stars)
stickStickStyleSpec draw bonds as capped cylinders
sphereSphereStyleSpec draw atoms as spheres
cartoonCartoonStyleSpec draw cartoon representation of secondary structure
clicksphereClickSphereStyleSpec invisible style for click handling only
-
BoxSpec
-
Box shape specification. Extends ShapeSpec
Properties:
Name Type Description corner$3Dmol.Vector3 bottom corner of box
center$3Dmol.Vector3 alternative to corner: center of box
dimensionsObject {w:width, h:height, d:depth}; can be either scalars or vectors (for not-axis aligned boxes)
-
CartoonStyleSpec
-
A visualization of protein or nucleic acid secondary structure. Applying this to other molecules will not show anything.
Properties:
Name Type Description colorColorSpec strand color, may specify as 'spectrum' which will apply reversed gradient based on residue number
stylestring style of cartoon rendering (trace, oval, rectangle
(default), parabola, edged)ribbonboolean whether to use constant strand width, disregarding
secondary structure; use thickness to adjust radiusarrowsboolean whether to add arrows showing beta-sheet
directionality; does not apply to trace or ribbontubesboolean whether to display alpha helices as simple cylinders;
does not apply to tracethicknessnumber cartoon strand thickness, default is 0.4
widthnumber cartoon strand width, default is secondary
structure-dependent; does not apply to trace or ribbonopacitynumber set opacity from 0-1; transparency is set per-chain
with a warning outputted in the event of ambiguityInnucleic acids, the base cylinders obtain their color from the
atom to which the cylinder is drawn, which is 'N1' for purines (resn:
'A', 'G', 'DA', 'DG') and 'N3' for pyrimidines (resn: 'C', 'U', 'DC',
'DT'). The different nucleobases can therefore be distinguished as
follows:Example
$3Dmol.download("pdb:4ZD3",viewer,{},function(){ viewer.setBackgroundColor(0xffffffff); viewer.setViewStyle({style:"outline"}); viewer.setStyle({},{cartoon:{}}); viewer.render(); }); -
ColorschemeSpec
-
Properties:
Name Type Description string color>Carbon - use default element colors but with carbon set to specify html color string
ssPyMOLstring PyMol secondary colorscheme
ssJmolstring Jmol secondary colorscheme
Jmolstring Jmol primary colorscheme
defaultstring default colorscheme
aminostring amino acid colorscheme
shapelystring shapely protien colorscheme
nucleicstring nucleic acid colorscheme
chainstring standard chain colorscheme
chainHetatmstring chain Hetatm colorscheme
propstring atomSpec property. Example 'b'. See AtomSpec.
gradientGradient Allows the user to provide a gradient to the colorscheme. Is either a $3Dmol.Gradient object or the name of a built-in gradient (rwb, roygb, sinebow)
min min value for gradient
max max value for gradient
mid mid point value for gradient (for rwb)
mapobject map of a certain AtomSpec property to a color of the form
{'prop': 'elem', map:$3Dmol.elementColors.greenCarbon}Allows the user to provide a mapping of elements to colors to the colorscheme. This can be done with any properties, and not just 'elem'.colorfuncfunction Allows the user to provide a function for setting the colorschemes.
Example
//Using a function in order to define the colors. $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(); }); -
ColorSpec
-
Color representation.
Properties:
Name Type Description 0xAF10ABstring any hex number
string color name>
-
CrossStyleSpec
-
Properties:
Name Type Description hiddenboolean do not show
linewidthnumber deprecated due to vanishing browser support
radiusnumber scalenumber scale radius by specified amount
colorschemeColorschemeSpec element based coloring
colorColorSpec fixed coloring, overrides colorscheme
opacitynumber opacity, must be the same for all atoms in the model
-
CurveSpec
-
Curve shape specification. Extends ShapeSpec
Properties:
Name Type Description points$3Dmol.Vector3 list of (x,y,z) points to interpolate between to make curve
smoothnumber amount of interpolation
radiusnumber fromArrowboolean if an arrow should be drawn at the start
toArrowboolean if an arrow should be drawn at the end
-
CustomShapeSpec
-
Specification for adding custom shape. Extends ShapeSpec.
Properties:
Name Type Description vertexArrArray.<$3Dmol.Vector3> List of vertex positions
normalArrArray.<$3Dmol.Vector3> List of normal vectors for each vertex
faceArrArray.<number> List of triangles to build the custom shape. Each triangle is defined by the indices of 3 vertices in vertexArr, so the array length should be 3 times the number of faces.
colorColorSpec | Array.<ColorSpec> Either a single color for the whole object or an array specifying the color at each vertex.
-
CylinderSpec
-
Cylinder shape specification. Extends ShapeSpec
Properties:
Name Type Description start$3Dmol.Vector3 end$3Dmol.Vector3 radiusnumber fromCap$3Dmol.CAP 0 for none, 1 for flat, 2 for round
toCap$3Dmol.CAP 0 for none, 1 for flat, 2 for round
dashedboolean -
FileFormats
-
File formats supported by 3Dmol.js
Properties:
Name Type Description cdjson,jsonChemical JSON format
cubeGaussian cube format
groGromacs topology format, need to add coordinates to resulting model.
mcif,cifCrystallographic Information File, the successor to PDB that makes you miss the PDB file format
mmtfMacromolecular Transmission Format, the successor to PDB that is totally awesome
mol2Sybyl Mol2 format
pdbThe venerable Protein Data Bank format
pqrLike PDB but with partial charges which are read into the partialcharge atom property
prmtopAmber topology file, must add coordinates
sdfMDL MOL format, supports multiple models and meta data
vaspVASP format (CONTCAR, POSCAR)
xyzXYZ cartesian coordinates format
-
IsoSurfaceSpec
-
Isosurface style specification
Properties:
Name Type Description isovalnumber specifies the isovalue to draw surface at
colorColorSpec solid color
opacitynumber transparency, between 0 and 1
wireframeboolean draw as wireframe, not surface
linewidthnumber width of line for wireframe rendering No longer supported by most browsers
smoothnessnumber amount to smooth surface (default 1)
coordslist coordinates around which to include data; use viewer.selectedAtoms() to convert an AtomSelectionSpec to coordinates
seldistnumber distance around coords to include data [default = 2.0]
voldata$3Dmol.VolumeData volumetric data for vertex coloring, can be VolumeData object or raw data if volformat is specified
volscheme$3Dmol.Gradient coloring scheme for mapping volumetric data to vertex color, if not a Gradient object, show describe a builtin gradient one by providing an object with gradient, min, max, and (optionally) mid fields.
volformatstring format of voldata if not a $3Dmol.VolumeData object
clickableboolean if true, user can click on object to trigger callback
callbackfunction function to call on click
-
LabelSpec
-
Label type specification
Properties:
Name Type Description fontstring font name, default sans-serif
fontSizenumber height of text, default 18
fontColorColorSpec font color, default white
fontOpacitynumber font opacity, default 1
borderThicknessnumber line width of border around label, default 0
borderColorColorSpec color of border, default backgroundColor
borderOpacitystring color of border
backgroundColorColorSpec color of background, default black
backgroundOpacitystring opacity of background, default 1
position$3Dmol.Vector3 x,y,z coordinates for label
screenOffset$3Dmol.Vector2 x,y pixel offset of label from position
inFrontboolean always put labels in from of model
showBackgroundboolean show background rounded rectangle, default true
fixedboolean sets the label to change with the model when zooming
useScreenboolean position is in screen (not model) coordinates which are pixel offsets from upper left corner.
backgroundImageObject An element to draw into the label. Any CanvasImageSource is allowed.
alignmentstring how to orient the label w/respect to position: topLeft (default), topCenter, topRight, centerLeft, center, centerRight, bottomLeft, bottomCenter, bottomRight
framenumber if set, only display in this frame of an animation
-
LineSpec
-
Line shape specification. Extends ShapeSpec (but defaults to wireframe)
Properties:
Name Type Description start$3Dmol.Vector3 end$3Dmol.Vector3 -
LineStyleSpec
-
Properties:
Name Type Description hiddenboolean do not show line
linewidthnumber deprecated due to vanishing browser support
colorschemeColorschemeSpec element based coloring
colorColorSpec fixed coloring, overrides colorscheme
opacitynumber opacity, must be the same for all atoms in the model
-
ParserOptionsSpec
-
Parser options specification. Used to specify the options of a GLModel. Depending on the input file format, not all fields may be defined.
Properties:
Name Type Description framesboolean true if you want to add to a new frame and false otherwise ; supported by all
vibrateobject object specifying the vibration behavior ; supported by all
Properties
Name Type Description framesnumber number of frames to be created, default to 10 ; supported by all
amplitudenumber amplitude of distortion, default to 1 (full) ; supported by all
multimodelboolean specifies weather or not multiple models are being defined ; supported by xyz,sdf, or mol2
onemolboolean specifies weather or not the model is of one molecule ; Supported by xyz , sdf , mol2
keepHboolean do not strip hydrogens ; supported by sdf,mol2
parseStyleobject used to define ChemDoodle styles ; supported by cdjson
doAssemblyboolean boolean dictating weather or not to do assembly ; supported by mcif
duplicateAssemblyAtoms-boolean Set to true if you wish to duplicate assembly atoms otherwise false ; supported by all formats with symmetries. Not duplicating will result in faster rendering but it will not be possible to individually style symmetries.
normalizeAssemblyboolean shift symmetry mates so their centroid is in the unit cell
dontConnectDuplicatedAtomsboolean do not detect bonds between symmetries generated with duplicateAssemblyAtoms (cif only - other formats never make bonds between symmetries)
noSecondaryStructureboolean boolean dictating the presence of a secondary structure ; supported by pdb
noComputeSecondaryStructureboolean do not compute ss ; supported by pdb
altLocstring which alternate location to select, if present; '*' to load all ; supported by pdb
assemblyIndexnumber index of the assembly in symmetry ; supported by mmtf
assignBondsboolean for formats without explicit bonds (e.g. PDB, xyz) infer bonding (default true).
-
ShapeSpec
-
GLShape style specification
Properties:
Name Type Description colorColorSpec solid color
alphanumber transparency
wireframeboolean draw as wireframe, not surface
hiddenboolean if true, do not display object
linewidthnumber width of line for wireframe rendering No longer supported by most browsers
clickableboolean if true, user can click on object to trigger callback
callbackfunction function to call on click
framenumber if set, only display in this frame of an animation
-
SphereShapeSpec
-
Sphere shape specification. Extends ShapeSpec
Properties:
Name Type Description center$3Dmol.Vector3 radiusnumber -
SphereStyleSpec
-
Properties:
Name Type Description hiddenboolean do not show atom
radiusnumber override van der waals radius
scalenumber scale radius by specified amount
colorschemeColorschemeSpec element based coloring
colorColorSpec fixed coloring, overrides colorscheme
opacitynumber opacity, must be the same for all atoms in the model
-
StickStyleSpec
-
Properties:
Name Type Description hiddenboolean do not show
radiusnumber singleBondsboolean draw all bonds as single bonds if set
colorschemeColorschemeSpec element based coloring
colorColorSpec fixed coloring, overrides colorscheme
opacitynumber opacity, must be the same for all atoms in the model
-
SurfaceStyleSpec
-
Properties:
Name Type Description opacitynumber sets the transparency: 0 to hide, 1 for fully opaque
colorschemeColorschemeSpec element based coloring
colorColorSpec fixed coloring, overrides colorscheme
voldata$3Dmol.VolumeData volumetric data for vertex coloring, can be VolumeData object or raw data if volformat is specified
volscheme$3Dmol.Gradient coloring scheme for mapping volumetric data to vertex color, if not a Gradient object, show describe a builtin gradient one by providing an object with gradient, min, max, and (optionally) mid fields.
volformatstring format of voldata if not a $3Dmol.VolumeData object
mapObject specifies a numeric atom property (prop) and color mapping (scheme) such as $3Dmol.Gradient.RWB. Deprecated, use colorscheme instead.
Example
var setStyles = function(volumedata){ var data = new $3Dmol.VolumeData(volumedata, "cube"); viewer.addSurface("VDW", {opacity:0.85, voldata: data, volscheme: new $3Dmol.Gradient.RWB(-10,10)},{chain:'A'}); viewer.mapAtomProperties($3Dmol.applyPartialCharges); viewer.addSurface($3Dmol.SurfaceType.SAS, {map:{prop:'partialCharge',scheme:new $3Dmol.Gradient.RWB(-.05,.05)}, opacity:1.0},{chain:'B'}); viewer.addSurface($3Dmol.SurfaceType.VDW, {opacity:0.85,voldata: data, color:'red'},{chain:'C'}); viewer.addSurface($3Dmol.SurfaceType.SAS, {opacity:0.85,voldata: data, colorscheme:'greenCarbon'},{chain:'D'}); viewer.render(); }; $3Dmol.download("pdb:4DLN",viewer,{},function(){ $.get("data/1fas.cube",setStyles); }); -
UnitCellStyleSpec
-
Unit Cell shape specification.
Properties:
Name Type Description boxLineStyleSpec line style used to draw box
astyleArrowSpec arrow specification of "a" axis
bstyleArrowSpec arrow specification of "b" axis
cstyleArrowSpec arrow specification of "c" axis
alabelstring label for a axis
alabelstyleLabelSpec label style for a axis
blabelstring label for b axis
blabelstyleLabelSpec label style for b axis
clabelstring label for c axis
clabelstyleLabelSpec label style for c axis
-
Vector3
-
3 dimensional vector
Properties:
Name Type Description xnumber x coordinate
ynumber y coordinate
znumber z coordinate
-
ViewerGridSpec
-
Grid GLViewer input specification
Properties:
Name Type Description rowsnumber number of rows in grid
colsnumber number of columns in grid
control_allboolean if true, mouse events are linked
-
ViewerSpec
-
GLViewer input specification
Properties:
Name Type Description callbackfunction Callback function to be immediately executed on this viewer
defaultcolorsObject Object defining default atom colors as atom => color property value pairs for all models within this viewer
nomouseboolean Whether to disable disable handling of mouse events.
If you want to use your own mouse handlers, set this then bind your handlers to the canvas object.
The default 3Dmol.js handlers are available for use:
'mousedown touchstart': viewer._handleMouseDown,
'DOMMouseScroll mousewheel': viewer._handleMouseScroll
'mousemove touchmove': viewer._handleMouseMovebackgroundColorstring Color of the canvas background
backgroundAlphanumber Alpha transparency of canvas background
cameraxnumber hoverDurationnumber idstring id of the canvas
cartoonQualitynumber default 5
rownumber colnumber rowsnumber colsnumber canvasviewersminimumZoomToDistancelowerZoomLimitupperZoomLimitantialiasboolean control_allboolean orthographicboolean disableFogboolean Disable fog, default to false
-
VolumetricRendererSpec
-
VolumetricRenderer style specification
Properties:
Name Type Description transferfnlist list of objects containing @color, @opacity and @value properties to specify color per voxel data value
subsamplesnumber number of times to sample each voxel approximately (default 5)
-
WithinSelectionSpec
-
Within selection object. Used to find the subset of an atom selection that is within
some distance from another atom selection. When added as a field of an AtomSelectionSpec,
intersects the set of atoms in that selection with the set of atoms within a given
distance from the given AtomSelectionSpec.Properties:
Name Type Description distancenumber the distance in angstroms away from the atom selection to include atoms in the parent selection
invertboolean if set, selects atoms not within distance range for intersection
selAtomSelectionSpec the selection of atoms against which to measure the distance from the parent atom selection
Example
$3Dmol.download("pdb:2EJ0",viewer,{},function(){ viewer.setStyle({chain: 'A', within:{distance: 10, sel:{chain: 'B'}}}, {sphere:{}}); viewer.render(); });// stylizes atoms in chain A that are within 10 angstroms of an atom in chain B