|
Please, note that the methods in this page are not recommended, since they
do not use the Jmol.js library. They are kept here for reference, particularly
for experienced programmers.
A description of the Jmol implementation of the scripting language
is available at
Interactive Online Scripting Documentation page.
For small scripts the transition from
Chime to Jmol should be straightforward.
With larger, more
complicated Chime web applications you may have challenges
because the button/event mechanism is different.
It is strongly recommended that you use the functionality
built into Jmol.js,
a library written in JavaScript which is
included in the standard downloadable Jmol package.
Simple scripts which are executed at applet load time can be
executed using the "script" parameter as part of your applet
definition in HTML. These scripts will execute
on browser platforms which do not support JavaScript or the
LiveConnect interface between JavaScript and Java applets.
If you choose to use this method, see the examples below.
To develop more flexible web applications using the Jmol applet,
you must write JavaScript code which passes text strings using the
"script" method of the applet, but you don't need to write the code
since it is all easily implemented
by using the functions in Jmol.js library.
For additional examples and documentation on Jmol applet scripting
see the documentation page.
The following examples are kept for reference by experienced programmers.
Please, note that they use the applet tag, with is deprecated since
HTML 4 and may become nonfunctional in modern browsers when HTML 5 becomes the default.
The recommended altenative is to use the object tag instead, but this
is tricky to implement because it requires different code for each browser.
Therefore, it is strongly recommended that you make your pages with JmolApplets
using the Jmol.js library provided with Jmol
distributions, since that takes care of inserting the proper code.
Eye Candy Without JavaScript
Basic Scripting
Advanced Scripting
This example demonstrates how scripting can be used without
JavaScript. Browsers that do not support LiveConnect communication
between JavaScript and Java applets will still run this type
of script.
<applet name="flash" code="JmolApplet" archive="JmolApplet.jar"
codebase="../jmol"
width="300" height="100" align="left" mayscript="true">
<param name="bgcolor" value="teal">
<param name="progressbar" value="true">
<param name="script" value="
load jmol.mol;
set perspectiveModel 10;
set zoomLarge off;
select all; cpk off; wireframe 10; color yellow;
move 0 0 0 400 0 0 0 0 2;
cpk 10; wireframe 5; delay 0.1;
cpk 30; wireframe 15; delay 0.1;
cpk 50; wireframe 30; delay 0.1;
cpk 70; wireframe 50; delay 0.1;
select atomno=1, atomno=9; color blue; delay 0.1;
select atomno=2, atomno=10; color red; delay 0.1;
select atomno=3, atomno=11; color green; delay 0.1;
select atomno=4, atomno=12; color orange; delay 0.1;
select atomno=5, atomno=13; color pink; delay 0.1;
select atomno=6, atomno=14; color brown; delay 0.1;
select atomno=7, atomno=15; color purple; delay 0.1;
select atomno=8, atomno=16; color cyan; delay 0.1;
move 0 0 0 -400 0 0 0 0 1;
move 0 0 360 50 0 0 0 0 1;
move 0 360 0 350 0 0 0 0 1;
loop 5;
">
</applet>
|
This example shows some of the scripting available.
<applet name="jmol" code="JmolApplet" archive="JmolApplet.jar"
codebase="../jmol"
width="200" height="200" mayscript="true">
<param name="progressbar" value="true"/>
<param name="load" value="caffeine.xyz"/>
</applet>
<br/>
<a href="javascript:document.jmol.script('wireframe on; spacefill off;');">
wireframe</a>
<a href="javascript:document.jmol.script('wireframe off; spacefill on;');">
spacefill</a>
<a href="javascript:document.jmol.script('wireframe 0.2; spacefill 25%;');">
ball & stick</a>
<br/>
<a href="javascript:document.jmol.script('load aspirina.mol');">
aspirina.mol</a>
<a href="javascript:document.jmol.script('load bulk_si.in');">
bulk_si.in</a>
<a href="javascript:document.jmol.script('load caffeine.xyz');">
caffeine.xyz</a>
<a href="javascript:document.jmol.script('load dna.xyz');">
dna.xyz</a>
<a href="javascript:document.jmol.script('load estron.cml');">
estron.cml</a>
<br/>
<a href="javascript:document.jmol.script('color background blue ; move 90 180 -45 0 0 0 0 0 5;
center 1 ; move 0 0 360 100 0 0 0 0 2 ; delay 2 ; reset; color background white')">move</a>
<a href="javascript:document.jmol.script('script move.txt');">
move off of server</a>
<a href="javascript:document.jmol.script('load aspirina.mol')">
load aspirina via script</a>
<a href="javascript:document.jmol.script('script testscript.txt')">
run test script off of server</a>
<br/>
<a href="javascript:document.jmol.script('set perspectiveDepth on')">
perspectiveDepth</a>
<a href="javascript:document.jmol.script('set perspectiveDepth off')">
no perspectiveDepth</a>
<br/>
<a href="javascript:document.jmol.script('color background black')">
black background</a>
<a href="javascript:document.jmol.script('color background grey')">
grey background</a>
<a href="javascript:document.jmol.script('color background [222,222,222]')">
background [222,222,222]</a>
<a href="javascript:document.jmol.script('color background white')">
white background</a>
wireframe
spacefill
ball & stick
aspirina.mol
bulk_si.in
caffeine.xyz
dna.xyz
estron.cml
move
move off of server
load aspirina via script
run test script off of server
perspectiveDepth
no perspectiveDepth
black background
grey background
background [222,222,222]
white background
More sophisticated and easier to code methods of interaction
are based on JavaScript, and provided by Jmol.js library.
|