> finally, i'd like to write some macros to perform some more unique functions.
> any general tips on this?
In the $CCPN_HOME/python/ccpnmr/analysis/ directory have a look at
AssignmentMacros.py
This file contains examples of some simple macros. At the top you will
notice the "from <module> import <function>" lines which show where all of
the called functions come from.
Generally the macros have optional arguments of an argServer
instance or data model objects (it is asserted that at least one of these
conditions is satisfied). This enables the macro to be run with explicit
data model objects (e.g. from inside another macro) or with the argServer
from Analysis supplying the objects.
The argServer is an instance of the ArgumentServer. Have a look at
ArgumentServer.py for the functions provided. These functions are not
currently documented and are not yet comprehensive. However,
ArgumentServer does provide the basic functions required to get hold of
all the usual things and its functions have obvious names like
"askInteger" and "getSpectrum".
If a macro is run from the menus within Analysis an instance of
ArgumentServer is automatically passed to the macro function. Thus, all
macros used in this way must have this ("argServer=") as an argument,
albeit an optional one and not necessarily used. (I thought this easier
than having to find an instance of ArgumentServer from within the macro
function all the time)
As for the functions that do most of the business, these are contained
within the *Basic.py files. For example AssignmentBasic.py carries every
function called by Analysis when it does anything to do with assignment.
Thus, if you're doing assignment within macros you should use these
functions. All the functions here are well documented so you know what
each does and what the inputs/outputs are.
Also, by using these inbuilt procedures you can focus on the higher level
strategy, rather than worry about the finer points or tedium. For example,
in AssignmentBasic.py the function assignResToDim is used to connect a
resonance to a peak dimension, but it will also automatically take care
of: recalculating the averaged chemical shift for the resonance given the
new assignment, checking the resonance's shift (if it has one) is within
the assignment tolerances for the given peak position, setting the peak
annotation to reflect the new assignment on screen etc. Thus, it is
usually best to use the *Basic modules wherever possible...
> specifically (to begin with) i'd like to be able to collect all the
> assignment possibilities for a number of selected peaks into a single
> list.
A few tips:
From AssignmentBasic import your required functions
Get peaks from
argServer.getCurrentPeaks() - gives those selected with the mouse
or
argServer.getPeakList().peaks - to use a whole peak list
Potentially helpful AssignmentBasic functions:
makeResonanceGuiName - Get the assigned name for a resonance as used in
Analysis
findMatchingShifts - Find the chemical shifts close to a position
getPeakDimPpm - Give the position of a peak dimension in ppm, rather
than the stored points
Read the Python API documentation to find out what the required Data
Model objects are and how they're connected:
$CCPN_HOME/python/doc/api.html
> i've been nosing around in the code finding some useful bits and
> pieces but i'm struggling at the first hurdle of how to tell my macro
> to work with (use as its input) the selected peaks.
def macro(argServer=None, peaks=None):
assert argServer or peaks
if peaks is None:
peaks = argServer.getCurrentPeaks()
for peak in peaks:
...
> also, can i import methods and functions from the existing modules
> into my function and use them as they are?
from ccpnmr.analysis.AssignmentBasic import assignResToDim ...etc.
Hope this helps,
Tim
-------------------------------------------------------------------------------
Dr Tim Stevens Email: [log in to unmask]
Department of Biochemistry [log in to unmask]
University of Cambridge Phone: +44 1223 766022 (office)
80 Tennis Court Road +44 7816 338275 (mobile)
Old Addenbrooke's Site +44 1223 364613 (home)
Cambridge CB2 1GA WWWeb: http://www.bio.cam.ac.uk/~tjs23
United Kingdom http://www.pantonia.co.uk
-------------------------------------------------------------------------------
------ +NH3CH(CH(CH3)OH)C(O)NHCH(CH(CH3)CH2CH3)C(O)NHCH(CH2CH2SCH3)CO2- -------
-------------------------------------------------------------------------------
|