Difference between revisions of "Jmol JavaScript Object"

From Jmol
Jump to navigation Jump to search
(Installation)
Line 1: Line 1:
Jmol Javascript Object is a set of javascript functions and utilities refactored and reorganized into a single javascript object. It supersedes the former [{{Website}}jslibrary/ Jmol.js javascript library] as it allows for a cleaner, more efficient way to interact with the applet from javascript, and abstracts the view of a molecular model so that the applet could be seamlessly replaced by an image, or a third party visualization method depending on client's browser resources.
+
The Jmol JavaScript Object ("Jmol-JSO") is a set of JavaScript functions and utilities refactored and reorganized into a single JavaScript object. It supersedes the former [{{Website}}jslibrary/ Jmol.js JavaScript library], allowing a cleaner, more efficient way to interact with the Jmol applet on a web page, and abstracting the visualization of a molecular model so that the applet can be seamlessly replaced by an image or a third-party non-Java visualization resource (using WebGL and/or HTML5) depending on client's platform resources.
 +
 
 +
Using Jmol-JSO, a web page developer can target Java-challenged (iPad, iPhone) and Applet-challenged (Android) platforms but still implement Jmol on traditional platforms. Compromises will have to be made, because no other resource has the scripting power of Jmol. However, the wide variety of options available allows a subset of Jmol functionality on all such devices, and there should be no need to ever see a message "Sorry, you don't have Java installed...."
 +
 
 +
