From 0c5bdaf78159669338d79777fc6a98116edffd16 Mon Sep 17 00:00:00 2001 From: Carlo Antonio Pignedoli Date: Wed, 10 Jul 2024 15:09:48 +0000 Subject: [PATCH 1/5] first tests done for reusing GW --- .../cp2k/adsorbed_gw_ic_workchain.py | 10 + .../workflows/cp2k/molecule_gw_workchain.py | 2 +- examples/workflows/aa | 431 ------------------ examples/workflows/example_cp2k_ads_gw_ic.py | 2 +- 4 files changed, 12 insertions(+), 433 deletions(-) delete mode 100755 examples/workflows/aa diff --git a/aiida_nanotech_empa/workflows/cp2k/adsorbed_gw_ic_workchain.py b/aiida_nanotech_empa/workflows/cp2k/adsorbed_gw_ic_workchain.py index d8fcad1..562d402 100644 --- a/aiida_nanotech_empa/workflows/cp2k/adsorbed_gw_ic_workchain.py +++ b/aiida_nanotech_empa/workflows/cp2k/adsorbed_gw_ic_workchain.py @@ -198,6 +198,13 @@ def define(cls, spec): required=False, help="Possibilities: ads_geo, gas_opt", ) + spec.input( + "debug", + valid_type=orm.Bool, + default=lambda: orm.Bool(False), + required=False, + help="Run with fast parameters for debugging.", + ) spec.outline( cls.setup, @@ -264,6 +271,8 @@ def gas_opt(self): builder.magnetization_per_site = self.ctx.mol_mag_per_site builder.vdw = orm.Bool(True) builder.protocol = orm.Str("standard") + if self.inputs.debug: + builder.protocol = orm.Str("debug") builder.options = self.inputs.options.scf builder.metadata.description = "gas_opt" submitted_node = self.submit(builder) @@ -297,6 +306,7 @@ def ic(self): builder.options.scf = self.inputs.options.scf builder.options.gw = self.inputs.options.ic builder.metadata.description = "ic" + builder.debug = self.inputs.debug submitted_node = self.submit(builder) return engine.ToContext(ic=submitted_node) diff --git a/aiida_nanotech_empa/workflows/cp2k/molecule_gw_workchain.py b/aiida_nanotech_empa/workflows/cp2k/molecule_gw_workchain.py index 4777b9c..1905825 100644 --- a/aiida_nanotech_empa/workflows/cp2k/molecule_gw_workchain.py +++ b/aiida_nanotech_empa/workflows/cp2k/molecule_gw_workchain.py @@ -119,7 +119,7 @@ def setup(self): self.report("Error: protocol not supported.") return self.exit_codes.ERROR_TERMINATION - self.ctx.protocols = cp2k_utils.load_cp2k_protocol("gw_protocols.yml") + self.ctx.protocols = cp2k_utils.load_protocol("gw_protocols.yml") structure = self.inputs.structure self.ctx.cutoff = cp2k_utils.get_cutoff(structure=structure) magnetization_per_site = copy.deepcopy(self.inputs.magnetization_per_site) diff --git a/examples/workflows/aa b/examples/workflows/aa deleted file mode 100755 index f9b714b..0000000 --- a/examples/workflows/aa +++ /dev/null @@ -1,431 +0,0 @@ -verdi node delete 337 -verdi node delete 344 -verdi node delete 345 -verdi node delete 353 -verdi node delete 354 -verdi node delete 362 -verdi node delete 369 -verdi node delete 370 -verdi node delete 378 -verdi node delete 379 -verdi node delete 387 -verdi node delete 394 -verdi node delete 395 -verdi node delete 403 -verdi node delete 404 -verdi node delete 414 -verdi node delete 422 -verdi node delete 423 -verdi node delete 434 -verdi node delete 442 -verdi node delete 443 -verdi node delete 498 -verdi node delete 501 -verdi node delete 508 -verdi node delete 509 -verdi node delete 517 -verdi node delete 518 -verdi node delete 523 -verdi node delete 537 -verdi node delete 545 -verdi node delete 550 -verdi node delete 555 -verdi node delete 556 -verdi node delete 557 -verdi node delete 558 -verdi node delete 571 -verdi node delete 575 -verdi node delete 576 -verdi node delete 577 -verdi node delete 588 -verdi node delete 593 -verdi node delete 596 -verdi node delete 603 -verdi node delete 610 -verdi node delete 611 -verdi node delete 612 -verdi node delete 621 -verdi node delete 622 -verdi node delete 630 -verdi node delete 631 -verdi node delete 638 -verdi node delete 655 -verdi node delete 663 -verdi node delete 668 -verdi node delete 673 -verdi node delete 674 -verdi node delete 675 -verdi node delete 676 -verdi node delete 689 -verdi node delete 693 -verdi node delete 694 -verdi node delete 695 -verdi node delete 710 -verdi node delete 715 -verdi node delete 718 -verdi node delete 725 -verdi node delete 732 -verdi node delete 733 -verdi node delete 734 -verdi node delete 743 -verdi node delete 744 -verdi node delete 752 -verdi node delete 753 -verdi node delete 760 -verdi node delete 975 -verdi node delete 981 -verdi node delete 988 -verdi node delete 989 -verdi node delete 997 -verdi node delete 998 -verdi node delete 1002 -verdi node delete 1003 -verdi node delete 1012 -verdi node delete 1018 -verdi node delete 1025 -verdi node delete 1026 -verdi node delete 1034 -verdi node delete 1035 -verdi node delete 1039 -verdi node delete 1040 -verdi node delete 1051 -verdi node delete 1056 -verdi node delete 1063 -verdi node delete 1064 -verdi node delete 1072 -verdi node delete 1073 -verdi node delete 1077 -verdi node delete 1080 -verdi node delete 1086 -verdi node delete 1090 -verdi node delete 1097 -verdi node delete 1098 -verdi node delete 1106 -verdi node delete 1107 -verdi node delete 1112 -verdi node delete 1118 -verdi node delete 1121 -verdi node delete 1128 -verdi node delete 1129 -verdi node delete 1137 -verdi node delete 1138 -verdi node delete 1143 -verdi node delete 1153 -verdi node delete 1161 -verdi node delete 1162 -verdi node delete 1174 -verdi node delete 1182 -verdi node delete 1183 -verdi node delete 1198 -verdi node delete 1206 -verdi node delete 1207 -verdi node delete 1222 -verdi node delete 1230 -verdi node delete 1231 -verdi node delete 1243 -verdi node delete 1251 -verdi node delete 1252 -verdi node delete 1263 -verdi node delete 1269 -verdi node delete 1275 -verdi node delete 1281 -verdi node delete 1287 -verdi node delete 1293 -verdi node delete 1299 -verdi node delete 1305 -verdi node delete 1311 -verdi node delete 1319 -verdi node delete 1320 -verdi node delete 1324 -verdi node delete 1332 -verdi node delete 1333 -verdi node delete 1341 -verdi node delete 1349 -verdi node delete 1350 -verdi node delete 1355 -verdi node delete 1363 -verdi node delete 1364 -verdi node delete 1369 -verdi node delete 1377 -verdi node delete 1378 -verdi node delete 1386 -verdi node delete 1394 -verdi node delete 1395 -verdi node delete 1433 -verdi node delete 1441 -verdi node delete 1442 -verdi node delete 1450 -verdi node delete 1456 -verdi node delete 1464 -verdi node delete 1465 -verdi node delete 1473 -verdi node delete 1481 -verdi node delete 1482 -verdi node delete 1490 -verdi node delete 1498 -verdi node delete 1499 -verdi node delete 1507 -verdi node delete 1515 -verdi node delete 1516 -verdi node delete 1524 -verdi node delete 1532 -verdi node delete 1533 -verdi node delete 1541 -verdi node delete 1549 -verdi node delete 1550 -verdi node delete 1553 -verdi node delete 1559 -verdi node delete 1567 -verdi node delete 1568 -verdi node delete 1571 -verdi node delete 1576 -verdi node delete 1584 -verdi node delete 1585 -verdi node delete 1588 -verdi node delete 1593 -verdi node delete 1601 -verdi node delete 1602 -verdi node delete 1610 -verdi node delete 1618 -verdi node delete 1619 -verdi node delete 1627 -verdi node delete 1635 -verdi node delete 1636 -verdi node delete 1644 -verdi node delete 1652 -verdi node delete 1653 -verdi node delete 1661 -verdi node delete 1667 -verdi node delete 1675 -verdi node delete 1676 -verdi node delete 1684 -verdi node delete 1692 -verdi node delete 1693 -verdi node delete 1701 -verdi node delete 1707 -verdi node delete 1715 -verdi node delete 1716 -verdi node delete 1724 -verdi node delete 1732 -verdi node delete 1733 -verdi node delete 1741 -verdi node delete 1749 -verdi node delete 1750 -verdi node delete 1753 -verdi node delete 1759 -verdi node delete 1767 -verdi node delete 1768 -verdi node delete 1776 -verdi node delete 1784 -verdi node delete 1785 -verdi node delete 1793 -verdi node delete 1801 -verdi node delete 1802 -verdi node delete 1807 -verdi node delete 1815 -verdi node delete 1816 -verdi node delete 1824 -verdi node delete 1832 -verdi node delete 1833 -verdi node delete 1841 -verdi node delete 1849 -verdi node delete 1850 -verdi node delete 1855 -verdi node delete 1863 -verdi node delete 1864 -verdi node delete 1872 -verdi node delete 1880 -verdi node delete 1881 -verdi node delete 1889 -verdi node delete 1897 -verdi node delete 1898 -verdi node delete 1906 -verdi node delete 1914 -verdi node delete 1915 -verdi node delete 1923 -verdi node delete 1931 -verdi node delete 1932 -verdi node delete 1940 -verdi node delete 1948 -verdi node delete 1949 -verdi node delete 1956 -verdi node delete 1961 -verdi node delete 1969 -verdi node delete 1970 -verdi node delete 1973 -verdi node delete 1978 -verdi node delete 1986 -verdi node delete 1987 -verdi node delete 1991 -verdi node delete 1999 -verdi node delete 2000 -verdi node delete 2033 -verdi node delete 2043 -verdi node delete 2050 -verdi node delete 2058 -verdi node delete 2068 -verdi node delete 2075 -verdi node delete 2082 -verdi node delete 2092 -verdi node delete 2099 -verdi node delete 2112 -verdi node delete 2122 -verdi node delete 2129 -verdi node delete 2143 -verdi node delete 2150 -verdi node delete 2163 -verdi node delete 2173 -verdi node delete 2179 -verdi node delete 2186 -verdi node delete 2196 -verdi node delete 2203 -verdi node delete 2216 -verdi node delete 2243 -verdi node delete 2249 -verdi node delete 2254 -verdi node delete 2259 -verdi node delete 2271 -verdi node delete 2279 -verdi node delete 2280 -verdi node delete 2281 -verdi node delete 2298 -verdi node delete 2306 -verdi node delete 2307 -verdi node delete 2308 -verdi node delete 2325 -verdi node delete 2326 -verdi node delete 2339 -verdi node delete 2340 -verdi node delete 2349 -verdi node delete 2354 -verdi node delete 2366 -verdi node delete 2374 -verdi node delete 2375 -verdi node delete 2376 -verdi node delete 2393 -verdi node delete 2401 -verdi node delete 2402 -verdi node delete 2403 -verdi node delete 2420 -verdi node delete 2428 -verdi node delete 2429 -verdi node delete 2430 -verdi node delete 2447 -verdi node delete 2455 -verdi node delete 2456 -verdi node delete 2457 -verdi node delete 2474 -verdi node delete 2482 -verdi node delete 2483 -verdi node delete 2484 -verdi node delete 2501 -verdi node delete 2509 -verdi node delete 2510 -verdi node delete 2511 -verdi node delete 2528 -verdi node delete 2529 -verdi node delete 2561 -verdi node delete 2566 -verdi node delete 2574 -verdi node delete 2601 -verdi node delete 2605 -verdi node delete 2610 -verdi node delete 2618 -verdi node delete 2623 -verdi node delete 2650 -verdi node delete 2655 -verdi node delete 2660 -verdi node delete 2665 -verdi node delete 2670 -verdi node delete 2678 -verdi node delete 2683 -verdi node delete 2695 -verdi node delete 2703 -verdi node delete 2704 -verdi node delete 2705 -verdi node delete 2722 -verdi node delete 2730 -verdi node delete 2731 -verdi node delete 2732 -verdi node delete 2749 -verdi node delete 2750 -verdi node delete 2763 -verdi node delete 2764 -verdi node delete 2773 -verdi node delete 2778 -verdi node delete 2790 -verdi node delete 2798 -verdi node delete 2799 -verdi node delete 2800 -verdi node delete 2817 -verdi node delete 2825 -verdi node delete 2826 -verdi node delete 2827 -verdi node delete 2844 -verdi node delete 2852 -verdi node delete 2853 -verdi node delete 2854 -verdi node delete 2871 -verdi node delete 2879 -verdi node delete 2880 -verdi node delete 2881 -verdi node delete 2898 -verdi node delete 2906 -verdi node delete 2907 -verdi node delete 2908 -verdi node delete 2925 -verdi node delete 2933 -verdi node delete 2934 -verdi node delete 2935 -verdi node delete 2952 -verdi node delete 2953 -verdi node delete 2961 -verdi node delete 2966 -verdi node delete 2978 -verdi node delete 2979 -verdi node delete 2990 -verdi node delete 2994 -verdi node delete 2999 -verdi node delete 3011 -verdi node delete 3019 -verdi node delete 3020 -verdi node delete 3021 -verdi node delete 3027 -verdi node delete 3029 -verdi node delete 3032 -verdi node delete 3034 -verdi node delete 3035 -verdi node delete 3037 -verdi node delete 3054 -verdi node delete 3062 -verdi node delete 3063 -verdi node delete 3064 -verdi node delete 3069 -verdi node delete 3071 -verdi node delete 3073 -verdi node delete 3077 -verdi node delete 3079 -verdi node delete 3081 -verdi node delete 3088 -verdi node delete 3090 -verdi node delete 3092 -verdi node delete 3105 -verdi node delete 3106 -verdi node delete 3115 -verdi node delete 3123 -verdi node delete 3124 -verdi node delete 3132 -verdi node delete 3140 -verdi node delete 3141 -verdi node delete 3149 -verdi node delete 3157 -verdi node delete 3158 -verdi node delete 3166 -verdi node delete 3174 -verdi node delete 3175 -verdi node delete 3183 -verdi node delete 3191 -verdi node delete 3192 -verdi node delete 3200 -verdi node delete 3208 -verdi node delete 3209 diff --git a/examples/workflows/example_cp2k_ads_gw_ic.py b/examples/workflows/example_cp2k_ads_gw_ic.py index 0ebb4a9..3da35d1 100644 --- a/examples/workflows/example_cp2k_ads_gw_ic.py +++ b/examples/workflows/example_cp2k_ads_gw_ic.py @@ -1,6 +1,6 @@ import os -import ase +import ase,ase.io from aiida import engine, orm, plugins Cp2kAdsorbedGwIcWorkChain = plugins.WorkflowFactory("nanotech_empa.cp2k.ads_gw_ic") From 6c31161003dfb20a297cd04abbc01c8b58dc538e Mon Sep 17 00:00:00 2001 From: Carlo Antonio Pignedoli Date: Fri, 12 Jul 2024 12:06:33 +0000 Subject: [PATCH 2/5] bug fix --- .../cp2k/adsorbed_gw_ic_workchain.py | 45 ++++++++++++------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/aiida_nanotech_empa/workflows/cp2k/adsorbed_gw_ic_workchain.py b/aiida_nanotech_empa/workflows/cp2k/adsorbed_gw_ic_workchain.py index 562d402..84bc509 100644 --- a/aiida_nanotech_empa/workflows/cp2k/adsorbed_gw_ic_workchain.py +++ b/aiida_nanotech_empa/workflows/cp2k/adsorbed_gw_ic_workchain.py @@ -1,6 +1,8 @@ import numpy as np from aiida import engine, orm +from ...utils import common_utils + from .geo_opt_workchain import Cp2kGeoOptWorkChain from .molecule_gw_workchain import Cp2kMoleculeGwWorkChain @@ -9,14 +11,18 @@ } -def geometrical_analysis(ase_geo, substr_elem): +def geometrical_analysis(ase_geo, substr_elem,mol_atoms=None): """Simple geometry analysis that returns in the case of 1) an isolated molecule -> geometry, None 2) adsorbed system -> molecular geometry, top substr. layer z """ - chem_symbols_arr = np.array(ase_geo.get_chemical_symbols()) - s_atoms = ase_geo[chem_symbols_arr == substr_elem] - non_s_atoms = ase_geo[chem_symbols_arr != substr_elem] + + if mol_atoms is not None: + s_atoms = ase_geo[[atom.index for atom in ase_geo if atom.index not in mol_atoms and atom.symbol == substr_elem]] + else: + chem_symbols_arr = np.array(ase_geo.get_chemical_symbols()) + s_atoms = ase_geo[chem_symbols_arr == substr_elem] + non_s_atoms = ase_geo[chem_symbols_arr != substr_elem] if len(s_atoms) == 0: return ase_geo, None layer_dz = 1.0 # ang @@ -25,17 +31,20 @@ def geometrical_analysis(ase_geo, substr_elem): ] surf_z = np.mean(substr_top_layer.positions[:, 2]) - mol_atoms = non_s_atoms[non_s_atoms.positions[:, 2] > surf_z] + if mol_atoms is None: + mol_atoms = non_s_atoms[non_s_atoms.positions[:, 2] > surf_z] + else: + mol_atoms = ase_geo[mol_atoms] return mol_atoms, surf_z @engine.calcfunction -def analyze_structure(structure, substrate, mag_per_site, ads_h=None): +def analyze_structure(structure, substrate, mag_per_site, ads_h=None,molecule_atoms=None): ase_geo = structure.get_ase() substr_elem = substrate.value.split("(")[0] - mol_atoms, surf_z = geometrical_analysis(ase_geo, substr_elem) + mol_atoms, surf_z = geometrical_analysis(ase_geo, substr_elem,mol_atoms=molecule_atoms) if surf_z is None: if ads_h is None: @@ -163,6 +172,12 @@ def define(cls, spec): default=lambda: orm.List(list=[]), required=False, ) + spec.input( + "molecule_atoms", + valid_type=orm.List, + default=lambda: orm.List(list=[]), + required=False, + ) spec.input_namespace( "options", valid_type=dict, @@ -243,11 +258,15 @@ def setup(self): if self.inputs.substrate.value not in IC_PLANE_HEIGHTS: return self.exit_codes.ERROR_SUBSTR_NOT_SUPPORTED + molecule_atoms = self.inputs.molecule_atoms + if len(molecule_atoms) == 0: + molecule_atoms = None an_out = analyze_structure( self.inputs.structure, self.inputs.substrate, self.inputs.magnetization_per_site, None if "ads_height" not in self.inputs else self.inputs.ads_height, + molecule_atoms=molecule_atoms, ) if "mol_struct" not in an_out: @@ -344,13 +363,9 @@ def finalize(self): "gw_ic_parameters", calc_gw_ic_parameters(gw_out_params, ic_out_params) ) - # Add the workchain pk to the input structure extras - extras_label = "Cp2kAdsorbedGwIcWorkChain_pks" - if extras_label not in self.inputs.structure.base.extras.all: - extras_list = [] - else: - extras_list = self.inputs.structure.base.extras.all[extras_label] - extras_list.append(self.node.pk) - self.inputs.structure.base.extras.set(extras_label, extras_list) + # Add extras. + struc = self.inputs.structure + common_utils.add_extras(struc, "surfaces", self.node.uuid) + return engine.ExitCode(0) From 7994364a483c64ada2337e62fabefd3153e7d389 Mon Sep 17 00:00:00 2001 From: Carlo Antonio Pignedoli Date: Thu, 18 Jul 2024 13:19:48 +0000 Subject: [PATCH 3/5] elpa protocol in global --- .../workflows/cp2k/protocols/gw_protocols.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/aiida_nanotech_empa/workflows/cp2k/protocols/gw_protocols.yml b/aiida_nanotech_empa/workflows/cp2k/protocols/gw_protocols.yml index 68ecb2e..145b6b9 100644 --- a/aiida_nanotech_empa/workflows/cp2k/protocols/gw_protocols.yml +++ b/aiida_nanotech_empa/workflows/cp2k/protocols/gw_protocols.yml @@ -93,6 +93,7 @@ gpw_std_scf_step: CELL: PERIODIC: NONE GLOBAL: + ELPA_KERNEL: AVX2_BLOCK2 RUN_TYPE: ENERGY PRINT_LEVEL: MEDIUM EXTENDED_FFT_LENGTHS: '' @@ -143,6 +144,7 @@ gpw_std_gw_step: CELL: PERIODIC: NONE GLOBAL: + ELPA_KERNEL: AVX2_BLOCK2 RUN_TYPE: ENERGY PRINT_LEVEL: MEDIUM EXTENDED_FFT_LENGTHS: '' @@ -197,6 +199,7 @@ gpw_std_ic_step: CELL: PERIODIC: NONE GLOBAL: + ELPA_KERNEL: AVX2_BLOCK2 RUN_TYPE: ENERGY PRINT_LEVEL: MEDIUM EXTENDED_FFT_LENGTHS: '' @@ -236,6 +239,7 @@ gapw_std_scf_step: CELL: PERIODIC: NONE GLOBAL: + ELPA_KERNEL: AVX2_BLOCK2 RUN_TYPE: ENERGY PRINT_LEVEL: MEDIUM EXTENDED_FFT_LENGTHS: '' @@ -284,6 +288,7 @@ gapw_std_gw_step: CELL: PERIODIC: NONE GLOBAL: + ELPA_KERNEL: AVX2_BLOCK2 RUN_TYPE: ENERGY PRINT_LEVEL: MEDIUM EXTENDED_FFT_LENGTHS: '' @@ -337,6 +342,7 @@ gapw_std_ic_step: CELL: PERIODIC: NONE GLOBAL: + ELPA_KERNEL: AVX2_BLOCK2 RUN_TYPE: ENERGY PRINT_LEVEL: MEDIUM EXTENDED_FFT_LENGTHS: '' @@ -376,6 +382,7 @@ gapw_hq_scf_step: CELL: PERIODIC: NONE GLOBAL: + ELPA_KERNEL: AVX2_BLOCK2 RUN_TYPE: ENERGY PRINT_LEVEL: MEDIUM EXTENDED_FFT_LENGTHS: '' @@ -424,6 +431,7 @@ gapw_hq_gw_step: CELL: PERIODIC: NONE GLOBAL: + ELPA_KERNEL: AVX2_BLOCK2 RUN_TYPE: ENERGY PRINT_LEVEL: MEDIUM EXTENDED_FFT_LENGTHS: '' @@ -477,6 +485,7 @@ gapw_hq_ic_step: CELL: PERIODIC: NONE GLOBAL: + ELPA_KERNEL: AVX2_BLOCK2 RUN_TYPE: ENERGY PRINT_LEVEL: MEDIUM EXTENDED_FFT_LENGTHS: '' From db6472876aad6a0099b773e52f3b5fe9a697ccde Mon Sep 17 00:00:00 2001 From: Carlo Antonio Pignedoli Date: Thu, 21 Nov 2024 11:05:03 +0000 Subject: [PATCH 4/5] removed final bugs --- .../cp2k/adsorbed_gw_ic_workchain.py | 61 ++++++++++--------- examples/workflows/example_cp2k_ads_gw_ic.py | 15 ++++- 2 files changed, 45 insertions(+), 31 deletions(-) diff --git a/aiida_nanotech_empa/workflows/cp2k/adsorbed_gw_ic_workchain.py b/aiida_nanotech_empa/workflows/cp2k/adsorbed_gw_ic_workchain.py index 84bc509..b530f81 100644 --- a/aiida_nanotech_empa/workflows/cp2k/adsorbed_gw_ic_workchain.py +++ b/aiida_nanotech_empa/workflows/cp2k/adsorbed_gw_ic_workchain.py @@ -126,6 +126,7 @@ class Cp2kAdsorbedGwIcWorkChain(engine.WorkChain): Two different ways to run: 1) geometry of a molecule adsorbed on a substrate 2) isolated molecule & adsorption height + Magnetization specified on molecule atoms is relabelled for the gas phase calculation """ @classmethod @@ -160,24 +161,14 @@ def define(cls, spec): required=False, help="Protocol supported by the Cp2kMoleculeGwWorkChain.", ) - spec.input( - "multiplicity", - valid_type=orm.Int, - default=lambda: orm.Int(0), - required=False, - ) - spec.input( - "magnetization_per_site", - valid_type=orm.List, - default=lambda: orm.List(list=[]), - required=False, - ) - spec.input( - "molecule_atoms", - valid_type=orm.List, - default=lambda: orm.List(list=[]), - required=False, - ) + spec.input("dft_params", valid_type=orm.Dict) + spec.input("sys_params", valid_type=orm.Dict) + #spec.input( + # "molecule_atoms", + # valid_type=orm.List, + # default=lambda: orm.List(list=[]), + # required=False, + #) spec.input_namespace( "options", valid_type=dict, @@ -248,9 +239,13 @@ def define(cls, spec): def setup(self): self.report("Inspecting input and setting up things.") - + + self.ctx.sys_params = self.inputs.sys_params.get_dict() + self.ctx.dft_params = self.inputs.dft_params.get_dict() + n_atoms = len(self.inputs.structure.get_ase()) - n_mags = len(list(self.inputs.magnetization_per_site)) + mags = self.ctx.dft_params.get('magnetization_per_site',[]) + n_mags = len(mags) if n_mags not in (0, n_atoms): self.report("If set, magnetization_per_site needs a value for every atom.") return self.exit_codes.ERROR_TERMINATION @@ -258,13 +253,13 @@ def setup(self): if self.inputs.substrate.value not in IC_PLANE_HEIGHTS: return self.exit_codes.ERROR_SUBSTR_NOT_SUPPORTED - molecule_atoms = self.inputs.molecule_atoms + molecule_atoms = self.ctx.sys_params.get('molecule_atoms',[])#self.inputs.molecule_atoms if len(molecule_atoms) == 0: molecule_atoms = None an_out = analyze_structure( self.inputs.structure, self.inputs.substrate, - self.inputs.magnetization_per_site, + mags, None if "ads_height" not in self.inputs else self.inputs.ads_height, molecule_atoms=molecule_atoms, ) @@ -276,6 +271,10 @@ def setup(self): self.ctx.mol_struct = an_out["mol_struct"] self.ctx.image_plane_z = an_out["image_plane_z"] self.ctx.mol_mag_per_site = an_out["mol_mag_per_site"] + if "magnetization_per_site" in self.ctx.dft_params: + self.ctx.dft_params["magnetization_per_site"] = an_out["mol_mag_per_site"] + + ### return engine.ExitCode(0) @@ -286,14 +285,14 @@ def gas_opt(self): builder = Cp2kGeoOptWorkChain.get_builder() builder.code = self.inputs.code builder.structure = self.ctx.mol_struct - builder.multiplicity = self.inputs.multiplicity - builder.magnetization_per_site = self.ctx.mol_mag_per_site - builder.vdw = orm.Bool(True) + builder.sys_params = orm.Dict(dict=self.ctx.sys_params) + builder.dft_params = orm.Dict(dict=self.ctx.dft_params) builder.protocol = orm.Str("standard") + builder.metadata.label = "CP2K_GW_GAS_GeoOpt" if self.inputs.debug: builder.protocol = orm.Str("debug") builder.options = self.inputs.options.scf - builder.metadata.description = "gas_opt" + builder.metadata.description = "Gas phase geomery optimization" submitted_node = self.submit(builder) return engine.ToContext(gas_opt=submitted_node) @@ -319,7 +318,7 @@ def ic(self): builder.protocol = self.inputs.protocol builder.structure = self.ctx.mol_struct builder.magnetization_per_site = self.ctx.mol_mag_per_site - builder.multiplicity = self.inputs.multiplicity + builder.multiplicity = orm.Int(self.ctx.dft_params.get("multiplicity",0)) builder.run_image_charge = orm.Bool(True) builder.z_ic_plane = self.ctx.image_plane_z builder.options.scf = self.inputs.options.scf @@ -340,7 +339,7 @@ def gw(self): builder.protocol = self.inputs.protocol builder.structure = self.ctx.mol_struct builder.magnetization_per_site = self.ctx.mol_mag_per_site - builder.multiplicity = self.inputs.multiplicity + builder.multiplicity = orm.Int(self.ctx.dft_params.get("multiplicity",0)) builder.options.scf = self.inputs.options.scf builder.options.gw = self.inputs.options.gw builder.metadata.description = "gw" @@ -352,9 +351,13 @@ def finalize(self): if not self.ctx.gw.is_finished_ok: return self.exit_codes.ERROR_TERMINATION + if hasattr(self.ctx, 'gas_opt') and self.ctx.gas_opt is not None: + gas_geo_opt_params = self.ctx.gas_opt.outputs.output_parameters + self.out("gas_geo_opt_parameters", gas_geo_opt_params) + gw_out_params = self.ctx.gw.outputs.gw_output_parameters ic_out_params = self.ctx.ic.outputs.gw_output_parameters - + self.out("gw_output_parameters", gw_out_params) self.out("ic_output_parameters", ic_out_params) diff --git a/examples/workflows/example_cp2k_ads_gw_ic.py b/examples/workflows/example_cp2k_ads_gw_ic.py index 3da35d1..d54e794 100644 --- a/examples/workflows/example_cp2k_ads_gw_ic.py +++ b/examples/workflows/example_cp2k_ads_gw_ic.py @@ -27,12 +27,23 @@ def _example_cp2k_ads_gw_ic(cp2k_code, slab_included): builder.ads_height = orm.Float(3.0) builder.structure = orm.StructureData(ase=ase_geom) - builder.magnetization_per_site = orm.List(mag_list) + + dft_params = { + "uks": True, + "magnetization_per_site": mag_list, + "charge": 0, + "periodic": "XYZ", + "vdw": False, + "multiplicity": 1, + "cutoff": 300, + } + sys_params = {} builder.protocol = orm.Str("gpw_std") - builder.multiplicity = orm.Int(1) builder.geometry_mode = orm.Str("ads_geo") + builder.sys_params = orm.Dict(dict=sys_params) + builder.dft_params = orm.Dict(dict=dft_params) builder.debug = orm.Bool(True) builder.options.scf = { From b9297eac47b84585226dec28bd3f5d3d75e2debd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 21 Nov 2024 11:07:58 +0000 Subject: [PATCH 5/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../cp2k/adsorbed_gw_ic_workchain.py | 52 +++++++++++-------- examples/workflows/example_cp2k_ads_gw_ic.py | 5 +- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/aiida_nanotech_empa/workflows/cp2k/adsorbed_gw_ic_workchain.py b/aiida_nanotech_empa/workflows/cp2k/adsorbed_gw_ic_workchain.py index b530f81..dbef1f1 100644 --- a/aiida_nanotech_empa/workflows/cp2k/adsorbed_gw_ic_workchain.py +++ b/aiida_nanotech_empa/workflows/cp2k/adsorbed_gw_ic_workchain.py @@ -2,7 +2,6 @@ from aiida import engine, orm from ...utils import common_utils - from .geo_opt_workchain import Cp2kGeoOptWorkChain from .molecule_gw_workchain import Cp2kMoleculeGwWorkChain @@ -11,14 +10,20 @@ } -def geometrical_analysis(ase_geo, substr_elem,mol_atoms=None): +def geometrical_analysis(ase_geo, substr_elem, mol_atoms=None): """Simple geometry analysis that returns in the case of 1) an isolated molecule -> geometry, None 2) adsorbed system -> molecular geometry, top substr. layer z """ - + if mol_atoms is not None: - s_atoms = ase_geo[[atom.index for atom in ase_geo if atom.index not in mol_atoms and atom.symbol == substr_elem]] + s_atoms = ase_geo[ + [ + atom.index + for atom in ase_geo + if atom.index not in mol_atoms and atom.symbol == substr_elem + ] + ] else: chem_symbols_arr = np.array(ase_geo.get_chemical_symbols()) s_atoms = ase_geo[chem_symbols_arr == substr_elem] @@ -40,11 +45,15 @@ def geometrical_analysis(ase_geo, substr_elem,mol_atoms=None): @engine.calcfunction -def analyze_structure(structure, substrate, mag_per_site, ads_h=None,molecule_atoms=None): +def analyze_structure( + structure, substrate, mag_per_site, ads_h=None, molecule_atoms=None +): ase_geo = structure.get_ase() substr_elem = substrate.value.split("(")[0] - mol_atoms, surf_z = geometrical_analysis(ase_geo, substr_elem,mol_atoms=molecule_atoms) + mol_atoms, surf_z = geometrical_analysis( + ase_geo, substr_elem, mol_atoms=molecule_atoms + ) if surf_z is None: if ads_h is None: @@ -163,12 +172,12 @@ def define(cls, spec): ) spec.input("dft_params", valid_type=orm.Dict) spec.input("sys_params", valid_type=orm.Dict) - #spec.input( + # spec.input( # "molecule_atoms", # valid_type=orm.List, # default=lambda: orm.List(list=[]), # required=False, - #) + # ) spec.input_namespace( "options", valid_type=dict, @@ -239,12 +248,12 @@ def define(cls, spec): def setup(self): self.report("Inspecting input and setting up things.") - + self.ctx.sys_params = self.inputs.sys_params.get_dict() self.ctx.dft_params = self.inputs.dft_params.get_dict() - + n_atoms = len(self.inputs.structure.get_ase()) - mags = self.ctx.dft_params.get('magnetization_per_site',[]) + mags = self.ctx.dft_params.get("magnetization_per_site", []) n_mags = len(mags) if n_mags not in (0, n_atoms): self.report("If set, magnetization_per_site needs a value for every atom.") @@ -253,7 +262,9 @@ def setup(self): if self.inputs.substrate.value not in IC_PLANE_HEIGHTS: return self.exit_codes.ERROR_SUBSTR_NOT_SUPPORTED - molecule_atoms = self.ctx.sys_params.get('molecule_atoms',[])#self.inputs.molecule_atoms + molecule_atoms = self.ctx.sys_params.get( + "molecule_atoms", [] + ) # self.inputs.molecule_atoms if len(molecule_atoms) == 0: molecule_atoms = None an_out = analyze_structure( @@ -261,7 +272,7 @@ def setup(self): self.inputs.substrate, mags, None if "ads_height" not in self.inputs else self.inputs.ads_height, - molecule_atoms=molecule_atoms, + molecule_atoms=molecule_atoms, ) if "mol_struct" not in an_out: @@ -272,8 +283,8 @@ def setup(self): self.ctx.image_plane_z = an_out["image_plane_z"] self.ctx.mol_mag_per_site = an_out["mol_mag_per_site"] if "magnetization_per_site" in self.ctx.dft_params: - self.ctx.dft_params["magnetization_per_site"] = an_out["mol_mag_per_site"] - + self.ctx.dft_params["magnetization_per_site"] = an_out["mol_mag_per_site"] + ### return engine.ExitCode(0) @@ -318,7 +329,7 @@ def ic(self): builder.protocol = self.inputs.protocol builder.structure = self.ctx.mol_struct builder.magnetization_per_site = self.ctx.mol_mag_per_site - builder.multiplicity = orm.Int(self.ctx.dft_params.get("multiplicity",0)) + builder.multiplicity = orm.Int(self.ctx.dft_params.get("multiplicity", 0)) builder.run_image_charge = orm.Bool(True) builder.z_ic_plane = self.ctx.image_plane_z builder.options.scf = self.inputs.options.scf @@ -339,7 +350,7 @@ def gw(self): builder.protocol = self.inputs.protocol builder.structure = self.ctx.mol_struct builder.magnetization_per_site = self.ctx.mol_mag_per_site - builder.multiplicity = orm.Int(self.ctx.dft_params.get("multiplicity",0)) + builder.multiplicity = orm.Int(self.ctx.dft_params.get("multiplicity", 0)) builder.options.scf = self.inputs.options.scf builder.options.gw = self.inputs.options.gw builder.metadata.description = "gw" @@ -351,13 +362,13 @@ def finalize(self): if not self.ctx.gw.is_finished_ok: return self.exit_codes.ERROR_TERMINATION - if hasattr(self.ctx, 'gas_opt') and self.ctx.gas_opt is not None: + if hasattr(self.ctx, "gas_opt") and self.ctx.gas_opt is not None: gas_geo_opt_params = self.ctx.gas_opt.outputs.output_parameters self.out("gas_geo_opt_parameters", gas_geo_opt_params) gw_out_params = self.ctx.gw.outputs.gw_output_parameters ic_out_params = self.ctx.ic.outputs.gw_output_parameters - + self.out("gw_output_parameters", gw_out_params) self.out("ic_output_parameters", ic_out_params) @@ -368,7 +379,6 @@ def finalize(self): # Add extras. struc = self.inputs.structure - common_utils.add_extras(struc, "surfaces", self.node.uuid) - + common_utils.add_extras(struc, "surfaces", self.node.uuid) return engine.ExitCode(0) diff --git a/examples/workflows/example_cp2k_ads_gw_ic.py b/examples/workflows/example_cp2k_ads_gw_ic.py index d54e794..ae04370 100644 --- a/examples/workflows/example_cp2k_ads_gw_ic.py +++ b/examples/workflows/example_cp2k_ads_gw_ic.py @@ -1,6 +1,7 @@ import os -import ase,ase.io +import ase +import ase.io from aiida import engine, orm, plugins Cp2kAdsorbedGwIcWorkChain = plugins.WorkflowFactory("nanotech_empa.cp2k.ads_gw_ic") @@ -27,7 +28,7 @@ def _example_cp2k_ads_gw_ic(cp2k_code, slab_included): builder.ads_height = orm.Float(3.0) builder.structure = orm.StructureData(ase=ase_geom) - + dft_params = { "uks": True, "magnetization_per_site": mag_list,