diff --git a/Notebooks/Metadata_Schemas_LinkML/materialMLinfo.yaml b/Notebooks/Metadata_Schemas_LinkML/materialMLinfo.yaml
index addac793..236c0e72 100644
--- a/Notebooks/Metadata_Schemas_LinkML/materialMLinfo.yaml
+++ b/Notebooks/Metadata_Schemas_LinkML/materialMLinfo.yaml
@@ -103,7 +103,8 @@ classes:
openbis_code: AM
openbis_label: Atomistic Model
slots:
- - structure
+ - volume
+ - cell
- dimensionality
- atoms_positions
- periodic_boundary_conditions
@@ -1770,6 +1771,22 @@ types:
# slots are first-class entities in the metamodel
# declaring them here allows them to be reused elsewhere
slots:
+ cell:
+ description: Cell
+ range: object
+ multivalued: false
+ slot_uri:
+ annotations:
+ openbis_type: JSON
+ openbis_label: Cell
+ volume:
+ description: Volume
+ range: double
+ multivalued: false
+ slot_uri:
+ annotations:
+ openbis_type: REAL
+ openbis_label: Volume
filepath_executable:
description: Filepath executable
range: string
diff --git a/Notebooks/connection_to_openbis/.create_molecule-0.ipynb b/Notebooks/connection_to_openbis/.create_molecule-0.ipynb
new file mode 100644
index 00000000..3dd5f166
--- /dev/null
+++ b/Notebooks/connection_to_openbis/.create_molecule-0.ipynb
@@ -0,0 +1,240 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from IPython.display import display\n",
+ "import ipywidgets as ipw\n",
+ "import widgets\n",
+ "import utils\n",
+ "import os\n",
+ "import rdkit\n",
+ "from rdkit.Chem import AllChem, Draw, rdMolDescriptors\n",
+ "import io\n",
+ "from pathlib import Path"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "CONFIG = utils.read_json(\"config.json\")\n",
+ "CONFIG_ELN = utils.get_aiidalab_eln_config()\n",
+ "# CONFIG_ELN = utils.read_json(\"eln_config.json\")\n",
+ "OPENBIS_SESSION, SESSION_DATA = utils.connect_openbis(CONFIG_ELN[\"url\"], CONFIG_ELN[\"token\"])\n",
+ "\n",
+ "molecule_widgets = widgets.ObjectPropertiesWidgets(\"Molecule\")\n",
+ "\n",
+ "molecule_structure = ipw.Image(\n",
+ " value=utils.read_file(CONFIG[\"default_image_filepath\"]), format='jpg', \n",
+ " width='420px', height='450px', layout=ipw.Layout(border='solid 1px #cccccc')\n",
+ ")\n",
+ "\n",
+ "molecule_cdxml_file = ipw.FileUpload(multiple = False, accept = '.cdxml')\n",
+ "\n",
+ "molecule_support_files = ipw.FileUpload(multiple = True)\n",
+ "\n",
+ "increase_buttons_size = utils.HTML(data = ''.join(CONFIG[\"save_home_buttons_settings\"]))\n",
+ "create_button = utils.Button(\n",
+ " description = '', disabled = False, button_style = '', tooltip = 'Save', \n",
+ " icon = 'save', layout = ipw.Layout(width = '100px', height = '50px')\n",
+ ")\n",
+ "quit_button = utils.Button(\n",
+ " description = '', disabled = False, button_style = '', \n",
+ " tooltip = 'Main menu', icon = 'home', layout = ipw.Layout(width = '100px', height = '50px')\n",
+ ")\n",
+ "save_close_buttons_hbox = ipw.HBox([create_button, quit_button])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def close_notebook(b):\n",
+ " display(utils.Javascript(data = 'window.location.replace(\"home.ipynb\")'))\n",
+ "\n",
+ "def load_molecule_structure(change):\n",
+ " for filename in molecule_cdxml_file.value:\n",
+ " file_info = molecule_cdxml_file.value[filename]\n",
+ " utils.save_file(file_info['content'], \"structures/structure.cdxml\")\n",
+ " \n",
+ " cdxml_molecule = utils.read_file(\"structures/structure.cdxml\")\n",
+ " molecules = rdkit.Chem.MolsFromCDXML(cdxml_molecule)\n",
+ " \n",
+ " if len(molecules) == 1:\n",
+ " mol = molecules[0] # Get first molecule\n",
+ " mol_chemical_formula = rdMolDescriptors.CalcMolFormula(mol) # Sum Formula\n",
+ " mol_smiles = rdkit.Chem.MolToSmiles(mol) # Canonical Smiles\n",
+ " chem_mol = rdkit.Chem.MolFromSmiles(mol_smiles)\n",
+ " \n",
+ " if chem_mol is not None:\n",
+ " AllChem.Compute2DCoords(chem_mol) # Add coords to the atoms in the molecule\n",
+ " img = Draw.MolToImage(chem_mol)\n",
+ " buffer = io.BytesIO()\n",
+ " img.save(buffer, format=\"PNG\")\n",
+ " molecule_structure.value = buffer.getvalue()\n",
+ " img.save(\"structures/structure.png\")\n",
+ " else:\n",
+ " print(f\"Cannot generate molecule image.\")\n",
+ " \n",
+ " molecule_widgets.properties_widgets[\"sum_formula\"].value = mol_chemical_formula\n",
+ " molecule_widgets.properties_widgets[\"smiles\"].value = mol_smiles\n",
+ " \n",
+ " elif len(molecules) > 1:\n",
+ " print(f\"There are more than one molecule in the file: {filename}\") \n",
+ " else:\n",
+ " print(f\"There are no molecules in the file: {filename}\")\n",
+ " \n",
+ "def create_molecule_openbis(b):\n",
+ " object_properties = {}\n",
+ " for prop in CONFIG[\"objects\"][\"Molecule\"][\"properties\"]:\n",
+ " object_properties[prop] = molecule_widgets.properties_widgets[prop].value\n",
+ " \n",
+ " # Check if the molecule is already in openBIS\n",
+ " smiles_molecules_openbis = [molecule.props['smiles'] for molecule in utils.get_openbis_objects(OPENBIS_SESSION, type =\"MOLECULE\")]\n",
+ " \n",
+ " if object_properties[\"smiles\"] in smiles_molecules_openbis:\n",
+ " display(utils.Javascript(data = \"alert('Molecule is already in openBIS!')\"))\n",
+ " \n",
+ " if Path(\"structures/structure.png\").exists():\n",
+ " os.remove(\"structures/structure.png\")\n",
+ " \n",
+ " if Path(\"structures/structure.png\").exists():\n",
+ " os.remove(\"structures/structure.cdxml\")\n",
+ " else:\n",
+ " molecule_object = utils.create_openbis_object(\n",
+ " OPENBIS_SESSION, type=\"MOLECULE\", \n",
+ " collection=\"/MATERIALS/MOLECULES/MOLECULE_COLLECTION\", \n",
+ " props = object_properties\n",
+ " )\n",
+ " \n",
+ " # Send molecule image to openBIS\n",
+ " if Path(\"structures/structure.png\").exists():\n",
+ " # Upload cdxml\n",
+ " utils.create_openbis_dataset(OPENBIS_SESSION, type = \"ELN_PREVIEW\", object = molecule_object, file = \"structures/structure.png\")\n",
+ " os.remove(\"structures/structure.png\")\n",
+ " \n",
+ " if Path(\"structures/structure.png\").exists():\n",
+ " # Upload cdxml\n",
+ " utils.create_openbis_dataset(OPENBIS_SESSION, type = \"RAW_DATA\", object = molecule_object, file = \"structures/structure.cdxml\")\n",
+ " os.remove(\"structures/structure.cdxml\")\n",
+ " \n",
+ " # Additional support files\n",
+ " upload_datasets(molecule_object, molecule_support_files)\n",
+ " \n",
+ " display(utils.Javascript(data = \"alert('Upload successful!')\"))\n",
+ "\n",
+ "def upload_datasets(method_object, support_files_widget):\n",
+ " for filename in support_files_widget.value:\n",
+ " file_info = support_files_widget.value[filename]\n",
+ " utils.save_file(file_info['content'], filename)\n",
+ " utils.create_openbis_dataset(OPENBIS_SESSION, type = 'RAW_DATA', object = method_object, file = filename)\n",
+ " os.remove(filename)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Create molecule"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Upload CDXML file"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "display(molecule_structure)\n",
+ "display(molecule_cdxml_file)\n",
+ "molecule_cdxml_file.observe(load_molecule_structure, names = \"value\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Properties"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "display(molecule_widgets)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Support files"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "display(molecule_support_files)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Save results"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "display(save_close_buttons_hbox)\n",
+ "display(increase_buttons_size)\n",
+ "create_button.on_click(create_molecule_openbis)\n",
+ "quit_button.on_click(close_notebook)"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "base",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.9.13"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/Notebooks/connection_to_openbis/.create_sample-1.ipynb b/Notebooks/connection_to_openbis/.create_sample-1.ipynb
new file mode 100644
index 00000000..13486b10
--- /dev/null
+++ b/Notebooks/connection_to_openbis/.create_sample-1.ipynb
@@ -0,0 +1,251 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from IPython.display import display, clear_output\n",
+ "import utils\n",
+ "import widgets\n",
+ "import ipywidgets as ipw\n",
+ "import shutil\n",
+ "import json"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ " \n",
+ " "
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "CONFIG = utils.read_json(\"config.json\")\n",
+ "CONFIG_ELN = utils.get_aiidalab_eln_config()\n",
+ "# CONFIG_ELN = utils.read_json(\"eln_config.json\")\n",
+ "OPENBIS_SESSION, SESSION_DATA = utils.connect_openbis(CONFIG_ELN[\"url\"], CONFIG_ELN[\"token\"])\n",
+ "\n",
+ "slabs_options = [object_key for object_key, object_info in CONFIG[\"objects\"].items() if object_info[\"object_type\"] == \"slab\"]\n",
+ "slabs_options.insert(0, \"No material\")\n",
+ "material_selection_radio_button = utils.Radiobuttons(\n",
+ " description = '', options = slabs_options, \n",
+ " disabled = False, layout = ipw.Layout(width = '300px'), \n",
+ " style = {'description_width': \"100px\"}\n",
+ ")\n",
+ "\n",
+ "material_selector = widgets.MaterialSelectionWidget()\n",
+ "\n",
+ "sample_out_name_textbox = utils.Text(\n",
+ " description = \"Name\", disabled = False, layout = ipw.Layout(width = '400px'), \n",
+ " placeholder = f\"Write sample name here...\", style = {'description_width': \"110px\"}\n",
+ ")\n",
+ "increase_buttons_size = utils.HTML(data = ''.join(CONFIG[\"save_home_buttons_settings\"]))\n",
+ "create_button = utils.Button(\n",
+ " description = '', disabled = False, button_style = '', tooltip = 'Save', \n",
+ " icon = 'save', layout = ipw.Layout(width = '100px', height = '50px')\n",
+ ")\n",
+ "quit_button = utils.Button(\n",
+ " description = '', disabled = False, button_style = '', \n",
+ " tooltip = 'Main menu', icon = 'home', layout = ipw.Layout(width = '100px', height = '50px')\n",
+ ")\n",
+ "save_close_buttons_hbox = ipw.HBox([create_button, quit_button])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def close_notebook(b):\n",
+ " display(utils.Javascript(data = 'window.location.replace(\"home.ipynb\")'))\n",
+ " \n",
+ "# Function to create sample object inside openBIS using information selected in the app\n",
+ "def create_sample_action(b):\n",
+ " samples_names = [sample.props[\"$name\"] for sample in OPENBIS_SESSION.get_objects(type = \"SAMPLE\")]\n",
+ " if sample_out_name_textbox.value in samples_names:\n",
+ " display(utils.Javascript(data = f\"alert('{'Sample name already exists!'}')\"))\n",
+ " return\n",
+ " else:\n",
+ " sample_parents = [] if material_selector.dropdown.value == -1 else [material_selector.dropdown.value]\n",
+ " sample_props = {\"$name\": sample_out_name_textbox.value, \"exists\": True}\n",
+ " utils.create_openbis_object(OPENBIS_SESSION, type=\"SAMPLE\", collection=\"/MATERIALS/SAMPLES/SAMPLE_COLLECTION\", props=sample_props, parents=sample_parents)\n",
+ " display(utils.Javascript(data = \"alert('Upload successful!')\"))\n",
+ "\n",
+ "def select_material_radio_change(change):\n",
+ " material_type = material_selection_radio_button.value\n",
+ " if material_type == \"No material\":\n",
+ " with material_selector:\n",
+ " clear_output()\n",
+ " material_selector.dropdown.value = -1\n",
+ " return\n",
+ " \n",
+ " material_selector.details_textbox.value = ''\n",
+ " material_types = {}\n",
+ " for object_key, object_info in CONFIG[\"objects\"].items():\n",
+ " if object_info[\"object_type\"] == \"slab\":\n",
+ " material_types[object_key] = (object_info[\"openbis_object_type\"], object_info[\"placeholder\"])\n",
+ " \n",
+ " with material_selector:\n",
+ " clear_output()\n",
+ " # Reset sample out name\n",
+ " sample_out_name_textbox.value = ''\n",
+ " display_list = [\n",
+ " material_selector.dropdown_boxes,\n",
+ " ipw.HBox([material_selector.details_textbox, material_selector.image_box])\n",
+ " ]\n",
+ " material_class, placeholder = material_types.get(material_type)\n",
+ " material_selector.load_dropdown_box(material_class, placeholder)\n",
+ " display(ipw.VBox(display_list))\n",
+ "\n",
+ "# Function to handle changes in the materials dropdown\n",
+ "def load_material_metadata(change):\n",
+ " if material_selector.dropdown_boxes.children[0].value == -1:\n",
+ " material_selector.details_textbox.value = ''\n",
+ " material_selector.image_box.value = utils.read_file(CONFIG[\"default_image_filepath\"])\n",
+ " return\n",
+ " \n",
+ " # Get selected object properties information from config file\n",
+ " selected_object = material_selection_radio_button.value\n",
+ " selected_object_properties = CONFIG[\"objects\"][selected_object][\"properties\"]\n",
+ " \n",
+ " # Get material object information and dataset\n",
+ " material_object = OPENBIS_SESSION.get_object(material_selector.dropdown_boxes.children[0].value)\n",
+ " material_dataset = material_object.get_datasets()[0]\n",
+ " \n",
+ " # Get the object image preview\n",
+ " if material_dataset:\n",
+ " material_dataset.download(destination=\"images\")\n",
+ " material_selector.image_box.value = utils.read_file(f\"images/{material_dataset.permId}/{material_dataset.file_list[0]}\")\n",
+ " # Erase file after downloading it\n",
+ " shutil.rmtree(f\"images/{material_dataset.permId}\")\n",
+ " else:\n",
+ " material_selector.image_box.value = utils.read_file(CONFIG[\"default_image_filepath\"])\n",
+ "\n",
+ " # Make a string with the property values of the object\n",
+ " material_metadata = material_object.props.all()\n",
+ " material_metadata_string = \"\"\n",
+ " for prop_key in selected_object_properties:\n",
+ " prop_title = CONFIG[\"properties\"][prop_key][\"title\"]\n",
+ " if CONFIG[\"properties\"][prop_key][\"property_type\"] == \"QUANTITY_VALUE\":\n",
+ " value = material_metadata.get(prop_key)\n",
+ " if value:\n",
+ " prop_dict = json.loads(value)\n",
+ " material_metadata_string += f\"{prop_title}: {prop_dict['value']} {prop_dict['unit']}\\n\"\n",
+ " else:\n",
+ " material_metadata_string += f\"{prop_title}: {value}\\n\"\n",
+ " else:\n",
+ " material_metadata_string += f\"{prop_title}: {material_metadata.get(prop_key)}\\n\"\n",
+ "\n",
+ " material_selector.details_textbox.value = material_metadata_string\n",
+ " sample_out_name_textbox.value = utils.convert_datetime_to_string(utils.get_current_datetime()) + f\"_{material_metadata['$name']}\"\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Create a sample object in openBIS"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Select material"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "application/vnd.jupyter.widget-view+json": {
+ "model_id": "6569a050959d477bb9bee85a1a8704e5",
+ "version_major": 2,
+ "version_minor": 0
+ },
+ "text/plain": [
+ "RadioButtons(layout=Layout(width='300px'), options=('No material', 'Crystal', 'Wafer substrate', '2D-layer mat…"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "material_selection_radio_button.observe(select_material_radio_change, names='value')\n",
+ "material_selector.dropdown_boxes.children[0].observe(load_material_metadata, names = 'value')\n",
+ "display(material_selection_radio_button)\n",
+ "display(material_selector)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Sample out"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "create_button.on_click(create_sample_action)\n",
+ "quit_button.on_click(close_notebook)\n",
+ "display(sample_out_name_textbox, save_close_buttons_hbox)\n",
+ "display(increase_buttons_size)"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "base",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.9.13"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/Notebooks/connection_to_openbis/.export_openbis_object-0.ipynb b/Notebooks/connection_to_openbis/.export_openbis_object-0.ipynb
new file mode 100644
index 00000000..75915ddd
--- /dev/null
+++ b/Notebooks/connection_to_openbis/.export_openbis_object-0.ipynb
@@ -0,0 +1,135 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from IPython.display import display, clear_output, Javascript, Markdown\n",
+ "import ipywidgets as ipw\n",
+ "import widgets\n",
+ "import utils\n",
+ "import os\n",
+ "import base64\n",
+ "import json"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "CONFIG = utils.read_json(\"config.json\")\n",
+ "CONFIG_ELN = utils.get_aiidalab_eln_config()\n",
+ "# CONFIG_ELN = utils.read_json(\"eln_config.json\")\n",
+ "OPENBIS_SESSION, SESSION_DATA = utils.connect_openbis(CONFIG_ELN[\"url\"], CONFIG_ELN[\"token\"])\n",
+ "\n",
+ "# Dropdown box for getting openBIS objects\n",
+ "publication_selector = widgets.PublicationSelectionWidget()\n",
+ "publication_selector.load_dropdown_box()\n",
+ "\n",
+ "download_button = utils.Button(\n",
+ " description = '', disabled = False, button_style = '', \n",
+ " tooltip = 'Download', icon = 'download', layout = ipw.Layout(width = '100px', height = '50px')\n",
+ ")\n",
+ "\n",
+ "quit_button = utils.Button(\n",
+ " description = '', disabled = False, button_style = '', \n",
+ " tooltip = 'Main menu', icon = 'home', layout = ipw.Layout(width = '100px', height = '50px')\n",
+ ")\n",
+ "\n",
+ "download_close_buttons_hbox = ipw.HBox([download_button, quit_button])\n",
+ "increase_buttons_size = utils.HTML(data = ''.join(CONFIG[\"save_home_buttons_settings\"]))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def close_notebook(b):\n",
+ " display(utils.Javascript(data = 'window.location.replace(\"home.ipynb\")'))\n",
+ "\n",
+ "def download_openbis_object_metadata(b):\n",
+ " if publication_selector.dropdown_boxes.children[0].value == -1:\n",
+ " return\n",
+ " else:\n",
+ " openbis_selected_object_permid = publication_selector.dropdown_boxes.children[0].value\n",
+ " openbis_selected_object = OPENBIS_SESSION.get_sample(openbis_selected_object_permid)\n",
+ "\n",
+ " # Collect all the information about the object from openBIS\n",
+ " parent_child_relationships = openbis_selected_object.props.all()\n",
+ " parent_child_relationships[\"perm_id\"] = openbis_selected_object_permid\n",
+ " parent_child_relationships[\"type\"] = str(openbis_selected_object.type)\n",
+ " selected_object_schema = utils.get_parent_child_relationships_nested(\n",
+ " OPENBIS_SESSION, openbis_selected_object, parent_child_relationships\n",
+ " )\n",
+ " \n",
+ " # Export to JSON\n",
+ " json_data = json.dumps(selected_object_schema, indent=4).encode('utf-8')\n",
+ " json_data = base64.b64encode(json_data).decode('utf-8')\n",
+ " \n",
+ " display(Javascript(f\"\"\"\n",
+ " var a = document.createElement('a');\n",
+ " a.href = 'data:text/json;base64,{json_data}';\n",
+ " a.download = 'data.json';\n",
+ " document.body.appendChild(a);\n",
+ " a.click();\n",
+ " document.body.removeChild(a);\n",
+ " \"\"\"))\n",
+ " display(Markdown(f\"[You .]({notebook_link})\"))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Export publication metadata"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Select publication"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "display(publication_selector)\n",
+ "display(download_close_buttons_hbox)\n",
+ "display(increase_buttons_size)\n",
+ "download_button.on_click(download_openbis_object_metadata)\n",
+ "quit_button.on_click(close_notebook)"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "base",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.9.13"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/Notebooks/connection_to_openbis/.export_openbis_object-1.ipynb b/Notebooks/connection_to_openbis/.export_openbis_object-1.ipynb
new file mode 100644
index 00000000..731cf4ef
--- /dev/null
+++ b/Notebooks/connection_to_openbis/.export_openbis_object-1.ipynb
@@ -0,0 +1,137 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from IPython.display import display, clear_output, Javascript, Markdown\n",
+ "import ipywidgets as ipw\n",
+ "import widgets\n",
+ "import utils\n",
+ "import os\n",
+ "import base64\n",
+ "import json"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "CONFIG = utils.read_json(\"config.json\")\n",
+ "CONFIG_ELN = utils.get_aiidalab_eln_config()\n",
+ "# CONFIG_ELN = utils.read_json(\"eln_config.json\")\n",
+ "OPENBIS_SESSION, SESSION_DATA = utils.connect_openbis(CONFIG_ELN[\"url\"], CONFIG_ELN[\"token\"])\n",
+ "\n",
+ "# Dropdown box for getting openBIS objects\n",
+ "publication_selector = widgets.PublicationSelectionWidget()\n",
+ "publication_selector.load_dropdown_box()\n",
+ "\n",
+ "prompt_textarea = utils.Textarea(description = \"Prompt: \", layout = ipw.Layout(width = '900px', height = '300px'))\n",
+ "\n",
+ "download_button = utils.Button(\n",
+ " description = '', disabled = False, button_style = '', \n",
+ " tooltip = 'Download', icon = 'download', layout = ipw.Layout(width = '100px', height = '50px')\n",
+ ")\n",
+ "\n",
+ "quit_button = utils.Button(\n",
+ " description = '', disabled = False, button_style = '', \n",
+ " tooltip = 'Main menu', icon = 'home', layout = ipw.Layout(width = '100px', height = '50px')\n",
+ ")\n",
+ "\n",
+ "download_close_buttons_hbox = ipw.HBox([download_button, quit_button])\n",
+ "increase_buttons_size = utils.HTML(data = ''.join(CONFIG[\"save_home_buttons_settings\"]))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def close_notebook(b):\n",
+ " display(utils.Javascript(data = 'window.location.replace(\"home.ipynb\")'))\n",
+ "\n",
+ "def download_openbis_object_metadata(b):\n",
+ " if publication_selector.dropdown.value == -1:\n",
+ " return\n",
+ " else:\n",
+ " openbis_selected_object_permid = publication_selector.dropdown_boxes.children[0].value\n",
+ " openbis_selected_object = OPENBIS_SESSION.get_sample(openbis_selected_object_permid)\n",
+ "\n",
+ " # Collect all the information about the object from openBIS\n",
+ " parent_child_relationships = openbis_selected_object.props.all()\n",
+ " parent_child_relationships[\"perm_id\"] = openbis_selected_object_permid\n",
+ " parent_child_relationships[\"type\"] = str(openbis_selected_object.type)\n",
+ " selected_object_schema = utils.get_parent_child_relationships_nested(\n",
+ " OPENBIS_SESSION, openbis_selected_object, parent_child_relationships\n",
+ " )\n",
+ " \n",
+ " # Export to JSON\n",
+ " json_data = json.dumps(selected_object_schema, indent=4).encode('utf-8')\n",
+ " json_data = base64.b64encode(json_data).decode('utf-8')\n",
+ " \n",
+ " display(Javascript(f\"\"\"\n",
+ " var a = document.createElement('a');\n",
+ " a.href = 'data:text/json;base64,{json_data}';\n",
+ " a.download = 'data.json';\n",
+ " document.body.appendChild(a);\n",
+ " a.click();\n",
+ " document.body.removeChild(a);\n",
+ " \"\"\"))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Export publication metadata"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Select publication"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "display(publication_selector)\n",
+ "display(prompt_textarea)\n",
+ "display(download_close_buttons_hbox)\n",
+ "display(increase_buttons_size)\n",
+ "download_button.on_click(download_openbis_object_metadata)\n",
+ "quit_button.on_click(close_notebook)"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "base",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.9.13"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/Notebooks/connection_to_openbis/.export_openbis_object-2.ipynb b/Notebooks/connection_to_openbis/.export_openbis_object-2.ipynb
new file mode 100644
index 00000000..560a2589
--- /dev/null
+++ b/Notebooks/connection_to_openbis/.export_openbis_object-2.ipynb
@@ -0,0 +1,137 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from IPython.display import display, clear_output, Javascript, Markdown\n",
+ "import ipywidgets as ipw\n",
+ "import widgets\n",
+ "import utils\n",
+ "import os\n",
+ "import base64\n",
+ "import json"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "CONFIG = utils.read_json(\"config.json\")\n",
+ "CONFIG_ELN = utils.get_aiidalab_eln_config()\n",
+ "# CONFIG_ELN = utils.read_json(\"eln_config.json\")\n",
+ "OPENBIS_SESSION, SESSION_DATA = utils.connect_openbis(CONFIG_ELN[\"url\"], CONFIG_ELN[\"token\"])\n",
+ "\n",
+ "# Dropdown box for getting openBIS objects\n",
+ "publication_selector = widgets.PublicationSelectionWidget()\n",
+ "publication_selector.load_dropdown_box()\n",
+ "\n",
+ "prompt_textarea = utils.Textarea(description = \"Prompt: \")\n",
+ "\n",
+ "download_button = utils.Button(\n",
+ " description = '', disabled = False, button_style = '', \n",
+ " tooltip = 'Download', icon = 'download', layout = ipw.Layout(width = '100px', height = '50px')\n",
+ ")\n",
+ "\n",
+ "quit_button = utils.Button(\n",
+ " description = '', disabled = False, button_style = '', \n",
+ " tooltip = 'Main menu', icon = 'home', layout = ipw.Layout(width = '100px', height = '50px')\n",
+ ")\n",
+ "\n",
+ "download_close_buttons_hbox = ipw.HBox([download_button, quit_button])\n",
+ "increase_buttons_size = utils.HTML(data = ''.join(CONFIG[\"save_home_buttons_settings\"]))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def close_notebook(b):\n",
+ " display(utils.Javascript(data = 'window.location.replace(\"home.ipynb\")'))\n",
+ "\n",
+ "def download_openbis_object_metadata(b):\n",
+ " if publication_selector.dropdown.value == -1:\n",
+ " return\n",
+ " else:\n",
+ " openbis_selected_object_permid = publication_selector.dropdown_boxes.children[0].value\n",
+ " openbis_selected_object = OPENBIS_SESSION.get_sample(openbis_selected_object_permid)\n",
+ "\n",
+ " # Collect all the information about the object from openBIS\n",
+ " parent_child_relationships = openbis_selected_object.props.all()\n",
+ " parent_child_relationships[\"perm_id\"] = openbis_selected_object_permid\n",
+ " parent_child_relationships[\"type\"] = str(openbis_selected_object.type)\n",
+ " selected_object_schema = utils.get_parent_child_relationships_nested(\n",
+ " OPENBIS_SESSION, openbis_selected_object, parent_child_relationships\n",
+ " )\n",
+ " \n",
+ " # Export to JSON\n",
+ " json_data = json.dumps(selected_object_schema, indent=4).encode('utf-8')\n",
+ " json_data = base64.b64encode(json_data).decode('utf-8')\n",
+ " \n",
+ " display(Javascript(f\"\"\"\n",
+ " var a = document.createElement('a');\n",
+ " a.href = 'data:text/json;base64,{json_data}';\n",
+ " a.download = 'data.json';\n",
+ " document.body.appendChild(a);\n",
+ " a.click();\n",
+ " document.body.removeChild(a);\n",
+ " \"\"\"))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Export publication metadata"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Select publication"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "display(publication_selector)\n",
+ "display(prompt_textarea)\n",
+ "display(download_close_buttons_hbox)\n",
+ "display(increase_buttons_size)\n",
+ "download_button.on_click(download_openbis_object_metadata)\n",
+ "quit_button.on_click(close_notebook)"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "base",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.9.13"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/Notebooks/connection_to_openbis/.export_openbis_object-3.ipynb b/Notebooks/connection_to_openbis/.export_openbis_object-3.ipynb
new file mode 100644
index 00000000..55278a70
--- /dev/null
+++ b/Notebooks/connection_to_openbis/.export_openbis_object-3.ipynb
@@ -0,0 +1,192 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from IPython.display import display, clear_output, Javascript, Markdown\n",
+ "import ipywidgets as ipw\n",
+ "import widgets\n",
+ "import utils\n",
+ "import os\n",
+ "import base64\n",
+ "import json\n",
+ "import google.generativeai as genai"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "CONFIG = utils.read_json(\"config.json\")\n",
+ "CONFIG_ELN = utils.get_aiidalab_eln_config()\n",
+ "# CONFIG_ELN = utils.read_json(\"eln_config.json\")\n",
+ "OPENBIS_SESSION, SESSION_DATA = utils.connect_openbis(CONFIG_ELN[\"url\"], CONFIG_ELN[\"token\"])\n",
+ "\n",
+ "# Dropdown box for getting openBIS objects\n",
+ "publication_selector = widgets.PublicationSelectionWidget()\n",
+ "publication_selector.load_dropdown_box()\n",
+ "\n",
+ "prompt_textarea = utils.Textarea(\n",
+ " description = \"Prompt\", \n",
+ " layout = ipw.Layout(width = '980px', height = '300px'),\n",
+ " style = {\"description_width\": \"110px\"}\n",
+ ")\n",
+ "\n",
+ "model_answer_textarea = utils.Textarea(\n",
+ " description = \"Answer\", \n",
+ " layout = ipw.Layout(width = '980px', height = '300px'),\n",
+ " style = {\"description_width\": \"110px\"}\n",
+ ")\n",
+ "\n",
+ "enter_button = utils.Button(\n",
+ " description = '', disabled = False, button_style = '', \n",
+ " tooltip = 'Enter', icon = 'arrow-right', layout = ipw.Layout(width = '100px', height = '50px')\n",
+ ")\n",
+ "\n",
+ "load_model_button = utils.Button(\n",
+ " description = '', disabled = False, button_style = '', \n",
+ " tooltip = 'Load chatbot', icon = 'arrow-down', layout = ipw.Layout(width = '100px', height = '50px')\n",
+ ")\n",
+ "\n",
+ "download_button = utils.Button(\n",
+ " description = '', disabled = False, button_style = '', \n",
+ " tooltip = 'Download', icon = 'download', layout = ipw.Layout(width = '100px', height = '50px')\n",
+ ")\n",
+ "\n",
+ "quit_button = utils.Button(\n",
+ " description = '', disabled = False, button_style = '', \n",
+ " tooltip = 'Main menu', icon = 'home', layout = ipw.Layout(width = '100px', height = '50px')\n",
+ ")\n",
+ "\n",
+ "load_download_buttons_hbox = ipw.HBox([load_model_button, download_button])\n",
+ "\n",
+ "increase_buttons_size = utils.HTML(data = ''.join(CONFIG[\"save_home_buttons_settings\"]))\n",
+ "\n",
+ "# Google Gemini 1.5 Flash\n",
+ "google_api_key = utils.read_json(\"/home/jovyan/gemini_api.json\")\n",
+ "genai.configure(api_key=google_api_key[\"api_key\"])\n",
+ "model = genai.GenerativeModel(\"gemini-1.5-flash\") # gemini-1.5-flash\n",
+ "\n",
+ "# Start the chatbot\n",
+ "chat = model.start_chat()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def close_notebook(b):\n",
+ " display(utils.Javascript(data = 'window.location.replace(\"home.ipynb\")'))\n",
+ "\n",
+ "def ask_chatbot(change):\n",
+ " model_answer_textarea.value = \"\"\n",
+ " prompt = prompt_textarea.value\n",
+ " response = chat.send_message(prompt, stream = True)\n",
+ " for chunk in response:\n",
+ " model_answer_textarea.value = model_answer_textarea.value + chunk.text\n",
+ " \n",
+ "def get_openbis_object_metadata():\n",
+ " if publication_selector.dropdown.value == -1:\n",
+ " return None\n",
+ " else:\n",
+ " openbis_selected_object_permid = publication_selector.dropdown_boxes.children[0].value\n",
+ " openbis_selected_object = OPENBIS_SESSION.get_sample(openbis_selected_object_permid)\n",
+ "\n",
+ " # Collect all the information about the object from openBIS\n",
+ " parent_child_relationships = openbis_selected_object.props.all()\n",
+ " parent_child_relationships[\"perm_id\"] = openbis_selected_object_permid\n",
+ " parent_child_relationships[\"type\"] = str(openbis_selected_object.type)\n",
+ " openbis_objects_history = {}\n",
+ " selected_object_schema = utils.get_parent_child_relationships_nested(\n",
+ " OPENBIS_SESSION, openbis_selected_object, parent_child_relationships, openbis_objects_history\n",
+ " )\n",
+ "\n",
+ " return selected_object_schema\n",
+ "\n",
+ "def load_chatbot(b):\n",
+ " data_dict = get_openbis_object_metadata()\n",
+ " if data_dict:\n",
+ " json_data = json.dumps(data_dict, indent=4)\n",
+ " response = chat.send_message(f\"This is the graph of my study: {json_data}\")\n",
+ " display(utils.Javascript(data = \"alert('Chatbot is ready!')\"))\n",
+ "\n",
+ "def download_metadata(b):\n",
+ " data_dict = get_openbis_object_metadata()\n",
+ " if data_dict:\n",
+ " # Export to JSON\n",
+ " json_data = json.dumps(data_dict, indent=4).encode('utf-8')\n",
+ " json_data = base64.b64encode(json_data).decode('utf-8')\n",
+ " \n",
+ " display(Javascript(f\"\"\"\n",
+ " var a = document.createElement('a');\n",
+ " a.href = 'data:text/json;base64,{json_data}';\n",
+ " a.download = 'data.json';\n",
+ " document.body.appendChild(a);\n",
+ " a.click();\n",
+ " document.body.removeChild(a);\n",
+ " \"\"\"))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Export publication metadata"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Select publication"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "display(increase_buttons_size)\n",
+ "display(publication_selector)\n",
+ "display(load_download_buttons_hbox)\n",
+ "display(prompt_textarea)\n",
+ "display(enter_button)\n",
+ "display(model_answer_textarea)\n",
+ "display(quit_button)\n",
+ "load_model_button.on_click(load_chatbot)\n",
+ "download_button.on_click(download_metadata)\n",
+ "enter_button.on_click(ask_chatbot)\n",
+ "quit_button.on_click(close_notebook)"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "base",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.9.13"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/Notebooks/connection_to_openbis/.export_openbis_object-4.ipynb b/Notebooks/connection_to_openbis/.export_openbis_object-4.ipynb
new file mode 100644
index 00000000..9f6e25a3
--- /dev/null
+++ b/Notebooks/connection_to_openbis/.export_openbis_object-4.ipynb
@@ -0,0 +1,192 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from IPython.display import display, clear_output, Javascript, Markdown\n",
+ "import ipywidgets as ipw\n",
+ "import widgets\n",
+ "import utils\n",
+ "import os\n",
+ "import base64\n",
+ "import json\n",
+ "import google.generativeai as genai"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "CONFIG = utils.read_json(\"config.json\")\n",
+ "CONFIG_ELN = utils.get_aiidalab_eln_config()\n",
+ "# CONFIG_ELN = utils.read_json(\"eln_config.json\")\n",
+ "OPENBIS_SESSION, SESSION_DATA = utils.connect_openbis(CONFIG_ELN[\"url\"], CONFIG_ELN[\"token\"])\n",
+ "\n",
+ "# Dropdown box for getting openBIS objects\n",
+ "publication_selector = widgets.PublicationSelectionWidget()\n",
+ "publication_selector.load_dropdown_box()\n",
+ "\n",
+ "prompt_textarea = utils.Textarea(\n",
+ " description = \"Prompt\", \n",
+ " layout = ipw.Layout(width = '980px', height = '300px'),\n",
+ " style = {\"description_width\": \"110px\"}\n",
+ ")\n",
+ "\n",
+ "model_answer_textarea = utils.Textarea(\n",
+ " description = \"Answer\", \n",
+ " layout = ipw.Layout(width = '980px', height = '300px'),\n",
+ " style = {\"description_width\": \"110px\"}\n",
+ ")\n",
+ "\n",
+ "enter_button = utils.Button(\n",
+ " description = '', disabled = False, button_style = '', \n",
+ " tooltip = 'Enter', icon = 'arrow-right', layout = ipw.Layout(width = '100px', height = '50px')\n",
+ ")\n",
+ "\n",
+ "load_model_button = utils.Button(\n",
+ " description = '', disabled = False, button_style = '', \n",
+ " tooltip = 'Load chatbot', icon = 'arrow-down', layout = ipw.Layout(width = '100px', height = '50px')\n",
+ ")\n",
+ "\n",
+ "download_button = utils.Button(\n",
+ " description = '', disabled = False, button_style = '', \n",
+ " tooltip = 'Download', icon = 'download', layout = ipw.Layout(width = '100px', height = '50px')\n",
+ ")\n",
+ "\n",
+ "quit_button = utils.Button(\n",
+ " description = '', disabled = False, button_style = '', \n",
+ " tooltip = 'Main menu', icon = 'home', layout = ipw.Layout(width = '100px', height = '50px')\n",
+ ")\n",
+ "\n",
+ "load_download_buttons_hbox = ipw.HBox([load_model_button, download_button])\n",
+ "\n",
+ "increase_buttons_size = utils.HTML(data = ''.join(CONFIG[\"save_home_buttons_settings\"]))\n",
+ "\n",
+ "# Google Gemini 1.5 Flash\n",
+ "google_api_key = utils.read_json(\"/home/jovyan/gemini_api.json\")\n",
+ "genai.configure(api_key=google_api_key[\"api_key\"])\n",
+ "model = genai.GenerativeModel(\"gemini-1.5-flash\") # gemini-1.5-flash\n",
+ "\n",
+ "# Start the chatbot\n",
+ "chat = model.start_chat()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def close_notebook(b):\n",
+ " display(utils.Javascript(data = 'window.location.replace(\"home.ipynb\")'))\n",
+ "\n",
+ "def ask_chatbot(change):\n",
+ " model_answer_textarea.value = \"\"\n",
+ " prompt = prompt_textarea.value\n",
+ " response = chat.send_message(prompt, stream = True)\n",
+ " # model_answer_textarea.value = response.text\n",
+ " for chunk in response:\n",
+ " model_answer_textarea.value = model_answer_textarea.value + chunk.text\n",
+ " \n",
+ "def get_openbis_object_metadata():\n",
+ " if publication_selector.dropdown.value == -1:\n",
+ " return None\n",
+ " else:\n",
+ " openbis_selected_object_permid = publication_selector.dropdown_boxes.children[0].value\n",
+ " openbis_selected_object = OPENBIS_SESSION.get_sample(openbis_selected_object_permid)\n",
+ "\n",
+ " # Collect all the information about the object from openBIS\n",
+ " parent_child_relationships = openbis_selected_object.props.all()\n",
+ " parent_child_relationships[\"perm_id\"] = openbis_selected_object_permid\n",
+ " parent_child_relationships[\"type\"] = str(openbis_selected_object.type)\n",
+ " selected_object_schema = utils.get_parent_child_relationships_nested(\n",
+ " OPENBIS_SESSION, openbis_selected_object, parent_child_relationships\n",
+ " )\n",
+ "\n",
+ " return selected_object_schema\n",
+ "\n",
+ "def load_chatbot(b):\n",
+ " data_dict = get_openbis_object_metadata()\n",
+ " if data_dict:\n",
+ " json_data = json.dumps(data_dict, indent=4)\n",
+ " response = chat.send_message(f\"This is the graph of my study: {json_data}\")\n",
+ " display(utils.Javascript(data = \"alert('Chatbot is ready!')\"))\n",
+ "\n",
+ "def download_metadata(b):\n",
+ " data_dict = get_openbis_object_metadata()\n",
+ " if data_dict:\n",
+ " # Export to JSON\n",
+ " json_data = json.dumps(data_dict, indent=4).encode('utf-8')\n",
+ " json_data = base64.b64encode(json_data).decode('utf-8')\n",
+ " \n",
+ " display(Javascript(f\"\"\"\n",
+ " var a = document.createElement('a');\n",
+ " a.href = 'data:text/json;base64,{json_data}';\n",
+ " a.download = 'data.json';\n",
+ " document.body.appendChild(a);\n",
+ " a.click();\n",
+ " document.body.removeChild(a);\n",
+ " \"\"\"))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Export publication metadata"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Select publication"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "display(increase_buttons_size)\n",
+ "display(publication_selector)\n",
+ "display(load_download_buttons_hbox)\n",
+ "display(prompt_textarea)\n",
+ "display(enter_button)\n",
+ "display(model_answer_textarea)\n",
+ "display(quit_button)\n",
+ "load_model_button.on_click(load_chatbot)\n",
+ "download_button.on_click(download_metadata)\n",
+ "enter_button.on_click(ask_chatbot)\n",
+ "quit_button.on_click(close_notebook)"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "base",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.9.13"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/Notebooks/connection_to_openbis/.home-3.ipynb b/Notebooks/connection_to_openbis/.home-3.ipynb
new file mode 100644
index 00000000..50cab7c7
--- /dev/null
+++ b/Notebooks/connection_to_openbis/.home-3.ipynb
@@ -0,0 +1,95 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Import libraries\n",
+ "from IPython.display import display\n",
+ "import ipywidgets as ipw\n",
+ "import utils"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "CONFIG = utils.read_json(\"config.json\")\n",
+ "CONFIG_ELN = utils.get_aiidalab_eln_config()\n",
+ "# CONFIG_ELN = utils.read_json(\"eln_config.json\")\n",
+ "OPENBIS_SESSION, SESSION_DATA = utils.connect_openbis(CONFIG_ELN[\"url\"], CONFIG_ELN[\"token\"])\n",
+ "\n",
+ "openbis_connection_status_htmlbox = utils.HTMLbox(value = '')\n",
+ "tab_children, tab_titles = [], []\n",
+ "if OPENBIS_SESSION:\n",
+ " tabs_data = CONFIG[\"home_page\"][\"enable_links\"]\n",
+ " openbis_connection_status_htmlbox.value = CONFIG[\"home_page\"][\"enable_status\"]\n",
+ "else:\n",
+ " tabs_data = CONFIG[\"home_page\"][\"disable_links\"]\n",
+ " openbis_connection_status_htmlbox.value = CONFIG[\"home_page\"][\"disable_status\"]\n",
+ "\n",
+ "# Populate tab widget\n",
+ "for tab_title, html_content in tabs_data.items():\n",
+ " tab_titles.append(tab_title)\n",
+ " content = ''.join(html_content)\n",
+ " widgets_list = [utils.HTMLbox(value=content)]\n",
+ " vbox = ipw.VBox(widgets_list)\n",
+ " tab_children.append(vbox)\n",
+ "\n",
+ "tabs = ipw.Tab(children=tab_children)\n",
+ "for idx, title in enumerate(tab_titles):\n",
+ " tabs.set_title(idx, title)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# AiiDAlab-openBIS app"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "display(openbis_connection_status_htmlbox)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "display(tabs)"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.9.13"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/Notebooks/connection_to_openbis/.home-4.ipynb b/Notebooks/connection_to_openbis/.home-4.ipynb
new file mode 100644
index 00000000..50cab7c7
--- /dev/null
+++ b/Notebooks/connection_to_openbis/.home-4.ipynb
@@ -0,0 +1,95 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Import libraries\n",
+ "from IPython.display import display\n",
+ "import ipywidgets as ipw\n",
+ "import utils"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "CONFIG = utils.read_json(\"config.json\")\n",
+ "CONFIG_ELN = utils.get_aiidalab_eln_config()\n",
+ "# CONFIG_ELN = utils.read_json(\"eln_config.json\")\n",
+ "OPENBIS_SESSION, SESSION_DATA = utils.connect_openbis(CONFIG_ELN[\"url\"], CONFIG_ELN[\"token\"])\n",
+ "\n",
+ "openbis_connection_status_htmlbox = utils.HTMLbox(value = '')\n",
+ "tab_children, tab_titles = [], []\n",
+ "if OPENBIS_SESSION:\n",
+ " tabs_data = CONFIG[\"home_page\"][\"enable_links\"]\n",
+ " openbis_connection_status_htmlbox.value = CONFIG[\"home_page\"][\"enable_status\"]\n",
+ "else:\n",
+ " tabs_data = CONFIG[\"home_page\"][\"disable_links\"]\n",
+ " openbis_connection_status_htmlbox.value = CONFIG[\"home_page\"][\"disable_status\"]\n",
+ "\n",
+ "# Populate tab widget\n",
+ "for tab_title, html_content in tabs_data.items():\n",
+ " tab_titles.append(tab_title)\n",
+ " content = ''.join(html_content)\n",
+ " widgets_list = [utils.HTMLbox(value=content)]\n",
+ " vbox = ipw.VBox(widgets_list)\n",
+ " tab_children.append(vbox)\n",
+ "\n",
+ "tabs = ipw.Tab(children=tab_children)\n",
+ "for idx, title in enumerate(tab_titles):\n",
+ " tabs.set_title(idx, title)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# AiiDAlab-openBIS app"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "display(openbis_connection_status_htmlbox)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "display(tabs)"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.9.13"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/Notebooks/connection_to_openbis/.home-5.ipynb b/Notebooks/connection_to_openbis/.home-5.ipynb
new file mode 100644
index 00000000..50cab7c7
--- /dev/null
+++ b/Notebooks/connection_to_openbis/.home-5.ipynb
@@ -0,0 +1,95 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Import libraries\n",
+ "from IPython.display import display\n",
+ "import ipywidgets as ipw\n",
+ "import utils"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "CONFIG = utils.read_json(\"config.json\")\n",
+ "CONFIG_ELN = utils.get_aiidalab_eln_config()\n",
+ "# CONFIG_ELN = utils.read_json(\"eln_config.json\")\n",
+ "OPENBIS_SESSION, SESSION_DATA = utils.connect_openbis(CONFIG_ELN[\"url\"], CONFIG_ELN[\"token\"])\n",
+ "\n",
+ "openbis_connection_status_htmlbox = utils.HTMLbox(value = '')\n",
+ "tab_children, tab_titles = [], []\n",
+ "if OPENBIS_SESSION:\n",
+ " tabs_data = CONFIG[\"home_page\"][\"enable_links\"]\n",
+ " openbis_connection_status_htmlbox.value = CONFIG[\"home_page\"][\"enable_status\"]\n",
+ "else:\n",
+ " tabs_data = CONFIG[\"home_page\"][\"disable_links\"]\n",
+ " openbis_connection_status_htmlbox.value = CONFIG[\"home_page\"][\"disable_status\"]\n",
+ "\n",
+ "# Populate tab widget\n",
+ "for tab_title, html_content in tabs_data.items():\n",
+ " tab_titles.append(tab_title)\n",
+ " content = ''.join(html_content)\n",
+ " widgets_list = [utils.HTMLbox(value=content)]\n",
+ " vbox = ipw.VBox(widgets_list)\n",
+ " tab_children.append(vbox)\n",
+ "\n",
+ "tabs = ipw.Tab(children=tab_children)\n",
+ "for idx, title in enumerate(tab_titles):\n",
+ " tabs.set_title(idx, title)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# AiiDAlab-openBIS app"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "display(openbis_connection_status_htmlbox)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "display(tabs)"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.9.13"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/Notebooks/connection_to_openbis/.home-6.ipynb b/Notebooks/connection_to_openbis/.home-6.ipynb
new file mode 100644
index 00000000..50cab7c7
--- /dev/null
+++ b/Notebooks/connection_to_openbis/.home-6.ipynb
@@ -0,0 +1,95 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Import libraries\n",
+ "from IPython.display import display\n",
+ "import ipywidgets as ipw\n",
+ "import utils"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "CONFIG = utils.read_json(\"config.json\")\n",
+ "CONFIG_ELN = utils.get_aiidalab_eln_config()\n",
+ "# CONFIG_ELN = utils.read_json(\"eln_config.json\")\n",
+ "OPENBIS_SESSION, SESSION_DATA = utils.connect_openbis(CONFIG_ELN[\"url\"], CONFIG_ELN[\"token\"])\n",
+ "\n",
+ "openbis_connection_status_htmlbox = utils.HTMLbox(value = '')\n",
+ "tab_children, tab_titles = [], []\n",
+ "if OPENBIS_SESSION:\n",
+ " tabs_data = CONFIG[\"home_page\"][\"enable_links\"]\n",
+ " openbis_connection_status_htmlbox.value = CONFIG[\"home_page\"][\"enable_status\"]\n",
+ "else:\n",
+ " tabs_data = CONFIG[\"home_page\"][\"disable_links\"]\n",
+ " openbis_connection_status_htmlbox.value = CONFIG[\"home_page\"][\"disable_status\"]\n",
+ "\n",
+ "# Populate tab widget\n",
+ "for tab_title, html_content in tabs_data.items():\n",
+ " tab_titles.append(tab_title)\n",
+ " content = ''.join(html_content)\n",
+ " widgets_list = [utils.HTMLbox(value=content)]\n",
+ " vbox = ipw.VBox(widgets_list)\n",
+ " tab_children.append(vbox)\n",
+ "\n",
+ "tabs = ipw.Tab(children=tab_children)\n",
+ "for idx, title in enumerate(tab_titles):\n",
+ " tabs.set_title(idx, title)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# AiiDAlab-openBIS app"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "display(openbis_connection_status_htmlbox)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "display(tabs)"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.9.13"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/Notebooks/connection_to_openbis/.home-7.ipynb b/Notebooks/connection_to_openbis/.home-7.ipynb
new file mode 100644
index 00000000..fa266541
--- /dev/null
+++ b/Notebooks/connection_to_openbis/.home-7.ipynb
@@ -0,0 +1,95 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Import libraries\n",
+ "from IPython.display import display\n",
+ "import ipywidgets as ipw\n",
+ "import utils"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "CONFIG = utils.read_json(\"config.json\")\n",
+ "CONFIG_ELN = utils.get_aiidalab_eln_config()\n",
+ "# CONFIG_ELN = utils.read_json(\"eln_config.json\")\n",
+ "OPENBIS_SESSION, SESSION_DATA = utils.connect_openbis(CONFIG_ELN[\"url\"], CONFIG_ELN[\"token\"])\n",
+ "\n",
+ "openbis_connection_status_htmlbox = utils.HTMLbox(value = '')\n",
+ "tab_children, tab_titles = [], []\n",
+ "if OPENBIS_SESSION:\n",
+ " tabs_data = CONFIG[\"home_page\"][\"enable_links\"]\n",
+ " openbis_connection_status_htmlbox.value = CONFIG[\"home_page\"][\"enable_status\"]\n",
+ "else:\n",
+ " tabs_data = CONFIG[\"home_page\"][\"disable_links\"]\n",
+ " openbis_connection_status_htmlbox.value = CONFIG[\"home_page\"][\"disable_status\"]\n",
+ "\n",
+ "# Populate tab widget\n",
+ "for tab_title, html_content in tabs_data.items():\n",
+ " tab_titles.append(tab_title)\n",
+ " content = ''.join(html_content)\n",
+ " widgets_list = [utils.HTMLbox(value=content)]\n",
+ " vbox = ipw.VBox(widgets_list)\n",
+ " tab_children.append(vbox)\n",
+ "\n",
+ "tabs = ipw.Tab(children=tab_children)\n",
+ "for idx, title in enumerate(tab_titles):\n",
+ " tabs.set_title(idx, title)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# AiiDAlab-openBIS app"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "display(openbis_connection_status_htmlbox)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "display(tabs)"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "base",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.9.13"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/Notebooks/connection_to_openbis/.send_simulation_to_openbis-1.ipynb b/Notebooks/connection_to_openbis/.send_simulation_to_openbis-1.ipynb
new file mode 100644
index 00000000..2330bda3
--- /dev/null
+++ b/Notebooks/connection_to_openbis/.send_simulation_to_openbis-1.ipynb
@@ -0,0 +1,468 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "%load_ext aiida\n",
+ "%aiida\n",
+ "from IPython.display import display, clear_output, Markdown\n",
+ "import ipywidgets as ipw\n",
+ "import widgets\n",
+ "import utils\n",
+ "import aiida_utils\n",
+ "import json\n",
+ "import shutil"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "CONFIG = utils.read_json(\"config.json\")\n",
+ "CONFIG_ELN = utils.get_aiidalab_eln_config()\n",
+ "# CONFIG_ELN = utils.read_json(\"eln_config.json\")\n",
+ "OPENBIS_SESSION, SESSION_DATA = utils.connect_openbis(CONFIG_ELN[\"url\"], CONFIG_ELN[\"token\"])\n",
+ "slabs_options = [object_key for object_key, object_info in CONFIG[\"objects\"].items() if object_info[\"object_type\"] == \"slab\"]\n",
+ "slabs_options.insert(0, \"No material\")\n",
+ "material_selection_radio_button = utils.Radiobuttons(\n",
+ " description = '', options = slabs_options, \n",
+ " disabled = False, layout = ipw.Layout(width = '300px'), \n",
+ " style = {'description_width': \"100px\"}\n",
+ ")\n",
+ "\n",
+ "simulation_material_dropdown = utils.Dropdown(\n",
+ " description = \"Simulation material\", disabled = False, \n",
+ " layout = ipw.Layout(width = \"300px\"), \n",
+ " options = [\"Select an option...\", \"Molecule and slab\", \"Reaction product\"],\n",
+ " value = \"Select an option...\",\n",
+ " style = {'description_width': \"150px\"} \n",
+ ")\n",
+ "simulation_material_properties_output = ipw.Output()\n",
+ "\n",
+ "material_selector = widgets.MaterialSelectionWidget()\n",
+ "\n",
+ "experiment_selector = widgets.ExperimentSelectionWidget()\n",
+ "experiment_selector.load_dropdown_box()\n",
+ "\n",
+ "molecule_selector_list = widgets.MultipleSelectorWidget(\"molecule\")\n",
+ "molecule_selector_list_output = ipw.Output()\n",
+ "\n",
+ "add_molecule_button = utils.Button(\n",
+ " description = 'Add molecule', disabled = False, button_style = '', \n",
+ " tooltip = 'Add molecule', layout = ipw.Layout(width = '150px', height = '25px')\n",
+ ")\n",
+ "remove_molecule_button = utils.Button(\n",
+ " description = 'Remove molecule', disabled = False, button_style = '', \n",
+ " tooltip = 'Remove molecule', layout = ipw.Layout(width = '150px', height = '25px')\n",
+ ")\n",
+ "add_remove_molecule_buttons_hbox = ipw.HBox([add_molecule_button, remove_molecule_button])\n",
+ "\n",
+ "product_selector_list = widgets.MultipleSelectorWidget(\"product\")\n",
+ "product_selector_list_output = ipw.Output()\n",
+ "\n",
+ "add_product_button = utils.Button(\n",
+ " description = 'Add product', disabled = False, button_style = '', \n",
+ " tooltip = 'Add product', layout = ipw.Layout(width = '150px', height = '25px')\n",
+ ")\n",
+ "remove_product_button = utils.Button(\n",
+ " description = 'Remove product', disabled = False, button_style = '', \n",
+ " tooltip = 'Remove product', layout = ipw.Layout(width = '150px', height = '25px')\n",
+ ")\n",
+ "add_remove_product_buttons_hbox = ipw.HBox([add_product_button, remove_product_button])\n",
+ "\n",
+ "is_automatic_checkbox = utils.Checkbox(\n",
+ " description = 'Simulation developed using AiiDA', value = False, \n",
+ " disabled = False, layout = ipw.Layout(width = \"250px\"), indent = False\n",
+ ")\n",
+ "\n",
+ "simulation_details_output = ipw.Output()\n",
+ "\n",
+ "simulation_type_dropdown = utils.Dropdown(\n",
+ " description = \"Simulation type\", disabled = False, \n",
+ " layout = ipw.Layout(width = \"300px\"), \n",
+ " options = [\"Select an option...\", \"Geometry Optimisation\", \"Band Structure\", \"PDOS\", \"Vibrational Spectroscopy\", \"Unclassified Simulation\"],\n",
+ " value = \"Select an option...\",\n",
+ " style = {'description_width': \"110px\"} \n",
+ ")\n",
+ "\n",
+ "atomistic_model_selector = widgets.AtomisticModelSelectionWidget()\n",
+ "atomistic_model_selector.load_dropdown_box()\n",
+ "\n",
+ "simulation_properties_output = ipw.Output()\n",
+ "simulation_properties_widgets = {\n",
+ " simulation_type: widgets.ObjectPropertiesWidgets(simulation_type) for simulation_type in simulation_type_dropdown.options[1:]\n",
+ "}\n",
+ "\n",
+ "simulation_selector = widgets.SimulationSelectionWidget()\n",
+ "simulation_selector.load_dropdown_box(\"aiidalab\")\n",
+ "\n",
+ "code_selector = widgets.CodeMultipleSelectionWidget()\n",
+ "code_selector.load_selector()\n",
+ "\n",
+ "simulation_dataset_upload = ipw.FileUpload(multiple = True)\n",
+ "simulation_preview_upload = ipw.FileUpload(multiple = False, accept = '.png, .jpg, .jpeg')\n",
+ "simulation_images_upload = ipw.FileUpload(multiple = True, accept = '.png, .jpg, .jpeg, .tar')\n",
+ "simulation_support_files_upload = ipw.FileUpload(multiple = True)\n",
+ "\n",
+ "increase_buttons_size = utils.HTML(data = ''.join(CONFIG[\"save_home_buttons_settings\"]))\n",
+ "create_button = utils.Button(\n",
+ " description = '', disabled = False, button_style = '', tooltip = 'Save', \n",
+ " icon = 'save', layout = ipw.Layout(width = '100px', height = '50px')\n",
+ ")\n",
+ "quit_button = utils.Button(\n",
+ " description = '', disabled = False, button_style = '', \n",
+ " tooltip = 'Main menu', icon = 'home', layout = ipw.Layout(width = '100px', height = '50px')\n",
+ ")\n",
+ "save_close_buttons_hbox = ipw.HBox([create_button, quit_button])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def close_notebook(b):\n",
+ " display(utils.Javascript(data = 'window.location.replace(\"home.ipynb\")'))\n",
+ "\n",
+ "def select_material_radio_change(change):\n",
+ " material_type = material_selection_radio_button.value\n",
+ " if material_type == \"No material\":\n",
+ " with material_selector:\n",
+ " clear_output()\n",
+ " return\n",
+ " \n",
+ " material_selector.details_textbox.value = ''\n",
+ " material_types = {}\n",
+ " for object_key, object_info in CONFIG[\"objects\"].items():\n",
+ " if object_info[\"object_type\"] == \"slab\":\n",
+ " material_types[object_key] = (object_info[\"openbis_object_type\"], object_info[\"placeholder\"])\n",
+ " \n",
+ " with material_selector:\n",
+ " clear_output()\n",
+ " display_list = [\n",
+ " material_selector.dropdown_boxes,\n",
+ " ipw.HBox([material_selector.details_textbox, material_selector.image_box])\n",
+ " ]\n",
+ " material_class, placeholder = material_types.get(material_type)\n",
+ " material_selector.load_dropdown_box(material_class, placeholder)\n",
+ " display(ipw.VBox(display_list))\n",
+ "\n",
+ "# Function to handle changes in the materials dropdown\n",
+ "def load_material_metadata(change):\n",
+ " if material_selector.dropdown_boxes.children[0].value == -1:\n",
+ " material_selector.details_textbox.value = ''\n",
+ " material_selector.image_box.value = utils.read_file(CONFIG[\"default_image_filepath\"])\n",
+ " return\n",
+ " \n",
+ " # Get selected object properties information from config file\n",
+ " selected_object = material_selection_radio_button.value\n",
+ " selected_object_properties = CONFIG[\"objects\"][selected_object][\"properties\"]\n",
+ " \n",
+ " # Get material object information and dataset\n",
+ " material_object = OPENBIS_SESSION.get_object(material_selector.dropdown_boxes.children[0].value)\n",
+ " material_dataset = material_object.get_datasets()[0]\n",
+ " \n",
+ " # Get the object image preview\n",
+ " if material_dataset:\n",
+ " material_dataset.download(destination=\"images\")\n",
+ " material_selector.image_box.value = utils.read_file(f\"images/{material_dataset.permId}/{material_dataset.file_list[0]}\")\n",
+ " # Erase file after downloading it\n",
+ " shutil.rmtree(f\"images/{material_dataset.permId}\")\n",
+ " else:\n",
+ " material_selector.image_box.value = utils.read_file(CONFIG[\"default_image_filepath\"])\n",
+ "\n",
+ " # Make a string with the property values of the object\n",
+ " material_metadata = material_object.props.all()\n",
+ " material_metadata_string = \"\"\n",
+ " for prop_key in selected_object_properties:\n",
+ " prop_title = CONFIG[\"properties\"][prop_key][\"title\"]\n",
+ " if CONFIG[\"properties\"][prop_key][\"property_type\"] == \"QUANTITY_VALUE\":\n",
+ " value = material_metadata.get(prop_key)\n",
+ " if value:\n",
+ " prop_dict = json.loads(value)\n",
+ " material_metadata_string += f\"{prop_title}: {prop_dict['value']} {prop_dict['unit']}\\n\"\n",
+ " else:\n",
+ " material_metadata_string += f\"{prop_title}: {value}\\n\"\n",
+ " else:\n",
+ " material_metadata_string += f\"{prop_title}: {material_metadata.get(prop_key)}\\n\"\n",
+ "\n",
+ " material_selector.details_textbox.value = material_metadata_string\n",
+ "\n",
+ "def add_molecule_widget(b):\n",
+ " molecule_selector_list.add_selector()\n",
+ " with molecule_selector_list_output:\n",
+ " clear_output()\n",
+ " display(molecule_selector_list)\n",
+ "\n",
+ "def remove_molecule_widget(b):\n",
+ " molecule_selector_list.remove_selector()\n",
+ " with molecule_selector_list_output:\n",
+ " clear_output()\n",
+ " display(molecule_selector_list)\n",
+ "\n",
+ "def add_product_widget(b):\n",
+ " product_selector_list.add_selector()\n",
+ " with product_selector_list_output:\n",
+ " clear_output()\n",
+ " display(product_selector_list)\n",
+ "\n",
+ "def remove_product_widget(b):\n",
+ " product_selector_list.remove_selector()\n",
+ " with product_selector_list_output:\n",
+ " clear_output()\n",
+ " display(product_selector_list)\n",
+ "\n",
+ "def find_atomistic_model_perm_id(data):\n",
+ " if isinstance(data, dict):\n",
+ " # Check if the current object is of type ATOMISTIC_MODEL and is at the deepest level\n",
+ " if data.get('type') == 'ATOMISTIC_MODEL' and (not data.get('has_part') or not isinstance(data['has_part'], list)):\n",
+ " return data['perm_id']\n",
+ " # Recurse into 'has_part' if it exists\n",
+ " if 'has_part' in data:\n",
+ " for item in data['has_part']:\n",
+ " result = find_atomistic_model_perm_id(item)\n",
+ " if result:\n",
+ " return result\n",
+ " \n",
+ " elif isinstance(data, list):\n",
+ " # Recurse into list elements\n",
+ " for item in data:\n",
+ " result = find_atomistic_model_perm_id(item)\n",
+ " if result:\n",
+ " return result\n",
+ " \n",
+ " return None\n",
+ " \n",
+ "def create_simulation_openbis(b):\n",
+ " if experiment_selector.dropdown.value == -1:\n",
+ " display(utils.Javascript(data = \"alert('Select an experiment.')\"))\n",
+ " return\n",
+ " else:\n",
+ " object_parents = []\n",
+ " if molecule_selector_list.selectors:\n",
+ " for molecule_selector in molecule_selector_list.selectors:\n",
+ " if molecule_selector.dropdown.value != -1:\n",
+ " object_parents.append(molecule_selector.dropdown.value)\n",
+ " if material_selector.dropdown.value != -1:\n",
+ " object_parents.append(material_selector.dropdown.value)\n",
+ " if product_selector_list.selectors:\n",
+ " for product_selector in product_selector_list.selectors:\n",
+ " if product_selector.dropdown.value != -1:\n",
+ " object_parents.append(product_selector.dropdown.value)\n",
+ " \n",
+ " if is_automatic_checkbox.value:\n",
+ " last_export = aiida_utils.export_workchain(\n",
+ " OPENBIS_SESSION, \n",
+ " experiment_selector.dropdown.value, \n",
+ " simulation_selector.dropdown.value\n",
+ " )\n",
+ " \n",
+ " if last_export:\n",
+ " last_export_metadata = utils.get_parent_child_relationships_nested(OPENBIS_SESSION, last_export)\n",
+ " first_atomistic_model_permid = find_atomistic_model_perm_id(last_export_metadata)\n",
+ " first_atomistic_model = utils.get_openbis_objects(OPENBIS_SESSION, identifier = first_atomistic_model_permid)[0]\n",
+ " if first_atomistic_model.parents is None:\n",
+ " first_atomistic_model.set_parents(object_parents)\n",
+ " first_atomistic_model.save()\n",
+ " display(utils.Javascript(data = \"alert('Upload successful!')\"))\n",
+ " else:\n",
+ " display(utils.Javascript(data = \"alert('Simulation is already in openBIS!')\"))\n",
+ " else:\n",
+ " if simulation_type_dropdown.value == \"Select an option...\":\n",
+ " display(utils.Javascript(data = \"alert('Select a simulation type.')\"))\n",
+ " return\n",
+ " else:\n",
+ " simulation_type = simulation_type_dropdown.value\n",
+ " simulation_openbis_type = CONFIG[\"objects\"][simulation_type][\"openbis_object_type\"]\n",
+ " object_properties = {}\n",
+ " for prop in CONFIG[\"objects\"][simulation_type][\"properties\"]:\n",
+ " if CONFIG[\"properties\"][prop][\"property_type\"] == \"QUANTITY_VALUE\":\n",
+ " object_properties[prop] = json.dumps({\"has_value\": simulation_properties_widgets[simulation_type_dropdown.value].properties_widgets[prop].children[0].value, \n",
+ " \"has_unit\": simulation_properties_widgets[simulation_type_dropdown.value].properties_widgets[prop].children[1].value})\n",
+ " elif CONFIG[\"properties\"][prop][\"property_type\"] == \"JSON\":\n",
+ " json_string = simulation_properties_widgets[simulation_type_dropdown.value].properties_widgets[prop].value\n",
+ " json_string = json_string.replace(\"'\", '\"')\n",
+ " if json_string:\n",
+ " if utils.is_valid_json(json_string):\n",
+ " object_properties[prop] = json_string\n",
+ " else:\n",
+ " display(utils.Javascript(data = \"alert('There is a JSON property that is not a valid JSON object.')\"))\n",
+ " return\n",
+ " else:\n",
+ " object_properties[prop] = simulation_properties_widgets[simulation_type_dropdown.value].properties_widgets[prop].value\n",
+ " \n",
+ " if atomistic_model_selector.dropdown.value != -1:\n",
+ " object_parents.append(atomistic_model_selector.dropdown.value)\n",
+ "\n",
+ " object_parents.extend(code_selector.selector.value)\n",
+ " \n",
+ " simulation_object = utils.create_openbis_object(\n",
+ " OPENBIS_SESSION, type=simulation_openbis_type, \n",
+ " collection = experiment_selector.dropdown.value, \n",
+ " props = object_properties,\n",
+ " parents = object_parents\n",
+ " )\n",
+ "\n",
+ " utils.upload_datasets(OPENBIS_SESSION, simulation_object, simulation_dataset_upload, \"RAW_DATA\")\n",
+ " utils.upload_datasets(OPENBIS_SESSION, simulation_object, simulation_preview_upload, \"ELN_PREVIEW\")\n",
+ " utils.upload_datasets(OPENBIS_SESSION, simulation_object, simulation_images_upload, \"RAW_DATA\")\n",
+ " utils.upload_datasets(OPENBIS_SESSION, simulation_object, simulation_support_files_upload, \"RAW_DATA\")\n",
+ " display(utils.Javascript(data = \"alert('Upload successful!')\"))\n",
+ "\n",
+ "def enter_simulation_details(change):\n",
+ " with simulation_details_output:\n",
+ " clear_output()\n",
+ " display(Markdown(\"### Select molecules\"))\n",
+ " display(molecule_selector_list_output)\n",
+ " with molecule_selector_list_output:\n",
+ " display(molecule_selector_list) \n",
+ " display(add_remove_molecule_buttons_hbox)\n",
+ " display(Markdown(\"### Select reaction products\"))\n",
+ " display(product_selector_list_output)\n",
+ " with product_selector_list_output:\n",
+ " display(product_selector_list) \n",
+ " display(add_remove_product_buttons_hbox)\n",
+ " display(Markdown(\"### Select slab\"))\n",
+ " display(material_selection_radio_button)\n",
+ " display(material_selector)\n",
+ " \n",
+ " if is_automatic_checkbox.value:\n",
+ " display(Markdown(\"### Select simulation\"))\n",
+ " display(simulation_selector)\n",
+ " else:\n",
+ " display(Markdown(\"### Select simulation type\"))\n",
+ " display(simulation_type_dropdown)\n",
+ " display(simulation_properties_output) \n",
+ " display(Markdown(\"### Select atomistic model\"))\n",
+ " display(atomistic_model_selector)\n",
+ " display(Markdown(\"### Select code\"))\n",
+ " display(code_selector)\n",
+ " display(Markdown(\"### Upload dataset\"))\n",
+ " display(simulation_dataset_upload)\n",
+ " display(Markdown(\"### Upload image preview\"))\n",
+ " display(simulation_preview_upload)\n",
+ " display(Markdown(\"### Upload other images\"))\n",
+ " display(simulation_images_upload)\n",
+ " display(Markdown(\"### Upload other support files\"))\n",
+ " display(simulation_support_files_upload)\n",
+ "\n",
+ "def load_simulation_properties_widgets(change):\n",
+ " with simulation_properties_output:\n",
+ " clear_output()\n",
+ " if simulation_type_dropdown.value != \"Select an option...\":\n",
+ " display(Markdown(\"### Enter simulation properties\"))\n",
+ " display(simulation_properties_widgets[simulation_type_dropdown.value])\n",
+ "\n",
+ "def load_structure_material(change):\n",
+ " if simulation_selector.dropdown.value != -1:\n",
+ " simulation_pk = simulation_selector.dropdown.value\n",
+ " simulation_uuid = load_node(simulation_pk).uuid\n",
+ " first_structure_uuid = aiida_utils.original_structure(simulation_uuid)\n",
+ " first_structure_extras = load_node(first_structure_uuid).extras\n",
+ " if first_structure_extras[\"eln\"][\"data_type\"] == \"cdxml\":\n",
+ " add_product_widget(None)\n",
+ " product_selector_list.selectors[0].dropdown.value = first_structure_extras[\"eln\"][\"sample_uuid\"]\n",
+ " else:\n",
+ " add_molecule_widget(None)\n",
+ " molecule_selector_list.selectors[0].dropdown.value = first_structure_extras[\"eln\"][\"sample_uuid\"]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Send simulation to openBIS"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Select experiment"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "display(experiment_selector)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Simulation details"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "display(is_automatic_checkbox)\n",
+ "display(simulation_details_output)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Save simulation workchain"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "display(save_close_buttons_hbox)\n",
+ "display(increase_buttons_size)\n",
+ "is_automatic_checkbox.observe(enter_simulation_details, names = 'value')\n",
+ "enter_simulation_details(None)\n",
+ "atomistic_model_selector.dropdown.observe(atomistic_model_selector.load_metadata, names = 'value')\n",
+ "simulation_selector.dropdown.observe(load_structure_material, names = 'value')\n",
+ "simulation_type_dropdown.observe(load_simulation_properties_widgets, names = 'value')\n",
+ "material_selection_radio_button.observe(select_material_radio_change, names='value')\n",
+ "material_selector.dropdown.observe(load_material_metadata, names = 'value')\n",
+ "add_molecule_button.on_click(add_molecule_widget)\n",
+ "remove_molecule_button.on_click(remove_molecule_widget)\n",
+ "add_product_button.on_click(add_product_widget)\n",
+ "remove_product_button.on_click(remove_product_widget)\n",
+ "create_button.on_click(create_simulation_openbis)\n",
+ "quit_button.on_click(close_notebook)"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "base",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.9.13"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/Notebooks/connection_to_openbis/aiida_utils.py b/Notebooks/connection_to_openbis/aiida_utils.py
index 91c65cc8..df97ce2a 100644
--- a/Notebooks/connection_to_openbis/aiida_utils.py
+++ b/Notebooks/connection_to_openbis/aiida_utils.py
@@ -492,8 +492,10 @@ def structure_to_atomistic_model(openbis_session, structure_uuid, uuids):
dictionary={
'$name': ase_geo.get_chemical_formula(),
'wfms_uuid': structure.uuid,
- 'structure': json.dumps(encode(ase_geo))
+ 'volume': structure.get_cell_volume(),
+ 'cell': json.dumps({"cell": structure.cell})
}
+
if dimensionality:
dictionary["dimensionality"] = int(dimensionality[0])
dictionary["periodic_boundary_conditions"] = [bool(i) for i in dimensionality[1]]
@@ -512,6 +514,16 @@ def structure_to_atomistic_model(openbis_session, structure_uuid, uuids):
files = [geo_to_png(ase_geo)]
)
+ structure_json = encode(ase_geo)
+ utils.create_json(structure_json, "structure_json.json")
+ utils.create_openbis_dataset(
+ openbis_session,
+ type = "RAW_DATA",
+ sample = obobject,
+ files = ["structure_json.json"]
+ )
+ os.remove("structure_json.json")
+
return obobject
def create_obis_object(obtype=None,parameters=None):
@@ -825,7 +837,16 @@ def Cp2kGeoOptWorkChain_export(openbis_session, experiment_id, workchain_uuid, u
sys_params = workchain.inputs.sys_params.get_dict()
dft_params = workchain.inputs.dft_params.get_dict()
code = workchain.inputs.code.description
- output_parameters = workchain.outputs.output_parameters.get_dict()
+
+ properties=['energy','energy_scf','energy_units','bandgap_spin1_au','bandgap_spin2_au']
+ try:
+ all_output_parameters = workchain.outputs.dft_output_parameters.get_dict()
+ except:
+ all_output_parameters = workchain.outputs.output_parameters.get_dict()
+ output_parameters = {key: all_output_parameters[key] for key in properties if key in all_output_parameters}
+ step_info={key: values[-1] for key, values in all_output_parameters['motion_step_info'].items()}
+ output_parameters.update(step_info)
+
input_parameters = {}
try:
input_parameters = workchain.outputs.final_input_parameters.get_dict()
@@ -893,11 +914,16 @@ def Cp2kStmWorkChain_export(openbis_session, experiment_id, workchain_uuid, uuid
spm_params = workchain.inputs.spm_params.get_dict()
# cp2k_code = workchain.inputs.cp2k_code.description
spm_code=workchain.inputs.spm_code.description
- output_parameters = {}
+
+ properties=['energy','energy_scf','energy_units','bandgap_spin1_au','bandgap_spin2_au']
try:
- output_parameters = workchain.outputs.dft_output_parameters.get_dict()
- except NotExistentAttributeError:
- pass
+ all_output_parameters = workchain.outputs.dft_output_parameters.get_dict()
+ except:
+ all_output_parameters = workchain.outputs.output_parameters.get_dict()
+ output_parameters = {key: all_output_parameters[key] for key in properties if key in all_output_parameters}
+ step_info={key: values[-1] for key, values in all_output_parameters['motion_step_info'].items()}
+ output_parameters.update(step_info)
+
input_parameters = {}
dft_object_parameters = get_dft_parameters_cp2k(spm_code, dft_params)
diff --git a/Notebooks/connection_to_openbis/config.json b/Notebooks/connection_to_openbis/config.json
index 66fe7a5c..a6cad897 100644
--- a/Notebooks/connection_to_openbis/config.json
+++ b/Notebooks/connection_to_openbis/config.json
@@ -1226,6 +1226,8 @@
".fa-home {font-size: 2em !important; /* Increase icon size */}",
".fa-times {font-size: 2em !important; /* Increase icon size */}",
".fa-download {font-size: 2em !important; /* Increase icon size */}",
+ ".fa-arrow-right {font-size: 2em !important; /* Increase icon size */}",
+ ".fa-arrow-down {font-size: 2em !important; /* Increase icon size */}",
""
],
"default_image_filepath": "images/white_screen.jpg"
diff --git a/Notebooks/connection_to_openbis/create_analysis.ipynb b/Notebooks/connection_to_openbis/create_analysis.ipynb
index adaf47c7..7ece8524 100644
--- a/Notebooks/connection_to_openbis/create_analysis.ipynb
+++ b/Notebooks/connection_to_openbis/create_analysis.ipynb
@@ -70,20 +70,20 @@
" analysis_props[prop] = analysis_widgets.properties_widgets[prop].value\n",
" \n",
" project_permid = project_selector.dropdown.value\n",
- " project_results_collection = OPENBIS_SESSION.get_collections(project = project_permid, code = \"ANALYSIS_COLLECTION\")\n",
+ " project_analysis_collection = OPENBIS_SESSION.get_collections(project = project_permid, code = \"ANALYSIS_COLLECTION\")\n",
" analysis_parents = []\n",
" analysis_parents.extend(list(measurements_selector.selector.value))\n",
" analysis_parents.extend(list(simulations_selector.selector.value))\n",
" analysis_parents.extend(list(codes_selector.selector.value))\n",
" \n",
- " if len(project_results_collection) == 0:\n",
+ " if len(project_analysis_collection) == 0:\n",
" analysis_collection = utils.create_openbis_collection(\n",
" OPENBIS_SESSION, \n",
" project = project_selector.dropdown.value, \n",
- " code = \"ANALISYS_COLLECTION\", type = \"COLLECTION\", props = {\"$name\": \"Analysis\"}\n",
+ " code = \"ANALYSIS_COLLECTION\", type = \"COLLECTION\", props = {\"$name\": \"Analysis\"}\n",
" )\n",
" else:\n",
- " analysis_collection = project_results_collection[0]\n",
+ " analysis_collection = project_analysis_collection[0]\n",
"\n",
" results_object = utils.create_openbis_object(\n",
" OPENBIS_SESSION, type=\"ANALYSIS\", collection=analysis_collection, \n",
diff --git a/Notebooks/connection_to_openbis/export_openbis_object.ipynb b/Notebooks/connection_to_openbis/export_openbis_object.ipynb
index 75915ddd..55278a70 100644
--- a/Notebooks/connection_to_openbis/export_openbis_object.ipynb
+++ b/Notebooks/connection_to_openbis/export_openbis_object.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
@@ -12,7 +12,8 @@
"import utils\n",
"import os\n",
"import base64\n",
- "import json"
+ "import json\n",
+ "import google.generativeai as genai"
]
},
{
@@ -30,6 +31,28 @@
"publication_selector = widgets.PublicationSelectionWidget()\n",
"publication_selector.load_dropdown_box()\n",
"\n",
+ "prompt_textarea = utils.Textarea(\n",
+ " description = \"Prompt\", \n",
+ " layout = ipw.Layout(width = '980px', height = '300px'),\n",
+ " style = {\"description_width\": \"110px\"}\n",
+ ")\n",
+ "\n",
+ "model_answer_textarea = utils.Textarea(\n",
+ " description = \"Answer\", \n",
+ " layout = ipw.Layout(width = '980px', height = '300px'),\n",
+ " style = {\"description_width\": \"110px\"}\n",
+ ")\n",
+ "\n",
+ "enter_button = utils.Button(\n",
+ " description = '', disabled = False, button_style = '', \n",
+ " tooltip = 'Enter', icon = 'arrow-right', layout = ipw.Layout(width = '100px', height = '50px')\n",
+ ")\n",
+ "\n",
+ "load_model_button = utils.Button(\n",
+ " description = '', disabled = False, button_style = '', \n",
+ " tooltip = 'Load chatbot', icon = 'arrow-down', layout = ipw.Layout(width = '100px', height = '50px')\n",
+ ")\n",
+ "\n",
"download_button = utils.Button(\n",
" description = '', disabled = False, button_style = '', \n",
" tooltip = 'Download', icon = 'download', layout = ipw.Layout(width = '100px', height = '50px')\n",
@@ -40,8 +63,17 @@
" tooltip = 'Main menu', icon = 'home', layout = ipw.Layout(width = '100px', height = '50px')\n",
")\n",
"\n",
- "download_close_buttons_hbox = ipw.HBox([download_button, quit_button])\n",
- "increase_buttons_size = utils.HTML(data = ''.join(CONFIG[\"save_home_buttons_settings\"]))"
+ "load_download_buttons_hbox = ipw.HBox([load_model_button, download_button])\n",
+ "\n",
+ "increase_buttons_size = utils.HTML(data = ''.join(CONFIG[\"save_home_buttons_settings\"]))\n",
+ "\n",
+ "# Google Gemini 1.5 Flash\n",
+ "google_api_key = utils.read_json(\"/home/jovyan/gemini_api.json\")\n",
+ "genai.configure(api_key=google_api_key[\"api_key\"])\n",
+ "model = genai.GenerativeModel(\"gemini-1.5-flash\") # gemini-1.5-flash\n",
+ "\n",
+ "# Start the chatbot\n",
+ "chat = model.start_chat()"
]
},
{
@@ -53,9 +85,16 @@
"def close_notebook(b):\n",
" display(utils.Javascript(data = 'window.location.replace(\"home.ipynb\")'))\n",
"\n",
- "def download_openbis_object_metadata(b):\n",
- " if publication_selector.dropdown_boxes.children[0].value == -1:\n",
- " return\n",
+ "def ask_chatbot(change):\n",
+ " model_answer_textarea.value = \"\"\n",
+ " prompt = prompt_textarea.value\n",
+ " response = chat.send_message(prompt, stream = True)\n",
+ " for chunk in response:\n",
+ " model_answer_textarea.value = model_answer_textarea.value + chunk.text\n",
+ " \n",
+ "def get_openbis_object_metadata():\n",
+ " if publication_selector.dropdown.value == -1:\n",
+ " return None\n",
" else:\n",
" openbis_selected_object_permid = publication_selector.dropdown_boxes.children[0].value\n",
" openbis_selected_object = OPENBIS_SESSION.get_sample(openbis_selected_object_permid)\n",
@@ -64,12 +103,25 @@
" parent_child_relationships = openbis_selected_object.props.all()\n",
" parent_child_relationships[\"perm_id\"] = openbis_selected_object_permid\n",
" parent_child_relationships[\"type\"] = str(openbis_selected_object.type)\n",
+ " openbis_objects_history = {}\n",
" selected_object_schema = utils.get_parent_child_relationships_nested(\n",
- " OPENBIS_SESSION, openbis_selected_object, parent_child_relationships\n",
+ " OPENBIS_SESSION, openbis_selected_object, parent_child_relationships, openbis_objects_history\n",
" )\n",
- " \n",
+ "\n",
+ " return selected_object_schema\n",
+ "\n",
+ "def load_chatbot(b):\n",
+ " data_dict = get_openbis_object_metadata()\n",
+ " if data_dict:\n",
+ " json_data = json.dumps(data_dict, indent=4)\n",
+ " response = chat.send_message(f\"This is the graph of my study: {json_data}\")\n",
+ " display(utils.Javascript(data = \"alert('Chatbot is ready!')\"))\n",
+ "\n",
+ "def download_metadata(b):\n",
+ " data_dict = get_openbis_object_metadata()\n",
+ " if data_dict:\n",
" # Export to JSON\n",
- " json_data = json.dumps(selected_object_schema, indent=4).encode('utf-8')\n",
+ " json_data = json.dumps(data_dict, indent=4).encode('utf-8')\n",
" json_data = base64.b64encode(json_data).decode('utf-8')\n",
" \n",
" display(Javascript(f\"\"\"\n",
@@ -79,8 +131,7 @@
" document.body.appendChild(a);\n",
" a.click();\n",
" document.body.removeChild(a);\n",
- " \"\"\"))\n",
- " display(Markdown(f\"[You .]({notebook_link})\"))"
+ " \"\"\"))"
]
},
{
@@ -103,10 +154,16 @@
"metadata": {},
"outputs": [],
"source": [
- "display(publication_selector)\n",
- "display(download_close_buttons_hbox)\n",
"display(increase_buttons_size)\n",
- "download_button.on_click(download_openbis_object_metadata)\n",
+ "display(publication_selector)\n",
+ "display(load_download_buttons_hbox)\n",
+ "display(prompt_textarea)\n",
+ "display(enter_button)\n",
+ "display(model_answer_textarea)\n",
+ "display(quit_button)\n",
+ "load_model_button.on_click(load_chatbot)\n",
+ "download_button.on_click(download_metadata)\n",
+ "enter_button.on_click(ask_chatbot)\n",
"quit_button.on_click(close_notebook)"
]
}
diff --git a/Notebooks/connection_to_openbis/find_simulations.ipynb b/Notebooks/connection_to_openbis/find_simulations.ipynb
index bef7baba..b7e23f98 100644
--- a/Notebooks/connection_to_openbis/find_simulations.ipynb
+++ b/Notebooks/connection_to_openbis/find_simulations.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
@@ -20,7 +20,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
diff --git a/Notebooks/connection_to_openbis/home.ipynb b/Notebooks/connection_to_openbis/home.ipynb
index 50cab7c7..fa266541 100644
--- a/Notebooks/connection_to_openbis/home.ipynb
+++ b/Notebooks/connection_to_openbis/home.ipynb
@@ -73,7 +73,7 @@
],
"metadata": {
"kernelspec": {
- "display_name": "Python 3 (ipykernel)",
+ "display_name": "base",
"language": "python",
"name": "python3"
},
diff --git a/Notebooks/connection_to_openbis/sample_measurement.ipynb b/Notebooks/connection_to_openbis/sample_measurement.ipynb
index 9ac99e67..94e35de4 100644
--- a/Notebooks/connection_to_openbis/sample_measurement.ipynb
+++ b/Notebooks/connection_to_openbis/sample_measurement.ipynb
@@ -143,18 +143,10 @@
"\n",
"def upload_measurements_to_openbis(b):\n",
" sample_object = OPENBIS_SESSION.get_object(sample_selector.dropdown_boxes.children[0].value)\n",
- "\n",
- " # Get measurements collection if available\n",
- " measurements_collection = next(\n",
- " (OPENBIS_SESSION.get_object(child_id).collection \n",
- " for child_id in sample_object.children \n",
- " if OPENBIS_SESSION.get_object(child_id).type in [\"1D_MEASUREMENT\", \"2D_MEASUREMENT\"]), \n",
- " None\n",
- " )\n",
" \n",
- " # Get sample project from parent\n",
- " sample_project = next(\n",
- " (OPENBIS_SESSION.get_object(parent_id).project \n",
+ " # Get sample experiment from parent\n",
+ " sample_experiment = next(\n",
+ " (OPENBIS_SESSION.get_object(parent_id).experiment\n",
" for parent_id in sample_object.parents \n",
" if OPENBIS_SESSION.get_object(parent_id).type in SAMPLE_PREPARATION_SAMPLE_TYPES), \n",
" None\n",
@@ -166,27 +158,17 @@
" correct_folder = all(f\".{filename.split('.')[-1]}\" in MEASUREMENT_FILE_EXTENSIONS for filename in data_files)\n",
" \n",
" if correct_folder:\n",
- " if measurements_collection:\n",
- " measurements_collection = f\"{sample_project.identifier}/{measurements_collection}\"\n",
- " measurements_collection = OPENBIS_SESSION.get_collection(measurements_collection)\n",
+ " if not sample_experiment:\n",
+ " print(\"Sample does not belong to any project yet.\")\n",
+ " return\n",
" else:\n",
- " if not sample_project:\n",
- " print(\"Sample does not belong to any project yet.\")\n",
- " return\n",
- " collection_props = {\"$name\": f\"Measurements from Sample {sample_object.props['$name']}\", \"$default_collection_view\": \"IMAGING_GALLERY_VIEW\"}\n",
- " measurements_collection = utils.create_openbis_collection(\n",
- " OPENBIS_SESSION,\n",
- " code=f\"MEASUREMENTS_COLLECTION_{sample_object.code}\", \n",
- " type=\"COLLECTION\", project=sample_project, \n",
- " props=collection_props\n",
+ " nanonis_importer.upload_measurements_into_openbis(\n",
+ " SESSION_DATA['url'], data_folder, \n",
+ " sample_experiment.permId, sample_object.permId, \n",
+ " instrument_selector.dropdown.value\n",
" )\n",
- " \n",
- " nanonis_importer.upload_measurements_into_openbis(\n",
- " SESSION_DATA['url'], data_folder, \n",
- " measurements_collection.permId, sample_object.permId, \n",
- " instrument_selector.dropdown.value\n",
- " )\n",
- " display(utils.Javascript(data = \"alert('Upload successful!')\"))\n",
+ " display(utils.Javascript(data = \"alert('Upload successful!')\"))\n",
+ " \n",
" else:\n",
" output_message = f\"Folder contains unrecognised files. Please remove files with extensions other than: {', '.join(MEASUREMENT_FILE_EXTENSIONS)}.\"\n",
" display(utils.Javascript(data = f\"alert({output_message})\"))\n"
diff --git a/Notebooks/connection_to_openbis/structures/structure.cdxml b/Notebooks/connection_to_openbis/structures/structure.cdxml
new file mode 100644
index 00000000..0b26e09e
--- /dev/null
+++ b/Notebooks/connection_to_openbis/structures/structure.cdxml
@@ -0,0 +1,590 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+BrBr
\ No newline at end of file
diff --git a/Notebooks/connection_to_openbis/structures/structure.png b/Notebooks/connection_to_openbis/structures/structure.png
new file mode 100644
index 00000000..94657db7
Binary files /dev/null and b/Notebooks/connection_to_openbis/structures/structure.png differ
diff --git a/Notebooks/connection_to_openbis/utils.py b/Notebooks/connection_to_openbis/utils.py
index c6e21284..59905b6c 100644
--- a/Notebooks/connection_to_openbis/utils.py
+++ b/Notebooks/connection_to_openbis/utils.py
@@ -216,7 +216,15 @@ def get_next_experiment_code(openbis_session):
def create_experiment_in_openbis(openbis_session, project_id, experiment_name):
experiment_code = get_next_experiment_code(openbis_session)
- experiment = openbis_session.new_experiment(code = experiment_code, type = "EXPERIMENT", project = project_id, props = {"$name": experiment_name})
+ experiment = openbis_session.new_experiment(
+ code = experiment_code,
+ type = "EXPERIMENT",
+ project = project_id,
+ props = {
+ "$name": experiment_name,
+ "$default_collection_view": "IMAGING_GALLERY_VIEW"
+ }
+ )
experiment.save()
def create_openbis_dataset(openbis_session, **kwargs):
@@ -255,7 +263,7 @@ def is_nan(var):
"""Function to verify whether it is a NaN."""
return var != var
-def get_parent_child_relationships_nested(openbis_session, selected_object, parent_child_relationships=None):
+def get_parent_child_relationships_nested(openbis_session, selected_object, parent_child_relationships = None, object_history = None):
"""
Function to get all the parent-child relations together with the information about the objects from openBIS.
This is a recursive function because the objects inside openBIS are like trees containing multiple
@@ -276,6 +284,12 @@ def get_parent_child_relationships_nested(openbis_session, selected_object, pare
"""
if parent_child_relationships is None:
parent_child_relationships = {}
+
+ if object_history is None:
+ object_history = {}
+
+ if selected_object.identifier not in object_history:
+ object_history[selected_object.identifier] = selected_object
# Fetch parents of the current publication
parents = selected_object.parents
@@ -284,7 +298,11 @@ def get_parent_child_relationships_nested(openbis_session, selected_object, pare
# Add current parents to the dictionary with child-parent relationships
parent_child_relationships["has_part"] = []
for parent_id in parents:
- parent = openbis_session.get_sample(parent_id)
+ if parent_id in object_history:
+ parent = object_history[parent_id]
+ else:
+ parent = openbis_session.get_sample(parent_id)
+ object_history[parent.identifier] = parent
parent_props = parent.props.all()
for prop in parent_props:
if openbis_session.get_property_type(prop).dataType == "SAMPLE" and parent_props[prop] is not None:
@@ -292,11 +310,11 @@ def get_parent_child_relationships_nested(openbis_session, selected_object, pare
parent_props[prop] = {"perm_id": parent_props[prop]}
parent_props[prop]["type"] = str(prop_object.type)
parent_props[prop].update(prop_object.props.all())
- parent_props[prop] = get_parent_child_relationships_nested(openbis_session, prop_object, parent_props[prop])
+ parent_props[prop] = get_parent_child_relationships_nested(openbis_session, prop_object, parent_props[prop], object_history)
parent_props["perm_id"] = parent.permId
parent_props["type"] = str(parent.type)
- parent_props = get_parent_child_relationships_nested(openbis_session, parent, parent_props)
+ parent_props = get_parent_child_relationships_nested(openbis_session, parent, parent_props, object_history)
parent_child_relationships["has_part"].append(parent_props)
return parent_child_relationships
\ No newline at end of file
diff --git a/Notebooks/connection_to_openbis/widgets.py b/Notebooks/connection_to_openbis/widgets.py
index 965301d9..c76594e6 100644
--- a/Notebooks/connection_to_openbis/widgets.py
+++ b/Notebooks/connection_to_openbis/widgets.py
@@ -1093,7 +1093,7 @@ def cancel_new_experiment_button_on_click(self, b):
clear_output()
def save_new_experiment_button_on_click(self, b):
- utils.create_experiment_in_openbis(OPENBIS_SESSION, self.projects_dropdown_boxes.children[0].children[0].value, self.new_experiment_name_textbox.value)
+ utils.create_experiment_in_openbis(OPENBIS_SESSION, self.projects_dropdown_boxes.dropdown.value, self.new_experiment_name_textbox.value)
self.load_dropdown_box()
with self.add_experiment_output:
clear_output()