Skip to content

Refactor of universe creation and applying transformations#93

Open
hannahbaumann wants to merge 11 commits into
rmsd_refactor_analysisbasefrom
code_refactor
Open

Refactor of universe creation and applying transformations#93
hannahbaumann wants to merge 11 commits into
rmsd_refactor_analysisbasefrom
code_refactor

Conversation

@hannahbaumann
Copy link
Copy Markdown
Contributor

@hannahbaumann hannahbaumann commented Feb 27, 2026

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
@hannahbaumann hannahbaumann requested a review from IAlibay May 21, 2026 11:32
Copy link
Copy Markdown
Member

@IAlibay IAlibay left a comment

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.

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.

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.

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.



def apply_transformations(
u: 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.

I often make this mistake, so I'm nit-picking but universe might be better here than u.


def apply_transformations(
u: mda.Universe,
protein: Optional[mda.AtomGroup] = 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.

Given we're post python 3.9, it might be good to go for mda.AtomGroup | None instead of Optional for new type hints.

from ..transformations import Aligner, ClosestImageShift, NoJump


def apply_transformations(
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.

Very small nit: is apply_tansformations generic as these are the standard alignment transformations, what about apply_alignment_transformations or apply_analysis_transformations?

Copy link
Copy Markdown
Contributor

@jthorton jthorton left a comment

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

API work - RMSD

3 participants