Skip to content

Commit

Permalink
Merge pull request #403 from ISISNeutronMuon/chi/velocity-fix
Browse files Browse the repository at this point in the history
Velocity interpolation order 0 fix
  • Loading branch information
MBartkowiakSTFC authored Apr 7, 2024
2 parents 7a1e720 + b94eff3 commit fd5b841
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def configure(self, value):
:type value: str one of *'no interpolation'*,*'1st order'*,*'2nd order'*,*'3rd order'*,*'4th order'* or *'5th order'*.
"""

if not value:
if value is None or value == "":
value = self._default

IntegerConfigurator.configure(self, value)
Expand All @@ -66,6 +66,12 @@ def configure(self, value):

self["variable"] = "velocities"

elif value > 5:
self.error_status = (
f"Use an interpolation order greater than 5 is not implemented."
)
return

else:
self["variable"] = "coordinates"
self.error_status = "OK"
3 changes: 1 addition & 2 deletions MDANSE/Src/MDANSE/Framework/Jobs/DensityOfStates.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ def run_step(self, index):
indexes = self.configuration["atom_selection"]["indexes"][index]

if self.configuration["interpolation_order"]["value"] == 0:
series = trajectory.read_configuration_variable(
self.configuration["trajectory"]["instance"],
series = trajectory.read_configuration_trajectory(
indexes[0],
first=self.configuration["frames"]["first"],
last=self.configuration["frames"]["last"] + 1,
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 @@ -121,8 +121,7 @@ def run_step(self, index):
trajectory = self.configuration["trajectory"]["instance"]

if self.configuration["interpolation_order"]["value"] == 0:
series = trajectory.read_configuration_variable(
self.configuration["trajectory"]["instance"],
series = trajectory.read_configuration_trajectory(
index,
first=self.configuration["frames"]["first"],
last=self.configuration["frames"]["last"] + 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ def run_step(self, index):
indexes = self.configuration["atom_selection"]["indexes"][index]

if self.configuration["interpolation_order"]["value"] == 0:
series = trajectory.read_configuration_variable(
self.configuration["trajectory"]["instance"],
series = trajectory.read_configuration_trajectory(
indexes[0],
first=self.configuration["frames"]["first"],
last=self.configuration["frames"]["last"] + 1,
Expand Down
24 changes: 21 additions & 3 deletions MDANSE/Src/MDANSE/MolecularDynamics/Trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,17 +366,35 @@ def read_configuration_trajectory(
if last is None:
last = len(self)

grp = self._h5_file["/configuration"]

if variable not in grp:
if not self.has_variable(variable):
raise TrajectoryError(
"The variable {} is not stored in the trajectory".format(variable)
)

grp = self._h5_file["/configuration"]
variable = grp[variable][first:last:step, index, :].astype(np.float64)

return variable

def has_variable(self, variable: str) -> bool:
"""Check if the trajectory has a specific variable e.g.
velocities.
Parameters
----------
variable : str
The variable to check the existence of.
Returns
-------
bool
True if variable exists.
"""
if variable in self._h5_file["/configuration"]:
return True
else:
return False

@property
def chemical_system(self):
"""Return the chemical system stored in the trajectory.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ def __init__(self, *args, **kwargs):
source_object = kwargs.get("source_object", None)

self._field = QSpinBox(self._base)
self._field.setValue(1)
self._field.setMaximum(5)
configurator = self._configurator
trajectory = configurator._configurable[
configurator._dependencies["trajectory"]
]["instance"]
if not trajectory.has_variable("velocities"):
self._field.setMinimum(1)
self._field.setValue(1)
label = QLabel("Interpolation order", self._base)
self.numerator = QLabel("st order")

Expand Down

0 comments on commit fd5b841

Please sign in to comment.