Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add openbis connection #587

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion aiidalab_widgets_base/elns.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,39 @@ def _observe_node(self, _=None):
)
info = q.all(flat=True)[0]
except IndexError:
info = {}
structures, _ = self.get_all_structures_and_geoopts(self.node)
info = structures[-1].base.extras.all["eln"]

self.eln.set_sample_config(**info)

def get_all_structures_and_geoopts(self, node):
"""Get all atomistic models that led to the one used in the simulation"""
current_node = node
all_structures = []
all_geoopts = []

while current_node is not None:
if isinstance(current_node, orm.StructureData):
all_structures.append(current_node)
current_node = current_node.creator

elif isinstance(current_node, orm.CalcJobNode):
current_node = current_node.caller

elif isinstance(current_node, orm.CalcFunctionNode):
current_node = current_node.inputs.source_structure

elif isinstance(current_node, orm.WorkChainNode):
if "GeoOpt" in current_node.label:
all_geoopts.append(current_node)
current_node = current_node.inputs.structure
elif "ORBITALS" in current_node.label or "STM" in current_node.label:
current_node = current_node.inputs.structure
else:
current_node = current_node.caller

return all_structures, all_geoopts

def send_to_eln(self, _=None):
if self.eln and self.eln.is_connected:
self.message.value = f"\u29d7 Sending data to {self.eln.eln_instance}..."
Expand Down
7 changes: 7 additions & 0 deletions aiidalab_widgets_base/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@
"parameter_name": "structure_uuid",
"description": "Optimize atomic positions and/or unit cell employing Quantum ESPRESSO. Quantum ESPRESSO is preferable for small structures with no cell dimensions larger than 15 Å. Additionally, you can choose to compute electronic properties of the material such as band structure and density of states.",
},
{
"name": "surfaces",
"calculation_type": "geo_opt",
"notebook": "submit_geometry_optimization.ipynb",
"parameter_name": "structure_uuid",
"description": "Optimize atomic positions and/or unit cell employing CP2K. CP2K is preferable for large structures with cell dimensions larger than 15 Å.",
},
{
"name": "aiidalab-lsmo",
"calculation_type": "geo_opt",
Expand Down
89 changes: 75 additions & 14 deletions notebooks/eln_import.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@
"from aiidalab_widgets_base import AiidaNodeViewWidget, OpenAiidaNodeInAppWidget, ElnImportWidget\n",
"import urllib.parse as urlparse\n",
"from aiidalab_widgets_base import viewer\n",
"from traitlets import dlink"
"from traitlets import dlink\n",
"\n",
"import json\n",
"from pyld import jsonld\n",
"\n",
"import sys\n",
"import os"
]
},
{
Expand All @@ -55,29 +61,82 @@
"metadata": {},
"outputs": [],
"source": [
"#sys.path.append(os.path.dirname(\"/home/jovyan/aiida-openbis/Notebooks/Metadata_Schemas_LinkML/\"))\n",
"# from materialMLinfo import Molecule, slots\n",
"# def extract_molecule_data_with_linkml(molecule_jsonld):\n",
"# expanded = jsonld.expand(molecule_jsonld)\n",
"# molecule_data = {}\n",
"# for obj in jsonld_object:\n",
"# if '@type' in obj and str(Molecule.class_class_uri) in obj['@type']:\n",
"# molecule_data['name'] = obj.get(str(slots.name.uri), [None])[0]['@value']\n",
"# molecule_data['smiles'] = obj.get(str(slots.smiles.uri), [None])[0]['@value']\n",
"# return molecule_data"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5",
"metadata": {},
"outputs": [],
"source": [
"# Extract data from the converted JSON-LD\n",
"def extract_molecule_data(jsonld_object, context):\n",
" expanded = jsonld.expand(molecule_jsonld)\n",
" compacted = jsonld.compact(expanded, context)\n",
" return {\"name\": compacted[\"name\"], \"smiles\": compacted[\"smiles\"]}\n",
"\n",
"def read_json(filepath: str) -> dict:\n",
" return json.load(open(filepath, \"r\"))\n",
"\n",
"url = urlparse.urlsplit(jupyter_notebook_url)\n",
"parsed_url = urlparse.parse_qs(url.query)\n",
"params = {key:value[0] for key, value in parsed_url.items()}\n",
"eln_widget = ElnImportWidget(**params)"
"molecule_jsonld = json.loads(params[\"molecule_info\"])\n",
"\n",
"molecule_info_valid = False\n",
"\n",
"jsonld_context_filename = os.path.join(\n",
" os.sep, \n",
" \"home\", \n",
" \"jovyan\", \n",
" \"aiida-openbis\", \n",
" \"Notebooks\", \n",
" \"Metadata_Schemas_LinkML\",\n",
" \"materialMLinfoContext.jsonld\"\n",
")\n",
"\n",
"\n",
"aiida_context = read_json(jsonld_context_filename)\n",
"\n",
"try:\n",
" molecule_data = extract_molecule_data(molecule_jsonld, aiida_context)\n",
" params[\"molecule_info\"] = json.dumps(molecule_data)\n",
" eln_widget = ElnImportWidget(path_to_root=\"../../\", **params)\n",
" molecule_info_valid = True\n",
"except ValueError as e:\n",
" print(e)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5",
"id": "6",
"metadata": {},
"outputs": [],
"source": [
"object_displayed = AiidaNodeViewWidget()\n",
"open_in_app = OpenAiidaNodeInAppWidget()\n",
"if molecule_info_valid:\n",
" object_displayed = AiidaNodeViewWidget()\n",
" open_in_app = OpenAiidaNodeInAppWidget(path_to_root=\"../../\")\n",
"\n",
"_ = dlink((eln_widget, 'node'), (object_displayed, 'node'))\n",
"_ = dlink((eln_widget, 'node'), (open_in_app, 'node'))"
" _ = dlink((eln_widget, 'node'), (object_displayed, 'node'))\n",
" _ = dlink((eln_widget, 'node'), (open_in_app, 'node'))"
]
},
{
"cell_type": "markdown",
"id": "6",
"id": "7",
"metadata": {},
"source": [
"## Selected object:"
Expand All @@ -86,17 +145,18 @@
{
"cell_type": "code",
"execution_count": null,
"id": "7",
"id": "8",
"metadata": {},
"outputs": [],
"source": [
"display(object_displayed)\n",
"display(eln_widget)"
"if molecule_info_valid:\n",
" display(object_displayed)\n",
" display(eln_widget)"
]
},
{
"cell_type": "markdown",
"id": "8",
"id": "9",
"metadata": {},
"source": [
"## What's next?"
Expand All @@ -105,11 +165,12 @@
{
"cell_type": "code",
"execution_count": null,
"id": "9",
"id": "10",
"metadata": {},
"outputs": [],
"source": [
"display(open_in_app)"
"if molecule_info_valid:\n",
" display(open_in_app)"
]
}
],
Expand Down
Loading