Пример #1
0
    def __init__(self, vasp_input_set, spec):
        # Initializes fws list and links_dict
        fws = []
        links_dict = {}

        if 'additional_controllers' in spec:
            additional_controllers = spec['additional_controllers']
            spec.pop('additional_controllers')
        else:
            additional_controllers = [
                WalltimeController(),
                MemoryController(),
                VaspXMLValidatorController()
            ]

        control_procedure = ControlProcedure(
            controllers=additional_controllers)
        task_helper = MPRelaxTaskHelper()
        task_type = task_helper.task_type
        src_fws = createVaspSRCFireworks(vasp_input_set=vasp_input_set,
                                         task_helper=task_helper,
                                         task_type=task_type,
                                         control_procedure=control_procedure,
                                         custodian_handlers=[],
                                         max_restarts=10,
                                         src_cleaning=None,
                                         task_index=None,
                                         spec=None,
                                         setup_spec_update=None,
                                         run_spec_update=None)

        fws.extend(src_fws['fws'])
        links_dict_update(links_dict=links_dict,
                          links_update=src_fws['links_dict'])

        self.wf = Workflow(fireworks=fws,
                           links_dict=links_dict,
                           metadata={
                               'workflow_class': self.workflow_class,
                               'workflow_module': self.workflow_module
                           },
                           name='MPRelaxFWWorkflowSRC')
