Skip to content

Commit

Permalink
Make code more ruff-compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
MBartkowiakSTFC committed Feb 7, 2025
1 parent 3c07587 commit 9e4086c
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions MDANSE/Src/MDANSE/Trajectory/H5MDTrajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def __init__(self, h5_filename: Union[Path, str]):
except Exception:
conv_factor = 1.0
else:
if pos_unit == "Ang" or pos_unit == "Angstrom":
if pos_unit in ("Ang", "Angstrom"):
pos_unit = "ang"
conv_factor = measure(1.0, pos_unit).toval("nm")
coords *= conv_factor
Expand Down Expand Up @@ -128,13 +128,12 @@ def __getitem__(self, frame):
:rtype: dict of ndarray
"""

grp = self._h5_file["/particles/all/position/value"]
try:
pos_unit = self._h5_file["/particles/all/position/value"].attrs["unit"]
except:
except Exception:
conv_factor = 1.0
else:
if pos_unit == "Ang" or pos_unit == "Angstrom":
if pos_unit in ("Ang", "Angstrom"):
pos_unit = "ang"
conv_factor = measure(1.0, pos_unit).toval("nm")
configuration = {}
Expand All @@ -144,12 +143,12 @@ def __getitem__(self, frame):
try:
try:
vel_unit = self._h5_file["/particles/all/velocity/value"].attrs["unit"]
except:
except Exception:
vel_unit = "ang/fs"
configuration["velocities"] = self._h5_file[
"/particles/all/velocity/value"
][frame, :, :] * measure(1.0, vel_unit).toval("nm/ps")
except:
except Exception:
pass

configuration["time"] = self.time()[frame]
Expand Down Expand Up @@ -186,7 +185,7 @@ def charges(self, frame):
except KeyError:
LOG.debug(f"No charge information in trajectory {self._h5_filename}")
charge = np.zeros(self._chemical_system.number_of_atoms)
except:
except Exception:
try:
charge = self._h5_file["/particles/all/charge"][:]
except KeyError:
Expand All @@ -209,10 +208,10 @@ def coordinates(self, frame):
raise IndexError(f"Invalid frame number: {frame}")
try:
pos_unit = self._h5_file["/particles/all/position/value"].attrs["unit"]
except:
except Exception:
conv_factor = 1.0
else:
if pos_unit == "Ang" or pos_unit == "Angstrom":
if pos_unit in ("Ang", "Angstrom"):
pos_unit = "ang"
conv_factor = measure(1.0, pos_unit).toval("nm")

Expand Down Expand Up @@ -243,7 +242,7 @@ def configuration(self, frame):
if k not in self._variables_to_skip:
try:
variables[k] = self.variable(k)[frame, :, :].astype(np.float64)
except:
except Exception:
self._variables_to_skip.append(k)

coordinates = self.coordinates(frame)
Expand Down Expand Up @@ -395,10 +394,10 @@ def read_com_trajectory(
grp = self._h5_file["/particles/all/position/value"]
try:
pos_unit = self._h5_file["/particles/all/position/value"].attrs["unit"]
except:
except Exception:
conv_factor = 1.0
else:
if pos_unit == "Ang" or pos_unit == "Angstrom":
if pos_unit in ("Ang", "Angstrom"):
pos_unit = "ang"
conv_factor = measure(1.0, pos_unit).toval("nm")

Expand Down Expand Up @@ -493,10 +492,10 @@ def read_atomic_trajectory(
grp = self._h5_file["/particles/all/position/value"]
try:
pos_unit = self._h5_file["/particles/all/position/value"].attrs["unit"]
except:
except Exception:
conv_factor = 1.0
else:
if pos_unit == "Ang" or pos_unit == "Angstrom":
if pos_unit in ("Ang", "Angstrom"):
pos_unit = "ang"
conv_factor = measure(1.0, pos_unit).toval("nm")
coords = grp[first:last:step, index, :].astype(np.float64) * conv_factor
Expand Down

0 comments on commit 9e4086c

Please sign in to comment.