Skip to content

Commit

Permalink
Use setdefault for dictionary defaults
Browse files Browse the repository at this point in the history
Co-authored-by: Jacob Wilkins <46597752+oerc0122@users.noreply.github.com>
  • Loading branch information
k-harris27 and oerc0122 committed Feb 28, 2025
1 parent cfaa1d0 commit ecd67e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
11 changes: 4 additions & 7 deletions janus_core/calculations/geom_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,10 @@ def __init__(
).absolute()

if self.write_traj:
if "filename" not in self.traj_kwargs:
self.traj_kwargs["filename"] = self._build_filename(
"traj.extxyz"
).absolute()
if "trajectory" not in self.opt_kwargs:
# Overwrite .traj binary with .extxyz by default.
self.opt_kwargs["trajectory"] = str(self.traj_kwargs["filename"])
self.traj_kwargs.setdefault(
"filename", self._build_filename("traj.extxyz").absolute()
)
self.opt_kwargs.setdefault("trajectory", str(self.traj_kwargs["filename"]))
elif self.traj_kwargs:
raise ValueError("traj_kwargs given, but trajectory writing not enabled.")
elif "trajectory" in self.opt_kwargs:
Expand Down
7 changes: 2 additions & 5 deletions janus_core/cli/geomopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,8 @@ def _set_minimize_kwargs(
Scalar pressure when optimizing cell geometry, in GPa. Passed to the filter
function if either `opt_cell_lengths` or `opt_cell_fully` is True.
"""
if "opt_kwargs" not in minimize_kwargs:
minimize_kwargs["opt_kwargs"] = {}

if "traj_kwargs" not in minimize_kwargs:
minimize_kwargs["traj_kwargs"] = {}
minimize_kwargs.setdefault("opt_kwargs", {})
minimize_kwargs.setdefault("traj_kwargs", {})

# Check hydrostatic_strain and scalar pressure not duplicated
if "filter_kwargs" in minimize_kwargs:
Expand Down

0 comments on commit ecd67e4

Please sign in to comment.