Skip to content

Commit

Permalink
Apply HDF5 viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
ndaelman committed Dec 12, 2024
1 parent 9697de0 commit 7a0202f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 68 deletions.
19 changes: 9 additions & 10 deletions src/nomad_parser_plugin_boss/parsers/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,22 @@ def parse(
iter_no = 40
res = BOResults.from_file(mainfile, os.path.join(os.path.dirname(mainfile), 'boss.out'))
pp = PPMain(
res, # or archive.m_context.raw_file for writing
res,
pp_models=True,
pp_iters=[iter_no],
pp_model_slice=[1, 2, 50],
)
X = build_query_points(pp.settings, res.select("x_glmin", iter_no)) # ! TODO change to local minima
x_1, x_2 = np.unique(X[:, 0]), np.unique(X[:, 1])
mu, var = res.reconstruct_model(40).predict(X)

x_1, x_2 = np.unique(X[:, 0]), np.unique(X[:, 1])
mu = mu.reshape(len(x_1), len(x_2))
var = var.reshape(len(x_1), len(x_2))

archive.data = PotentialEnergySurfaceFit(
parameter_1_name='parameter_1_name',
parameter_1_values=x_1,
parameter_2_name='parameter_2_name',
parameter_2_values=x_2, #! add check
energy_values=mu,
energy_variance=np.sqrt(var),
)
archive.data = PotentialEnergySurfaceFit()
archive.data.parameter_names=['x_1', 'x_2'] # !
archive.data.parameter_1=x_1
archive.data.parameter_2=x_2
archive.data.energy_values=mu
archive.data.energy_variance=np.sqrt(var)

84 changes: 26 additions & 58 deletions src/nomad_parser_plugin_boss/schema_packages/schema_package.py
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__()

0 comments on commit 7a0202f

Please sign in to comment.