Skip to content

Commit 03aa397

Browse files
Apply suggestions from code review
Co-authored-by: Jacob Wilkins <46597752+oerc0122@users.noreply.github.com> Signed-off-by: Maciej Bartkowiak <108934199+MBartkowiakSTFC@users.noreply.github.com>
1 parent d3cd775 commit 03aa397

6 files changed

Lines changed: 27 additions & 25 deletions

File tree

MDANSE/Src/MDANSE/Framework/Configurators/HDFTrajectoryConfigurator.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ def next_prime(nchunks: int) -> int:
9898
int
9999
A prime number larger than the input number.
100100
"""
101-
for prime in PRIMES:
102-
if prime > nchunks:
103-
return prime
104-
return nchunks
101+
import bisect
102+
103+
ip = bisect.bisect_right(nchunks, PRIMES)
104+
return nchunks if ip == len(PRIMES) else PRIMES[ip]
105105

106106

107107
def guess_hdf5_trajectory_parameters(
@@ -154,17 +154,18 @@ def configure(self, value):
154154
self.error_status = "OK"
155155
self.warning_status = ""
156156

157-
if isinstance(value, (str, Path)):
158-
file_name = value
159-
driver = None
160-
rdcc_nbytes, rdcc_nslots = guess_hdf5_trajectory_parameters(value)
161-
rdcc_w0 = None
162-
else:
163-
file_name = value[0]
164-
driver = value[1] if value[1] in HDF5_DRIVERS else None
165-
rdcc_nbytes = value[2]
166-
rdcc_nslots = value[3]
167-
rdcc_w0 = value[4]
157+
match value:
158+
case str() | Path():
159+
file_name = value
160+
driver = None
161+
rdcc_nbytes, rdcc_nslots = guess_hdf5_trajectory_parameters(value)
162+
rdcc_w0 = None
163+
case (str(), str(), int(), int(), int()):
164+
file_name, driver, rdcc_nbytes, rdcc_nslots, rdcc_w0 = value
165+
driver = driver if driver in HDF5_DRIVERS else None
166+
case _:
167+
self.error_status = f"Invalid value {value!r}"
168+
return
168169

169170
self["driver"] = driver
170171
self["rdcc_nbytes"] = rdcc_nbytes

MDANSE/Src/MDANSE/Framework/Jobs/ScatteringLengthDensityProfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def run_step(self, index: int):
184184
conf = self.trajectory.configuration(frame_index)
185185

186186
box_coords = conf.to_fractional_coordinates()
187-
box_coords = box_coords - np.floor(box_coords)
187+
box_coords -= np.floor(box_coords)
188188

189189
axis_index = self.configuration["axis"]["index"]
190190
self._extent += np.linalg.norm(conf.unit_cell.direct[axis_index])

MDANSE/Src/MDANSE/Framework/Jobs/TrajectoryEditor.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,7 @@ def initialize(self):
160160
com_conf = AbsoluteConfiguration(
161161
coords,
162162
)
163-
self.grouped_indices = reduce(
164-
list.__add__, new_chemical_system.clusters.values(), []
165-
)
163+
self.grouped_indices = list(more_itertools.flatten(new_chemical_system.clusters.values()))
166164
coords = com_conf.contiguous_configuration(self.grouped_indices).coordinates
167165
else:
168166
assign_molecules_after_atom_selection(

MDANSE/Src/MDANSE/MolecularDynamics/Configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ def clone(self) -> _PeriodicConfiguration:
423423
variables = copy.deepcopy(self.variables)
424424
coords = variables.pop("coordinates")
425425

426-
return self.__class__(coords, unit_cell, **variables)
426+
return type(self)(coords, unit_cell, **variables)
427427

428428
def fold_coordinates(self):
429429
"""Fold the coordinates into simulation box."""

MDANSE/Src/MDANSE/MolecularDynamics/Trajectory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ def to_absolute_coordinates(
651651
Returns
652652
-------
653653
ndarray
654-
2D array containing the real coordinates converted from box coordinates.
654+
2D array containing the absolute coordinates converted from fractionals.
655655
656656
"""
657657
return self._trajectory.to_absolute_coordinates(box_coordinates, first, last, step)

MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/OutputTrajectoryWidget.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,16 @@ def __init__(self, *args, **kwargs):
6868
self.dtype_box.setCurrentText("float64")
6969
self.chunk_atom_box = QSpinBox(self._base)
7070
self.chunk_frame_box = QSpinBox(self._base)
71-
for index, chunk_box in enumerate((self.chunk_atom_box, self.chunk_frame_box)):
71+
for typ, chunk_box in zip(
72+
("atoms", "frames"),
73+
(self.chunk_atom_box, self.chunk_frame_box)
74+
):
7275
chunk_box.setMinimum(1)
7376
chunk_box.setMaximum(0xFFFF)
74-
chunk_box.setValue(1 if index else 128)
75-
chunk_box.setSingleStep(1 if index else 32)
77+
chunk_box.setValue(1 if typ == "frames" else 128)
78+
chunk_box.setSingleStep(1 if typ == "frames" else 32)
7679
chunk_box.setToolTip(
77-
f"Specifies the number of {'frames' if index else 'atoms'} in a single chunk of the HDF5 file."
80+
f"Specifies the number of {typ} in a single chunk of the HDF5 file."
7881
"Affects the performance of reading and writing the trajectory."
7982
)
8083
self.compression_box = QComboBox(self._base)

0 commit comments

Comments
 (0)