Jmol Applet Documentation


Table of Contents

1. Introduction
2. Supported Browsers
Testing results
3. Jmol Applet Usage
Embedding the Jmol Applet in a Web Page
Jmol Applet Parameters
style
Atom Labels
script
4. JavaScript integration
Web Browser support
JavaScript LiveConnect overview
Jmol JavaScript API
document.jmol.load(String url)
document.jmol.loadInline(String model)
document.jmol.setStyle(String style)
document.jmol.setLabelStyle(String labelStyle)
document.jmol.setWireframeRotation(boolean wfrMode)
document.jmol.setPerspectiveDepth(boolean pdMode)
5. Scripting
Scripting References
Ways to integrate scripts

Chapter 1. Introduction

The Jmol Applet allows the 3D display of molecules within a web page.

With the exception of a few wrapper classes, the Jmol Applet code is shared with the Jmol Application.

Chapter 2. Supported Browsers

Table of Contents

Testing results

The applet is tested and working with Internet Explorer, Netscape, Opera, Mozilla (and derivatives) and Konqueror on various platforms. Below are given the testing results.

If you find problems with the browser/operating system/jvm combination of your choice, please send an email to jmol-users@lists.sf.net, stating the exact error (most browsers have a Java Console), and the versions of the browser, the operating system, and the java virtual machine that is used.

Testing results

The applet Jmol v6 is tested successfully with these browsers:

Browser Brand/VersionOperation System/VersionArchitectureJVM Brand/Version
Mozilla 1.2.1RedHat Linux 9.0Intel CeleronSun 1.4.1_02-b06
Netscape 4.79RedHat Linux 9.0Intel CeleronSun 1.4.1_01-b03
Konqueror 3.1-12 Red HatRedHat Linux 9.0Intel CeleronSun 1.4.2
Galeon 1.2.7RedHat Linux 9.0Intel CeleronSun 1.4.1_02-b06
IE 5.50.4134.0600WinMEInten PentiumMS JVM 5.00.3309
IE 5.50.4134.0600WinMEIntel PentiumSun 1.3.1_06
Netscape 4.61WinMEIntel Pentium1.1.5
Mozilla 1.3WinMEIntel PentiumSun 1.4.1_01
above this linetested forjmol 6
IE 6.0WinMEIntel PentiumSun 1.4.1_01
IE 6.0WinMEIntel PentiumSun 1.4.1_01
IE 5.50.4134.0100Win98PentiumMS JVM 5.0.0.3809
IE 5.0.0Win98i386MS JVM 5.00.3805
Netscape 7.0 rv 1.0.1SunOS 5.8Sparc v91.4.1
Netscape 4.79SunOS 5.8Sparc v91.1.5
Netscape 4.79RedHat Linux 8.0Intel CeleronNetscape Java 1.1.5
Opera 7.0 (b2345)Win98i386Sun 1.4
Mozilla 1.0.1RedHat Linux 8.0Intel Celeron? 1.4.0_01-b03
Galeon 1.2.5Debian GNU/Linux TestingIntel Pentium IIBlackdown 1.3
Galeon 1.2.6Debian GNU/Linux UnstableIntel Pentium4Sun 1.4.1
Konqueror 3.0.1SunOS 5.8Sparc v9Sun 1.4.0
Konqueror 3.0.1SunOS 5.8Sparc v9Sun 1.2.2

Errors were encountered with these browsers:

Browser Brand/VersionOperation System/VersionArchitectureJVM Brand/VersionProblem
Netscape 4.79RedHat Linux 8.0Intel CeleronNetscape Java 1.1.51.
IE 6.0WinMEIntel PentiumMicrosoft VM 5.0.0.38052.
Galeon 1.2.5Debian GNU/Linux StableIntel Pentium3Sun 1.4.13.

  1. Verified Error on jmol-applet.jar. Applet was not compiled with a classic compiler. This is an compilation problem.

  2. Verified Error on cdk-cml.jar. CML lib was not compiled with a classic compiler. This is an compilation problem.

  3. The environment variable was not recognized by the JVM, which in return did not start. This is a OS problem.

Chapter 3. Jmol Applet Usage

Embedding the Jmol Applet in a Web Page

To embed the Jmol Applet in a web page, you need only one java archive file, JmolApplet.jar. All classes and data files are included in this file. Put this file in the directory on your webserver.

The name of the applet class is JmolApplet.

The Jmol applet can be embedded in html pages using the APPLET html tag:

      <applet code="JmolApplet" archive="JmolApplet.jar"
	width="350" height="350">
	<param name="load" value="caffeine.xyz">
	</applet>
	
    

CODE identifies the name of the class, in this case 'JmolApplet' or 'JmolApplet.class'. ARCHIVE identifies the name of the jar file where the classes for this applet are to be found. WIDTH and HEIGHT specify the dimensions of the applet within the html page in pixels.

The PARAM tags are used to pass parameters to the applet. The LOAD parameter specifies the URL of the molecule file which should be loaded.

The following is a slightly more complicated version with a few more options:

      <applet name="jmol" code="JmolApplet" archive="JmolApplet.jar"
	width="350" height="350" align="right">
	<param name="load"    value="molecules/caffeine.xyz">
	<param name="bgcolor" value="#DDDDFF">
	<param name="style"   value="quickdraw">
	<param name="label"   value="symbol">
	<param name="script"  value="move 0 0 360 0 0 0 0 0 5">
	<param name="wireframeRotation" value="true">
	<param name="perspectiveDepth"  value="false">
        </applet>
        
    