Пример #2
0
    def __init__(self,
                 neb_vasp_input_set,
                 spec,
                 neb_terminals,
                 relax_terminals=True,
                 n_insert=1,
                 n_nebs=3,
                 relax_vasp_input_set=None,
                 initial_neb_structures=None,
                 climbing_image=True):
        user_incar_settings = {'NPAR': 4, 'ISIF': 0, 'SIGMA': 0.2, 'ISMEAR': 0}
        if n_nebs < 1:
            raise ValueError('Minimum one NEB ...')
        if relax_terminals and initial_neb_structures is not None:
            raise ValueError(
                'Cannot relax terminals and start from initial NEB structures')
        # Initializes fws list and links_dict
        fws = []
        links_dict = {}

        if 'additional_controllers' in spec:
            additional_controllers = spec['additional_controllers']
            spec.pop('additional_controllers')
        else:
            additional_controllers = [
                WalltimeController(),
                MemoryController(),
                VaspXMLValidatorController()
            ]

        # Control procedure
        control_procedure = ControlProcedure(
            controllers=additional_controllers)

        # First NEB
        gen_neb_spec = spec.copy()
        if relax_terminals:
            gen_neb_spec['terminal_start'] = None
            gen_neb_spec['terminal_end'] = None
        else:
            gen_neb_spec['terminal_start'] = neb_terminals[0]
            gen_neb_spec['terminal_end'] = neb_terminals[1]

        # gen_neb_spec['structures'] = neb_terminals
        gen_neb_spec = set_short_single_core_to_spec(gen_neb_spec)

        terminal_start_relax_task_type = 'MPRelaxVasp-start'
        terminal_end_relax_task_type = 'MPRelaxVasp-end'
        terminal_start_task_type = None
        terminal_end_task_type = None
        if relax_terminals:
            terminal_start_task_type = terminal_start_relax_task_type
            terminal_end_task_type = terminal_end_relax_task_type
        gen_neb_task = GenerateNEBRelaxationTask(
            n_insert=n_insert,
            user_incar_settings=user_incar_settings,
            climbing_image=climbing_image,
            task_index='neb1',
            terminal_start_task_type=terminal_start_task_type,
            terminal_end_task_type=terminal_end_task_type)
        gen_neb_fw = Firework([gen_neb_task],
                              spec=gen_neb_spec,
                              name='gen-neb1')
        fws.append(gen_neb_fw)

        if relax_terminals:
            # Start terminal
            relax_task_helper = MPRelaxTaskHelper()
            vis_start = relax_vasp_input_set(
                neb_terminals[0], user_incar_settings=user_incar_settings)
            start_src_fws = createVaspSRCFireworks(
                vasp_input_set=vis_start,
                task_helper=relax_task_helper,
                task_type=terminal_start_relax_task_type,
                control_procedure=control_procedure,
                custodian_handlers=[],
                max_restarts=10,
                src_cleaning=None,
                task_index=None,
                spec=None,
                setup_spec_update=None,
                run_spec_update=None)
            fws.extend(start_src_fws['fws'])
            links_dict_update(links_dict=links_dict,
                              links_update=start_src_fws['links_dict'])
            linkupdate = {start_src_fws['control_fw'].fw_id: gen_neb_fw.fw_id}
            links_dict_update(links_dict=links_dict, links_update=linkupdate)

            # End terminal

            vis_end = relax_vasp_input_set(
                neb_terminals[1], user_incar_settings=user_incar_settings)
            end_src_fws = createVaspSRCFireworks(
                vasp_input_set=vis_end,
                task_helper=relax_task_helper,
                task_type=terminal_end_relax_task_type,
                control_procedure=control_procedure,
                custodian_handlers=[],
                max_restarts=10,
                src_cleaning=None,
                task_index=None,
                spec=None,
                setup_spec_update=None,
                run_spec_update=None)
            fws.extend(end_src_fws['fws'])
            links_dict_update(links_dict=links_dict,
                              links_update=end_src_fws['links_dict'])
            linkupdate = {end_src_fws['control_fw'].fw_id: gen_neb_fw.fw_id}
            links_dict_update(links_dict=links_dict, links_update=linkupdate)

        if n_nebs > 1:
            for ineb in range(2, n_nebs + 1):
                prev_gen_neb_fw = gen_neb_fw
                gen_neb_spec = spec.copy()
                gen_neb_spec['structures'] = None
                gen_neb_spec = set_short_single_core_to_spec(gen_neb_spec)
                gen_neb_task = GenerateNEBRelaxationTask(
                    n_insert=n_insert,
                    user_incar_settings=user_incar_settings,
                    climbing_image=climbing_image,
                    task_index='neb{:d}'.format(ineb),
                    prev_neb_task_type='neb{:d}'.format(ineb - 1),
                    terminal_start_task_type=terminal_start_task_type,
                    terminal_end_task_type=terminal_end_task_type)
                gen_neb_fw = Firework([gen_neb_task],
                                      spec=gen_neb_spec,
                                      name='gen-neb{:d}'.format(ineb))
                fws.append(gen_neb_fw)
                linkupdate = {prev_gen_neb_fw.fw_id: gen_neb_fw.fw_id}
                links_dict_update(links_dict=links_dict,
                                  links_update=linkupdate)
                if relax_terminals:
                    linkupdate = {
                        start_src_fws['control_fw'].fw_id: gen_neb_fw.fw_id
                    }
                    links_dict_update(links_dict=links_dict,
                                      links_update=linkupdate)
                    linkupdate = {
                        end_src_fws['control_fw'].fw_id: gen_neb_fw.fw_id
                    }
                    links_dict_update(links_dict=links_dict,
                                      links_update=linkupdate)

        if climbing_image:
            wfname = "MPcNEBRelaxFWWorkflowSRC"
        else:
            wfname = "MPcNEBRelaxFWWorkflowSRC"
        self.wf = Workflow(fireworks=fws,
                           links_dict=links_dict,
                           metadata={
                               'workflow_class': self.workflow_class,
                               'workflow_module': self.workflow_module
                           },
                           name=wfname)
