From f17b601f0db5e222a2b2a2efaf262a8985b1ec6f Mon Sep 17 00:00:00 2001 From: Sebastiaan Huber Date: Mon, 30 Jan 2023 15:31:02 +0100 Subject: [PATCH] Update the docs --- .../functions/xspectra/get_powder_spectrum.py | 6 +- .../functions/xspectra/merge_spectra.py | 10 ++- .../workflows/xspectra/core.py | 70 +++++++++---------- tests/workflows/xspectra/test_core.py | 5 +- 4 files changed, 41 insertions(+), 50 deletions(-) diff --git a/src/aiida_quantumespresso/calculations/functions/xspectra/get_powder_spectrum.py b/src/aiida_quantumespresso/calculations/functions/xspectra/get_powder_spectrum.py index 6843f71c6..c152ffd30 100644 --- a/src/aiida_quantumespresso/calculations/functions/xspectra/get_powder_spectrum.py +++ b/src/aiida_quantumespresso/calculations/functions/xspectra/get_powder_spectrum.py @@ -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 @@ -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] diff --git a/src/aiida_quantumespresso/calculations/functions/xspectra/merge_spectra.py b/src/aiida_quantumespresso/calculations/functions/xspectra/merge_spectra.py index 56f9875f4..4e9d7116f 100644 --- a/src/aiida_quantumespresso/calculations/functions/xspectra/merge_spectra.py +++ b/src/aiida_quantumespresso/calculations/functions/xspectra/merge_spectra.py @@ -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 = [] diff --git a/src/aiida_quantumespresso/workflows/xspectra/core.py b/src/aiida_quantumespresso/workflows/xspectra/core.py index 5b21aa0bc..474db806e 100644 --- a/src/aiida_quantumespresso/workflows/xspectra/core.py +++ b/src/aiida_quantumespresso/workflows/xspectra/core.py @@ -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 diff --git a/tests/workflows/xspectra/test_core.py b/tests/workflows/xspectra/test_core.py index b4293d3bf..1615eef5e 100644 --- a/tests/workflows/xspectra/test_core.py +++ b/tests/workflows/xspectra/test_core.py @@ -1,11 +1,9 @@ # -*- 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 @@ -13,9 +11,10 @@ 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