aiida_castep.workflows package#

Submodules#

aiida_castep.workflows.bands module#

Workflow from computing the band structures

class aiida_castep.workflows.bands.CastepBandsWorkChain(*args: Any, **kwargs: Any)[source]#

Bases: aiida.engine.processes.workchains.workchain.WorkChain

Workchain for running bands calculation.

This workchain does the following:

  1. Relax the structure if requested (eg. inputs passed to the relax namespace).

  2. Optionally: Do a SCF singlepoint calculation

  3. Do combined SCF + non-SCF calculation for bands and dos.

Inputs must be passed for the SCF calculation (dispatched to bands and DOS), others are optional.

Input for bands and dos calculations are optional. However, if they are needed, the full list of inputs must be passed. For the parameters node, one may choose to only specify those fields that need to be updated.

__abstractmethods__ = frozenset({})#
__module__ = 'aiida_castep.workflows.bands'#
_abc_impl = <_abc_data object>#
_base_wk_string = 'castep.base'#
_relax_wk_string = 'castep.relax'#
_task_name = 'spectral'#
classmethod define(spec)[source]#

Initialise the WorkChain class

inspect_bands_dos()[source]#

Inspect the bands and dos calculations

on_terminated()[source]#

Clean the remote directories of all called childrens

run_bands_dos()[source]#

Run the bands and the DOS calculations

run_relax()[source]#

Run the relaxation

run_scf()[source]#

Run the SCF calculation

run_seekpath()[source]#

Run seekpath to obtain the primitive structure and bands NOTE: Need to handle the magnetic symmetry properly

setup()[source]#

Setup the calculation

setup_restart_folder(inputs)[source]#

Setup restart folder related tags for the inputs

should_do_relax()[source]#

Wether we should do relax or not

should_run_scf()[source]#

Wether we should run SCF calculation?

should_run_seekpath()[source]#

Seekpath should only run if no explicit bands is provided

verify_relax()[source]#

Verify the relaxation

verify_scf()[source]#

Inspect the SCF calculation

aiida_castep.workflows.bands.compose_labelled_bands(bands, kpoints)[source]#

Add additional information from the kpoints allow richer informations to be stored such as band structure labels.

aiida_castep.workflows.bands.dos_from_bands(bands, smearing, npoints)[source]#

Compute DOS from bands

Parameters
  • bands – The BandsData to be used as input.

  • smearing – Smearing width in eV

  • npoints – Number of points

aiida_castep.workflows.bands.ensure_checkpoint(pdict)[source]#

Ensure that check/castep_bin file will be wirtten

aiida_castep.workflows.bands.nested_update(dict_in, update_dict)[source]#

Update the dictionary - combine nested subdictionary with update as well

aiida_castep.workflows.bands.nested_update_dict_node(dict_node, update_dict)[source]#

Utility to update a Dict node in a nested way

aiida_castep.workflows.bands.seekpath_structure_analysis(structure, **kwargs)[source]#

Primitivize the structure with SeeKpath and generate the high symmetry k-point path through its Brillouin zone. This calcfunction will take a structure and pass it through SeeKpath to get the normalized primitive cell and the path of high symmetry k-points through its Brillouin zone. Note that the returned primitive cell may differ from the original structure in which case the k-points are only congruent with the primitive cell. The keyword arguments can be used to specify various Seekpath parameters, such as:

with_time_reversal: True reference_distance: 0.025 recipe: ‘hpkot’ threshold: 1e-07 symprec: 1e-05 angle_tolerance: -1.0

Note that exact parameters that are available and their defaults will depend on your Seekpath version.

aiida_castep.workflows.base module#

This module contains the base workchain class which acts as the starting point of implementing more complex ones

class aiida_castep.workflows.base.CastepBaseWorkChain(*args: Any, **kwargs: Any)[source]#

Bases: aiida.engine.processes.workchains.workchain.WorkChain

A basic workchain for generic CASTEP calculations. We try to handle erros such as walltime exceeded or SCF not converged

__abstractmethods__ = frozenset({})#
__init__(*args, **kwargs)[source]#

Construct a WorkChain instance.

Construct the instance only if it is a sub class of WorkChain, otherwise raise InvalidOperation.

Parameters
  • inputs – work chain inputs

  • logger – aiida logger

  • runner – work chain runner

  • enable_persistence – whether to persist this work chain

__module__ = 'aiida_castep.workflows.base'#
_abc_impl = <_abc_data object>#
_calculation_class#

alias of aiida_castep.calculations.castep.CastepCalculation

_context_pain_dicts = ('parameters', 'settings')#
_error_handlers = [ErrorHandler(priority=900, method=<function _handle_scf_failure>), ErrorHandler(priority=500, method=<function _handle_walltime_limit>), ErrorHandler(priority=600, method=<function _handle_no_empty_bands>), ErrorHandler(priority=10000, method=<function _handle_stop_by_request>)]#
_handle_calculation_failure(calculation)[source]#

