コード例 #1
0
ファイル: __init__.py プロジェクト: woal777/materialDesign
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()
コード例 #2
0
    def test_rdf(self):
        # Parse the DiffusionAnalyzer object from json file directly
        obj = loadfn(os.path.join(tests_dir, "cNa3PS4_pda.json"))

        structure_list = []
        for i, s in enumerate(obj.get_drift_corrected_structures()):
            structure_list.append(s)
            if i == 9: break
        species = ["Na", "P", "S"]

        # Test from_species
        obj = RadialDistributionFunction.from_species(
            structures=structure_list, ngrid=101, rmax=10.0, cell_range=1,
            sigma=0.1, species=species, reference_species=species)

        check = np.shape(obj.rdf)[0] == 101 and np.argmax(obj.rdf) == 34
        self.assertTrue(check)
        self.assertAlmostEqual(obj.rdf.max(), 1.634448, 4)

        # Test init
        s = structure_list[0]
        indices = [i for (i, site) in enumerate(s) if
                   site.species_string in species]
        obj = RadialDistributionFunction(
            structures=structure_list, ngrid=101, rmax=10.0, cell_range=1,
            sigma=0.1, indices=indices, reference_indices=indices)

        check = np.shape(obj.rdf)[0] == 101 and np.argmax(obj.rdf) == 34
        self.assertTrue(check)
        self.assertAlmostEqual(obj.rdf.max(), 1.634448, 4)

        # Test init using structures w/ different lattices
        s0 = deepcopy(structure_list[0])
        sl_1 = [s0, s0, s0 * [1, 2, 1]]
        sl_2 = [s0 * [2, 1, 1], s0, s0]

        obj_1 = RadialDistributionFunction(
            structures=sl_1, ngrid=101, rmax=10.0, cell_range=1,
            sigma=0.1, indices=indices, reference_indices=indices)
        obj_2 = RadialDistributionFunction(
            structures=sl_2, ngrid=101, rmax=10.0, cell_range=1,
            sigma=0.1, indices=indices, reference_indices=indices)

        self.assertEqual(obj_1.rho, obj_2.rho)
        self.assertEqual(obj_1.rdf[0], obj_2.rdf[0])
コード例 #3
0
ファイル: __init__.py プロジェクト: woal777/materialDesign
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()
コード例 #4
0
    def test_rdf(self):
        data_file = os.path.join(tests_dir, "cNa3PS4_pda.json")
        data = json.load(open(data_file, "r"))
        obj = DiffusionAnalyzer.from_dict(data)

        structure_list = []
        for i, s in enumerate(obj.get_drift_corrected_structures()):
            structure_list.append(s)
            if i == 9: break

        obj = RadialDistributionFunction(structures=structure_list, ngrid=101, rmax=10.0,
                                         cellrange=1, sigma=0.1, species=["Na", "P", "S"])

        check = np.shape(obj.rdf)[0] == 101 and np.argmax(obj.rdf) == 34
        self.assertTrue(check)
        self.assertAlmostEqual(obj.rdf.max(), 1.6831, 4)
コード例 #5
0
 def test_rdf_coordination_number(self):
     # create a simple cubic lattice
     coords = np.array([[0.5, 0.5, 0.5]])
     atom_list = ['S']
     lattice = Lattice.from_parameters(a=1.0,
                                       b=1.0,
                                       c=1.0,
                                       alpha=90,
                                       beta=90,
                                       gamma=90)
     structure = Structure(lattice, atom_list, coords)
     rdf = RadialDistributionFunction(structures=[structure],
                                      species=['S'],
                                      rmax=5.0,
                                      sigma=0.1,
                                      ngrid=500)
     self.assertEqual(rdf.coordination_number[100], 6.0)
コード例 #6
0
    def test_rdf(self):
        data_file = os.path.join(tests_dir, "cNa3PS4_pda.json")
        with open(data_file, "r") as j:
            data = json.load(j)
        obj = DiffusionAnalyzer.from_dict(data)

        structure_list = []
        for i, s in enumerate(obj.get_drift_corrected_structures()):
            structure_list.append(s)
            if i == 9: break
        species = ["Na", "P", "S"]

        # Test from_species
        obj = RadialDistributionFunction.from_species(
            structures=structure_list,
            ngrid=101,
            rmax=10.0,
            cell_range=1,
            sigma=0.1,
            species=species,
            reference_species=species)

        check = np.shape(obj.rdf)[0] == 101 and np.argmax(obj.rdf) == 34
        self.assertTrue(check)
        self.assertAlmostEqual(obj.rdf.max(), 1.634448, 4)

        # Test init
        s = structure_list[0]
        indices = [
            i for (i, site) in enumerate(s) if site.species_string in species
        ]
        obj = RadialDistributionFunction(structures=structure_list,
                                         ngrid=101,
                                         rmax=10.0,
                                         cell_range=1,
                                         sigma=0.1,
                                         indices=indices,
                                         reference_indices=indices)

        check = np.shape(obj.rdf)[0] == 101 and np.argmax(obj.rdf) == 34
        self.assertTrue(check)
        self.assertAlmostEqual(obj.rdf.max(), 1.634448, 4)
コード例 #7
0
 def test_raises_ValueError_if_reference_species_not_in_structure(self):
     with self.assertRaises(ValueError):
         rdf = RadialDistributionFunction(structures=[self.structure],
                                          species=['S'],
                                          reference_species=['Cl'])
コード例 #8
0
 def test_raises_ValueError_if_sigma_is_not_positive(self):
     with self.assertRaises(ValueError):
         rdf = RadialDistributionFunction(structures=[self.structure],
                                          sigma=0)
コード例 #9
0
 def test_raises_valueerror_if_ngrid_is_less_than_2(self):
     with self.assertRaises(ValueError):
         rdf = RadialDistributionFunction(structures=[self.structure],
                                          ngrid=1)
コード例 #10
0
ファイル: rdf.py プロジェクト: woal777/materialDesign
import os
import numpy as np
from pymatgen.io.vasp import Xdatcar
from pymatgen_diffusion.aimd.van_hove import RadialDistributionFunction, plt
from pymatgen import Structure

if __name__ == '__main__':
    structure = Structure.from_file('POSCAR')
    num = 4
    fig = plt.figure(0)
    output = np.zeros((201, num))
    output[:, 0] = np.linspace(0.0, 10, 201)
    for c in range(num - 1):
        oxy = []
        for i, j in enumerate(structure.sites):
            if j.species_string == "O" and c / num < j.c < (c + 1) / num:
                oxy.append(i)
        zn = []
        for i, j in enumerate(structure.sites):
            if j.species_string == "Zn":
                zn.append(i)
        ax = fig.add_subplot(221 + c)
        rdf = RadialDistributionFunction([structure], oxy, zn, ngrid=201)
        rdf.get_rdf_plot(ylim=(0, max(rdf.rdf)))
        output[:, c + 1] = rdf.rdf
    np.savetxt('output.dat', output)
    plt.show()
コード例 #11
0
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)