Skip to content

Commit

Permalink
Add method and results
Browse files Browse the repository at this point in the history
  • Loading branch information
ladinesa committed Jan 28, 2025
1 parent 4e35a66 commit 9232147
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 18 deletions.
36 changes: 34 additions & 2 deletions src/nomad_simulations/schema_packages/workflow/general.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
from nomad.datamodel import EntryArchive
from nomad.datamodel import ArchiveSection, EntryArchive
from nomad.datamodel.metainfo.workflow import Link, Task, Workflow
from nomad.metainfo.util import MSubSectionList
from nomad.metainfo import SubSection
from structlog.stdlib import BoundLogger

INCORRECT_N_TASKS = 'Incorrect number of tasks found.'


class SimulationWorkflowMethod(ArchiveSection):
"""
Base class for simulation workflow method sub-section definition.
"""

pass


class SimulationWorkflowResults(ArchiveSection):
"""
Base class for simulation workflow results sub-section definition.
"""

pass


class SimulationWorkflow(Workflow):
"""
Base class for simulation workflows.
"""

method = SubSection(sub_section=SimulationWorkflowMethod.m_def)

results = SubSection(sub_section=SimulationWorkflowResults.m_def)

def normalize(self, archive: EntryArchive, logger: BoundLogger):
"""
Generate tasks from the archive data outputs.
Expand Down Expand Up @@ -69,3 +89,15 @@ def normalize(self, archive: EntryArchive, logger: BoundLogger):
if not self.outputs:
# assign parent outputs as workflow outputs
self.outputs.extend(parent_outputs)

if not self.method:
self.method = SimulationWorkflowMethod()

if not self.results:
self.results = SimulationWorkflowResults()

# set method as inputs
self.inputs.append(Link(name='Input method', section=self.method))

# set results as outputs
self.outputs.append(Link(name='Ouput results', section=self.results))
143 changes: 127 additions & 16 deletions src/nomad_simulations/schema_packages/workflow/geometry_optimization.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,106 @@
from nomad.datamodel import EntryArchive
from nomad.datamodel.metainfo.workflow import Link, Task
from nomad.metainfo import MEnum, Quantity
from nomad.metainfo.util import MSubSectionList
from structlog.stdlib import BoundLogger

from .general import SimulationWorkflow
from nomad_simulations.schema_packages.outputs import Outputs

from .general import (
SimulationWorkflow,
SimulationWorkflowMethod,
SimulationWorkflowResults,
)


class GeometryOptimizationMethod(SimulationWorkflowMethod):
optimization_type = Quantity(
type=MEnum('static', 'atomic', 'cell_shape', 'cell_volume'),
shape=[],
description="""
The type of geometry optimization, which denotes what is being optimized.
Allowed values are:
| Type | Description |
| ---------------------- | ----------------------------------------- |
| `"static"` | no optimization |
| `"atomic"` | the atomic coordinates alone are updated |
| `"cell_volume"` | `"atomic"` + cell lattice paramters are updated isotropically |
| `"cell_shape"` | `"cell_volume"` but without the isotropic constraint: all cell parameters are updated |
""",
)

optimization_method = Quantity(
type=str,
shape=[],
description="""
The method used for geometry optimization. Some known possible values are:
`"steepest_descent"`, `"conjugant_gradient"`, `"low_memory_broyden_fletcher_goldfarb_shanno"`.
""",
)

convergence_tolerance_energy_difference = Quantity(
type=float,
shape=[],
unit='joule',
description="""
The input energy difference tolerance criterion.
""",
)

convergence_tolerance_force_maximum = Quantity(
type=float,
shape=[],
unit='newton',
description="""
The input maximum net force tolerance criterion.
""",
)

convergence_tolerance_stress_maximum = Quantity(
type=float,
shape=[],
unit='pascal',
description="""
The input maximum stress tolerance criterion.
""",
)

convergence_tolerance_displacement_maximum = Quantity(
type=float,
shape=[],
unit='meter',
description="""
The input maximum displacement tolerance criterion.
""",
)

optimization_steps_maximum = Quantity(
type=int,
shape=[],
description="""
Maximum number of optimization steps.
""",
)

sampling_frequency = Quantity(
type=int,
shape=[],
description="""
The number of optimization steps between sucessive outputs.
""",
)


class GeometryOptimizationResults(SimulationWorkflowResults):
pass


class GeometryOptimization(SimulationWorkflow):
Expand All @@ -14,20 +112,33 @@ def normalize(self, archive: EntryArchive, logger: BoundLogger) -> None:
"""
Specify the inputs and outputs of the tasks as the model system.
"""

# set up first method and results before we call base normalizer
if not self.method:
self.method = GeometryOptimizationMethod()

if not self.results:
self.results = GeometryOptimizationResults()

super().normalize(archive, logger)

def to_system_links(task: Task) -> None:
task.inputs = [
Link(name='Input system', section=link.section.model_system_ref)
for link in task.inputs
if link.section and link.section.model_system_ref
]
task.outputs = [
Link(name='Output system', section=link.section.model_system_ref)
for link in task.inputs
if link.section and link.section.model_system_ref
]

to_system_links(self)
for task in self.tasks:
to_system_links(task)
def extend_links(task: Task) -> None:
def get_system_links(links: MSubSectionList, name: str) -> list[Link]:
return [
Link(name=name, section=link.section.model_system_ref)
for link in links
if isinstance(link.section, Outputs)
and link.section.model_system_ref
]

task.inputs.extend(get_system_links(self.inputs, 'Input system'))
task.outputs.extend(get_system_links(self.outputs, 'Output system'))

if not self.name:
self.name = 'Geometry Optimization'

extend_links(self)
for n, task in enumerate(self.tasks):
if not task.name:
task.name = f'Step {n}'
extend_links(task)

1 comment on commit 9232147

@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.py1902189%13–15, 201–204, 228, 283–284, 352–353, 355, 537, 549–550, 611–615, 630–634, 641
   basis_set.py2402888%8–9, 122–133, 172–185, 208, 391–395, 417–418, 462–465, 584, 615, 617
   general.py85891%4–7, 123, 143, 253–254, 264
   model_method.py2697871%10–12, 171–174, 177–184, 276–277, 297, 318–339, 355–381, 384–401, 587, 780, 791, 833–840, 878, 897, 977, 1034, 1109, 1223
   model_system.py3483789%45–51, 235, 254, 258, 261, 264, 290, 376–377, 454–455, 472–473, 686–689, 736–743, 917–918, 1140–1144, 1150–1151, 1159–1160, 1165, 1188
   numerical_settings.py2596176%12–14, 217, 219–220, 223–226, 230–231, 238–241, 250–253, 257–260, 262–265, 270–273, 279–282, 469–496, 571, 606–609, 633, 636, 681, 683–686, 690, 694, 741, 745–766, 821–822, 889
   outputs.py1201092%8–9, 253–256, 296–299, 324, 326, 363, 382
   physical_property.py102793%20–22, 202, 331–333
   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.py1232580%9–11, 232–265, 278, 285, 321–322, 325, 372–373, 378
   energies.py42979%7–9, 36, 57, 82, 103, 119, 134
   fermi_surface.py17476%7–9, 40
   forces.py22673%7–9, 36, 56, 79
   greens_function.py991387%7–9, 210–211, 214, 235–236, 239, 260–261, 264, 400
   hopping_matrix.py29583%7–9, 58, 94
   permittivity.py48883%7–9, 97–105
   spectral_profile.py26012851%9–11, 57–60, 95–98, 199–300, 356–368, 393–396, 416, 421–424, 466–502, 526, 573–576, 592–593, 598–604
   thermodynamics.py752764%7–9, 35, 56, 72, 81, 90, 101, 110, 137, 147, 157, 172–174, 177, 193, 213–215, 218, 234, 254–256, 259
src/nomad_simulations/schema_packages/utils
   utils.py791680%8–11, 65–74, 83–84, 89, 92, 169–170
src/nomad_simulations/schema_packages/workflow
   __init__.py440%1–4
   general.py39390%1–103
   geometry_optimization.py37370%1–144
   gw.py19190%1–37
   single_point.py22220%1–40
TOTAL271663577% 

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

Please sign in to comment.