Handle failure of calculation by refering to a range of handlers

_handle_no_empty_bands(calculation)#

Handle the case where there is no empty bands

_handle_scf_failure(calculation)#

Handle case when SCF failed

_handle_stop_by_request(calculation)#

Handle the case when the stop flag is raised by the user

_handle_unexpected_failure(calculation, exception=None)[source]#

The calculation has failed for an unknown reason and could not be handled. If the unexpected_failure flag is true, this is the second consecutive unexpected failure and we abort the workchain. Otherwise we restart once more.

_handle_walltime_limit(calculation)#

Handle case when the walltime limit has reached

_prepare_process_inputs(inputs_dict)[source]#

Convert plain dictionary to Dict node

_spec = <aiida.engine.processes.workchains.workchain.WorkChainSpec object>#
_verbose = False#
classmethod define(spec)[source]#

Define this workchain

inspect_calculation()[source]#

Analyse the results of the previous calculation, return/restart/abort if necessary

inspect_dryrun()[source]#
on_terminated()[source]#

Clean the working directories of all child calculation jobs if clean_workdir=True in the inputs and the calculation is finished without problem.

prepare_calculation()[source]#

Prepare the inputs for the next calculation.

results()[source]#

Attach the outputs specified in the output specification from the last completed calculation

run_calculation()[source]#

Submit a new calculation, taking the input dictionary from the context at self.ctx.inputs

run_dry_run()[source]#
setup()[source]#

Initialize internal variables

should_dry_run()[source]#

Do a dryrun to validate the inputs

should_run_calculation()[source]#

Should we start the calculation (again)?

validate_dryrun_inputs()[source]#
validate_inputs()[source]#

Validate the inputs. Populate the inputs in the context This inputs is used as a staging area for the next calculation to be launched

aiida_castep.workflows.base._compute_castep_gam_offset(grids)[source]#

Compute the offset need to get gamma-centred grids for a given grid specification

Note that the offset are expressed in the reciprocal cell units.

aiida_castep.workflows.base._get_castep_output_file(calculation)[source]#

Return a list of the lines in the retrieved dot castep file

aiida_castep.workflows.base._handle_no_empty_bands(self, calculation)[source]#

Handle the case where there is no empty bands

aiida_castep.workflows.base._handle_scf_failure(self, calculation)[source]#

Handle case when SCF failed

aiida_castep.workflows.base._handle_stop_by_request(self, calculation)[source]#

Handle the case when the stop flag is raised by the user

aiida_castep.workflows.base._handle_walltime_limit(self, calculation)[source]#

Handle case when the walltime limit has reached

aiida_castep.workflows.common module#

Common module Courtesy to aiida-quantumespresso’s WorkChain design

class aiida_castep.workflows.common.ErrorHandler(priority, method)#

Bases: tuple

A namedtuple to define an error handler for a WorkChain.

The priority determines in which order the error handling methods are executed, with the higher priority being executed first. The method defines an unbound WorkChain method that takes an instance of a CalcJobNode as its sole argument. If the condition of the error handler is met, it should return an ErrorHandlerReport.

Parameters
  • priority – integer denoting the error handlers priority

  • method – the workchain class method

__getnewargs__()#

Return self as a plain tuple. Used by copy and pickle.

__module__ = 'aiida_castep.workflows.common'#
static __new__(_cls, priority, method)#

Create new instance of ErrorHandler(priority, method)

__repr__()#

Return a nicely formatted representation string

__slots__ = ()#
_asdict()#

Return a new dict which maps field names to their values.

_field_defaults = {}#
_fields = ('priority', 'method')#
_fields_defaults = {}#
classmethod _make(iterable)#

Make a new ErrorHandler object from a sequence or iterable

_replace(**kwds)#

Return a new ErrorHandler object replacing specified fields with new values

method#

Alias for field number 1

priority#

Alias for field number 0

class aiida_castep.workflows.common.ErrorHandlerReport(is_handled, do_break, exit_code)#

Bases: tuple

__getnewargs__()#

Return self as a plain tuple. Used by copy and pickle.

__module__ = 'aiida_castep.workflows.common'#
static __new__(_cls, is_handled=False, do_break=False, exit_code=ExitCode(status=0, message=None, invalidates_cache=False))#

Create new instance of ErrorHandlerReport(is_handled, do_break, exit_code)

__repr__()#

Return a nicely formatted representation string

__slots__ = ()#
_asdict()#

Return a new dict which maps field names to their values.

_field_defaults = {}#
_fields = ('is_handled', 'do_break', 'exit_code')#
_fields_defaults = {}#
classmethod _make(iterable)#

Make a new ErrorHandlerReport object from a sequence or iterable

