diff --git a/submit_gw_ic.ipynb b/submit_gw_ic.ipynb index 4ea2cae..3e962b3 100644 --- a/submit_gw_ic.ipynb +++ b/submit_gw_ic.ipynb @@ -37,12 +37,7 @@ "from aiida import orm, plugins\n", "\n", "# Custom imports.\n", - "from surfaces_tools.widgets import (\n", - " analyze_structure,\n", - " cdxml,\n", - " computational_resources,\n", - " inputs,\n", - ")" + "from surfaces_tools.widgets import analyze_structure, computational_resources, inputs" ] }, { @@ -67,17 +62,16 @@ " importers=[\n", " awb.StructureBrowserWidget(title=\"AiiDA database\"),\n", " awb.StructureUploadWidget(title=\"Import from computer\"),\n", - " awb.SmilesWidget(title=\"From SMILES\"),\n", - " cdxml.CdxmlUpload2GnrWidget(title=\"CDXML\"),\n", " ],\n", " storable=False,\n", " node_class=\"StructureData\",\n", ")\n", - "display(structure_selector)\n", + "\n", "ipw.dlink((structure_selector, \"structure\"), (input_details, \"structure\"))\n", + "display(structure_selector)\n", "\n", "# Code.\n", - "resources = awb.ComputationalResourcesWidget(\n", + "code_input_widget = awb.ComputationalResourcesWidget(\n", " description=\"CP2K code:\", default_calc_job_plugin=\"cp2k\"\n", ")" ] @@ -97,20 +91,6 @@ ")\n", "\n", "\n", - "# Multiplicity\n", - "multiplicity = ipw.IntText(value=1, description=\"Multiplicity\", disabled=False)\n", - "# UKS\n", - "uks = ipw.Checkbox(value=False, description=\"UKS\", disabled=False, indent=False)\n", - "\n", - "# spin guess\n", - "spins_up = ipw.Text(\n", - " value=\"\", placeholder=\"1 2 10..13\", description=\"Spins U:\", disabled=False\n", - ")\n", - "\n", - "spins_down = ipw.Text(\n", - " value=\"\", placeholder=\"3 4 14..17\", description=\"Spins D:\", disabled=False\n", - ")\n", - "\n", "# geometry mode\n", "geo_mode = ipw.Dropdown(\n", " options=[\"ads_geo\", \"gas_opt\"],\n", @@ -135,6 +115,17 @@ " style={\"description_width\": \"initial\"},\n", ")\n", "\n", + "# molecule\n", + "molecule = ipw.Text(\n", + " value=\"\",\n", + " placeholder=\"1..2\",\n", + " description=\"Molecule ids:\",\n", + " disabled=False,\n", + " style={\"description_width\": \"initial\"},\n", + ")\n", + "\n", + "# error message\n", + "error_msg = ipw.HTML(value=\"\")\n", "\n", "# description adsorption height\n", "html_ads_height = ipw.HTML(\n", @@ -153,10 +144,27 @@ "metadata": {}, "outputs": [], "source": [ + "ipw.dlink((code_input_widget, \"value\"), (input_details, \"selected_code\"))\n", + "\n", + "\n", "def get_builder_gw():\n", + " with output:\n", + " clear_output()\n", + " if not structure_selector.structure_node:\n", + " can_submit, msg = False, \"Select a structure first.\"\n", + " elif not code_input_widget.value:\n", + " can_submit, msg = False, \"Select CP2K code.\"\n", + " else:\n", + " can_submit, msg, parameters = input_details.return_final_dictionary()\n", + "\n", + " if not can_submit:\n", + " with output:\n", + " print(msg)\n", + " return\n", " builder = Cp2kAdsorbedGwIcWorkChain.get_builder()\n", + " builder.metadata.label = \"CP2K_GWIC\"\n", " builder.metadata.description = description.value\n", - " builder.code = orm.load_code(resources.value)\n", + " builder.code = orm.load_code(code_input_widget.value)\n", " builder.geometry_mode = orm.Str(geo_mode.value)\n", "\n", " # Override automatic adsorption height.\n", @@ -165,22 +173,17 @@ "\n", " ase_geom = structure_selector.structure\n", "\n", - " # Spin guess.\n", - " mag_list = [0 for t in ase_geom]\n", - " if uks.value:\n", - " for i in awb.utils.string_range_to_list(spins_up.value)[0]:\n", - " mag_list[i] = 1\n", - " for i in string_range_to_list(spins_down.value)[0]:\n", - " mag_list[i] = -1\n", - "\n", - " builder.multiplicity = orm.Int(multiplicity.value)\n", - "\n", " builder.structure = structure_selector.structure_node\n", - " builder.magnetization_per_site = orm.List(list=mag_list)\n", - "\n", + " # builder.magnetization_per_site = orm.List(list=mag_list)\n", + " builder.dft_params = orm.Dict(parameters[\"dft_params\"])\n", + " builder.sys_params = orm.Dict(\n", + " {\"molecule_atoms\": awb.utils.string_range_to_list(molecule.value)[0]}\n", + " )\n", " builder.protocol = orm.Str(gw_type.value)\n", "\n", " builder.geometry_mode = orm.Str(geo_mode.value)\n", + " # builder.molecule_atoms = orm.List(awb.utils.string_range_to_list(molecule.value)[0])\n", + " builder.debug = orm.Bool(False)\n", "\n", " builder.options.scf = {\n", " \"max_wallclock_seconds\": resources_scf.walltime_seconds,\n", @@ -237,7 +240,29 @@ "output = ipw.Output()\n", "\n", "\n", - "def update_all(_=None):\n", + "def extract_details_on_adsorbed_molecule(all_atoms):\n", + " structure_analyzer = analyze_structure.StructureAnalyzer()\n", + " structure_analyzer.structure = all_atoms\n", + " molecule_indices = awb.utils.string_range_to_list(molecule.value)[0]\n", + "\n", + " if \"all_molecules\" in structure_analyzer.details:\n", + " if len(molecule_indices) == 0:\n", + " molecule_indices = [\n", + " item\n", + " for sublist in structure_analyzer.details[\"all_molecules\"]\n", + " for item in sublist\n", + " ]\n", + "\n", + " if len(molecule_indices) > 0:\n", + " molecule.value = awb.utils.list_to_string_range(molecule_indices)\n", + " structure_analyzer.structure = all_atoms[molecule_indices]\n", + " return structure_analyzer.details\n", + " else:\n", + " molecule.value = \"\"\n", + " return {}\n", + "\n", + "\n", + "def check_system(_=None):\n", " btn_submit_gw.btn_submit.disabled = False\n", " # check system\n", " only_one_molecule = input_details.details[\"system_type\"] == \"SlabXY\"\n", @@ -245,43 +270,39 @@ " only_one_molecule or input_details.details[\"system_type\"] == \"Molecule\"\n", " )\n", " only_one_molecule = (\n", - " only_one_molecule and len(input_details.details[\"all_molecules\"]) == 1\n", + " only_one_molecule and len(awb.utils.string_range_to_list(molecule.value)[0]) > 0\n", + " )\n", + " error_msg.value = (\n", + " \"

Check the molecule indices

\"\n", " )\n", - " msg = \"GW for this system not implemented\"\n", " if only_one_molecule:\n", " btn_submit_gw.btn_submit.disabled = False\n", - " msg = \"\"\n", - " spins_up.value = awb.utils.list_to_string_range(input_details.details[\"spins_up\"])\n", - " spins_down.value = awb.utils.list_to_string_range(\n", - " input_details.details[\"spins_down\"]\n", - " )\n", + " error_msg.value = \"\"\n", + "\n", + "\n", + "def update_all(name=None):\n", + "\n", + " if name[\"name\"] == \"structure\":\n", + " input_details.gwic = True\n", + " molecule.value = \"\"\n", + " error_msg.value = \"\"\n", + " check_system()\n", + " if structure_selector.structure is not None:\n", + " extract_details_on_adsorbed_molecule(structure_selector.structure)\n", " with output:\n", " clear_output()\n", - " print(msg)\n", - "\n", - " if uks.value:\n", - " to_display = [\n", - " gw_type,\n", - " geo_mode,\n", - " ipw.HBox([ads_height, html_ads_height]),\n", - " uks,\n", - " spins_up,\n", - " spins_down,\n", - " multiplicity,\n", - " description,\n", - " ]\n", - " else:\n", - " to_display = [\n", - " gw_type,\n", - " geo_mode,\n", - " ipw.HBox([ads_height, html_ads_height]),\n", - " uks,\n", - " ]\n", + " to_display = [\n", + " gw_type,\n", + " geo_mode,\n", + " ipw.HBox([ads_height, html_ads_height]),\n", + " molecule,\n", + " input_details,\n", + " ]\n", " display(ipw.VBox(to_display))\n", "\n", "\n", "structure_selector.observe(update_all, names=\"structure\")\n", - "uks.observe(update_all, names=\"value\")" + "molecule.observe(check_system, names=\"value\")" ] }, { @@ -311,22 +332,6 @@ "resources_estimation_gw.link_to_resources_widget(resources_gw)\n", "resources_estimation_ic.link_to_resources_widget(resources_ic)\n", "\n", - "\n", - "def extract_details_on_adsorbed_molecule(all_atoms):\n", - " structure_analyzer = analyze_structure.StructureAnalyzer()\n", - " structure_analyzer.structure = all_atoms\n", - " if \"all_molecules\" in structure_analyzer.details:\n", - " molecules_indices = [\n", - " item\n", - " for sublist in structure_analyzer.details[\"all_molecules\"]\n", - " for item in sublist\n", - " ]\n", - " structure_analyzer.structure = all_atoms[molecules_indices]\n", - " return structure_analyzer.details\n", - " else:\n", - " return {}\n", - "\n", - "\n", "# Link viewer to resources estimation widgets.\n", "ipw.dlink(\n", " (structure_selector, \"structure\"),\n", @@ -345,14 +350,19 @@ ")\n", "\n", "# Link code selector to resources estimation widgets.\n", - "_ = ipw.dlink((resources, \"value\"), (resources_estimation_scf, \"selected_code\"))\n", - "_ = ipw.dlink((resources, \"value\"), (resources_estimation_gw, \"selected_code\"))\n", - "_ = ipw.dlink((resources, \"value\"), (resources_estimation_ic, \"selected_code\"))\n", + "_ = ipw.dlink((code_input_widget, \"value\"), (resources_estimation_scf, \"selected_code\"))\n", + "_ = ipw.dlink((code_input_widget, \"value\"), (resources_estimation_gw, \"selected_code\"))\n", + "_ = ipw.dlink((code_input_widget, \"value\"), (resources_estimation_ic, \"selected_code\"))\n", "\n", "# Link UKS\n", - "_ = ipw.dlink((uks, \"value\"), (resources_estimation_scf, \"uks\"))\n", - "_ = ipw.dlink((uks, \"value\"), (resources_estimation_gw, \"uks\"))\n", - "_ = ipw.dlink((uks, \"value\"), (resources_estimation_ic, \"uks\"))\n", + "_ = ipw.dlink((input_details, \"uks\"), (resources_estimation_scf, \"uks\"))\n", + "_ = ipw.dlink((input_details, \"uks\"), (resources_estimation_gw, \"uks\"))\n", + "_ = ipw.dlink((input_details, \"uks\"), (resources_estimation_ic, \"uks\"))\n", + "\n", + "# Link details\n", + "_ = ipw.dlink((input_details, \"details\"), (resources_estimation_scf, \"details\"))\n", + "_ = ipw.dlink((input_details, \"details\"), (resources_estimation_gw, \"details\"))\n", + "_ = ipw.dlink((input_details, \"details\"), (resources_estimation_ic, \"details\"))\n", "\n", "# Estimate all resources\n", "estimate_nodes_button = ipw.Button(\n", @@ -372,6 +382,7 @@ "display(\n", " output,\n", " description,\n", + " error_msg,\n", " ipw.HBox(\n", " [\n", " ipw.VBox(\n", @@ -395,7 +406,7 @@ " ]\n", " ),\n", " estimate_nodes_button,\n", - " resources,\n", + " code_input_widget,\n", " btn_submit_gw,\n", ")" ] diff --git a/surfaces_tools/widgets/inputs.py b/surfaces_tools/widgets/inputs.py index c43e38d..c348efc 100644 --- a/surfaces_tools/widgets/inputs.py +++ b/surfaces_tools/widgets/inputs.py @@ -30,6 +30,7 @@ class InputDetails(ipw.VBox): do_cell_opt = tr.Bool() uks = tr.Bool() net_charge = tr.Int() + gwic = tr.Bool() neb = tr.Bool() # Set by app in case of neb calculation, to be linked to resources. replica = tr.Bool() # Set by app in case of replica chain calculation. phonons = tr.Bool() # Set by app in case of phonons calculation @@ -67,6 +68,10 @@ def __init__( def _default_neb(self): return False + @tr.default("gwic") + def _default_gwic(self): + return False + @tr.default("phonons") def _default_phonons(self): return False @@ -81,7 +86,7 @@ def _default_n_proc_replica(self): def _default_n_replica_per_group_trait(self): return 1 - @tr.observe("details", "neb", "replica", "phonons") + @tr.observe("details", "gwic", "neb", "replica", "phonons") def _observe_details(self, _=None): self.to_fix = [] self.net_charge = 0 @@ -97,6 +102,8 @@ def _observe_details(self, _=None): sys_type = "Replica" if self.phonons: sys_type = "Phonons" + if self.gwic: + sys_type = "GwIc" else: sys_type = "None" @@ -768,4 +775,9 @@ def smearing_enabled(self): constraints.ConstraintsWidget, PhononsWidget, ], + "GwIc": [ + StructureInfoWidget, + VdwSelectorWidget, + UksSectionWidget, + ], } diff --git a/surfaces_tools/widgets/search_structures_widget.py b/surfaces_tools/widgets/search_structures_widget.py index 2382b15..6660bae 100644 --- a/surfaces_tools/widgets/search_structures_widget.py +++ b/surfaces_tools/widgets/search_structures_widget.py @@ -19,6 +19,7 @@ "CP2K_NEB": "view_neb.ipynb", "CP2K_Replica": "view_replica.ipynb", "ReplicaWorkChain": "view_replica.ipynb", + "CP2K_GWIC": "view_gw_ic.ipynb", }