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

Fix/reuse gw #228

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 100 additions & 89 deletions submit_gw_ic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand All @@ -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",
")"
]
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -237,51 +240,69 @@
"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",
" only_one_molecule = (\n",
" 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",
" \"<p style='font-weight:bold; color:red;'>Check the molecule indices</p>\"\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\")"
]
},
{
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -372,6 +382,7 @@
"display(\n",
" output,\n",
" description,\n",
" error_msg,\n",
" ipw.HBox(\n",
" [\n",
" ipw.VBox(\n",
Expand All @@ -395,7 +406,7 @@
" ]\n",
" ),\n",
" estimate_nodes_button,\n",
" resources,\n",
" code_input_widget,\n",
" btn_submit_gw,\n",
")"
]
Expand Down
14 changes: 13 additions & 1 deletion surfaces_tools/widgets/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"

Expand Down Expand Up @@ -768,4 +775,9 @@ def smearing_enabled(self):
constraints.ConstraintsWidget,
PhononsWidget,
],
"GwIc": [
StructureInfoWidget,
VdwSelectorWidget,
UksSectionWidget,
],
}
1 change: 1 addition & 0 deletions surfaces_tools/widgets/search_structures_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"CP2K_NEB": "view_neb.ipynb",
"CP2K_Replica": "view_replica.ipynb",
"ReplicaWorkChain": "view_replica.ipynb",
"CP2K_GWIC": "view_gw_ic.ipynb",
}


Expand Down