Subject: Re: [nmr_sparky] about peak picking
From: Thomas Goddard
Date: Mar 7, 2006

Previous: 81 Next: 83


Hi JLee,

Sparky does not have a command to number peaks 1, 2, 3, ... but here
is Python code that adds accelerator np to Sparky that numbers the
selected peaks 1, 2, 3, ... showing those numbers as peak labels.

On Mac or Linux you put the script in Sparky/Python/sparky_init.py in
your home directory, or on Windows in
C:Documents and SettingsYourUserNameSparkyPythonsparky_init.py.
Make sure not to change the indentation of the code since this is important
in the Python language.

Tom


# ----------------------------------------------------------------------------
# Put this code in ~/Sparky/Python/sparky_init.py.
#
# It is loaded whenever you start Sparky and is usually used to define new
# keyboard accelerators.
#
def initialize_session(session):

def number_peaks(s = session):
peaks = s.selected_peaks()
n = 1
for p in peaks:
if not p.is_assigned:
nstring = str(n)
p.show_label(nstring)
# Could use the following to make an assignment label instead.
# p.assign(0, nstring, )
# p.show_assignment_label()
n = n + 1

session.add_command(np, Number peaks, number_peaks)