Friday 11 January 2013

3. Embedding a jmol applet in your blog

Jmol has a beautiful feature: it can be embedded in a web page so you can present an interactive jmol view in yours, including blog posts.

You will need a place in the web to store the jmol jar file. If you don't have your own server, you can just use your Dropbox (or similar service) public folder, and this is the method i will describe here as it is readily available for anyone.

First step is to download the latest version (i had problems testing the procedure with version 12. My tests were done with version 13.0.10) of jmol full source package and uncompress it:
http://sourceforge.net/projects/jmol/files/Jmol/

Then create a folder jmol inside your Dropbox Public folder, and copy there the file JmolAppletSigned.jar and any of the models you want to show in your web page or blog. In Jmol version 14, JmolAppletSigned.jar comes inside a zip file jsmol.zip, included in the jmol distribution.

Finally, assuming the public Dropbox link to the folder is http://dl.dropbox.com/u/xxxxxxxx/jmol/, you would include something like this in the proper place in your post:

<applet name='jmol' code="JmolApplet" archive="http://dl.dropbox.com/u/xxxxxxxx/jmol/JmolAppletSigned.jar" width="350" height="350">
<param name="progressbar" value='true' />
<param name="script" value="load http://dl.dropbox.com/u/xxxxxxxx/jmol/L-proline.mol; spin on;" />
</applet>

And this is the working example (give a time to load):


Observe that you can interact with the applet using your mouse1. Right button opens an options menu. You can change the size of the applet area at taste using the tag attributes width and height. This is the most basic usage. About everything else, it is just a matter of adding the needed jmol script code in the value attribute of the script parameter.

Notes

[1] Check my previous post Visualizing a 3D structure of a molecule with jmol.

Thursday 10 January 2013

2. Creating a molecule scheme with bkchem

The best application i found for creating a molecule scheme is bkchem. It has an excellent user interface for scheme edition and reads smiles1 files.

In comparison with other applications, i found bkchem has very practical and friendly tools for performing edition operations, where the others becomes very annoying and even impossible.

Let's introduce the user interface of bkchem by creating the scheme of D-glucose molecule (the figure is what we want to obtain as final result)
  1. Go to main menu -> Chemistry -> Read SMILES and enter the smiles string for D-glucose O=C[C@H](O)[C@@H](O)[C@H](O)[C@H](O)C(O).
  2. Select the "transformation mode" set of tools (from the first line of icons menu), and using its different tools unfold and align the obtained structure.
  3. In order to fix the group symbols order (in our example, OH instead of HO, or viceversa) click right button over the group, and select option Symbol positioning. Select center last or center first, according to your needs.
  4. Finally lets fix the bond draws in order to reflect the correct stereo isomer configuration. Use the "draw" set of tools and fix bonds with the wedge and hatch tools.
  5. bkchem saves the image directly in SVG (Scalable Vector Graphics) format, another big advantage i found with this program. SVG graphic format is very suitable for edition of molecule schemes, because is based on vector primitives instead of pixels. And most important browsers and document editing applications supports it. Before saving the file, just ensure to crop the image to the area of the scheme (main menu -> File -> File properties) with a nice margin.
This has been an introduction using just a small subset --but the most used-- of tools among all the possibilities this application provides, so i leave for you the task for exploring the rest.

Notes

[1] On smiles files, see previous post, Visualizing a 3D structure of a molecule with jmol.

Wednesday 9 January 2013

1. Visualizing a 3D structure of a molecule with jmol

jmol is well suited for creating 3D molecule structures in a graphical way, and my first steps were in this direction. However, soon i found that writing the molecule specification in a smiles formatted file, import them to mol format and finally open with jmol is much easier and much much faster, once you learn the smiles format specifications (very easy indeed).

The best place i found for learning smiles format specs is
http://www.daylight.com/dayhtml/doc/theory/theory.smiles.html
A smiles file consist just in a text file with a single line which specifies chemical composition and structure. In the table below some examples are shown.

molecule namesmiles specification
methanolCO
ammonium[NH4+]
D-glucoseO=C[C@H](O)[C@@H](O)[C@H](O)[C@H](O)C(O)
L-proline[O-]C(=O)C1CCC[NH2+]1
psilocybinO(P(O)(=O)[O-])c1cccc2c1c(CC[NH+](C)C)cn2
iron(III) oxideO=[Fe]O[Fe]=O
Sodium chloride[Na+].[Cl-]

Another great advantage of using this approach is that most chemical compounds found in wikipedia comes with the smiles specification string.

Once you have the smiles file with the molecule spec, you can easily convert to jmol format file (.mol extension), using babel:
linux$ babel myfile.smi myfile.mol --gen3d
The --gen3d option is needed in order to generate 3D coordinates in the destination file. babel will also perform energy minimization calculations in order to create a valid molecule configuration.

Finally, you open it with jmol:
linux$ jmol myfile.mol
The image is an example on how a molecule looks in the jmol visualizer area (jmol can export a view as an image in different formats), according to ball-and-stick model:



Once in the jmol visualizer, you can move and rotate the molecule easily with the mouse:

  • rotate on X axis: press left button and move the mouse pointer up/down without releasing the button.
  • rotate on  Y axis: press left button and move the mouse pointer left/right without releasing the button.
  • rotate on Z axis: press SHIFT key, then right button, and move the mouse pointer left/right without releasing the key nor the button.
  • move away/closer: use the mouse wheel.
  • translate: double click left button and move mouse pointer without releasing button.
Rotation operations center is the first atom of the file.

Other interesting functions are accesible by clicking right mouse on the visualization area. For example, with menu View you can change the perspective from the six sides of the molecule bounding box. Also you can active spin on and off in order to view the molecule from a rotating camera around the object.

Jmol commands are also accesible from a console (to open: Menu File -> Console) and in fact advanced control and computations can only be done from the console.

For instance, spin can be set on/off from the console using the jmol command spin. Examples:
jmol$ spin on
jmol$ spin off
In order to reset the molecule to its initial position:
jmol$ reset
When you place the mouse over an atom, a label will be displayed (by default, the element symbol plus the number id of the atom, but can be controlled with the command hover). You can use this label with the command center in order to center the molecule at the given atom. Rotation operations then will be centered on the selected atom. Examples:
jmol$ center C3
jmol$ center N11

A complete reference of jmol commands and functions can be found here:
http://chemapps.stolaf.edu/jmol/docs/