Skip to content

Commit

Permalink
Merge pull request #635 from ISISNeutronMuon/chi/deriv-setting-check
Browse files Browse the repository at this point in the history
Numerical derivatives configurators now check there are enough MD frames.
  • Loading branch information
MBartkowiakSTFC authored Jan 14, 2025
2 parents 798a919 + 17429ff commit 78005e7
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 22 deletions.
20 changes: 12 additions & 8 deletions MDANSE/Src/MDANSE/Framework/Configurable.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,21 @@ def configuration(self):

return self._configuration

def setup(self, parameters):
def setup(self, parameters: dict, rebuild: bool = True):
"""Builds and sets the configuration according to a set of
input parameters.
Parameters
----------
parameters : dict
A dictionary of setting parameters.
rebuild : bool
Rebuilds all the configurators if true.
"""
Setup the configuration according to a set of input parameters.
:param parameters: the input parameters
:type parameters: dict
"""

self._configured = False

self.build_configuration()
if rebuild:
self.build_configuration()

# If no configurator has to be configured, just return
if not self._configuration:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ def configure(self, value: Optional[int]) -> None:
value : int or None
The interpolation order to use.
"""
frames_configurator = self._configurable[self._dependencies["frames"]]
if not frames_configurator._valid:
self.error_status = f"Frames configurator is not valid."
return

self._original_input = value
if value is None:
value = self._default
Expand All @@ -54,4 +59,11 @@ def configure(self, value: Optional[int]) -> None:
)
return

number = frames_configurator["number"]
if number < value + 1:
self.error_status = (
f"Not enough MD frames to apply derivatives of order {value}"
)
return

