def get_magmoms_from_job(path_i):
    """
    """
    #| -  get_magmoms_from_job
    incar_params = read_incar(path_i)
    if incar_params is not None:
        ispin_i = incar_params["ISPIN"]

        path_i = os.path.join(path_i, "OUTCAR")

        magmoms_i = None
        if ispin_i == 2:
            try:
                atoms = io.read(path_i)
                atoms_read_properly = True
            except:
                atoms_read_properly = False

            if atoms_read_properly:
                magmoms_i = atoms.get_magnetic_moments()
    else:
        magmoms_i = None

    return (magmoms_i)
Beispiel #2
0
    rev_num_im1 = rev_num_i - 1
    prev_rev_dir = "../_" + str(rev_num_im1).zfill(2)


    my_file = Path(prev_rev_dir)
    if my_file.is_dir():
        # directory exists

        prev_rev_files_list = os.listdir(prev_rev_dir)

        # Checking spin of previous calculation
        path_i = os.path.join(prev_rev_dir, "INCAR")
        my_file = Path(path_i)
        prev_ispin = 1
        if my_file.is_file():
            prev_incar_dict = read_incar(prev_rev_dir, verbose=False)
            prev_ispin = prev_incar_dict.get("ISPIN", None)

        if ispin == 2 and prev_ispin == 1:
            print("Job changed spin, so not copying WAVECAR")
        else:
            if "WAVECAR" in prev_rev_files_list:
                wavecar_dir = os.path.join(prev_rev_dir, "WAVECAR")
                from shutil import copyfile
                copyfile(wavecar_dir, "./WAVECAR")
#__|

#| - Writing pre-DFT objects to file
out_data = dict(
    atoms=atoms,
    dft_calc_settings=dft_calc_settings,
def analyze_oszicar(path):
    """
    """

    #| - analyze_oszicar
    def ediff_conv_reached(df_scf, ediff=None):
        """
        """
        #| - ediff_conv_reached

        row_last = df_scf.iloc[-1]
        # row_i = row_last

        dE_i = row_last.dE
        if np.abs(dE_i) < ediff:
            # print("Last dE is less than ediff")
            ediff_conv_reached = True
        else:
            # print("Last dE does not reach required ediff convergence")
            ediff_conv_reached = False

        return (ediff_conv_reached)
        #__|

    path_i = path

    out_dict = parse_oszicar(vasp_dir=path_i)

    if out_dict is not None:
        #| - __temp__
        ion_step_conv_dict = out_dict["ion_step_conv_dict"]
        num_N_dict = out_dict["num_N_dict"]
        N_tot = out_dict["N_tot"]
        if N_tot is not None:
            N_tot = int(N_tot)

        # #########################################################
        keys_list = list(ion_step_conv_dict.keys())
        num_scf_cycles = len(keys_list)

        # #########################################################
        # Read INCAR file
        incar_dict = read_incar(path_i)
        if incar_dict is None:
            ediff = 2E-5
        else:
            ediff = incar_dict["EDIFF"]

        # #########################################################
        # Checking last SCF cycle for convergence
        # df_scf_last = ion_step_conv_dict[keys_list[-1]]
        # ediff_conv_reached_last = ediff_conv_reached(df_scf_last, ediff=ediff)
        if len(ion_step_conv_dict) > 0:
            df_scf_last = ion_step_conv_dict[keys_list[-1]]
            ediff_conv_reached_last = ediff_conv_reached(df_scf_last,
                                                         ediff=ediff)
        else:
            ediff_conv_reached_last = None

        # #########################################################
        # Checking ediff convergence of all scf cycles
        ediff_conv_reached_dict = dict()
        for key, df_scf_i in ion_step_conv_dict.items():
            ediff_conv_reached_i = ediff_conv_reached(df_scf_i, ediff=ediff)
            ediff_conv_reached_dict[key] = ediff_conv_reached_i

        #| - Getting ratio of successful to unsuccessful scf runs
        # ediff_conv_reached_dict = ion_step_conv_dict
        # (list(ediff_conv_reached_dict.values()))

        true_list = [
            i for i in list(ediff_conv_reached_dict.values()) if i == True
        ]
        num_true = len(true_list)

        false_list = [
            i for i in list(ediff_conv_reached_dict.values()) if i == False
        ]
        num_false = len(false_list)

        if num_false == 0:
            true_false_ratio = 9999
        else:
            true_false_ratio = num_true / num_false

        # If both num_true and num_false are 0, then just return None
        if (num_true + num_false) > 0:
            frac_true = num_true / (num_true + num_false)
            frac_false = num_false / (num_true + num_false)
        else:
            frac_true = None
            frac_false = None
        #__|

        # #########################################################
        # Preparing out_dict
        out_dict = dict(
            ediff_conv_reached=ediff_conv_reached_last,
            ediff_conv_reached_dict=ediff_conv_reached_dict,
            num_scf_cycles=num_scf_cycles,
            N_tot=N_tot,
            true_false_ratio=true_false_ratio,
            frac_true=frac_true,
            frac_false=frac_false,
            num_nonconv_scf=num_false,
            num_conv_scf=num_true,
        )

        #__|
    else:

        # #########################################################
        # Preparing out_dict
        out_dict = dict(
            ediff_conv_reached=None,
            ediff_conv_reached_dict=None,
            num_scf_cycles=None,
            N_tot=None,
            true_false_ratio=None,
            num_nonconv_scf=None,
            num_conv_scf=None,
        )
    return (out_dict)
Beispiel #4
0
        if verbose:
            print("running job")

        # print("isjfdsi 000000 - - - - ")
        # #################################################
        job_err_out_i = parse_job_err(path_full_i, compenv=compenv_i)
        # print("isjfdsi 11")
        finished_i = parse_finished_file(path_full_i)
        job_state_i = parse_job_state(path_full_i)
        job_submitted_i = is_job_submitted(path_full_i)
        job_started_i = is_job_started(path_full_i)
        # print("isjfdsi 222")
        isif_i = get_isif_from_incar(path_full_i)
        num_steps = get_number_of_ionic_steps(path_full_i)
        oszicar_anal = analyze_oszicar(path_full_i)
        incar_params = read_incar(path_full_i, verbose=verbose)
        irr_kpts = get_irr_kpts_from_outcar(path_full_i)
        pickle_data = read_data_pickle(path_full_i)
        # print("isjfdsi 333")
        init_atoms = get_init_atoms(path_full_i)
        final_atoms = get_final_atoms(path_full_i)
        magmoms_i = get_magmoms_from_job(path_full_i)
        data_dict_out_i = read_dir_data_dict(path_full_i)

        forces_dict_out_i = get_forces_info(path_full_i)
        # #################################################

        # #################################################
        data_dict_i.update(job_err_out_i)
        data_dict_i.update(finished_i)
        data_dict_i.update(job_state_i)