What does the Macro do?
This macro will Pick and Assign a 3D triple resonance spectrum based on a root 2D spectrum. It will do this for all selected peaks in the 2D.
How to run the Macro
Set the 3D PeakList you want to pick the peaks in at the top of the macro in line 10. You can get the name of your PeakList (something like PL:myTripleResSpectrum.1) from the sidebar (copy it by right-clicking on it and selecting Copy Pid to Clipboard). Then select the peaks in the 2D which you would like to transfer to the 3D and run the macro either in the iPython console or the Macro Editor (or associate it with a keyboard shortcut).
Code
# Macro to pick and Assign a 3D spectrum based on a 2D
# Set the 3D peakList you want to pick the peaks in at the top of the macro.
# Then select the peaks in the 2D which you would like to transfer to the 3D and run the macro.
#
# Copyright 2024 Vicky Higman
# This code is distributed using the MIT licence. See http://opensource.org/license/mit for details.
#####################################################################################################################
from ccpn.ui.gui.widgets.MessageDialog import showWarning
from ccpn.core.lib.ContextManagers import undoBlock
pl = get('PL:hncoca.1')
def findMatchingDimensions(pk, peaks):
for pk2 in peaks:
if pk2.pid != pk.pid:
# Check if the peaks have any isotopeCodes in common
for ic, axcde in zip(pk.spectrum.isotopeCodes, pk.spectrum.axisCodes):
for ic2, axcde2 in zip(pk2.spectrum.isotopeCodes, pk2.spectrum.axisCodes):
if ic == ic2:
copyPeakAssignments(pk, pk2, axcde, axcde2)
def copyPeakAssignments(pk, pk2, axcde, axcde2):
# get assigned nmrAtoms from first or reference Peak
nmrAtoms = getCleanNmrAtomsList(pk, axcde)
nmrAtomsToAssign = []
for nmrAtom in nmrAtoms:
nmrAtomsToAssign.append(nmrAtom)
# add assigned nmrAtoms from own peak
nmrAtomsFromOwnPeak = getCleanNmrAtomsList(pk2, axcde2)
nmrAtomsToAssign = nmrAtomsToAssign + nmrAtomsFromOwnPeak
if nmrAtomsToAssign:
nmrAtomsToAssign = list(dict.fromkeys(nmrAtomsToAssign))
pk2.assignDimension(axcde2, nmrAtomsToAssign)
def getCleanNmrAtomsList(peak, axCde):
assignedNmrAtoms = [na for i in peak.getByAxisCodes('assignments', [axCde], True) 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 []
with undoBlock():
if not current.peak:
showWarning('No Peaks selected', 'Please make sure you have selected a peak')
else:
for pk in current.peaks:
_positionCodeDict = dict(zip(pk.axisCodes, pk.position))
ppks = pl.restrictedPick(positionCodeDict=_positionCodeDict, doPos=True, doNeg=False)
if pk.assignments != 0:
findMatchingDimensions(pk, ppks)
Credits and References
Vicky Higman, CCPN Team, University of Leicester
