Skip to content

Commit

Permalink
Add plotly visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
ndaelman committed Jan 28, 2025
1 parent 95d403a commit 66f234b
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions src/nomad_simulations/schema_packages/properties/electronic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import numpy as np
from nomad.config import config
from nomad.metainfo import Quantity, SchemaPackage, Section, SubSection
from nomad.datamodel.metainfo.plot import PlotSection, PlotlyFigure
from nomad_simulations.schema_packages.general import ModelBaseSection
import plotly.graph_objects as go
import plotly.express as px

configuration = config.get_plugin_entry_point(
'nomad_simulations.schema_packages:nomad_simulations_plugin'
Expand All @@ -15,8 +18,10 @@
class Spin(ModelBaseSection):
pass

class DOS(ModelBaseSection):

class DOS(PlotSection, ModelBaseSection):
"""Collection of Electronic Density of States"""

m_def = Section()

class SemanticDOS(ModelBaseSection):
Expand All @@ -28,39 +33,64 @@ class SpinResolvedDOS(ModelBaseSection):

spin = Quantity(
type=Spin,
description="Spin channel",
description='Spin channel',
)

values = Quantity(
type=np.float64,
shape=['*'],
description="Actual DOS values",
description='Actual DOS values',
) # ? add renormalized_values

def name_from_section(self, section):
def name_from_section(self, section) -> str:
return self.spin.name_from_section()

label = Quantity(
type=str,
description="Label of the DOS",
default='total',
description='Label of the DOS',
) # TODO: el n m

energies = Quantity(
type=np.float64,
unit='J',
shape=['*'],
description="Energy values at which the DOS is evaluated",
description='Energy values at which the DOS is evaluated',
)

spin_channels = SubSection(subsection=SpinResolvedDOS.m_def, repeats=True)

def name_from_section(self, section):
def name_from_section(self, section) -> str:
if section.label:
return section.label
else:
return 'total'

collections = SubSection(subsection=SemanticDOS.m_def, repeats=True)

def generate_plot(self) -> go.Figure:
fig = go.Figure()
for collection in self.collections:
for spin_channel in collection.spin_channels:
fig.add_trace(
px.line(
x=collection.energies,
y=spin_channel.values,
name=f'{collection.name_from_section()} {spin_channel.spin.name_from_section()}',
)
)
return fig

def normalize(self, archive, logger):
super().normalize(archive, logger)
# this does not check if the plot was already stored
self.figures.append(
PlotlyFigure(
label='Full DOS',
index=0,
figure=self.generate_plot().to_plotly_json(),
)
)


m_package.__init_metainfo__()

1 comment on commit 66f234b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/nomad_simulations
   __init__.py4250%3–4
   _version.py11282%5–6
src/nomad_simulations/schema_packages
   __init__.py15287%39–41
   atoms_state.py1892189%12–14, 200–203, 227, 282–283, 350–351, 353, 530, 542–543, 603–607, 622–626, 633
   basis_set.py2372789%8–9, 119–130, 169–182, 382–386, 408–409, 453–456, 575, 606, 608
   general.py931089%4–7, 83, 87–89, 312–313, 323
   model_method.py2507271%9–11, 155–158, 161–168, 257–258, 278, 299–320, 336–362, 365–382, 567, 760, 771, 813–820
   model_system.py3453789%44–50, 224, 243, 247, 250, 253, 279, 365–366, 440–441, 458–459, 671–674, 721–728, 902–903, 1122–1126, 1132–1133, 1141–1142, 1147, 1170
   numerical_settings.py2556076%12–14, 214, 216–217, 220–223, 227–228, 235–238, 247–250, 254–257, 259–262, 267–270, 276–279, 466–493, 568, 603–606, 630, 633, 678, 680–683, 687, 691, 738, 742–763, 818–819
   outputs.py117992%8–9, 249–252, 292–295, 320, 322, 375
   physical_property.py101793%19–21, 201, 329–331
   variables.py861286%8–10, 98, 121, 145, 167, 189, 211, 233, 256, 276
src/nomad_simulations/schema_packages/properties
   band_gap.py51590%8–10, 135–136
   band_structure.py1172380%9–11, 229–262, 275, 282, 318–319, 366–367
   electronic.py38380%1–96
   energies.py30390%7–9
   fermi_surface.py17476%7–9, 40
   forces.py16381%7–9
   greens_function.py931089%7–9, 210–211, 232–233, 254–255, 391
   hopping_matrix.py25388%7–9
   permittivity.py48883%7–9, 97–105
   spectral_profile.py25812751%9–11, 57–60, 95–98, 199–300, 356–368, 393–396, 416, 421–424, 466–502, 570–573, 589–590, 595–601
   thermodynamics.py451273%7–9, 142–144, 177–179, 212–214
src/nomad_simulations/schema_packages/utils
   utils.py791680%8–11, 65–74, 83–84, 89, 92, 169–170
TOTAL253151380% 

Tests Skipped Failures Errors Time
402 0 💤 0 ❌ 0 🔥 6.611s ⏱️

Please sign in to comment.