Skip to content

Commit

Permalink
Update the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sphuber committed Jan 30, 2023
1 parent 52424f2 commit f17b601
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
"""CalcFunction to compute the powder spectrum of a set of XANES spectra from `XspectraCalculation`s."""

"""CalcFunction to compute the powder spectrum of a set of XANES spectra from ``XspectraCalculation``."""
from aiida.common import ValidationError
from aiida.engine import calcfunction
from aiida.orm import XyData
Expand All @@ -10,10 +9,9 @@
def get_powder_spectrum(**kwargs): # pylint: disable=too-many-statements
"""Combine the given spectra into a single "Powder" spectrum, representing the XAS of a powder sample.
The function expects between 1 and 3 XyData nodes from `XspectraCalculation`s whose
The function expects between 1 and 3 XyData nodes from ``XspectraCalculation`` whose
polarisation vectors are the basis vectors of the original crystal structure (100, 010, 001).
"""

spectra = [node for node in kwargs.values() if isinstance(node, XyData)]
vectors = [node.creator.res['xepsilon'] for node in spectra]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
# -*- coding: utf-8 -*-
"""CalcFunction to merge multiple XyData nodes of calculated XANES spectra into a new XyData node."""

"""CalcFunction to merge multiple ``XyData`` nodes of calculated XANES spectra into a new ``XyData`` node."""
from aiida.engine import calcfunction
from aiida.orm import XyData


