def run_ph(self):
        """
        Run a PhCalculation either starting from a previous PwCalculation or restarting from a
        previous PhCalculation run in this workchain
        """
        self.ctx.iteration += 1

        # Create local copy of general inputs stored in the context and adapt for next calculation
        inputs = dict(self.ctx.inputs)

        if isinstance(self.ctx.restart_calc, PhCalculation):
            inputs['parameters']['INPUTPH']['recover'] = True
        elif isinstance(self.ctx.restart_calc, PwCalculation):
            pass
        else:
            ctype = type(self.ctx.restart_calc)
            self.abort_nowait(
                "The type '{}' of the parent calculation is invalid".format(
                    ctype))

        inputs['parent_folder'] = self.ctx.restart_calc.out.remote_folder
        inputs['parameters'] = ParameterData(dict=inputs['parameters'])
        inputs['settings'] = ParameterData(dict=inputs['settings'])

        process = PhCalculation.process()
        running = submit(process, **inputs)

        self.report('launching PhCalculation<{}> iteration #{}'.format(
            running.pid, self.ctx.iteration))

        return ToContext(calculations=append_(running))
Exemple #2
0
    def run_atoms(self):
        """
        Run a separate HpBaseWorkChain for each of the defined Hubbard atoms
        """
        workchain = self.ctx.initialization

        if not workchain.is_finished_ok:
            self.report(
                'initialization workchain<{}> failed with finish status {}, aborting...'
                .format(workchain.pk, workchain.finish_status))
            return self.ERROR_CHILD_WORKCHAIN_FAILED

        output_params = workchain.out.output_parameters.get_dict()
        hubbard_sites = output_params['hubbard_sites']

        for site_index, site_kind in hubbard_sites.iteritems():

            do_only_key = 'do_one_only({})'.format(site_index)

            inputs = AttributeDict(self.exposed_inputs(HpBaseWorkChain))
            inputs.parameters = inputs.parameters.get_dict()
            inputs.parameters['INPUTHP'][do_only_key] = True
            inputs.parameters = ParameterData(dict=inputs.parameters)

            running = self.submit(HpBaseWorkChain, **inputs)

            self.report(
                'launching HpBaseWorkChain<{}> for atomic site {} of kind {}'.
                format(running.pk, site_index, site_kind))
            self.to_context(workchains=append_(running))
Exemple #3
0
    def run_calculation(self):
        """Run a new calculation, taking the input dictionary from the context at self.ctx.inputs."""
        self.ctx.iteration += 1

        try:
            unwrapped_inputs = self.ctx.inputs
        except AttributeError:
            raise ValueError(
                'no calculation input dictionary was defined in self.ctx.inputs'
            )

        inputs = prepare_process_inputs(unwrapped_inputs)
        process = self._calculation_class.process()
        running = self.submit(process, **inputs)

        if hasattr(running, 'pid'):
            self.report('launching {}<{}> iteration #{}'.format(
                self._calculation_class.__name__, running.pid,
                self.ctx.iteration))
        else:
            self.report('launching {}<{}> iteration #{}'.format(
                self._calculation_class.__name__, running.pk,
                self.ctx.iteration))

        return ToContext(calculations=append_(running))
Exemple #4
0
    def run_scf_smearing(self):
        """
        Run a simple PwCalculation with smeared occupations
        """
        inputs = copy(self.ctx.inputs)
        inputs.parameters = deepcopy(inputs.parameters)

        inputs.parameters['CONTROL']['calculation'] = 'scf'
        inputs.parameters['SYSTEM']['occupations'] = 'smearing'
        inputs.parameters['SYSTEM']['smearing'] = inputs.parameters[
            'SYSTEM'].get('smearing', self.defaults.smearing_method)
        inputs.parameters['SYSTEM']['degauss'] = inputs.parameters[
            'SYSTEM'].get('degauss', self.defaults.smearing_degauss)
        inputs.parameters['SYSTEM']['u_projection_type'] = inputs.parameters[
            'SYSTEM'].get('u_projection_type',
                          self.defaults.u_projection_type_scf)
        inputs.parameters['ELECTRONS']['conv_thr'] = inputs.parameters[
            'ELECTRONS'].get('conv_thr', self.defaults.conv_thr_preconverge)

        inputs.parameters = ParameterData(dict=inputs.parameters)

        running = self.submit(PwBaseWorkChain, **inputs)

        self.report(
            'launching PwBaseWorkChain<{}> with smeared occupations'.format(
                running.pk))

        return ToContext(workchains_scf=append_(running))
