Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Centralized notebook for managing AiiDA codes #188

Merged
merged 14 commits into from
Jan 10, 2025
Merged
157 changes: 157 additions & 0 deletions code_setup.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from aiida import load_profile\n",
"\n",
"load_profile();"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# AiiDAlab Code Setup\n",
"\n",
"This page provides an interface for creating AiiDA codes on local or remote machines."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "html"
}
},
"outputs": [],
"source": [
"%%html\n",
"\n",
"<style>\n",
" .output_subarea {\n",
" max-width: none !important;\n",
" }\n",
" .header-tr {\n",
" column-gap: 5px;\n",
" }\n",
" .th {\n",
" padding: 2px 5px;\n",
" font-weight: bold;\n",
" color: #fff;\n",
" text-align: center;\n",
" background-color: #000;\n",
" }\n",
" .tr:hover {\n",
" background-color: #f5f5f5;\n",
" }\n",
"</style>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create new code"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import ipywidgets as ipw\n",
"from aiidalab_widgets_base.computational_resources import _ResourceSetupBaseWidget\n",
"from aiidalab_widgets_base.utils import StatusHTML\n",
"\n",
"setup_message = StatusHTML(clear_after=15)\n",
"\n",
"widget = _ResourceSetupBaseWidget()\n",
"ipw.dlink(\n",
" (widget, \"message\"),\n",
" (setup_message, \"message\"),\n",
")\n",
"\n",
"ipw.VBox(\n",
" children=[\n",
" widget,\n",
" setup_message,\n",
" ]\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Available codes"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from home.code_setup import create_paginated_table, fetch_code_data\n",
"\n",
"output = ipw.Output()\n",
"\n",
"\n",
"def render():\n",
" data = fetch_code_data()\n",
" paginated_table = create_paginated_table(data)\n",
" output.clear_output()\n",
" with output:\n",
" display(paginated_table)\n",
"\n",
"\n",
"display(output)\n",
"render()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def on_code_setup_message_change(change):\n",
" if \"created\" in change[\"new\"]:\n",
" render()\n",
"\n",
"\n",
"widget.aiida_code_setup.observe(\n",
" on_code_setup_message_change,\n",
" \"message\",\n",
Comment on lines +172 to +174
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why observe the message?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a code was created ("created" in message), I rerender the table to refresh and pick up the new code. If none create, no need to refresh.

")"
]
}
],
"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
}
Loading
Loading