Beispiel #1
0
def xyz_rdf(name):
    os.chdir(
        '/home/jinho93/oxides/cluster/zno/cp2k/1.aimd/3.16A/30/3.fix/2.again')
    mole = IMolecule.from_file('tail.xyz')
    #    mole = IMolecule.from_str(out, fmt='xyz')
    s = mole.get_boxed_structure(1.6027345000000000E+01,
                                 1.6671211000000000E+01,
                                 6.0678892000000005E+01)
    structures = [s]
    ind = []
    ref = []
    print(name)
    for i, sp in enumerate(s.sites):
        print(sp.z)
        up = .7
        down = .66
        if sp.species_string == name and up > sp.c > down:
            ind.append(i)
        elif sp.species_string == 'O' and up + 0.05 > sp.c > down - 0.05:
            ref.append(i)
    r = RadialDistributionFunction(structures,
                                   ind,
                                   reference_indices=ref,
                                   ngrid=301,
                                   sigma=.1)
    print(r.peak_r[0])
    r.get_rdf_plot(plt=plt, ylim=[-0.005, max(r.rdf)], label=f'{name}-ref')
    r.export_rdf('rdf.dat')
    plt.show()
Beispiel #2
0
def xdat_rdf_speices(name):
    import matplotlib.pyplot as plt
    from pymatgen_diffusion.aimd.van_hove import RadialDistributionFunction
    s = Xdatcar('XDATCAR').structures[-1:]
    ind = []
    ref = []
    for i, sp in enumerate(s[0].species):
        if sp.name == name:
            ind.append(i)
        elif sp.name == 'O':
            ref.append(i)
    r = RadialDistributionFunction(s, ind, reference_indices=ref, ngrid=501, sigma=.1)
    print(r.peak_r[0])
    r.get_rdf_plot(plt=plt, ylim=[-0.005, max(r.rdf)], label=f'{name}-ref')
    r.export_rdf('/home/jinho93/rdf.dat')
    plt.show()
def process_rdf(
    atoms=None,
    active_site_i=None,
    df_coord_slab_i=None,
    metal_atom_symbol=None,
    custom_name=None,
    TEST_MODE=False,
):
    """
    """
    #| - process_rdf
    if custom_name is None:
        custom_name = ""

    #| - Create out folders
    import os

    # directory = "out_data"
    directory = os.path.join(os.environ["PROJ_irox_oer"],
                             "workflow/enumerate_adsorption", "out_data")

    if not os.path.exists(directory):
        os.makedirs(directory)

    # assert False, "Fix os.makedirs"

    directory = "out_plot/rdf_figures"
    if not os.path.exists(directory):
        os.makedirs(directory)

    directory = "out_data/rdf_data"
    if not os.path.exists(directory):
        os.makedirs(directory)
    #__|

    AAA = AseAtomsAdaptor()
    slab_structure = AAA.get_structure(atoms)

    # Pickling data ###########################################
    out_dict = dict()
    out_dict["active_site_i"] = active_site_i
    out_dict["df_coord_slab_i"] = df_coord_slab_i
    out_dict["metal_atom_symbol"] = metal_atom_symbol

    import os
    import pickle
    path_i = os.path.join(os.environ["HOME"], "__temp__", "temp.pickle")
    with open(path_i, "wb") as fle:
        pickle.dump(out_dict, fle)
    # #########################################################

    neigh_dict = get_indices_of_neigh(active_oxy_ind=active_site_i,
                                      df_coord_slab_i=df_coord_slab_i,
                                      metal_atom_symbol=metal_atom_symbol)

    neighbor_oxy_indices = neigh_dict["neighbor_oxy_indices"]
    neighbor_metal_indices = neigh_dict["neighbor_metal_indices"]
    shell_2_metal_atoms = neigh_dict["shell_2_metal_atoms"]

    neighbor_indices = neighbor_oxy_indices + neighbor_metal_indices + shell_2_metal_atoms
    # neighbor_indices = neighbor_indices[0:1]
    # print("neighbor_indices:", neighbor_indices)

    #| - Get RDF
    RDF = RadialDistributionFunction(
        [
            slab_structure,
        ],
        [
            active_site_i,
        ],
        neighbor_indices,
        # ngrid=1801,
        ngrid=4801,
        rmax=8.0,
        cell_range=2,

        # sigma=0.2,
        # sigma=0.08,
        sigma=0.015,
        # sigma=0.008,
        # sigma=0.0005,
    )

    # data_file = "out_data/rdf_data/rdf_out.csv"

    data_file = os.path.join(
        "out_data/rdf_data",
        custom_name + "_" + str(active_site_i).zfill(4) + "_" + "rdf_out.csv")
    RDF.export_rdf(data_file)
    df_rdf = pd.read_csv(data_file)

    df_rdf = df_rdf.rename(columns={" g(r)": "g"})
    #__|

    #| - Plotting
    import plotly.graph_objs as go

    x_array = df_rdf.r
    # y_array = df_rdf[" g(r)"]
    y_array = df_rdf["g"]

    trace = go.Scatter(
        x=x_array,
        y=y_array,
    )
    data = [trace]

    fig = go.Figure(data=data)
    # fig.show()

    from plotting.my_plotly import my_plotly_plot

    if TEST_MODE:
        plot_dir = "__temp__"
    else:
        plot_dir = "rdf_figures"

    out_plot_file = os.path.join(
        plot_dir, custom_name + "_" + str(active_site_i).zfill(4) + "_rdf")
    my_plotly_plot(
        figure=fig,
        # plot_name=str(active_site_i).zfill(4) + "_rdf",
        plot_name=out_plot_file,
        write_html=True,
        write_png=False,
        png_scale=6.0,
        write_pdf=False,
        write_svg=False,
        try_orca_write=False,
    )
    #__|

    return (df_rdf)