Skip to content

Commit fc6d57b

Browse files
authored
Merge pull request #18 from FAIRmat-NFDI/update-to-nuw-0.2.0
custom entry to ELNFileManager, custom workflow update for v0.2.0
2 parents 145fb13 + ecfb840 commit fc6d57b

8 files changed

Lines changed: 1135 additions & 1165 deletions

File tree

docs/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ Let's also add the drag and drop upload with the MD data to our dataset. First,
436436
with open(os.path.join('<path to PIDs>', 'PIDs.json')) as f:
437437
pids_dict = json.load(f)
438438

439-
md_upload_id = pids_dict.get('upload_ids').get('md')
439+
md_upload_id = pids_dict.get('upload_ids').get('md-workflow')
440440
metadata_new = {'upload_name': f'Test Upload - MD-equilibration', 'datasets': dataset_id}
441441
edit_upload_metadata(md_upload_id, url='test', upload_metadata=metadata_new)
442442
```

docs/assets/Custom_ELN_Entries.zip

-1.17 KB
Binary file not shown.

docs/assets/ELNFileManager.webm

3.54 MB
Binary file not shown.

docs/assets/Generate_Workflow_Yaml.ipynb

Lines changed: 1079 additions & 1074 deletions
Large diffs are not rendered by default.

docs/core.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ This example data has been pre-uploaded and published on NOMAD. Go to the [examp
101101

102102
Create a workspace folder for this tutorial, e.g., `workspace_nomad_tutorial_workflows/`, and then move the downloaded zip to this folder. We suggest also creating sub-folders `Part-1`-`Part-4` for organizational purposes.
103103

104-
Now go to the [Test NOMAD Deployment](https://nomad-lab.eu/prod/v1/test/gui/search/entries){:target="\_blank"}.
104+
**Now go to the [Test NOMAD Deployment](https://nomad-lab.eu/prod/v1/test/gui/search/entries){:target="\_blank"}.**
105105

106106
!!! warning "Attention"
107107

@@ -147,6 +147,10 @@ We will need both the `upload_id` and the `entry_id` for this entry later. Copy
147147
}
148148
```
149149

150+
!!! warning "Attention"
151+
152+
The JSON format requires double quotations!
153+
150154
Production Simulation:
151155

152156
<video width="100%" controls>

docs/custom.md

Lines changed: 28 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
## 🎯 What You Will Learn
44

55
- How to store data that is **not supported by existing NOMAD parsers**
6-
- How to define a custom **YAML schema**
76
- How to use the **NOMAD ELN (Electronic Lab Notebook)** interface
8-
- How to connect these custom entries into a workflow graph
7+
- How to annotate and reference files as part of a workflow
8+
- How to connect entries into a workflow graph
99

1010
---
1111

@@ -79,87 +79,36 @@ Uploading this yaml to the test deployment results in an entry with the overview
7979
</label>
8080
</div>
8181

