Skip to content

Commit

Permalink
removed final bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
cpignedoli committed Nov 21, 2024
1 parent 7994364 commit db64728
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 31 deletions.
61 changes: 32 additions & 29 deletions aiida_nanotech_empa/workflows/cp2k/adsorbed_gw_ic_workchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -248,23 +239,27 @@ 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

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,
)
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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)
Expand Down
15 changes: 13 additions & 2 deletions examples/workflows/example_cp2k_ads_gw_ic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit db64728

Please sign in to comment.