Exemple #5
0
    def run_relax(self):
        """
        Run the PwRelaxWorkChain to run a relax PwCalculation
        """
        inputs = copy(self.ctx.inputs)
        inputs.parameters = deepcopy(inputs.parameters)

        u_projection_type_relax = inputs.parameters['SYSTEM'].get(
            'u_projection_type', self.defaults.u_projection_type_relax)

        if u_projection_type_relax != self.defaults.u_projection_type_relax:
            self.report(
                "warning: you specified 'u_projection_type = {}' in the input parameters, but this will crash "
                "pw.x, changing it to '{}'".format(
                    u_projection_type_relax,
                    self.defaults.u_projection_type_relax))

        inputs.parameters['SYSTEM'][
            'u_projection_type'] = self.defaults.u_projection_type_relax

        inputs.parameters = ParameterData(dict=inputs.parameters)

        running = self.submit(PwRelaxWorkChain, **inputs)

        self.report('launching PwRelaxWorkChain<{}> iteration #{}'.format(
            running.pk, self.ctx.iteration))

        return ToContext(workchains_relax=append_(running))
 def do_submit(self):
     if self.should_submit():
         self.report('Submitting nested workchain.')
         return ToContext(
             workchain=append_(self.submit(
                 NestedWorkChain,
                 inp=self.inputs.inp - 1
             ))
         )
Exemple #7
0
    def run_relax(self):
        """Run the BaseVaspWf for the relaxation."""
        self.ctx.inputs.structure = self.ctx.current_structure
        inputs = prepare_process_inputs(self.ctx.inputs)
        running = self.submit(VaspBaseWf, **inputs)
        self.ctx.iteration += 1

        self.report('launching VaspBaseWf{}'.format(running))

        return ToContext(workchains=append_(running))
Exemple #8
0
    def run_final(self):
        """
        Perform the final HpCalculation to collect the various components of the chi matrices
        """
        inputs = AttributeDict(self.exposed_inputs(HpBaseWorkChain))
        inputs.parameters = inputs.parameters.get_dict()
        inputs.parameters['INPUTHP']['collect_chi'] = True
        inputs.parameters = ParameterData(dict=inputs.parameters)
        inputs.parent_folder = self.ctx.merged_retrieved
        inputs.pop('parent_calculation', None)

        running = self.submit(HpBaseWorkChain, **inputs)

        self.report('launching HpBaseWorkChain<{}> to collect matrices'.format(
            running.pk))
        self.to_context(workchains=append_(running))
Exemple #9
0
    def run_calculation(self):
        """
        Run a new calculation, taking the input dictionary from the context at self.ctx.inputs
        """
        self.ctx.iteration += 1

        try:
            unwrapped_inputs = self.ctx.inputs
        except AttributeError:
            raise ValueError('no calculation input dictionary was defined in self.ctx.inputs')

        inputs = self._prepare_process_inputs(self._calculation_class, unwrapped_inputs)
        calculation = self.submit(self._calculation_class, **inputs)

        self.report('launching {}<{}> iteration #{}'.format(self.ctx.calc_name, calculation.pk, self.ctx.iteration))

        return ToContext(calculations=append_(calculation))
