aim2dat.aiida_workflows.cp2k.pdos_work_chain

Aiida work chains for cp2k to find parameters that converge the Kohn-Sham equations.

Module Contents

Classes

PDOSWorkChain

AiiDA work chain to calculate the projected density of states.

Attributes

StructureData

class aim2dat.aiida_workflows.cp2k.pdos_work_chain.PDOSWorkChain(*args, **kwargs)[source]

Bases: aim2dat.aiida_workflows.cp2k.base_core_work_chain._BaseCoreWorkChain

AiiDA work chain to calculate the projected density of states.

class SaveKeys

Bases: enum.Enum

Keys used to identify things in the saved instance state bundle.

Overview

Methods

name()

The name of the Enum member.

value()

The value of the Enum member.

CALC_ID : str = 'calc_id'
name()

The name of the Enum member.

value()

The value of the Enum member.

Overview

Properties

ctx

Get the context.

inputs

Return the inputs attribute dictionary or an empty one.

metadata

Return the metadata that were specified when this process instance was launched.

node

Return the ProcessNode used by this process to represent itself in the database.

process_class

Return the process class to run in the loop.

runner

Get process runner.

uuid

Return the UUID of the process which corresponds to the UUID of its associated ProcessNode.

Methods

build_process_type()

class The process type.

check_scf_convergence(calc)

Check if the scf-calculation is convergenced and increments the

decode_input_args(encoded)

Decode saved input arguments as they came from the saved instance state Bundle

define(spec)

class Specify inputs and outputs.

encode_input_args(inputs)

Encode input arguments such that they may be saved in a Bundle

exit_codes()

Return the namespace of exit codes defined for this WorkChain through its ProcessSpec.

exposed_inputs(process_class, namespace, agglomerate)

Gather a dictionary of the inputs that were exposed for a given Process class under an optional namespace.

exposed_outputs(node, process_class, namespace, agglomerate)

Return the outputs which were exposed from the process_class and emitted by the specific node

get_builder()

class -

get_exit_statuses(exit_code_labels)

class Return the exit status (integers) for the given exit code labels.

get_or_create_db_record()

class Create a process node that represents what happened in this process.

get_outputs(node)

Return a mapping of the outputs that should be attached as outputs to the work chain.

get_parent_calc()

Get the parent process node

get_process_handlers()

class -

get_process_handlers_by_priority()

Return list of process handlers where overrides from inputs.handler_overrides are taken into account.

get_provenance_inputs_iterator()

Get provenance input iterator.

init()

-

initialize_scf_parameters()

-

inspect_process()

Analyse the results of the previous process and call the handlers when necessary.

is_process_handler(process_handler_name)

class Return whether the given method name corresponds to a process handler of this class.

is_valid_cache(node)

class Check if the given node can be cached from.

kill(msg)

Kill the process and all the children calculations it called

load_instance_state(saved_state, load_context)

Load instance state.

on_create()

Called when a Process is created.

on_entered(from_state)

After entering a new state, save a checkpoint and update the latest process state change timestamp.

on_except(exc_info)

Log the exception by calling the report method with formatted stack trace from exception info object

on_exiting()

Ensure that any unstored nodes in the context are stored, before the state is exited

on_finish(result, successful)

Set the finish status on the process node.

on_output_emitting(output_port, value)

The process has emitted a value on the given output port.

on_paused(msg)

The Process was paused so set the paused attribute on the process node

on_playing()

The Process was unpaused so remove the paused attribute on the process node

on_run()

-

on_terminated()

Clean working directories of the calculations.

on_wait(awaitables)

Entering the WAITING state.

out(output_port, value)

Attach output to output port.

out_many(out_dict)

Attach outputs to multiple output ports.

post_processing()

-

report(msg, *args, **kwargs)

Log a message to the logger, which should get saved to the database through the attached DbLogHandler.

results()

Attach the outputs specified in the output specification from the last completed process.

run()

-

run_process()

