Sunday, October 28, 2012

JmolApplet and Visualiziation of NBOs in Web Browsers


Lone-pair -> antibond delocalization in formamide.


In this post, we will continue exploring visualization possibilities offered by the free Jmol viewer, particularly, the graphical representations of Natural Bond Orbitals (NBOs) generated by GENNBO 5.0W.  Other sources of .31-.46 plot files can be used as well. Ultimately, we should be able to output and dynamically display selected NBOs in any web browser and further they display properties.

Jmol is a free, open source molecule  viewer running on several common operating systems (Mac, Windows).  There are two main applications that most users will want to use for visualization of molecular orbitals and molecular surfaces:

  • The JmolApplet is a web browser applet that can be integrated into web pages.
  • The Jmol application is a standalone Java application that runs on the desktop.

Jmol: an open-source Java viewer for chemical structures in 3D. http://www.jmol.org/
Let's go through the steps of setting up files, directories, and parameters to output visualization directly to a web browser.

As briefly outlined in the previous post, we first need to get the Jmol application files from
jmolsourceforge.net (zip file). Unpack the zip file into any drive/folder (e.g. D:/computation/jmol for this tutorial) and make a shortcut to Jmol.jar file on your desktop. Next, we will need the formamide.31-.46 plot files generated earlier (previous post). In case that you wish to reproduce examples in this tutorial, here are the files. For now, just keep them separate from the jmol directory.
To be able to use ScriptButton features of the Export to Web module of the Jmol application, we need to run a simple web server*. There are several choices available:
  • Using your own or institution's web server
  • Installing a free web server environment, such as WampServer
  • Running a simple portable web server, such as mongoose

* Launching .html files directly from the web export folder fails to display Interactive buttons and most importantly, the java visualizations.

Assuming that we want to run visualization on our local computer, the address will be http://localhost:8080/dir/file.html, where dir and file will be replaced by your actual directory name and the corresponding .html file name.

While I am using WampServer (on Windows 7, 32bit), examples discussed here use simpler and "light-weight" mongoose server. Download it (mongoose-x.x.exe) from the above link and place the .exe file at the same level where the Jmol file is located (Fig. 1).


This blog has been UPDATED (summer 2015) to reflect the recent changes in Jmol structure and Web presentation.
With the Chrome browser phasing out support of Java-based plugins (applets), Jmol development has moved to JavaScript-based framework and HTML5 support. 
As of mid-2015, Firefox, Opera, and IE still support java applets and plugins.


Fig. 1 Folder structure of the Jmol app and loca/server files

Preparing the web output:
Now, open the desktop version of Jmol (click Jmol.jar shortcut) and make sure to have sevral macro files ready (created earlier with JmolNBO Visualization Helper). Then go to:

  1.  File -> Export -> Export to web page and select tab "ScriptButton Jmol" 


  2. Fig. 2 Jmol Web Page Maker main window


  3. Fill out the Author field, and enter "./jsmol" into the "Relative server path to jar files" field. Upon saving the html page, Jmol export Jsmol directory to your server structure (./java/jsmol). Enter just a dot into the "Relative path to local jar files" field (see Fig. 2). 
  4. For each desirable loaded visualization (through the macro scripts in the main Jmol app window), click "Add Present Jmol State as Instance" button to add NBOs to make them available for display in the browser. Name the state (NBO) by its corresponding number (Fig. 2).
  5. Click "Save HTML as" and navigate to the folder where Jmol folder is located (Fig. 3). In this example, it is D:/computation/jmol/java.

Fig. 3 Exporting web files with the folder layout



Now, the important part - go to the folder with .31-.42 plot files created earlier.  Due to an unknown bug in the java code, you have to re-name files form.31 and form.46 to form.37.31 and form37.46, respectively and copy them into the just created web folder /java. Essentially, we just insert .37 in the middle of the file name. Files in that directory should look similar to the top three files in Fig. 4.


Fig. 4 Structure and new files in the web export folder
All files created in this last step (except of jsmol directory) are available for download (java.zip). Unpack them next to the Jmol folder (Fig. 5) and follow the next step to reproduce this tutorial.

Fig. 5 Final directory layout

Launching the server:


  • Launch mongoose.exe by double clicking it (Fig. 5). Mongoose web server icon will appear at the right-bottom notification area.
  • Confirm security exception (if any) and check "Install service". 
  • Type http://localhost:8080/java/java.html to launch the in browser. Again, replace "java" with the name of your actual folder and .html file name.
  • After finishing visualization, cancel and exit the mongoose server service.
Since the visualization and web structure use a lot of JavaScript, loading of all files may take 10-20s. Once the image is loaded there is a small 3D icon positioned down-left in the image window. Click on that icon to start loading 3D view and Jmol menu (opens on right-mouse click).

The final web view is shown below.


Note that there is still the option to switch to Java-driven view (link below the image). However, the view will not work in the Chrome browser as of version 43.

Watch video tutorial:
This video pertains to the early version of Jmol tutorial. While many steps are the same, please adapt revisions from the updated blog.
mobile link:





