Skip to content
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

Velocity interpolation order 0 fix #403

Merged
merged 8 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading