Macro for extracting EXSY intensities

Here`s a rough macro that I cooked up to extract peak intensities from a series of EXSY zz-exchange spectra.

It illustrates some ways of navigating the data structure from peaks to assignments and constructing a dictionary for further use fitting the data.

It would be nice to have proper NMRSeries support so that the spectrum names don`t have to be set up for the mixing times.

Comments & suggestions for improvement welcome.

Python
  1. # user to take care of selecting peaks at all mixing times only from the residues they want
  2. # auto peaks assigned to different chains to to indicate states
  3. # cross peaks assigned to one atom from each of the (normally two) chains
  4.  
  5. from collections import OrderedDict
  6.  
  7. EXSYdata = []
  8. mixes = set() # will be an unordered set containing each mixing time once
  9. #transfers = set() # will be an unordered set containing each peak type once
  10. for peak in current.peaks:
  11.    #print(peak.peakList.spectrum.name, \
  12.    # peak.dimensionNmrAtoms[0][0].nmrResidue.nmrChain.name, \
  13.    # peak.dimensionNmrAtoms[0][0].nmrResidue.sequenceCode, \
  14.    # peak.dimensionNmrAtoms[1][0].nmrResidue.nmrChain.name, \
  15.    # peak.dimensionNmrAtoms[1][0].nmrResidue.sequenceCode, \
  16.    # peak.height)
  17.    spectrum = peak.peakList.spectrum.name
  18.    #spectra should be named EXSY[0-9]+ where the digits represent the mixing time in ms
  19.    if spectrum[:4] == `EXSY`:
  20.        mix = (float(spectrum[4:])/1000)
  21.        toChain = peak.dimensionNmrAtoms[0][0].nmrResidue.nmrChain.name
  22.        toResid = peak.dimensionNmrAtoms[0][0].nmrResidue.sequenceCode
  23.        fromChain = peak.dimensionNmrAtoms[1][0].nmrResidue.nmrChain.name
  24.        fromResid = peak.dimensionNmrAtoms[1][0].nmrResidue.sequenceCode
  25.        #should test that toResid and fromResid are the same!
  26.        #print(fromChain + toChain+`_`+toResid, mix, peak.height)
  27.        EXSYdata.append([fromChain + toChain+`_`+toResid, mix, peak.height])
  28.        mixes.add(mix)
  29.        #transfers.add(fromChain + toChain+`_`+toResid)
  30.    
  31. print(sorted(mixes))
  32. #print(sorted(transfers))
  33. #print(sorted(EXSYdata))
  34.  
  35. EXSYdict = OrderedDict()
  36. for trf, mix, intens in (sorted(EXSYdata)):
  37.    #print(trf, mix, intens)
  38.    EXSYdict.setdefault(trf, []).append(intens) # adds trf to keys if neccessary and appends intens to list of values
  39.  
  40. print(EXSYdict)
  41.