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

add should_run_scf for PwBandsWorkChain #1016

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
29 changes: 22 additions & 7 deletions src/aiida_quantumespresso/workflows/pw/bands.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ def define(cls, spec):
'help': 'Inputs for the `PwRelaxWorkChain`, if not specified at all, the relaxation step is skipped.'})
spec.expose_inputs(PwBaseWorkChain, namespace='scf',
exclude=('clean_workdir', 'pw.structure'),
namespace_options={'help': 'Inputs for the `PwBaseWorkChain` for the SCF calculation.'})
namespace_options={
'help': 'Inputs for the `PwBaseWorkChain` for the SCF calculation.',
'required': False,
'populate_defaults': False,
})
spec.expose_inputs(PwBaseWorkChain, namespace='bands',
exclude=('clean_workdir', 'pw.structure', 'pw.kpoints', 'pw.kpoints_distance', 'pw.parent_folder'),
namespace_options={'help': 'Inputs for the `PwBaseWorkChain` for the BANDS calculation.'})
Expand All @@ -81,8 +85,10 @@ def define(cls, spec):
if_(cls.should_run_seekpath)(
cls.run_seekpath,
),
cls.run_scf,
cls.inspect_scf,
if_(cls.should_run_scf)(
cls.run_scf,
cls.inspect_scf,
),
cls.run_bands,
cls.inspect_bands,
cls.results,
Expand All @@ -104,7 +110,9 @@ def define(cls, spec):
required=False,
help='The parameters used in the SeeKpath call to normalize the input or relaxed structure.')
spec.output('scf_parameters', valid_type=orm.Dict,
help='The output parameters of the SCF `PwBaseWorkChain`.')
required=False,
help='The output parameters of the SCF `PwBaseWorkChain`.'
)
spec.output('band_parameters', valid_type=orm.Dict,
help='The output parameters of the BANDS `PwBaseWorkChain`.')
spec.output('band_structure', valid_type=orm.BandsData,
Expand Down Expand Up @@ -222,6 +230,10 @@ def run_seekpath(self):
self.out('primitive_structure', result['primitive_structure'])
self.out('seekpath_parameters', result['parameters'])

def should_run_scf(self):
"""Return whether the work chain should run an SCF calculation."""
return 'scf' in self.inputs

def run_scf(self):
"""Run the PwBaseWorkChain in scf mode on the primitive cell of (optionally relaxed) input structure."""
inputs = AttributeDict(self.exposed_inputs(PwBaseWorkChain, namespace='scf'))
Expand Down Expand Up @@ -259,7 +271,9 @@ def run_bands(self):
inputs.metadata.call_link_label = 'bands'
inputs.kpoints = self.ctx.bands_kpoints
inputs.pw.structure = self.ctx.current_structure
inputs.pw.parent_folder = self.ctx.current_folder
# override the parent_folder if the scf was run
if 'scf' in self.inputs:
inputs.pw.parent_folder = self.ctx.current_folder
Comment on lines +274 to +276
Copy link
Contributor

Choose a reason for hiding this comment

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

How would the parent_folder be defined though? It is excluded from the bands input namespace, and if scf is skipped this will therefore not be set?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for pointing out this. I didn't notice that the parent_folder is excluded. I run a simple example with Si by setting the parent_folder, it's strange that no error is reported, and the process finished successfully! Here is the process detail:

$ verdi process show 28038
Property     Value
-----------  ------------------------------------
type         PwBandsWorkChain
state        Finished [0]
pk           28038
uuid         94b2d315-6a72-4f73-ae87-5a3b50d86d07
label
description
ctime        2024-03-21 15:34:17.077194+00:00
mtime        2024-03-21 15:34:24.276367+00:00

Inputs                  PK     Type
----------------------  -----  -------------
bands
    pw
        code            216    InstalledCode
        pseudos
            Si          19     UpfData
        parameters      28034  Dict
        parent_folder   28029  RemoteData
    max_iterations      28035  Int
bands_kpoints_distance  28036  Float
clean_workdir           28037  Bool
structure               28020  StructureData

Outputs                 PK  Type
-------------------  -----  -------------
band_parameters      28054  Dict
band_structure       28052  BandsData
primitive_structure  28042  StructureData
seekpath_parameters  28040  Dict

Called       PK  Type
--------  -----  ---------------------------
seekpath  28039  seekpath_structure_analysis
bands     28046  PwBaseWorkChain

Log messages
---------------------------------------------
There are 3 log messages for this calculation
Run 'verdi process report 28038' to see them

You see that the parent_folder is set. Here is the node graph
Screenshot from 2024-03-21 16-50-37

inputs.pw.parameters = inputs.pw.parameters.get_dict()
inputs.pw.parameters.setdefault('CONTROL', {})
inputs.pw.parameters.setdefault('SYSTEM', {})
Expand All @@ -275,7 +289,7 @@ def run_bands(self):
inputs.pw.parameters['SYSTEM']['nbnd'] = nbnd

# Otherwise set the current number of bands, unless explicitly set in the inputs
else:
elif 'scf' in self.inputs:
inputs.pw.parameters['SYSTEM'].setdefault('nbnd', self.ctx.current_number_of_bands)

inputs = prepare_process_inputs(PwBaseWorkChain, inputs)
Expand All @@ -296,7 +310,8 @@ def inspect_bands(self):
def results(self):
"""Attach the desired output nodes directly as outputs of the workchain."""
self.report('workchain succesfully completed')
self.out('scf_parameters', self.ctx.workchain_scf.outputs.output_parameters)
if 'scf' in self.inputs:
self.out('scf_parameters', self.ctx.workchain_scf.outputs.output_parameters)
self.out('band_parameters', self.ctx.workchain_bands.outputs.output_parameters)
self.out('band_structure', self.ctx.workchain_bands.outputs.output_band)

Expand Down
Loading