Skip to content

Commit

Permalink
Merge pull request #19 from nomad-coe/entry-point
Browse files Browse the repository at this point in the history
Entry point
  • Loading branch information
ladinesa authored Aug 19, 2024
2 parents fd32d79 + a38ffc6 commit 2cc33cd
Show file tree
Hide file tree
Showing 9 changed files with 447 additions and 681 deletions.
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ authors = [{ name = "The NOMAD Authors" }]
license = { text = "Apache-2.0" }
dependencies = [
"nomad-lab>=1.2.0",
"nomad-schema-plugin-run@git+https://github.com/nomad-coe/nomad-schema-plugin-run.git@develop",
"nomad-schema-plugin-run@git+https://github.com/nomad-coe/nomad-schema-plugin-run.git@f5d348fec5cef89e76021b42e48ff49b1832034b",
]

[project.urls]
Expand Down Expand Up @@ -70,5 +70,5 @@ line-ending = "auto"
[tool.setuptools.packages.find]
include = ["simulationworkflowschema*"]

[tool.setuptools.package-data]
simulationworkflowschema = ["*/nomad_plugin.yaml"]
[project.entry-points.'nomad.plugin']
simulationworkflowschema = "simulationworkflowschema:simulationworkflow_schema_entry_point"
147 changes: 99 additions & 48 deletions simulationworkflowschema/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,103 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from .general import (
SimulationWorkflow,
SimulationWorkflowMethod,
SimulationWorkflowResults,
ParallelSimulation,
SerialSimulation,
BeyondDFT,
DFTMethod,
ElectronicStructureOutputs,
MagneticOutputs,
import importlib

from nomad.config.models.plugins import SchemaPackageEntryPoint


__all__ = [
'SimulationWorkflow',
'SimulationWorkflowMethod',
'SimulationWorkflowResults',
'ParallelSimulation',
'SerialSimulation',
'BeyondDFT',
'DFTMethod',
'ElectronicStructureOutputs',
'MagneticOutputs',
'SinglePoint',
'SinglePointMethod',
'SinglePointResults',
'GeometryOptimization',
'GeometryOptimizationMethod',
'GeometryOptimizationResults',
'MolecularDynamics',
'MolecularDynamicsMethod',
'MolecularDynamicsResults',
'Phonon',
'PhononMethod',
'PhononResults',
'EquationOfState',
'EquationOfStateMethod',
'EquationOfStateResults',
'ChemicalReaction',
'ChemicalReactionMethod',
'ChemicalReactionResults',
'Elastic',
'ElasticMethod',
'ElasticResults',
'FirstPrinciplesPlusTB',
'FirstPrinciplesPlusTBMethod',
'FirstPrinciplesPlusTBResults',
'DFTPlusGW',
'DFTPlusGWMethod',
'DFTPlusGWResults',
'XS',
'XSMethod',
'XSResults',
'DFTPlusTBPlusDMFT',
'DFTPlusTBPlusDMFTMethod',
'DFTPlusTBPlusDMFTResults',
'DMFTPlusMaxEnt',
'DMFTPlusMaxEntMethod',
'DMFTPlusMaxEntResults',
'PhotonPolarization',
'PhotonPolarizationMethod',
'PhotonPolarizationResults',
'Thermodynamics',
'ThermodynamicsMethod',
'ThermodynamicsResults',
]


def load_modules():
sub_modules = [
'general',
'single_point',
'geometry_optimization',
'molecular_dynamics',
'phonon',
'equation_of_state',
'chemical_reaction',
'elastic',
'tb',
'gw',
'xs',
'dmft',
'max_ent',
'photon_polarization',
'thermodynamics',
]
import simulationworkflowschema

for name in sub_modules:
sub_module = importlib.import_module(f'simulationworkflowschema.{name}')
for method in sub_module.__dict__:
if method in __all__:
setattr(simulationworkflowschema, method, sub_module.__dict__[method])


class SimulationWorkflowSchemaEntryPoint(SchemaPackageEntryPoint):
def load(self):
load_modules()

from .general import m_package

return m_package


simulationworkflow_schema_entry_point = SimulationWorkflowSchemaEntryPoint(
name='SimulationWorkflowSchema',
description='Schema for the nomad simulation workflows.',
)
from .single_point import SinglePoint, SinglePointMethod, SinglePointResults
from .geometry_optimization import (
GeometryOptimization,
GeometryOptimizationMethod,
GeometryOptimizationResults,
)
from .molecular_dynamics import (
MolecularDynamics,
MolecularDynamicsMethod,
MolecularDynamicsResults,
)
from .phonon import Phonon, PhononMethod, PhononResults
from .equation_of_state import (
EquationOfState,
EquationOfStateMethod,
EquationOfStateResults,
)
from .chemical_reaction import (
ChemicalReaction,
ChemicalReactionMethod,
ChemicalReactionResults,
)
from .elastic import Elastic, ElasticMethod, ElasticResults
from .tb import (
FirstPrinciplesPlusTB,
FirstPrinciplesPlusTBMethod,
FirstPrinciplesPlusTBResults,
)
from .gw import DFTPlusGW, DFTPlusGWMethod, DFTPlusGWResults
from .xs import XS, XSMethod, XSResults
from .dmft import DFTPlusTBPlusDMFT, DFTPlusTBPlusDMFTMethod, DFTPlusTBPlusDMFTResults
from .max_ent import DMFTPlusMaxEnt, DMFTPlusMaxEntMethod, DMFTPlusMaxEntResults
from .photon_polarization import (
PhotonPolarization,
PhotonPolarizationMethod,
PhotonPolarizationResults,
)
from .thermodynamics import Thermodynamics, ThermodynamicsMethod, ThermodynamicsResults
8 changes: 7 additions & 1 deletion simulationworkflowschema/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import numpy as np

from nomad.datamodel.data import ArchiveSection
from nomad.metainfo import SubSection, Section, Quantity, Reference
from nomad.metainfo import SubSection, Section, Quantity, Reference, Package
from nomad.datamodel.metainfo.common import FastAccess
from nomad.datamodel.metainfo.workflow import Workflow, Link, Task, TaskReference
from runschema.method import (
Expand All @@ -41,6 +41,9 @@
)


m_package = Package()


def resolve_difference(values):
delta_values = None

Expand Down Expand Up @@ -497,3 +500,6 @@ class MagneticOutputs(SimulationWorkflowResults):
Reference to the magnetic susceptibility tensors.
""",
)


m_package.__init_metainfo__()
22 changes: 15 additions & 7 deletions simulationworkflowschema/molecular_dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,11 @@ def normalize(self, archive, logger):
if self._rg_results:
self.type = self._rg_results.get('type')
self.label = self._rg_results.get('label')
self.atomsgroup_ref = self._rg_results.get('atomsgroup_ref')
# TODO Fix this assignment fails with TypeError
try:
self.atomsgroup_ref = self._rg_results.get('atomsgroup_ref')
except Exception:
pass
self.n_frames = self._rg_results.get('n_frames')
self.times = self._rg_results.get('times')
self.value = self._rg_results.get('value')
Expand Down Expand Up @@ -1245,11 +1249,11 @@ def normalize(self, archive, logger):
else []
)
sec_diffusion.error_type = 'Pearson correlation coefficient'
sec_diffusion.errors = (
self._msd_results['error_diffusion_constant'][i_type]
if self._msd_results.get('error_diffusion_constant') is not None
else []
)
if self._msd_results.get('error_diffusion_constant') is not None:
errors = self._msd_results['error_diffusion_constant'][i_type]
sec_diffusion.errors = (
list(errors) if isinstance(errors, (list, np.ndarray)) else [errors]
)


class MolecularDynamicsResults(ThermodynamicsResults):
Expand Down Expand Up @@ -1394,7 +1398,11 @@ def normalize(self, archive, logger):
sec_rg_values = sec_rgs_calc.m_create(
RadiusOfGyrationValuesCalculation
)
sec_rg_values.atomsgroup_ref = rg.get('atomsgroup_ref')
# TODO Fix this assignment fails with TypeError
try:
sec_rg_values.atomsgroup_ref = rg.get('atomsgroup_ref')
except Exception:
pass
sec_rg_values.label = rg.get('label')
sec_rg_values.value = rg.get('value')[sys_ind]

Expand Down
24 changes: 16 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,33 @@
RadialDistributionFunctionValues,
)
from simulationworkflowschema.equation_of_state import EOSFit
from simulationworkflowschema import (
from simulationworkflowschema.molecular_dynamics import (
MolecularDynamics,
MolecularDynamicsMethod,
MolecularDynamicsResults,
SinglePoint,
)
from simulationworkflowschema.single_point import SinglePoint
from simulationworkflowschema.geometry_optimization import (
GeometryOptimization,
GeometryOptimizationMethod,
Elastic,
ElasticResults,
MolecularDynamics,
)
from simulationworkflowschema.elastic import Elastic, ElasticResults
from simulationworkflowschema.equation_of_state import (
EquationOfState,
EquationOfStateResults,
DFTPlusGWMethod,
DFTPlusGW as GWworkflow,
)
from simulationworkflowschema.gw import DFTPlusGWMethod, DFTPlusGW as GWworkflow
from simulationworkflowschema.dmft import (
DFTPlusTBPlusDMFTMethod,
DFTPlusTBPlusDMFT as DMFTworkflow,
)
from simulationworkflowschema.photon_polarization import (
PhotonPolarization,
PhotonPolarizationMethod,
PhotonPolarizationResults,
XS as XSworkflow,
)
from simulationworkflowschema.xs import XS as XSworkflow
from simulationworkflowschema.max_ent import (
DMFTPlusMaxEntMethod,
DMFTPlusMaxEnt as MaxEntworkflow,
)
Expand Down
Loading

0 comments on commit 2cc33cd

Please sign in to comment.