Beispiel #1
0
def get_wf_gibbs_robust(structure,
                        num_deformations=7,
                        deformation_fraction=(-0.1, 0.1),
                        phonon=False,
                        isif4=False,
                        phonon_supercell_matrix=None,
                        override_symmetry_tolerances=None,
                        t_min=5,
                        t_max=2000,
                        t_step=5,
                        eos_tolerance=0.01,
                        volume_spacing_min=0.03,
                        vasp_cmd=None,
                        db_file=None,
                        metadata=None,
                        name='EV_QHA',
                        override_default_vasp_params=None,
                        modify_incar_params={},
                        modify_kpoints_params={},
                        verbose=False,
                        level=1,
                        phonon_supercell_matrix_min=60,
                        phonon_supercell_matrix_max=120,
                        optimize_sc=False,
                        force_phonon=False,
                        stable_tor=0.01,
                        store_volumetric_data=False):
    """
    E - V
    curve

    workflow
    Parameters
    ------
    structure: pymatgen.Structure
        The initial structure
    num_deformations: int
        The number of deformation
    deformation_fraction: float
        Can be a float (a single value) or a 2-type of a min,max deformation fraction.
        Default is (-0.1, 0.1) leading to volumes of 0.90-1.10. A single value gives plus/minus by default.
    phonon : bool
        Whether to do a phonon calculation. Defaults to False, meaning the Debye model.
    phonon_supercell_matrix : list/str
        3x3 array of the supercell matrix, e.g. [[2,0,0],[0,2,0],[0,0,2]]. Must be specified if phonon is specified.
         if string, choose from 'atoms', 'lattice' or 'volume' (only the first letter works, case insensitive),
            which determine who to determin the matrix
    override_symmetry_tolerances : dict
        The symmetry tolerance. It contains three keys, default: {'tol_energy':0.025, 'tol_strain':0.05, 'tol_bond':0.1}
    t_min : float
        Minimum temperature
    t_step : float
        Temperature step size
    t_max : float
        Maximum temperature (inclusive)
    eos_tolerance: float
        Acceptable value for average RMS, recommend >= 0.005.
    volume_spacing_min: float
        Minimum ratio of Volumes spacing
    vasp_cmd : str
        Command to run VASP. If None (the default) is passed, the command will be looked up in the FWorker.
    db_file : str
        Points to the database JSON file. If None (the default) is passed, the path will be looked up in the FWorker.
    name : str
        Name of the workflow
    metadata : dict
        Metadata to include
    override_default_vasp_params: dict
        Override vasp parameters for all vasp jobs. e.g override_default_vasp_params={'user_incar_settings': {'ISIF': 4}}
    modify_incar_params : dict
        Override vasp settings in firework level
        User can use these params to modify the INCAR set. It is a dict of class ModifyIncar with keywords in Workflow name.
    modify_kpoints_params : dict
        User can use these params to modify the KPOINTS set. It is a dict of class ModifyKpoints with keywords in Workflow name.
        Only 'kpts' supported now.
    phonon_supercell_matrix_min/max: int
        minimum/maximum atoms/lattice/volume(controlled by scale_object, default is using atoms)
    optimize_sc: bool
        Optimize the super cell matrix (True) or not (False)
            If False, then use the closest integer transformation matrix of ideal matrix
    stable_tor: float
        The tolerance for phonon stability (the percentage of negative part frequency)
   """
    vasp_cmd = vasp_cmd or VASP_CMD
    db_file = db_file or DB_FILE

    override_symmetry_tolerances = override_symmetry_tolerances or {
        'tol_energy': 0.025,
        'tol_strain': 0.05,
        'tol_bond': 0.10
    }
    override_default_vasp_params = override_default_vasp_params or {}

    site_properties = deepcopy(structure).site_properties

    metadata = metadata or {}
    tag = metadata.get('tag', '{}'.format(str(uuid4())))
    metadata.update({'tag': tag})

    deformations = _get_deformations(deformation_fraction, num_deformations)
    vol_spacing = max(
        (deformations[-1] - deformations[0]) / (num_deformations - 1),
        volume_spacing_min)

    common_kwargs = {
        'vasp_cmd': vasp_cmd,
        'db_file': ">>db_file<<",
        "metadata": metadata,
        "tag": tag,
        'override_default_vasp_params': override_default_vasp_params
    }
    robust_opt_kwargs = {
        'isif': 7,
        'isif4': isif4,
        'level': level,
        'override_symmetry_tolerances': override_symmetry_tolerances
    }
    vasp_kwargs = {
        'modify_incar_params': modify_incar_params,
        'modify_kpoints_params': modify_kpoints_params
    }
    t_kwargs = {'t_min': t_min, 't_max': t_max, 't_step': t_step}
    eos_kwargs = {
        'deformations': deformations,
        'vol_spacing': vol_spacing,
        'eos_tolerance': eos_tolerance,
        'threshold': 14
    }

    fws = []

    robust_opt_fw = RobustOptimizeFW(
        structure,
        prev_calc_loc=False,
        name='Full relax',
        store_volumetric_data=store_volumetric_data,
        **robust_opt_kwargs,
        **vasp_kwargs,
        **common_kwargs)
    fws.append(robust_opt_fw)
    check_qha_parent = []

    if phonon:
        if isinstance(phonon_supercell_matrix, str):
            if phonon_supercell_matrix == 'Yphon':
                phonon_supercell_matrix = supercell_scaling_by_Yphon(
                    structure, supercellsize=phonon_supercell_matrix_max)
            else:
                phonon_supercell_matrix = supercell_scaling_by_atom_lat_vol(
                    structure,
                    min_obj=phonon_supercell_matrix_min,
                    max_obj=phonon_supercell_matrix_max,
                    scale_object=phonon_supercell_matrix,
                    target_shape='sc',
                    lower_search_limit=-2,
                    upper_search_limit=2,
                    verbose=verbose,
                    sc_tolerance=1e-5,
                    optimize_sc=optimize_sc)
        ph_scm_size = np.array(phonon_supercell_matrix).shape
        if not (ph_scm_size[0] == 3 and ph_scm_size[1] == 3):
            raise ValueError(
                'Current phonon_supercell_matrix({}) is not correct.'.format(
                    phonon_supercell_matrix))
        phonon_wf = PhononFW(structure,
                             phonon_supercell_matrix,
                             parents=robust_opt_fw,
                             prev_calc_loc='static',
                             name='structure_{:.3f}-phonon'.format(
                                 structure.volume),
                             stable_tor=stable_tor,
                             **t_kwargs,
                             **common_kwargs)
        fws.append(phonon_wf)
        check_qha_parent.append(phonon_wf)

    check_relax_fw = Firework(CheckRelaxScheme(db_file=">>db_file<<", tag=tag),
                              parents=robust_opt_fw,
                              name="{}-CheckRelaxScheme".format(
                                  structure.composition.reduced_formula))
    fws.append(check_relax_fw)
    check_qha_parent.append(check_relax_fw)
    check_qha_fw = Firework(
        EVcheck_QHA(site_properties=site_properties,
                    verbose=verbose,
                    stable_tor=stable_tor,
                    phonon=phonon,
                    phonon_supercell_matrix=phonon_supercell_matrix,
                    force_phonon=force_phonon,
                    override_symmetry_tolerances=override_symmetry_tolerances,
                    store_volumetric_data=store_volumetric_data,
                    **eos_kwargs,
                    **vasp_kwargs,
                    **t_kwargs,
                    **common_kwargs),
        parents=check_qha_parent,
        name='{}-EVcheck_QHA'.format(structure.composition.reduced_formula))
    fws.append(check_qha_fw)

    wfname = "{}:{}".format(structure.composition.reduced_formula, name)
    wf = Workflow(fws, name=wfname, metadata=metadata)
    add_modify_incar_by_FWname(wf, modify_incar_params=modify_incar_params)
    add_modify_kpoints_by_FWname(wf,
                                 modify_kpoints_params=modify_kpoints_params)

    return wf