_replace(**kwds)#

Return a new ErrorHandlerReport object replacing specified fields with new values

do_break#

Alias for field number 1

exit_code#

Alias for field number 2

is_handled#

Alias for field number 0

exception aiida_castep.workflows.common.UnexpectedCalculationFailure[source]#

Bases: aiida.common.exceptions.AiidaException

Exception for encountering unknown errors

__module__ = 'aiida_castep.workflows.common'#
aiida_castep.workflows.common.register_error_handler(cls, priority)[source]#

Decorator that will turn any function in an error handler for workchain that inherits from the BaseCastepWorkChain. The function expects two arguments, a workchain class and a priortity. The decorator will add the function as a class method to the workchain class and add an ErrorHandler tuple to the BaseCastepWorkChain._error_handlers attribute of the workchain. During failed calculation handling the inspect_calculation() outline method will call the _handle_calculation_failure which will loop over all error handler in the BaseCastepWorkChain._error_handlers, sorted with respect to the priority in reverse. If the workchain class defines a BaseCastepWorkChain._verbose attribute and is set to True, a report message will be fired when the error handler is executed.

Requirements on the function signature of error handling functions. The function to which the decorator is applied needs to take two arguments:

  • self: This is the instance of the workchain itself

  • calculation: This is the calculation that failed and needs to be investigated

The function body should usually consist of a single conditional that checks the calculation if the error that it is designed to handle is applicable. Although not required, it is advised that the function return an ErrorHandlerReport tuple when its conditional was met. If an error was handled it should set is_handled to True. If no other error handlers should be considered set do_break to True.

Parameters
  • cls – the workchain class to register the error handler with

  • priority – an integer that defines the order in which registered handlers will be called during the handling of a failed calculation. Higher priorities will be handled first

aiida_castep.workflows.relax module#

Module for Relaxation WorkChain

CHANGELOG:

  • 0.1.0: Added bypass option to skip convergence checking. The user is still responsible to setting the correct inputs.

class aiida_castep.workflows.relax.CastepAlterRelaxWorkChain(*args: Any, **kwargs: Any)[source]#

Bases: aiida_castep.workflows.relax.CastepRelaxWorkChain

A relaxation workflow that alternates between fixed cell and unfixed cell This is meidate the problem in CASTEP where if the cell is partially constraints the convergence would be very slow.

To overcome this problem, the structure should be relaxed with cell constraints then restart with fixed cell and repeat.

Following fields can be used in relax_options

Var_cell_iter_max

Maximum iterations in variable cell relaxation, default to 10

Fix_cell_iter_max

Maximum iterations in fixed cell relaxation, default to 20

__abstractmethods__ = frozenset({})#
__module__ = 'aiida_castep.workflows.relax'#
_abc_impl = <_abc_data object>#
_default_fix_cell_iter_max = 20#
_default_var_cell_iter_max = 10#
_max_meta_iterations = 11#
classmethod define(spec)[source]#

Define the workchain

inspect_relax()[source]#

Inspet the relaxation results, check if convergence is reached.

set_cons_and_imax(cell_cons, iter_max)[source]#

Set the cell constraints

setup()[source]#

Initialize internal parameters

class aiida_castep.workflows.relax.CastepRelaxWorkChain(*args: Any, **kwargs: Any)[source]#

Bases: aiida.engine.processes.workchains.workchain.WorkChain

WorkChain to relax structures. Restart the relaxation calculation until the structure is fully relaxed. Each CASTEP relaxation may finish without error with not fully relaxed structure if the number of iteration is exceeded (geom_max_iter). This workchain try to restart such calculations (wrapped in CastepBaseWorkChain) until the structure is fully relaxed

relax_options is a Dict of the options avaliable fields are:

  • restart_mode: mode of restart, choose from reuse (default), structure, continuation.

  • bypass: Bypass relaxation control - e.g. no checking of the convergence. Can be used for doing singlepoint calculation.

__abstractmethods__ = frozenset({})#
__module__ = 'aiida_castep.workflows.relax'#
_abc_impl = <_abc_data object>#
_max_meta_iterations = 10#
_push_parameters(workchain)[source]#

Push the parameters for completed calculation to the current inputs

_spec = <aiida.engine.processes.workchains.workchain.WorkChainSpec object>#
classmethod define(spec)[source]#

Define this workchain

finalize()[source]#

Finalize the workchain. Clean the remote working directories of the called calcjobs

inspect_relax()[source]#

Inspet the relaxation results, check if convergence is reached.

result()[source]#

Attach the output parameters and structure of the last workchain to the outputs.

run_relax()[source]#

Run the relaxation

setup()[source]#

Initialize internal parameters

should_run_relax()[source]#

Decide whether another iteration should be run

Module contents#

Sub-package of workchain and workfuctions for aiida-castep