Skip to content

Commit

Permalink
Adding script for plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
JosePizarro3 committed Jun 28, 2024
1 parent 774cc73 commit c44c238
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions plots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import graphviz as gr
import numpy as np

from nomad.datamodel.data import ArchiveSection
from nomad.datamodel.metainfo.basesections import Activity, Entity
from nomad.metainfo import Quantity, SubSection

from nomad_simulations.schema_packages.atoms_state import AtomsState, OrbitalsState
from nomad_simulations.schema_packages.general import (
Simulation,
Program,
BaseSimulation,
)


# class Program(Entity):
# name = Quantity(type=str)


# class Simulation(Activity):
# cpu1_start = Quantity(type=np.float64, unit='second')
# program = SubSection(Program.m_def, repeat=False)


# simulation = Simulation()
# print(m_package)

# m_package.all_definitions.get('Program').quantities[0].type

nomad_simulations_classes = {
# 'BaseSimulation': BaseSimulation(),
'Simulation': Simulation(),
# 'Program': Program(),
}


def format_quantities(class_def):
quantities = class_def.all_quantities
formatted_quantities = []
for name, quantity in quantities.items():
# q_type = quantity.type.__name__
# q_unit = quantity.unit if quantity.unit else ''
# formatted_quantities.append(f"{name}: {q_type}, {q_unit}")
formatted_quantities.append(f'{name}')
return '\\n'.join(formatted_quantities)


def generate_inheritance_tree(class_def, graph: gr.Digraph, added_edges: set):
prev_name = ''
for i, inh in enumerate(class_def.inherited_sections):
node_properties = {
'name': inh.name,
'shape': 'box',
'fontname': 'Titillium-Web',
'style': 'filled',
}
if inh.name in nomad_simulations_classes.keys():
node_properties.update({'fontcolor': 'white', 'fillcolor': '#0097a7'})
else:
node_properties.update({'fontcolor': 'black', 'fillcolor': 'white'})
graph.node(**node_properties)

if i > 0:
if inh.name == 'ArchiveSection':
prev_name = inh.name
continue
edge = (inh.name, prev_name)
if edge not in added_edges:
graph.edge(inh.name, prev_name, arrowhead='empty')
added_edges.add(edge)

# sub-sections
for subsection in class_def.sub_sections:
graph.edge()

prev_name = inh.name
return graph


for name, section in nomad_simulations_classes.items():
graph = gr.Digraph(
name=f'{name.lower()}-uml-diagram', comment=f'{name} UML diagram', format='pdf'
)
graph.attr(rankdir='BT')
# Set to keep track of added edges to avoid duplication
added_edges = set()
graph = generate_inheritance_tree(
class_def=section.m_def, graph=graph, added_edges=added_edges
)
if name == 'Simulation':
graph.edge(name, 'BaseSimulation', arrowhead='empty')
print(graph)
graph.render(directory='umlgraphs').replace('\\', '/')

1 comment on commit c44c238

@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__.py14286%53–55
   atoms_state.py1902189%32–34, 220–223, 247, 302–303, 371–372, 374, 556, 568–569, 630–634, 649–653, 660
   general.py75791%30–31, 99, 163, 273–274, 284
   model_method.py2607770%29–31, 158–161, 164–171, 262–263, 283, 304–323, 339–365, 368–385, 737, 748, 790–797, 843, 862, 942, 1001, 1074, 1186
   model_system.py2612292%45–47, 514–517, 565–572, 746–747, 969–973, 979–980, 988–989, 994, 1017
   numerical_settings.py2636575%32–34, 166, 236, 238–239, 242–245, 249–250, 257–260, 269–272, 276–279, 281–284, 289–292, 298–301, 472–499, 574, 609–612, 636, 639, 684, 686–689, 693, 697, 744, 748–769, 824–825, 892, 901–903, 906
   outputs.py91891%26–27, 204–207, 247–250, 275, 277
   physical_property.py94496%38–40, 219
   variables.py641183%27–29, 115, 138, 158–159, 162, 184, 207, 227
src/nomad_simulations/schema_packages/properties
   band_gap.py51590%27–29, 154–155
   band_structure.py1112280%28–30, 250–283, 296, 303, 339–340, 343
   energies.py26581%26–28, 58, 86
   fermi_surface.py17476%26–28, 59
   hopping_matrix.py29583%26–28, 76, 111
   permittivity.py48883%26–28, 116–124
   spectral_profile.py25612452%28–30, 76–79, 114–117, 218–319, 375–387, 412–415, 435, 440–443, 485–521, 545, 592–595, 611–612, 617–623
src/nomad_simulations/schema_packages/utils
   utils.py661183%75–84, 93–94, 99, 102
TOTAL193940579% 

Tests Skipped Failures Errors Time
299 0 💤 0 ❌ 0 🔥 2.321s ⏱️

Please sign in to comment.