self.error_status = "OK"
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ def configure(self, value):
:param value: the interpolation order to be configured.
:type value: str one of *'no interpolation'*,*'1st order'*,*'2nd order'*,*'3rd order'*,*'4th order'* or *'5th order'*.
"""
frames_configurator = self._configurable[self._dependencies["frames"]]
if not frames_configurator._valid:
self.error_status = f"Frames configurator is not valid."
return

self._original_input = value
if value is None or value == "":
Expand All @@ -71,5 +75,12 @@ def configure(self, value):
return

else:
number = frames_configurator["number"]
if number < value + 1:
self.error_status = (
f"Not enough MD frames to apply derivatives of order {value}"
)
return

self["variable"] = "coordinates"
self.error_status = "OK"
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ class CurrentCorrelationFunction(IJob):
"InterpolationOrderConfigurator",
{
"label": "velocities",
"dependencies": {"trajectory": "trajectory"},
"default": 1,
"dependencies": {"trajectory": "trajectory", "frames": "frames"},
},
)
settings["q_vectors"] = (
Expand Down
5 changes: 4 additions & 1 deletion MDANSE/Src/MDANSE/Framework/Jobs/DensityOfStates.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ class DensityOfStates(IJob):
)
settings["interpolation_order"] = (
"InterpolationOrderConfigurator",
{"label": "velocities", "dependencies": {"trajectory": "trajectory"}},
{
"label": "velocities",
"dependencies": {"trajectory": "trajectory", "frames": "frames"},
},
)
settings["projection"] = (
"ProjectionConfigurator",
Expand Down
5 changes: 4 additions & 1 deletion MDANSE/Src/MDANSE/Framework/Jobs/Infrared.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ class Infrared(IJob):
)
settings["derivative_order"] = (
"DerivativeOrderConfigurator",
{"label": "d/dt dipole numerical derivative"},
{
"label": "d/dt dipole numerical derivative",
"dependencies": {"frames": "frames"},
},
)
settings["molecule_name"] = (
"MoleculeSelectionConfigurator",
Expand Down
3 changes: 1 addition & 2 deletions MDANSE/Src/MDANSE/Framework/Jobs/Temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ class Temperature(IJob):
"InterpolationOrderConfigurator",
{
"label": "velocities",
"dependencies": {"trajectory": "trajectory"},
"default": 1,
"dependencies": {"trajectory": "trajectory", "frames": "frames"},
},
)
settings["output_files"] = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ class VelocityAutoCorrelationFunction(IJob):
)
settings["interpolation_order"] = (
"InterpolationOrderConfigurator",
{"label": "velocities", "dependencies": {"trajectory": "trajectory"}},
{
"label": "velocities",
"dependencies": {"trajectory": "trajectory", "frames": "frames"},
},
)
settings["projection"] = (
"ProjectionConfigurator",
Expand Down
16 changes: 13 additions & 3 deletions MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/DerivativeOrderWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, *args, **kwargs):
self._field.setValue(3)
label = QLabel("Interpolation order", self._base)
self.numerator = QLabel("st order")
self.adjust_numerator(3)
self.adjust_numerator_and_update(3)

self._layout.addWidget(label)
self._layout.addWidget(self._field)
Expand All @@ -53,7 +53,16 @@ def __init__(self, *args, **kwargs):

self._field.setToolTip(tooltip_text)
self.numerator.setToolTip(tooltip_text)
self._field.valueChanged.connect(self.adjust_numerator)
self._field.valueChanged.connect(self.adjust_numerator_and_update)

for widget in self.parent()._widgets:
if (
widget._configurator
is self._configurator._configurable[
self._configurator._dependencies["frames"]
]
):
widget.value_changed.connect(self.updateValue)

def configure_using_default(self):
"""This is too simple to have a default value"""
Expand All @@ -65,10 +74,11 @@ def default_labels(self):
self._tooltip = "The order of the polynomial function used for interpolating time-dependent variables."

@Slot(int)
def adjust_numerator(self, order: int):
def adjust_numerator_and_update(self, order: int):
text_order = str(order)
new_numerator = suffix_dict.get(text_order[-1])
self.numerator.setText(new_numerator)
self.updateValue()

def get_widget_value(self):
value = self._field.value()
Expand Down
16 changes: 13 additions & 3 deletions MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/InterpolationOrderWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, *args, **kwargs):
self._field.setValue(3)
label = QLabel("Interpolation order", self._base)
self.numerator = QLabel("st order")
self.adjust_numerator(3)
self.adjust_numerator_and_update(3)

self._layout.addWidget(label)
self._layout.addWidget(self._field)
Expand All @@ -60,7 +60,16 @@ def __init__(self, *args, **kwargs):
tooltip_text = "The order of the polynomial function used for interpolating velocity values from atom positions. If zero, velocity values present in the trajectory will be used."
self._field.setToolTip(tooltip_text)
self.numerator.setToolTip(tooltip_text)
self._field.valueChanged.connect(self.adjust_numerator)
self._field.valueChanged.connect(self.adjust_numerator_and_update)

for widget in self.parent()._widgets:
if (
widget._configurator
is self._configurator._configurable[
self._configurator._dependencies["frames"]
]
):
widget.value_changed.connect(self.updateValue)

def configure_using_default(self):
"""This is too simple to have a default value"""
Expand All @@ -76,10 +85,11 @@ def default_labels(self):
self._tooltip = "The order of the polynomial function used for interpolating velocity values from atom positions. If zero, velocity values present in the trajectory will be used."

@Slot(int)
def adjust_numerator(self, order: int):
def adjust_numerator_and_update(self, order: int):
text_order = str(order)
new_numerator = suffix_dict.get(text_order[-1], " - no interpolation")
self.numerator.setText(new_numerator)
self.updateValue()

def get_widget_value(self):
value = self._field.value()
Expand Down
2 changes: 1 addition & 1 deletion MDANSE_GUI/Src/MDANSE_GUI/Tabs/Visualisers/Action.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def show_output_prediction(self):
self.allow_execution()
LOG.info("Show output prediction")
pardict = self.set_parameters()
self._job_instance.setup(pardict)
self._job_instance.setup(pardict, rebuild=False)
axes = self._job_instance.preview_output_axis()
LOG.info(f"Axes = {axes.keys()}")
text = "<p><b>The results will cover the following range:</b></p>"
Expand Down

0 comments on commit 78005e7

Please sign in to comment.