From e7f25ca7e96c755b003844faf87c63d8e74c5621 Mon Sep 17 00:00:00 2001 From: pkoukos Date: Fri, 27 Jul 2018 14:55:49 +0200 Subject: [PATCH] Support cases with insertion codes Previous versions of the script would not renumber residues that were flagged as insertions. They are now renumbered with respect to the last non-insertion residue that was encou- netered. --- pdb_reres.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/pdb_reres.py b/pdb_reres.py index 949835cd..9cbb5f8c 100755 --- a/pdb_reres.py +++ b/pdb_reres.py @@ -74,13 +74,23 @@ def _renumber_pdb_residue(fhandle, sresid): resi = sresid - 1 prev_resi = None + + inserted_residues = {} + for line in fhandle: if line.startswith(('ATOM', 'HETATM', 'TER')): - if line[22:26] != prev_resi: - prev_resi = line[22:26] + if line[22:27] != prev_resi and line[26] == " ": + prev_resi = line[22:27] resi += 1 - - yield line[:22] + str(resi).rjust(4) + line[26:] + elif line[22:27] != prev_resi and line[26] != " ": + # Insertion code + i_code = line[22:27] + if i_code not in inserted_residues: + # inserted_residues[i_code] = len(inserted_residues) + 1 + # resi += inserted_residues[i_code] + inserted_residues[i_code] = True + resi += 1 + yield line[:22] + str(resi).rjust(4) + " " + line[27:] else: yield line