82-
## Customizing the schema
83-
84-
To document our simulation setup workflow, we need to reference files within our ELN entry. For standardization and search capabilities, it is best practice to use existing classes in the MetaInfo. However, NOMAD also allows users to customize the schema to their own specific needs. Let's create our own schema to store annotated files within an ELN.
85-
86-
!!! warning "Attention"
87-
Understanding the details of the customized schema below is beyond the scope of this tutorial, and is not necessarily the adviced route for the most robust customization. The important take away is that you can in principal create you own schema. In this case we have done so to enable storage of annotated files.
88-
89-
Create a file `ELNFiles.archive.yaml` with the following contents:
90-
91-
<h4><code>ELNFiles.archive.yaml</code></h4>
92-
```yaml
93-
definitions: # Use the defintions section to create your schema
94-
name: 'ELN-Annotated-File-List'
95-
sections:
96-
AnnotatedFile: # A subsection for storing an annotated file
97-
m_annotations:
98-
eln:
99-
overview: True # Displays this quantity in the overview page of the entry
100-
quantities:
101-
file: # a quantity for storing the actualy file reference
102-
type: str
103-
description: single workflow files
104-
m_annotations:
105-
browser:
106-
adaptor: RawFileAdaptor # Allows to navigate to files in the data browser
107-
eln:
108-
component: FileEditQuantity # Allows editing with the GUI
109-
description: # a quantity for storing the annotation
110-
type: str
111-
description: describe the file
112-
m_annotations:
113-
eln:
114-
component: StringEditQuantity # Allows editing within the GUI
115-
ELNAnnotatedFiles: # Define a subsection for storing files
116-
base_sections:
117-
- 'nomad.datamodel.metainfo.eln.ElnBaseSection' # inherits from the basic ELN class
118-
- 'nomad.datamodel.data.EntryData' # necessary when a class will be the root of our archive
119-
m_annotations:
120-
eln:
121-
hide: ['lab_id'] # hides the lab_id quantity that we will not use
122-
sub_sections:
123-
Files:
124-
repeats: True # makes the subsection repeating (i.e., a list)
125-
section: '#/AnnotatedFile' # this subsection will include the quantities defined within the `AnnotedFile` class defined above
126-
```
127-
128-
The section `AnnotationFile` contains 2 quantities `file` and `description` for storing a file reference and annotation, respectively. The section `ELNAnnotatedFiles` extends the most basic ELN implementation (`ElnBaseSection`) with a repeating subsection of type `AnnotatedFile`. In this way, our ELN will be able to store a list of annotated files.
129-
130-
??? tip "More on custom schemas"
131-
132-
The YAML approach is a quick and dirty way to customize your NOMAD entries.
133-
To disincentivise the proliferation of _ad-hoc_ schemas and remain FAIR, YAML sections or quantities only have partial support.
134-
Seamless integration of new quantities happens when schemas are organized in **plugins** (python packages) and installed in NOMAD during deployment.
135-
See [NOMAD Docs > How to write a YAML schema package](https://nomad-lab.eu/prod/v1/test/docs/howto/customization/basics.html){:target="_blank"} for more details about defining custom schemas in this way.
82+
## The `ELNFileManager`
13683

137-
The more robust and powerful approach for creating custom schemas is to create a *schema plugin* (see [NOMAD Docs > How to get started with plugins](https://nomad-lab.eu/prod/v1/test/docs/howto/plugins/plugins.html){:target="_blank"}).
84+
`ELNFileManager` is a built-in schema for referencing and annotating files within an ELN entry. You can create an `ELNFileManager` either from the GUI or via the YAML approach, in the same ways as described above.
13885

139-
Useful resources for plugin developers are the [Plugin Template](https://github.com/FAIRmat-NFDI/nomad-plugin-template) and the [NOMAD Distro Template](https://github.com/FAIRmat-NFDI/nomad-distro-template).
140-
141-
We can now use these definitions to create an entry file for the step of creating the force field file (as illustrated in the image above):
86+
We can now use these definitions to create an entry file for the step of creating the force field, and link to the output force field file from this step in the workflow:
14287

14388
<h4><code>create_force_field.archive.yaml</code></h4>
14489
```yaml
14590
data:
146-
m_def: '../upload/raw/Custom_ELN_Entries/ELNFiles.archive.yaml#ELNAnnotatedFiles'
91+
m_def: 'nomad.datamodel.metainfo.eln.ElnFileManager'
14792
name: 'Create force field'
14893
description: 'The force field is defined for input to the MD simulation engine.'
14994
Files:
15095
- file: 'Custom_ELN_Entries/water.top'
15196
description: 'The force field file for simulation input.'
15297
```
15398

154-
Here we define the data section using our `ELNFiles.archive.yaml` schema. The given path is a relative path assuming that we will upload these 2 files (i.e., `ELNFiles.archive.yaml` and `create_force_field.archive.yaml`) within the same upload with a root folder called `Custom_ELN_Entries`.
99+
Uploading to NOMAD should result in the following entry display:
100+
101+
<video width="100%" controls>
102+
<source src="../assets/ELNFileManager.webm" alt="" type="video/mp4">
103+
</video>
155104

156105
You can now create analogous files `create_box.archive.yaml`, `insert_water.archive.yaml`, `workflow_parameters.archive.yaml`, `workflow_scripts.archive.yaml`:
157106

158107
??? success "`create_box.archive.yaml`"
159108

160109
```yaml
161110
data:
162-
m_def: '../upload/raw/Custom_ELN_Entries/ELNFiles.archive.yaml#ELNAnnotatedFiles'
111+
m_def: 'nomad.datamodel.metainfo.eln.ElnFileManager'
163112
name: 'Create box'
164113
description: 'The initial simulation box is created.'
165114
Files:
@@ -171,7 +120,7 @@ You can now create analogous files `create_box.archive.yaml`, `insert_water.arch
171120

172121
```yaml
173122
data:
174-
m_def: '../upload/raw/Custom_ELN_Entries/ELNFiles.archive.yaml#ELNAnnotatedFiles'
123+
m_def: 'nomad.datamodel.metainfo.eln.ElnFileManager'
175124
name: 'Insert water'
176125
description: 'Water is inserted into the simulation box, creating the structure file for simulation input.'
177126
Files:
@@ -192,7 +141,7 @@ You can now create analogous files `create_box.archive.yaml`, `insert_water.arch
192141

193142
```yaml
194143
data:
195-
m_def: '../upload/raw/Custom_ELN_Entries/ELNFiles.archive.yaml#ELNAnnotatedFiles'
144+
m_def: 'nomad.datamodel.metainfo.eln.ElnFileManager'
196145
name: 'Workflow Scripts'
197146
description: 'All the scripts run during setup of the MD simulation.'
198147
Files:
@@ -202,9 +151,22 @@ You can now create analogous files `create_box.archive.yaml`, `insert_water.arch
202151
description: 'Creates the appropriate force field files for the simulation engine.'
203152
```
204153

154+
## Customizing the schema
155+
156+
For standardization and search capabilities, it is best practice to use existing classes in the MetaInfo. However, NOMAD also allows users to customize the schema to their own specific needs. For example, you can customize one of the existing ELN schemas by adding specific sections and quantities relevant for your use case.
157+
158+
Customization of schemas is beyond the scope of the present tutorial, however, the tip box below will direct you to further resources if you are interested in learning more.
159+
160+
??? tip "Customizing the schema"
161+
Schema customization can be achieved via 2 approaches:
162+
163+
1. By including a `YAML`-based schema alongside your `YAML` entry file: This is a quick and dirty way to customize your NOMAD entries, and only provides partial support in terms of, e.g., search capabilities. See [NOMAD Docs > How to write a YAML schema package](https://nomad-lab.eu/prod/v1/test/docs/howto/customization/basics.html){:target="_blank"}.
164+
165+
2. By creating a *schema plugin*: This more robust and powerful approach integrates your new schema into NOMAD via python class definitions See [NOMAD Docs > How to get started with plugins](https://nomad-lab.eu/prod/v1/test/docs/howto/plugins/plugins.html){:target="_blank"}. The following tools are available to assist in plugin creation and development: [Plugin Template](https://github.com/FAIRmat-NFDI/nomad-plugin-template); [NOMAD Distro Template](https://github.com/FAIRmat-NFDI/nomad-distro-template).
166+
205167
## Creating a custom workflow in NOMAD
206168

207-
NOMAD allows users to connect entries into a workflow, i.e., a directed graph structure. This is achieved using the same parsing functionality as demonstrated with the custom schemas above. In this case, we simply populate the `workflow2` section instead of the `data` section. When uploaded to NOMAD, a new _workflow_ entry will be created, with references to each of the workflow tasks, and also an interactive workflow graph for easy navigation of the entire workflow. Learn more about the [archive file structure](https://nomad-lab.eu/prod/v1/test/docs/explanation/data.html#archive-files-a-shared-entry-structure) in the official NOMAD documentation.
169+
NOMAD allows users to connect entries into a workflow, i.e., a directed graph structure. This is achieved using the same parsing functionality as demonstrated with the custom schemas above. In this case, we simply populate the `workflow2` section instead of the `data` section. When uploaded to NOMAD, a new _workflow_ entry will be created, with references to each of the workflow tasks, and also an interactive workflow graph for easy navigation of the entire workflow.
208170

209171
Let's construct this workflow yaml piece by piece, starting with the section definition and global inputs/outputs:
210172

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pip install uv
107107
Install the latest pypi version of the plugin using pip:
108108

109109
```bash
110-
uv pip install "nomad-utility-workflows[vis]>=0.1.0"
110+
uv pip install "nomad-utility-workflows[vis]>=0.2.0"
111111
```
112112

113113
Install `python-dotenv` package.

docs/workflows.md

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ import networkx as nx
186186
from nomad_utility_workflows.utils.workflows import (
187187
NodeAttributes,
188188
NodeAttributesUniverse,
189-
build_nomad_workflow,
189+
NomadWorkflow
190190
nodes_to_graph,
191191
)
192192
```
@@ -316,34 +316,21 @@ gv.d3(
316316
</label>
317317
</div>
318318

319-
## Generate the workflow yaml
319+
## Filling the workflow graph with default connections
320320

321-
First designate the full path and filename for your YAML and a name for your workflow:
321+
Before creating the workflow YAML, `nomad-utility-workflows` will fill the workflow graph generated in the previous step with certain "default" connections (i.e., inputs and outputs) based on the types of nodes in the workflow. This happens automatically upon instantiation of the `NomadWorkflow` class:
322322

323323
```python
324-
workflow_metadata = {
325-
'destination_filename': './project_workflow.archive.yaml',
326-
'workflow_name': 'NOMAD Tutorial Workflows Project',
327-
}
328-
```
329-
330-
The workflow name will show up on top of the workflow graph visualization on the overview page of the workflow entry that we will create.
331-
332-
We can now use the generated graph to create the workflow YAML using the `build_nomad_workflow()` function:
333-
334-
```
335-
workflow_graph_output = build_nomad_workflow(
336-
workflow_metadata=workflow_metadata,
337-
workflow_graph=nx.DiGraph(workflow_graph_input),
338-
write_to_yaml=True,
324+
nomad_workflow = NomadWorkflow(
325+
workflow_graph=workflow_graph_input,
339326
)
340327
```
341328

342-
Another workflow graph is returned by this function:
329+
Here, we create a `NomadWorkflow` using the workflow graph generated in the previous step. The resulting "filled" workflow graph can be visualized with:
343330

344-
```python
331+
```javascript
345332
gv.d3(
346-
workflow_graph_output,
333+
nomad_workflow.workflow_graph,
347334
node_label_data_source='name',
348335
edge_label_data_source='name',
349336
zoom_factor=1.5,
@@ -358,7 +345,19 @@ gv.d3(
358345
</label>
359346
</div>
360347

361-
We see that our output graph looks signficantly different than the input. That's because `nomad-utility-workflow` is automatically adding some default inputs/outputs to ensure the proper node connections within the workflow visualizer. For nodes without an `entry_type`, these default connections work by simply adding inputs/outputs that point to the mainfile of one of the nodes connected by an edge in the graph.
348+
We see that our output graph looks signficantly different than the input. The additional inputs/outputs ensure the proper node connections within NOMAD's workflow visualizer. For nodes without an `entry_type`, these default connections work by simply adding inputs/outputs that point to the mainfile of one of the nodes connected by an edge in the graph.
349+
350+
## Generating the workflow yaml
351+
352+
Finally, we can add some workflow metadata to the [`NomadWorkflow`](../reference/workflows.md#nomadworkflow) (i.e., the filename of the output yaml and the name of the workflow) and generate the workflow YAML file with the class method [`build_workflow_yaml()`](../reference/workflows.md#build_workflow_yaml):
353+
354+
```python
355+
nomad_workflow.destination_filename = './project_workflow.archive.yaml'
356+
nomad_workflow.name = 'NOMAD Tutorial Workflows Project'
357+
nomad_workflow.build_workflow_yaml()
358+
```
359+
360+
The workflow name will show up on top of the workflow graph visualization on the overview page of the workflow entry that we will create.
362361

363362
??? success "example `project_workflow.archive.yaml`"
364363

0 commit comments

Comments
 (0)