Saturday, October 27, 2012

Visualizing NBOs in Jmol

In the previous post, concept and usage of NBO analysis were introduced. This post outlines steps for visualization of natural bond orbitals in open source viewer - Jmol. We will also assume the least practical scenario - running our calculations in Gaussian 09 for Windows (G09W). 


There are two prerequisite parts that we need for NBO analysis:

  • Molecular system wavefunction and
  • NBO program that perform the analysis


The former is usually generated by our electronic structure system (ESS), the latter one is either part of the ESS or has to be purchased separately (see NBO web site). Currently, the most recent version of the NBO program is at version 5.9 (aka NBO5). Unfortunately, users of Windows version of Gaussian have only access to the older version of NBO (3.1), which is incorporated in binaries G03W or G09W. To gain access to NBO5 options, Windows users have to use GENNBO 5.0W application, which performs analysis of wavefunction generated by the Gaussian ESS. 

The process of obtaining NBO5 output files and results of NBO analysis is following:

  1. Specify POP=NBOREAD keyword in route card of Gaussian input file ($NBO keylist will be read and processed)
  2. Include the ARCHIVE and FILE=name in the $NBO keylist that is specified after the "standard" Gaussian input (Fig. 1). Leave one blank line before and after the keylist.
  3. File name.47 (in our case form.47) will be stored in "Scratch" directory of the G09W install path (typically C:\G09W).
  4. Open this name.47 file in any text editor and enter keywords "file=form plot" between $NBO ... $END delimiters at the top of the file (Fig. 2).
  5. Save the file and use it as input for GENNBO 5.0W analysis.


Fig. 1 Example of G09W input file for formamide



Fig. 2 Setting up $NBO keylist in name.47 file

After GENNBO analysis finishes, the corresponding .31-.46 plot files will be in the GENNBO5 main directory. I usually just move them into directory where all other output files reside. At this point, our directory should contain the following files (Fig. 3):


Fig. 3 List of created files



Having GaussView 5.0, but not GENNBO 5.0W? For direct output of NBOs from G09W/NBO3.1 binary, include command "POP=(nbo,savenbo)" in the input file route card. Only NBOs (not other orbitals) are then saved in .chk file for further analysis. Format the checkpoint .chk file with Gaussian utility to formatted .fch file and use GaussView 5.0 to visualize NBOs. Due to the slight differences in NBO3.1 and NBO5 calculations, NBOs may look a bit different.

With plot files .32-.46 in place, we are ready to inspect shapes and size of NBOs. Actually, not just yet. We need to install Jmol application that will run on our desktop. It is a free, open-source molecule viewer, running on Windows, Mac OS X, and Linux/Unix systems. Jmol can be downloaded from jmolsourceforge.net as .zip file. Unpack it in any place you wish and make shortcut to Jmol.jar file on your desktop. Then, just run it.

To make generation of the NBO imagery easier, we will use Jmol scripts that can be run as "macro". Save the following text between the dashed lined into file called, nbo12.macro
---------------------------------------------

Title=NBO12
Script=reset;background [0,0,150];load F:/your/path/to/plotfiles/form.37;mo 12;wireframe 30;spacefill 50;center {0.0 0.419936 0.0}; rotate z 145.3; rotate y 176.92; rotate z 13.53; translate x 3.92; translate y 5.95; set rotationRadius 3.27;isosurface color [247,255,71] [113,168,254] mo 12 opaque;mo nomesh;isosurface translucent 0.3;

---------------------------------------------

This file should have no line breaks after the first line (just a long line text). You will need to change the path to your set of .32-.40 plot files and orbital number after "mo" command. Currently, it will display mo 12 (NBO), which is the HOMO in our formamide example.

Now, save the above created file nbo12.macro in the "macro" folder located at:
C:\Users\username\.jmol\macros (Windows 7)

Launch the Jmol, click on "Macros" in the menu and click on "NBO12". You should see the following image.
Fig. 4  NBO 12 of formamide (HOMO)
In the next post, we will explore Jmol Applet and Visualiziation of NBOs in web browsers. Some other time, I'll take a look at the same visualization using Molekel 4.3.






Sunday, September 23, 2012

Natural Bond Orbitals (NBO)

Some of the most important information about chemistry can be obtained from solutions of the Schrödinger equation. It is through the use of quantum mechanics that we are able to arrive to solutions that can predict properties of molecules with a high level of accuracy. While there are many excellent teachers, books, and lectures describing the fundamental theory of quantum mechanics (QM), it is the interpretation and practicality of many existing QM schemes that chemists find difficult to translate into their everyday observations and understanding. By solving the Schrodinger equation one obtains "electronic energy" for a specific spatial and spin state of electron, called molecular orbital. As an exact solution of Schrödinger equation has only been achieved for one-electron system (hydrogen),  there are many computational techniques developed that approximate the solution for multiple-electron system.
To understand properties and reactivity of organic compounds, chemists have to rely on concepts such as, chemical bond, lone electron pair, conjugation, charges, aromaticity, and other properties, which are often difficult to predict or quantify. By successfully applying those understandings to molecular structures, more complex properties or concepts including anomeric effect, rotational barriers, hyperconjugation, resonance, and basicity can be described and predicted.

Molecular Orbitals:
The most commonly used technique to approximately solve the Schrödinger equation is called a Hartree-Fock method (HF), which  decomposes many-electron wavefunction into a combination of molecular orbitals that are normalized and orthogonal. Molecular orbitals are then expanded in terms of atomic orbitals as linear combination of atomic orbitals (LCAO). Conceptually different, but similar in mathematical formalism is Density functional theory (DFT), which has evolved rather recently from the Hohenberg and Kohn theorem, determines the energy of a molecule from the electron density instead of a wavefunction. In the HF analogy, a determinant of Kohn-Scham (K-S) orbitals is formed and the electron density is used to calculate energy. While there has been some debate over the interpretation of K-S orbitals (being a pure mathematical construct used to re-construct the density), their shapes tend to be remarkably similar to canonical HF MOs. Today, DFT formalism including the K-S orbitals are frequently used in qualitative analysis of chemical properties.

Although "classical" Hartree-Fock and Kohn-Sham orbitals are, by definition, the best possible for a single-configuration wavefunction or electron density, respectively, there is even a "better" set of orbitals, called "natural" orbitals, to describe the correlated electron density. And this is the point, where the concept of Natural Bond Orbitals comes in. NBO localization algorithm permits the form of the BOs to be fully optimized with respect to a maximum-occupancy criterion based solely on the first-order reduced density matrix. In NBO analysis, the input basis set is transformed successively into various localized basis sets, first to natural atomic orbitals and then to hybrid orbitals which are used to form bond orbitals (NBOs). Finally the NBOs are transformed into localized MOs. The NBO analysis can illuminate interesting chemical aspects of the bonding and allow explanations of the various chemistry phenomena, such as, reactivity, stereoselectivity, basicity, and intramolecular and intermolecular energy barriers, all based on orbital interaction concepts. Most importantly, from the chemist's perspective, NBO analysis provides an orbital picture that is as close as possible to a classical "textbook" Lewis structure for a molecule.


NBO methodology:
The NBO analysis involves sequential transformation of nonorthogonal atomic orbitals (AOs) to the complete and orthonormal sets of “natural” atomic orbitals (NAOs), hybrid orbitals (NHOs), and bond orbital (NBOs). These localized basis sets describe electron density and other properties by the smallest number of filled orbitals in the most rapidly convergent fashion. As mentioned earlier, these orbital are closely related to the localized orbitals (bonds and lone pairs) used by organic chemists. The NBO method was developed by Weinhold and co-authors and it is becoming a powerful and popular method for study of bonding concepts. 

On a more technical level, the NBO localization protocol divides NBOs into core, bonding, anti-bonding and ‘‘Rydberg’’(remaining) orbitals. The core and bonding orbitals describe the strictly localized Lewis structure of a molecule. The sequence goes through various localized basis sets in the following order:

AOs-> NAOs -> NHOs -> NBOs -> NLMOs -> CMOs 

Examples of properties that can be calculated in NBO basis include:
  • Dipole, polarizability, atomic charges,
  • Bonding-anti-bonding orbital interactions, 
  • Resonance structures (second order perturbation theory),
  • Bond orders,
  • Energy decomposition,
  • Chemical shift, J-couplings,
  • Steric analysis,
  • Canonical MO analysis.

Differences between  canonical and NBO MOs:
  • Canonical MOs (CMOs) are delocalized over the whole molecule,
  • They usually bear no resemblance to localized s and p bonds, or to lone pairs, so they cannot be used to support familiar chemical reasoning 
  • On the path to NBOs, an ordinary MO calculation is done at a high enough level to reproduce measured geometry or energies (delocalized MOs are obtained), 
  • Then the atomic basis set is transformed into an equal number of natural atomic orbitals (NAOs), and the MOs into an equal number of natural bond orbitals (NBOs) 
  • These additional transformations are cheap in computer time
  • More intuitive NBOs are result of those mathematical transformations 


While analysis of the NBO results is instructive and informative, one usually wishes to visualize newly generated NBOs. In the next post, I will describe the use of Jmol for visualization of NBOs.

References:
  • F. Weinhold, "Natural Bond Orbital Methods" in, Encyclopedia of Computational Chemistry, P. v.R. Schleyer, N. L. Allinger, T. Clark, J. Gasteiger., P. A. Kollman, H. F. Schaefer III, P. R. Schreiner (Eds.), (John Wiley & Sons, Chichester, UK, 1998), Vol. 3, pp. 1792-1811. 
  • F. Weinhold and C. R. Landis, Valency and Bonding: A Natural Bond Orbital Donor-Acceptor Perspective (Cambridge University Press, Sept 2005). 
  • A. E. Reed, L. A. Curtiss, and F. Weinhold, Chem. Rev. 88, 899-926 (1988).
  • L. Pauling, "The Nature of the Chemical Bond", (Cornell University Press, 3rd ed., 1960)