From 71969dd61b03b0392517782a3df89be7e30cc7c1 Mon Sep 17 00:00:00 2001 From: "Adam J. Jackson" Date: Mon, 30 Sep 2024 10:42:33 +0000 Subject: [PATCH] Tidy up a bit --- janus_core/calculations/geom_opt.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/janus_core/calculations/geom_opt.py b/janus_core/calculations/geom_opt.py index 301f0b56..9fb05f89 100644 --- a/janus_core/calculations/geom_opt.py +++ b/janus_core/calculations/geom_opt.py @@ -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.""" @@ -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__)