Skip to content

Fix residue names & numbers for the PlainMDProtocol - #2178

Open
IAlibay wants to merge 9 commits into
mainfrom
resname_plainmd
Open

Fix residue names & numbers for the PlainMDProtocol#2178
IAlibay wants to merge 9 commits into
mainfrom
resname_plainmd

Conversation

@IAlibay

@IAlibay IAlibay commented Aug 29, 2026

Copy link
Copy Markdown
Member

Fix #2158

LLM / AI generated code disclosure

LLMs or other AI-powered tools (beyond simple IDE use cases) were used in this contribution: no
If yes, please provide details here:

Checklist

  • All new code is appropriately documented (user-facing code must have complete docstrings).
  • Added a news entry, or the changes are not user-facing.
  • Ran pre-commit: you can run pre-commit locally or comment on this PR with pre-commit.ci autofix.
  • Filled in the AI generated code disclosure.

Manual Tests: these are slow so don't need to be run every commit, only before merging and when relevant changes are made (generally at reviewer-discretion).

Developers certificate of origin

@IAlibay

IAlibay commented Aug 29, 2026

Copy link
Copy Markdown
Member Author

pre-commit.ci autofix

@IAlibay
IAlibay requested a review from hannahbaumann August 29, 2026 23:29
if _get_offmol_metadata(offmol, "residue_number") is None:
_set_offmol_metadata(offmol, "residue_number", _next_resnum())
resnum = _next_available_number(used_resnums)
_set_offmol_metadata(offmol, "residue_number", str(resnum))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I checked that OpenFF reads residue numbers into strings, so we should be doing that (it also works fine when converting to OpenMM Topologies).

@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.11111% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.25%. Comparing base (a4a5a6d) to head (724d5b2).

Files with missing lines Patch % Lines
...fe/tests/protocols/openmm_md/test_plain_md_slow.py 25.00% 3 Missing ⚠️
...openfe/protocols/openmm_utils/offmolecule_utils.py 96.29% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2178      +/-   ##
==========================================
- Coverage   95.02%   90.25%   -4.77%     
==========================================
  Files         206      206              
  Lines       20514    20531      +17     
==========================================
- Hits        19493    18530     -963     
- Misses       1021     2001     +980     
Flag Coverage Δ
fast-tests 90.25% <91.11%> (?)
slow-tests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines 73 to 111
def _set_offmol_resname(
offmol: OFFMolecule,
resname: str | None,
) -> None:
"""
Helper method to set offmol residue names

Parameters
----------
offmol : openff.toolkit.Molecule
Molecule to assign a residue name to.
resname : str | None
Residue name to be set. Set to None to clear it.

Returns
-------
None
"""
_set_offmol_metadata(offmol, "residue_name", resname)


def _get_offmol_resname(offmol: OFFMolecule) -> str | None:
"""
Helper method to get an offmol's residue name and make sure it is
consistent across all atoms in the Molecule.

Parameters
----------
offmol : openff.toolkit.Molecule
Molecule to get the residue name from.

Returns
-------
resname : Optional[str]
Residue name of the molecule. ``None`` if the Molecule
does not have a residue name, or if the residue name is
inconsistent across all the atoms.
"""
return _get_offmol_metadata(offmol, "residue_name")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we still need these, it looks like you are using the general metadata functions in the plainMD now but assign_offmol_residue_metadata is using a mix, if the changes to plain MD are the prefered pattern lets remove these.

@jthorton jthorton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just a bit of code clean up and news to add.

@hannahbaumann hannahbaumann 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.

Thanks @IAlibay ! Approving early, but agreeing with Josh's comments!

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.

Update residue names for the PlainMDProtocol

3 participants