-
Notifications
You must be signed in to change notification settings - Fork 31
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
Implement common bands work chain for Quantum ESPRESSO #257
Open
mbercx
wants to merge
4
commits into
aiidateam:master
Choose a base branch
from
mbercx:new/qe-bands
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
aiida_common_workflows/workflows/bands/quantum_espresso/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# -*- coding: utf-8 -*- | ||
# pylint: disable=undefined-variable | ||
"""Module with the implementations of the common bands workchain for Quantum ESPRESSO.""" | ||
from .generator import * | ||
from .workchain import * | ||
|
||
__all__ = (generator.__all__ + workchain.__all__) |
69 changes: 69 additions & 0 deletions
69
aiida_common_workflows/workflows/bands/quantum_espresso/generator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Implementation of the ``CommonBandsInputGenerator`` for Quantum ESPRESSO.""" | ||
|
||
from aiida import engine, orm | ||
from aiida.common import LinkType | ||
|
||
from aiida_common_workflows.generators import CodeType | ||
|
||
from ..generator import CommonBandsInputGenerator | ||
|
||
__all__ = ('QuantumEspressoCommonBandsInputGenerator',) | ||
|
||
|
||
class QuantumEspressoCommonBandsInputGenerator(CommonBandsInputGenerator): | ||
"""Input generator for the ``QuantumEspressoCommonBandsWorkChain``""" | ||
|
||
@classmethod | ||
def define(cls, spec): | ||
"""Define the specification of the input generator. | ||
|
||
The ports defined on the specification are the inputs that will be accepted by the ``get_builder`` method. | ||
""" | ||
super().define(spec) | ||
spec.inputs['engines']['bands']['code'].valid_type = CodeType('quantumespresso.pw') | ||
|
||
def _construct_builder(self, **kwargs) -> engine.ProcessBuilder: | ||
"""Construct a process builder based on the provided keyword arguments. | ||
|
||
The keyword arguments will have been validated against the input generator specification. | ||
""" | ||
# pylint: disable=too-many-branches,too-many-statements,too-many-locals | ||
engines = kwargs.get('engines', None) | ||
parent_folder = kwargs['parent_folder'] | ||
bands_kpoints = kwargs['bands_kpoints'] | ||
|
||
# Find the `PwCalculation` that created the `parent_folder` and obtain the restart builder. | ||
parent_calc = parent_folder.creator | ||
if parent_calc.process_type != 'aiida.calculations:quantumespresso.pw': | ||
raise ValueError('The `parent_folder` has not been created by a `PwCalculation`.') | ||
builder = self.process_class.get_builder() | ||
|
||
parameters = builder_common_bands_wc.pw.parameters.get_dict() | ||
parameters['CONTROL']['calculation'] = 'bands' | ||
|
||
# Inputs of the `pw` calcjob are based of the inputs of the `parent_folder` creator's inputs | ||
builder.pw = parent_folder.creator.get_builder_restart() | ||
builder.pw.parameters = orm.Dict(dict=parameters) | ||
builder.pw.parent_folder = parent_folder | ||
builder.pw.pop('kpoints') | ||
builder.kpoints = bands_kpoints | ||
|
||
# Update the structure in case we have one in output, i.e. the `parent_calc` optimized the structure | ||
if 'output_structure' in parent_calc.outputs: | ||
builder_common_bands_wc.pw.structure = parent_calc.outputs.output_structure | ||
|
||
# Update the code and computational options if `engines` is specified | ||
try: | ||
bands_engine = engines['bands'] | ||
mbercx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
except KeyError: | ||
raise ValueError('The `engines` dictionary must contain `bands` as a top-level key') | ||
if 'code' in bands_engine: | ||
code = bands_engine['code'] | ||
if isinstance(code, str): | ||
code = orm.load_code(code) | ||
builder_common_bands_wc.pw.code = code | ||
if 'options' in bands_engine: | ||
builder_common_bands_wc.pw.metadata.options = bands_engine['options'] | ||
|
||
return builder_common_bands_wc |
34 changes: 34 additions & 0 deletions
34
aiida_common_workflows/workflows/bands/quantum_espresso/workchain.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Implementation of the ``CommonBandsWorkChain`` for Quantum ESPRESSO.""" | ||
from aiida.engine import calcfunction | ||
from aiida.orm import Float | ||
from aiida.plugins import WorkflowFactory | ||
|
||
from ..workchain import CommonBandsWorkChain | ||
from .generator import QuantumEspressoCommonBandsInputGenerator | ||
|
||
__all__ = ('QuantumEspressoCommonBandsWorkChain',) | ||
|
||
|
||
@calcfunction | ||
def get_fermi_energy(output_parameters): | ||
"""Extract the Fermi energy from the ``output_parameters`` of a ``PwBaseWorkChain``.""" | ||
return Float(output_parameters['fermi_energy']) | ||
|
||
|
||
class QuantumEspressoCommonBandsWorkChain(CommonBandsWorkChain): | ||
"""Implementation of the ``CommonBandsWorkChain`` for Quantum ESPRESSO.""" | ||
|
||
_process_class = WorkflowFactory('quantumespresso.pw.base') | ||
_generator_class = QuantumEspressoCommonBandsInputGenerator | ||
|
||
def convert_outputs(self): | ||
"""Convert the outputs of the sub work chain to the common output specification.""" | ||
outputs = self.ctx.workchain.outputs | ||
|
||
if 'output_band' not in outputs: | ||
self.report('The `bands` PwBaseWorkChain does not have the `output_band` output.') | ||
return self.exit_codes.ERROR_SUB_PROCESS_FAILED | ||
|
||
self.out('bands', outputs.output_band) | ||
self.out('fermi_energy', get_fermi_energy(outputs.output_parameters)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few more instances of
builder_common_bands_wc
lying around. Would be good if you could try to run it at least once in absence of unit tests.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, I think this is only in e81a8e2, in the latest commit (2e298cb) this should be fixed. It seems I was a little careless in accepting the reorganisation of the builder code however, I fixed this in c1d0695. Now I tested the relaxation + bands work chain for Si, and it seems to be running fine again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must have seen it after that first commit. Then I haven't said anything :D