generated from FAIRmat-NFDI/nomad-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ndaelman
committed
Dec 12, 2024
1 parent
9697de0
commit 7a0202f
Showing
2 changed files
with
35 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 26 additions & 58 deletions
84
src/nomad_parser_plugin_boss/schema_packages/schema_package.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,52 @@ | ||
from typing import ( | ||
TYPE_CHECKING, | ||
) | ||
|
||
if TYPE_CHECKING: | ||
from nomad.datamodel.datamodel import ( | ||
EntryArchive, | ||
) | ||
from structlog.stdlib import ( | ||
BoundLogger, | ||
) | ||
|
||
import numpy as np | ||
import plotly.graph_objs as go | ||
|
||
from nomad.datamodel.data import Schema | ||
from nomad.datamodel.metainfo.annotations import ELNAnnotation, ELNComponentEnum | ||
from nomad.datamodel.metainfo.plot import PlotlyFigure, PlotSection | ||
from nomad.datamodel.hdf5 import HDF5Dataset | ||
from nomad.datamodel.metainfo.annotations import H5WebAnnotation, ELNAnnotation, ELNComponentEnum | ||
from nomad.metainfo import Quantity, SchemaPackage, Section | ||
|
||
m_package = SchemaPackage() | ||
|
||
|
||
class PotentialEnergySurfaceFit(PlotSection, Schema): | ||
m_def = Section() | ||
class PotentialEnergySurfaceFit(Schema): | ||
m_def = Section( | ||
a_h5web=H5WebAnnotation( | ||
title='Potential Energy Surface Fit', | ||
axes=['parameter_2', 'parameter_1'], | ||
signal='energy_values', | ||
# auxialary_singals=['energy_variance'], | ||
), | ||
) | ||
|
||
parameter_1_name = Quantity( | ||
parameter_names = Quantity( | ||
type=str, | ||
shape=['*'], | ||
a_eln=ELNAnnotation(component=ELNComponentEnum.StringEditQuantity), | ||
) | ||
|
||
parameter_1_values = Quantity( | ||
type=np.float64, | ||
shape=['*'], | ||
parameter_1 = Quantity( | ||
type=HDF5Dataset, | ||
# unit='', | ||
shape=[], | ||
) # ! TODO use `PhysicalProperty` | ||
|
||
parameter_2_name = Quantity( | ||
type=str, | ||
a_eln=ELNAnnotation(component=ELNComponentEnum.StringEditQuantity), | ||
) | ||
|
||
parameter_2_values = Quantity( | ||
type=np.float64, | ||
shape=['*'], | ||
parameter_2 = Quantity( | ||
type=HDF5Dataset, | ||
# unit='', | ||
shape=[], | ||
) # ! TODO use `PhysicalProperty` | ||
|
||
energy_values = Quantity( | ||
type=np.float64, | ||
type=HDF5Dataset, | ||
unit='eV', # ? | ||
shape=['*', '*'], | ||
shape=[], | ||
) # ! TODO use `PhysicalProperty` | ||
|
||
energy_variance = Quantity( | ||
type=np.float64, | ||
type=HDF5Dataset, | ||
unit='eV^2', # ? | ||
shape=['*', '*'], | ||
shape=[], | ||
) # ! TODO use `PhysicalProperty` | ||
|
||
def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None: | ||
super(Schema, self).normalize(archive, logger) | ||
|
||
try: | ||
if self.energy_values.shape != (len(self.parameter_1_values), len(self.parameter_2_values)): | ||
raise ValueError('Energy values shape does not match parameter values') # ? | ||
|
||
figure = go.Figure( | ||
data=go.Contour( | ||
x=self.parameter_1_values, | ||
y=self.parameter_2_values, | ||
z=self.energy_values.magnitude, | ||
colorbar=dict(title='Energy'), | ||
) | ||
).to_plotly_json() | ||
figure['config'] = {'staticPlot': True} | ||
|
||
self.figures.append( | ||
PlotlyFigure( | ||
label='Potential Energy Surface', | ||
figure=figure, | ||
), | ||
) | ||
except Exception as e: | ||
print(e) | ||
|
||
m_package.__init_metainfo__() |