Difference between revisions of "JSmol"

From Jmol
Jump to navigation Jump to search
(update on JSmol needs and syntax)
Line 1: Line 1:
'''JSmol''' is the tentative name for an alternative to Jmol applet that does not require Java but instead renders the molecular models in a webpage using just JavaScript and HTML5 features. This opens up the use of Jmol not only in PC's, Mac's and Linux's systems without Java installed, but also in tablets and phones (iOS, Android) that do not allow Java or applets. No hardware-based graphics acceleration is used either, and hence it should run in any system that supports HTML5 standards in the web browser. JSmol runs entirely in the client, does not use any server technologies.
+
'''JSmol''' is the name for an alternative to Jmol applet that does not require Java but instead renders the molecular models in a webpage using just JavaScript and HTML5 features. This opens up the use of Jmol not only in PC's, Mac's and Linux's systems without Java installed, but also in tablets and phones (iOS, Android) that do not allow Java or applets. No hardware-based graphics acceleration is used either, and hence it should run in any system that supports HTML5 standards in the web browser. JSmol runs entirely in the client, does not use any server technologies.
  
 
JSmol allows rendering, scripting and interaction with the models just as Jmol does, since the source code is shared by both. Note that JSmol is not a different program than Jmol: it is Jmol, just compiled into JavaScript instead of Java (thanks to the [http://java2script.sourceforge.net/ Java2Script] software).  
 
JSmol allows rendering, scripting and interaction with the models just as Jmol does, since the source code is shared by both. Note that JSmol is not a different program than Jmol: it is Jmol, just compiled into JavaScript instead of Java (thanks to the [http://java2script.sourceforge.net/ Java2Script] software).  
Line 6: Line 6:
 
* Using local files (i.e. not in a web server) may not be feasible depending on the browser (security policies).
 
* Using local files (i.e. not in a web server) may not be feasible depending on the browser (security policies).
 
* Opening binary files (e.g Spartan files, gzipped files, PNGJ files):
 
* Opening binary files (e.g Spartan files, gzipped files, PNGJ files):
** Binary files can now be read; not all file types are identified yet, only those that match a file extension; you should be able to rename any file to include <code>.bin</code> in its name to force JSmol to read it as a binary file. For example, <code>c6h6.bin.spartan</code> should work.
+
** Binary files can be read, but not all file types are identified yet, only those that match a few file extensions; if you rename any file to include <code>.bin</code> in its name, that will instruct JSmol to read it as a binary file. For example, <code>c6h6.bin.spartan</code> should work.
** For binary file reading to be compatible with Chrome and MSIE, you will need to have a base64 server-side piece that will convert the binary data to BASE64 format. This is because only Firefox allows clean (reliable) synchronous binary file transfer. The [http://chemapps.stolaf.edu/jmol/jsmol/test2.htm test2.htm demo page] is using a [http://chemapps.stolaf.edu/jmol/jsmol/jsmol.php jsmol.php file], which does that and considerably more.
+
** For binary file reading to be compatible with Chrome and MSIE, you will need to have a base64 server-side piece that will convert the binary data to BASE64 format. This is because only Firefox allows clean (reliable) synchronous binary file transfer. The [http://chemapps.stolaf.edu/jmol/jsmol/jsmol.htm demo pages] use a [http://chemapps.stolaf.edu/jmol/jsmol/jsmol.php jsmol.php file], which does that and considerably more.
* Commands that involve threading are not working yet. This includes <code>hover, spin, animation, minimize, delay</code>, as well as animated <code>move, moveTo, compare</code>.
+
* Writing of JPG and PNG data is not supported directly (but see [[Recycling_Corner#Exporting_an_image_from_the_applet|Exporting an image]]).
* Writing of JPG and PNG data is not supported.
 
 
* Background images are not supported.
 
* Background images are not supported.
  
 
When used together with [[Jmol JavaScript Object]] (Jmol-JSO), the same webpage may be authored to run in all devices using in each case a Jmol variety or surrogate that is adjusted to capabilities of each device.
 
When used together with [[Jmol JavaScript Object]] (Jmol-JSO), the same webpage may be authored to run in all devices using in each case a Jmol variety or surrogate that is adjusted to capabilities of each device.
  
JSmol is still in the development stage (Nov. 2012). You can see it in action at the [http://chemapps.stolaf.edu/jmol/jsmol/test2.htm test page]. The current set of files (development version, subject to changes) may be downloaded [http://chemapps.stolaf.edu/jmol/JSmol.zip here].
+
JSmol is still in a development stage, although mostly functional (Feb. 2013). You can see it in action at the [http://chemapps.stolaf.edu/jmol/jsmol/jsmol.htm test page]. Preliminary releases may be obtained at [http://sourceforge.net/projects/jsmol/ the JSmol Project page] and the latest development set of files from [http://chemapps.stolaf.edu/jmol/jsmol.zip St. Olaf].
  
  
Necessary code is like this (subject to change):  
+
The code you must include in your pages is like this:  
  
 
In the <code>head</code> section:
 
In the <code>head</code> section:
  <script type="text/javascript" src="JSmoljQuery.js"></script>
+
  <script type="text/javascript" src="JSmol.min.js"></script>
<script type="text/javascript" src="JSmolCore.js"></script>
 
<script type="text/javascript" src="JSmolApplet.js"></script>
 
<script type="text/javascript" src="JSmolApi.js"></script>
 
<script type="text/javascript" src="JSmolThree.js"></script>
 
<script type="text/javascript" src="JSmolGLmol.js"></script>
 
<script type="text/javascript" src="j2s/j2sjmol.js"></script>
 
<script type="text/javascript" src="JSmol.js"></script>
 
 
  <script type="text/javascript">
 
  <script type="text/javascript">
 
  var Info = {
 
  var Info = {
 
   width: 300,
 
   width: 300,
 
   height: 300,
 
   height: 300,
   serverURL: "http://chemapps.stolaf.edu/jmol/jsmol/jsmol.php ",
+
   serverURL: "<nowiki>http://chemapps.stolaf.edu/jmol/jsmol/jsmol.php</nowiki>",
 
   use: "HTML5",
 
   use: "HTML5",
 
   j2sPath: "j2s",
 
   j2sPath: "j2s",
   console: "jmolApplet0_infodiv"
+
   console: "myJmol_infodiv"
 
  }
 
  }
 
  </script>
 
  </script>
  
(see [[Jmol_JavaScript_Object]] for more details about the <code>Info</code> variable)
+
Please note that although a single JavaScript file is invoked, you must have available in your server the full set contained in the download, since additional components of JSmol will be called as needed by that initial {{file|JSmol.min.js}} file. (The total size is around 3 MB, but only those components needed will be downloaded to the user's machine.)
  
JSmolThree.js and JSmolGLmol.js are only necessary if you are using the WebGL version (which currently is only partially working).
+
See [[Jmol_JavaScript_Object]] for more details about the <code>Info</code> variable.
  
 
And in the <code><body></code> section:
 
And in the <code><body></code> section:

Revision as of 18:21, 17 February 2013

JSmol is the name for an alternative to Jmol applet that does not require Java but instead renders the molecular models in a webpage using just JavaScript and HTML5 features. This opens up the use of Jmol not only in PC's, Mac's and Linux's systems without Java installed, but also in tablets and phones (iOS, Android) that do not allow Java or applets. No hardware-based graphics acceleration is used either, and hence it should run in any system that supports HTML5 standards in the web browser. JSmol runs entirely in the client, does not use any server technologies.

JSmol allows rendering, scripting and interaction with the models just as Jmol does, since the source code is shared by both. Note that JSmol is not a different program than Jmol: it is Jmol, just compiled into JavaScript instead of Java (thanks to the Java2Script software).

Current limitations:

  • Using local files (i.e. not in a web server) may not be feasible depending on the browser (security policies).
  • Opening binary files (e.g Spartan files, gzipped files, PNGJ files):
    • Binary files can be read, but not all file types are identified yet, only those that match a few file extensions; if you rename any file to include .bin in its name, that will instruct JSmol to read it as a binary file. For example, c6h6.bin.spartan should work.
    • For binary file reading to be compatible with Chrome and MSIE, you will need to have a base64 server-side piece that will convert the binary data to BASE64 format. This is because only Firefox allows clean (reliable) synchronous binary file transfer. The demo pages use a jsmol.php file, which does that and considerably more.
  • Writing of JPG and PNG data is not supported directly (but see Exporting an image).
  • Background images are not supported.

When used together with Jmol JavaScript Object (Jmol-JSO), the same webpage may be authored to run in all devices using in each case a Jmol variety or surrogate that is adjusted to capabilities of each device.

JSmol is still in a development stage, although mostly functional (Feb. 2013). You can see it in action at the test page. Preliminary releases may be obtained at the JSmol Project page and the latest development set of files from St. Olaf.


The code you must include in your pages is like this:

In the head section:

<script type="text/javascript" src="JSmol.min.js"></script>
<script type="text/javascript">
var Info = {
  width: 300,
  height: 300,
  serverURL: "http://chemapps.stolaf.edu/jmol/jsmol/jsmol.php",
  use: "HTML5",
  j2sPath: "j2s",
  console: "myJmol_infodiv"
}
</script>

Please note that although a single JavaScript file is invoked, you must have available in your server the full set contained in the download, since additional components of JSmol will be called as needed by that initial File icon.gifJSmol.min.js file. (The total size is around 3 MB, but only those components needed will be downloaded to the user's machine.)

See Jmol_JavaScript_Object for more details about the Info variable.

And in the <body> section:

<script type="text/javascript">
  myJmol = Jmol.getApplet("myJmol", Info); 
</script>