Difference between revisions of "Recycling Corner"

From Jmol
Jump to navigation Jump to search
(moving long sections to subpages)
(reordering subsections)
 
(24 intermediate revisions by 3 users not shown)
Line 3: Line 3:
 
Feel free to add your material!
 
Feel free to add your material!
  
{{Jmol_Applications_Sections}}
 
 
For example:
 
For example:
  
Line 14: Line 13:
 
[[Image:Jmol_icon13.png]]
 
[[Image:Jmol_icon13.png]]
  
[[Image:Jmol_icon_13.ico|Windows icon]]; .ico files cannot be shown on this webpage, but you can download them.
+
[[Image:Jmol_icon_13.ico.zip|Windows icon]]; .ico files cannot be shown on this webpage, but you can download this one zipped.
  
 
for more icon formats, visit [http://biomodel.uah.es/Jmol/logos/ Angel's webpage]  
 
for more icon formats, visit [http://biomodel.uah.es/Jmol/logos/ Angel's webpage]  
Line 91: Line 90:
  
 
(''The word "spin" above can be changed to any other text you like.'')
 
(''The word "spin" above can be changed to any other text you like.'')
 
  
 
=== "Foolproof" spin toggle ===
 
=== "Foolproof" spin toggle ===
Line 99: Line 97:
  
 
Valid for recent versions of Jmol:
 
Valid for recent versions of Jmol:
 
 
<pre>
 
<pre>
 
jmolButton("if(_spinning);spin off;else;spin on;endif","toggle spin")
 
jmolButton("if(_spinning);spin off;else;spin on;endif","toggle spin")
 
</pre>
 
</pre>
 +
Or even more compact:
 +
<pre>
 +
jmolButton("spin @{!_spinning}","toggle spin")
 +
</pre>
 +
 
(If you prefer <code>jmolLink</code>, it can be used in the same manner. If you don't use <code>Jmol.js</code>, and you have a good reason for not using it, you will know how to modify this code.)
 
(If you prefer <code>jmolLink</code>, it can be used in the same manner. If you don't use <code>Jmol.js</code>, and you have a good reason for not using it, you will know how to modify this code.)
  
Line 142: Line 144:
  
 
=== Slider controls for Jmol ===
 
=== Slider controls for Jmol ===
==== Version (A) ====
+
See [[Recycling_Corner/Slider controls]]
This has an amazing look-and-feel. Uses javascript, Jmol.js and Walter Zorn's Drag'n'Drop & DHTML Library, &copy; Walter Zorn under GNU LGPL.
 
 
 
See it [http://biomodel.uah.es/Jmol/sliders/wzorn/slab-slider.htm in action].
 
 
 
Steps to follow:
 
 
 
# Download Walter Zorn's library from http://www.walterzorn.com/dragdrop/dragdrop_e.htm (You need the <code>wz_dragdrop.js</code> file.)
 
# Get a copy of the image files, [[Image:Track.gif]]<code>track.gif</code> and [[Image:Sliderthumb.gif]]<code>sliderthumb.gif</code>. You could use your own, but size is important since the code is related to it.
 
# Include this code in your webpage:
 
<pre>
 
<head>
 
<script src="../../Jmol.js" type="text/javascript"></script>
 
<script type="text/javascript">
 
/* Uses Walter Zorn's Drag'n'Drop & DHTML Library (GNU LGPL).
 
  Integration with Jmol by Angel Herráez.
 
*/
 
function slabSlider()
 
{
 
  jmolScript( 'slab ' + eval(100-(20+dd.elements.thumb.x-dd.elements.thumb.defx)) )
 
  document.getElementById("posi").innerHTML = 100-(20+dd.elements.thumb.x-dd.elements.thumb.defx)
 
}
 
</script>
 
</head>
 
 
 
<body>
 
<script type="text/javascript" src="wz_dragdrop.js"></script>
 
<script type="text/javascript">
 
jmolInitialize("../../")
 
jmolApplet(300, "load lysozyme.pdb; spacefill;")
 
</script>
 
<input type="button"  value="prepare for slabbing"
 
onClick='jmolScript("spin off; slab on; slab 80;"); document.getElementById("posi").innerHTML="80"; dd.elements.thumb.moveTo(dd.elements.track.x+20, dd.elements.track.y); '>
 
<br>
 
<img name="track" src="track.gif" width="104" height="29" alt="" title="" align="absmiddle">
 
<img name="thumb" src="sliderthumb.gif" width="18" height="29" alt="" title="move me" align="absmiddle">
 
<span id="posi">80</span>%
 
<br>
 
<input type="button" value="cancel slabbing"
 
onClick='jmolScript("slab off;")'>
 
 
 
<script type="text/javascript">
 
/*  Courtesy of Walter Zorn;
 
Drag'nDrop & DHTML Library  (c)Walter Zorn under the LGPL (Lesser General Public License, http://www.gnu.org/copyleft/lesser.html
 
*/
 
SET_DHTML("thumb"+MAXOFFLEFT+20+MAXOFFRIGHT+80+HORIZONTAL,"track"+NO_DRAG)
 
dd.elements.thumb.moveTo(dd.elements.track.x+20, dd.elements.track.y);
 
dd.elements.thumb.setZ(dd.elements.track.z+1);
 
dd.elements.track.addChild("thumb");
 
dd.elements.thumb.defx = dd.elements.track.x+20;
 
dd.elements.thumb.setDragFunc(slabSlider);
 
//dd.elements.thumb.setDropFunc(slabSlider); //alternative, if it cannot cope with the other
 
</script>
 
</body>
 
</pre>
 
Important Notes:
 
# You must adjust the path to <code>Jmol.js</code>, <code>jmolInitialize()</code> and <code>wz_dragdrop.js</code> according to your set-up.
 
# The order of the code element in the above example is crucial. In particular, wz_dragdrop.js must be included in the body, not in the head. If in the head, the slider works in Firefox and Safari, but '''not in Internet Explorer'''. Also, the block starting with SET_DHTML(...) must follow the block that displays the slider itself on the page.
 
 
 
==== Version (B) ====
 
This looks excellent too, and has some more versatility. Uses javascript, CSS, Jmol.js and WebFX Slider, &copy; Erik Arvidsson under Apache Software License.
 
 
 
See instructions and several examples [http://biomodel.uah.es/Jmol/sliders/ here], applied to slabbing, bond thickness, translucency, ribbon width and thickness.
 
 
 
  
 
=== Echoing PDB "Title" to the applet window ===
 
=== Echoing PDB "Title" to the applet window ===
Line 247: Line 186:
 
* [http://www.marietta.edu/%7Espilatrs/MnQuiry/JmolDemo/jmolImgCopy-test.html inserted into the same web page]
 
* [http://www.marietta.edu/%7Espilatrs/MnQuiry/JmolDemo/jmolImgCopy-test.html inserted into the same web page]
  
<br />
 
  
 
=== Opening a duplicate of the model in a resizable pop-up window ===
 
=== Opening a duplicate of the model in a resizable pop-up window ===
 
The model, with is current state, is duplicated or cloned into a new (pop-up) window so it may be displayed at a larger size (and the user may resize that window at will).
 
The model, with is current state, is duplicated or cloned into a new (pop-up) window so it may be displayed at a larger size (and the user may resize that window at will).
  
The classic version (not shown here) is good for Jmol.js-based JmolApplet.
+
See [[Recycling_Corner/Duplicate_Pop-up]]
 
 
This version is for [[JSmol]] (in either HTML5, Java or WebGL modalities).
 
  
You need a portion of JavaScript code included in your page and a separate html file (for the pop-up), also with the relevant code.
 
 
1. Code in your page:
 
<pre><script type="text/javascript">
 
var JSmolCloneData = {};
 
function cloneJSmol(JSmolObject) {
 
  var t = JSmolObject._jmolType; //temp
 
  if ( /_Canvas2D/.test(t) ) { t = 'HTML5'; }
 
  else if ( /_Canvas3D/.test(t) ) { t = 'WebGL'; }
 
  else if ( /_Applet/.test(t) ) { t = 'Java'; }
 
  else { t = null; }
 
  JSmolCloneData.type = t;
 
  JSmolCloneData.state = Jmol.getPropertyAsString(JSmolObject, 'stateInfo');
 
  window.open('JSmolPopup.htm','JSmolPopup','resizable, width=500, height=500');
 
}
 
</script>
 
 
<input type="button" value="clone JSmol in a popup window" onClick="cloneJSmol(myJmol)">
 
</pre>
 
 
Note: <code>myJmol</code> should be changed to whatever you have named your JSmol object - and it is the object itself, not a text string.
 
 
2. Source code of the {{file|JSmolPopup.htm}} file:
 
<pre><!DOCTYPE html>
 
<html>
 
<title>cloned JSmol</title>
 
<head>
 
<meta charset="utf-8">
 
<style type="text/css">
 
html , body { height:100%; overflow:hidden; margin:0; padding:0; }
 
</style>
 
<script type="text/javascript" src="JSmol.min.js"></script>
 
<script type="text/javascript">
 
if (opener.JSmolCloneData.type == 'WebGL') {
 
  document.writeln('<script src="js/JSmolThree.js" type="text/javascript"><'+'/script>');
 
  document.writeln('<script src="js/JSmolGLmol.js" type="text/javascript"></'+'script>');
 
}
 
</script>
 
</head>
 
<body>
 
<script type="text/javascript">
 
var cloneInfo = {
 
  height: '100%',
 
  width: '100%',
 
  isSigned: false,
 
  jarFile: 'JmolApplet0.jar',
 
  jarPath: 'java',
 
  j2sPath: 'j2s',
 
  script: opener.JSmolCloneData.state.replace(/zoomLarge true/i,'zoomLarge false'),
 
  use: opener.JSmolCloneData.type
 
};
 
Jmol.getApplet("JSmolClone", cloneInfo);
 
</script>
 
</body>
 
</pre>
 
 
Note: you need to adjust the paths to {{file|JSmol.min.js}}, {{folder|j2s}} and {{folder|java}}
 
 
<br />
 
  
 
=== Style transitions ===
 
=== Style transitions ===
Line 363: Line 240:
 
  echo "\u2192 is an arrow pointing right";
 
  echo "\u2192 is an arrow pointing right";
 
  echo "\u00B2 is the superscript two, or square power";
 
  echo "\u00B2 is the superscript two, or square power";
 +
Note that, in these cases, the use of quotes surrounding the echoed text is compulsory.
  
 
=== Center of mass ===
 
=== Center of mass ===
 
Jmol centers the model around its geometric center, i.e. the center of the boundbox. If you are interested in the mass center of the molecule:
 
Jmol centers the model around its geometric center, i.e. the center of the boundbox. If you are interested in the mass center of the molecule:
  
1. Run or define or load from a script file this content in JmolScript:
+
See [[Recycling_Corner/Center_Of_Mass]]
<pre>
+
 
function CoM(atomSet) {
+
 
  if (atomSet=="") {
+
=== RIBOZOME - an Alpha Helix Generator script ===
    print "Warning: there are no atoms in the provided set. Using all atoms in the model.";  
+
Creates an alpha helix from a user input string.
    atomSet = {*};  
+
 
  }
+
A script for the Jmol Application and also applied to a webpage with a J(S)mol object.
  var n = atomSet.size;
+
 
  var mx = 0; var my = 0; var mz = 0;
+
See [[Recycling_Corner/Alpha_Helix_Generator]]
  for (i=0; i<n; i+=1) {
+
 
    mx = mx + atomSet[i].x * atomSet[i].mass;
+
=== POLYMERAZE - an DNA Double Helix Generator script ===
    my = my + atomSet[i].y * atomSet[i].mass;
+
Creates a DNA or RNA single or double helix from a user input string.
    mz = mz + atomSet[i].z * atomSet[i].mass;
+
 
  }
+
See [[Recycling_Corner/DNA_Generator]]
  var m = atomSet.mass.sum;
+
 
  mx = mx / m;
+
 
  my = my / m;
+
=== Drawing objects ===
  mz = mz / m;
+
==== Cylinder ====
  return {@mx @my @mz};
+
To draw a cylinder, you need this information:
}
+
* two points that define the axis of the cylinder and its length
 +
** each of these may be an XYZ coordinate, an atom, the center of an atom set, or a reference to another previously drawn object
 +
* the diameter of the cylinder (in Angstroms)
 +
Examples (with two XYZ points):
 +
// open cylinder (tube):
 +
draw myCyl diameter 6.0 color translucent cyan cylinder {13 1.58 9.3} {15 1.21 15} mesh nofill;
 +
// closed at both ends:
 +
draw myCyl diameter 6.0 color translucent cyan cylinder {13 1.58 9.3} {15 1.21 15} fill;
 +
// closed at one end:
 +
draw myCyl diameter 6.0 color translucent cyan cylinder {13 1.58 9.3} {15 1.21 15} fill;
 +
draw myCap diameter 6.0 color opaque cyan circle {13 1.58 9.3} {15 1.21 15};
 +
For options, see documentation for the [{{ScriptingDoc}}#draw draw] command.
 +
 
 +
==== Ellipsoid ====
 +
Starting from these:
 +
* two points that define the main axis of the ellipsoid and its length
 +
** each of these may be an XYZ coordinate, an atom, the center of an atom set
 +
 
 +
Example, with two atoms (numbers 3 and 7) at the ends of the ellipsoid:
 +
atA = {atomNo=3};
 +
atB = {atomNo=7};
 +
dC = {(atA,atB)}; // defines the center, midpoint between both atoms
 +
dE = 0.5; // eccentricity (<1 for cigar-shaped, 1 for a sphere, >1 for disk-shaped)
 +
dR = 7; // resolution of the mesh or surface
 +
dX = {atA}.x - {atB}.x; // for defining the orientation
 +
dY = {atA}.y - {atB}.y;
 +
dZ = {atA}.z - {atB}.z;
 +
dL = {atA}.xyz.distance({atB}.xyz) /2; // length of the main ellipsoid axis
 +
isosurface myEllipA color blueTint scale @dL resolution @dR center @dC ellipsoid {@dX @dY @dZ @dE} mesh nofill;
 +
isosurface myEllipB color translucent 0.7 lime scale @dL resolution @dR center @dC ellipsoid {@dx @dy @dz @dE} fill;
 +
Resolution and eccentricity will need to be adjusted depending on your case.
 +
 
 +
=== Element legend ===
 +
This will work with any loaded molecule (it automatically reads the list of elements present).
 +
 
 +
''It requires Jmol 14.6.0 or later.''
  
function drawCoM(atomSet) {
+
Use either with <code>color echo black; background white; </code>
  draw ctr diameter 0.9 color translucent yellowTint @{CoM(atomSet)};
+
or with <code>color echo white; background black; </code>
}
+
function createElementKey() {
 +
  var y = 90;
 +
  for (var e in {*}.element.pivot) {
 +
    var c = {element=@e}.color;
 +
    draw id @{"d_"+ e} diameter 2 [90 @y %] color @c;
 +
    set echo id @{"e_" + e} [91 @{y-1} %];
 +
    echo @e;
 +
    font echo 24 bold sans;
 +
    y -= 5;
 +
  }
 +
}
 +
createElementKey;
  
function axesCoM(atomSet) {
+
=== Test if a file exists before displaying it ===
   axes center @{CoM(atomSet)};
+
==== Using HTML, Javascript and Jmol scripting: ====
   axes on;
+
A Javascript function:
 +
<pre>function loadFile(x) {
 +
   var s = 'filedat = load("' + x  + '"); exists = true; '+
 +
  'if ( filedat.find("NetworkError") != 0 ) { exists = false; } '+
 +
  'elseif ( filedat.find("Not Found") != 0 ) { exists = false; } '+
 +
  'if ( exists ) { load var filedat; } else { zap; set echo e0 50% 50%; set echo e0 center; echo "This file cannot be found"; }';
 +
   Jmol.script(myJmol, s);
 
}
 
}
 
</pre>
 
</pre>
  
2. after that has been executed, you can
+
And the HTML element calling it:
* retrieve the coordinates of the center:
+
<pre><input type="button" onClick="loadFile('test.mol')" value="load it">
<pre>c = CoM(); // using all atoms
 
print @c;
 
c = CoM( {_C},{_O} ); // just the carbon and oxygen atoms
 
print @c;
 
</pre>
 
* draw a sphere in the center of mass:
 
<pre>drawCoM();
 
drawCoM( {_C},{_O} );
 
</pre>
 
* place axes in the center of mass:
 
<pre>axesCoM();
 
axesCoM( {_C},{_O} );
 
 
</pre>
 
</pre>
  
 +
==== Using Jmol callbacks to Javascript: ====
 +
Another possibility is to use [[Jmol_JavaScript_Object/Info#Callbacks|loadStructCallback]] to detect the failure in loading the file. For instance:
  
=== RIBOZOME - an Alpha Helix Generator script ===
+
In Javascript:
Creates an alpha helix from a user input string.
+
<pre>
<pre>#  RIBOZOME - Jmol script by Ron Mignery with help from Dr. Angel Herráez
+
Info.loadstructcallback = 'loadCB';
#  v1.2 beta    10/23/2013
+
function loadCB() {
#
+
if (arguments[5]==0 && !window['noFile']) { //avoid repeated callbacks by zap
#  New in v1.2 beta:
+
   Jmol.script(myJmol, 'zap; set echo e0 50% 50%; set echo e0 center; echo "This file cannot be found";');
#      No longer zaps existing atoms
+
   window['noFile'] = true;
#      Now adds on to existing helix on subsequent runs
+
} else {
#      Fixes proline cross-link bug with XXXXPXP
+
   window['noFile'] = false;
#      Localizes variables and globalizes constants
+
}
#
+
}
#  RIBOZOME takes a string message encoding an amino acid (aa) sequence
+
</pre>
#   and generates a corresponding alpha helix one aa at a time from the
 
#  N terminus to the C terminus rotating the emerging helix as it goes.
 
#
 
#  The message is a string entered by the user at a prompt.
 
#  It may be typed in or pasted in and be of any length
 
#  If the message is prepended with <C>: (where C is any single letter)
 
#  then the chain is so labeled and separated from existing chains
 
#  if different from the first chain.
 
#
 
#  The IUPAC/IUBMB 1 letter code is used:
 
#   A=ALAnine B=GLutam?X* C=CYSteine D=ASPartate E=GLUtamate
 
#  F=PHEnylalanine G=GLYcine H=HIStidine I=IsoLEucine K=LYSine
 
#   L=LEUcine M=METhionine N=ASparagiNe O=PYrroLysine*** P=PROline
 
#  Q=GLutamiNe R=ARGinine S=SERine T=THReonine U=SElenoCysteine
 
#  V=VALine W=TRyPtophan X=UNKnown Y=TYRosine Z=ASpar?X**
 
#    *Either GLU or GLN: drawn as GLN with chi3 flipped
 
#    **Either ASP or ASN: drawn as ASN with chi3 flipped
 
#  ***Not supported: drawn as ALA
 
  
# The following constant values determine the pitch of the alpha helix
+
==== Using only Jmol scripting: ====
gPHI = -57    # Dihedral angle of N-CA bond (nominally -57)
+
Javascript:
gPSI = -47    # Dihedral angle of CA-C bond (nominally -47)
+
<pre>Info.script = 'function loadFile(x) { filedat=load(x); exists=true; '+
gOMEGA = 180    # Dihedral angle of the peptide bond (nominally 180)
+
'if (filedat.find("NetworkError")!=0) {exists=false;} elseif (filedat.find("Not Found")!=0) {exists=false;}; '+
gPEPTIDE_ANGLE = 110    # C-N-CA angle (nominally 110)
+
'if (exists) {load var filedat;} else {zap; set echo e0 50% 50%; set echo e0 center; echo "This file cannot be found";} }; ';
gPRO_BUMP = -10 # Psi angle change increment to N-3psi when N is Pro
+
</pre>
gCHAIN = 'A'   # The chain id
 
  
# Lookup 3 letter code from 1 letter code
+
And HTML:
g3from1 = {"A":"ALA", "B":"GLX","C":"CYS", "D":"ASP","E":"GLU", "F":"PHE",
+
<pre>
    "G":"GLY", "H":"HIS","I":"ILE", "K":"LYS","L":"LEU", "M":"MET",
+
<p>This file exists in the same folder
    "N":"GLN", "O":"PYL","P":"PRO", "Q":"GLN","R":"ARG", "S":"SER",
+
<script type="text/javascript">Jmol.jmolButton(myJmol, "loadFile('test.mol')", "load it");</script></p>
    "T":"THR", "U":"SEC","V":"VAL", "W":"TRP","X":"UNK", "Y":"TYR", "Z":"ASX"}
+
<p>This file  does not exist
 +
<script type="text/javascript">Jmol.jmolButton(myJmol, "loadFile('test2.mol')", "load it");</script></p>
 +
</pre>
  
# Generate PDB atom record
+
==== Using an AJAX call: ====
function genAtom(e, aa, i, xyz) {
+
Javascript:
    gA format("ATOM  %5d %4s %3s ", gN, e, aa )        
+
<pre>function loadFile(pathFilenameExt) {
     gA +=  format("%s%4d    %8.3f", gCHAIN, i, xyz[1] )        
+
var req = new XMLHttpRequest();
    gA += format("%8.3f%8.3f\n", xyz[2], xyz[3] )
+
  req.onreadystatechange = function() {
    gn++
+
  if (this.readyState != 4) { return; } /*not finished yet*/
    return gA
+
  if (this.status == 200) {
};
+
    Jmol.script(myJmol, 'load "' + pathFilenameExt + '";');
 +
  } else {
 +
     Jmol.script(myJmol, 'zap; set echo e0 50% 50%; set echo e0 center; echo "This file cannot be found";');
 +
  }
 +
};
 +
  req.open('GET', pathFilenameExt, false);
 +
req.send();
 +
}
 +
</pre>
  
# Generate a PDB amino acid record set
+
And the HTML:
function genAA(i, aa) {    # Writes globals gA and gN
+
<pre><p>This file exists in the same folder <input type="button" onClick="loadFile('test.mol')" value="load it"></p>
 +
<p>This file does not exist <input type="button" onClick="loadFile('test2.mol')" value="load it"></p>
 +
</pre>
  
    # From constructed AAs
+
''(Based on a contribution by Bilal Nizami)''
    var N0 = [0.0, 0.0, 0.0]
 
    var CA = [ 0.200, 1.174, 0.911 ]
 
    var C  = [ -1.110, 1.668, 1.425 ]
 
    var O  = [ -1.320, 1.693, 2.62 ]
 
    var CB = [ 1.062, 2.1950, 0.230 ]
 
   
 
    var G1 = [ 2.359, 1.607, -0.344]
 
    var G2 = [ 1.363, 3.336, 1.157 ]
 
    var D1 = [ 3.222, 2.656, -1.048 ]
 
    var D2 = [ 3.143, 0.904, 0.725 ]
 
    var E1 = [ 3.645, 3.749, -0.167 ]
 
    var E2 = [ 2.491, 3.234, -2.249 ]
 
    var Z  = [ 4.470, 4.717, -0.885 ]
 
    var H1 = [ 4.450, 6.006, -0.220 ]
 
    var H2 = [5.833, 4.228, -0.984 ]
 
   
 
    var Gp = [ 2.008, 1.24, -0.46 ]
 
    var Dp = [1.022, 0.213, -1.031 ]
 
   
 
    var Gfy  = [ 2.368, 1.471, -0.0152 ]
 
    var D1fy = [ 3.346, 1.524, 0.921 ]
 
    var D2fy = [ 2.493, 0.516, -1.151 ]
 
    var E1fy = [ 4.513, 0.615, 0.8244 ]
 
    var E2fy = [ 3.528, -0.336, -1.206 ]
 
    var Zfy  = [ 4.588, -0.285, -0.168 ]
 
    var Hfy = [ 5.738, -1.245, -0.233 ]
 
   
 
    var Ghw  = [ 2.406, 1.626, -0.134 ]
 
    var D1hw = [3.498, 1.936, 0.675]
 
    var D2hw = [ 2.713, 0.901, -1.211 ]
 
    var E1hw = [ 4.160, 0.518, -1.178 ]
 
    var E2hw = [ 4.622, 1.160, 0.0816 ]
 
    var E3hw = [ 3.789, 2.523, 1.944 ]
 
    var Z2hw = [ 5.973, 1.177, 0.689 ]
 
    var Z3hw = [ 5.014, 2.550, 2.503 ]
 
    var H2hw = [ 6.153, 1.846, 1.844 ]
 
   
 
    #N1 = [ 2.069, -2.122, -0.554]
 
   
 
    # Build PDB atom records common to all AAs
 
    a3 = g3from1[aa]
 
    if (a3 = "") {
 
        a3 = "UNK"
 
    }
 
    print format("+ %s%d/%d", a3, i, gSeq.count + gResno)
 
    gA = genAtom(" N  ", a3, i, N0)
 
    gA += genAtom(" CA ", a3, i, CA)
 
    gA += genAtom(" C  ", a3, i, C)
 
    gA += genAtom(" O  ", a3, i, O)
 
    if ((aa != 'G') && (aa != 'X')) {
 
        gA += genAtom(" CB ", a3, i, CB)
 
    }
 
  
    # Now add AA specific atom records
+
=== Improved lighting ===
    switch (aa) {
+
The lighting of atoms, bonds and ribbons and the thickness of ribbons may be customized to provide a nicer look, by adjusting several settings. Here is an example:
    case 'A' :
 
        break;
 
    case 'B' :
 
        gA += genAtom(" CG ", a3, i, G1)
 
        gA += genAtom(" CD ", a3, i, D1)
 
        gA += genAtom(" OE1", a3, i, E2)    # GLN with Es switched
 
        gA += genAtom(" NE2", a3, i, E1)
 
        break;
 
    case 'C' :
 
        gA += genAtom(" SG ", a3, i, G2)
 
        break;
 
    case 'D' :
 
        gA += genAtom(" CG ", a3, i, G1)
 
        gA += genAtom(" OD1", a3, i, D1)
 
        gA += genAtom(" OD2", a3, i, D2)
 
        break;
 
    case 'E' :
 
        gA += genAtom(" CG ", a3, i, G1)
 
        gA += genAtom(" CD ", a3, i, D1)
 
        gA += genAtom(" OE1", a3, i, E1)
 
        gA += genAtom(" OE2", a3, i, E2)
 
        break;
 
    case 'F' :
 
        gA += genAtom(" CG ", a3, i, Gfy)
 
        gA += genAtom(" CD1", a3, i, D1fy)
 
        gA += genAtom(" CD2", a3, i, D2fy)
 
        gA += genAtom(" CE1", a3, i, E1fy)
 
        gA += genAtom(" CE2", a3, i, E2fy)
 
        gA += genAtom(" CZ ", a3, i, Zfy)
 
        break;
 
    case 'G' :
 
        break;
 
    case 'H' :
 
        gA += genAtom(" CG ", a3, i, Ghw)
 
        gA += genAtom(" ND1", a3, i, D1hw)
 
        gA += genAtom(" CD2", a3, i, D2hw)
 
        gA += genAtom(" CE1", a3, i, E2hw)
 
        gA += genAtom(" NE2", a3, i, E1hw)
 
        break;
 
    case 'I' :
 
        gA += genAtom(" CG1", a3, i, G1)
 
        gA += genAtom(" CG2", a3, i, G2)
 
        gA += genAtom(" CD1", a3, i, D1)
 
        break;
 
    case 'K' :
 
        gA += genAtom(" CG ", a3, i, G1)
 
        gA += genAtom(" CD ", a3, i, D1)
 
        gA += genAtom(" CE ", a3, i, E1)
 
        gA += genAtom(" NZ ", a3, i, Z)
 
        break;
 
    case 'L' :
 
        gA += genAtom(" CG1", a3, i, G1)
 
        gA += genAtom(" CD1", a3, i, D1)
 
        gA += genAtom(" CD2", a3, i, D2)
 
        break;
 
    case 'M' :
 
        gA += genAtom(" CG ", a3, i, G1)
 
        gA += genAtom(" SD ", a3, i, D1)
 
        gA += genAtom(" CE ", a3, i, E1)
 
        break;
 
    case 'N' :
 
        gA += genAtom(" CG ", a3, i, G1)
 
        gA += genAtom(" OD1", a3, i, D1)
 
        gA += genAtom(" ND2", a3, i, D2)
 
        break;
 
    case 'P' :
 
        gA += genAtom(" CG ", a3, i, GP)
 
        gA += genAtom(" CD ", a3, i, DP)
 
        break;
 
    case 'Q' :
 
        gA += genAtom(" CG ", a3, i, G1)
 
        gA += genAtom(" CD ", a3, i, D1)
 
        gA += genAtom(" OE1", a3, i, E1)
 
        gA += genAtom(" NE2", a3, i, E2)
 
        break;
 
    case 'R' :
 
        gA += genAtom(" CG ", a3, i, G1)
 
        gA += genAtom(" CD ", a3, i, D1)
 
        gA += genAtom(" NE ", a3, i, E1)
 
        gA += genAtom(" CZ ", a3, i, Z)
 
        gA += genAtom(" NH1", a3, i, H1)
 
        gA += genAtom(" NH2", a3, i, H2)
 
        break;
 
    case 'S' :
 
        gA += genAtom(" OG ", a3, i, G1)
 
        break;
 
    case 'T' :
 
        gA += genAtom(" OG1", a3, i, G1)
 
        gA += genAtom(" CG2", a3, i, G2)
 
        break;
 
    case 'U' :
 
        gA += genAtom("SeG ", a3, i, G1)
 
        break;
 
    case 'V' :
 
        gA += genAtom(" CG1", a3, i, G1)
 
        gA += genAtom(" CG2", a3, i, G2)
 
        break;
 
    case 'W' :
 
        gA += genAtom(" CG ", a3, i, Ghw)
 
        gA += genAtom(" CD1", a3, i, D1hw)
 
        gA += genAtom(" CD2", a3, i, D2hw)
 
        gA += genAtom(" CE2", a3, i, E2hw)
 
        gA += genAtom(" NE1", a3, i, E1hw)
 
        gA += genAtom(" CE3", a3, i, E3hw)
 
        gA += genAtom(" CZ2", a3, i, Z2hw)
 
        gA += genAtom(" CZ3", a3, i, Z3hw)
 
        gA += genAtom(" CH2", a3, i, H2hw)
 
        break;
 
    case 'X' :
 
        gA += genAtom(" Xx ", a3, i, CB)
 
        break;
 
    case 'Y' :
 
        gA += genAtom(" CG ", a3, i, Gfy)
 
        gA += genAtom(" CD1", a3, i, D1fy)
 
        gA += genAtom(" CD2", a3, i, D2fy)
 
        gA += genAtom(" CE1", a3, i, E1fy)
 
        gA += genAtom(" CE2", a3, i, E2fy)
 
        gA += genAtom(" CZ ", a3, i, Zfy)
 
        gA += genAtom(" OH ", a3, i, Hfy)
 
        break;
 
    case 'Z' :
 
        gA += genAtom(" CG ", a3, i, G1)
 
        gA += genAtom(" OD1", a3, i, D2)    # ASN with Ds switched
 
        gA += genAtom(" ND2", a3, i, D1)
 
        break;
 
    default :
 
        break;
 
    }
 
  
    return gA
+
[[File:Fast, fancy, shiny.png]]
};
 
  
# Generate an alpha helix
+
[[File:Fast, fancy, shiny ball-and-stick.png]]
function genAlpha(gSeq) {
 
  
    gN = all.count    + 1 # global new N atom index
+
Default:
 +
reset lighting; set cartoonsFancy off; set hermiteLevel 0; set antialiasDisplay off;
  
    # Find last linkable N if any
+
"Fast": (quick rendering, same as default except antialias is applied for a better comparison with the other two)
    gResno = 0    # global pre-existing AA count
+
  reset lighting; set cartoonsFancy off; set hermiteLevel 0; set antialiasDisplay on;
    var pn = 1    # previous gN
 
    for (var i = all.count-1; i  > 0; i--) {
 
   
 
        # If found
 
        if (distance({atomno=i}, {0,0,0}) < 0.1) {
 
            pn = i
 
           
 
            # If new chain, separate from existing chain
 
            if ({atomno=i}.chain != gCHAIN) {
 
                select all
 
                translateselected {2.069, -2.122, -0.554 } #N1
 
            }
 
            else {
 
                gResno = {atomno=i}.resno
 
            }
 
            break;
 
        }
 
    }
 
  
    # For each aa
+
"Fancy":  (relevant only for cartoons, without effect on atoms and bonds)
    set appendnew false
+
reset lighting; set cartoonsFancy on; set hermiteLevel 20; set antialiasDisplay on;
    var nn = gN    # new N
 
    for (var i = 1; i <= gSeq.count; i++) {
 
  
        # Move polypeptide C to bond distance from new AA N
+
"Shiny": (adds light and shadow effects)
        select all
+
(more similar to rendering in other software like e.g. Chimera)
        fix none
+
set ambientPercent 25; set specularPower 100; set specularPercent 22; set specularExponent 4; set cartoonsFancy on; set antialiasDisplay on; set hermiteLevel 20;
        translateselected {2.069, -2.122, -0.554 } #N1
 
  
        # Gen AA
+
[[File:Shiny-rendering-spacefill.png]]
        gA = "data \"append aa\"\n"    # global PDB atom record
 
        gA += genAA(i + gResno, gSeq[i]);    # gN is updated in subroutine
 
        gA += "end \"append aa\""
 
        script inline @{gA}
 
  
        # If PRO ahead
+
Note: Jmol defaults may be restored using <code>reset lighting</code> which applies these values:
        var pb = 0
+
{| style="border-spacing:8px 0;"
        if ((gSeq.count - i) >= 2) {
+
|-  
            if (gSeq[i + 2] == 'P') {
+
|| set
                pb = gPRO_BUMP
+
|| ambientPercent
            }
+
|| diffusePercent
        }
+
|| specular
 +
|| specularPercent
 +
|| specularPower
 +
|| specularExponent
 +
|-
 +
| align=center| default value:
 +
| align=center| 45
 +
| align=center| 84
 +
| align=center| on
 +
| align=center| 22
 +
| align=center| 40
 +
| align=center| 6
 +
|-
 +
|}
  
        # If not first AA
+
{| style="border-spacing:8px 0; margin-top:1.4em;"
        if (nn > 1) {
+
|-
 +
|| set
 +
|| zDepth
 +
|| zSlab
 +
|| zShade
 +
|| zShadePower
 +
|| celShading
 +
|| celShadingPower
 +
|- style=""
 +
| align=center| default value:
 +
| align=center| 0
 +
| align=center| 50
 +
| align=center| off
 +
| align=center| 3
 +
| align=center| off
 +
| align=center| 10
 +
|-
 +
|}
  
            # Gen axis on new N perpendicular to the plane
+
For more details about each of these settings, see the  
            # containing atoms nn, pn+2 and nn+1
+
[{{ScriptingDoc}}#setlighting Scripting Documentation].
            var v1={atomno = @{pn+2}}.xyz - {atomno = nn}.xyz
 
            var v2={atomno = @{nn+1}}.xyz - {atomno = nn}.xyz
 
            var axis = cross(v1, v2)
 
           
 
            # Center on atom previous C
 
            axis += {atomno = @{pn+2}}.xyz
 
  
            # Rotate the polypeptide N on the new AA C to tetrahedral (nominally 110)
+
=== Extract phi and psi values ===
            select atomno < nn
+
The dihedral angles phi and psi are known in Jmol, as properties of each amino acid residue in a protein, which are copied to properties of each atom in that residue.
            fix atomno >= nn
 
            rotateselected @axis {atomno = nn} @{gPEPTIDE_ANGLE - 69.3}
 
           
 
            # Make omega dihedral = gOMEGA (nominally 180)
 
            rotateselected {atomno=@{pn+2}} {atomno=nn} @{gOMEGA - 147.4}
 
  
            # Make the new phi dihedral = gPHI (nominally -57)
+
These scripts may be used to extract their values into an array:
            rotateselected {atomno = nn} {atomno = @{nn+1}} @{gPHI - 8.7}
 
  
            # Make the old psi dihedral = gPSI (nominally -47)
+
<table>
            select atomno < @{pn+2} && atomno != @{pn+3}
+
<tr>
            rotateselected {atomno=@{pn+1}} {atomno=@{pn+2}} @{gPSI + 33.4 + pb}
+
<td style="vertical-align:top;padding-right:2em;">For the first polymer in the first model in the loaded file:
        }
+
p = getProperty("polymerinfo.models[1].polymers[1].monomers").select("psi,phi")
       
+
p will be an associative array, one element per residue, each one with keys "phi" and "psi" and their values.
        # Step new and previous N
+
</td>
        pn = nn
+
<td>Result for the first 2 and last 2 residues:
        nn = gN
+
print p
 +
  {
 +
    "psi"  :  135.30487
 +
  }
 +
  {
 +
    "phi"  :  -103.61969
 +
    "psi"  :  110.173744
 +
  }
 +
...
 +
  {
 +
    "phi"  :  -81.423874
 +
    "psi"  :  131.89566
 +
  }
 +
  {
 +
    "phi"  :  -166.42226
 +
  }
 +
</td>
 +
</tr>
 +
</table>
  
        # Make the peptide bond
+
<table>
        connect
+
<tr>
    }
+
<td style="vertical-align:top;padding-right:2em;">Another way, which will read all protein chains present:
   
+
<pre>ph = [];
    # Clean up
+
ps = [];
    connect ([UNK].CA) ([UNK].Xx and within(group, _1))
+
n1 = {protein}.resno.min;
    select all
+
n2 = {protein}.resno.max;
    fix none
+
for (r=n1; r<=n2; r++) {
    print format("%d atoms generated", gN)
+
ph.push({resno=r}.phi);
 +
ps.push({resno=r}.psi);
 
}
 
}
 +
</pre>
 +
</td>
 +
<td>Result:
 +
print ph.join("\n")
 +
NaN
 +
-34.539898
 +
...
 +
-81.423874
 +
-166.42226
  
echo Generating Alpha Helix
+
print ps.join("\n")
 +
135.30487
 +
36.724583
 +
...
 +
131.89566
 +
NaN
 +
</td>
 +
</tr>
 +
</table>
  
# Get the sequence from the user
+
=== Front of the molecule, selecting (by percentage) ===
gSeq = prompt("Enter AA sequence (1 char coded)", "")%9999%0
 
if (gSeq.count > 0) {
 
    if (gSeq[2] == ':') {
 
        gCHAIN = gSeq[1]
 
        gSeq[1] = ' '
 
        gSeq[2] = ' '
 
        gSeq = gSeq%0
 
    }
 
    print format ("Sequence=%s  phi=%d  psi=%d", gSeq, gPHI, gPSI)
 
    print format ("chain=%s peptide angle=%d  pro bump=%d", gCHAIN, gPEPTIDE_ANGLE, gPRO_BUMP)
 
    genAlpha(gSeq)
 
}
 
</pre>
 
  
<br />
+
The Jmol function at [[Recycling_Corner/Front_Selection]] selects a specified percentage of the front of the molecule, according to the orientation of the molecule when the function is executed.
  
 
== Custom pop-up menus ==
 
== Custom pop-up menus ==
Starting on v. 11.3.15, Jmol (both application and applet) allows a customized pop-up menu instead of the standard default menu.
+
Jmol (both application and applet) allows a customized pop-up menu instead of the standard default menu.
 
Their definition and use are explained in [[Custom Menus]].
 
Their definition and use are explained in [[Custom Menus]].
  
 
Examples:
 
Examples:
* Default menu is built using this: [http://jmol.svn.sourceforge.net/viewvc/jmol/trunk/Jmol/jmol.mnu Jmol.mnu]
+
* Default menu is built using this: [{{SVN Trunk}}Jmol/jmol.mnu jmol.mnu]
 
* An example of custom menu: [[test.mnu]]
 
* An example of custom menu: [[test.mnu]]
  

Latest revision as of 18:11, 13 September 2021

This section intends to collect material by some users that may be useful to other users.

Feel free to add your material!

For example:

Jmol logos, banners, icons

New 2013 Jmol icon and logos

Icon, png:

Jmol icon13.png

File:Jmol icon 13.ico.zip; .ico files cannot be shown on this webpage, but you can download this one zipped.

for more icon formats, visit Angel's webpage

Logos and banners:

Jmol logo13.png JSmol logo13.png

'Made with Jmol' banners, in several languages: Jmol_Images

Older versions

Old logos and icons


Templates for creating Jmol webpages

Jmol_Web_Page_Maker

Jonathan Gutow has written a Java program that automates generation of webpages that include Jmol. The two templates below are among the types of web pages that can be generated. When using Jmol_Web_Page_Maker for the templates below, you can choose the view(s) to be displayed inside the Jmol application and have the necessary scripts, images plus .html code generated and saved automatically. Visit his website.

This is now superceeded by the "export to web page" ability included within recent versions of Jmol application (11.3.x).

Easy assignments for students or quick building of a simple page!

SChiSM2

SChiSM2 is a program running in a web server that lets you easily create a web page that includes interactive molecular models using JmolApplet.

S. Cammer (2007) SChiSM2: creating interactive web page annotations of molecular structure models using Jmol. Bioinformatics 23:383-384. doi:10.1093/bioinformatics/btl603 [1]

Jmol "pop-up" and "pop-in"

Delays the appearance of Jmol panel until the user requests it. An image or caption is shown and upon user's choice it is replaced by the applet.

No more waiting for Java and Jmol to load if you are not interested in the 3D model!

Two methods have been developed:

  • Method A - versatile: The user clicks to see the 3D model, and chooses whether it will be opened inline within the page (“pop-in”), or in a common pop-up window, or in separate pop-up windows for each model. (Uses <iframe>.)
  • Method B - simpler: The user clicks to see the 3D model, always inline within the page (“pop-in”). (Uses <div>.) (A similar method is used on Jmol home webpage.)

You can find more details, demo pages and downloadable templates for both methods at Biomodel website.

For an alternative method, see Bill Reusch's page that uses innerHTML.

For other pop-up solutions, see also below.

Dynamically resized panels layout

Six templates for dividing the screen into two or more panels, either for Jmol or for content, all sized in percent relative to window size, using the whole window space, and automatically resized when the window is resized; no scrollbars in Jmol section, scrollbars in content if needed, no duplicate parallel scrollbars.

No more guessing the user's screen resolution, browser chrome, default font size!

Resizable-panels.png

You can find more details, demo pages and downloadable templates at Biomodel website.

Reusable scripts

Molecule color picker

Molcolpicker.gif Appcolpicker.gif

The code below was used to create the palettes shown above. It's a pure javascript color picker that can be used for changing color of selected part of molecule, applet background, or any feature of the model (cartoons, surfaces, etc.).

Sample of use, JavaScript code needed, example page: Recycling_Corner/Molecule_color_picker

"Basic" spin toggle

Quite trivial, but compact and useful. However, if other scripts, controls, or the user change the spin status, the checkbox will need to be reset accordingly using javascript. (To avoid this limitation, see the "foolproof" solution below)

It will work with any version of Jmol (as long as Jmol.js is being used in the web page).

jmolCheckbox("spin on", "spin off", "spin", false)

if the model is initially not spinning (the default);

or

jmolCheckbox("spin on", "spin off", "spin", true)

if the model is initially spinning (due to another script).

(The word "spin" above can be changed to any other text you like.)

"Foolproof" spin toggle

Reads the current spin status from the applet and changes it, so it can cope with any other previous change via script, popup menu, page controls, etc.

The best and simplest trick:

Valid for recent versions of Jmol:

jmolButton("if(_spinning);spin off;else;spin on;endif","toggle spin")

Or even more compact:

jmolButton("spin @{!_spinning}","toggle spin")

(If you prefer jmolLink, it can be used in the same manner. If you don't use Jmol.js, and you have a good reason for not using it, you will know how to modify this code.)

(The words "toggle spin" above can be changed to any other text you like.)

The old trick:

Only compatible with Jmol 11.x (as long as Jmol.js is being used in the web page).

jmolButton("show spin", "toggle spin")

(If you prefer jmolLink, it can be used in the same manner.)

(The words "toggle spin" above can be changed to any other text you like.)

You must include these additional pieces of code:

Somewhere between <script> tags (recommended: within the head section):

function messageProcess(a_,b_)
{	// Convert both parameters from Java strings to JavaScript strings:
        var a = (""+a_).substring("jmolApplet".length)	
        var b = ""+b_
        // a_ will start with "jmolApplet": strip and leave just the ID part
	/*  SPIN DETECTION AND TOGGLE */
	if ( b.indexOf("set spin") != -1 )
	{	if ( b.indexOf("spin on") != -1 ) //was spinning
		{	jmolScript("spin off", a) 
		}
		else //was not spinning
		{ 	jmolScript("spin on", a) 
		}
	}
	/*  END of SPIN DETECTION AND TOGGLE  */
}

and somewhere between <script> tags, after the call to jmolInitialize() and before the call to jmolApplet():

jmolSetCallback("messageCallback", "messageProcess")

(The word "messageProcess" above can be changed to any other text you like, as long as it is the same in the above two sections of code.)

Slider controls for Jmol

See Recycling_Corner/Slider controls

Echoing PDB "Title" to the applet window

The following JavaScript code snippet will report the title of a PDB entry to the applet window when a PDB file is loaded. This should be included within a JavaScript portion of the html file that loads the applet and the PDB file. One caveat: the "TITLE" in a PDB file is depositor-generated and may or may not be "useful" to the end user! :)

var headerInfo = jmolGetPropertyAsString("fileHeader");
var cutUp = headerInfo.split("\n");
var headerstring="";
for (l=0;l<cutUp.length;l++) {
  var regexp = new RegExp("TITLE.{5}(.*)\s*");
  var temp = cutUp[l];           
  if (temp.search(regexp) == 0) {
    temp2 = RegExp.$1;
    temp2.replace(/^\s+|\s+$/g, "").replace(/\s+/g, " ");
    temp2 = temp2 + "|";
    headerstring += temp2;                          }
  }
}
headerstring.replace(/TITLE/, "");
jmolScript("set echo depth 0; set echo headerecho 2% 2%; font echo 12 sanserif bolditalic; color echo green");
jmolScript('echo "' + headerstring + '"');

Bob Hanson has also contributed this much more elegant way to accomplish the same thing all within JmolScript:

function getHeader()
  var titleLines = getProperty("fileHeader").split().find("TITLE").split()
  for (var i = 1; i <= titleLines.size;i = i + 1)
    titleLines[i] = (titleLines[i])[11][0].trim()
  end for
  return titleLines.join("|")
end function
set echo bottom left
echo @{getheader()}

Providing a 'please wait' notice while the applet loads

in a separate page

Exporting an image from the applet

An image of the current view may be exported from the Jmol applet, either


Opening a duplicate of the model in a resizable pop-up window

The model, with is current state, is duplicated or cloned into a new (pop-up) window so it may be displayed at a larger size (and the user may resize that window at will).

See Recycling_Corner/Duplicate_Pop-up


Style transitions

Smooth transitions from one rendering style to another.

Spacefill to ball & stick

for (var i=0;i<=9;i++) {
 s=100-80*i/9;
 spacefill @s%;
 w=0.9-0.75*i/9;
 wireframe @w;
 delay 0.2;
}

Can be given in a single line:

for(var i=0;i<=9;i++){s=100-80*i/9;spacefill @s%;w=0.9-0.75*i/9;wireframe @w;delay 0.2;}


Replacing applet with signed applet upon demand

The signed applet has certain capabilities that the unsigned applet lacks, but using the signed applet will raise some dialogs with security warnings that the general user may find scary and, if permission is denied, the expanded features will not be available and hence the page will fail to do what is expected.

This may lead to a situation where webpage authors wish to use the unsigned applet by default and make the switch to the signed applet if and when the users requests a certain capability (like saving a model to disk). The code here will do that.

The rationale is:

  1. Store the current state of the model in the applet so that it can be restored after the applet switch.
  2. Destroy the applet object.
  3. Insert the signed applet in the same place.
  4. Load back the model and state.

Latest Jmol.js (post-26 Sep 2011, Jmol_12.2.RC8 or later) includes a new jmolSwitchToSignedApplet() function to do this replacement easier:

The code (html + JavaScript, relying on Jmol.js):

<script type="text/javascript">
  jmolInitialize(".");
  jmolApplet(400, 'load example.mol;', 'ABC');
</script>
<br>
<input type="button" value="make the switch" onClick="jmolSwitchToSignedApplet('ABC')">

That's all! Note that 'ABC' is an example of an applet suffix ID, and if omitted will default to '0' (zero) in both jmolApplet() and jmolSwitchToSignedApplet().

Warning!

  • This method has not been thoroughly tested and might fail or break the page; particularly, testing under different browsers and OS's is needed.

Including special characters in echo

Non-keyboard characters may be included in echo texts using their Unicode character number, like this:

echo "\u03B1 is the alpha letter";
echo "\u2192 is an arrow pointing right";
echo "\u00B2 is the superscript two, or square power";

Note that, in these cases, the use of quotes surrounding the echoed text is compulsory.

Center of mass

Jmol centers the model around its geometric center, i.e. the center of the boundbox. If you are interested in the mass center of the molecule:

See Recycling_Corner/Center_Of_Mass


RIBOZOME - an Alpha Helix Generator script

Creates an alpha helix from a user input string.

A script for the Jmol Application and also applied to a webpage with a J(S)mol object.

See Recycling_Corner/Alpha_Helix_Generator

POLYMERAZE - an DNA Double Helix Generator script

Creates a DNA or RNA single or double helix from a user input string.

See Recycling_Corner/DNA_Generator


Drawing objects

Cylinder

To draw a cylinder, you need this information:

  • two points that define the axis of the cylinder and its length
    • each of these may be an XYZ coordinate, an atom, the center of an atom set, or a reference to another previously drawn object
  • the diameter of the cylinder (in Angstroms)

Examples (with two XYZ points):

// open cylinder (tube):
draw myCyl diameter 6.0 color translucent cyan cylinder {13 1.58 9.3} {15 1.21 15} mesh nofill;
// closed at both ends:
draw myCyl diameter 6.0 color translucent cyan cylinder {13 1.58 9.3} {15 1.21 15} fill;
// closed at one end:
draw myCyl diameter 6.0 color translucent cyan cylinder {13 1.58 9.3} {15 1.21 15} fill;
draw myCap diameter 6.0 color opaque cyan circle {13 1.58 9.3} {15 1.21 15};

For options, see documentation for the draw command.

Ellipsoid

Starting from these:

  • two points that define the main axis of the ellipsoid and its length
    • each of these may be an XYZ coordinate, an atom, the center of an atom set

Example, with two atoms (numbers 3 and 7) at the ends of the ellipsoid:

atA = {atomNo=3};
atB = {atomNo=7};
dC = {(atA,atB)}; // defines the center, midpoint between both atoms
dE = 0.5; // eccentricity (<1 for cigar-shaped, 1 for a sphere, >1 for disk-shaped)
dR = 7; // resolution of the mesh or surface
dX = {atA}.x - {atB}.x; // for defining the orientation
dY = {atA}.y - {atB}.y;
dZ = {atA}.z - {atB}.z;
dL = {atA}.xyz.distance({atB}.xyz) /2; // length of the main ellipsoid axis
isosurface myEllipA color blueTint scale @dL resolution @dR center @dC ellipsoid {@dX @dY @dZ @dE} mesh nofill;
isosurface myEllipB color translucent 0.7 lime scale @dL resolution @dR center @dC ellipsoid {@dx @dy @dz @dE} fill;

Resolution and eccentricity will need to be adjusted depending on your case.

Element legend

This will work with any loaded molecule (it automatically reads the list of elements present).

It requires Jmol 14.6.0 or later.

Use either with color echo black; background white; or with color echo white; background black;

function createElementKey() {
  var y = 90;
  for (var e in {*}.element.pivot) {
    var c = {element=@e}.color;
    draw id @{"d_"+ e} diameter 2 [90 @y %] color @c;
    set echo id @{"e_" + e} [91 @{y-1} %];
    echo @e;
    font echo 24 bold sans;
    y -= 5;
  }
}
createElementKey;

Test if a file exists before displaying it

Using HTML, Javascript and Jmol scripting:

A Javascript function:

function loadFile(x) {
  var s = 'filedat = load("' + x  + '"); exists = true; '+
   'if ( filedat.find("NetworkError") != 0 ) { exists = false; } '+
   'elseif ( filedat.find("Not Found") != 0 ) { exists = false; } '+
   'if ( exists ) { load var filedat; } else { zap; set echo e0 50% 50%; set echo e0 center; echo "This file cannot be found"; }';
  Jmol.script(myJmol, s);
}

And the HTML element calling it:

<input type="button" onClick="loadFile('test.mol')" value="load it">

Using Jmol callbacks to Javascript:

Another possibility is to use loadStructCallback to detect the failure in loading the file. For instance:

In Javascript:

Info.loadstructcallback = 'loadCB';
function loadCB() {
 if (arguments[5]==0 && !window['noFile']) { //avoid repeated callbacks by zap
  Jmol.script(myJmol, 'zap; set echo e0 50% 50%; set echo e0 center; echo "This file cannot be found";'); 
  window['noFile'] = true;
 } else {
  window['noFile'] = false;
 }
}

Using only Jmol scripting:

Javascript:

Info.script = 'function loadFile(x) { filedat=load(x); exists=true; '+
 'if (filedat.find("NetworkError")!=0) {exists=false;} elseif (filedat.find("Not Found")!=0) {exists=false;}; '+
 'if (exists) {load var filedat;} else {zap; set echo e0 50% 50%; set echo e0 center; echo "This file cannot be found";} }; ';

And HTML:

<p>This file exists in the same folder 
 <script type="text/javascript">Jmol.jmolButton(myJmol, "loadFile('test.mol')", "load it");</script></p>
<p>This file  does not exist 
 <script type="text/javascript">Jmol.jmolButton(myJmol, "loadFile('test2.mol')", "load it");</script></p>

Using an AJAX call:

Javascript:

function loadFile(pathFilenameExt) {
 var req = new XMLHttpRequest();
 req.onreadystatechange = function() {
  if (this.readyState != 4) { return; } /*not finished yet*/
  if (this.status == 200) {
    Jmol.script(myJmol, 'load "' + pathFilenameExt + '";');
  } else {
    Jmol.script(myJmol, 'zap; set echo e0 50% 50%; set echo e0 center; echo "This file cannot be found";');
  }
 };
 req.open('GET', pathFilenameExt, false);
 req.send();
}

And the HTML:

<p>This file exists in the same folder <input type="button" onClick="loadFile('test.mol')" value="load it"></p>
<p>This file does not exist <input type="button" onClick="loadFile('test2.mol')" value="load it"></p>

(Based on a contribution by Bilal Nizami)

Improved lighting

The lighting of atoms, bonds and ribbons and the thickness of ribbons may be customized to provide a nicer look, by adjusting several settings. Here is an example:

Fast, fancy, shiny.png

Fast, fancy, shiny ball-and-stick.png

Default:

reset lighting; set cartoonsFancy off; set hermiteLevel 0; set antialiasDisplay off;

"Fast": (quick rendering, same as default except antialias is applied for a better comparison with the other two)

reset lighting; set cartoonsFancy off; set hermiteLevel 0; set antialiasDisplay on;

"Fancy": (relevant only for cartoons, without effect on atoms and bonds)

reset lighting; set cartoonsFancy on; set hermiteLevel 20; set antialiasDisplay on;

"Shiny": (adds light and shadow effects) (more similar to rendering in other software like e.g. Chimera)

set ambientPercent 25; set specularPower 100; set specularPercent 22; set specularExponent 4; set cartoonsFancy on; set antialiasDisplay on; set hermiteLevel 20;

Shiny-rendering-spacefill.png

Note: Jmol defaults may be restored using reset lighting which applies these values:

set ambientPercent diffusePercent specular specularPercent specularPower specularExponent
default value: 45 84 on 22 40 6
set zDepth zSlab zShade zShadePower celShading celShadingPower
default value: 0 50 off 3 off 10

For more details about each of these settings, see the Scripting Documentation.

Extract phi and psi values

The dihedral angles phi and psi are known in Jmol, as properties of each amino acid residue in a protein, which are copied to properties of each atom in that residue.

These scripts may be used to extract their values into an array:

For the first polymer in the first model in the loaded file:
p = getProperty("polymerinfo.models[1].polymers[1].monomers").select("psi,phi")

p will be an associative array, one element per residue, each one with keys "phi" and "psi" and their values.

Result for the first 2 and last 2 residues:
print p
 {
   "psi"  :  135.30487
  }
 {
   "phi"  :  -103.61969
   "psi"  :  110.173744
  }
...
 {
   "phi"  :  -81.423874
   "psi"  :  131.89566
  }
 {
   "phi"  :  -166.42226
  }
Another way, which will read all protein chains present:
ph = [];
ps = [];
n1 = {protein}.resno.min;
n2 = {protein}.resno.max;
for (r=n1; r<=n2; r++) {
 ph.push({resno=r}.phi);
 ps.push({resno=r}.psi);
}
Result:
print ph.join("\n")
NaN
-34.539898
...
-81.423874
-166.42226
print ps.join("\n")
135.30487
36.724583
...
131.89566
NaN

Front of the molecule, selecting (by percentage)

The Jmol function at Recycling_Corner/Front_Selection selects a specified percentage of the front of the molecule, according to the orientation of the molecule when the function is executed.

Custom pop-up menus

Jmol (both application and applet) allows a customized pop-up menu instead of the standard default menu. Their definition and use are explained in Custom Menus.

Examples:

Users, if you design a new menu, please, share it here.

SimpleBio

SimpleBio menu.jpg

This is devised to ease the handling of the menu by inexperienced users with only basic tasks, in tutorial pages of simple biomolecules.

It includes just these entries:

  • Style - with simplified contents.
  • Color - compacted to have less submenu nesting.
  • Spin - just with on/off, no axes or speed options.
  • Select - a bit simplified.
  • Advanced (*) - a new entry including:
    • Choose menu (*) - that allows to revert to the standard full menu.
    • Language
    • Console
  • About

(*) These are new entries, and so will not be localized; you may wish to edit them for your intended language.

You can get this custom menu here.

SimpleChem

SimpleChem menu.jpg

This is devised to ease the handling of the menu by inexperienced users with only basic tasks, in tutorial pages of organic/inorganic molecules (no crystallography, symmetry, vibration or animation, no pdb-related options).

It includes just these entries:

  • Style - with simplified contents.
  • Color - simplified.
  • Spin - just with on/off, no axes or speed options.
  • Select - a bit simplified.
  • Measurements
  • Advanced (*) - a new entry including:
    • Choose menu (*) - that allows to revert to the standard full menu.
    • Language
    • Console
  • About

(*) These are new entries, and so will not be localized; you may wish to edit them for your intended language.

You can get this custom menu here.