Skip to content

fix: hydrophobic energy does not return nan when no hydrophobic residues - #122

Open
jakublala wants to merge 2 commits into
mainfrom
fix/hydrophobic-energy-nan
Open

jakublala wants to merge 2 commits into
mainfrom
fix/hydrophobic-energy-nan

Conversation

@jakublala

@jakublala jakublala commented Feb 3, 2026

Copy link
Copy Markdown
Member

Fixes #121

Summary by CodeRabbit

  • Bug Fixes

    • Hydrophobic energy now correctly returns 0 when no hydrophobic residues are present in the relevant region.
    • Consistent SASA-based weighting applied across modes (“surface” and “core”) using only relevant hydrophobic atoms.
  • Tests

    • Added unit tests for scenarios with no hydrophobic residues across all modes, verifying zero (non-NaN) energies.
  • Chores

    • Bumped package version to 0.1.12.

@jakublala
jakublala requested a review from sangioletti February 3, 2026 15:43
@coderabbitai

coderabbitai Bot commented Feb 3, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Version bumped to 0.1.12. HydrophobicEnergy.compute now intersects relevance and hydrophobic masks, adds early return when no hydrophobics, and adjusts SASA weighting to use the combined mask. New unit test validates zero-energy behavior when no hydrophobic residues are present across modes.

Changes

Cohort / File(s) Summary
Versioning
pyproject.toml
Bumped project version from 0.1.11 to 0.1.12.
Hydrophobic energy logic
src/bagel/energies.py
Compute uses combined_mask = relevance_mask & hydrophobic_mask, early-return (0.0, 0.0) if none, and mode-specific SASA means now taken over combined mask.
Unit tests
tests/unit_tests/test_energies.py
Added parameterized test ensuring energies are 0.0 when no hydrophobic residues (GLU/ASP-only structure) for modes 'all', 'surface', 'core'.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • Binder new #90: Related changes to HydrophobicEnergy’s mode-based SASA weighting; this PR refines masking and adds early-return behavior.

Poem

A nibble of code, a hop in the log,
Masks now align where hydrophobes jog.
If none are found—zero we say,
Tests keep watch in their tidy array.
Version bumps softly—flip of a page,
Carrot-high fives from a coding-stage hare! 🥕🐇

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the primary change by stating the hydrophobic energy function no longer returns NaN when no hydrophobic residues are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/hydrophobic-energy-nan

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HydrophobicEnergy gives nan if no hydrophobic residues

1 participant