Renumber unconnected nmrChain

A macro to renumber an unconnected nmrChain.

import numpy as np
import re

nmrChain = get('NC:A') ## replace with your nmrChain name
offset = 100           ## residue 1 will become 101

newValues = []
for nmrResidue in nmrChain.nmrResidues:
    sequenceCode = nmrResidue.sequenceCode
    ints = re.findall(r'\d+', sequenceCode)
    if len(ints)==1:
        code,sep, resOffs = int(ints[0]), '',''
    if len(ints)==2:
        code, sep, resOffs = int(ints[0]), '-', int(ints[1])

    newCode = f'{int(code)+offset}{sep}{resOffs}'
    newValues.append([str(newCode), nmrResidue.residueType])

newValues = np.array(newValues)[::-1]
nmrResidues = np.array(nmrChain.nmrResidues)[::-1]

with undoBlock():
    for nmrResidue, newValue in zip(nmrResidues, newValues):
        print(f'Renaming {nmrResidue} to --> {newValue}')

So far the macro is not running but I will play around! Thanks a lot Luca!

ok I tested on 3.1 with few nmrChains and various residue offsets. like i-1. Let me know any issues, traceback, or upload your version…