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 Feature: XspectraCrystalWorkChain #888

Merged

Conversation

PNOGillespie
Copy link
Contributor

Overview

In this PR we propose to implement a new WorkChain intended to fully automate the calculation of K-edge XANES spectra for each element in a given input structure. This new WorkChain essentially automates the generation of input structures for XspectraCoreWorkChain sub-processes, as well as handling generation and setting of inputs for each sub-process, in order to compute a complete K-edge XANES spectrum for each element requested. The workflow process defined herein applies specifically to periodic systems as it uses the get_xspectra_structures CalcFunction to prepare input structures under the assumption that the input structure is not molecular. Due to the lack of pseudopotentials currently available which either contain GIPAW information or define a core-hole state, such pseudopotentials are presently required to be given as input. A code node to calculate the core wavefunction using upf2plotcore.sh in AiiDA-Shell can be provided to produce the core wavefunction data for each pseudopotential on-the-fly if desired, however pre-computed core wavefunction files can also be provided as input, either directly or via get_builder_from_protocol.

Process Flow

The steps of the WorkChain are:

  1. Perform a vc-relax of the input structure using the PwRelaxWorkChain (optional)
  2. Analyse the symmetry of the input/relaxed structure using get_xspectra_structures and return a marked structure for each symmetrically inequivalent absorbing atom site. Use the spacegroup number obtained to determine the list of polarisation vectors to calculate for each marked structure.
  3. Collect the core wavefunction data from each GIPAW pseudopotential provided as input (optional).
  4. Launch an XspectraCoreWorkChain sub-process for each marked structure
  5. Collect the powder spectra generated by each XspectraCoreWorkChain sub-process and compile a final spectrum for each element using a weighted average, based on the multiplicity of each absorbing atom site of the same element.

Inputs

In addition to inputs for the XspectraCoreWorkChain and PwRelaxWorkChain, other inputs to take notice of are:

  • gipaw_pseudos - an input namespace for UpfData nodes, taking the form {{element} : {upf}}, which defines the ground-state pseudopotential for the associated element.
  • core_hole_pseudos - an input namespace analagous to gipaw_pseudos, used to define each pseudopotential containing the core-hole. The namespace keys must be those of their associated element, not the marker to be used for the absorbing atom.
  • core_wfc_data - an optional input namespace for SinglefileData nodes, taking the form {{element} : {singlefile}}. The WorkChain will automatically skip the upf2plotcore.sh step if this input is provided. Note that this input must be complete for all elements to be calculated.
  • core_hole_treatments - an optional Dict input which defines the core-hole treatment (approximation) to be used in the XspectraCoreWorkChain for each element. Note that this does not need to be complete as any elements not defined in this input will use the default full-core-hole (FCH) approximation instead.
  • spglib_settings - an optional Dict input which defines symmetry tolerances to be used by spglib. Must contain valid options used by spglib.get_symmetry_dataset() and spglib.standardize_structure(), though not all options must be defined.
  • structure_preparation_settings - an optional Dict input which defines parameters to be used by get_xspectra_structures(). Must contain valid options used by get_xspectra_structures, though not all options must be defined.
  • return_all_powder_spectra - an optional Bool input which requests that all powder spectra generated during the runtime of the entire WorkChain be returned as output to the main WorkChain. Optional and set to False by default in order to keep the terminal display of the WorkChain's outputs in a condensed format, though potentially useful if spectra for each absorbing atom site are of interest.

PNOGillespie and others added 30 commits May 9, 2022 10:58
Added CalcJob implementations of the xspectra.x executable and upf2plotcore.sh shell script from the Quantum ESPRESSO library
Added Parser classes for the xspectra.x executable and upf2plotcore.sh shell script from the Quantum ESPRESSO library
Added entry points for both CalcJob and Parser classes required for XSpectra post-processing calculations
Change 'spectra_data' output to 'spectra'

Co-authored-by: Sebastiaan Huber <mail@sphuber.net>
Change the caplitalization for XSpectraCalculation to XspectraCalculation

Co-authored-by: Sebastiaan Huber <mail@sphuber.net>
Correct the capitalization of XSpectraParser to XspectraParser

Co-authored-by: Sebastiaan Huber <mail@sphuber.net>
Correct the capitalization of XSpectraCalculation to XspectraCalculation

Co-authored-by: Sebastiaan Huber <mail@sphuber.net>
Correct the capitalization of XSpectraParser to XspectraParser

