Skip to content

Commit

Permalink
Provide categorized example structures. (#1019)
Browse files Browse the repository at this point in the history
[x] Provide categorized example structures, and only the respective examples are shown when the button is clicked. 
[x] The example catalog is extensible by the plugins.
[x] Remove the "Primitive cell" from everywhere, as done below, as we should always ONLY provide the primitive cell):
[x] For gold, replace the current one with its primitive cell.
[x] For Cobalt, remove it and replace with Nickel FCC.
  • Loading branch information
superstar54 authored Dec 23, 2024
1 parent d4c495e commit 802bca8
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 27 deletions.
8 changes: 4 additions & 4 deletions docs/source/tutorials/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Advanced Tutorial
Overview
--------

Calculations probing more intricate properties often require additional computational resources. In this tutorial, we will again compute a band structure, but this time, we will do it for a magnetic system, namely bulk cobalt. As such, will set up our environment to submit to a remote machine capable of handling the calculation.
Calculations probing more intricate properties often require additional computational resources. In this tutorial, we will again compute a band structure, but this time, we will do it for a magnetic system, namely bulk nickel. As such, will set up our environment to submit to a remote machine capable of handling the calculation.

Start
-----

.. admonition:: Goal

To submit a band structure calculation for magnetic cobalt on a remote machine.
To submit a band structure calculation for magnetic nickel on a remote machine.

To start, go ahead and :doc:`launch </installation/launch>` the app, then follow the steps below.

Expand All @@ -23,12 +23,12 @@ To start, go ahead and :doc:`launch </installation/launch>` the app, then follow
Step 1: Select a structure
**************************

Select `Cobalt (hcp)` from the `From examples` tab and click `Confirm`.
Select `Nickel (hcp)` from the `From examples` tab and click `Confirm`.

Step 2: Configure the workflow
******************************

Select `Full geometry` to relax the structure. As we are looking at magnetic cobalt, we also want to turn on `Magnetism`. Go ahead and do so now.
Select `Full geometry` to relax the structure. As we are looking at magnetic nickel, we also want to turn on `Magnetism`. Go ahead and do so now.

Select both `Band structure` and `Projected density of states` as the properties of interest.

Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ aiidalab_qe.app.static.styles = *.css
aiidalab_qe.app.static.templates = *.jinja
aiidalab_qe.app.structure.examples = *
aiidalab_qe.plugins.xas = pseudo_toc.yaml
aiidalab_qe.plugins.xps.structure_examples = *
aiidalab_qe.plugins.xas.structure_examples = *

[options.entry_points]
aiidalab_qe.properties =
Expand Down
30 changes: 19 additions & 11 deletions src/aiidalab_qe/app/structure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
LazyLoadedStructureBrowser,
)
from aiidalab_qe.common.infobox import InAppGuide
from aiidalab_qe.common.widgets import CategorizedStructureExamplesWidget
from aiidalab_widgets_base import (
BasicCellEditor,
BasicStructureEditor,
StructureExamplesWidget,
StructureManagerWidget,
StructureUploadWidget,
WizardAppWidgetStep,
Expand All @@ -28,16 +28,13 @@
# StructureExamplesWidget.
file_path = pathlib.Path(__file__).parent
Examples = [
("Bulk silicon (primitive cell)", file_path / "examples" / "Si.cif"),
("Silicon oxide (alpha quartz)", file_path / "examples" / "SiO2.cif"),
("Diamond (primitive cell)", file_path / "examples" / "Diamond.cif"),
("Gallium arsenide (primitive cell)", file_path / "examples" / "GaAs.cif"),
("Gold (conventional cell)", file_path / "examples" / "Au.cif"),
("Cobalt (primitive cell)", file_path / "examples" / "Co.cif"),
("Lithium carbonate", file_path / "examples" / "Li2CO3.cif"),
("Phenylacetylene molecule", file_path / "examples" / "Phenylacetylene.xyz"),
("ETFA molecule", file_path / "examples" / "ETFA.xyz"),
("Bulk silicon", file_path / "examples" / "Si.cif"),
("Diamond", file_path / "examples" / "Diamond.cif"),
("Gallium arsenide", file_path / "examples" / "GaAs.cif"),
("Gold", file_path / "examples" / "Au.cif"),
("Nickel", file_path / "examples" / "Ni.cif"),
("LiCoO2", file_path / "examples" / "LiCoO2.cif"),
("Silicon oxide (alpha quartz)", file_path / "examples" / "SiO2.cif"),
]


Expand Down Expand Up @@ -73,11 +70,22 @@ def render(self):
if self.rendered:
return

examples_by_category = {"Simple crystals": Examples}
plugin_structure_examples = {
item["title"]: item["structures"]
for item in get_entry_items(
"aiidalab_qe.properties", "structure_examples"
).values()
}
examples_by_category.update(plugin_structure_examples)

importers = [
StructureUploadWidget(title="Upload file"),
LazyLoadedOptimade(title="OPTIMADE"),
LazyLoadedStructureBrowser(title="AiiDA database"),
StructureExamplesWidget(title="From Examples", examples=Examples),
CategorizedStructureExamplesWidget(
title="From Examples", examples_by_category=examples_by_category
),
]

plugin_importers = get_entry_items("aiidalab_qe.properties", "importer")
Expand Down
19 changes: 8 additions & 11 deletions src/aiidalab_qe/app/structure/examples/Au.cif
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
data_image0
_chemical_formula_structural Au4
_chemical_formula_sum "Au4"
_cell_length_a 4.078
_cell_length_b 4.078
_cell_length_c 4.078
_cell_angle_alpha 90
_cell_angle_beta 90
_cell_angle_gamma 90
_chemical_formula_structural Au
_chemical_formula_sum "Au1"
_cell_length_a 2.885
_cell_length_b 2.885
_cell_length_c 2.885
_cell_angle_alpha 60
_cell_angle_beta 60
_cell_angle_gamma 60

_space_group_name_H-M_alt "P 1"
_space_group_IT_number 1
Expand All @@ -24,6 +24,3 @@ loop_
_atom_site_fract_z
_atom_site_occupancy
Au Au1 1.0 0.00000 0.00000 0.00000 1.0000
Au Au2 1.0 0.00000 0.50000 0.50000 1.0000
Au Au3 1.0 0.50000 0.00000 0.50000 1.0000
Au Au4 1.0 0.50000 0.50000 0.00000 1.0000
26 changes: 26 additions & 0 deletions src/aiidalab_qe/app/structure/examples/Ni.cif
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
data_image0
_chemical_formula_structural Ni
_chemical_formula_sum "Ni1"
_cell_length_a 2.48902
_cell_length_b 2.48902
_cell_length_c 2.48902
_cell_angle_alpha 60
_cell_angle_beta 60
_cell_angle_gamma 60

_space_group_name_H-M_alt "P 1"
_space_group_IT_number 1

loop_
_space_group_symop_operation_xyz
'x, y, z'

loop_
_atom_site_type_symbol
_atom_site_label
_atom_site_symmetry_multiplicity
_atom_site_fract_x
_atom_site_fract_y
_atom_site_fract_z
_atom_site_occupancy
Ni Ni1 1.0 0.00000 0.00000 0.00000 1.0000
28 changes: 27 additions & 1 deletion src/aiidalab_qe/common/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from aiida.orm import CalcJobNode, load_code, load_node
from aiida.orm import Data as orm_Data
from aiidalab_widgets_base import ComputationalResourcesWidget
from aiidalab_widgets_base import ComputationalResourcesWidget, StructureExamplesWidget
from aiidalab_widgets_base.utils import (
StatusHTML,
list_to_string_range,
Expand Down Expand Up @@ -1065,3 +1065,29 @@ def _get_widget(self):
HubbardStructureData,
),
)


