GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix undefined vector angles and preserve planar dihedrals by Oblivionis028 · Pull Request #5352 · biopython/biopython

Conversation

@Oblivionis028

@Oblivionis028 Oblivionis028 commented Oct 4, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
  • I hereby agree to dual licence this and any previous contributions under both
    the Biopython License Agreement AND the BSD 3-Clause License.

  • I have read the CONTRIBUTING.rst file, have run pre-commit
    locally, and understand that continuous integration checks will be used to
    confirm the Biopython unit tests and style checks pass with these changes.

  • I have added my name to the alphabetical contributors listings in the files
    NEWS.rst and CONTRIB.rst as part of this pull request, am listed
    already, or do not wish to be listed. (This acknowledgement is optional.)

Closes #5342

Zero-length vectors currently produce NaN when calculating the cosine in Vector.angle,
but the roundoff clamp converts that NaN into -1. As a result, four collinear
points return a finite dihedral of -pi, although the angle is undefined.

This change raises ValueError for zero-length vector angles and uses a
NaN-preserving clamp for roundoff. It also uses the scalar triple product to
determine the dihedral sign, so valid planar dihedrals do not require an angle
with a zero intermediate vector. The 180-degree endpoint is returned as +pi,
consistent with the documented interval. vector_to_axis uses a dot-product
projection so projecting the origin remains valid.

Seven new test methods cover zero vectors in either argument, NaN propagation,
roundoff, coincident points, undefined planes, signed and planar dihedrals, and
projection of the origin. The API docstrings and release notes document the
new exception behavior.

Behavior to review

This proposes ValueError for undefined zero-length angles rather than returning
NaN with a warning. calc_angle and calc_dihedral inherit that behavior.
Callers that previously accepted a finite result for degenerate geometry may now
need to handle the exception. Feedback on this API choice is welcome.

Validation

  • Python 3.12.14, NumPy 2.3.5, Windows 11.
  • 31 focused vector, polypeptide and exposure tests passed. The added regressions
    fail against unmodified Biopython 1.88.
  • The offline Bio.PDB run passed 26 module groups and skipped three:
    test_PDB_alphafold_db, test_PDB_PDBList (offline), and
    test_PDB_PSEA (external executable unavailable).
  • 1,000 seeded nondegenerate dihedrals matched an independent atan2 calculation
    to a maximum absolute difference of approximately 5.1e-14 radians.
  • All applicable configured pre-commit checks passed for the three changed files.
  • The offline full runner completed and reported 502 test entries, with two
    failing module groups: test_Align_aligncore and
    test_align_substitution_matrices. The failing checks also reproduce against
    the unmodified 1.88 wheel.

The local environment lacks a source-build C toolchain. Validation used the
current Python source with the official 1.88 wheel's extension binaries in a
separate staging directory. The two failing groups exercise newer C-extension
behavior that those binaries do not provide. This is not a clean source-build
pass; source-built CI validation is still needed. Online and unavailable
external-tool tests were skipped.

This contribution was prepared with AI assistance; the implementation, regression
results, and validation limitations are documented for review.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Oblivionis028
Add files via upload
ef70c9a
Fix undefined vector angles and preserve planar dihedrals
@Oblivionis028
Oblivionis028 requested a review from JoaoRodrigues as a code owner October 4, 2026 13:36
@Oblivionis028
Normalize line endings for web upload
c862776
@Oblivionis028
Oblivionis028 marked this pull request as draft October 4, 2026 13:47
@Oblivionis028
Oblivionis028 marked this pull request as ready for review October 4, 2026 18:50
@peterjc

peterjc commented Oct 5, 2026

Copy link
Copy Markdown
Member

Thank you for declaring the AI usage, #5334 would add that to the PR template. I'm going to leave this on hold pending agreement on our AI policy, see the mailing list or eg #5241.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Oblivionis028

Oblivionis028 commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for your feedback and for considering my contribution. I understand the decision to put this PR on hold while the AI policy is being discussed. I’ll continue to follow the discussion and look forward to contributing to Biopython in the future.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dbolser dbolser mentioned this pull request Nov 10, 2026
Adopt upstream #5352: undefined PDB angles and dihedrals raise ValueError instead of returning ±π BioAGI-org/biop-ai#328
Merged
dbolser pushed a commit to BioAGI-org/biop-ai that referenced this pull request Nov 10, 2026
Dan Bolser @claude @dbolser
Polypeptide: None for an undefined tau or theta angle
9e0aa0d
With calc_angle and calc_dihedral now raising ValueError for an undefined
angle (biopython/biopython#5352), one degenerate window, such as two
C-alpha atoms on the same spot, made get_tau_list and get_theta_list
raise and lose the whole list. Put None in that window instead, as
get_phi_psi_list already does and as is done for a residue without CA,
so the lists keep their lengths and positions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
dbolser pushed a commit to BioAGI-org/biop-ai that referenced this pull request Nov 10, 2026
Dan Bolser @claude @dbolser
HSExposure: handle undefined angles instead of raising
06917df
Vector.angle now raises ValueError for a zero-length vector, where it
used to return pi (biopython/biopython#5352). In the half-sphere
exposure classes:

- a residue whose CA-CB (or pseudo-CB) direction has zero length is left
  out, as for missing atoms; before, every neighbour came out as "down";
- a neighbouring CA exactly on the residue's own CA is counted in neither
  half sphere; before, it was counted as "down";
- HSExposureCA gives None for the CB to pseudo-CB angle when the CB sits
  on the CA, as it does when there is no CB.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
dbolser pushed a commit to BioAGI-org/biop-ai that referenced this pull request Nov 10, 2026
Dan Bolser @claude @dbolser
NEWS: argue the undefined-angle change and its Bio.PDB callers
ce60926
Say what used to come back, what code must now do, how Polypeptide and
HSExposure handle it, and credit biopython/biopython#5352 (and mention
the withdrawn NaN alternative, biopython/biopython#5357).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@JoaoRodrigues JoaoRodrigues Awaiting requested review from JoaoRodrigues JoaoRodrigues is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Vector.angle's roundoff-clamping silently turns a NaN (zero-length vector) into pi

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@Oblivionis028 @peterjc
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.