How could I access Delta-shift from Peak Assigner in the command line?

Hi,

How could I get in the command line the Delta-shift parameter for the current peak assignment from the PeakAssigner? I tried to look in the API documentation and a bit in console and it is still not clear to me.
Essentially, I am trying to write a macro that pulls the peaks in a peaklist where the delta-shift to the average chemical shift is the largest to give them a second round of verification.

Thanks,
Józef

Hi Józef,

we don’t currently have a method for this, but will add one. It’s not quite as easy as it seems, as each peak can multiple dimensions, each dimension can have multiple assignments, and each NmrAtom can be present in multiple ChemicalShiftLists.

Here is some code to get you going, though.
The basics you need are that for a dimension of a peak assigned to an nmrAtom, you can get delta with:

cslShiftValue = peak.chemicalShiftList.getChemicalShift(nmrAtom).value
delta = abs(cslShiftValue - peak.getByDimensions('position', [dimension])[0])
delta = round(delta, 3)

In addition, here is a macro based on some other code I had written. It is probably more elaborate than anything you need - it’s got various checks and fail-safes which might be a bit over the top for you, but it should work. It will give you the delta values of the current peak as a list of lists (i.e. for each assigned NmrAtom of each dimension of the peak):

# Macro to get the delta values of the current peak.
#####################################################################################################################

def getCleanNmrAtomsList(peak, dim):
    assignedNmrAtoms = [na for i in peak.getByDimensions('assignments', [dim]) for na in i]
    nmrAtomsList = []
    # remove assignments that are None
    for na in assignedNmrAtoms:
        if na != None:
            nmrAtomsList.append(na)
    if nmrAtomsList:
        # remove duplicates
        nmrAtomsList = list(dict.fromkeys(nmrAtomsList))
        return nmrAtomsList
    else:
        return []

def getDeltaValue(pk):
    deltas = []
    for dim in pk.spectrum.dimensions:
        dimDeltas = []
        # get assigned nmrAtoms
        nmrAtoms = getCleanNmrAtomsList(pk, dim)
        for nmrAtom in nmrAtoms:
            shift = pk.chemicalShiftList.getChemicalShift(nmrAtom)
            # print(shift, shift.value)
            if shift and shift.figureOfMerit != 0:
                sValue = shift.value
                # Do Try/Except in case ChemShiftValue is None
                try:
                    delta = abs(sValue - pk.getByDimensions('position', [dim])[0])
                    delta = round(delta, 3)
                    # print(delta)
                except:
                    delta = None
                    # print("The ChemicalShift ", shift.pid, " in ChemicalShiftList", pk.chemicalShiftList.pid,
                    #       "doesn't have a value. Please correct!")
            else:
                delta = None
            dimDeltas.append(delta)
        deltas.append(dimDeltas)
    print(deltas)
    return(deltas)

getDeltaValue(current.peak)

Vicky

Hi Vicky,

Thank you for the macro. Very useful. I have modified it a bit and it does exactly what I want.
And now back to tracking assignment errors…

Best,
Józef