def on_terminated(self): """ Clean the working directories of all child calculation jobs if `clean_workdir=True` in the inputs and the calculation is finished without problem. """ # Directly called the WorkChain method as this method replaces that of the BaseRestartWorkChain WorkChain.on_terminated(self) clean_workdir = self.inputs.get('clean_workdir', None) if clean_workdir is not None: clean_workdir = clean_workdir.value else: clean_workdir = False if clean_workdir is False: self.report('remote folders will not be cleaned') return if not self.ctx.is_finished: self.report( 'remote folders will not be cleaned because the workchain finished with error.' ) return cleaned_calcs = [] for called_descendant in self.node.called_descendants: if isinstance(called_descendant, orm.CalcJobNode): try: called_descendant.outputs.remote_folder._clean() # pylint: disable=protected-access cleaned_calcs.append(str(called_descendant.pk)) except (IOError, OSError, KeyError): pass if cleaned_calcs: self.report( f"cleaned remote folders of calculations: {' '.join(cleaned_calcs)}" )
def test_run_base_class(self): """Verify that it is impossible to run, submit or instantiate a base `WorkChain` class.""" with self.assertRaises(exceptions.InvalidOperation): WorkChain() with self.assertRaises(exceptions.InvalidOperation): launch.run(WorkChain) with self.assertRaises(exceptions.InvalidOperation): launch.run.get_node(WorkChain) with self.assertRaises(exceptions.InvalidOperation): launch.run.get_pk(WorkChain) with self.assertRaises(exceptions.InvalidOperation): launch.submit(WorkChain)
---------------- {{ cookiecutter.workchain_docstring }} """ # pylint: disable=attribute-defined-outside-init import random import numpy as np from aiida.common.extendeddicts import AttributeDict from aiida.engine import calcfunction, WorkChain, while_, append_ from aiida.plugins import WorkflowFactory, DataFactory from aiida_vasp.utils.workchains import prepare_process_inputs, compose_exit_code class {{ cookiecutter.workchain_name[0]|upper}}{{cookiecutter.workchain_name[1:] }}WorkChain(WorkChain): """ The {{ cookiecutter.workchain_name }} workchain ---------------- {{ cookiecutter.workchain_docstring }} """ _verbose = False _next_workchain_string = '{{ cookiecutter.next_workchain_to_call }}' _next_workchain = WorkflowFactory(_next_workchain_string) @classmethod def define(cls, spec): super({{ cookiecutter.workchain_name[0]|upper}}{{cookiecutter.workchain_name[1:] }}WorkChain, cls).define(spec)