Posts Tagged ‘jmol’

Ten years on: Jmol and WordPress.

Wednesday, May 16th, 2018

Ten years are a long time when it comes to (recent) technologies. The first post on this blog was on the topic of how to present chemistry with three intact dimensions. I had in mind molecular models, molecular isosurfaces and molecular vibrations (arguably a further dimension). Here I reflect on how ten years of progress in technology has required changes and the challenge of how any necessary changes might be kept “under the hood” of this blog.

That first post described how the Java-based applet Jmol could be used to present 3D models and animations. Gradually over this decade, use of the Java technology has become more challenging, largely in an effort to make Web-page security higher. Java was implemented into web browsers via something called Netscape Plugin Application Programming Interface  or NPAPI, dating from around 1995. NPAPI has now been withdrawn from pretty much all modern browsers. Modern replacements are based on JavaScript, and the standard tool for presenting molecular models, Jmol has been totally refactored into JSmol. Now the challenge becomes how to replace Jmol by JSmol, whilst retaining the original Jmol Java-based syntax (as described in the original post). Modern JSmol uses its own improved syntax, but fortunately one can use a syntax converter script Jmol2.js which interprets the old syntax for you. Well, almost all syntax, but not in fact the variation I had used throughout this blog, which took the form:

<img onclick=”jmolApplet([450,450],’load a-data-file;spin 3;’);” src=”static-image-file” width=”450″ /> Click for 3D structure

This design was originally intended to allow browsers which did not have the Java plugin installed to default to a static image, but that clicking on the image would allow browsers that did support Java to replace (in a new window) the static image with a 3D model generated from the contents of a-data-file. The Jmol2.js converter script had not been coded to detect such invocations. Fortunately Angel came to my rescue and wrote a 39 line Javascript file that does just that (my Javascript coding skills do not extend that far!). Thanks Angel!!

In fact I did have to make one unavoidable change, to;

<img onclick=”jmolApplet([450,450],’load a-data-file;spin 3;’,’c1′);” src=”image-file” width=”450″ /> Click for 3D structure

to correct an error present in the original. It manifests when one has more than one such model present in the same document, and this necessitates that each instance has a unique name/identifier (e.g. c1). So now, in the WordPress header for the theme used here (in fact the default theme), the following script requests are added to the top of each page, the third of which is the new script.

<script type=”text/javascript” src=”JSmol.min.js”></script>
<script type=”text/javascript” src=”js/Jmol2.js”></script>
<script type=”text/javascript” src=”JmolAppletNew.js”></script>

The result is e.g.

Click for 3D

Click for 3D structure of GAVFIS

Click for 3D

Click for 3D interaction

This solution unfortunately is also likely to be unstable over the longer term. As standards (and security) evolve, so invocations such as onclick= have become considered “bad practice” (and may even become unsupported). Even more complex procedures will have to be devised to keep up with the changes in web browser behaviour and so I may have to again rescue the 3D models in this blog at some stage! Once upon a time, the expected usable lifetime of e.g. a Scientific Journal (print!) was a very long period (>300 years). Since ~1998 when most journals went online, that lifetime has considerably shortened (or at least requires periodic, very expensive, maintenance). For more ambitious types of content such as the 3D models discussed here, it might be judged to be <10 years, perhaps much less before the maintenance becomes again necessary. Sigh!


At the time of writing, WaterFox is one of the few browsers to still support it. An early issue with using Javascript instead of Java was performance. For some tasks, the former was often 10-50 times slower. Improvements in both hardware and software have now largely eliminated this issue. Thus using Jquery.

Twenty one years of chemistry-related Java apps: RIP Java?

Saturday, June 10th, 2017

In an earlier post, I lamented the modern difficulties in running old instances of Jmol, an example of an application program written in the Java programming language. When I wrote that, I had quite forgotten a treasure trove of links to old Java that I had collected in 1996-7 and then abandoned. Here I browse through a few of the things I found.

The collection is at DOI: 10.14469/hpc/2657. Here I track down how some of them are doing 20+ years on.

  1. Formula-To-Mass-To-Formula (f2m2f), which was started in August 1996 and was written by Guillaume Cottenceau, a french undergraduate student visiting London and who wanted to learn to program. I suggested he try Java, and as I recollect sent him out to the business park west of London where Sun Microsystems had an office to learn how to do so (they had only released the development kit a few months earlier!). The applet he wrote still works (being unsigned, you have to jump through a few hoops to allow it to run (but be quick, not many browsers will still let you do so!). The applet also has a benchmark feature. Running the heavy bench now takes ~ 0.4s on a laptop.  I cannot be sure,  but I seem to remember that this one took ~20 seconds back in 1997. 
  2. Guillaume then returned to Paris to finish the above off, but also managed to find the time a year later to produce Jspec, a visualiser for NMR and MS. Darek Bogdal was visiting from Poland in August 1997(8?) and he incorporated these tools into a general spectral display and problem solving resource, which also still mostly works (with no curation!). The bit that does not work depended on the Chime plugin, now long gone and of course replaced in large measure by Jmol and now JSmol. 
  3. Here is an equation setter. The original site has long gone, but I had copied the classes over and it also (mostly) works!
  4. This dates from 1997 by Wyn Locke and Alan Tongue and uses JavaScript plus the spectral viewer to communicate with Chime. All done much better by many others since of course.

That said, many of the other links at DOI: 10.14469/hpc/2657 no longer work. In truth I am slightly surprised a few still do! 

Quite possibly these screen shots may be the only visual images that can be created in the very near future, as all but very specialised web browsers drop “plug-in” (aka Java) support. So perhaps it will be RIP Java, at least for the in-browser frame mode (but certainly not for the stand-alone application mode).

Curating a nine year old journal FAIR data table.

Monday, May 29th, 2017

As the Internet and its Web-components age, so early pages start to decay as technology moves on. A few posts ago, I talked about the maintenance of a relatively simple page first hosted some 21 years ago. In my notes on the curation, I wrote the phrase “Less successful was the attempt to include buttons which could be used to annotate the structures with highlights. These buttons no longer work and will have to be entirely replaced in the future at some stage.” Well, that time has now come, for a rather more crucial page associated with a journal article published more recently in 2009.[1]

The story started a few days ago when I was contacted by the learned society publisher of that article, noting they were “just checking our updated HTML view and wanted to test some of our old exceptions“. I should perhaps explain what this refers to. The standard journal production procedures involve receiving a Word document from authors and turning that into XML markup for the internal production processes. For some years now, I have found such passive (i.e. printable only) Word content unsatisfactory for expressing what is now called FAIR (Findable, accessible, inter-operable and re-usable) data. Instead, I would create another XML expression (using HTML), which I described as Interactive Tables and then ask the publisher to host it and add that as a further link to the final published article. I have found that learned society publishers have not been unwilling to create an “exception” to their standard production workflows (the purely commercial publishers rather less so!). That exceptional link is http://www.rsc.org/suppdata/cp/b8/b810301a/Table/Table1.html but it has now “fallen foul of the java deprecation“. 

Back in 2008 when the table was first created, I used the Java-based Jmol program to add the interactive component. That page, when loaded, now responds with the message:

This I must emphasise is nothing to do with the publisher, it is the Jmol certificate that has been revoked. That of itself requires explanation. Java is a powerful language which needs to be “sandboxed” to ensure system safety. But commands can be created which can access local file stores and write files out there (including potentially dangerous ones). So it started to become the practise to sign the Java code with the developer certificate to ensure provenance for the code. These certificates are time-expired and around 2015 the time came to renew it. Normally, when such a certificate is renewed, the old one is allowed to continue operation. On this occasion the agency renewing the certificate did not do this but revoked the old one instead (Certificate has been revoked, reason: CESSATION_OF_OPERATION, revocation date: Thu Oct 15 23:11:18 BST 2015). So all instances of Jmol with the old certificate now give the above error message. 

The solution in this case is easy; the old Jmol code (as JmolAppletSigned.jar) is simply replaced with the new version for which the certificate is again valid. But simply doing that alone would merely have postponed the problem; Java is now indeed deprecated for many publishers, which is a warning that it will be prohibited at some stage in the future.‡ So time to bite the bullet and remove the dependency on Java-Jmol, replacing it with JSmol which uses only JavaScript.

Changing published content is in general not allowed; one instead must publish a corrigendum. But in this instance, it is not the content that needs changing but the style of its presentation (following the principle of the Web of a clear-cut separation of style and content). So I set out to update the style of presentation, but I was keen to document the procedures used. I did this by commenting out non-functional parts of the style components of my original HTML document (as <!– comment –>) and adding new ones. I describe the changes I made below.

  1. The old HTML contained the following initialisation code: jmolInitialize(".","JmolAppletSigned.jar");jmolSetLogLevel('0'); which was commented out.
  2. New scripts to initialize instead JSmol were added, such as:
    <script src="JSmol.min.js" type="text/javascript"> </script>
  3. I added further scripts to set up controls to add interactivity.
  4. The now deprecated buttons had been invoked using a Jmol instance:  jmolButton('load "7-c2-h-020.jvxl";isosurface "" opaque; zoom 120;',"rho(r) H")
  5. which was replaced by the JSmol equivalent, but this time to produce a hyperlink rather than a button (to allow the greek ρ to appear, which it could not on a button): <a href="javascript:show_jmol_window();Jmol.script(jmolApplet0,'load 7-c2-020.jvxl;isosurface &quot;&quot; translucent;spin 3;')">ρ(r)</a>,
  6. Some more changes were made to another component of the table, the links to the data repository. Originally, these quoted a form of persistent identifier known as a Handle; 10042/to-800. Since the data was deposited in 2008, the data repository has licensed further functionality to add DataCite DOIs to each entry. For this entry,  10.14469/ch/775. Why? Well, the original Handle registration had very little (chemically) useful registered metadata, whereas DataCite allows far richer content. So an extra column was added to the table to indicate these alternate identifiers for the data.
  7. We are now at the stage of preparing to replace the Java applet at the publishers site with the Javascript version, along with the amended HTML file. The above link, as I write this post, still invokes the old Java, but hopefully it will shortly change to function again as a fully interactive table.
  8. I should say that the whole process, including finding a solution and implementing it took 3-4 hours work, of which the major part was the analysis rather than its implementation.

It might be interesting to speculate how long the curated table will last before it too needs further curation. There are some specifics in the files which might be a cause for worry, namely the so-called JVXL isosurfaces which are displayed. These are currently only supported by Jmol/JSmol. They were originally deployed because iso-surfaces tend to be quite large datafiles and JVXL used a remarkably efficient compression algorithm (“marching cubes”) which reduces their size ten-fold or more. Should JSmol itself become non-operational at some time in the (hopefully) far future (which we take to be ~10 years!) then a replacement for the display of JVXL will need to be found. But the chances are that the table itself will decay “gracefully”, with the HTML components likely to outlive most of the other features. The data repository quoted above has itself now been available for ~12 years and it too is expected to survive in some form for perhaps another 10. Beyond that period, no-one really knows what will still remain. 

You may well ask why the traditional journal model of using paper to print articles and which has survived some 350 years now, is being replaced by one which struggles to survive 10 years without expensive curation. Obviously, a 3D interactive display is not possible on paper. But one also hears that publishers are increasingly dropping printed versions entirely. One presumes that the XML content will be assiduously preserved, but re-working (transforming, as in XSLT) any particular flavour of XML into another publishers systems is also likely to be expensive. Perhaps in the future the preservation of 100% of all currently published journals will indeed become too expensive and we might see some of the less important ones vanishing for ever?


Nowadays it is necessary to configure your system or Web browser to allow even signed valid Java applets to operate. Thus in the Safari browser (which still allows Java to operate, other popular browsers such as Chrome and Firefox have recently removed this ability), one has to go to preferences/security/plugin-settings/Java, enter the URL of the site hosting the applet and set it to either “ask” (when a prompt will always appear asking if you want to accept the applet) or “on” when it will always do so. How much longer this option will remain in this browser is uncertain.

In the area of chemistry, an early pioneer was the Internet Journal of Chemistry, where the presentation of the content took full advantage of Web-technologies and was on-line only. It no longer operates and the articles it hosted are gone.

References

  1. H.S. Rzepa, "Wormholes in chemical space connecting torus knot and torus link π-electron density topologies", Phys. Chem. Chem. Phys., vol. 11, pp. 1340-1345, 2009. https://doi.org/10.1039/b810301a

Does combining molecules with augmented reality have a future?

Monday, March 28th, 2016

Augmented reality, a superset if you like of virtual reality (VR), has really been hitting the headlines recently. Like 3D TV, its been a long time coming! Since ~1994 or earlier, there have been explorations of how molecular models can be transferred from actual reality to virtual reality using conventional computers (as opposed to highly specialised ones). It was around then that a combination of software (Rasmol) and hardware (Silicon Graphics, and then soon after standard personal computers with standard graphics cards) became capable of such manipulations. VRML (virtual reality modelling language) also proved something of a false start So have things changed?

Many of the posts on this blog have some element of such VR in the form of the Jmol or JSmol software (the natural successor to Rasmol) that allows a 2D projection of a 3D model to be manipulated in "real-time", allowing the geometrical features to be inspected and even animations of reactions. Google cardboard is a (minor?) variation on the VR theme, allowing a 3D object to be viewed through a simple cardboard headset containing a mounted phone, but controlled by head movements acting on the accelerometers in the phone rather than a mouse or trackpad. But the full-blown experience is something else, and watching this TED video really brought it home to me. The virtual object, such as say a molecule, is superimposed upon one's view of the real world (AR) and this object can now be controlled with hands as well as eyes. Again, this is not new; so-called haptic control of virtual objects has been around for a decade or more, in which you can e.g. probe how "hard" an object is using a haptic or hands-on device such as a joystick. All of this quickly convinces one that the secret of successful use of VR and now AR to augment chemistry is going to be the software!

We now need inspired programmers to create the Rasmol/Jmol of augmented reality. But beyond mere software, chemistry with AR needs to be placed into the appropriate environment or context. One might presume this will include the stereoscopic video inputs from other AR headsets (the research team, the collaborators, etc) but what else? The pages of a blog? Or a journal article? Could indeed one recast the journal article itself into an AR scene, with the various components floating in space, with molecules conjured out of a table (or a synthetic procedure) to float in full 3D glory to be played with by the participants? I rather suspect this might be quite a few steps too many for most!  Think how little ~22 years of the Web (and perhaps ~36 years of the Internet itself) has actually changed the construction (I do not mean the delivery) of the average scientific article. Even now, tables in which molecules can be treated interactively are extremely rare. Most of this is because authoring tools such as Microsoft Word have not yet made the production of such documents viable. So perhaps the augmented-reality scientific or chemical article may not be quite around the corner. Perhaps the AR hype will end in the same way that 3D TV appears to have. But unless we experiment, we will never know the answer. So if any reader of this blog knows of interesting work in chemistry AR, do drop me a line.


Virtual Reality Modelling Language (VRML) in Chemistry, O. Casher, C. Leach, C. S. Page and H. S. Rzepa, Chem. in Brit., 1998, 34(9), 26. But VRML has made a come-back as the language of choice for 3D printing!

 

WebCite and Jmol

Sunday, April 18th, 2010

Since I have gotten into the habit of quoting some of my posts in other contexts, I have started to also archive them using WebCite. One can quote the resulting archive as:

Rzepa, Henry. Quintuple bonds.  2010-04-18. URL:http://www.ch.ic.ac.uk/rzepa/blog/?p=1722. Accessed: 2010-04-18. (Archived by WebCite® at http://www.webcitation.org/5p5BtuzSH)

There is one issue though.  Many of my posts expose molecules via a  Jmol popup.  WebCite cannot archive that aspect; the Jmol applet fails to run (it would be surprising, since WebCite would have to archive a local copy of  Jmol to create a new sandbox). Anyone got any thoughts?

A Disrotatory 4n+2 electron anti-aromatic Möbius transition state for a thermal electrocyclic reaction.

Thursday, April 2nd, 2009

Mauksch and Tsogoeva have recently published an article illustrating how a thermal electrocyclic reaction can proceed with distoratory ring closure, whilst simultaneously also exhibiting 4n electron Möbius-aromatic character (DOI 10.1002/anie.200806009). Why is this remarkable? Because the simple Woodward-Hoffmann rules state that a disrotatory thermal electrocyclic reaction should proceed via a Hückel-aromatic 4n+2 electron transition state. Famously, Woodward and Hoffmann stated there were no exceptions to this rule. Yet here we apparently have one! So what is the more fundamental? The disrotatory character, or the 4n/Möbius character in the example above? Mauksch and Tsogoeva are in no doubt; it is the former that gives, and the latter is correct.

So inevitably one has to ask; are there other examples? Well, during the annual updating of my own lecture notes on pericyclic reactions, I had decided to revisit a fascinating reaction, which we had first looked at years ago (below).

Electrocylization of [14] annulene

Electrocylization of 14 annulene. Click above to obtain model

Let us focus specifically on the last reaction, which involves cyclization of a [14] annulene. The pedagogic interest was to challenge the students as to whether this was a π4+π2 cycloaddition, or two 6-electron electrocyclizations. The answer of course was that either way of considering this reaction was equally valid, and both modes were presumed to proceed via Hückel-aromatic transition states. I had said as such in my lectures for many years. This year, I finally decided to evaluate the NICS index to verify this long stated hypothesis. NICS is a magnetic index which yields a negative value (of -10 to -16 ppm) for aromatic rings, and positive values for antiaromatic rings. I was fully expecting to get negative values for all three rings at the transition state. Of course, this result was not obtained! Instead, whilst the central ring did have a negative value (of -16.4 ppm), the two outer rings had the initially mystifying value of +4.8! In other words they were antiaromatic. The electron count was in no doubt, ie 4n+2 (six). The transition state stereochemistry was clearly disrotatory. But the resulting transition state ring was antiaromatic and not aromatic! Well, close (and this is why it helps to have models) inspection reveals that despite the disrotation, the bond which is being formed actually does so antarafacially, and that the topology of this transition state is actually Möbius and not  Hückel. A little more thought reveals that a thermal Möbius transition state with 4n+2 electrons must be antiaromatic. So we conclude by saying that a second example of how a disrotatory reaction can actually have Möbius character has now been revealed. Unlike the example shown by Mauksch and Tsogoeva, this Möbius transition state is actually anti-aromatic, the first example of such which has been postulated.

That the disrotatory mode is not the fundamental here is shown by the alternative exo isomer of this transition state. The antarafacial nature of the bond formation is retained, but now the disrotation is replaced by conrotation. The two electrocyclic rings however retain their anti-aromaticity. Notice also how for both the examples, the bond lengths in the aromatic central ring are fully delocalized (equalized), whereas for the two outside rings, they are full localized (with long and short bond lengths). These two properties are of course characteristic for aromatic and antiaromatic rings.

Let’s also take a look at the example preceeding the  [14] annulene, which is the analogous reaction of a  [16] annulene.  This reaction takes the phenomenon one stage further. The central ring is formed by a π4a + π4s cycloaddition via a Möbius aromatic transition state, whilst the two outer rings are again Möbius antiaromatic transition states, but now with conventional conrotation rather than disrotation.

Oh, there are other reactions in the above scheme. They, it turns out, are equally fascinating. But I will leave analysis of that to another day.

(See also Steve Bachrach’s blog)

Jmol and WordPress: Loading 3D molecular models, molecular isosurfaces and molecular vibrations into a blog

Saturday, April 12th, 2008

A lemniscular molecular orbital

Click on the static image to get an active model. The code used to obtain the above was:

  1. This line is best added to the theme header by editing the file /wp-content/themes/default/header.php to add the following line in the header:

    <script src="../Jmol/Jmol.js" type="text/javascript"></script>

  2. <img onclick="jmolInitialize('../Jmol/','JmolAppletSigned.jar');jmolSetAppletColor('yellow');
    jmolApplet([500,500],'load http://www.ch.imperial.ac.uk/rzepa/blog/wp-content/uploads/2009/08/HV2-62.jvxl;isosurface translucent;zoom 5;moveto 4 0 2 0 90 70;');"  alt="A lemniscular molecular orbital" src="http://www.ch.imperial.ac.uk/rzepa/blog/wp-content/uploads/2008/04/14-knot.jpg" />

    where of course the uploads directory needs to be modified to correspond to your own content, and the file and script following it also correspond to the effect you wish to achieve.

The path wp-content/uploads/2009/08/ is that created by the built-in editor using the Add media file upload mechanism. The Jmol directory is located at the level above that of the blog itself. The JVXL file is created from either the corresponding (Gaussian) output file, or a CUB file created using a program such as Gaussview. Any suitable surface can be displayed using JVXL. In addition to MOs, we have also displayed ELF (Electron localization function) isosurfaces and molecular vibrations. For the latter, use a script of the form

'load wp-content/uploads/2008/04/vibration.log; frame 9; vectors on;vectors 4;vectors scale 5.0; color vectors green; vibration 10;animation mode loop;'

where the vibration you want is contained in e.g. frame 9.

There does appear to be a display bug with the above; the Jmol model replaces the window rather than being inlined in it. Once the model is displayed, just refresh the page to return to the blog entry.

A recent addition is the display of non-covalent-interaction (NCI) surfaces, which are colour coded by using the values in one cube of points to colorize a second cube.

'load wp-content/uploads/2011/05/isobornyl1.xyz;isosurface wp-content/uploads/2011/05/isobornyl1.jvxl colorscheme translucent bgyor;'