class CategorizedStructureExamplesWidget(StructureExamplesWidget):
"""Extended widget to provide categorized example structures."""

def __init__(self, examples_by_category, title="", **kwargs):
self.examples_by_category = examples_by_category
self._category_buttons = ipw.ToggleButtons(
options=list(examples_by_category.keys()),
description="Category:",
)
self._category_buttons.observe(self._on_category_change, names="value")

# Initialize with the first category
initial_category = next(iter(examples_by_category.keys()))
super().__init__(
examples=examples_by_category[initial_category], title=title, **kwargs
)

self.children = [self._category_buttons, *list(self.children)]

def _on_category_change(self, change):
"""Update the dropdown when the category changes."""
new_category = change["new"]
new_examples = self.examples_by_category.get(new_category, [])
self._select_structure.options = self.get_example_structures(new_examples)
2 changes: 2 additions & 0 deletions src/aiidalab_qe/plugins/xas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .resources import XasResourceSettingsModel, XasResourceSettingsPanel
from .result import XasResultsModel, XasResultsPanel
from .setting import XasConfigurationSettingsPanel
from .structure_examples import structure_examples
from .workchain import workchain_and_builder

PSEUDO_TOC = yaml.safe_load(
Expand All @@ -25,6 +26,7 @@ class XasPluginOutline(PluginOutline):

xas = {
"outline": XasPluginOutline,
"structure_examples": structure_examples,
"configuration": {
"panel": XasConfigurationSettingsPanel,
"model": XasConfigurationSettingsModel,
Expand Down
10 changes: 10 additions & 0 deletions src/aiidalab_qe/plugins/xas/structure_examples/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pathlib

file_path = pathlib.Path(__file__).parent

structure_examples = {
"title": "XAS examples",
"structures": [
("Lithium carbonate", file_path / "Li2CO3.cif"),
],
}
2 changes: 2 additions & 0 deletions src/aiidalab_qe/plugins/xps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .model import XpsConfigurationSettingsModel
from .result import XpsResultsModel, XpsResultsPanel
from .setting import XpsConfigurationSettingsPanel
from .structure_examples import structure_examples
from .workchain import workchain_and_builder


Expand All @@ -12,6 +13,7 @@ class XpsPluginOutline(PluginOutline):

xps = {
"outline": XpsPluginOutline,
"structure_examples": structure_examples,
"configuration": {
"panel": XpsConfigurationSettingsPanel,
"model": XpsConfigurationSettingsModel,
Expand Down
10 changes: 10 additions & 0 deletions src/aiidalab_qe/plugins/xps/structure_examples/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pathlib

file_path = pathlib.Path(__file__).parent
structure_examples = {
"title": "XPS examples",
"structures": [
("Phenylacetylene molecule", file_path / "Phenylacetylene.xyz"),
("ETFA molecule", file_path / "ETFA.xyz"),
],
}

0 comments on commit 802bca8

Please sign in to comment.