Beispiel #2
0
    def run_task(self, fw_spec):
        ''' 
        run_num: maximum number of appending VASP running; this limitation is to avoid always running due to bad settings;
            only for internal usage;

        Important args:
        tolerance: acceptable value for average RMS, recommend >= 0.005;
        threshold: total point number above the value should be reduced, recommend < 16 or much time to run;
        del_limited: maximum deletion ration for large results;
        vol_spacing: the maximum ratio step between two volumes, larger step will be inserted points to calculate;
        '''
        max_run = 10
        deformations = self.get('deformations') or []
        db_file = self['db_file']
        tag = self['tag']
        vasp_cmd = self['vasp_cmd']
        metadata = self['metadata']
        relax_path = self['relax_path'] or ''
        run_num = self.get('run_num') or 0
        tolerance = self.get('tolerance') or 0.005
        threshold = self.get('threshold') or 14
        del_limited = self.get('del_limited') or 0.3
        vol_spacing = self.get('vol_spacing') or 0.03
        t_min = self.get('t_min') or 5 
        t_max = self.get('t_max') or 2000
        t_step = self.get('t_step') or 5
        phonon = self.get('phonon') or False
        phonon_supercell_matrix = self.get('phonon_supercell_matrix') or None
        verbose = self.get('verbose') or False
        modify_incar_params = self.get('modify_incar_params') or {}
        modify_kpoints_params = self.get('modify_kpoints_params') or {}
        Pos_Shape_relax = self.get('Pos_Shape_relax') or False
        symmetry_tolerance = self.get('symmetry_tolerance') or None
        run_num += 1
        
        relax_path, Pos_Shape_relax = check_relax_path(relax_path, db_file, tag, Pos_Shape_relax)
        if relax_path == '':
            print('''
#######################################################################
#                                                                     #
#       Cannot find relax path for static calculations, exit!         #
#               You can modify the tag and run again!                 #
#                                                                     #
#######################################################################
                ''')
            return
        
        from pymatgen.io.vasp.inputs import Poscar
        poscar = Poscar.from_file(relax_path + '/CONTCAR')
        structure = poscar.structure
        
        if phonon:
            if not consistent_check_db(db_file, tag):
                print('Please check DB, DFTTK running ended!')
                return

        volumes, energies, dos_objs = self.get_orig_EV(db_file, tag)
        vol_adds = self.check_deformations_in_volumes(deformations, volumes, structure.volume)
        if (len(vol_adds)) == 0:
            self.check_points(db_file, metadata, tolerance, threshold, del_limited, volumes, energies, verbose)
        else:
            self.correct = True
            self.error = 1e10
        
        EVcheck_result = {}
        EVcheck_result['append_run_num'] = run_num
        EVcheck_result['correct'] = self.correct
        EVcheck_result['volumes'] = volumes
        EVcheck_result['energies'] = energies
        EVcheck_result['tolerance'] = tolerance
        EVcheck_result['threshold'] = threshold
        EVcheck_result['vol_spacing'] = vol_spacing
        EVcheck_result['error'] = self.error
        EVcheck_result['metadata'] = metadata

        if self.correct:
            vol_orig = structure.volume
            if (len(vol_adds)) == 0:
                volume, energy, dos_obj = self.gen_volenergdos(self.points, volumes, energies, dos_objs)
                vol_adds = self.check_vol_coverage(volume, vol_spacing, vol_orig, run_num, 
                                                   energy, structure, dos_obj, phonon, 
                                                   db_file, tag, t_min, t_max, t_step,
                                                   EVcheck_result)   # Normalized to 1
                EVcheck_result['sellected'] = volume
                EVcheck_result['append'] = (vol_adds * vol_orig).tolist()
                # Marked as adopted in db
                mark_adopted(tag, db_file, volume)
            lpad = LaunchPad.auto_load()
            fws = []
            if len(vol_adds) > 0:      # VASP calculations need to append
                if run_num < max_run:
                    # Do VASP and check again
                    print('Appending the volumes of : %s to calculate in VASP!' %(vol_adds * vol_orig).tolist())
                    calcs = []
                    vis_relax = RelaxSet(structure)
                    vis_static = StaticSet(structure)
                    isif = 5 if 'infdet' in relax_path else 4
                    for vol_add in vol_adds:
                        if Pos_Shape_relax:
                            ps_relax_fw = OptimizeFW(structure, scale_lattice=vol_add, symmetry_tolerance=None, modify_incar = {'ISIF': isif},
                                                     job_type='normal', name='Pos_Shape_%.3f-relax' %(vol_add * vol_orig), prev_calc_loc=relax_path, 
                                                     vasp_input_set=vis_relax, vasp_cmd=vasp_cmd, db_file=db_file, metadata=metadata, Pos_Shape_relax = True,
                                                     modify_incar_params=modify_incar_params, modify_kpoints_params = modify_kpoints_params,
                                                     parents=None)
                            calcs.append(ps_relax_fw)
                            fws.append(ps_relax_fw)
                            static = StaticFW(structure, name = 'structure_%.3f-static' %(vol_add * vol_orig), vasp_input_set=vis_static, vasp_cmd=vasp_cmd, 
                                              db_file=db_file, metadata=metadata, prev_calc_loc=True, parents=ps_relax_fw)
                        else:
                            static = StaticFW(structure, scale_lattice=vol_add, name = 'structure_%.3f-static' %(vol_add * vol_orig), vasp_input_set=vis_static, vasp_cmd=vasp_cmd, 
                                              db_file=db_file, metadata=metadata, prev_calc_loc=relax_path, parents=None)
                        fws.append(static)
                        calcs.append(static)
                        if phonon:
                            visphonon = ForceConstantsSet(structure)
                            phonon_fw = PhononFW(structure, phonon_supercell_matrix, t_min=t_min, t_max=t_max, t_step=t_step,
                                     name='structure_%.3f-phonon' %(vol_add * vol_orig), vasp_input_set=visphonon,
                                     vasp_cmd=vasp_cmd, db_file=db_file, metadata=metadata,
                                     prev_calc_loc=True, parents=static)
                            fws.append(phonon_fw)
                            calcs.append(phonon_fw)
                    check_result = Firework(EVcheck_QHA(db_file = db_file, tag = tag, relax_path = relax_path, tolerance = tolerance, 
                                                        threshold = threshold, vol_spacing = vol_spacing, vasp_cmd = vasp_cmd, run_num = run_num,
                                                        metadata = metadata, t_min = t_min, t_max = t_max, t_step = t_step, phonon = phonon,
                                                        phonon_supercell_matrix = phonon_supercell_matrix, symmetry_tolerance = symmetry_tolerance,
                                                        modify_incar_params = modify_incar_params, verbose = verbose, Pos_Shape_relax = Pos_Shape_relax,
                                                        modify_kpoints_params = modify_kpoints_params), 
                                            parents = calcs, name='%s-EVcheck_QHA' %structure.composition.reduced_formula)
                    fws.append(check_result)
                    strname = "{}:{}".format(structure.composition.reduced_formula, 'EV_QHA_Append')
                    wfs = Workflow(fws, name = strname, metadata=metadata)
                    if modify_incar_params != {}:
                        from dfttk.utils import add_modify_incar_by_FWname
                        add_modify_incar_by_FWname(wfs, modify_incar_params = modify_incar_params)
                    if modify_kpoints_params != {}:
                        from dfttk.utils import add_modify_kpoints_by_FWname
                        add_modify_kpoints_by_FWname(wfs, modify_kpoints_params = modify_kpoints_params)
                    lpad.add_wf(wfs)
                else:
                    print('''

#######################################################################
#                                                                     #
#            Too many appended VASP running times, abort!             #
#                      Please check VASP setting!                     #
#                                                                     #
#######################################################################

                         ''')
            else:  # No need to do more VASP calculation, QHA could be running 
                print('Success in Volumes-Energies checking, enter QHA ...')
                # Debye
                debye_fw = Firework(QHAAnalysis(phonon=False, t_min=t_min, t_max=t_max, t_step=t_step, db_file=db_file, tag=tag, metadata=metadata), 
                                    name="{}-qha_analysis-Debye".format(structure.composition.reduced_formula))
                fws.append(debye_fw)
                if phonon:
                    phonon_supercell_matrix = self.get('phonon_supercell_matrix')
                    # do a Debye run before the phonon, so they can be done in stages.
                    phonon_fw = Firework(QHAAnalysis(phonon=True, t_min=t_min, t_max=t_max, t_step=t_step, db_file=db_file, tag=tag, 
                                                     metadata=metadata), parents=debye_fw, name="{}-qha_analysis-phonon".format(structure.composition.reduced_formula))
                    fws.append(phonon_fw)
                strname = "{}:{}".format(structure.composition.reduced_formula, 'QHA')
                wfs = Workflow(fws, name = strname, metadata=metadata)
                lpad.add_wf(wfs)
        else:   # failure to meet the tolerance
            if len(volumes) == 0: #self.error == 1e10:   # Bad initial running set
                print('''

#######################################################################
#                                                                     #
#  "passinitrun = True" could not set while initial results absent.   #
#                                                                     #
#######################################################################

                      
                      ''')
            else:                      # fitting fails
                print('''

#######################################################################
#                                                                     #
#           Can not achieve the tolerance requirement, abort!         #
#                                                                     #
#######################################################################

                      ''')
        import json
        with open('E-V check_summary.json', 'w') as fp:
            json.dump(EVcheck_result, fp)
