示例#1
0
    def print_report(self, *args):
        """
        Print the report of a workflow.
        """
        from aiida.backends.utils import load_dbenv, is_dbenv_loaded
        if not is_dbenv_loaded():
            load_dbenv()

        from aiida.orm.utils import load_workflow
        from aiida.common.exceptions import NotExistent

        if len(args) != 1:
            print >> sys.stderr, "You have to pass a valid workflow PK as a parameter."
            sys.exit(1)

        try:
            pk = int(args[0])
        except ValueError:
            print >> sys.stderr, "You have to pass a valid workflow PK as a parameter."
            sys.exit(1)

        try:
            w = load_workflow(pk)
        except NotExistent:
            print >> sys.stderr, "No workflow with PK={} found.".format(pk)
            sys.exit(1)

        print "### WORKFLOW pk: {} ###".format(pk)
        print "\n".join(w.get_report())
示例#2
0
    def on_legacy_workflow_finished(self, awaitable, pk):
        """
        Callback function called by the runner when the legacy workflow instance identified by pk
        is completed. The awaitable will be effectuated on the context of the workchain and
        removed from the internal list. If all awaitables have been dealt with, the workchain
        process is resumed

        :param awaitable: an Awaitable instance
        :param pk: the pk of the awaitable's target
        """
        try:
            workflow = load_workflow(pk=pk)
        except ValueError:
            raise ValueError(
                'provided pk<{}> could not be resolved to a valid Workflow instance'
                .format(pk))

        if awaitable.outputs:
            value = workflow.get_results()
        else:
            value = workflow

        if awaitable.action == AwaitableAction.ASSIGN:
            self.ctx[awaitable.key] = value
        elif awaitable.action == AwaitableAction.APPEND:
            self.ctx.setdefault(awaitable.key, []).append(value)
        else:
            assert "invalid awaitable action '{}'".format(awaitable.action)

        self.remove_awaitable(awaitable)
        if self.state == ProcessState.WAITING and not self._awaitables:
            self.resume()
示例#3
0
def prepare_input_optical_constants(workflow_pk):
    """
    workflow_pk: pk of ColourWorkflow
    """

    wf = load_workflow(workflow_pk)
    shirley_calc = wf.get_results()['shirley_calculation']
    drude_parameters = shirley_calc.out.output_parameters
    eps_im_inter = shirley_calc.out.array_eps_im
    eps_re_inter = shirley_calc.out.array_eps_re
    formula = wf.get_parameter('structure').get_formula()

    return drude_parameters, eps_im_inter, eps_re_inter, formula
示例#4
0
    def print_logshow(self, *args):
        from aiida.backends.utils import load_dbenv, is_dbenv_loaded
        if not is_dbenv_loaded():
            load_dbenv()

        from aiida.orm.utils import load_workflow
        from aiida.backends.utils import get_log_messages
        from aiida.common.exceptions import NotExistent

        for wf_pk in args:
            try:
                wf = load_workflow(int(wf_pk))
            except ValueError:
                print "*** {}: Not a valid PK".format(wf_pk)
                continue
            except NotExistent:
                print "*** {}: Not a valid Workflow".format(wf_pk)
                continue

            log_messages = get_log_messages(wf)
            label_string = " [{}]".format(wf.label) if wf.label else ""
            state = wf.get_state()
            print "*** {}{}: {}".format(wf_pk, label_string, state)

            if wf.get_report():
                print "Print the report with 'verdi workflow report {}'".format(
                    wf_pk)
            else:
                print "*** Report is empty"

            if log_messages:
                print "*** {} LOG MESSAGES:".format(len(log_messages))
            else:
                print "*** 0 LOG MESSAGES"

            for log in log_messages:
                print "+-> {} at {}".format(log['levelname'], log['time'])
                # Print the message, with a few spaces in front of each line
                print "\n".join(
                    ["|   {}".format(_) for _ in log['message'].splitlines()])
