Skip to content

Commit

Permalink
Tidy up a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
ajjackson committed Sep 30, 2024
1 parent d27a76c commit 71969dd
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions janus_core/calculations/geom_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,16 +242,14 @@ def __init__(
# Configure optimizer dynamics
self.set_optimizer()

def _get_constraint_args(self, constraint_class: object) -> list[Any]:
def _set_mandatory_constraint_kwargs(self) -> None:
"""Inspect constraint class for mandatory arguments
For now we are just looking for the "atoms" parameter of FixSymmetry
"""
parameters = inspect.signature(constraint_class.__init__).parameters
parameters = inspect.signature(self.constraint_func.__init__).parameters
if "atoms" in parameters:
return [self.struct]

return []
self.constraint_kwargs["atoms"] = self.struct

def set_optimizer(self) -> None:
"""Set optimizer for geometry optimization."""
Expand All @@ -260,8 +258,8 @@ def set_optimizer(self) -> None:
self.logger.info("Using optimizer: %s", self.optimizer.__name__)

if self.constraint_func is not None:
constraint_args = self._get_constraint_args(self.constraint_func)
self.struct.set_constraint(self.constraint_func(*constraint_args, **self.constraint_kwargs))
self._set_mandatory_constraint_kwargs()
self.struct.set_constraint(self.constraint_func(**self.constraint_kwargs))

if self.logger:
self.logger.info("Using constraint: %s", self.constraint_func.__name__)
Expand Down

0 comments on commit 71969dd

Please sign in to comment.