Пример #1
0
            def s2(self):
                assert self.ctx.r1['_return'] == A
                assert self.ctx.r2['_return'] == B

                # Try overwriting r1
                return ToContext(r1=Outputs(async(b)))
Пример #2
0
    def run_eos(self):
        """
        Run the equation of states for all delta structures with their parameters
        """

        eos_results = {}
        inputs = self.get_inputs_eos()

        
        for struc, para in self.ctx.calcs_to_run[10:33]:#[10:33]
            print para
            formula = struc.get_formula()
            label = '|delta_wc|eos|{}'.format(formula)
            description = '|delta| fleur_eos_wc on {}'.format(formula)            
            if para:
                eos_future = submit(fleur_eos_wc,
                                wf_parameters=inputs['wc_eos_para'], structure=struc,
                                calc_parameters=para, inpgen=inputs['inpgen'], fleur=inputs['fleur'],
                                _label=label, _description=description)
                #fleur_eos_wc.run(#
            else: # TODO: run eos_wc_simple
                eos_future = submit(fleur_eos_wc,
                                wf_parameters=inputs['wc_eos_para'], structure=struc,
                                inpgen=inputs['inpgen'], fleur=inputs['fleur'],
                                _label=label, _description=description)
                #fleur_eos_wc.run(#a
            self.report('launching fleur_eos_wc<{}> on structure {} with parameter {}'
                        ''.format(eos_future.pid, struc.pk, para.pk))
            label = formula
            self.ctx.labels.append(label)
            eos_results[label] = eos_future

        return ToContext(**eos_results)

        '''
        #async to limit through put
        eos_results = {}
        inputs = self.get_inputs_eos()


        for struc, para in self.ctx.calcs_to_run[:4]:
            print para
            formula = struc.get_formula()
            label = '|delta_wc|eos|{}'.format(formula)
            description = '|delta| fleur_eos_wc on {}'.format(formula)
            if para:
                eos_future = asy(fleur_eos_wc,
                                wf_parameters=inputs['wc_eos_para'], structure=struc,
                                calc_parameters=para, inpgen=inputs['inpgen'], fleur=inputs['fleur'],
                                _label=label, _description=description)
                #fleur_eos_wc.run(#
            else:
                eos_future = asy(fleur_eos_wc,
                                wf_parameters=inputs['wc_eos_para'], structure=struc,
                                inpgen=inputs['inpgen'], fleur=inputs['fleur'],
                                _label=label, _description=description)
                #fleur_eos_wc.run(#a
            self.report('launching fleur_eos_wc<{}> on structure {} with parameter {}'
                        ''.format(eos_future.pid, struc.pk, para.pk))
            label = formula
            self.ctx.labels.append(label)
            eos_results[label] = eos_future

        return ToContext(**eos_results)
        '''
        '''
Пример #3
0
 def s1(self):
     return ToContext(r1=Outputs(async(a)), r2=Outputs(async(b)))
Пример #4
0
    def run_voronoi(self):
        """
        run voronoi calculation with parameters from input
        """
        # incerement iteration counter
        self.ctx.iter += 1

        # increase some parameters
        if self.ctx.iter > 1:
            # check if cluster size is actually the reason for failure
            if self.ctx.dos_check_fail_reason not in [
                    'EMIN too high', 'core state in contour',
                    'core state too close'
            ]:
                self.ctx.r_cls = self.ctx.r_cls * self.ctx.fac_clsincrease

        structure = self.inputs.structure
        self.ctx.formula = structure.get_formula()
        label = 'voronoi calculation step {}'.format(self.ctx.iter)
        description = '{} vornoi on {}'.format(self.ctx.description_wf,
                                               self.ctx.formula)

        voronoicode = self.inputs.voronoi

        # get valid KKR parameters
        if self.ctx.iter > 1:
            # take value from last run to continue
            params = self.ctx.last_params
            first_iter = False
        else:
            # used input or defaults in first iteration
            first_iter = True
            if 'calc_parameters' in self.inputs:
                params = self.inputs.calc_parameters
            else:
                kkrparams_default = kkrparams()
                para_version = self._kkr_default_params[1]
                for key, val in self._kkr_default_params[0].iteritems():
                    kkrparams_default.set_value(key, val, silent=True)
                # create ParameterData node
                params = ParameterData(dict=kkrparams_default.get_dict())
                params.label = 'Defaults for KKR parameter node'
                params.description = 'defaults as defined in kkrparams of version {}'.format(
                    para_version)
            #  set last_params accordingly (used below for provenance tracking)
            self.ctx.last_params = params

        # check if RCLUSTZ is set and use setting from wf_parameters instead (calls update_params_wf to keep track of provenance)
        updated_params = False
        update_list = []
        kkr_para = kkrparams()
        for key, val in params.get_dict().iteritems():
            kkr_para.set_value(key, val, silent=True)
        set_vals = kkr_para.get_set_values()
        set_vals = [keyvalpair[0] for keyvalpair in set_vals]
        if 'RCLUSTZ' in set_vals:
            rcls_input = params.get_dict()['RCLUSTZ']
            # set r_cls by default or from input in first iteration
            if self.ctx.r_cls < rcls_input and first_iter:
                self.ctx.r_cls = rcls_input
                updated_params = True
                update_list.append('RCLUSTZ')
            elif self.ctx.r_cls > rcls_input:
                # change rcls with iterations
                updated_params = True
                update_list.append('RCLUSTZ')
        else:
            updated_params = True
            update_list.append('RCLUSTZ')
        # in case of dos check verify that RMAX, GMAX are set and use setting from wf_parameters otherwise
        if 'RMAX' in set_vals:
            update_list.append('RMAX')
            rmax_input = params.get_dict()['RMAX']
        elif self.ctx.check_dos:  # add only if doscheck is done
            updated_params = True
            update_list.append('RMAX')
            rmax_input = kkrparams.get_KKRcalc_parameter_defaults()[0].get(
                'RMAX')
        if 'GMAX' in set_vals:
            update_list.append('GMAX')
            gmax_input = params.get_dict()['GMAX']
        elif self.ctx.check_dos:  # add only if doscheck is done
            updated_params = True
            update_list.append('GMAX')
            gmax_input = kkrparams.get_KKRcalc_parameter_defaults()[0].get(
                'GMAX')

        # check if emin should be changed:
        skip_voro = False
        if self.ctx.iter > 1:
            if (self.ctx.dos_check_fail_reason == 'EMIN too high' or
                    self.ctx.dos_check_fail_reason == 'core state too close'):
                # decrease emin  by self.ctx.delta_e
                emin_old = self.ctx.dos_params_dict['emin']
                eV2Ry = 1. / get_Ry2eV()
                emin_new = emin_old - self.ctx.delta_e * eV2Ry
                self.ctx.dos_params_dict['emin'] = emin_new
                updated_params = True
                update_list.append('EMIN')
                skip_voro = True

        # store updated nodes (also used via last_params in kkr_scf_wc)
        if updated_params:
            # set values that are updated
            if 'RCLUSTZ' in update_list:
                kkr_para.set_value('RCLUSTZ', self.ctx.r_cls)
                self.report("INFO: setting RCLUSTZ to {}".format(
                    self.ctx.r_cls))
            if 'EMIN' in update_list:
                kkr_para.set_value('EMIN', emin_new)
                self.report("INFO: setting EMIN to {}".format(emin_new))
            if 'RMAX' in update_list:
                kkr_para.set_value('RMAX', rmax_input)
                self.report(
                    "INFO: setting RMAX to {} (needed for DOS check with KKRcode)"
                    .format(rmax_input))
            if 'GMAX' in update_list:
                kkr_para.set_value('GMAX', gmax_input)
                self.report(
                    "INFO: setting GMAX to {} (needed for DOS check with KKRcode)"
                    .format(gmax_input))

            updatenode = ParameterData(dict=kkr_para.get_dict())
            updatenode.description = 'changed values: {}'.format(update_list)
            if first_iter:
                updatenode.label = 'initial params from wf input'
                # used workfunction for provenance tracking if parameters have been changed
                params = update_params_wf(self.ctx.last_params, updatenode)
                self.ctx.last_params = params
            else:
                updatenode.label = 'updated params: {}'.format(update_list)
                # also keep track of last voronoi output if that has been used
                voro_out = self.ctx.voro_calc.out.output_parameters
                params = update_voro_input(self.ctx.last_params, updatenode,
                                           voro_out)
                self.ctx.last_params = params

        # run voronoi step
        if not skip_voro:
            options = {
                "max_wallclock_seconds": self.ctx.walltime_sec,
                "resources": self.ctx.resources,
                "queue_name": self.ctx.queue
            }

            VoronoiProcess, inputs = get_inputs_voronoi(voronoicode,
                                                        structure,
                                                        options,
                                                        label,
                                                        description,
                                                        params=params)
            self.report('INFO: run voronoi step {}'.format(self.ctx.iter))
            future = submit(VoronoiProcess, **inputs)

            # return remote_voro (passed to dos calculation as input)
            return ToContext(voro_calc=future)
        else:
            self.report(
                "INFO: skipping voronoi calculation (do DOS run with different emin only)"
            )
Пример #5
0
 def run_calculation(self):
     """Run scf calculation."""
     # Create the calculation process and launch it
     running = submit(Cp2kDftBaseWorkChain, **self.ctx.inputs)
     self.report("pk: {} | Running cp2k CELL_OPT".format(running.pid))
     return ToContext(cp2k=Outputs(running))
Пример #6
0
 def start(self):
     return ToContext(res=Outputs(legacy_workflow(wf.pk)))
Пример #7
0
    def create_displacement_calculations(self):
        self.report('create displacements')

        if 'optimized' in self.ctx:
            self.ctx.final_structure = self.ctx.optimized.out.optimized_structure
            self.out('optimized_data',
                     self.ctx.optimized.out.optimized_structure_data)
        else:
            self.ctx.final_structure = self.inputs.structure

        self.ctx.primitive_structure = get_primitive(
            self.ctx.final_structure,
            self.inputs.ph_settings)['primitive_structure']

        supercells = create_supercells_with_displacements_using_phonopy(
            self.ctx.final_structure, self.inputs.ph_settings)

        self.ctx.data_sets = supercells.pop('data_sets')
        self.ctx.number_of_displacements = len(supercells)

        calcs = {}

        # Load data from nodes
        if __testing__:
            from aiida.orm import load_node
            nodes = [96661, 96664]  # VASP
            labels = ['structure_1', 'structure_0']
            for pk, label in zip(nodes, labels):
                future = load_node(pk)
                self.ctx._content[label] = future

            #self.ctx._content['single_point'] = load_node(96667)
            return

        # Forces
        for label, supercell in supercells.iteritems():

            JobCalculation, calculation_input = generate_inputs(
                supercell,
                # self.inputs.machine,
                self.inputs.es_settings,
                # pressure=self.input.pressure,
                type='forces')

            calculation_input._label = label
            future = submit(JobCalculation, **calculation_input)
            self.report('{} pk = {}'.format(label, future.pid))

            calcs[label] = future

        # Born charges
        if bool(self.inputs.use_nac):
            self.report('calculate born charges')
            JobCalculation, calculation_input = generate_inputs(
                self.ctx.primitive_structure,
                self.inputs.es_settings,
                # pressure=self.input.pressure,
                type='born_charges')
            future = submit(JobCalculation, **calculation_input)
            print('single_point: {}'.format(future.pid))
            calcs['single_point'] = future

        return ToContext(**calcs)
Пример #8
0
 def start(self):
     return ToContext(wf=legacy_workflow(wf.pk))
Пример #9
0
 def run(self):
     return ToContext(subwc=async (SubWorkChain))
Пример #10
0
    def run_fleur(self):
        """
        run a FLEUR calculation
        """

        self.change_fleurinp()
        fleurin = self.ctx.fleurinp
        '''
        if 'settings' in self.inputs:
            settings = self.input.settings
        else:
            settings = ParameterData(dict={'files_to_retrieve' : [],
                                           'files_not_to_retrieve': [],
                                           'files_copy_remotely': [],
                                           'files_not_copy_remotely': [],
                                           'commandline_options': ["-wtime", "{}".format(self.ctx.walltime_sec)],
                                           'blaha' : ['bla']})
        '''
        if self.ctx['last_calc']:
            # will this fail if fleur before failed? try needed?
            remote = self.ctx['last_calc'].out.remote_folder
        elif 'remote_data' in self.inputs:
            remote = self.inputs.remote_data
        else:
            remote = None

        label = ' '
        description = ' '
        if self.ctx.formula:
            label = 'scf: fleur run {}'.format(self.ctx.loop_count + 1)
            description = '{} fleur run {} on {}'.format(
                self.ctx.description_wf, self.ctx.loop_count + 1,
                self.ctx.formula)
        else:
            label = 'scf: fleur run {}'.format(self.ctx.loop_count + 1)
            description = '{} fleur run {}, fleurinp given'.format(
                self.ctx.description_wf, self.ctx.loop_count + 1)

        code = self.inputs.fleur
        options = {
            "max_wallclock_seconds": self.ctx.walltime_sec,
            "resources": self.ctx.resources,
            "queue_name": self.ctx.queue
        }  #,
        if self.ctx.custom_scheduler_commands:
            options[
                "custom_scheduler_commands"] = self.ctx.custom_scheduler_commands
        inputs = get_inputs_fleur(code,
                                  remote,
                                  fleurin,
                                  options,
                                  label,
                                  description,
                                  serial=self.ctx.serial)

        future = submit(FleurProcess, **inputs)
        self.ctx.loop_count = self.ctx.loop_count + 1
        self.report('INFO: run FLEUR number: {}'.format(self.ctx.loop_count))
        self.ctx.calcs.append(future)

        return ToContext(last_calc=future)
Пример #11
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))
Пример #12
0
from aiida.orm.data.int import Int
from aiida.work.workchain import WorkChain, ToContext

class SomeWorkChain(WorkChain):

    @classmethod
    def define(cls, spec):
        super(SomeWorkChain, cls).define(spec)
        spec.outline(
            cls.submit_workchain,
            cls.inspect_workchain,
        )

    def submit_workchain(self)
        future = self.submit(SomeWorkChain)
        return ToContext(workchain=future)

    def inspect_workchain(self)
        assert self.ctx.workchain.is_finished_ok