Run the next process, taking the input dictionary from the context at self.ctx.inputs.

save_instance_state(out_state, save_context)

Save instance state.

set_status(status)

The status of the Process is about to be changed, so we reflect this is in node’s attribute proxy.

setup()

Initialize context variables that are used during the logical flow of the BaseRestartWorkChain.

setup_inputs()

-

setup_wc_specific_inputs()

Derive super cell and set input parameter.

should_run_process()

Return whether a new process should be run.

spec()

class -

spec_metadata()

Return the metadata port namespace of the process specification of this process.

submit(process, **kwargs)

Submit process for execution.

switch_to_broyden_mixing(calc)

Switch to the Broyden mixing scheme in case of numerical instabilities with the Pulay

switch_to_open_shell_ks(calc)

Turn on restricted or unrestricted open-shell Kohn-Sham equations in case of an odd

to_context(**kwargs)

Add a dictionary of awaitables to the context.

update_outputs()

Attach new outputs to the node since the last call.

wc_specific_post_processing()

-

SINGLE_OUTPUT_LINKNAME : str = 'result'
property ctx : aiida.common.extendeddicts.AttributeDict

Get the context.

property inputs : plumpy.utils.AttributesFrozendict

Return the inputs attribute dictionary or an empty one.

This overrides the property of the base class because that can also return None. This override ensures calling functions that they will always get an instance of AttributesFrozenDict.

property metadata : aiida.common.extendeddicts.AttributeDict

Return the metadata that were specified when this process instance was launched.

Returns:

metadata dictionary

property node : aiida.orm.WorkChainNode

Return the ProcessNode used by this process to represent itself in the database.

Returns:

instance of sub class of ProcessNode

property process_class : type[aiida.engine.processes.process.Process]

Return the process class to run in the loop.

property runner : aiida.engine.runners.Runner

Get process runner.

property uuid : str

Return the UUID of the process which corresponds to the UUID of its associated ProcessNode.

Returns:

the UUID associated to this process instance

classmethod build_process_type() str

The process type.

Returns:

string of the process type

Note: This could be made into a property ‘process_type’ but in order to have it be a property of the class it would need to be defined in the metaclass, see https://bugs.python.org/issue20659

check_scf_convergence(calc)

Check if the scf-calculation is convergenced and increments the internal level of mixing parameters.

decode_input_args(encoded: str) dict[str, Any]

Decode saved input arguments as they came from the saved instance state Bundle

Parameters:
encoded: str

encoded (serialized) inputs

Returns:

The decoded input args

classmethod define(spec)[source]

Specify inputs and outputs.

encode_input_args(inputs: dict[str, Any]) str

Encode input arguments such that they may be saved in a Bundle

Parameters:
inputs: dict[str, Any]

A mapping of the inputs as passed to the process

Returns:

The encoded (serialized) inputs

exit_codes() aiida.engine.processes.exit_code.ExitCodesNamespace

Return the namespace of exit codes defined for this WorkChain through its ProcessSpec.

The namespace supports getitem and getattr operations with an ExitCode label to retrieve a specific code. Additionally, the namespace can also be called with either the exit code integer status to retrieve it.

Returns:

ExitCodesNamespace of ExitCode named tuples

exposed_inputs(process_class: type[Process], namespace: str | None = None, agglomerate: bool = True) aiida.common.extendeddicts.AttributeDict

Gather a dictionary of the inputs that were exposed for a given Process class under an optional namespace.

Parameters:
process_class: type[Process]

Process class whose inputs to try and retrieve

namespace: str | None = None

PortNamespace in which to look for the inputs

agglomerate: bool = True

If set to true, all parent namespaces of the given namespace will also be searched for inputs. Inputs in lower-lying namespaces take precedence.

Returns:

exposed inputs

exposed_outputs(node: aiida.orm.ProcessNode, process_class: type[Process], namespace: str | None = None, agglomerate: bool = True) aiida.common.extendeddicts.AttributeDict

