From 78eb29c91306d51c54ff1af1c28072a6efe41440 Mon Sep 17 00:00:00 2001 From: Lauri Himanen <6513318+lauri-codes@users.noreply.github.com> Date: Fri, 3 May 2024 09:20:03 +0300 Subject: [PATCH] Interface fix (#3) * Changed interface * Removed archive from constructor * Removed use of old variable * Fixed test calls. --- simulationworkflownormalizer/normalizer.py | 24 +++++++++++----------- tests/test_simulationworkflownormalizer.py | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/simulationworkflownormalizer/normalizer.py b/simulationworkflownormalizer/normalizer.py index ae836fa..fcab4af 100644 --- a/simulationworkflownormalizer/normalizer.py +++ b/simulationworkflownormalizer/normalizer.py @@ -33,20 +33,20 @@ class SimulationWorkflowNormalizer(Normalizer): This normalizer produces information specific to a simulation workflow. """ - def __init__(self, entry_archive: EntryArchive): - super().__init__(entry_archive) + def __init__(self): + super().__init__() self._elastic_programs = ['elastic'] self._phonon_programs = ['phonopy'] self._molecular_dynamics_programs = ['lammps'] - def _resolve_workflow(self): - if not self.entry_archive.run: + def _resolve_workflow(self, archive: EntryArchive): + if not archive.run: return # resolve it from parser workflow = None try: - program_name = self.entry_archive.run[-1].program.name + program_name = archive.run[-1].program.name except Exception: program_name = None @@ -66,20 +66,20 @@ def _resolve_workflow(self): if workflow is None: # workflow references always to the last run # TODO decide if workflow should map to each run - if len(self.entry_archive.run[-1].calculation) == 1: + if len(archive.run[-1].calculation) == 1: workflow = SinglePoint() else: workflow = GeometryOptimization() return workflow - def normalize(self, logger=None) -> None: + def normalize(self, archive: EntryArchive, logger=None) -> None: logger = logger if logger is not None else get_logger(__name__) - super().normalize(logger) + super().normalize(archive, logger) - # Do nothing if section_run is not present - if not self.entry_archive.run: + # Do nothing if run section is not present + if not archive.run: return - if not self.entry_archive.workflow2: - self.entry_archive.workflow2 = self._resolve_workflow() + if not archive.workflow2: + archive.workflow2 = self._resolve_workflow(archive) diff --git a/tests/test_simulationworkflownormalizer.py b/tests/test_simulationworkflownormalizer.py index 32729f0..9733d21 100644 --- a/tests/test_simulationworkflownormalizer.py +++ b/tests/test_simulationworkflownormalizer.py @@ -46,7 +46,7 @@ def test_resolve_workflow_from_program_name( ): run = Run(program=Program(name=program_name)) entry_archive.run.append(run) - SimulationWorkflowNormalizer(entry_archive).normalize(get_logger(__name__)) + SimulationWorkflowNormalizer().normalize(entry_archive, get_logger(__name__)) assert isinstance(entry_archive.workflow2, workflow_class) @@ -58,5 +58,5 @@ def test_resolve_workflow_from_calculation( ): run = Run(calculation=[Calculation() for _ in range(n_calculations)]) entry_archive.run.append(run) - SimulationWorkflowNormalizer(entry_archive).normalize(get_logger(__name__)) + SimulationWorkflowNormalizer().normalize(entry_archive, get_logger(__name__)) assert isinstance(entry_archive.workflow2, workflow_class)