This page is derived from a document written by Pascal Mercier.

Some of NMRView's internal commands behave differently in the J version, or are simply no longer supported. Similarly, Tk widgets might not be totally functional in J. This document lists some of the most encountered differences and tricks to bring everything up and running in NMRViewJ. It's surely not complete, but it's a start. Many thanks to Bruce Johnson for kindly answering all of my emails.

Tcl - general

The low-level code of NMRViewJ is written in the Java programming language. For scripting NMRViewJ uses the Jacl and Swank toolkits. Jacl is the Java implementation of the Tcl scripting language. Jacl doesn't correspond to exactly any particular version of Tcl. It is certainly in the family of 8.x Tcl, but lacks a few of the features of 8.4 (like lsearch -all) and more features of 8.5.

Swank is the Java implementation of the Tk Graphical User Interface Toolkit. Like Jacl, it doesn't correspond exactly to any particular version of Tk. In some ways, since it relies on the underlying Swing toolkit it has more features than Tk, but there also some limitations relative to Tk.

To use specific code for the J vs C version, you can test which version of the program is running using NMRView's global variable Nv_Priv(javaMode). See the example given below in the widgets section.

The info nameofexecutable command returns an empty string in Java. You might want to use the global variable tcl_platform instead. Type more tcl_platform in the console to all elements of the array and their values.

Widgets- general

The commands selection get and selection own do not work.

to replace selection get, refer to your widget directly:


 set index_selected_item [$widget curselection]
 set selection [$widget get $index_selected_item]

Widgets listboxes, scrollbars

Scrollbars do not work properly in Swank. There is, however, an alternative that is superior to scrollbars. Swank has a new widget, the "jscrollpane". If you add a scrollable widget (such as text, jtable or listbox) into it, it will add scrollbars automatically, and only if they are needed. The following bit of code illustrates the use:

listbox $NvStrips($nm,listbox) -yscrollcommand "$cframe.lframe.scroll1 set"
pack $NvStrips($nm,listbox) -fill both -expand y -side left
pack $cframe.lframe.scroll1 -fill y -expand y -side right
jscrollpane $cframe.lframe.spane
listbox $NvStrips($nm,listbox) -selectmode browse
$cframe.lframe.spane add $NvStrips($nm,listbox)
pack $cframe.lframe.spane -fill both -expand y -side left

To have a listbox with no scrollbars use the following:


$listbox configure -horizontalscrollbarpolicy [[java::field javax.swing.JScrollPane HORIZONTAL_SCROLLBAR_NEVER]]

The $listbox itemconfigure command does not work.

Window commands

The command nv_win clear is not working. Use:


   [nv_win act] dataset ""
   nv_win draw
   nv_win draw (yes, use nv_win draw twice)

nv_win anno

(from [BAJ]) The NMRViewJ spectrum widgets now inherit most all the properties of the Tk/Swank canvas widget. This means you can create lines, arcs, rectangles, text etc. directly on the spectra. This capability replaces the nv_anno command used in NMRViewC and provides substantially more features. Some examples are given below.

draw a red line on the spectrum

nv_win create line 5.7 118.0 8.3 120.0 -width 2 -fill red

draw a transparent black rectangle on the spectrum

nv_win create rectangle 6.0 115.0 8.0 120.0 -fill "0 0 0 100"

(the 100 is the transparency on a scale of 0 to 255)

draw a text label on the spectrum

nv_win create text 7.0 118.3 -text "This is the best peak in the spectrum"

drawslice axis

NvJ has a new subcommand for controlling slices: nv_win slice. See the documentation for details.

NvChangeLvl (up/down)

Use

  nv_win lvl [expr [nv_win lvl]*1.2]; nv_win draw   ;#(for up)
  nv_win lvl [expr [nv_win lvl]/1.2]; nv_win draw   ;#(for down)
  
  

Peak commands

nv_peak elem peaklist

In C, if no peak list is specified, the current peak list (the one returned by NMRView's global variable curr_list) is automatically used. In J, you MUST always specify a peak list, as it will not take the current peak list by default.

nv_peak elem dimname.L peaklist.peaknumber nv_peak elem comment peaklist.peaknumber:

Both these commands now return an empty string if the peak is not assigned, whereas the C version returns '?'.

This creates one possible problem: if you read in a peak list that was saved with a C version, you still get the '?' for unassigned peaks. Make sure your scripts check for both '?' and empty strings to detect peaks with no assignments.

nv_peak close: not working for now nv_peak match: not working for now nv_peak template: Always(!) use eval nv_peak template to set the template.

Atom commands

NMRViewJ offers better support for multiple molecules/polypeptide chains than the C version. As displayed in the atom analysis panel, a molecular identifier precedes each atom.

nv_atom num: no longer returns the atom index. Avoid using it for that purpose. At the moment, "nv_atom num" only returns two values:"-1" if the atom does not exist, "1" if the atom does exist.

nv_atom elem: all nv_atom elem commands work with atom identifiers in the form residue_number.atom_name (nv_atom elem ppm 5.N for instance). Similarly, all commands return an atom identifier, not a number anymore.

To get a list of all atoms in J, use:

mol select atoms *

Use:

  mol select atoms C*
  

to select only carbons, etc...)

set listofallatoms [mol listatoms]

if you want to get rid of the molecule identifiers returned by mol listatoms

set listofatoms_without_molidentifier {}

foreach item $listofallatoms { lappend listofatoms_without_molidentifier [lindex [split $item ":"] 1] }

nv_atom elem ppm

now returns an empty string if the atom shift is not assigned, whereas the C version returns -1000000. Note that in the C version, the value of 1000000 was not saved upon writing the ppm.out file.

Here again you might want to update your scripts to check for both 1000000 and "" to detect unassigned shifts.

For maximum speed, avoid using an if statement like

  
  if {$shift==1000000 ||  $shift==""}
  
  

Instead, do something like:

  set string_for_no_shift_available "?"
  lappend string_for_no_shift_available ""
  if {[string match $shift* $string_for_no_shift_available]} {
     # the atom is assigned
  } else {
    # the atom is not assigned
  }

NOE commands

nv_noe elem peaklist x: now returns the name of the peak list the noe #x is from, no longer the index of [[nv_peak list]] where the peak list is.