Skip to content

Refactor of universe creation and applying transformations#93

Merged
hannahbaumann merged 54 commits into
mainfrom
code_refactor
May 27, 2026
Merged

Refactor of universe creation and applying transformations#93
hannahbaumann merged 54 commits into
mainfrom
code_refactor

Conversation

@hannahbaumann

@hannahbaumann hannahbaumann commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

The make_Universe function did two things: Create a Universe for a state and then applying some transformations to it, hard coding selection strings for protein and ligand.
Here, I split off the creation of the universe and the applying of transformations into separate steps. This allows passing AtomGroups to the apply_transformations function. I thought that this might be useful for moving towards a more individual Protocol based analysis.

@hannahbaumann hannahbaumann requested a review from jthorton March 2, 2026 13:26
Comment thread src/openfe_analysis/utils/apply_transformations.py Outdated
@hannahbaumann hannahbaumann requested a review from IAlibay May 21, 2026 11:32

@IAlibay IAlibay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mostly small things / nits, otherwise lgtm.

Comment thread src/openfe_analysis/reader.py Outdated
from openfe_analysis.utils.multistate import _determine_position_indices


def _create_universe_single_state(top, trj, state):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this should go into utils. The reader file should really concentrate on reader things rather than universe creation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I moved it into it's own universe_utils.py file.

ligand: Optional[mda.AtomGroup] = None,
):
"""
Apply a collection of transformations to a Universe.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since MDAnalysis transformations are meant to be quite flexible and additive, it might be good to be more descriptive about this sentence. Maybe be even just "collection of transformations usually required for X, Y, Z analyses" would be fine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added that they are typically used in RMSD analyses and other structural analyses.

u.trajectory.add_transformations(*transforms)


def _apply_transformations_complex(protein, ligand=None):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please do add type hints everywhere.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!

Comment thread src/openfe_analysis/utils/apply_transformations.py Outdated
Comment thread src/openfe_analysis/utils/apply_transformations.py Outdated
Comment thread src/openfe_analysis/utils/apply_transformations.py Outdated

@jthorton jthorton 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 @hannahbaumann looks great, nothing to add over @IAlibay so i'll approve early!

@hannahbaumann hannahbaumann linked an issue May 21, 2026 that may be closed by this pull request
Co-authored-by: Irfan Alibay <IAlibay@users.noreply.github.com>
Comment thread environment.yml Outdated
Comment thread pyproject.toml Outdated
@hannahbaumann hannahbaumann linked an issue May 26, 2026 that may be closed by this pull request
Base automatically changed from rmsd_refactor_analysisbase to main May 27, 2026 09:45
@hannahbaumann hannahbaumann reopened this May 27, 2026
Comment thread src/openfe_analysis/tests/test_rmsd.py Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Tests are now in test_gather_rms_data.py and test_transformations.py

@codecov

codecov Bot commented May 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.61905% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.63%. Comparing base (0911e9b) to head (03bb871).

Files with missing lines Patch % Lines
src/openfe_analysis/utils/apply_transformations.py 96.42% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #93      +/-   ##
==========================================
+ Coverage   96.93%   97.63%   +0.70%     
==========================================
  Files           6        8       +2     
  Lines         359      381      +22     
==========================================
+ Hits          348      372      +24     
+ Misses         11        9       -2     

☔ View full report in Codecov by Sentry.
📢 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.

@hannahbaumann hannahbaumann requested review from IAlibay and jthorton May 27, 2026 11:12

@IAlibay IAlibay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Couple of small things that might be worth fixing, I'm going to eagerly approve.

Comment thread src/openfe_analysis/reader.py Outdated
from ..reader import FEReader


def create_universe_single_state(top: Path, trj: nc.Dataset, state: int) -> mda.Universe:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
def create_universe_single_state(top: Path, trj: nc.Dataset, state: int) -> mda.Universe:
def create_universe_single_state(top: Path | mda.core.topology.Topology, trj: nc.Dataset, state: int) -> mda.Universe:

Or something like that - you can actually pass anything that Universe accepts for the topology argument. In practice we actually pass through a pre-existing Topology (see how it's called in gather_rms_data), so making it clear that it could at least be one of Path and Topology would be grand.

Comment thread src/openfe_analysis/utils/universe_utils.py Outdated
Comment thread src/openfe_analysis/utils/apply_transformations.py Outdated
hannahbaumann and others added 4 commits May 27, 2026 13:45
Co-authored-by: Irfan Alibay <IAlibay@users.noreply.github.com>
Co-authored-by: Irfan Alibay <IAlibay@users.noreply.github.com>
@hannahbaumann

Copy link
Copy Markdown
Contributor Author

pre-commit.ci autofix

@hannahbaumann hannahbaumann merged commit e093451 into main May 27, 2026
9 checks passed
@hannahbaumann hannahbaumann deleted the code_refactor branch May 27, 2026 12:27
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.

Expose the atom selection in the gather_rms_data function API work - RMSD

3 participants