Hoist b_factor and occupancy annotations out of per-sample loop#18
Hoist b_factor and occupancy annotations out of per-sample loop#18longleo17 wants to merge 1 commit intobytedance:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR reduces redundant work in DataDumper._save_structure() by moving b_factor and occupancy annotation initialization out of the per-sample CIF writing loop, avoiding repeating identical annotation setup across many samples.
Changes:
- Hoist
b_factorandoccupancyannotation setup to run once before iterating over samples in_save_structure(). - Add a test that asserts annotation setup occurs before the per-sample loop (via source inspection).
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
pxdesign/runner/dumper.py |
Moves annotation initialization outside the per-sample loop to avoid redundant per-iteration work. |
tests/test_parallel_cif_writing.py |
Adds a regression test intended to ensure annotations are set before the loop. |
tests/__init__.py |
Adds an (empty) package marker for the tests directory. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| method_source = source[method_start:] | ||
| b_factor_pos = method_source.find("b_factor") | ||
| loop_pos = method_source.find("for sample_idx") | ||
| assert b_factor_pos < loop_pos, ( |
There was a problem hiding this comment.
This test can produce false positives because str.find() returns -1 when the substring is missing (e.g., if b_factor is renamed/removed). In that case b_factor_pos < loop_pos can still pass, so the test would not actually enforce the intended ordering. Consider asserting that method_start, b_factor_pos, and loop_pos are all != -1 and/or searching for the more specific pattern set_annotation("b_factor" (and similarly for occupancy) or using ast parsing to validate the statement order reliably.
| method_source = source[method_start:] | |
| b_factor_pos = method_source.find("b_factor") | |
| loop_pos = method_source.find("for sample_idx") | |
| assert b_factor_pos < loop_pos, ( | |
| assert method_start != -1, "Expected to find '_save_structure' in dumper.py" | |
| method_source = source[method_start:] | |
| b_factor_pos = method_source.find('set_annotation("b_factor"') | |
| occupancy_pos = method_source.find('set_annotation("occupancy"') | |
| loop_pos = method_source.find("for sample_idx") | |
| assert b_factor_pos != -1, "Expected b_factor annotation to be set in _save_structure" | |
| assert occupancy_pos != -1, "Expected occupancy annotation to be set in _save_structure" | |
| assert loop_pos != -1, "Expected per-sample loop ('for sample_idx') in _save_structure" | |
| assert b_factor_pos < loop_pos and occupancy_pos < loop_pos, ( |
Summary
Moves the b_factor and occupancy annotation setup out of the per-sample loop in
_save_structure(). Previously these were redundantly set on every iteration (100-500 times) despite being identical across samples.Changes
pxdesign/runner/dumper.py—DataDumper._save_structure(): set annotations once before the loopTest plan
pytest tests/test_parallel_cif_writing.py -v