Class: GLModel

$3Dmol. GLModel

new GLModel(mid, defaultcolors)

GLModel represents a group of related atoms

Parameters:
Name Type Argument Description
mid number <optional>
defaultcolors Object <optional>

Object defining default atom colors as atom => color property value pairs

See:

Methods

<static> setColorByProperty(sel, prop, gradient)

Parameters:
Name Type Description
sel type
prop type
gradient type

addAtoms(newatoms)

Add list of new atoms to model. Adjusts bonds appropriately.

Parameters:
Name Type Description
newatoms type
Example
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();

addAtomSpecs(customAtomSpecs)

add atomSpecs to validAtomSelectionSpecs

Parameters:
Name Type Description
customAtomSpecs Array

array of strings that can be used as atomSelectionSpecs this is to prevent the 'Unknown Selector x' message on the console for the strings passed

addFrame(atom)

Add atoms as frames of model

Parameters:
Name Type Description
atom AtomSpec

atoms to be added

addMolData(data, format, options)

add atoms to this model from molecular data string

Parameters:
Name Type Description
data string | ArrayBuffer

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

addResLabels(sel, viewer)

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.

Parameters:
Name Type Description
sel AtomSelectionSpec
viewer $3Dmol.GLViewer

atomIsSelected(atom, sel) → {boolean}

given a selection specification, return true if atom is selected

Parameters:
Name Type Description
atom AtomSpec
sel AtomSelectionSpec
Returns:
Type
boolean

getFrames() → {Array.<Object>}

Returns model's frames property, a list of atom lists

Returns:
Type
Array.<Object>

getID() → {number}

Returns model id number

Returns:

Model ID

Type
number

globj(group, Object)

manage the globj for this model in the possed modelGroup - if it has to be regenerated, remove and add

Parameters:
Name Type Description
group $3Dmol.Object3D
Object

options

hide()

Example
var element=$('#gldiv');
var viewer = $3Dmol.createViewer(element);
   var m = viewer.addModel();
   m.hide();
   viewer.render(callback);

removeAtoms(badatoms) → {removeAtoms}

Remove specified atoms from model

Parameters:
Name Type Description
badatoms type

list of atoms

Returns:
Type
removeAtoms

removegl(group)

Remove any renderable mol object from scene

Parameters:
Name Type Description
group $3Dmol.Object3D

selectedAtoms(sel) → {Array.<Object>}

return list of atoms selected by sel, this is specific to glmodel

Parameters:
Name Type Description
sel AtomSelectionSpec
Returns:
Type
Array.<Object>
Example
$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

Parameters:
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

Example
      viewer.addCylinder({start:{x:0.0,y:0.0,z:0.0},
                          end:{x:10.0,y:0.0,z:0.0},
                          radius:1.0,
                          fromCap:1,
                          toCap:2,
                          color:'red',
                          hoverable:true,
                          clickable:true,
                          callback:function(){ this.color.setHex(0x00FFFF00);viewer.render( );},
                          hover_callback: function(){ viewer.render( );},
                          unhover_callback: function(){ this.color.setHex(0xFF000000);viewer.render( );}
                         });
      viewer.addCylinder({start:{x:0.0,y:2.0,z:0.0},
                          end:{x:0.0,y:10.0,z:0.0},
                          radius:0.5,
                          fromCap:false,
                          toCap:true,
                          color:'teal'});
      viewer.addCylinder({start:{x:15.0,y:0.0,z:0.0},
                          end:{x:20.0,y:0.0,z:0.0},
                          radius:1.0,
                          color:'black',
                          fromCap:false,
                          toCap:false});
      viewer.render();

setColorByElement(sel, colors)

given a mapping from element to color, set atom colors

Parameters:
Name Type Description
sel type
colors type

setColorByFunction(sel, func)

Parameters:
Name Type Description
sel type

selection object

func type

function to be used to set the color

Deprecated:
  • use setStyle and colorfunc attribute
Example
$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();
    });

setCoordinates(str, format, callback)

Set coordinates for the atoms parsed from the prmtop file.

Parameters:
Name Type Description
str string

contains the data of the file

format string

contains the format of the file

callback function

function called when a inpcrd or a mdcrd file is uploaded

setFrame(framenum)

Sets model's atomlist to specified frame Sets to last frame if framenum out of range

Parameters:
Name Type Description
framenum number

model's atoms are set to this index in frames list

setHoverable(sel, hoverable, hover_callback, unhover_callback)

Set hoverable and callback of selected atoms

Parameters:
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

Example
     viewer.addCylinder({start:{x:0.0,y:0.0,z:0.0},
                         end:{x:10.0,y:0.0,z:0.0},
                         radius:1.0,
                         fromCap:1,
                         toCap:2,
                         color:'red',
                         hoverable:true,
                         clickable:true,
                         callback:function(){ this.color.setHex(0x00FFFF00);viewer.render( );},
                         hover_callback: function(){ viewer.render( );},
                         unhover_callback: function(){ this.color.setHex(0xFF000000);viewer.render( );}
                        });
     viewer.addCylinder({start:{x:0.0,y:2.0,z:0.0},
                         end:{x:0.0,y:10.0,z:0.0},
                         radius:0.5,
                         fromCap:false,
                         toCap:true,
                         color:'teal'});
     viewer.addCylinder({start:{x:15.0,y:0.0,z:0.0},
                         end:{x:20.0,y:0.0,z:0.0},
                         radius:1.0,
                         color:'black',
                         fromCap:false,
                         toCap:false});
     viewer.render();

setStyle(sel, style, add)

Set atom style of selected atoms

Parameters:
Name Type Description
sel AtomSelectionSpec
style AtomStyleSpec
add boolean

if true, add to current style, don't replace

Example
$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();
      });

toCDObject(whether) → {Object}

Convert the model into an object in the format of a ChemDoodle JSON model.

Parameters:
Name Type Description
whether boolean

or not to include style information. Defaults to false.

Returns:
Type
Object

vibrate(numFrames, amplitude)

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

Parameters:
Name Type Description
numFrames number

number of frames to be created, default to 10

amplitude number

amplitude of distortion, default to 1 (full)

Example
$3Dmol.download("pdb:4UAA",viewer,{},function(){  
  viewer.setStyle({},{stick:{}});
  viewer.vibrate(10, 1);
  viewer.animate({loop: "forward",reps: 1});
  viewer.zoomTo();
        viewer.render();
    });