Calculate splitting (sparky script)
From NMR Wiki
(Difference between revisions)
(→Installation) |
(→Macintosh) |
||
Line 7: | Line 7: | ||
===Macintosh=== | ===Macintosh=== | ||
+ | Put file coupling.py with contents below into directory | ||
+ | |||
+ | /Applications/Sparky.app/Contents/Resources/python/sparky | ||
==Code== | ==Code== |
Revision as of 22:23, 8 April 2008
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
Put file coupling.py with contents below into directory
/Applications/Sparky.app/Contents/Resources/python/sparky
Code
import string 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()