def test_neworder_potential_wf(self):
     from numpy import loadtxt
     from aiida.orm import load_node
     from aiida.plugins import DataFactory
     from aiida_kkr.tools.common_workfunctions import neworder_potential_wf
     from aiida.tools.importexport import import_data
     Dict = DataFactory('dict')
     import_data('files/db_dump_kkrflex_create.tar.gz')
     GF_host_calc = load_node(
         'baabef05-f418-4475-bba5-ef0ee3fd5ca6').outputs
     neworder_pot1 = [
         int(i) for i in
         loadtxt(GF_host_calc.retrieved.open('scoef'), skiprows=1)[:, 3] - 1
     ]
     settings_dict = {
         'pot1': 'out_potential',
         'out_pot': 'potential_imp',
         'neworder': neworder_pot1
     }
     settings = Dict(dict=settings_dict)
     startpot_imp_sfd = neworder_potential_wf(
         settings_node=settings,
         parent_calc_folder=GF_host_calc.remote_folder)
     assert startpot_imp_sfd.get_object_content(
         startpot_imp_sfd.filename
     )[::
       1000] == u'C12807143D556463084.6+55 7D117 9D-87 0+25\n20.70351.75\n0521259.2+491.0-462. 02621D74112D03547T00 4D02116D502 6D39\n96.20261.50941.4944.7+30 98-29 .5-3625D07193.58104D0773D27252285417D341 9.506544D548447094.9+38 91063 54-08 6D28277.60909.98111'
Esempio n. 2
0
    def construct_startpot(self):
        """
        Take the output of GF writeout and the converged host potential as well as the
        auxiliary startpotentials for the impurity to construct the startpotential for the
        KKR impurity sub workflow
        """

        # collect all nodes necessary to construct the startpotential
        if self.ctx.do_gf_calc:
            GF_host_calc_pk = self.ctx.gf_writeout.outputs.workflow_info.get_dict().get('pk_flexcalc')
            self.report('GF_host_calc_pk: {}'.format(GF_host_calc_pk))
            GF_host_calc = load_node(GF_host_calc_pk)
            converged_host_remote = self.inputs.remote_data_host
        else:
            remote_data_gf_node = load_node(self.inputs.remote_data_gf.pk)
            GF_host_calc = remote_data_gf_node.get_incoming(link_label_filter=u'remote_folder').first().node
            self.report('GF_host_calc_pk: {}'.format(GF_host_calc.pk))
            # follow parent_folder link up to get remote folder
            converged_host_remote = GF_host_calc.get_incoming(link_label_filter='parent_folder').first().node
        voro_calc_remote = self.ctx.last_voro_calc.outputs.last_voronoi_remote
        imp_info = self.inputs.impurity_info
        nspin = GF_host_calc.outputs.output_parameters.get_dict().get('nspin')

        ilayer_cent = imp_info.get_dict().get('ilayer_center')

        # prepare settings dict
        potname_converged = 'out_potential'
        potname_impvorostart = 'output.pot'
        potname_imp = 'potential_imp'

        if nspin < 2:
            replacelist_pot2 = [[0,ilayer_cent]]
        else:
            replacelist_pot2 = [[0,2*ilayer_cent],[1,2*ilayer_cent+1]]
        try:
            neworder_pot1 = [int(i) for i in np.loadtxt(GF_host_calc.outputs.retrieved.open('scoef'), skiprows=1)[:,3]-1]
        except:
            neworder_pot1 = [int(np.loadtxt(GF_host_calc.outputs.retrieved.open('scoef'), skiprows=1)[3]-1)]

        settings_label = 'startpot_KKRimp for imp_info node {}'.format(imp_info.pk)
        settings_description = 'starting potential for impurity info: {}'.format(imp_info)
        settings = Dict(dict={'pot1': potname_converged,  'out_pot': potname_imp, 'neworder': neworder_pot1,
                              'pot2': potname_impvorostart, 'replace_newpos': replacelist_pot2, 'label': settings_label,
                              'description': settings_description})
        startpot_kkrimp = neworder_potential_wf(settings_node=settings, parent_calc_folder=converged_host_remote,
                                                parent_calc_folder2=voro_calc_remote)

        # add starting potential for kkrimp calculation to context
        self.ctx.startpot_kkrimp = startpot_kkrimp
        # add to list for final cleanup
        self.ctx.sfd_final_cleanup.append(startpot_kkrimp)

        self.report('INFO: created startpotential (pid: {}) for the impurity calculation '
                    'by using information of the GF host calculation (pid: {}), the potential of the '
                    'converged host system (remote pid: {}) and the potential of the auxiliary voronoi '
                    'calculation (remote pid: {})'.format(startpot_kkrimp.pk, GF_host_calc.pk, converged_host_remote.pk, self.ctx.last_voro_calc.pk))
