-
Notifications
You must be signed in to change notification settings - Fork 34
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 CommonBandsWorkChain for CASTEP #258
Open
zhubonan
wants to merge
20
commits into
aiidateam:master
Choose a base branch
from
zhubonan:castep
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 all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1a90ef6
Added the CASTEP oxide-validation protocol
zhubonan a47cfc8
Update for CASTEP
zhubonan 60f0ac5
Merge branch 'master' into castep
zhubonan 34ff533
Do not write checkpoint - they are huge !
zhubonan 5ff96f8
Commit changes of the protocol.yml
zhubonan ccfbd43
Added set with increased kspacing
zhubonan c0a6e5e
Merge remote-tracking branch 'aiidateam' into castep
zhubonan c0f8b62
Initial commit for the CASTEP common workchain
zhubonan dc4d663
Updated the generation for CASTEP
zhubonan 8d01573
Fix typo
zhubonan b1c7020
Remove the limitor of the protocols
zhubonan 34060a3
Update the generator codes
zhubonan 82e96b5
Rename the protocol to verification-PBE-v1
zhubonan f279031
Update the protocol
zhubonan 0495428
Merge remote-tracking branch 'aiidateam/master' into castep
zhubonan ecc4432
Fix the handling of soft elements
zhubonan d48a79b
Fix the handling
zhubonan a581750
Fix the soft_elements.yml
zhubonan e7c2dba
Updated CASTEP protcol
zhubonan 82bf2f5
Added extractor of TS term for CASTEP
zhubonan 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
Empty file.
81 changes: 81 additions & 0 deletions
81
aiida_common_workflows/workflows/bands/castep/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,81 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Implementation of `aiida_common_workflows.common.bands.generator.CommonBandsInputGenerator` for CASTEP.""" | ||
from aiida import engine, orm | ||
|
||
from aiida_common_workflows.generators import CodeType | ||
|
||
from ..generator import CommonBandsInputGenerator | ||
|
||
__all__ = ('CastepCommonBandsInputGenerator',) | ||
|
||
|
||
class CastepCommonBandsInputGenerator(CommonBandsInputGenerator): | ||
"""Generator of inputs for the CastepCommonBandsWorkChain""" | ||
|
||
@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('castep.castep') | ||
|
||
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 | ||
|
||
required_keys = ('engines', 'parent_folder', 'bands_kpoints') | ||
for key in required_keys: | ||
if key not in kwargs: | ||
raise ValueError(f'Required key `{key}` is missing in the function argument.') | ||
engines = kwargs['engines'] | ||
parent_folder = kwargs['parent_folder'] | ||
bands_kpoints = kwargs['bands_kpoints'] | ||
|
||
# From the parent folder, we retrieve the calculation that created it. Note | ||
# that we are sure it exists (it wouldn't be the same for WorkChains). We then check | ||
# that it is a CastepCalculation and create the builder. | ||
parent_castep_calc = parent_folder.creator | ||
if parent_castep_calc.process_type != 'aiida.calculations:castep.castep': | ||
raise ValueError('The `parent_folder` has not been created by a CastepCalculation') | ||
builder_castep_calc = parent_castep_calc.get_builder_restart() | ||
|
||
# Construct the builder of the `common_bands_wc` from the builder of a CastepCalculation. | ||
builder_common_bands_wc = self.process_class.get_builder() | ||
builder_common_bands_wc.scf.calc_options = orm.Dict(dict=dict(builder_castep_calc.metadata.options)) | ||
# Ensure we use castep_bin for restart, instead of the check file | ||
#builder_common_bands_wc.scf.options = orm.Dict(dict={'use_castep_bin': True}) | ||
|
||
builder_castep_calc.metadata = {} | ||
|
||
# Attach inputs of the calculation | ||
for key, value in builder_castep_calc.items(): | ||
if value and key not in ['metadata', 'structure']: | ||
builder_common_bands_wc.scf.calc[key] = value | ||
|
||
# Updated the structure (in case we have one in output) | ||
if 'output_structure' in parent_castep_calc.outputs: | ||
builder_common_bands_wc.structure = parent_castep_calc.outputs.output_structure | ||
else: | ||
builder_common_bands_wc.structure = parent_castep_calc.inputs.structure | ||
|
||
try: | ||
engb = engines['bands'] | ||
except KeyError: | ||
raise ValueError('The engines dictionary passed must contains a key named `bands`.') | ||
|
||
builder_common_bands_wc.scf.calc.code = engb['code'] | ||
|
||
if 'options' in engb: | ||
builder_common_bands_wc.scf.calc.metadata.options = engb['options'] | ||
|
||
# Set the `bandskpoints` and the `parent_calc_folder` for restart | ||
builder_common_bands_wc.bands_kpoints = bands_kpoints | ||
builder_common_bands_wc.scf.continuation_folder = parent_folder | ||
builder_common_bands_wc.run_separate_scf = orm.Bool(False) | ||
|
||
return builder_common_bands_wc |
41 changes: 41 additions & 0 deletions
41
aiida_common_workflows/workflows/bands/castep/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,41 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Implementation of `aiida_common_workflows.common.relax.workchain.CommonRelaxWorkChain` for CASTEP.""" | ||
from logging import getLogger | ||
|
||
from aiida.engine import calcfunction | ||
from aiida.orm import Float | ||
from aiida.plugins import WorkflowFactory | ||
|
||
from ..workchain import CommonBandsWorkChain | ||
from .generator import CastepCommonBandsInputGenerator | ||
|
||
__all__ = ('CastepCommonBandsWorkChain',) | ||
|
||
|
||
@calcfunction | ||
def get_fermi_energy(bands): | ||
"""Extract the Fermi energy from the BandsData output""" | ||
efermi = bands.get_attribute('efermi') | ||
if isinstance(efermi, list): | ||
efermi = efermi[0] | ||
logger = getLogger(__name__) | ||
logger.warning('Spin polarised calculation - using the efermi energy of the first spin channel.') | ||
return Float(efermi) | ||
|
||
|
||
class CastepCommonBandsWorkChain(CommonBandsWorkChain): | ||
"""Implementation of `aiida_common_workflows.common.bands.workchain.CommonBandsWorkChain` for CASTEP.""" | ||
|
||
_process_class = WorkflowFactory('castep.bands') | ||
_generator_class = CastepCommonBandsInputGenerator | ||
|
||
def convert_outputs(self): | ||
"""Convert the outputs of the sub workchain to the common output specification.""" | ||
if 'band_structure' not in self.ctx.workchain.outputs: | ||
self.report('CastepBandsWorkChain concluded without returning bands!') | ||
return self.exit_codes.ERROR_SUB_PROCESS_FAILED | ||
|
||
self.out('fermi_energy', get_fermi_energy(self.ctx.workchain.outputs['band_structure'])) | ||
|
||
self.out('bands', self.ctx.workchain.outputs['band_structure']) | ||
return None |
32 changes: 32 additions & 0 deletions
32
aiida_common_workflows/workflows/relax/castep/additional_otfg_families.yml
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,32 @@ | ||
# Family based on C19 with updated potentials for lanthanide and actinides | ||
C19V2: | ||
- "C19" | ||
- "La 2|2.3|5|6|7|50U:60:51:52:43{4f0.1}(qc=4.5)" | ||
- "Ce 2|2.2|8|9|10|50U:60:51:52:43{5d0.1}(qc=4.5)" | ||
- "Pr 2|2.1|10|12|13|50U:60:51:52:43{5d0.1}(qc=5)" | ||
- "Nd 2|2.1|10|12|13|50U:60:51:52:43{5d0.1}(qc=5)" | ||
- "Pm 2|2.1|8|9|11|50U:60:51:52:43{5d0.1,4f4}(qc=5.5)" | ||
- "Sm 2|2.1|9|10|12|50U:60:51:52:43{5d0.1,4f5}(qc=5.5)" | ||
- "Eu 2|2.1|9|10|12|50U:60:51:52:43{5d0.1,4f6}(qc=5.5)" | ||
- "Gd 3|2.1|9|10|12|50U:60:51:52:43(qc=5.5)" | ||
- "Tb 2|2.2|12|13|15|50U:60:51:52:43{5d0.1}(qc=5)" | ||
- "Dy 2|2.0|12|13|15|50U:60:51:52:43{5d0.1}(qc=6.5)" | ||
- "Ho 2|2.0|12|13|15|50U:60:51:52:43{5d0.1}(qc=6.5)" | ||
- "Er 2|2.1|10|12|13|50U:60:51:52:43{6s0.1,5d0.1}(qc=6)" | ||
- "Tm 2|2.1|10|12|13|50U:60:51:52:43{5d0.1,4f12}(qc=6)" | ||
- "Yb 2|2.1|10|12|13|50U:60:51:52:43{5d0.1,4f13}(qc=6)" | ||
- "Ac 2|2.4|7|7|9|60U:70U2U2:61:62:53{6d0.1,5f0.1}(qc=5)" | ||
- "Th 2|2.2|7|7|9|60U:70U2U2:61:62:53{5f0.1}(qc=5)" | ||
- "Pa 2|2.2|8|9|10|60U:70U2U2:61:62:53(qc=5)" | ||
- "U 2|2.2|8|9|10|60U:70U2U2:61:62:53(qc=5)" | ||
- "Np 2|2.2|9|10|12|60U:70U2U2:61:62:53(qc=5)" | ||
- "Pu 2|2.2|9|10|12|60U:70U2U2:61:62:53{6d0.1}(qc=5.5)" | ||
- "Am 2|2.2|9|10|12|60U:70U2U2:61:62:53{6d0.1}(qc=5.5)" | ||
- "Cm 2|2.2|9|10|12|60U:70U2U2:61:62:53(qc=5.5)" | ||
# Elements below in this family are not tested again all-electron codes - use with CAUTION | ||
- "Bk 2|2.2|9|10|12|60U:70U2U2:61:62:53{6d0.1}(qc=5.5)" | ||
- "Cf 2|2.2|9|10|12|60U:70U2U2:61:62:53{6d0.1}(qc=5.5)" | ||
- "Es 2|2.1|10|12|13|60U:70U2U2:61:62:53{6d0.1}(qc=6)" | ||
- "Fm 2|2.1|10|12|13|60U:70U2U2:61:62:53{6d0.1}(qc=6)" | ||
- "Md 2|2.0|10|12|13|60U:70U2U2:61:62:53{6d0.1,5f12}(qc=6)" | ||
- "No 2|2.0|10|12|13|60U:70U2U2:61:62:53{6d0.1,5f13}(qc=6)" |
37 changes: 37 additions & 0 deletions
37
aiida_common_workflows/workflows/relax/castep/extractors.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,37 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Collects some functions to postprocess a `CastepCommonRelaxWorkChain`. | ||
""" | ||
from aiida.common import LinkType | ||
from aiida.orm import WorkChainNode | ||
from aiida.plugins import WorkflowFactory | ||
|
||
CastepCommonRelaxWorkChain = WorkflowFactory('common_workflows.relax.castep') | ||
|
||
|
||
def get_ts_energy(common_relax_workchain): | ||
""" | ||
Return the TS value of a concluded CastepCommonRelaxWorkChain. | ||
|
||
CASTEP reports three quantities related to the energy: | ||
|
||
- "free energy": ``Final free energy`` - the total energy minus the TS term. | ||
This is the energy that gets minimised and is consistent with the forces calculated. | ||
- "total energy": ``Final energy`` - the total Khon-Sham energy. | ||
- "extrapolated 0K energy": ``NB est. 0K energy`` - the result of E-0.5TS to give better convergence. | ||
- "enthalpy": Is the free energy minus to PV term under finite temperature (for geometry optimisation). | ||
|
||
The TS term can extrapolated by subtracting the free energy from the total energy. | ||
""" | ||
if not isinstance(common_relax_workchain, WorkChainNode): | ||
return ValueError('The input is not a workchain (instance of `WorkChainNode`)') | ||
if common_relax_workchain.process_class != CastepCommonRelaxWorkChain: | ||
return ValueError('The input workchain is not a `CastepCommonRelaxWorkChain`') | ||
|
||
castep_base_wc = common_relax_workchain.get_outgoing(link_type=LinkType.CALL_WORK).one().node | ||
e_ks = castep_base_wc.outputs.output_parameters['total energy'] | ||
free_e = castep_base_wc.outputs.output_parameters['free energy'] | ||
|
||
ts = e_ks - free_e #pylint: disable=invalid-name | ||
|
||
return ts |
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
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
Oops, something went wrong.
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.
This is a good point. Should we discuss whether the
fermi_energy
output should be aFloat
or aList[float]
depending on polarization? Think this would be a common "problem" across implementationsThere 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 will put in the list for discussion tomorrow
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.
An additional issue is that some code may not have a well defined single efermi energy if there are two spin channels (is such quantity itself well-defined at all?). Not sure if this is a limitation across the board or not. I know CASTEP always give two if there are two spin channels. VASP gives ones fermi energy with spin polarised calculation I think, but it may give a wrong value if spin is constrained.