Fix off-by-one bugs in 1-indexed loops over pose residues#695
Open
lyskov-ai wants to merge 1 commit into
Open
Conversation
Replace `i != end` with `i <= end` (or `i != size()` with `i <= size()`)
in several loops that iterate over 1-indexed residue ranges. With the
old condition, the last residue (index == end) was skipped:
* core/pack/task/PackerTask_.cc: pymol-style debug selection output
omitted the last residue.
* protocols/forge/components/BDR.cc:
- the full-atom check used to gate `switch_to_residue_type_set`
skipped the last residue, so a non-full-atom last residue could
bypass conversion and later cause sidechain-restore mismatch.
- the loop building the `RestrictResidueToRepacking` operation
skipped the last residue, so residues outside `new_positions`
at the C-terminus were designed instead of repack-only.
* protocols/fldsgn/BluePrintBDR.cc: same full-atom check bug as BDR.
* protocols/denovo_design/components/StructureData.cc:
`compute_cutpoints` skipped the last residue, dropping a
CUTPOINT_LOWER variant on the C-terminal residue.
* protocols/enzdes/BackboneSampler.cc: the user-requested number of
trials was off by one (e.g. `bb_moves_=1000` actually ran 999).
Member
|
Wow, I can't believe this one went unnoticed for so long: |
Member
|
@ajasja yeah, this is certainly frightening, - and who knows how many more similar bugs are still undiscovered! |
lyskov
approved these changes
May 12, 2026
This was referenced May 13, 2026
roccomoretti
approved these changes
May 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace `i != end` with `i <= end` (or `i != size()` with `i <= size()`) in several loops that iterate over 1-indexed residue ranges. With the old condition, the last residue (index == end) was silently skipped.
These are all instances of the same pattern: a 1-indexed loop using `!=` against a one-past-the-last bound that was actually meant to be the last valid index. Each loop body uses the index directly to access pose data, so the fix is to switch the comparison to `<=`.