Skip to content

Commit

Permalink
Fix pyplots
Browse files Browse the repository at this point in the history
  • Loading branch information
ndaelman committed Nov 22, 2024
1 parent 297f1f5 commit 5dfff90
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
7 changes: 3 additions & 4 deletions src/nomad_parser_plugin_boss/parsers/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def parse(
slice_parser.parse()

def get_column_unique(column_name: str) -> list[float]:
return list({x.get(column_name) for x in slice_parser.results.get('row', [])})
return np.sort(list({x.get(column_name) for x in slice_parser.results.get('row', [])}))

def get_column(column_name: str) -> list[float]:
return [x.get(column_name) for x in slice_parser.results.get('row', [])]
Expand All @@ -67,14 +67,13 @@ def reshaping(target: list, dim_1: int, dim_2: int) -> np.ndarray:

x_1, x_2 = get_column_unique('x_1'), get_column_unique('x_2')

archive.m_add_sub_section(EntryArchive.data,
archive.m_add_sub_section(EntryArchive.data,
PotentialEnergySurfaceFit(
parameter_1_name='parameter_1_name',
parameter_1_values=x_1,
parameter_2_name='parameter_2_name',
parameter_2_values=x_2,
energy_values=reshaping(get_column('mu'), len(x_1), len(x_2)),
energy_variance=reshaping(get_column('nu'), len(x_1), len(x_2)),
)
)
)

32 changes: 12 additions & 20 deletions src/nomad_parser_plugin_boss/schema_packages/schema_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@
)

import numpy as np
import plotly.graph_objs as go

from nomad.config import config
from nomad.datamodel.data import Schema
from nomad.datamodel.metainfo.annotations import ELNAnnotation, ELNComponentEnum
from nomad.datamodel.metainfo.plot import PlotSection, PlotlyFigure
from nomad.metainfo import Quantity, SchemaPackage

configuration = config.get_plugin_entry_point(
'nomad_parser_plugin_boss.schema_packages:schema_package_entry_point'
)

m_package = SchemaPackage()


Expand Down Expand Up @@ -69,22 +66,17 @@ def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:

self.figures.append(
PlotlyFigure(
name='Potential Energy Surface',
data=[
dict(
x=self.parameter_values[0],
y=self.parameter_values[1],
z=self.energy_values,
type='contour',
labels=dict(
x=self.parameter_1_name,
y=self.parameter_2_name,
z='Energy',
),
),
],
)
)
label='Potential Energy Surface',
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(),
),
),
except Exception as e:
pass

Expand Down

0 comments on commit 5dfff90

Please sign in to comment.