Skip to content

Commit

Permalink
Add NoJump transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
p-j-smith committed Sep 16, 2023
1 parent 592e809 commit 708438b
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/mda_tui/widgets/transformations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from MDAnalysis import Universe
from MDAnalysis.transformations import (
NoJump as nojump,
TransformationBase,
center_in_box,
translate,
Expand Down Expand Up @@ -51,12 +52,14 @@ def compose(self) -> ComposeResult:
center_in_box = CenterInBox(id=CenterInBox.id)
wrap = Wrap(id=Wrap.id)
unwrap = Unwrap(id=Unwrap.id)
nojump = NoJump(id=NoJump.id)

options = [
(translate.description, translate),
(center_in_box.description, center_in_box),
(wrap.description, wrap),
(unwrap.description, unwrap),
(nojump.description, nojump),
]
select: Select[TransformationBase] = Select(
options=options,
Expand All @@ -70,6 +73,7 @@ def compose(self) -> ComposeResult:
yield center_in_box
yield wrap
yield unwrap
yield nojump

@on(Select.Changed, "#transformation")
def select_transformation(self, event) -> None:
Expand Down Expand Up @@ -350,3 +354,37 @@ def setup_transformation(self, universe: Universe):

def validate(self):
return [widget.validate(widget.value) for widget in self.query(Input)]


class NoJump(Vertical):
"""Widgets for setting parameters for nojump transformation"""

description = "Prevent jumps across periodic boundaries"
transformation = nojump
id = str(nojump).removeprefix("<class '").removesuffix("'>") # noqa: A003

def compose(self) -> ComposeResult:
"""Create layout of parameter widgets"""

check_continuity = Switch()

# Define tooltips
check_continuity_tooltip = "check the trajectory step size is not more than 1"

yield WidgetWithLabel(
label="check continuity",
widget=check_continuity,
id="check_continuity",
tooltip=check_continuity_tooltip,
)

@property
def check_continuity(self):
return self.query_one(Switch).value

def setup_transformation(self, universe: Universe): # noqa: ARG002
"""Initialise the transformation for a given universe"""
return self.transformation(check_continuity=self.check_continuity)

def validate(self):
return [widget.validate(widget.value) for widget in self.query(Input)]

0 comments on commit 708438b

Please sign in to comment.