Skip to content

feat: support extended (12-char) PDB IDs in output CIF patching#292

Open
smallfishabc wants to merge 7 commits into
mainfrom
feat/extended-pdb-ids
Open

feat: support extended (12-char) PDB IDs in output CIF patching#292
smallfishabc wants to merge 7 commits into
mainfrom
feat/extended-pdb-ids

Conversation

@smallfishabc

@smallfishabc smallfishabc commented Jul 1, 2026

Copy link
Copy Markdown

RCSB now issues extended PDB IDs (pdb_########, e.g. pdb_00004hhb) alongside legacy 4-char codes, ahead of the July 2027 archive cutover. Make the CIF-patching pipeline accept both forms so it keeps working through the transition, with 4-char behavior unchanged.

  • patch_output_cif_files.py: widen the RCSB-id regex to (pdb_[A-Za-z0-9]{8}|<legacy>) and route extraction through a new extract_rcsb_id helper. The helper validates the captured token against the real PDB-id grammar (legacy = leading digit; extended = pdb_ + 8 alnum), so a stray folder like TEST/ is rejected instead of silently fetched, and returns the id verbatim.
  • analyses/{all,analyze_grid_search,external_tools}.toml: PATCH_RCSB_PATTERN accepts both forms.
  • tests: add tests/eval/test_patch_output_cif_files.py (legacy, extended, and rejected inputs) and update the runner pattern assertion.

Extended IDs already resolve on RCSB production, so fetch works today with no endpoint change.

Summary by CodeRabbit

  • New Features
    • Expanded RCSB identifier recognition to support both legacy 4-character IDs and newer pdb_-prefixed 8-character formats across evaluation and CIF patching workflows.
  • Bug Fixes
    • Improved CIF path parsing to avoid ambiguous/partial matches, with clearer handling for invalid identifier captures.
  • Documentation
    • Updated the patching command example to use the broadened identifier pattern.
  • Tests
    • Added/updated unit tests covering valid formats, no-match behavior, invalid-capture handling, and regex misconfiguration cases.

Copilot AI review requested due to automatic review settings July 1, 2026 19:03
@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 00e6d54b-401a-4f9c-bffb-00ecdf3e5e68

📥 Commits

Reviewing files that changed from the base of the PR and between 0b70ab4 and 6d1ed55.

📒 Files selected for processing (1)
  • scripts/patch_output_cif_files.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • scripts/patch_output_cif_files.py

📝 Walkthrough

Walkthrough

The RCSB identifier pattern now accepts pdb_-prefixed 8-character IDs and legacy 4-character IDs. The patch script validates extracted IDs and distinguishes invalid captures from missing complete path components, with corresponding tests and configuration updates.

Changes

RCSB pattern broadening

Layer / File(s) Summary
Validated RCSB extraction and patching
scripts/patch_output_cif_files.py
Adds shared validation patterns, extract_rcsb_id(), InvalidRcsbIdError, consistent defaults, and separate handling for invalid or incomplete matches.
Extraction and integration validation
tests/eval/*, tests/runs/test_runner.py
Adds standalone script loading and tests for valid, missing, malformed, and misconfigured extraction cases, while updating the runner assertion.
Configuration and documentation alignment
analyses/*.toml, scripts/eval/EVALUATION.md
Updates analysis presets and the evaluation example to match both identifier forms.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Suggested reviewers: marcuscollins

Sequence Diagram(s)

sequenceDiagram
  participant CIFPath
  participant PatchScript
  participant Extractor
  participant RcsbPattern

  CIFPath->>PatchScript: provide CIF path
  PatchScript->>Extractor: extract_rcsb_id(path, regex)
  Extractor->>RcsbPattern: compile and validate capture
  RcsbPattern-->>Extractor: valid ID, no match, or invalid ID
  Extractor-->>PatchScript: extraction result
  PatchScript->>PatchScript: patch file or report extraction failure
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding support for extended PDB IDs in output CIF patching.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/extended-pdb-ids

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the CIF output patching pipeline to recognize both legacy 4-character PDB IDs and the newer extended pdb_######## identifiers, ensuring evaluation tooling continues to work through the RCSB transition without changing legacy behavior for valid legacy IDs. (Confidence: ~85% that this fully covers the intended ID extraction path for the patching script and presets.)

Changes:

  • Expanded the --rcsb-pattern defaults/presets to accept (pdb_[A-Za-z0-9]{8}|<legacy>) and introduced extract_rcsb_id() to validate extracted IDs against the actual grammar (legacy must start with a digit; extended must be pdb_ + 8 alnum).
  • Added focused unit tests covering legacy IDs, extended IDs, invalid folder names, and misconfigured regex capture groups.
  • Updated analysis preset TOMLs and the runner assertion to propagate the widened pattern.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
scripts/patch_output_cif_files.py Widen default RCSB regex and add validated extract_rcsb_id() helper used by the patching logic.
tests/eval/test_patch_output_cif_files.py New unit tests pin legacy/extended extraction behavior and reject malformed inputs/patterns.
analyses/all.toml Update PATCH_RCSB_PATTERN to accept legacy + extended IDs.
analyses/analyze_grid_search.toml Update PATCH_RCSB_PATTERN to accept legacy + extended IDs.
analyses/external_tools.toml Update PATCH_RCSB_PATTERN to accept legacy + extended IDs.
tests/runs/test_runner.py Update expected --rcsb-pattern passed from presets to the patching script.
scripts/eval/EVALUATION.md Refresh example invocation to show the updated regex shape.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/patch_output_cif_files.py Outdated
Comment on lines +159 to +166
m = re.search(rcsb_regex, str(cif_path))
if not m:
return None
if m.re.groups != 1:
raise ValueError(
f"--rcsb-pattern must have exactly one capturing group, "
f"got {m.re.groups}: {rcsb_regex!r}"
)

This comment was marked as resolved.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
scripts/patch_output_cif_files.py (1)

146-170: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Docstring doesn't follow the repo's NumPy style.

extract_rcsb_id's docstring is prose-only, unlike main() above it which properly uses Parameters/Returns sections. Per coding guidelines, every function should use NumPy-style docstrings.

As per coding guidelines: "Always include NumPy-style docstrings for every function and class."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/patch_output_cif_files.py` around lines 146 - 170, The docstring for
extract_rcsb_id is prose-only and should be rewritten to match the repo’s
NumPy-style convention. Update extract_rcsb_id to use standard Parameters and
Returns sections (and Raises if applicable), keeping the same behavior
description and validation details consistent with the style used by main().

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@scripts/patch_output_cif_files.py`:
- Around line 146-170: The docstring for extract_rcsb_id is prose-only and
should be rewritten to match the repo’s NumPy-style convention. Update
extract_rcsb_id to use standard Parameters and Returns sections (and Raises if
applicable), keeping the same behavior description and validation details
consistent with the style used by main().

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9924b689-0211-4002-902c-11e7be03ea03

📥 Commits

Reviewing files that changed from the base of the PR and between b2b96d1 and d11354a.

📒 Files selected for processing (7)
  • analyses/all.toml
  • analyses/analyze_grid_search.toml
  • analyses/external_tools.toml
  • scripts/eval/EVALUATION.md
  • scripts/patch_output_cif_files.py
  • tests/eval/test_patch_output_cif_files.py
  • tests/runs/test_runner.py

RCSB now issues extended PDB IDs (`pdb_########`, e.g. `pdb_00004hhb`)
alongside legacy 4-char codes, ahead of the July 2027 archive cutover.
Make the CIF-patching pipeline accept both forms so it keeps working
through the transition, with 4-char behavior unchanged.

- patch_output_cif_files.py: widen the RCSB-id regex to
  `(pdb_[A-Za-z0-9]{8}|<legacy>)` and route extraction through a new
  `extract_rcsb_id` helper. The helper validates the captured token
  against the real PDB-id grammar (legacy = leading digit; extended =
  `pdb_` + 8 alnum), so a stray folder like `TEST/` is rejected instead
  of silently fetched, and returns the id verbatim.
- analyses/{all,analyze_grid_search,external_tools}.toml: PATCH_RCSB_PATTERN
  accepts both forms.
- tests: add tests/eval/test_patch_output_cif_files.py (legacy, extended,
  and rejected inputs) and update the runner pattern assertion.

Extended IDs already resolve on RCSB production, so fetch works today with
no endpoint change.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread analyses/all.toml Outdated
Comment thread scripts/eval/EVALUATION.md Outdated
Comment thread scripts/patch_output_cif_files.py Outdated
Comment thread scripts/patch_output_cif_files.py Outdated
Comment on lines +159 to +166
m = re.search(rcsb_regex, str(cif_path))
if not m:
return None
if m.re.groups != 1:
raise ValueError(
f"--rcsb-pattern must have exactly one capturing group, "
f"got {m.re.groups}: {rcsb_regex!r}"
)

This comment was marked as resolved.

Comment thread scripts/patch_output_cif_files.py
Comment thread scripts/patch_output_cif_files.py Outdated
Comment thread tests/eval/test_patch_output_cif_files.py Outdated
Comment thread tests/eval/test_patch_output_cif_files.py Outdated
Comment thread tests/eval/test_patch_output_cif_files.py Outdated
Comment thread tests/eval/test_patch_output_cif_files.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
scripts/patch_output_cif_files.py (3)

215-237: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

patch_individual_cif_file lacks a docstring; new error-path branching looks correct otherwise.

The new extract_rcsb_id-based flow with distinct InvalidRcsbIdError vs. None handling reads correctly. However the function itself has no docstring. As per coding guidelines, **/*: "Always include NumPy-style docstrings for every function and class."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/patch_output_cif_files.py` around lines 215 - 237, Add a NumPy-style
docstring to patch_individual_cif_file describing its purpose, parameters
(cif_file, rcsb_regex, reference_dir, input_pdb_pattern), and return
value/error-message behavior; keep the existing InvalidRcsbIdError vs. None
branching unchanged and document that it returns a string on failure or None on
success.

Source: Coding guidelines


70-96: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Missing NumPy-style docstring for parse_args.

As per coding guidelines, **/*: "Always include NumPy-style docstrings for every function and class." parse_args() has no docstring.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/patch_output_cif_files.py` around lines 70 - 96, Add a NumPy-style
docstring to parse_args in scripts/patch_output_cif_files.py. Document that it
parses CLI arguments for the patching script, and include an Args section only
if needed for any parameters, plus a Returns section describing the parsed
Namespace. Keep the docstring consistent with the project’s function/class
documentation standard.

Source: Coding guidelines


151-159: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Class/__init__ docstrings not in NumPy style.

InvalidRcsbIdError has a narrative docstring but no Parameters section describing token/rcsb_regex, and __init__ itself has no docstring at all. As per coding guidelines, **/*: "Always include NumPy-style docstrings for every function and class."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/patch_output_cif_files.py` around lines 151 - 159, Add NumPy-style
docstrings for InvalidRcsbIdError and its __init__ method. Replace the narrative
class docstring with a proper summary plus a Parameters section describing token
and rcsb_regex, and add a NumPy-style __init__ docstring that documents the same
arguments and the raised condition. Keep the documentation aligned with the
existing InvalidRcsbIdError class behavior and constructor signature.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/patch_output_cif_files.py`:
- Around line 162-212: In extract_rcsb_id, add a left-boundary validation for
the captured group so custom --rcsb-pattern matches are rejected when the id is
embedded inside a larger folder name (check the character before m.start(1), not
just the trailing boundary). Keep the existing whole-component and
_VALID_RCSB_ID checks, and update the function docstring to use NumPy-style
Parameters, Returns, and Raises sections for rcsb_path/rcsb_regex and the
existing return/error behavior.

---

Nitpick comments:
In `@scripts/patch_output_cif_files.py`:
- Around line 215-237: Add a NumPy-style docstring to patch_individual_cif_file
describing its purpose, parameters (cif_file, rcsb_regex, reference_dir,
input_pdb_pattern), and return value/error-message behavior; keep the existing
InvalidRcsbIdError vs. None branching unchanged and document that it returns a
string on failure or None on success.
- Around line 70-96: Add a NumPy-style docstring to parse_args in
scripts/patch_output_cif_files.py. Document that it parses CLI arguments for the
patching script, and include an Args section only if needed for any parameters,
plus a Returns section describing the parsed Namespace. Keep the docstring
consistent with the project’s function/class documentation standard.
- Around line 151-159: Add NumPy-style docstrings for InvalidRcsbIdError and its
__init__ method. Replace the narrative class docstring with a proper summary
plus a Parameters section describing token and rcsb_regex, and add a NumPy-style
__init__ docstring that documents the same arguments and the raised condition.
Keep the documentation aligned with the existing InvalidRcsbIdError class
behavior and constructor signature.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1bec314a-130a-4694-8998-0958c3cbf0c0

📥 Commits

Reviewing files that changed from the base of the PR and between d11354a and 699941c.

📒 Files selected for processing (8)
  • analyses/all.toml
  • analyses/analyze_grid_search.toml
  • analyses/external_tools.toml
  • scripts/eval/EVALUATION.md
  • scripts/patch_output_cif_files.py
  • tests/eval/script_loader.py
  • tests/eval/test_patch_output_cif_files.py
  • tests/runs/test_runner.py
✅ Files skipped from review due to trivial changes (3)
  • analyses/all.toml
  • scripts/eval/EVALUATION.md
  • analyses/external_tools.toml
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/runs/test_runner.py
  • analyses/analyze_grid_search.toml

Comment thread scripts/patch_output_cif_files.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread scripts/patch_output_cif_files.py Outdated
Co-authored-by: Copilot Autofix powered by AI <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread scripts/patch_output_cif_files.py Outdated
Co-authored-by: Copilot Autofix powered by AI <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread scripts/patch_output_cif_files.py Outdated
Co-authored-by: Copilot Autofix powered by AI <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread scripts/patch_output_cif_files.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

3 participants