Skip to content

Commit

Permalink
Support cases with insertion codes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pkoukos committed Jul 27, 2018
1 parent 16c94d3 commit e7f25ca
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions pdb_reres.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e7f25ca

Please sign in to comment.