Skip to content

Turn on autotoppar by default and handle unknown residues safely - issue #1743 - #1745

Merged
amjjbonvin merged 9 commits into
mainfrom
autotoppar
Nov 3, 2026
Merged

amjjbonvin merged 9 commits into
mainfrom
autotoppar

Conversation

@amjjbonvin

@amjjbonvin amjjbonvin commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Before submitting, read the contributing guidelines and the AI policy.

What does this PR do and why?

This PR sets autotoppar = true by default in [topoaa], so that PRODRG generates the topology and parameters of unknown residues automatically. Every unknown residue then goes through PRODRG. The PR therefore also makes sure that residues PRODRG cannot handle correctly lead to a clear error instead of a silently wrong system.

  • Default: autotoppar = true. The topoaa docstring is updated accordingly.

  • Clearer PRODRG errors: the error names the failing residue and gives PRODRG's own reason. PRODRG exits with 0 on failure and prints its errors on stdout, so they were never shown before. For ion-like residues, it lists the supported residue and atom names (e.g. ZN: if this is an ion, use residue ZN2 with atom ZN+2), with a link to the manual.

  • Ions: the neutral single-atom ion residues are removed from ion.top, except AR, AS, KR and XE, which have no charged species. A PDB-style ZN was silently treated as a neutral zinc atom; it is now reported as unknown, with the hint above.

  • PDB name aliases: TPO→TOP, HEM→HEB, SLB→SIB, CMO→COM and ARS→AS are renamed on input (libpdb.rename_residues), before the check for unknown residues. Their heavy-atom names match the HADDOCK3 definitions.

  • Selenocysteine: a PDB selenocysteine (SEC with an SE atom) was silently built as the HADDOCK3 SEC residue, a serine variant for covalent docking, with SE dropped and OG built. It is now converted on input to cysteine (SE renamed to SG, coordinates kept), with a warning. The HADDOCK3 SEC residue itself is unchanged.

  • Residues PRODRG would parameterise without their bonds: topoaa now stops with an error for

    • unknown residues inside a polymer chain (C–N or O3'–P bond to a neighbour);
    • unknown sugars linked by a glycosidic bond (to a protein or another sugar).

    Residues of fewer than three atoms (e.g. ions) are not passed to PRODRG.

  • autotoppar = false: unknown residues are still removed, but a warning now lists them and says when their removal breaks a chain or a glycosidic bond.

How was this tested?

  • New unit tests (tests/test_libligand.py, tests/test_libpdb.py) cover:
    • a real PRODRG failure;
    • the extraction of PRODRG's error lines;
    • the ion hint;
    • the residue aliases and the selenocysteine conversion;
    • the in-chain and linked-sugar detection, including free ligands and sugars that must still go to PRODRG.
  • Updated tests: the preprocessing ion tests now expect neutral ZN, NI and F to stay unrecognised. tests/test_gear_preprocessing.py is also ruff-formatted.
  • Test suites: pytest tests/ (2371 passed), integration_tests/ (129 passed) and end-to-end_tests/test_protein_ligand.py all pass.
  • Manual topoaa runs:
    • an ion with an undefined charge;
    • a neutral ZN, with autotoppar true and false;
    • a TPO in a protein, which is built as TOP with its phosphate;
    • a PDB selenocysteine, which is built as a cysteine instead of a serine;
    • an unknown residue inside a protein chain;
    • an unknown O-linked sugar.
  • Zinc-finger example: CAPRI results identical to main.
  • No false positives: none of the tracked PDB files in the examples and tests is wrongly flagged by the in-chain or sugar checks.

AI assistance

Claude Code wrote the code, tests and docstrings based on my specifications and checked them as described above.
The force-field change (removal of the neutral ions from ion.top) and the residue aliases were decided by me after reviewing the analysis
(affected files, atom-name comparison against the PDB Chemical Component Dictionary).

Checklist

  • Tests cover the new and/or changed code
  • Documentation updated if needed (also in the haddock3 user-manual) (user-manual update to follow: default, ion naming, aliases)
  • CHANGELOG.md updated for user-facing changes

Related issues

Closes #1743

Notes for reviewers

  • Behaviour change: runs with unknown residues that previously went through, with the residues silently removed or treated as neutral ions, now either generate their topology or stop with an explicit error. autotoppar = false restores the old behaviour, now with a warning.
  • Glycan trimming: opt-in trimming of unknown glycan branches is proposed in Opt-in trimming of unknown glycan branches in topoaa #1744.

🤖 Generated with Claude Code

amjjbonvin and others added 4 commits October 28, 2026 12:38
…1743

- PRODRG failures name the residue and give PRODRG's own reason; for
  ion-like residues, the supported residue/atom names are suggested
  (absolute charge in the residue name, exact charge in the atom name).
- Remove the neutral single-atom ion residues from ion.top (except AR,
  AS, KR, XE), so that e.g. a PDB-style ZN is no longer silently treated
  as a neutral atom.
- Rename PDB residue names on input to their HADDOCK3 names (TPO->TOP,
  HEM->HEB, SLB->SIB, CMO->COM, ARS->AS), before the unknown residue check.
- Stop with an error for unknown residues inside a polymer chain and for
  unknown sugars linked by a glycosidic bond, which PRODRG would
  parameterise without their bonds; residues of less than three atoms are
  not passed to PRODRG.
- Warn when unknown residues are removed from the models
  (autotoppar = false), including broken chains or glycosidic bonds.
- Update the topoaa docstring for the new default and fix the CHANGELOG
  date.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@amjjbonvin amjjbonvin self-assigned this Oct 28, 2026
@amjjbonvin amjjbonvin added enhancement Improving something in the codebase m|topoaa topoaa module AI Changes authored or assisted by AI labels Oct 28, 2026
amjjbonvin and others added 2 commits October 28, 2026 18:41
A PDB selenocysteine (SEC with an SE atom) was silently built as the
HADDOCK3 SEC residue, a serine variant for covalent docking (SE dropped,
OG built). rename_residues now converts it to cysteine (SE renamed to SG,
coordinates kept) and topoaa logs a warning. The HADDOCK3 SEC residue is
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
amjjbonvin and others added 2 commits October 29, 2026 09:44
Merge the two prodrg failure tests into one parametrized test, keep only
the fallback case of the prodrg message test (the error lines are already
checked by the failure test), and drop redundant asserts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@Comp-era Comp-era 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.

Tests ran fine, including additional protein–RNA testing. Custom topology handling and the remaining residue-processing checks also passed.

However, I noticed that haddock3-analyse reports a 'dict' object has no attribute 'rel_path' warning when analysing topoaa output. The same warning was also reproduced on main, so it does not appear to be related to this PR.

I'm unsure whether this warning is safe to ignore or if it could affect downstream analysis.

@amjjbonvin

Copy link
Copy Markdown
Member Author

However, I noticed that haddock3-analyse reports a 'dict' object has no attribute 'rel_path' warning when analysing topoaa output. The same warning was also reproduced on main, so it does not appear to be related to this PR.

Opened an issue about it #1758
Unrelated to this PR

@amjjbonvin
amjjbonvin requested a review from Comp-era November 3, 2026 12:08

@Comp-era Comp-era 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.

Looks good to me 🚀

@amjjbonvin
amjjbonvin merged commit ae72d8a into main Nov 3, 2026
9 checks passed
@amjjbonvin
amjjbonvin deleted the autotoppar branch November 3, 2026 12:14
amjjbonvin added a commit that referenced this pull request Nov 3, 2026
Conflicts with #1745 (autotoppar), resolved by keeping both sides:
- CHANGELOG.md: both 2026-10-28 entries.
- libpdb.py: find_insertion_codes next to _rename_line and rename_residues.
- topoaa: the insertion-code check runs before the residue renaming and
  the unknown-residue checks.
- test_libpdb.py: both imports and all tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Changes authored or assisted by AI enhancement Improving something in the codebase m|topoaa topoaa module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Turn on by default the automatic generation of ligand topo/param files

2 participants