Calculate splitting (sparky script)

From NMR Wiki

Revision as of 08:29, 17 November 2009 by (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search



Open some 2D or 3D data file in sparky, select two peaks, type 'pd'. Splittings in Hz will be shown in a pop up window.


  • install code below into <path_to_sparky>/python/sparky/
  • register script with 'pd' hotkeys in the file by adding line shown below to the peak_menu array
('pd', 'Calculate coupling',        ('coupling','show_dialog')),


On Mac's sparky's default installation directory is


so the script should go to directory



Looks like this macro does not account for splitting sign correctly, this is most likely sparky issue - not something that can be fixed in this script.

Info window won't go away when "ok" button is clicked.


import noesy
import pyutil
import sputil
import tkutil
def show_dialog(session):
    tk =
    window = Tkinter.Toplevel(tk)
    view = session.selected_view()
    spectrum = view.spectrum
    peaks = spectrum.selected_peaks()
    num_peaks = len(peaks)
    if num_peaks != 2:
        message = 'Select two peaks!'
        p1 = peaks[0]
        p2 = peaks[1]
        dim = len(p1.position)
        message = ''
        lbl = ('Delta W1:','Delta W2:','Delta W3:')
        for i in range(dim):
        #x y z must correspond to actual xyz (axis order!)
        #print hertz instead of ppms
            ppm = spectrum.hz_per_ppm[i]
            delta = (p1.position[i] - p2.position[i])*ppm
            delta = '%.2f' % delta
            message = message + lbl[i] + str(delta) + '\n'
    lbl = Tkinter.Label(window,text=message)
    btn = Tkinter.Button(window,text='ok')
Personal tools