Return the outputs which were exposed from the process_class and emitted by the specific node

Parameters:
node: aiida.orm.ProcessNode

process node whose outputs to try and retrieve

namespace: str | None = None

Namespace in which to search for exposed outputs.

agglomerate: bool = True

If set to true, all parent namespaces of the given namespace will also be searched for outputs. Outputs in lower-lying namespaces take precedence.

Returns:

exposed outputs

classmethod get_builder() aiida.engine.processes.builder.ProcessBuilder
classmethod get_exit_statuses(exit_code_labels: Iterable[str]) list[int]

Return the exit status (integers) for the given exit code labels.

Parameters:
exit_code_labels: Iterable[str]

a list of strings that reference exit code labels of this process class

Returns:

list of exit status integers that correspond to the given exit code labels

Raises:

AttributeError – if at least one of the labels does not correspond to an existing exit code

classmethod get_or_create_db_record() aiida.orm.ProcessNode

Create a process node that represents what happened in this process.

Returns:

A process node

get_outputs(node) Mapping[str, aiida.orm.Node]

Return a mapping of the outputs that should be attached as outputs to the work chain.

By default this method returns the outputs of the last completed calculation job. This method can be overridden if the implementation wants to update those outputs before attaching them. Make sure that if the content of an output node is modified that this is done through a calcfunction in order to not lose the provenance.

get_parent_calc() aiida.orm.ProcessNode | None

Get the parent process node

Returns:

the parent process node if there is one

classmethod get_process_handlers() list[types.FunctionType]
get_process_handlers_by_priority() list[tuple[int, types.FunctionType]]

Return list of process handlers where overrides from inputs.handler_overrides are taken into account.

get_provenance_inputs_iterator() Iterator[tuple[str, aiida.engine.processes.ports.InputPort | aiida.engine.processes.ports.PortNamespace]]

Get provenance input iterator.

Return type:

filter

init() None
initialize_scf_parameters()
inspect_process() aiida.engine.processes.ExitCode | None

Analyse the results of the previous process and call the handlers when necessary.

If the process is excepted or killed, the work chain will abort. Otherwise any attached handlers will be called in order of their specified priority. If the process was failed and no handler returns a report indicating that the error was handled, it is considered an unhandled process failure and the process is relaunched. If this happens twice in a row, the work chain is aborted. In the case that at least one handler returned a report the following matrix determines the logic that is followed:

Process Handler Handler Action result report? exit code —————————————– Success yes == 0 Restart Success yes != 0 Abort Failed yes == 0 Restart Failed yes != 0 Abort

If no handler returned a report and the process finished successfully, the work chain’s work is considered done and it will move on to the next step that directly follows the while conditional, if there is one defined in the outline.

classmethod is_process_handler(process_handler_name: str | types.FunctionType) bool

Return whether the given method name corresponds to a process handler of this class.

Parameters:
process_handler_name: str | types.FunctionType

string name of the instance method

Returns:

boolean, True if corresponds to process handler, False otherwise

classmethod is_valid_cache(node: aiida.orm.ProcessNode) bool

Check if the given node can be cached from.

Overriding this method allows Process sub-classes to modify when corresponding process nodes are considered as a cache.

Warning

When overriding this method, make sure to return False at least in all cases when super()._node.base.caching.is_valid_cache(node) returns False. Otherwise, the invalidates_cache keyword on exit codes may have no effect.

kill(msg: str | None = None) bool | plumpy.futures.Future

Kill the process and all the children calculations it called

Parameters:
msg: str | None = None

message

load_instance_state(saved_state, load_context)

Load instance state.

Parameters:
saved_state

saved instance state

load_context

on_create() None

Called when a Process is created.

on_entered(from_state: plumpy.process_states.State | None) None

After entering a new state, save a checkpoint and update the latest process state change timestamp.

on_except(exc_info: tuple[Any, Exception, types.TracebackType]) None

