-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor of universe creation and applying transformations #93
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
8
commits into
rmsd_refactor_analysisbase
Choose a base branch
from
code_refactor
base: rmsd_refactor_analysisbase
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3e7f6d8
Refactor of universe creation and applying transformations
hannahbaumann 5e65b34
Add new file
hannahbaumann 8a8b20a
more updates
hannahbaumann 8c08fa6
Merge branch 'rmsd_refactor_analysisbase' into code_refactor
hannahbaumann b7ba29f
Merge branch 'rmsd_refactor_analysisbase' into code_refactor
hannahbaumann 113dc6d
Merge branch 'rmsd_refactor_analysisbase' into code_refactor
hannahbaumann a73f096
Split complex and ligand only treatment into separate functions
hannahbaumann 2f7a441
Fix docstring
hannahbaumann 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
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
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,89 @@ | ||
| from typing import Optional | ||
|
|
||
| import MDAnalysis as mda | ||
| from MDAnalysis.transformations import unwrap | ||
|
|
||
| from ..transformations import Aligner, ClosestImageShift, NoJump | ||
|
|
||
|
|
||
| def apply_transformations( | ||
| u: mda.Universe, | ||
| protein: Optional[mda.AtomGroup] = None, | ||
| ligand: Optional[mda.AtomGroup] = None, | ||
| ): | ||
| """ | ||
| Apply a collection of transformations to a Universe. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| u: Universe | ||
| The Universe the transformations are applied to | ||
| protein: Optional[AtomGroup] | ||
| The AtomGroup of the protein | ||
| ligand: Optional[AtomGroup] | ||
| The AtomGroup of the ligand | ||
|
|
||
| Notes | ||
| ----- | ||
| Depending on whether a protein is present, a sequence of trajectory | ||
| transformations is applied: | ||
|
|
||
| If a protein is present: | ||
|
|
||
| - Unwraps protein and ligand atom to be made whole | ||
| - Shifts protein chains and the ligand to the image closest to the first | ||
| protein chain (:class:`ClosestImageShift`) | ||
| - Aligns the entire system to minimise the protein RMSD (:class:`Aligner`) | ||
|
|
||
| If only a ligand is present: | ||
|
|
||
| - Prevents the ligand from jumping between periodic images | ||
| - Aligns the ligand to minimize its RMSD | ||
| """ | ||
| has_protein = protein is not None and protein.n_atoms > 0 | ||
| has_ligand = ligand is not None and ligand.n_atoms > 0 | ||
|
|
||
| if has_protein: | ||
| lig = ligand if has_ligand else None | ||
| transforms = _apply_transformations_complex(protein, lig) | ||
| elif has_ligand: | ||
| transforms = _apply_transformations_ligand_only(ligand) | ||
| else: | ||
| return | ||
|
|
||
| u.trajectory.add_transformations(*transforms) | ||
|
|
||
|
|
||
| def _apply_transformations_complex(protein, ligand=None): | ||
| """ | ||
| Build transformations for systems containing a protein | ||
| and optionally a ligand. | ||
| """ | ||
| transforms = [] | ||
| # 1. Make molecules whole (protein + optional ligand) | ||
| group = protein if ligand is None else protein + ligand | ||
| transforms.append(unwrap(group)) | ||
|
|
||
| # 2. Closest image shift for protein chains + ligand (if present) | ||
| chains = [seg.atoms for seg in protein.segments] | ||
| shift_targets = chains[1:] | ||
| if ligand is not None: | ||
| shift_targets.append(ligand) | ||
| transforms.append(ClosestImageShift(chains[0], shift_targets)) | ||
|
|
||
| # 3. Align on protein backbone/atoms | ||
| transforms.append(Aligner(protein)) | ||
|
|
||
| return transforms | ||
|
|
||
|
|
||
| def _apply_transformations_ligand_only(ligand): | ||
| """ | ||
| Build transformations for ligand-only systems. | ||
| - make the ligand not jump periodic images between frames | ||
| - align the ligand to minimize its RMSD | ||
| """ | ||
| return [ | ||
| NoJump(ligand), | ||
| Aligner(ligand), | ||
| ] | ||
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.
Uh oh!
There was an error while loading. Please reload this page.