Пример #3
0
    def run_task(self, fw_spec):
        from magdesign.diffusion.neb_structures import neb_structures_insert_in_existing
        terminal_start_rundir = fw_spec['previous_fws'][
            self.terminal_start_task_type][0]['dir']
        terminal_end_rundir = fw_spec['previous_fws'][
            self.terminal_end_task_type][0]['dir']
        if 'structures' in fw_spec:
            if fw_spec['structures'] is not None:
                structs = neb_structures_insert_in_existing(
                    fw_spec['structures'], n_insert=self.n_insert)
            else:
                # Get the structures from the previous nebs ...
                if len(fw_spec['previous_fws'][self.prev_neb_task_type]) != 1:
                    raise RuntimeError(
                        'Multiple or no fws with task_type "{}"'.format(
                            self.prev_neb_task_type))
                prev_neb_rundir = fw_spec['previous_fws'][
                    self.prev_neb_task_type][0]['dir']
                prev_neb_analysis = NEBAnalysis.from_dir(
                    prev_neb_rundir,
                    relaxation_dirs=(terminal_start_rundir,
                                     terminal_end_rundir))
                structs = neb_structures_insert_in_existing(
                    prev_neb_analysis.structures, n_insert=self.n_insert)
        else:
            if fw_spec['terminal_start'] is not None:
                structs = neb_structures_insert_in_existing(
                    [fw_spec['terminal_start'], fw_spec['terminal_end']],
                    n_insert=self.n_insert)
            else:
                # Get the terminals from the relaxation of the terminals.
                if len(fw_spec['previous_fws'][
                        self.terminal_start_task_type]) != 1:
                    raise RuntimeError(
                        'Multiple or no fws with task_type "{}"'.format(
                            self.terminal_start_task_type))
                if len(fw_spec['previous_fws'][
                        self.terminal_end_task_type]) != 1:
                    raise RuntimeError(
                        'Multiple or no fws with task_type "{}"'.format(
                            self.terminal_end_task_type))
                terminal_start_rundir = fw_spec['previous_fws'][
                    self.terminal_start_task_type][0]['dir']
                terminal_end_rundir = fw_spec['previous_fws'][
                    self.terminal_end_task_type][0]['dir']
                terminal_start_vasprun = Vasprun(
                    os.path.join(terminal_start_rundir, 'vasprun.xml'))
                terminal_end_vasprun = Vasprun(
                    os.path.join(terminal_end_rundir, 'vasprun.xml'))
                terminal_start_structure = terminal_start_vasprun.final_structure
                terminal_end_structure = terminal_end_vasprun.final_structure
                structs = neb_structures_insert_in_existing(
                    [terminal_start_structure, terminal_end_structure],
                    n_insert=self.n_insert)
        if self.climbing_image:
            neb_vis = MPcNEBSet(structures=structs,
                                user_incar_settings=self.user_incar_settings)
            task_helper = MPcNEBTaskHelper()
        else:
            neb_vis = MPNEBSet(structures=structs,
                               user_incar_settings=self.user_incar_settings)
            task_helper = MPNEBTaskHelper()
        if 'additional_controllers' in fw_spec:
            additional_controllers = fw_spec['additional_controllers']
            fw_spec.pop('additional_controllers')
        else:
            additional_controllers = [
                WalltimeController(),
                MemoryController(),
                VaspNEBValidatorController()
            ]

        control_procedure = ControlProcedure(
            controllers=additional_controllers)

        if self.task_index is None:
            # Define the task_index as "MPNEBVaspN" where N is the number of structures in the NEB (e.g. 3 when two end
            #  points plus one structure are computed)
            if self.climbing_image:
                task_index = 'MPcNEBVasp{:d}'.format(len(structs))
            else:
                task_index = 'MPNEBVasp{:d}'.format(len(structs))
        else:
            task_index = self.task_index

        task_index = SRCTaskIndex.from_any(task_index)
        task_type = task_index.task_type

        src_fws = createVaspSRCFireworks(vasp_input_set=neb_vis,
                                         task_helper=task_helper,
                                         task_type=task_type,
                                         control_procedure=control_procedure,
                                         custodian_handlers=[],
                                         max_restarts=10,
                                         src_cleaning=None,
                                         task_index=task_index,
                                         spec={
                                             'additional_vasp_wf_info': {
                                                 'terminal_start_run_dir':
                                                 terminal_start_rundir,
                                                 'terminal_end_run_dir':
                                                 terminal_end_rundir
                                             }
                                         },
                                         setup_spec_update=None,
                                         run_spec_update=None)
        wf = Workflow(fireworks=src_fws['fws'],
                      links_dict=src_fws['links_dict'])
        return FWAction(detours=[wf])