Beispiel #3
0
    def run_task(self, fw_spec):
        '''
        run_num: maximum number of appending VASP running; this limitation is to avoid always running due to bad settings;
            only for internal usage;

        Important args:
        eos_tolerance: acceptable value for average RMS, recommend >= 0.005;
        threshold: total point number above the value should be reduced, recommend < 16 or much time to run;
        del_limited: maximum deletion ration for large results;
        vol_spacing: the maximum ratio step between two volumes, larger step will be inserted points to calculate;
        '''
        # Get the parameters from the object
        max_run = 10
        db_file = env_chk(self.get('db_file', DB_FILE),
                          fw_spec)  #always concrete db_fiel
        vasp_cmd = ">>vasp_cmd<<"  #chould change for user to provide the change
        deformations = self.get('deformations', [])
        run_num = self.get('run_num', 0)
        eos_tolerance = self.get('eos_tolerance', 0.005)
        threshold = self.get('threshold', 14)
        del_limited = self.get('del_limited', 0.3)
        vol_spacing = self.get('vol_spacing', 0.05)
        t_min = self.get('t_min', 5)
        t_max = self.get('t_max', 2000)
        t_step = self.get('t_step', 5)
        phonon = self.get('phonon', False)
        force_phonon = self.get('force_phonon', False)
        phonon_supercell_matrix = self.get('phonon_supercell_matrix', None)
        verbose = self.get('verbose', False)
        modify_kpoints_params = self.get('modify_kpoints_params', {})
        site_properties = self.get('site_properties', None)

        modify_incar_params = self.get('modify_incar_params', {})
        powerups_options = modify_incar_params.get('powerups', None)

        override_default_vasp_params = self.get('override_default_vasp_params',
                                                {})
        user_incar_settings = override_default_vasp_params.get(
            'user_incar_settings', {})
        powerups_options = user_incar_settings.get('powerups',
                                                   powerups_options)

        override_symmetry_tolerances = self.get('override_symmetry_tolerances',
                                                {})
        store_volumetric_data = self.get('store_volumetric_data', False)

        stable_tor = self.get('stable_tor', 0.01)
        force_phonon = self.get('force_phonon', False)
        test = self.get('test', False)

        relax_structure = self.get('structure') or fw_spec.get(
            'structure', None)
        relax_scheme = self.get('relax_scheme') or fw_spec.get(
            'relax_scheme', [2])
        relax_phonon = fw_spec.get('relax_phonon', False)

        #Only set phonon=True and ISIF=4 passed, then run phonon
        if not force_phonon:
            phonon = phonon and relax_phonon

        metadata = self.get('metadata', {})
        tag = self.get('tag', metadata.get('tag', None))
        if tag is None:
            tag = str(uuid4())
            metadata['tag'] = tag

        common_kwargs = {
            'vasp_cmd': vasp_cmd,
            'db_file': self.get('db_file', DB_FILE),
            "metadata": metadata,
            "tag": tag,
            'override_default_vasp_params': override_default_vasp_params,
        }
        vasp_kwargs = {
            'modify_incar_params': modify_incar_params,
            'modify_kpoints_params': modify_kpoints_params
        }
        t_kwargs = {'t_min': t_min, 't_max': t_max, 't_step': t_step}
        eos_kwargs = {
            'vol_spacing': vol_spacing,
            'eos_tolerance': eos_tolerance,
            'threshold': 14
        }

        run_num += 1

        #Some initial checks
        #TODO: add phonon after RobustOptimizeFW
        if phonon:
            #To check if the consistent of phonon and optimize
            if not consistent_check_db(db_file, tag):
                print('Please check DB, DFTTK running ended!')
                return

        if relax_structure is not None:
            structure = deepcopy(relax_structure)
        else:
            raise ValueError(
                'Not structure in spec, please provide structure as input')

        if site_properties:
            for pkey in site_properties:
                structure.add_site_property(pkey, site_properties[pkey])
        # get original EV curve
        volumes, energies, dos_objs = self.get_orig_EV(db_file, tag)
        vol_adds = check_deformations_in_volumes(deformations, volumes,
                                                 structure.volume)
        if (len(vol_adds)) == 0:
            self.check_points(db_file, metadata, eos_tolerance, threshold,
                              del_limited, volumes, energies, verbose)
        else:
            self.correct = True
            self.error = 1e10

        EVcheck_result = init_evcheck_result(append_run_num=run_num,
                                             correct=self.correct,
                                             volumes=volumes,
                                             energies=energies,
                                             eos_tolerance=eos_tolerance,
                                             threshold=threshold,
                                             vol_spacing=vol_spacing,
                                             error=self.error,
                                             metadata=metadata)

        if self.correct:
            vol_orig = structure.volume
            if (len(vol_adds)) == 0:
                volume, energy, dos_obj = gen_volenergdos(
                    self.points, volumes, energies, dos_objs)
                vol_adds = self.check_vol_coverage(
                    volume, vol_spacing, vol_orig, run_num, energy, structure,
                    dos_obj, phonon, db_file, tag, t_min, t_max, t_step,
                    EVcheck_result)  # Normalized to 1
                EVcheck_result['selected'] = volume
                EVcheck_result['append'] = (vol_adds).tolist()
                # Marked as adopted in db
                mark_adopted(tag, db_file, volume, phonon=phonon)
            lpad = LaunchPad.auto_load()
            fws = []
            if len(vol_adds) > 0:  # VASP calculations need to append
                if run_num < max_run:
                    # Do VASP and check again
                    print(
                        'Appending the volumes of : %s to calculate in VASP!' %
                        (vol_adds).tolist())
                    calcs = []
                    #vis_relax = RelaxSet(structure)
                    #vis_static = StaticSet(structure)
                    #isif2 = 5 if 'infdet' in relax_path else 4
                    for vol_add in vol_adds:
                        struct = deepcopy(structure)
                        struct.scale_lattice(structure.volume * vol_add)

                        relax_parents_fw = None
                        for isif_i in relax_scheme:
                            #record_path=record_path
                            relax_fw = OptimizeFW(
                                struct,
                                isif=isif_i,
                                store_volumetric_data=store_volumetric_data,
                                name="relax_Vol{:.3f}".format(vol_add),
                                vasp_input_set=None,
                                job_type="normal",
                                override_symmetry_tolerances=
                                override_symmetry_tolerances,
                                prev_calc_loc=True,
                                parents=relax_parents_fw,
                                db_insert=False,
                                force_gamma=True,
                                modify_incar={},
                                **vasp_kwargs,
                                **common_kwargs)
                            relax_parents_fw = deepcopy(relax_fw)
                            fws.append(relax_fw)
                            calcs.append(relax_fw)

                        static_fw = StaticFW(
                            struct,
                            isif=relax_scheme[-1],
                            name='static_Vol{:.3f}'.format(vol_add),
                            vasp_input_set=None,
                            prev_calc_loc=True,
                            parents=relax_parents_fw,
                            store_volumetric_data=store_volumetric_data,
                            **common_kwargs)
                        fws.append(static_fw)
                        calcs.append(static_fw)

                        if phonon:
                            #visphonon = ForceConstantsSet(struct)
                            phonon_fw = PhononFW(
                                struct,
                                phonon_supercell_matrix,
                                vasp_input_set=None,
                                stable_tor=stable_tor,
                                name='structure_{:.3f}-phonon'.format(vol_add),
                                prev_calc_loc=True,
                                parents=static_fw,
                                **t_kwargs,
                                **common_kwargs)
                            fws.append(phonon_fw)
                            calcs.append(phonon_fw)
                    check_result = Firework(
                        EVcheck_QHA(
                            structure=relax_structure,
                            relax_scheme=relax_scheme,
                            store_volumetric_data=store_volumetric_data,
                            run_num=run_num,
                            verbose=verbose,
                            site_properties=site_properties,
                            stable_tor=stable_tor,
                            phonon=phonon,
                            phonon_supercell_matrix=phonon_supercell_matrix,
                            force_phonon=force_phonon,
                            **eos_kwargs,
                            **vasp_kwargs,
                            **t_kwargs,
                            **common_kwargs),
                        parents=calcs,
                        name='{}-EVcheck_QHA'.format(
                            structure.composition.reduced_formula))
                    fws.append(check_result)
                    strname = "{}:{}".format(
                        structure.composition.reduced_formula, 'EV_QHA_Append')
                    wfs = Workflow(fws, name=strname, metadata=metadata)

                    if modify_incar_params != {}:
                        from dfttk.utils import add_modify_incar_by_FWname
                        add_modify_incar_by_FWname(
                            wfs, modify_incar_params=modify_incar_params)
                    if modify_kpoints_params != {}:
                        from dfttk.utils import add_modify_kpoints_by_FWname
                        add_modify_kpoints_by_FWname(
                            wfs, modify_kpoints_params=modify_kpoints_params)
                    wfs = Customizing_Workflows(
                        wfs, powerups_options=powerups_options)
                    if not test: lpad.add_wf(wfs)
                else:
                    too_many_run_error()
            else:  # No need to do more VASP calculation, QHA could be running
                print('Success in Volumes-Energies checking, enter QHA ...')
                debye_fw = Firework(QHAAnalysis(phonon=phonon,
                                                t_min=t_min,
                                                t_max=t_max,
                                                t_step=t_step,
                                                db_file=self.get(
                                                    'db_file', DB_FILE),
                                                tag=tag,
                                                metadata=metadata),
                                    name="{}-qha_analysis".format(
                                        structure.composition.reduced_formula))
                fws.append(debye_fw)
                '''
                # Debye
                debye_fw = Firework(QHAAnalysis(phonon=False, t_min=t_min, t_max=t_max, t_step=t_step, db_file=db_file, tag=tag, metadata=metadata),
                                    name="{}-qha_analysis-Debye".format(structure.composition.reduced_formula))
                fws.append(debye_fw)
                if phonon:
                    phonon_supercell_matrix = self.get('phonon_supercell_matrix')
                    # do a Debye run Staticore the phonon, so they can be done in stages.
                    phonon_fw = Firework(QHAAnalysis(phonon=True, t_min=t_min, t_max=t_max, t_step=t_step, db_file=db_file, tag=tag,
                                                     metadata=metadata), parents=debye_fw, name="{}-qha_analysis-phonon".format(structure.composition.reduced_formula))
                    fws.append(phonon_fw)
                '''
                strname = "{}:{}".format(structure.composition.reduced_formula,
                                         'QHA')
                wfs = Workflow(fws, name=strname, metadata=metadata)
                wfs = Customizing_Workflows(wfs,
                                            powerups_options=powerups_options)
                if not test: lpad.add_wf(wfs)
        else:  # failure to meet the tolerance
            if len(volumes
                   ) == 0:  #self.error == 1e10:   # Bad initial running set
                pass_result_error()
            else:  # fitting fails
                tol_error()
        import json
        with open('EV_check_summary.json', 'w') as fp:
            json.dump(EVcheck_result, fp, indent=4)
