So I gave up trying to do this elegantly and went with the following approach:
Copy existing resids to orig_resids
Loop through all chains and split resids with rescodes (new resid numbering preserves gap sizes in original numbering including at the start of a chain).
The advantage is that no other code needs changing and sequences now align properly. The disadvantage is that it means editing the original numbers, but this will happen when making models any way.
I've tested this on only a couple of PDBs using Scan only - but there is no reason it should present issues for remotely well formed PDBs.
So I gave up trying to do this elegantly and went with the following approach:
The advantage is that no other code needs changing and sequences now align properly. The disadvantage is that it means editing the original numbers, but this will happen when making models any way.
I've tested this on only a couple of PDBs using Scan only - but there is no reason it should present issues for remotely well formed PDBs.