diff --git a/pyproject.toml b/pyproject.toml index f36fd0f..902ebf8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,5 +70,5 @@ line-ending = "auto" [tool.setuptools.packages.find] include = ["simulationworkflownormalizer*"] -[tool.setuptools.package-data] -simulationworkflownormalizer = ["*/nomad_plugin.yaml"] +[project.entry-points.'nomad.plugin'] +simulationworkflownormalizer = "simulationworkflownormalizer:simulationworkflow_normalizer_entry_point" diff --git a/simulationworkflownormalizer/__init__.py b/simulationworkflownormalizer/__init__.py index 2595e4e..618f610 100644 --- a/simulationworkflownormalizer/__init__.py +++ b/simulationworkflownormalizer/__init__.py @@ -15,4 +15,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .normalizer import SimulationWorkflowNormalizer +from nomad.config.models.plugins import NormalizerEntryPoint + + +class SimulationWorkflowNormalizerEntryPoint(NormalizerEntryPoint): + def load(self): + import simulationworkflownormalizer + from .normalizer import SimulationWorkflowNormalizer + + simulationworkflownormalizer.SimulationWorkflowNormalizer = SimulationWorkflowNormalizer + + return SimulationWorkflowNormalizer(**self.dict()) + + +simulationworkflow_normalizer_entry_point = SimulationWorkflowNormalizerEntryPoint( + name='SimulationWorkflowNormalizer', + description='Normalizer for the simulation workflow data.', +) + diff --git a/simulationworkflownormalizer/normalizer.py b/simulationworkflownormalizer/normalizer.py index fcab4af..72f32d3 100644 --- a/simulationworkflownormalizer/normalizer.py +++ b/simulationworkflownormalizer/normalizer.py @@ -33,8 +33,8 @@ class SimulationWorkflowNormalizer(Normalizer): This normalizer produces information specific to a simulation workflow. """ - def __init__(self): - super().__init__() + def __init__(self, **kwargs): + super().__init__(**kwargs) self._elastic_programs = ['elastic'] self._phonon_programs = ['phonopy'] self._molecular_dynamics_programs = ['lammps'] diff --git a/tests/test_simulationworkflownormalizer.py b/tests/test_simulationworkflownormalizer.py index 9733d21..7363382 100644 --- a/tests/test_simulationworkflownormalizer.py +++ b/tests/test_simulationworkflownormalizer.py @@ -20,9 +20,9 @@ from nomad.utils import get_logger from nomad.datamodel import EntryArchive, EntryMetadata +from nomad.normalizing import normalizers from runschema.run import Run, Program from runschema.calculation import Calculation -from simulationworkflownormalizer import SimulationWorkflowNormalizer from simulationworkflowschema import ( Elastic, MolecularDynamics, @@ -31,6 +31,12 @@ GeometryOptimization, ) +simulationworkflownormalizer = None +for normalizer in normalizers: + if normalizer.__name__ == 'SimulationWorkflowNormalizer': + simulationworkflownormalizer = normalizer + +assert simulationworkflownormalizer is not None @pytest.fixture() def entry_archive(): @@ -46,7 +52,8 @@ def test_resolve_workflow_from_program_name( ): run = Run(program=Program(name=program_name)) entry_archive.run.append(run) - SimulationWorkflowNormalizer().normalize(entry_archive, get_logger(__name__)) + + simulationworkflownormalizer(entry_archive).normalize() assert isinstance(entry_archive.workflow2, workflow_class) @@ -58,5 +65,5 @@ def test_resolve_workflow_from_calculation( ): run = Run(calculation=[Calculation() for _ in range(n_calculations)]) entry_archive.run.append(run) - SimulationWorkflowNormalizer().normalize(entry_archive, get_logger(__name__)) + simulationworkflownormalizer(entry_archive).normalize() assert isinstance(entry_archive.workflow2, workflow_class)