Skip to content

refactor: extract magic numbers into named constants module#448

Open
haoyu-haoyu wants to merge 1 commit intoRosettaCommons:mainfrom
haoyu-haoyu:refactor/extract-magic-numbers
Open

refactor: extract magic numbers into named constants module#448
haoyu-haoyu wants to merge 1 commit intoRosettaCommons:mainfrom
haoyu-haoyu:refactor/extract-magic-numbers

Conversation

@haoyu-haoyu
Copy link

Summary

Add rfdiffusion/constants.py centralizing undocumented magic numbers with explanations, and replace the most widely duplicated ones.

Constants replaced in this PR

Constant Value Occurrences Files
CBETA_A/B/C -0.5827, 0.5680, -0.5407 4 util.py, Embeddings.py, coords6d.py
AA_MASK_TOKEN 21 2 run_inference.py
AA_GLYCINE 7 1 run_inference.py

Constants documented (for future refactoring)

The constants module also defines (but does not yet wire up) documented constants for:

  • NO_CONTACT_DIST (999.9) — sentinel distance, used 7 times across 3 files
  • CHAIN_BREAK_INDEX_JUMP (200) — contig chain break offset
  • SE3_TRANSLATION_SCALE / SE3_ROTATION_SCALE (10.0 / 100.0) — Track module scaling
  • IGSO3 distribution parameters
  • Diffusion schedule reference values

These are intentionally left as documentation-only in this PR to keep the diff reviewable. They can be wired up incrementally in follow-up PRs.

Test plan

  • Run tests/test_diffusion.py — output should be bit-identical
  • Run a small inference job and compare PDB output

Add rfdiffusion/constants.py centralizing magic numbers used across the
codebase, with documentation of each constant's meaning and provenance.

Replace inline values in 4 files:
- Cbeta reconstruction coefficients (-0.58273431, 0.56802827, -0.54067466)
  used in util.py (2x), Embeddings.py, coords6d.py → CBETA_A/B/C
- Amino acid token indices (21=mask, 7=glycine) in run_inference.py
  → AA_MASK_TOKEN, AA_GLYCINE

Also documents additional constants (NO_CONTACT_DIST, CHAIN_BREAK_*,
SE3_*_SCALE, diffusion schedule params) for future refactoring.
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.

1 participant