Exemple #10
0
    def run_hp(self):
        """
        Run the HpWorkChain restarting from the last completed scf calculation
        """
        self.ctx.iteration += 1
        workchain = self.ctx.workchains_scf[-1]
        parent_calculation = workchain.out.output_parameters.get_inputs(
            node_type=PwCalculation)[0]

        inputs = self.exposed_inputs(HpWorkChain, namespace='hp')
        inputs['parent_calculation'] = parent_calculation

        running = self.submit(HpWorkChain, **inputs)

        self.report('launching HpWorkChain<{}> iteration #{}'.format(
            running.pk, self.ctx.iteration))

        return ToContext(workchains_hp=append_(running))
Exemple #11
0
    def run_scf_fixed_magnetic(self):
        """
        Run a simple PwCalculation with fixed occupations restarting from the previous calculation
        with smeared occupations, based on which the number of bands and total magnetization are fixed
        """
        inputs = copy(self.ctx.inputs)
        inputs.parameters = deepcopy(inputs.parameters)

        previous_workchain = self.ctx.workchains_scf[-1]
        previous_parameters = previous_workchain.out.output_parameters

        inputs.parameters['CONTROL']['calculation'] = 'scf'
        inputs.parameters['CONTROL']['restart_mode'] = 'restart'
        inputs.parameters['SYSTEM']['occupations'] = 'fixed'
        inputs.parameters['SYSTEM'].pop('degauss', None)
        inputs.parameters['SYSTEM'].pop('smearing', None)
        inputs.parameters['SYSTEM'].pop('starting_magnetization', None)
        inputs.parameters['SYSTEM']['nbnd'] = previous_parameters.get_dict(
        )['number_of_bands']
        inputs.parameters['SYSTEM'][
            'tot_magnetization'] = previous_parameters.get_dict(
            )['total_magnetization']
        inputs.parameters['SYSTEM']['u_projection_type'] = inputs.parameters[
            'SYSTEM'].get('u_projection_type',
                          self.defaults.u_projection_type_scf)
        inputs.parameters['ELECTRONS']['conv_thr'] = inputs.parameters[
            'ELECTRONS'].get('conv_thr', self.defaults.conv_thr_strictfinal)

        inputs.parameters = ParameterData(dict=inputs.parameters)

        running = self.submit(PwBaseWorkChain, **inputs)

        self.report(
            'launching PwBaseWorkChain<{}> with fixed occupations, bands and total magnetization'
            .format(running.pk))

        return ToContext(workchains_scf=append_(running))
Exemple #12
0
    def run_relax(self):
        """
        Run the PwBaseWorkChain to run a relax PwCalculation
        """
        self.ctx.iteration += 1

        inputs = AttributeDict(
            self.exposed_inputs(PwBaseWorkChain, namespace='base'))
        inputs.structure = self.ctx.current_structure
        inputs.parameters = inputs.parameters.get_dict()

        inputs.parameters.setdefault('CONTROL', {})
        inputs.parameters['CONTROL'][
            'calculation'] = self.inputs.relaxation_scheme.value

        # Do not clean workdirs of sub workchains, because then we won't be able to restart from them
        inputs.pop('clean_workdir', None)

        inputs = prepare_process_inputs(PwBaseWorkChain, inputs)
        running = self.submit(PwBaseWorkChain, **inputs)

        self.report('launching PwBaseWorkChain<{}>'.format(running.pk))

        return ToContext(workchains=append_(running))
from aiida.orm.data.int import Int
from aiida.work.workchain import WorkChain, ToContext, append_

class SomeWorkChain(WorkChain):

    @classmethod
    def define(cls, spec):
        super(SomeWorkChain, cls).define(spec)
        spec.outline(
            cls.submit_workchains,
            cls.inspect_workchains,
        )

    def submit_workchains(self)
        for i in range(3):
            future = self.submit(SomeWorkChain)
            self.to_context(workchains=append_(future))

    def inspect_workchains(self)
        for workchain in self.ctx.workchains:
            assert workchain.is_finished_ok
Exemple #14
0
    def run(self):
        inputs = {'inp': self.inputs.inp}
        running = submit(SubWorkChain, **inputs)
        self.report('launching SubWorkChain<{}>'.format(running.pid))

        return ToContext(workchains=append_(running))