Skip to content

Do not serialize ExtraPoint children on atoms - #1439

Merged
swails merged 2 commits into
ParmEd:masterfrom
barlowa124:ep-children-pickle-1407
Oct 9, 2026
Merged

swails merged 2 commits into
ParmEd:masterfrom
barlowa124:ep-children-pickle-1407

Conversation

@barlowa124

Copy link
Copy Markdown
Contributor

Fixes #1407.

Atom.__getstate__ included the children list, so deepcopy(atom) (which Structure.copy calls per atom) cloned each child ExtraPoint into an orphan object. Those orphans were never added to the new structure's atom list, but the real copied ExtraPoint was appended to the same children list when Structure.copy rebuilt the Bond objects. Every atom bonded to an extra-point parent ended up with a stale ExtraPoint partner whose idx stayed -1, which made rediscover_molecules split TIP4P waters and raised MoleculeError.

children is derived state. It is populated only by bond_to and rebuilt whenever bonds are rebuilt, so this drops it from __getstate__ to make copied or unpickled atoms start with an empty list, matching the _bond_partners lists that are already excluded and repopulated the same way. Atom.__setstate__ initializes children before applying the stored dict, so old pickles that still carry the key restore unchanged.

Verification: python -m pytest test/test_parmed_amber.py test/test_parmed_topologyobjects.py test/test_parmed_structure.py test/test_parmed_formats.py gives 281 passed and 17 skipped. The pre-existing test_optimized_reader failure is an unbuilt _rdparm extension on this machine and fails on master too. The new test fails on unfixed code.

Atom.__getstate__ carried the children list, so deepcopy(atom) cloned
each child ExtraPoint into an orphan object that was never added to the
new structure's atom list. Structure.copy() rebuilds bonds afterwards,
appending the real copied ExtraPoint to the same children list, which
left every parent atom with a stale ExtraPoint partner (idx == -1) and
broke rediscover_molecules during GROMACS-to-Amber conversion.

children is derived state populated only by bond_to, like the partner
lists that are already excluded from __getstate__. Drop it so copied
atoms start empty and are repopulated by bond rebuilding.

Fixes ParmEd#1407
@swails

swails commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Thanks!

@swails
swails merged commit 6d14acb into ParmEd:master Oct 9, 2026
3 checks passed
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.

TIP4P-Ew water causes invalid -1-index ExtraPoint in bond partners, breaking rediscover_molecules in _amberparm.py

2 participants