Esempio n. 1
0
    def atom_type_num_dict(self, path_i):
        """Return dictionary containing atomic count for each element.

        Args:
            path_i:
        """
        #| - atom_type_num_dict
        atoms = None
        atoms_file_names = ["out_opt.traj", "out.traj"]
        for file_name in atoms_file_names:
            try:
                print(path_i + "/" + file_name)
                atoms = io.read(path_i + "/" + file_name)
                break

            except:
                pass

        # print(atoms)
        # atoms = io.read(path_i + "/out.traj")

        # print("dft_methods")
        out_dict = create_species_element_dict(
            atoms,
            include_all_elems=False,
            elems_to_always_include=None,
        )

        print("dft_methods - atom_type_num_dict")
        print(out_dict)
        # out_dict = number_of_atoms(atoms)

        return ([out_dict])
Esempio n. 2
0
    def __calc_units_of_bulk_in_slab__(self):
        """
        """
        # | - __calc_units_of_bulk_in_slab__
        # TODO
        main_atom = "Ir"  # Make this a class attribute

        # 'main_atom' or 'gcm' (greatest common multiple)
        find_bulk_form_units_method = "main_atom"

        bulk_atoms = self.bulk_atoms
        atoms = self.atoms

        comp0 = Composition(bulk_atoms.get_chemical_formula())

        df = pd.DataFrame([
            create_species_element_dict(atoms,
                                        elems_to_always_include=["O", "H"]),
            dict(comp0.to_data_dict["reduced_cell_composition"])
        ],
                          index=["slab", "bulk"])

        # Replace NaNs with 0.
        df = df.replace(np.nan, 0.0, regex=True)

        # Removingg columns with 0
        df = df.loc[:, (df != 0).any(axis=0)]

        # slab_comp_array = np.array(list(df.loc["slab"]))
        # bulk_comp_array = np.array(list(df.loc["bulk"]))
        # df.loc["slab"].to_numpy()
        # df.loc["bulk"].to_numpy()

        # Number of unit of the bulk's reduced formula that fit into the slab
        if find_bulk_form_units_method == "main_atom":
            bulk_formula_units_in_slab = int(df.loc["slab"][main_atom] /
                                             df.loc["bulk"][main_atom])

        elif find_bulk_form_units_method == "gcm":
            bulk_formula_units_in_slab = int(
                min(df.loc["slab"].to_numpy() / df.loc["bulk"].to_numpy()))
        bfuis = bulk_formula_units_in_slab

        # #####################################################################
        # Getting the non-stoicheometric atoms composition
        df.loc["nonstoich"] = df.loc["slab"] - bfuis * df.loc["bulk"]
        non_stoich_comp = df.loc["nonstoich"].to_dict()
        self.non_stoich_comp = non_stoich_comp

        # print(bulk_formula_units_in_slab)
        # print(non_stoich_comp)

        return (bulk_formula_units_in_slab)
def calc_formation_energy(
    atoms,
    energy,
    reference_states,
    normalize_per_atom=True,
):
    """Calculate formation energy of structure on a per atom basis.

        reference states = [
            {
                "energy": ,
                "element_dict": {"H": 1, "Ir": 2},
                },
            {

                },
            ...
            ]

    Args:
        atoms:
        energy:
        reference_dict:
        normalize_per_atom:
    """
    # | - calc_formation_energy
    atoms.info["element_dict"] = create_species_element_dict(atoms)

    num_atoms = atoms.get_number_of_atoms()

    # ordered_elems = list(atoms.info["element_dict"])
    # ordered_elems.sort()

    # | - Finding List of Unique Elements Defined by reference_states list
    ref_state_elem_list = []
    for i in reference_states:
        ref_i_elems = list(i["element_dict"])
        ref_state_elem_list.extend(ref_i_elems)

    ordered_elems = list(set(ref_state_elem_list))
    ordered_elems.sort()
    # __|

    # | - Constructing the A matrix
    a_matrix = []
    for ref_state_i in reference_states:
        ref_i_comp_vect = []
        for elem_i in ordered_elems:
            if elem_i in list(ref_state_i["element_dict"]):
                elem_i_num = ref_state_i["element_dict"][elem_i]
                ref_i_comp_vect.append(elem_i_num)
            else:
                ref_i_comp_vect.append(0.)

        a_matrix.append(np.array(ref_i_comp_vect))
    a_matrix = np.array(a_matrix).transpose()
    # __|

    # | - Constructing the b vector
    # phi = 1.
    b_vect = []
    for elem_i in ordered_elems:
        if elem_i in list(atoms.info["element_dict"]):
            elem_i_num = atoms.info["element_dict"][elem_i]
            b_vect.append(elem_i_num)
        else:
            b_vect.append(0.)

    b_vect = np.array(b_vect)
    # __|

    # | - Solve linear system of equations
    x = np.linalg.solve(
        a_matrix,
        b_vect,
    )
    # __|

    # | - Calculate Formation Energy
    ref_e_sum = 0.
    for coeff_i, ref_i in zip(x, reference_states):
        ref_i_contribution = coeff_i * ref_i["elec_e"]
        ref_e_sum += ref_i_contribution

    form_e = energy - ref_e_sum

    if normalize_per_atom:
        form_e = form_e / num_atoms
    # __|

    return (form_e)
Esempio n. 4
0
    # #####################################################
    row_dft_i = df_dft.loc[bulk_id_i]
    # #####################################################
    bulk_energy_pa_i = row_dft_i.energy_pa
    # #####################################################

    # Calculate surface area of slab
    cell = atoms_init_i.cell

    cross_prod_i = np.cross(cell[0], cell[1])
    area_i = np.linalg.norm(cross_prod_i)

    elem_dict_i = create_species_element_dict(
        atoms_init_i,
        include_all_elems=False,
        elems_to_always_include=None,
    )

    stoich_B_i = int(stoich_i[2:])

    num_atoms_in_form_unit = stoich_B_i + 1

    num_metal_atoms = elem_dict_i[metal_atom_symbol]
    N_stoich_units = num_metal_atoms

    num_stoich_O = num_metal_atoms * stoich_B_i

    num_nonstoich_O = elem_dict_i["O"] - num_stoich_O

    assert num_nonstoich_O >= 0, "Must have non-negative number of non-stoich Os"
Esempio n. 5
0
from ase_modules.ase_methods import create_species_element_dict

from pymatgen.core.composition import Composition
#__|

# + jupyter={}
main_atom = "Ir"  # Make this a class attribute
find_bulk_form_units_method = "main_atom"  # 'gcm' (greatest common multiple)

bulk_atoms = self.bulk_atoms
atoms = self.atoms

comp0 = Composition(bulk_atoms.get_chemical_formula())

df = pd.DataFrame([
    create_species_element_dict(atoms, elems_to_always_include=["O", "H"]),
    dict(comp0.to_data_dict["reduced_cell_composition"])
],
                  index=["slab", "bulk"])

# Replace NaNs with 0.
df = df.replace(np.nan, 0.0, regex=True)

# Removingg columns with 0
df = df.loc[:, (df != 0).any(axis=0)]

# slab_comp_array = np.array(list(df.loc["slab"]))
# bulk_comp_array = np.array(list(df.loc["bulk"]))
# df.loc["slab"].to_numpy()
# df.loc["bulk"].to_numpy()