Co-authored-by: Sebastiaan Huber <mail@sphuber.net>
…ved redundant file loop, and added new error code
Fixed the terms used in the XSpectra-specific error
codes in order to make them easier to read.
Changed filename assigned to `_Plotcore_FILENAME`
from `plotcore.out` to `stdout` in order to work
properly with the `aiida-shell` plugin.
Made corrections to the parsing of various output
parameters (e.g. energy levels and associated units)
in both spin-polarised and unpolarised cases. An
additional parameter `lsda` is also added to report
explicitly the case of spin polarisation.
Adds tests of the `XspectraParser`, covering spin-polarised
and non-spin-polarised cases, interrupted calculations, and
XSpectra-specific error codes 313 and 314.
Adds the following features to the `XspectraCalculation` and
`XspectraParser` classes:
- A save file ('xanes.sav') is now reserved by default and is printed
at the end of each calculation run or after a designated time limit.
The file can then be used for re-starting halted calculations or
re-plotting spectra from previously-finished calculations.
- The `XspectraCalculation` class now copies the save file from a
parent calculation if the calculation type is itself an
XspectraCalculation, thus re-starts and re-plot runs are handled
automatically.
- An error code has been added (315) for calculations which safely exit
after reaching their time limit, thus enabiling a restart.
- Additional information is now included in the `output_parameters`
node (e.g. the polarisation vectors used and whether the calculation was
set to "xonly_plot").
Updates `XspectraParser` tests to work with changes made in a previous
commit (commit 875fa58) and adds a new
test for error code 315 (job exceeded time limit)
Addresses aiidateam#837

Co-authored-by: Sebastiaan Huber <mail@sphuber.net>
Addresses PR aiidateam#837

Co-authored-by: Sebastiaan Huber <mail@sphuber.net>
Addresses PR aiidateam#837

Changes error code from 315 to 400 to match conventions

Co-authored-by: Sebastiaan Huber <mail@sphuber.net>
Addresses PR aiidateam#837

Required for commit aiidateam@746770e

Co-authored-by: Sebastiaan Huber <mail@sphuber.net>
Addresses PR aiidateam#837

Required with commit aiidateam@746770e

Co-authored-by: Sebastiaan Huber <mail@sphuber.net>
PNOGillespie and others added 12 commits October 28, 2022 19:25
Adds a new WorkChain for `xspectra.x` calculations to compute a complete
K-edge XANES for each element of a given structure using `pw.x` and
`xspectra.x`. The WorkChain uses the following process flow:

* Relax the given input structure using the `PwRelaxWorkChain`
(optional).
* Generate the core wavefunction of each ground-state pseudopotential
for each absorbing element considered (requires AiiDA-Shell plugin).
* Analyse the symmetry of the relaxed structure using `spglib`. Use the
outputs of the analysis to prepare inputs for `XspectraCoreWorkChain`
sub-processes.
* Call the `XspectraCoreWorkChain` for each structure prepared in the
previous step to generate the powder sample XANES for each identified
absorbing atom site in the structure.
* Compile all outputs from the `XspectraCoreWorkChain` sub-processes and
return a single XANES spectrum for each element considered in the
analysis.