Beispiel #4
0
def get_wf_gibbs(structure, num_deformations=7, deformation_fraction=(-0.05, 0.1),
                 phonon=False, phonon_supercell_matrix=None,
                 t_min=5, t_max=2000, t_step=5,
                 vasp_cmd=None, db_file=None, metadata=None, name='EV_QHA'):
    """
    E - V
    curve

    workflow
    Parameters
    ------
    structure: pymatgen.Structure
    num_deformations: int
    deformation_fraction: float
        Can be a float (a single value) or a 2-type of a min,max deformation fraction.
        Default is (-0.05, 0.1) leading to volumes of 0.95-1.10. A single value gives plus/minus
        by default.
    phonon : bool
        Whether to do a phonon calculation. Defaults to False, meaning the Debye model.
    phonon_supercell_matrix : list
        3x3 array of the supercell matrix, e.g. [[2,0,0],[0,2,0],[0,0,2]]. Must be specified if phonon is specified.
    t_min : float
        Minimum temperature
    t_step : float
        Temperature step size
    t_max : float
        Maximum temperature (inclusive)
    vasp_cmd : str
        Command to run VASP. If None (the default) is passed, the command will be looked up in the FWorker.
    db_file : str
        Points to the database JSON file. If None (the default) is passed, the path will be looked up in the FWorker.
    name : str
        Name of the workflow
    metadata : dict
        Metadata to include
    """
    vasp_cmd = vasp_cmd or VASP_CMD
    db_file = db_file or DB_FILE

    metadata = metadata or {}
    tag = metadata.get('tag', '{}'.format(str(uuid4())))
    if 'tag' not in metadata.keys():
        metadata['tag'] = tag

    if isinstance(deformation_fraction, (list, tuple)):
        deformations = np.linspace(1+deformation_fraction[0], 1+deformation_fraction[1], num_deformations)
    else:
        deformations = np.linspace(1-deformation_fraction, 1+deformation_fraction, num_deformations)

    # follow a scheme of
    # 1. Full relax + symmetry check
    # 2. If symmetry check fails, detour to 1. Volume relax, 2. inflection detection
    # 3. Inflection detection
    # 4. Static EV
    # 5. Phonon EV
    fws = []
    static_calcs = []
    phonon_calcs = []
    # for each FW, we set the structure to the original structure to verify to ourselves that the
    # volume deformed structure is set by input set.

    # Full relax
    vis = RelaxSet(structure)
    full_relax_fw = OptimizeFW(structure, symmetry_tolerance=0.05, job_type='normal', name='Full relax', prev_calc_loc=False, vasp_input_set=vis, vasp_cmd=vasp_cmd, db_file=db_file, metadata=metadata, spec={'_preserve_fworker': True})
    fws.append(full_relax_fw)

    for i, deformation in enumerate(deformations):
        vis = StaticSet(structure)
        static = StaticFW(structure, scale_lattice=deformation, name='structure_{}-static'.format(i), vasp_input_set=vis, vasp_cmd=vasp_cmd, db_file=db_file, metadata=metadata, parents=full_relax_fw)
        fws.append(static)
        static_calcs.append(static)

        if phonon:
            vis = ForceConstantsSet(structure)
            phonon_fw = PhononFW(structure, phonon_supercell_matrix, t_min=t_min, t_max=t_max, t_step=t_step,
                     name='structure_{}-phonon'.format(i), vasp_input_set=vis,
                     vasp_cmd=vasp_cmd, db_file=db_file, metadata=metadata,
                     prev_calc_loc=True, parents=static)
            fws.append(phonon_fw)
            phonon_calcs.append(static)
            phonon_calcs.append(phonon_fw)

    # always do a Debye after the static calculations. That way we can set up a phonon calculation, do a Debye fitting, then do the phonon if we want.
    debye_fw = Firework(QHAAnalysis(phonon=False, t_min=t_min, t_max=t_max, t_step=t_step, db_file=db_file, tag=tag, metadata=metadata), parents=static_calcs, name="{}-qha_analysis-Debye".format(structure.composition.reduced_formula))
    fws.append(debye_fw)
    if phonon:
        # do a Debye run before the phonon, so they can be done in stages.
        phonon_fw = Firework(QHAAnalysis(phonon=True, t_min=t_min, t_max=t_max, t_step=t_step, db_file=db_file, tag=tag, metadata=metadata), parents=phonon_calcs, name="{}-qha_analysis-phonon".format(structure.composition.reduced_formula))
        fws.append(phonon_fw)

    wfname = "{}:{}".format(structure.composition.reduced_formula, name)

    return Workflow(fws, name=wfname, metadata=metadata)