-
Notifications
You must be signed in to change notification settings - Fork 51
Fix residue naming #2042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hannahbaumann
wants to merge
12
commits into
main
Choose a base branch
from
fix_residue_naming
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fix residue naming #2042
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e7882f0
Initial change of lig and cofactor resname
hannahbaumann cb4ece2
Merge branch 'main' into fix_residue_naming
hannahbaumann a32cf02
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 369f9d5
Fix tests
hannahbaumann 69a6a08
Add news entry
hannahbaumann 2609bc4
Add more tests
hannahbaumann 0844937
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 91fde04
Merge branch 'main' into fix_residue_naming
hannahbaumann d7a36cd
Merge branch 'main' into fix_residue_naming
IAlibay 11b9c2c
Update src/openfe/tests/protocols/openmm_rfe/test_hybrid_top_protocol.py
hannahbaumann 12b9840
Address review comments
hannahbaumann c68b88e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| **Added:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Changed:** | ||
|
|
||
| * Small molecules in RelativeHybridTopology topologies (including the output PDB) are now named LIG (alchemical ligand) and CF1, CF2… (cofactors) instead of UNK. If a residue name was already assigned, the assigned one is kept. | ||
|
|
||
| **Deprecated:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Removed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Fixed:** | ||
|
|
||
| * Fixed inflated ligand RMSD in the RelativeHybridTopology protocol's structural analysis for systems containing cofactors; the ligand RMSD is now computed for the alchemical ligand alone rather than conflating it with cofactors that shared the UNK residue name. | ||
|
|
||
| **Security:** | ||
|
|
||
| * <news item> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| # This code is part of OpenFE and is licensed under the MIT license. | ||
| # For details, see https://github.com/OpenFreeEnergy/openfe | ||
| import logging | ||
| from typing import Any | ||
|
|
||
| from openff.toolkit import Molecule as OFFMolecule | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def _set_offmol_metadata( | ||
| offmol: OFFMolecule, | ||
| key: Any, | ||
| val: Any | None, | ||
| ) -> None: | ||
| """ | ||
| Set a given metadata entry for a whole Molecule. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| offmol : openff.toolkit.Molecule | ||
| The Molecule to set the metadata for. | ||
| key : Any | ||
| The metadata key. | ||
| val : Any | ||
| The value to set the metadata entry to. | ||
| """ | ||
| if val is None: | ||
| for a in offmol.atoms: | ||
| a.metadata.pop(key, None) | ||
| else: | ||
| for a in offmol.atoms: | ||
| a.metadata[key] = val | ||
|
|
||
|
|
||
| def _get_offmol_metadata(offmol: OFFMolecule, key: Any) -> Any | None: | ||
| """ | ||
| Get an offmol's given metadata entry and make sure it is | ||
| consistent across all atoms in the Molecule. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| offmol : openff.toolkit.Molecule | ||
| Molecule to get the metadata value from. | ||
| key: Any | ||
| The metadata entry key. | ||
|
|
||
| Returns | ||
| ------- | ||
| value : Any | None | ||
| Metadata for the given key in the molecule. ``None`` if the | ||
| Molecule does not have that metadata entry set, or if | ||
| the value is inconsistent across all the atoms. | ||
| """ | ||
| value: Any | None = None | ||
| for a in offmol.atoms: | ||
| if value is None: | ||
| try: | ||
| value = a.metadata[key] | ||
| except KeyError: | ||
| return None | ||
|
|
||
| if value != a.metadata[key]: | ||
| wmsg = f"Inconsistent metadata {key} in OFFMol: {offmol}" | ||
| logger.warning(wmsg) | ||
| return None | ||
|
|
||
| return value | ||
|
|
||
|
|
||
| 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") |
32 changes: 16 additions & 16 deletions
32
src/openfe/tests/data/openmm_rfe/benzene_toluene_hybrid_top/hybrid_topology_atoms.csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,17 @@ | ||
| ,serial,name,element,resSeq,resName,chainID,segmentID,formal_charge | ||
| 0,,C1x,C,0,UNK,0,, | ||
| 1,,C2x,C,0,UNK,0,, | ||
| 2,,C3x,C,0,UNK,0,, | ||
| 3,,C4x,C,0,UNK,0,, | ||
| 4,,C5x,C,0,UNK,0,, | ||
| 5,,C6x,C,0,UNK,0,, | ||
| 6,,H1x,H,0,UNK,0,, | ||
| 7,,H2x,H,0,UNK,0,, | ||
| 8,,H3x,H,0,UNK,0,, | ||
| 9,,H4x,H,0,UNK,0,, | ||
| 10,,H5x,H,0,UNK,0,, | ||
| 11,,H6x,H,0,UNK,0,, | ||
| 12,,H1x,H,0,UNK,0,, | ||
| 13,,H2x,H,0,UNK,0,, | ||
| 14,,C1x,C,0,UNK,0,, | ||
| 15,,H3x,H,0,UNK,0,, | ||
| 0,,C1x,C,0,LIG,0,, | ||
| 1,,C2x,C,0,LIG,0,, | ||
| 2,,C3x,C,0,LIG,0,, | ||
| 3,,C4x,C,0,LIG,0,, | ||
| 4,,C5x,C,0,LIG,0,, | ||
| 5,,C6x,C,0,LIG,0,, | ||
| 6,,H1x,H,0,LIG,0,, | ||
| 7,,H2x,H,0,LIG,0,, | ||
| 8,,H3x,H,0,LIG,0,, | ||
| 9,,H4x,H,0,LIG,0,, | ||
| 10,,H5x,H,0,LIG,0,, | ||
| 11,,H6x,H,0,LIG,0,, | ||
| 12,,H1x,H,0,LIG,0,, | ||
| 13,,H2x,H,0,LIG,0,, | ||
| 14,,C1x,C,0,LIG,0,, | ||
| 15,,H3x,H,0,LIG,0,, |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would call this "offmolecule_utils" so that we know it's utilities for openff molecules and not rdkit molecules
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!