Skip to content

Commit

Permalink
Add entry point
Browse files Browse the repository at this point in the history
  • Loading branch information
ladinesa committed Aug 20, 2024
1 parent 78eb29c commit 3b532b5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
19 changes: 18 additions & 1 deletion simulationworkflownormalizer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
)

4 changes: 2 additions & 2 deletions simulationworkflownormalizer/normalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
13 changes: 10 additions & 3 deletions tests/test_simulationworkflownormalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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():
Expand All @@ -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)


Expand All @@ -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)

0 comments on commit 3b532b5

Please sign in to comment.