Skip to content

Fix FrozenInstanceError when discarding non-reactant monomers#43

Merged
janitha-mahanthe merged 2 commits into25-v02-refactor-into-class-basedfrom
copilot/sub-pr-42
Mar 3, 2026
Merged

Fix FrozenInstanceError when discarding non-reactant monomers#43
janitha-mahanthe merged 2 commits into25-v02-refactor-into-class-basedfrom
copilot/sub-pr-42

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 3, 2026

MonomerEntry is @dataclass(frozen=True), but non_reactant_selection was directly assigning monomer.status = 'discarded', which raises FrozenInstanceError at runtime.

Changes

  • non_monomer_detector.py: Replace all three .status mutation sites with dataclasses.replace(), rebuilding simulation_setup.monomers via list comprehension with ID-based set lookups
# Before — raises FrozenInstanceError
for monomer in non_reactants_list:
    monomer.status = 'discarded'

# After — creates new instances, updates monomers list in one pass
discard_ids = {m.id for m in non_reactants_list}
simulation_setup.monomers = [
    replace(m, status='discarded') if m.id in discard_ids else m
    for m in simulation_setup.monomers
]
  • Updated the docstring note that previously claimed in-place mutation to reflect the new immutable replacement pattern.

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…tribute assignment on frozen MonomerEntry

Co-authored-by: janitha-mahanthe <119646255+janitha-mahanthe@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on improving Monomer Input Schema Fix FrozenInstanceError when discarding non-reactant monomers Mar 3, 2026
@janitha-mahanthe janitha-mahanthe marked this pull request as ready for review March 3, 2026 21:31
@janitha-mahanthe janitha-mahanthe merged commit ef45b76 into 25-v02-refactor-into-class-based Mar 3, 2026
@janitha-mahanthe janitha-mahanthe deleted the copilot/sub-pr-42 branch March 5, 2026 19:23
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