Calculate splitting (sparky script)
From NMR Wiki
Contents |
Usage
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.
Installation
- install code below into <path_to_sparky>/python/sparky/coupling.py
- register script with 'pd' hotkeys in the sparky_site.py file by adding line shown below to the peak_menu array
('pd', 'Calculate coupling', ('coupling','show_dialog')),
Macintosh
On Mac's sparky's default installation directory is
/Applications/Sparky.app/Contents/Resources/
so the script should go to directory
/Applications/Sparky.app/Contents/Resources/python/sparky
Bugs
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.
Code
import noesy import pyutil import sputil import tkutil def show_dialog(session): tk = 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!' else: 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) lbl.pack() btn = Tkinter.Button(window,text='ok') btn.pack()