Excited-state and ground-state pseudopotentials presently must be provided
using the input namespaces `core_hole_pseudos` and `gipaw_pseudos`
respectively, taking the form of a Dict node with the format:

	{'{element} : {'core_hole' : {upf}, 'gipaw' : {upf}}}

In addition to the final XANES spectra for each element, the powder
spectrum of each absorbing atom calculated can be returned as output to
the head WorkChain node with the optional input
`return_all_powder_spectra` (`False` by default).
Adds an input namespace `core_wfc_data` which can be used to provide
already-computed core wavefunction data files for each element. Must use
the format:
	{core_wfc_data : {"{element}" : {node}}}
Adds tests for the `get_builder_from_protocol` method of the
`XspectraCrystalWorkChain`
@superstar54 superstar54 self-requested a review February 20, 2023 10:42
Copy link
Member

@superstar54 superstar54 left a comment

Choose a reason for hiding this comment

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

@PNOGillespie Thanks for the PR! Nice work. I added a few comments.

src/aiida_quantumespresso/workflows/xspectra/crystal.py Outdated Show resolved Hide resolved
src/aiida_quantumespresso/workflows/xspectra/crystal.py Outdated Show resolved Hide resolved
src/aiida_quantumespresso/workflows/xspectra/crystal.py Outdated Show resolved Hide resolved
src/aiida_quantumespresso/workflows/xspectra/crystal.py Outdated Show resolved Hide resolved
src/aiida_quantumespresso/workflows/xspectra/crystal.py Outdated Show resolved Hide resolved
src/aiida_quantumespresso/workflows/xspectra/crystal.py Outdated Show resolved Hide resolved
src/aiida_quantumespresso/workflows/xspectra/crystal.py Outdated Show resolved Hide resolved
PNOGillespie and others added 5 commits March 20, 2023 14:14
Removes redundant code in `setup` and `get_xspectra_structures`

Co-authored-by: Xing Wang <xingwang1991@gmail.com>
Co-authored-by: Xing Wang <xingwang1991@gmail.com>
Addresses changes requested for PR aiidateam#888 (1):
* Expands the docstring for `get_spectra_by_element` to describe input
parameters and usage.
* Fixes an oversight in `get_xspectra_structures` where the
`standardized_structure` value was returned regardless of whether the
structure was actually standardized by the CalcFunction.
* Add a check for the `core_wfc_data` input to check for
improperly-formatted file content.
* Modify the `elements_list` input to be a required input and correct
all instances where data provenance was lost. Changes
`get_builder_from_protocol()` to set `elements_list` automatically based
on `pseudos` input if no `elements_list` is given
* Correct all instances of `optimized_structure` and `relaxed_structure`
to all be `optimized_structure`
* Change from simply using `append_` to add all CoreWorkChains to the
context and instead assign each their site indexes as keys (i.e.
`self.ctx.site_{i}`)
* Add a step to unassign the pseudopotential for the element of the
absorbing atom if the element does not exist in the structure (e.g. for
the case where only one atomic site of the element exists).
* Change the `structure_preparation_settings` input to be a dynamic
namespace instead of a single Dict node, thus ensuring data provenance
is maintained.
Updates the `test_crystal.yaml` to include the required `elements_list`
input generated by the protocol.
@PNOGillespie
Copy link
Contributor Author

Ok @superstar54, I've applied the suggested changes. I am planning to look into re-factoring the Core and Crystal WorkChains to properly maintain data provenance, but I think this would be too time-consuming to finish at the moment - especially considering the other plans we have going on with AiiDALab.

Rest assured, I have a list of potential improvements that I want to investigate and implement once time allows for it.

@superstar54 superstar54 self-requested a review March 22, 2023 10:39
@superstar54
Copy link
Member

@sphuber Thanks for the explanation.

@PNOGillespie thanks for the implementation and changes. Considering the need for our parallel work with AiiDAlab, I agree that we can merge this PR first, then add improvements in the future PR.

For the improvement, please also consider this issue.
When caching is enabled. I got this:

XspectraCalculation               ⏸ Waiting        Pausing after failed transport task: upload_calculation failed 5 times consecutively

The error are:

| Traceback (most recent call last):
 |   File "/opt/conda/lib/python3.9/site-packages/aiida/engine/utils.py", line 186, in exponential_backoff_retry
 |     result = await coro()
 |   File "/opt/conda/lib/python3.9/site-packages/aiida/engine/processes/calcjobs/tasks.py", line 90, in do_upload
 |     execmanager.upload_calculation(node, transport, calc_info, folder)
 |   File "/opt/conda/lib/python3.9/site-packages/aiida/engine/daemon/execmanager.py", line 254, in upload_calculation
 |     transport.copy(remote_abs_path, dest_rel_path)
 |   File "/opt/conda/lib/python3.9/site-packages/aiida/transports/plugins/local.py", line 560, in copy
 |     raise OSError('Source not found')
 | OSError: Source not found

This only happens when using upf2plotcore. It seems that the shell job upf2plotcore does not work with caching. I am not sure if this is special to upf2plotcore or is common for all ShellJob.

superstar54
superstar54 previously approved these changes Mar 22, 2023
@superstar54 superstar54 self-requested a review March 22, 2023 13:27
Comment on lines 279 to 280
use the mapping of {"element" : {"core_hole" : <upf>,
"gipaw" : <upf>}}
Copy link
Member

Choose a reason for hiding this comment

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

The docs check failed because of ERROR: Unexpected indentation.
This should fix the error.

Suggested change
use the mapping of {"element" : {"core_hole" : <upf>,
"gipaw" : <upf>}}
use the mapping of {"element" : {"core_hole" : <upf>, "gipaw" : <upf>}}

I will merge this PR after you fix it.

In the future, please run the docs locally and check the error. You can do it by:

pip install -e .[docs]
# then go to docs folder and run
make

@superstar54 superstar54 merged commit 01e7593 into aiidateam:main Mar 22, 2023
bastonero pushed a commit that referenced this pull request Apr 5, 2023
In this PR we propose to implement a new WorkChain intended to fully automate the calculation of K-edge XANES spectra for each element in a given input structure. This new WorkChain essentially automates the generation of input structures for XspectraCoreWorkChain sub-processes, as well as handling generation and setting of inputs for each sub-process, in order to compute a complete K-edge XANES spectrum for each element requested. The workflow process defined herein applies specifically to periodic systems as it uses the get_xspectra_structures CalcFunction to prepare input structures under the assumption that the input structure is not molecular. Due to the lack of pseudopotentials currently available which either contain GIPAW information or define a core-hole state, such pseudopotentials are presently required to be given as input. A code node to calculate the core wavefunction using upf2plotcore.sh in AiiDA-Shell can be provided to produce the core wavefunction data for each pseudopotential on-the-fly if desired, however pre-computed core wavefunction files can also be provided as input, either directly or via get_builder_from_protocol.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants