Sunday, February 3, 2013

Getting started with JSmol

Readers of this blog will know I am quite fond of Jmol. But Jmol uses Java, which has some securities issues and doesn't work on iOS.  Luckily, Jmol has been converted to JavaScript to create a program called JSmol.

JSmol accepts all the same commands as Jmol, but setting up a webpage with JSmol is a little bit different.  Here is a very simple page to help get you started and the HTML code and be found below.
DOCTYPE html>
<html>
<title>A simple Jsmol example</title>
<head>
<script type="text/javascript" src="jsmol/JSmoljQuery.js"></script>
<script type="text/javascript" src="jsmol/JSmolCore.js"></script>
<script type="text/javascript" src="jsmol/JSmolApplet.js"></script>
<script type="text/javascript" src="jsmol/JSmolApi.js"></script>
<script type="text/javascript" src="jsmol/j2s/j2sjmol.js"></script>
<script type="text/javascript" src="jsmol/JSmol.js"></script>
<!-- // following two only necessary for WebGL version: -->
<script type="text/javascript" src="jsmol/JSmolThree.js"></script>
<script type="text/javascript" src="jsmol/JSmolGLmol.js"></script>
<script type="text/javascript">
var Info = {
width: 300,
height: 300,
// serverURL: "http://chemapps.stolaf.edu/jmol/jsmol/jsmol.php ",
serverURL: "http://propka.ki.ku.dk/~jhjensen/jsmol/jsmol.php ",
use: "HTML5",
j2sPath: "jsmol/j2s",
console: "jmolApplet0_infodiv"
}
</script>
</head>
<body>
<script type="text/javascript">
jmolApplet0 = Jmol.getApplet("jmolApplet0", Info);
Jmol.script(jmolApplet0,"background black;load caffeine.xyz")
</script>
<br>
<a href="javascript:Jmol.script(jmolApplet0,'spin on')">spin</a>
<a href="javascript:Jmol.script(jmolApplet0,'spin off')">off</a>
</body>
view raw gistfile1.txt hosted with ❤ by GitHub

The location of the jsmoltest.html is in my home directory while the jsmol code is in a folder called "jsmol" also sitting in my hope directory.  The jsmol folder is created when you unzip the JSmol zip file you can download here.

The JSmol distribution also includes a simple example of having two JSmol windows on one webpage.  You can find that file here.

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 

2 comments:

Angel Herráez said...

Also, latest version of JSmol includes a minified / packed version of the libraries, so you only need to call a single JS file in the head.

Jan Jensen said...

Not sure I understand completely. Do you have an example?