Issue with Residual Position Markers After Deleting Peaks

Hi everyone,

I’m having an issue in CCPNMR Analysis where, after deleting all peaks from certain entries (e.g., HB%), the position markers (guide lines) still remain in the spectra. These lines reappear whenever I select a peak from the Peak Inspector or use the Pick and Assign module.

I do want the guide lines to remain for entries that still have peaks, but I’d like to remove them only for entries where all peaks have been deleted. Simply using “Clear Marks” isn’t helpful since it removes all position markers, including the useful ones.

Is there a way to clear only the markers for entries where all peaks have been deleted, while keeping the rest?

Thanks for any suggestions!

Hi Zou,

this is an intriguing and certainly relevant question. But solving it is not entirely straight forward.

One day we do hope to make marks “selectable”, so that you can delete or even move them interactively. But that isn’t likely to happen any time soon.

So in the meantime we need to think of some ways round this. The issue is that it depends how you made your marks and what else is going on in your project. So it will be very difficult to find a one size fits all solution and we are going to have to do this via some bespoke macros.

So if you created your marks with PM (i.e. marking specific peaks), then the following macro would easily remove any marks whose peaks have been removed:

for mk in project.marks:
    keepMark = False
    for pk in project.peaks:
        if mk.positions == pk.ppmPositions:
            keepMark = True
    if keepMark == False:
        mk.delete()

But this will only work if you marks are absolutely in the same position as the peaks (to something ridiculous like more than 12 decimal places!). It would therefore also remove any marks created in other ways. It would be possible to write a considerably more complicated version of this which would allow for certain tolerances, but I don’t think it’s worth writing that unless someone definitely thinks it would be helpful.

In your situation (given that your marks are labelled with NmrAtoms) it looks as though the marks were placed by creating marks for specific NmrAtoms in some way or other. In this case the following macro should do what you are wanting:

for mk in project.marks:
    keepMark = False
    for lab in mk.labels:
        na = get('NA:'+lab)
        for pk in project.peaks:
            for item in pk.assignedNmrAtoms:
                if na in item:
                    keepMark = True
    if keepMark == False:
        mk.delete()

It will remove any marks which are labelled with an NmrAtom for which there isn’t a peak labelled with that NmrAtom. At the moment it will simply work on peaks across the whole project. If you wanted, I could change it so as to work only on the peaks in the selected SpectrumDisplay.

For information on running macros see our Running Macros webpage.

Vicky