Jmol-JSO also allows easy access to public databases such as [http://rcsb.org the RCSB PDB database], [http://cactus.nci.nih.gov/ the National Cancer Institute CACTVS server], and [http://pubchem.ncbi.nlm.nih.gov/ PubChem], even when the Jmol Java applet is not available because of a user's platform.
 +
 
 +
In addition, Jmol-JSO allows easy interaction with the JSpecView applet (for spectroscopy) and the JME applet (for 2D drawing input) on a web page. Thus, 3D models can be tied to IR, NMR, UV/VIS, GC, and GC/MS spectra (using the JCAMP-DX Version 6 standard), 3D models can be embedded in JCAMP-DX files (see [http://chemapps.stolaf.edu/jmol/docs/misc/Jmol-JSpecView-specs.pdf Jmol-JSpecView-specs.pdf]), and 3D models can be introduce by a page visitor using simple chemical drawing.
 +
 
 +
Jmol-JSO is fully compatible with jQuery, creating the single global Jmol object. The library has been W3C and XHTML validated.
  
 
==Installation==
 
==Installation==
  
These files must be accessible to the html page. Note that [[Troubleshooting/Applet#Java_security_errors|Java scurity policy]] imposes limitations on the folder location of files. The JavaScript files should be in the following order:
+
JmolJSO requires a small suite of JavaScript libraries that replace Jmol.js. However, the Java files necessary are the same:
  
 
*  {{file|JmolApplet.jar}} or {{file|JmolAppletSigned.jar}} or {{file|JmolApplet0*.jar}} or {{file|JmolAppletSigned0*.jar}}
 
*  {{file|JmolApplet.jar}} or {{file|JmolAppletSigned.jar}} or {{file|JmolApplet0*.jar}} or {{file|JmolAppletSigned0*.jar}}
: (That is a set of files, where the * stands for several suffixes. You may need to read about [[Jmol_Applet#Unsigned_vs._Signed_Applet_.26_Data_Access|signed vs. unsigned applet]].)
+
: (That is, a set of files, where the * stands for several suffixes. You may need to read about [[Jmol_Applet#Unsigned_vs._Signed_Applet_.26_Data_Access|signed vs. unsigned applet]] if you are unfamiliar with the Jmol jar files.)
 +
 
 +
Note that [[Troubleshooting/Applet#Java_security_errors|Java scurity policy]] imposes limitations on the folder location of files.
 +
 
 +
The basic suite of JavaScript libraries include these four:
 +
 
 
* {{file|JmolCore.js}} (required)
 
* {{file|JmolCore.js}} (required)
 
* {{file|JmolApplet.js}} (required)
 
* {{file|JmolApplet.js}} (required)
 
* {{file|JmolControls.js}} (optional -- required if any buttons or links or other input methods will be used)
 
* {{file|JmolControls.js}} (optional -- required if any buttons or links or other input methods will be used)
 
* {{file|JmolApi.js}} (required)
 
* {{file|JmolApi.js}} (required)
 +
 +
However, AJAX access (by the unsigned applet or non-Java resources) to cross-domain resources such as public databases also requires jQuery.min.js and jQuery.iecors.js (loaded prior to JmolCore.js), and use of ChemDoodle, GLmol, JSpecView, or JME requires additional libraries.
  
 
==Initialization==
 
==Initialization==
 +
 +
Note that JavaScript libraries not starting with "Jmol" may not be included in the Jmol distribution. Files can be found at [http://chemapps.stolaf.edu/jmol chemapps.stolaf.edu/jmol] and associated subdirectories. These include:
 +
 +
* {{file|jQuery.min.js}} The [http://jquery.com/ jQuery JavaScript library] allowing the unsigned applet and non-Jmol options cross-domain access to public databases for all browsers other than MSIE.
 +
* {{file|jQuery.iecors.js}} An [https://github.com/dkastner/jquery.iecors extension of jQuery] allowing the unsigned applet and non-Jmol options to have cross-domain access to public databases.
 +
* {{file|ChemDoodleWeb.js}} [http://web.chemdoodle.com/ ChemDoodle Web Components].
 +
* {{file|gl-matrix-min.js}} [https://github.com/toji/gl-matrix Javascript Matrix and Vector library for High Performance WebGL apps]; required for the ChemDoodle option only.
 +
* {{file|mousewheel.js}} [https://github.com/brandonaaron/jquery-mousewheel/ jQuery Mouse Wheel Plugin] required for the ChemDoodle option only.
 +
* {{file|GLmol.js}} [http://webglmol.sourceforge.jp/index-en.html GLmol - Molecular Viewer on WebGL/JavaScript].
 +
* {{file|Three49custom.js}} A custom version of the [http://mrdoob.github.com/three.js/ WebGL 3D JavaScript library] required for the GLmol option only and available at [https://github.com/biochem-fan/GLmol/tree/master/src/js gitHub].
 +
 
===Basic===
 
===Basic===
  
The html page must reference (usually with a <code>script</code> tag in the <code>head</code> section) the javascript libraries:
+
The web page at the very least should have the following in the <code>head</code> section (referencing files in appropriate directories if not the directory of the web page, as shown here):
* {{file|JmolCore.js}}  essential
+
 
* {{file|JmolApplet.js}}  essential, must go after JmolCore
+
<code>
* {{file|JmolApi.js}}  essential, must go after JmolCore
+
&lt;script type="text/javascript" src="JmolCore.js">&lt;/script><br />
* {{file|JmolControls.js}}  optional, must go after JmolCore; only needed if you will insert user interface controls like buttons, links, menus, etc.
+
&lt;script type="text/javascript" src="JmolApplet.js">&lt;/script><br />
 +
&lt;script type="text/javascript" src="JmolControls.js">&lt;/script><br />
 +
&lt;script type="text/javascript" src="JmolApi.js">&lt;/script><br />
 +
</code>
 +
 
 +
JmolControls.js may be omitted if no buttons, links, menus, or other user-interactive features are implemented on the page. All functions discussed below are found in JmolApi.js. The other files contain code that creates the various Jmol object prototypes and methods that are called from JmolApi.js.
 +
 
 +
===Unsigned Jmol applet requiring access to public databases and all non-Java options ===
 +
 
 +
Web pages requiring the unsigned applet to access public databases, as well as all non-Jmol options, additionally require jQuery so that they can perform cross-browser or host-server AJAX calls:
 +
 
 +
<code>
 +
&lt;script type="text/javascript" src="jQuery.min.js">&lt;/script><br />
 +
&lt;script type="text/javascript" src="jQuery.iecors.js">&lt;/script><br />
 +
&lt;script type="text/javascript" src="JmolCore.js">&lt;/script><br />
 +
&lt;script type="text/javascript" src="JmolApplet.js">&lt;/script><br />
 +
&lt;script type="text/javascript" src="JmolControls.js">&lt;/script><br />
 +
&lt;script type="text/javascript" src="JmolApi.js">&lt;/script><br />
 +
</code>
 +
 
 +
===ChemDoodle option===
 +
 
 +
Web pages utilizing ChemDoodle (either HTML5/WebGL or HTML5/non-WebGL versions) should have the following in their <code>head</code> section:
 +
 
 +
<code>
 +
&lt;script type="text/javascript" src="jQuery.min.js">&lt;/script><br />
 +
&lt;script type="text/javascript" src="jQuery.iecors.js">&lt;/script><br />
 +
&lt;script type="text/javascript" src="JmolCore.js">&lt;/script><br />
 +
&lt;script type="text/javascript" src="JmolApplet.js">&lt;/script><br />
 +
&lt;script type="text/javascript" src="JmolControls.js">&lt;/script><br />
 +
&lt;script type="text/javascript" src="JmolApi.js">&lt;/script><br />
 +
&lt;script type="text/javascript" src="gl-matrix-min.js">&lt;/script><br />
 +
&lt;script type="text/javascript" src="mousewheel.js">&lt;/script><br />
 +
&lt;script type="text/javascript" src="ChemDoodleWeb.js">&lt;/script><br />
 +
&lt;script type="text/javascript" src="JmolCD.js">&lt;/script><br />
 +
</code>
  
===Using the ChemDoodle alternative===
+
===GLmol option===
The html page must reference these additional javascript libraries:
 
* {{file|jQuery.min.js}} required; unrelated to Jmol and not included in Jmol distribution. The [http://jquery.com/ jQuery JavaScript Library].
 
* {{file|gl-matrix-min.js}} required; not included in Jmol distribution. [https://github.com/toji/gl-matrix Javascript Matrix and Vector library for High Performance WebGL apps].
 
* {{file|mousewheel.js}}  required; not included in Jmol distribution. [https://github.com/brandonaaron/jquery-mousewheel/ jQuery Mouse Wheel Plugin].
 
* {{file|ChemDoodleWeb.js}} required; from [http://web.chemdoodle.com/ ChemDoodle Web Components]; must go after the above three.
 
* {{file|JmolCD.js}} required; must go after JmolApplet and all those above.
 
  
===Using the GLmol alternative===
+
&lt;script type="text/javascript" src="jQuery.min.js">&lt;/script><br />
The html page must reference these additional javascript libraries:
+
&lt;script type="text/javascript" src="jQuery.iecors.js">&lt;/script><br />
* {{file|jQuery.min.js}} required; unrelated to Jmol and not included in Jmol distribution. The [http://jquery.com/ jQuery JavaScript Library].
+
&lt;script type="text/javascript" src="JmolCore.js">&lt;/script><br />
* {{file|Three49custom.js}} required; not included in Jmol distribution; available with GLmol, below.
+
&lt;script type="text/javascript" src="JmolApplet.js">&lt;/script><br />
* {{file|GLmol.js}}  required; from [http://webglmol.sourceforge.jp/index-en.html GLmol - Molecular Viewer on WebGL/Javascript]; must go after the above two.
+
&lt;script type="text/javascript" src="JmolControls.js">&lt;/script><br />
* {{file|JmolGlmol.js}} required; must go after JmolApplet and all those above.
+
&lt;script type="text/javascript" src="JmolApi.js">&lt;/script><br />
 +
&lt;script type="text/javascript" src="Three49custom.js">&lt;/script><br />
 +
&lt;script type="text/javascript" src="GLmol.js">&lt;/script><br />
 +
&lt;script type="text/javascript" src="JmolGLmol.js">&lt;/script><br />
  
 
===Initialization parameters===
 
===Initialization parameters===
  
 
==API==
 
==API==

Revision as of 22:44, 12 August 2012

The Jmol JavaScript Object ("Jmol-JSO") is a set of JavaScript functions and utilities refactored and reorganized into a single JavaScript object. It supersedes the former Jmol.js JavaScript library, allowing a cleaner, more efficient way to interact with the Jmol applet on a web page, and abstracting the visualization of a molecular model so that the applet can be seamlessly replaced by an image or a third-party non-Java visualization resource (using WebGL and/or HTML5) depending on client's platform resources.

Using Jmol-JSO, a web page developer can target Java-challenged (iPad, iPhone) and Applet-challenged (Android) platforms but still implement Jmol on traditional platforms. Compromises will have to be made, because no other resource has the scripting power of Jmol. However, the wide variety of options available allows a subset of Jmol functionality on all such devices, and there should be no need to ever see a message "Sorry, you don't have Java installed...."

Jmol-JSO also allows easy access to public databases such as the RCSB PDB database, the National Cancer Institute CACTVS server, and PubChem, even when the Jmol Java applet is not available because of a user's platform.

In addition, Jmol-JSO allows easy interaction with the JSpecView applet (for spectroscopy) and the JME applet (for 2D drawing input) on a web page. Thus, 3D models can be tied to IR, NMR, UV/VIS, GC, and GC/MS spectra (using the JCAMP-DX Version 6 standard), 3D models can be embedded in JCAMP-DX files (see Jmol-JSpecView-specs.pdf), and 3D models can be introduce by a page visitor using simple chemical drawing.

Jmol-JSO is fully compatible with jQuery, creating the single global Jmol object. The library has been W3C and XHTML validated.

Installation

JmolJSO requires a small suite of JavaScript libraries that replace Jmol.js. However, the Java files necessary are the same:

  • File icon.gifJmolApplet.jar or File icon.gifJmolAppletSigned.jar or File icon.gifJmolApplet0*.jar or File icon.gifJmolAppletSigned0*.jar
(That is, a set of files, where the * stands for several suffixes. You may need to read about signed vs. unsigned applet if you are unfamiliar with the Jmol jar files.)

Note that Java scurity policy imposes limitations on the folder location of files.

The basic suite of JavaScript libraries include these four:

  • File icon.gifJmolCore.js (required)
  • File icon.gifJmolApplet.js (required)
  • File icon.gifJmolControls.js (optional -- required if any buttons or links or other input methods will be used)
  • File icon.gifJmolApi.js (required)

However, AJAX access (by the unsigned applet or non-Java resources) to cross-domain resources such as public databases also requires jQuery.min.js and jQuery.iecors.js (loaded prior to JmolCore.js), and use of ChemDoodle, GLmol, JSpecView, or JME requires additional libraries.

Initialization

Note that JavaScript libraries not starting with "Jmol" may not be included in the Jmol distribution. Files can be found at chemapps.stolaf.edu/jmol and associated subdirectories. These include:

Basic

The web page at the very least should have the following in the head section (referencing files in appropriate directories if not the directory of the web page, as shown here):

<script type="text/javascript" src="JmolCore.js"></script>
<script type="text/javascript" src="JmolApplet.js"></script>
<script type="text/javascript" src="JmolControls.js"></script>
<script type="text/javascript" src="JmolApi.js"></script>

JmolControls.js may be omitted if no buttons, links, menus, or other user-interactive features are implemented on the page. All functions discussed below are found in JmolApi.js. The other files contain code that creates the various Jmol object prototypes and methods that are called from JmolApi.js.

Unsigned Jmol applet requiring access to public databases and all non-Java options

Web pages requiring the unsigned applet to access public databases, as well as all non-Jmol options, additionally require jQuery so that they can perform cross-browser or host-server AJAX calls:

<script type="text/javascript" src="jQuery.min.js"></script>
<script type="text/javascript" src="jQuery.iecors.js"></script>
<script type="text/javascript" src="JmolCore.js"></script>
<script type="text/javascript" src="JmolApplet.js"></script>
<script type="text/javascript" src="JmolControls.js"></script>
<script type="text/javascript" src="JmolApi.js"></script>

ChemDoodle option

Web pages utilizing ChemDoodle (either HTML5/WebGL or HTML5/non-WebGL versions) should have the following in their head section:

<script type="text/javascript" src="jQuery.min.js"></script>
<script type="text/javascript" src="jQuery.iecors.js"></script>
<script type="text/javascript" src="JmolCore.js"></script>
<script type="text/javascript" src="JmolApplet.js"></script>
<script type="text/javascript" src="JmolControls.js"></script>
<script type="text/javascript" src="JmolApi.js"></script>
<script type="text/javascript" src="gl-matrix-min.js"></script>
<script type="text/javascript" src="mousewheel.js"></script>
<script type="text/javascript" src="ChemDoodleWeb.js"></script>
<script type="text/javascript" src="JmolCD.js"></script>

GLmol option

<script type="text/javascript" src="jQuery.min.js"></script>
<script type="text/javascript" src="jQuery.iecors.js"></script>
<script type="text/javascript" src="JmolCore.js"></script>
<script type="text/javascript" src="JmolApplet.js"></script>
<script type="text/javascript" src="JmolControls.js"></script>
<script type="text/javascript" src="JmolApi.js"></script>
<script type="text/javascript" src="Three49custom.js"></script>
<script type="text/javascript" src="GLmol.js"></script>
<script type="text/javascript" src="JmolGLmol.js"></script>

Initialization parameters

API