示例#5
0
    def run_nscf(self):    
        """
        Run non self-consistent DFT
        """  
        main_params = self.get_parameters()   

        try:
            main_params['nscf_calculation']
            has_nscf_calc = True
        except KeyError:
            has_nscf_calc = False
        try:
            main_params['simple_calculation']
            has_simple_calc = True
        except KeyError:
            has_simple_calc = False
        
        if not has_nscf_calc and not has_simple_calc:     
            list_of_wfs = [wf for wf in self.get_step(self.run_pw).get_sub_workflows()] \
                    + [load_workflow(pk) for pk in self.get_attribute('pw_wf_pks_already_computed')]
            if len(list_of_wfs)>1:
                raise Exception('Found more than one PwWorkflow for the previous self-consistent calculation') 
            if len(list_of_wfs)==0:
                raise Exception('Not found any previous PwWorkflow for the self-consistent calculation')
            pw_wf = list_of_wfs[0]
            pw_calc = pw_wf.get_result('pw_calculation')     
            
            nscf_wf_params = {}
            for k,v in main_params.iteritems():
                if k.startswith('nscf_'):
                    new_k = k[5:] # remove 'nscf_' from the key name
                    nscf_wf_params[new_k] = v
        
            nscf_wf_params['input']['relaxation_scheme'] = 'nscf'
            nscf_wf_params['pseudo_family'] = main_params['pseudo_family']
            nscf_wf_params['codename'] = main_params['pw_codename']
            nscf_wf_params['parameters']['CONTROL']['wf_collect'] = True     # write wfc to disk: necessary for simple.x
            nscf_wf_params['parameters']['ELECTRONS']['diago_full_acc'] = True 
            try:
                nscf_wf_params['structure'] = pw_wf.get_result('structure') 
            except ValueError:
                if main_params['pw_input']['relaxation_scheme'] == 'scf':
                    nscf_wf_params['structure'] = pw_calc.inp.structure 
                else:
                    raise Exception('Structure not found!')
            nscf_wf_params['remote_folder'] = pw_calc.out.remote_folder
            
            # k-points grid (uniform grid in the full 1BZ including the periodic images of Gamma)
            try:
                nscf_wf_params['settings'].update({'FORCE_KPOINTS_LIST':True, 'GAMMA_IMAGES':True})
            except KeyError:
                nscf_wf_params.update({'settings':{'FORCE_KPOINTS_LIST':True, 'GAMMA_IMAGES':True}})
            kpoints = KpointsData()
            kpoints.set_kpoints_mesh(main_params['parameters']['nscf_kpoints_mesh'])
            kpoints.store()
            nscf_wf_params['kpoints'] = kpoints
            
            nscf_wf_params['parameters']['SYSTEM']['nosym'] = True
            nscf_wf_params['parameters']['SYSTEM']['noinv'] = True
            
            try:      
                nscf_wf_params['parameters']['ELECTRONS']['conv_thr']
            except KeyError:
                number_of_atoms = pw_calc.res.number_of_atoms
                nscf_wf_params['parameters']['ELECTRONS']['conv_thr'] = self._default_conv_thr * number_of_atoms

            # If not specified in input_dict the default number of bands is put (arbitrarily we put at least 30 empty bands)    
            try:
                number_of_bands = nscf_wf_params['parameters']['SYSTEM']['nbnd']
            except KeyError:
                number_of_electrons = pw_calc.res.number_of_electrons
                number_of_bands = int(number_of_electrons/2) + max(30,int(0.3*number_of_electrons))
                nscf_wf_params['parameters']['SYSTEM']['nbnd'] = number_of_bands
        
            nscf_wf = PwrestartWorkflow(params=nscf_wf_params)
            self.attach_workflow(nscf_wf)
            nscf_wf.start()
            self.append_to_report("Launching PwWorkflow for 'nscf' calculation (pk: {})".format(nscf_wf.pk))
        elif has_nscf_calc and not has_simple_calc:
            self.append_to_report("Found previous nscf calculation (pk: {})".format(main_params['nscf_calculation'].pk))
        elif has_simple_calc:
            self.append_to_report("Found previous simple calculation: I will not do the nscf caclulation")    
        
                    
        self.next(self.run_simple)
示例#6
0
 def is_ready(self):
     wf = load_workflow(self._pk)
     if wf.has_finished_ok() or wf.has_failed():
         return True
     else:
         return False
示例#7
0
            o.write(str(energies[i]))
            o.write('  ' + str(eps_im_inter_avg[i]))
            o.write('  ' + str(eps_re_inter_avg[i]))
            o.write('\n')


if __name__ == "__main__":
    '''
    workflow_pk = pk of ColourWorkflow
    intra_broadening = empirical broadening for intraband contribution [eV]
    '''
    import sys, spglib
    workflow_pk = sys.argv[1]
    intra_broadening = sys.argv[2]
    (drude_parameters, eps_im_inter, eps_re_inter,
     formula) = prepare_input_optical_constants(int(workflow_pk))

    wf = load_workflow(int(workflow_pk))
    structure = wf.get_parameters()['structure']
    spacegroup_number = spglib.get_spacegroup(
        structure.get_ase()).split(' ')[1].split('(')[1].split(')')[0]

    os.mkdir('{}_pk{}_sg{}'.format(formula, workflow_pk, spacegroup_number))
    os.chdir('./{}_pk{}_sg{}'.format(formula, workflow_pk, spacegroup_number))

    parameters = ParameterData(
        dict={'intra_broadening': intra_broadening}
    )  # specify value of gamma (intraband broadening in Drude-like expression)
    optical_constants_2file(parameters, drude_parameters, eps_im_inter,
                            eps_re_inter, formula)