Esempio n. 3
0
    def test_host_in_host(self):
        """
        simple Cu noSOC, FP, lmax2
        """
        from aiida.orm import Code, load_node
        from aiida.plugins import DataFactory
        from masci_tools.io.kkr_params import kkrparams
        from aiida_kkr.calculations.kkrimp import KkrimpCalculation
        Dict = DataFactory('dict')

        # first load parent voronoi calculation
        from aiida.tools.importexport import import_data
        import_data('files/db_dump_kkrflex_create.tar.gz')
        GF_host_calc = load_node('baabef05-f418-4475-bba5-ef0ee3fd5ca6')

        # prepare computer and code (needed so that
        prepare_code(kkrimp_codename, codelocation, computername, workdir)

        # now create a SingleFileData node containing the impurity starting potential
        from aiida_kkr.tools.common_workfunctions import neworder_potential_wf
        from numpy import loadtxt
        neworder_pot1 = [int(i) for i in loadtxt(GF_host_calc.outputs.retrieved.open('scoef'), skiprows=1)[:,3]-1]
        settings_dict = {'pot1': 'out_potential',  'out_pot': 'potential_imp', 'neworder': neworder_pot1}
        settings = Dict(dict=settings_dict)
        startpot_imp_sfd = neworder_potential_wf(settings_node=settings, parent_calc_folder=GF_host_calc.outputs.remote_folder)

        # set 1 simple mixing step
        kkrimp_params = kkrparams(params_type='kkrimp')
        kkrimp_params.set_multiple_values(SCFSTEPS=1, IMIX=0, MIXFAC=0.05)
        ParamsKKRimp = Dict(dict=kkrimp_params.get_dict())

        # create new KKRimp calculation
        #kkrimp_code = Code.get_from_string(codename)
        kkrimp_code = Code.get_from_string(kkrimp_codename+'@'+computername)
        options = {'resources': {'num_machines':1, 'tot_num_mpiprocs':1}, 'queue_name': queuename}
        builder = KkrimpCalculation.get_builder()
        builder.code = kkrimp_code
        builder.host_Greenfunction_folder = GF_host_calc.outputs.remote_folder
        builder.impurity_potential = startpot_imp_sfd
        builder.metadata.options = options
        builder.parameters = ParamsKKRimp
        builder.metadata.dry_run = True
        from aiida.engine import run
        run(builder)
potname_impvorostart = voro_calc_aux._OUT_POTENTIAL_voronoi
replacelist_pot2 = [[0, 0]]

settings_dict = {
    'pot1': potname_converged,
    'out_pot': potname_imp,
    'neworder': neworder_pot1,
    'pot2': potname_impvorostart,
    'replace_newpos': replacelist_pot2,
    'label': 'startpot_KKRimp',
    'description': 'starting potential for Au impurity in bulk Cu'
}
settings = ParameterData(dict=settings_dict)

startpot_Au_imp_sfd = neworder_potential_wf(
    settings_node=settings,
    parent_calc_folder=kkrcalc_converged.out.remote_folder,
    parent_calc_folder2=voro_calc_aux.out.remote_folder)

# now create KKRimp calculation and run first (some simple mixing steps) calculation

# needed to link to host GF writeout calculation
GF_host_output_folder = GF_host_calc.out.remote_folder

# create new KKRimp calculation
from aiida_kkr.calculations.kkrimp import KkrimpCalculation
kkrimp_calc = KkrimpCalculation()

### !!! use your code name !!! ###
kkrimp_code = Code.get_from_string('KKRimp@my_mac')

kkrimp_calc.use_code(kkrimp_code)
    def test_kkrimp_sub_wc(self):
        """
        simple Cu noSOC, FP, lmax2 full example using scf workflow for impurity host-in-host
        """
        from aiida.orm import Code, load_node
        from aiida.plugins import DataFactory
        from aiida.orm.querybuilder import QueryBuilder
        from masci_tools.io.kkr_params import kkrparams
        from aiida_kkr.workflows.kkr_imp_sub import kkr_imp_sub_wc
        from numpy import array

        Dict = DataFactory('dict')
        StructureData = DataFactory('structure')

        # prepare computer and code (needed so that
        prepare_code(kkrimp_codename, codelocation, computername, workdir)

        wfd = kkr_imp_sub_wc.get_wf_defaults()

        wfd['nsteps'] = 20
        wfd['strmix'] = 0.05

        options = {
            'queue_name': queuename,
            'resources': {
                "num_machines": 1
            },
            'max_wallclock_seconds': 5 * 60,
            'use_mpi': False,
            'custom_scheduler_commands': ''
        }
        options = Dict(dict=options)

        # The scf-workflow needs also the voronoi and KKR codes to be able to run the calulations
        KKRimpCode = Code.get_from_string(kkrimp_codename + '@' + computername)

        # import previous GF writeout
        from aiida.tools.importexport import import_data
        import_data('files/db_dump_kkrflex_create.tar.gz')
        GF_host_calc = load_node('baabef05-f418-4475-bba5-ef0ee3fd5ca6')

        # now create a SingleFileData node containing the impurity starting potential
        from aiida_kkr.tools.common_workfunctions import neworder_potential_wf
        from numpy import loadtxt
        neworder_pot1 = [
            int(i)
            for i in loadtxt(GF_host_calc.outputs.retrieved.open('scoef'),
                             skiprows=1)[:, 3] - 1
        ]
        settings_dict = {
            'pot1': 'out_potential',
            'out_pot': 'potential_imp',
            'neworder': neworder_pot1
        }
        settings = Dict(dict=settings_dict)
        startpot_imp_sfd = neworder_potential_wf(
            settings_node=settings,
            parent_calc_folder=GF_host_calc.outputs.remote_folder)

        label = 'kkrimp_scf Cu host_in_host'
        descr = 'kkrimp_scf workflow for Cu bulk'

        # create process builder to set parameters
        builder = kkr_imp_sub_wc.get_builder()
        builder.metadata.description = descr
        builder.metadata.label = label
        builder.kkrimp = KKRimpCode
        builder.options = options
        builder.remote_data = GF_host_calc.outputs.remote_folder
        builder.wf_parameters = Dict(dict=wfd)
        builder.host_imp_startpot = startpot_imp_sfd

        # now run calculation
        from aiida.engine import run
        print(builder)
        out = run(builder)

        n = out['workflow_info']
        n = n.get_dict()

        assert n.get('successful')
        assert n.get('convergence_reached')