CcpnForum
Copy Assignments macro - Printable Version

+- CcpnForum (https://www.ccpn.ac.uk/forums)
+-- Forum: CcpNmr Analysis Version 3 (https://www.ccpn.ac.uk/forums/forumdisplay.php?fid=4)
+--- Forum: V3 Macros (https://www.ccpn.ac.uk/forums/forumdisplay.php?fid=14)
+--- Thread: Copy Assignments macro (/showthread.php?tid=70)



Copy Assignments macro - VickyH - 01-29-2020

Here is a macro to copy assignments from one peak to one or more others. This would be useful if you have two spectra recorded under different conditions where some or all of the peaks have moved (e.g with/without ligand, different temperature, buffer etc.) and want to copy the assignments from one spectrum to another.

Select one (fully or partially) assigned peak and one or more unassigned peaks. The assignments from the assigned peak will be copied to the unassigned peaks. This will work both within and between peak lists, spectra and spectrum displays.

The macro works in a similar way to the V2 "Propagate Assignment" function. However, note that the peak dimensions are matched by their Axis Codes and there is no checking of chemical shifts. This is deliberate, so that you can copy assignments in situations where the chemical shift has changed. But this does mean that you might encounter unexpected behaviour for spectra with at least two dimensions belonging to the same isotope (e.g. when copying assignments across the diagonal of a homonuclear spectrum), or for two spectra where the peaks' Axis Codes and Assignments don't line up. But this should hopefully only be a minority of cases.

Python
  1. def copyAssignment(peak, assignmentsToCopy, axisCodesToUse):
  2. assignDone = 0
  3. count = 0
  4. for assignment in assignmentsToCopy:
  5. temp = str(assignment)
  6. assignmentLabels = temp.split(',')
  7. assignmentLabels[0] = assignmentLabels[0][1:]
  8. assignmentLabels[-1] = assignmentLabels[-1][0:-1]
  9. axCodes = dict(zip(assignmentLabels, axisCodesToUse))
  10. for label in assignmentLabels:
  11. count = count+1
  12. if 'None' not in label:
  13. temp = str(label)
  14. assignmentComponents = temp.split(':')
  15. assignmentComponents[0] = 'NA'
  16. assignmentComponents[1] = assignmentComponents[1][0:-1]
  17. axCde = axCodes[label]
  18. newAssignment = ':'.join(assignmentComponents)
  19. if axCde in peak.axisCodes:
  20. peak.assignDimension(axCde, newAssignment)
  21. assignDone = 1
  22. if assignDone == 0:
  23. print('Your peaks have to have matching Axis Codes in at least one assigned dimension in order to copy an assignment.')
  24.  
  25.  
  26. assignmentsToCopy = None
  27. axisCodesToUse = None
  28. # Check only one peak is fully or partially assigned and get the assignments and Axis Codes to copy
  29. for peak in current.peaks:
  30. if len(peak.assignments) != 0 and assignmentsToCopy is None:
  31. assignmentsToCopy = peak.assignments
  32. axisCodesToUse = peak.axisCodes
  33. elif len(peak.assignments) != 0 and assignmentsToCopy is not None:
  34. print("You have more than one assigned peak.")
  35. assignmentsToCopy = None
  36.  
  37.  
  38. if assignmentsToCopy is not None:
  39. for peak in current.peaks:
  40. if len(peak.assignments) == 0: # only copy assignments to unassigned peaks
  41. copyAssignment(peak, assignmentsToCopy, axisCodesToUse)
  42. else:
  43. print("Please make sure you have one assigned peak.")



Any problems, let me know.

Vicky