Skip to content

esmfold2: return each CCD ligand component as its own residue - #416

Open
daylight-00 wants to merge 1 commit into
Biohub:mainfrom
daylight-00:draft/nonpolymer-components
Open

daylight-00 wants to merge 1 commit into
Biohub:mainfrom
daylight-00:draft/nonpolymer-components

Conversation

@daylight-00

Copy link
Copy Markdown

A ligand given as several CCD codes comes back from fold() as one residue named after its first component:

LigandInput(id="B", ccd=["NAG", "BMA"])
# complex.sequence: [..., "NAG"]          # both components' atoms under one name
# with this PR:     [..., "NAG", "BMA"]

The tokenizer already keeps each component's residue_index; only the output builder threw it away.

  • Non-polymer tokens are now grouped by residue_index, the same way atom-tokenized polymer residues (MSE, HYP, ...) already are. The two branches share one loop and differ only in the hetero flag.
  • SMILES ligands, single-CCD ligands and polymers come back exactly as before. The docstring described the old collapse, so this is a deliberate behavior change for multi-component ligands only.
  • Bonus fix: to_mmcif() keys entities on residue names, so ["NAG", "NAG"] and ["NAG", "BMA"] were written as the same entity. They no longer are.

Tested with a new tests/models/esmfold2_output_test.py (needs the CCD pickle): the two multi-component cases fail on main and pass here, and the single-component case passes on both. No new failures in prepare_input_test.py, esmfold2_inputs_test.py or esmfold2_cpu_only_test.py; ruff and ty are clean.

`LigandInput(ccd=["NAG", "BMA"])` decoded as a single NAG residue holding both components' atoms, although the tokenizer keeps each component's residue_index.

- Group non-polymer tokens by residue_index, the same groupby polymer residues already use.
- SMILES, single-CCD ligands and polymers decode exactly as before.
- Chains that differ after their first component no longer share an mmCIF entity.
Copilot AI lite review requested due to automatic review settings September 28, 2026 11:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

The experimental output path and empty-CCD fallback still need correction.

Review effort: Lite
Findings: None

What changed in this PR

This PR updates ESMFold2 output construction so multi-component CCD ligands are returned as separate residues and distinct mmCIF entities.

Changes:

  • Groups ligand components by residue_index.
  • Preserves hetero flags and existing behavior for other ligand types.
  • Adds regression tests for residue grouping and entity separation.
File Summary
tests/​models/​esmfold2_output_test.py Adds coverage for multi-component ligand residues and entity mapping.
esm/​models/​esmfold2/​output.py Groups ligand components into separate residues and updates entity handling.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

2 participants