@calcfunction
def merge_spectra(**kwargs):
"""Compile all calculated spectra into a single XyData node for easier plotting.
"""Compile all calculated spectra into a single ``XyData`` node for easier plotting.
The keyword arguments must be an arbitrary number of XyData nodes from
The keyword arguments must be an arbitrary number of ``XyData`` nodes from
the `output_spectra` of `XspectraCalculation`s, all other `kwargs` will be discarded at
runtime.
Returns a single XyData node where each set of y values is labelled
Returns a single ``XyData`` node where each set of y values is labelled
according to the polarisation vector used for the `XspectraCalculation`.
"""

output_spectra = XyData()
y_arrays_list = []
y_units_list = []
Expand Down
70 changes: 33 additions & 37 deletions src/aiida_quantumespresso/workflows/xspectra/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,45 +26,41 @@
class XspectraCoreWorkChain(ProtocolMixin, WorkChain):
"""Workchain to compute X-ray absorption spectra for a given structure using Quantum ESPRESSO.
The workflow follows the process required to compute the XAS of an input structure:
an SCF calculation is performed using the provided structure, which is then followed by
the calculation of the XAS itself by XSpectra. The calculations performed by the WorkChain
in a typical run will be:
- PwSCF calculation with pw.x of the input structure with a core-hole present.
- Generation of core-wavefunction data with upf2plotcore.sh (if requested).
- XAS calculation with xspectra.x to compute the Lanczos coefficients and print the
XANES spectra for the polarisation vectors requested in the input.
- Collation of output data from pw.x and xspectra.x calculations, including a
combination of XANES dipole spectra based on polarisation vectors to represent the
powder spectrum of the structure (if requested).
If ``run_replot = True`` is set in the inputs (defaults to False), the WorkChain will run
a second xspectra.x calculation which replots the spectra produced from the ``xs_prod``
step. This option can be very useful for obtaining a final spectrum at low levels of
broadening (relative to the default of 0.5 eV), particularly as higher levels of
broadening significantly speed up the convergence of the Lanczos procedure. Inputs for the
replot calculation are found in the ``xs_plot`` namespace.
The core-wavefunction plot derived from the ground-state of the absorbing element can
be provided as a top-level input or produced by the WorkChain. If left to the WorkChain,
the ground-state pseudopotential assigned to the absorbing element will be used to
generate this data using the upf2plotcore.sh utility script (via the ``aiida-shell``
plugin).
The workflow follows the process required to compute the XAS of an input structure: an SCF calculation is performed
using the provided structure, which is then followed by the calculation of the XAS itself by XSpectra. The
calculations performed by the WorkChain in a typical run will be:
- PwSCF calculation with pw.x of the input structure with a core-hole present.
- Generation of core-wavefunction data with upf2plotcore.sh (if requested).
- XAS calculation with xspectra.x to compute the Lanczos coefficients and print the XANES spectra for the
polarisation vectors requested in the input.
- Collation of output data from pw.x and xspectra.x calculations, including a combination of XANES dipole spectra
based on polarisation vectors to represent the powder spectrum of the structure (if requested).
If ``run_replot = True`` is set in the inputs (defaults to False), the WorkChain will run a second xspectra.x
calculation which replots the spectra produced from the ``xs_prod`` step. This option can be very useful for
obtaining a final spectrum at low levels of broadening (relative to the default of 0.5 eV), particularly as higher
levels of broadening significantly speed up the convergence of the Lanczos procedure. Inputs for the replot
calculation are found in the ``xs_plot`` namespace.
The core-wavefunction plot derived from the ground-state of the absorbing element can be provided as a top-level
input or produced by the WorkChain. If left to the WorkChain, the ground-state pseudopotential assigned to the
absorbing element will be used to generate this data using the upf2plotcore.sh utility script (via the
``aiida-shell`` plugin).
In its current stage of development, the workflow requires the following:
- An input structure where the desired absorbing atom in the system is marked as a
separate Kind. The default behaviour for the WorkChain is to set the Kind name as
'X', however this can be changed via the `overrides` dictionary.
- A code node for ``upf2plotcore``, configured for the ``aiida-shell`` plugin
(https://github.com/sphuber/aiida-shell). Alternatively, a ``SinglefileData`` node
from a previous ``ShellJob`` run can be supplied under ``inputs.core_wfc_data``.
- A suitable pair of pseudopotentials for the element type of the absorbing atom,
one for the ground-state occupancy which contains GIPAW informtation for the core
level of interest for the XAS (e.g. 1s in the case of a K-edge calculation) and
the other containing a core hole.
- For the moment this can be passed either via the ``core_hole_pseudos`` field
in ``get_builder_from_protocol`` or via the overrides, but will be
changed later once full families of core-hole pseudopotentials become
available.
- An input structure where the desired absorbing atom in the system is marked as a separate Kind. The default
behaviour for the WorkChain is to set the Kind name as 'X', however this can be changed via the `overrides`
dictionary.
- A code node for ``upf2plotcore``, configured for the ``aiida-shell`` plugin
(https://github.com/sphuber/aiida-shell). Alternatively, a ``SinglefileData`` node from a previous ``ShellJob``
run can be supplied under ``inputs.core_wfc_data``.
- A suitable pair of pseudopotentials for the element type of the absorbing atom, one for the ground-state occupancy
which contains GIPAW informtation for the core level of interest for the XAS (e.g. 1s in the case of a K-edge
calculation) and the other containing a core hole. (For the moment this can be passed either via the
``core_hole_pseudos`` field in ``get_builder_from_protocol`` or via the overrides, but will be changed later once
full families of core-hole pseudopotentials become available).
"""

# pylint: disable=too-many-public-methods, too-many-statements
Expand Down
5 changes: 2 additions & 3 deletions tests/workflows/xspectra/test_core.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
# -*- coding: utf-8 -*-
"""Tests for the `XspectraCoreWorkChain` class."""

import io

from aiida import engine, orm
from aiida.common import LinkType
from aiida.engine.utils import instantiate_process
from aiida.manage.manager import get_manager
from plumpy import ProcessState
import pytest


def instantiate_process(cls_or_builder, inputs=None):
"""Instantiate a process, from a ``Process`` class or ``ProcessBuilder`` instance."""
from aiida.engine.utils import instantiate_process as _instantiate_process
manager = get_manager()
runner = manager.get_runner()
return instantiate_process(runner, cls_or_builder **{inputs or {})
return _instantiate_process(runner, cls_or_builder, **(inputs or {}))


@pytest.fixture
Expand Down

0 comments on commit f17b601

Please sign in to comment.