Jmol JavaScript Object/JSV

From Jmol
Revision as of 11:34, 27 April 2019 by AngelHerraez (talk | contribs) (update documentation on JSpecView)
Jump to navigation Jump to search

JSpecView

JSpecView is a graphical viewer for spectral data in the JCAMP-DX format. It was initially developed as a Java application and Java applet, at the Department of Chemistry of the University of the West Indies, Mona, Jamaica.

It was later integrated into Jmol distribution and converted, to avoid Java, as a JavaScript-HTML5 version. This page documents this latter version.

Integration of JSpecView into Jmol-JSO

Extensive work in 2012 integrated JSpecView into Jmol 13 thanks to the JSO infrastructure (the same used for JSmol).

  • The Jmol application now includes a new tools menu item that opens a frame for JSpecView.
  • The JSmol object can communicate to and from a JSpecView object in the same page, using the Jmol sync command. The JSmol object syntax (Jmol-JSO) brokers this transaction and allows coordinated start-up of both kind of objects so that one does not send a command to the other before both are ready.

This makes it possible to tie 3D models to IR, NMR, UV/VIS, GC, and GC/MS spectra, using the JCAMP-DX Version 6 standard.

Associated with this integration, we have designed a specification for an extension of the JCAMP-DX format that allows one JDX file to contain both Jmol-readable 3D models and peak information, allowing the user to click on, for example, a carbon atom in Jmol and have the 13C-NMR spectrum automatically display and highlight the associated peak in JSpecView.

Note: this needs updating, StOlaf pages are broken at UWI pages use old Java versions, not JSmol.
For a demonstration of the Jmol <-> JSpecView connection, see the JSpecView subdirectory at St.Olaf or the demo pages at the University of the West Indies.

Initialization

Add this in the head section of your page:

<script src="somePath/JSmol.min.js" type="text/javascript"></script>
<script src="somePath/js/JSmolJSV.js" type="text/javascript"></script>

And also define jsvInfo (you can use whatever name for this variable) which is an associative array (a set of key+value pairs) indicating all the desired characteristics of the JSpecView object. The keys that may be used and their default values are given below:

  • height 500
  • width 300
  • color #FFFFFF
  • j2sPath j2s
  • jarPath java
  • jarFile JSpecViewApplet.jar
  • isSigned false
  • initParams <empty>
  • readyFunction <empty>
  • script <empty>

Example:

var jsvInfo = {
  j2sPath: 'somePath/j2s',
  height: 300,
  width: 300,
  script: 'load "acetophenone.jdx"'
};


Creating and inserting the JSpecView applet

To create a JSpecView applet and insert it into the htm page, use for example:

Jmol.getJSVApplet("myJSV", jsvInfo)

This will create a myJSV global variable in JavaScript that holds the JSpecView object and is also the unique ID for that object in all functions and methods described below.

If you prefer to insert the JSpecView object later after page creation, you can use:

Jmol.getJSVAppletHtml("myJSV", jsvInfo)

For example like this:

$("#myPlace").html( Jmol.getJSVAppletHtml("myJSV", jsvInfo) )


JSpecView-specific methods

All these functions must be applied to the unique Jmol object (this name is literal, cannot be changed):

Handling files and scripting:

Jmol.jsvLoadInline(myJSV, data, params)
Jmol.jsvRunScript(myJSV, script)
Jmol.jsvRunScriptNow(myJSV, script) 
Jmol.jsvSyncScript(myJSV, peakScript)
Jmol.jsvExport(myJSV, exportType, n) 
Jmol.jsvSetFilePath(myJSV, tmpFilePath) 

Configuration:

Jmol.jsvIsPro(myJSV) 
Jmol.jsvIsSigned(myJSV) 

Interface:

Jmol.jsvAddHighlight(myJSV, x1, x2, r, g, b, a) 
Jmol.jsvRemoveHighlight(myJSV, x1, x2)
Jmol.jsvRemoveAllHighlights(myJSV) 
Jmol.jsvToggleCoordinate(myJSV)
Jmol.jsvToggleGrid(myJSV) 

Other features:

Jmol.jsvGetCoordinate(myJSV) 
Jmol.jsvGetPropertyAsJavaObject(myJSV, key) 
Jmol.jsvGetPropertyAsJSON(myJSV, key) 
Jmol.jsvGetSolnColour(myJSV) 
Jmol.jsvReversePlot(myJSV) 
Jmol.jsvSetSpectrumNumber(myJSV, n) 
Jmol.jsvSetVisible(myJSV, true/false)
Jmol.jsvToggleIntegration(myJSV)
Jmol.jsvWriteStatus(myJSV, message)

Contributors

AngelHerraez