In this case the applet is given a name so that it can be referenced from JavaScript code (applet="jmol"). The applet is aligned to the right side of the page so that text flows to the left (align="right"). Using additional parameters (<param name="*" value="*">) a molecule is loaded from a relative URL on the web server (molecules/caffeine.xyz), the background color is set to a light blue (#DDDDFF), the style is set so that shaded atoms/bonds are not used (quickdraw), atoms are labeled with their atomic symbol (symbol), a script is run which rotates 360 degrees around the z axis in 5 seconds, wireframeRotation is turned on so that all movements are done in wireframe mode, and perspective depth is turned off so that the molecule rendering is a flat projection to the screen with no size adjustment for atoms and bonds further away from the viewer.

Jmol Applet Parameters

The complete list of Jmol Applet parameters is as follows:

  • bgcolor - The color of the background: official html color names or #RRGGBB notation

  • style - The rendering style for atoms and bonds: SHADED, WIREFRAME or QUICKDRAW

  • label - The rendering style for atom labels: NONE, SYMBOL or NUMBER

  • wireframeRotation - Rotations use wireframe for faster rendering: TRUE or FALSE (defaults to FALSE)

  • perspectiveDepth - Rotations use wireframe for faster rendering: TRUE or FALSE (defaults to TRUE)

  • script - RasMol/Chime script commands to execute

style

shaded

Renders atoms and bonds as shaded spheres and cylinders. Shaded images are calculated and cached, so performance should not be an issue except when dealing with very large protein molecules.

quickdraw

Renders atoms and bonds as flat, solid-colored circles and rectangles.

wireframe

Atoms are drawn as unfilled circles. Bonds are drawn as single lines.

Note: If rendering performance is unacceptably slow when dealing with very large molecules, the WIREFRAMEROTATION option can be used to switch to wireframe mode during rotations and translations.

Atom Labels

none

View the atoms without any label. This is the default.

symbol

Label the atoms with their element symbol.

number

Label the atoms with their index number.

script

The script parameter allows you to specify a script of RasMol/Chime commands to be executed after the molecule file is loaded.

Multiple script commands must be separated by the semicolon (;) character.

Chapter 4. JavaScript integration

Using JavaScript commands embedded in web pages, you can control the behavior of the Jmol applet. This flexibility enables you to create complex user interactions that are controlled using standard web page elements.

Web Browser support

The underlying technology that supports this is known as LiveConnect. The LiveConnect layer provides the data and method conversion interface between the JavaScript world and the Java world.

Netscape and Internet Explorer have both supported LiveConnect for some time.

The Konqueror browser does not yet support LiveConnect.

Unfortunately, the news is not good for Macintosh OS X. Internet Explorer does not support LiveConnect. Neither does Safari (which is based upon Konqueror). (I have not yet checked Netscape on OS X.)

JavaScript LiveConnect overview

In order to reference an applet on an HTML page the applet must be given a name. We recommend that you use the name 'jmol' as in:

      <applet name="jmol" code="JmolApplet" archive="JmolApplet.jar"
	width="350" height="350">
	<param name="load" value="caffeine.xyz">
	</applet>
	
    

If you would like to have multiple instances of the applet on a single page then you should give them unique names.

With some browser versions you can sneak by without starting object references with 'document'. However, this does not work with many browsers. Therefore, we strongly recommend that you start all your references with 'document'.

Therefore, assuming you have named your applet 'jmol', all your references to the applet will start with 'document.jmol'. JavaScript method references in this documentation will use this notation.

Within a web page, there are several ways to invoke a JavaScript method based upon user events. One method is to use the 'javascript:' protocol in an href, as in:

      <a href="javascript:document.jmol.load('dna.xyz')">
	Load DNA molecule
      </a>
      
    

Another method is to use explicit JavaScript event tags, as in:

      <form name="myform">
	<input type="button" value="Rotate X 90"
	  onClick="document.jmol.script('rotate x 90')">
	<input type="button" value="Rotate Y 90"
	  onClick="document.jmol.script('rotate y 90')">
	<input type="button" value="Rotate Z 90"
	  onClick="document.jmol.script('rotate Z 90')">
      </form>
      
    

For further information on JavaScript programming we recommend that you search for JavaScript development resources on the web or at your nearest technical bookstore.

To get things to run on an installed base of older Netscape and IE browsers you may want to consider looking for 'old' documentation rather than 'up to date' documentation. One good reference source is http://developer.netscape.com/docs/manuals/js/client/jsguide/index.html

Jmol JavaScript API

document.jmol.load(String url)

The 'load' method allows you to load a different molecular model into the applet.

document.jmol.loadInline(String model)

At times it may be more convenient to store the contents of the molecular model as a string in the HTML file itself. The 'loadInline' method allows you to load a molecular model of this type.

document.jmol.setStyle(String style)

Set the atom/bond rendering style to one of 'SHADED', 'QUICKDRAW' or 'WIREFRAME'

document.jmol.setLabelStyle(String labelStyle)

Set the atom label to be one of 'NONE', 'SYMBOL' or 'NUMBER'

document.jmol.setWireframeRotation(boolean wfrMode)

Controls whether or not rotations should be performed with wireframe rendering. This should not be needed except on very large molecules (or very old computers).

document.jmol.setPerspectiveDepth(boolean pdMode)

By default, atoms are rendered with perspective depth. That is, objects further away are smaller. When perspective depth is set to false you get a flat projection which is orthogonal to the screen.

The different projection modes are easily visible with crystaline structures or when the enclosing boundbox is turned on, as in:

	document.jmol.script('set boundbox on');
      

Chapter 5. Scripting

Scripting commands are the same under the applet as under the Jmol application. However, with the applet you do not have the feedback of the script command window.

Scripting References

Jmol implements most of the scripting language found in the RasMol molecular visualization tool. For more detailed documentation on RasMol scripting see http://www.openrasmol.org

MDL extended the RasMol scripting language for use in their Chime plug-in. Jmol implements some of these script language extensions. For more detailed information on Chime and Chime/RasMol extensions see http://www.mdlchime.com/chime

For a complete listing of the RasMol/Chime scripting commands which are implemented in Jmol see the Jmol Guide. This listing gives brief descriptions of the commands.

The RasMol commands which are currently not implemented in Jmol are generally those associated with protein visualization: ribbons, strands, etc. In addition, the Jmol rendering engine does not currently handle intersecting spheres. So if you make the atom sizes large you will get disappointing results.

Ways to integrate scripts

There are two methods of defining a script to be run by the applet

  • by using the parameter="script" tag as part of the applet specification
  • by using the JavaScript script('script-commands') method

In either of these cases you can

  • include the entire script in the html page
  • use the 'script [scriptname]' command to load a script from the webserver

In general, the first of these methods is only acceptable for short scripts. For longer scripts it is probably better to store the script files on the server and run them indirectly through the 'script' command.

All of the following examples load the molecule caffeine.xyz. Various ways of invoking scripts are demonstrated

A short script included as an applet parameter which is executed as soon as the applet is loaded.

      <html>
	<title>Example 1</title>
	<body>
	  <applet name="jmol" code="JmolApplet" archive="JmolApplet.jar"
	    width="350" height="350">
	    <param name="load"   value="caffeine.xyz">
	    <param name="script" value="rotate x 90 ; background yellow">
	  </applet>
	</body>
      </html>
      
    

In this example, the script command is used to execute a longer script which is stored in the scripts subdirectory on the web server.

      <html>
	<title>Example 2</title>
	<body>
	  <applet name="jmol" code="JmolApplet" archive="JmolApplet.jar"
	    width="350" height="350">
	    <param name="load"   value="caffeine.xyz">
	    <param name="script" value="script scripts/myLongScript.txt">
	  </applet>
	</body>
      </html>
      
    

This example uses onLoad to execute JavaScript which, in turn, drives the applet.

      <html>
	<title>Example 3</title>
        <body onLoad="document.jmol.script('select carbon; color green')">
	  <applet name="jmol" code="JmolApplet" archive="JmolApplet.jar"
	    width="350" height="350">
	    <param name="load"   value="caffeine.xyz">
	  </applet>
	</body>
      </html>
      
    

Essentially the same thing, but loading a script off of the web server.

      <html>
	<title>Example 4</title>
	<body onLoad="document.jmol.script('script scripts/myLongScript.txt')">
	  <applet name="jmol" code="JmolApplet" archive="JmolApplet.jar"
	    width="350" height="350">
	    <param name="load"   value="caffeine.xyz">
	  </applet>
	</body>
      </html>
      
    

Calling a javascript function which controls the script.

      <html>
	<title>Example 5</title>
	<script>
	  function runMyScript() {
	    document.jmol.script('move 0 0 360 0 0 0 0 0 4');
	  }
	</script>
	<body onLoad="runMyScript()">
	  <applet name="jmol" code="JmolApplet" archive="JmolApplet.jar"
	    width="350" height="350">
	    <param name="load"   value="caffeine.xyz">
	  </applet>
	</body>
      </html>
      
    

Using buttons to call javascript methods, each of which is running a jmol script.

      <html>
	<title>Example 6</title>
	<script>
	  function rotateX() {
	    document.jmol.script('move 360 0 0 0 0 0 0 0 4');
	  }
	  function rotateY() {
	    document.jmol.script('move 0 360 0 0 0 0 0 0 4');
	  }
	  function rotateZ() {
	    document.jmol.script('move 0 0 360 0 0 0 0 0 4');
	  }
	</script>
	<body>
	  <applet name="jmol" code="JmolApplet" archive="JmolApplet.jar"
	    width="350" height="350">
	    <param name="load"   value="caffeine.xyz">
	  </applet>
	  <form>
	    <input type="button" value="rotate x" onClick="rotateX()"/>
	    <input type="button" value="rotate y" onClick="rotateY()"/>
	    <input type="button" value="rotate z" onClick="rotateZ()"/>
	  </form>
	</body>
      </html>
      
    

Using buttons to call javascript methods, each of which is driving a jmol animate script

    <html>
      <title>Example 7</title>
        <script>
	  function play(script) {
	    document.jmol.script(script);
	  }
	</script>
	<body>
	  <applet name="jmol" code="JmolApplet" archive="JmolApplet.jar"
                  width="350" height="350">
            <param name="load"   value="models/SN1_reaction.xyz">
          </applet>
          <form>
            <input type="button" value="next"
	           onClick="play('animate next')">
            <input type="button" value="prev"
	           onClick="play('animate prev')">
            <input type="button" value="rewind"
	           onClick="play('animate rewind')">
            <input type="button" value="play"
	           onClick="play('animate play')">
            <input type="button" value="revplay"
	           onClick="play('animate revplay')">
            <br>
            <input type="button" value="repeated with 2 second delay"
                   onClick="play('animate play; loop 2')">
            <br>
            <input type="button" value="repeated no delay"
                   onClick="play('animate play; loop 0')">
            <br>
            <input type="button" value="forward and reverse"
                   onClick="play('animate play; animate revplay; loop 0')">
          </form>
        </body>
      </html>