Log the exception by calling the report method with formatted stack trace from exception info object and store the exception string as a node attribute

Parameters:
exc_info: tuple[Any, Exception, types.TracebackType]

the sys.exc_info() object (type, value, traceback)

on_exiting() None

Ensure that any unstored nodes in the context are stored, before the state is exited

After the state is exited the next state will be entered and if persistence is enabled, a checkpoint will be saved. If the context contains unstored nodes, the serialization necessary for checkpointing will fail.

on_finish(result: int | aiida.engine.processes.exit_code.ExitCode | None, successful: bool) None

Set the finish status on the process node.

Parameters:
result: int | aiida.engine.processes.exit_code.ExitCode | None

result of the process

successful: bool

whether execution was successful

on_output_emitting(output_port: str, value: Any) None

The process has emitted a value on the given output port.

Parameters:
output_port: str

The output port name the value was emitted on

value: Any

The value emitted

on_paused(msg: str | None = None) None

The Process was paused so set the paused attribute on the process node

Parameters:
msg: str | None = None

message

on_playing() None

The Process was unpaused so remove the paused attribute on the process node

on_run()
on_terminated()

Clean working directories of the calculations.

on_wait(awaitables: collections.abc.Sequence[Awaitable])

Entering the WAITING state.

out(output_port: str, value: Any = None) None

Attach output to output port.

The name of the port will be used as the link label.

Parameters:
output_port: str

name of output port

value: Any = None

value to put inside output port

out_many(out_dict: dict[str, Any]) None

Attach outputs to multiple output ports.

Keys of the dictionary will be used as output port names, values as outputs.

Parameters:
out_dict : dict

output dictionary

post_processing()
report(msg: str, *args, **kwargs) None

Log a message to the logger, which should get saved to the database through the attached DbLogHandler.

The pk, class name and function name of the caller are prepended to the given message

Parameters:
msg: str

message to log

*args

args to pass to the log call

**kwargs

kwargs to pass to the log call

results() aiida.engine.processes.ExitCode | None

Attach the outputs specified in the output specification from the last completed process.

run() Any
run_process() aiida.engine.processes.workchains.context.ToContext

Run the next process, taking the input dictionary from the context at self.ctx.inputs.

save_instance_state(out_state, save_context)

Save instance state.

Parameters:
out_state

state to save in

save_context

set_status(status: str | None) None

The status of the Process is about to be changed, so we reflect this is in node’s attribute proxy.

Parameters:
status: str | None

the status message

setup() None

Initialize context variables that are used during the logical flow of the BaseRestartWorkChain.

setup_inputs()
setup_wc_specific_inputs()[source]

Derive super cell and set input parameter.

should_run_process() bool

Return whether a new process should be run.

This is the case as long as the last process has not finished successfully and the maximum number of restarts has not yet been exceeded.

classmethod spec() WorkChainSpec
spec_metadata() aiida.engine.processes.ports.PortNamespace

Return the metadata port namespace of the process specification of this process.

submit(process: type[Process], **kwargs) aiida.orm.ProcessNode

Submit process for execution.

Parameters:
process: type[Process]

process

Returns:

the calculation node of the process

switch_to_broyden_mixing(calc)

Switch to the Broyden mixing scheme in case of numerical instabilities with the Pulay mixing scheme.

switch_to_open_shell_ks(calc)

Turn on restricted or unrestricted open-shell Kohn-Sham equations in case of an odd number of electrons.

to_context(**kwargs: aiida.engine.processes.workchains.awaitable.Awaitable | aiida.orm.ProcessNode) None

Add a dictionary of awaitables to the context.

This is a convenience method that provides syntactic sugar, for a user to add multiple intersteps that will assign a certain value to the corresponding key in the context of the work chain.

update_outputs() None

Attach new outputs to the node since the last call.

Does nothing, if self.metadata.store_provenance is False.

wc_specific_post_processing()
aim2dat.aiida_workflows.cp2k.pdos_work_chain.StructureData[source]