Example #1
0
def plot_dos(phonons,
             bandwidth=.05,
             n_points=200,
             is_showing=True,
             input_fig=None):
    if input_fig is None:
        fig = plt.figure()
    else:
        fig = input_fig
    kde = KernelDensity(kernel='gaussian', bandwidth=bandwidth).fit(
        phonons.frequency.flatten(order='C').reshape(-1, 1))
    x = np.linspace(phonons.frequency.min(), phonons.frequency.max(), n_points)
    y = np.exp(kde.score_samples(x.reshape((-1, 1))))
    plt.plot(x, y)
    plt.fill_between(x, y, alpha=.2)
    plt.xlabel("$\\nu$ (THz)", fontsize=16)
    plt.ylabel('DOS', fontsize=16)
    plt.tick_params(axis='both', which='major', labelsize=16)
    plt.tick_params(axis='both', which='minor', labelsize=16)
    folder = get_folder_from_label(phonons, base_folder=DEFAULT_FOLDER)
    if not os.path.exists(folder):
        os.makedirs(folder)
    fig.savefig(folder + '/' + 'dos.png')
    if is_showing:
        plt.show()
    elif input_fig is None:
        plt.close()
    else:
        return fig
Example #2
0
def plot_vs_frequency(phonons, observable, observable_name, is_showing=True):
    frequency = phonons.frequency.flatten()
    observable = observable.flatten()
    fig = plt.figure()
    plt.scatter(frequency[3:], observable[3:], s=5)
    observable[np.isnan(observable)] = 0
    plt.ylabel(observable_name, fontsize=16)
    plt.xlabel("$\\nu$ (THz)", fontsize=16)
    plt.ylim(observable.min(), observable.max())
    plt.tick_params(axis='both', which='major', labelsize=16)
    plt.tick_params(axis='both', which='minor', labelsize=16)
    folder = get_folder_from_label(phonons, base_folder=DEFAULT_FOLDER)
    if not os.path.exists(folder):
        os.makedirs(folder)
    fig.savefig(folder + '/' + observable_name + '.png')
    if is_showing:
        plt.show()
    else:
        plt.close()
# Visualize phonon dispersion, group velocity and density of states with
# the build-in plotter.

# 'with_velocity': specify whether to plot both group velocity and dispersion relation
# 'is_showing':specify if figure window pops up during simulation
plotter.plot_dispersion(phonons, with_velocity=True, is_showing=False)
plotter.plot_dos(phonons, is_showing=False)

# Visualize heat capacity vs frequency and
# 'order': Index order to reshape array,
# 'order'='C' for C-like index order; 'F' for Fortran-like index order

# Define the base folder to contain plots
# 'base_folder':name of the base folder
folder = get_folder_from_label(phonons, base_folder='plots')
if not os.path.exists(folder):
    os.makedirs(folder)
# Define a boolean flag to specify if figure window pops during sumuatlion
is_show_fig = False

frequency = phonons.frequency.flatten(order='C')
heat_capacity = phonons.heat_capacity.flatten(order='C')
plt.figure()
plt.scatter(frequency[3:], 1e23 * heat_capacity[3:], s=5)
plt.xlabel("$\\nu$ (THz)", fontsize=16)
plt.ylabel("$C_{v} \ (10^{23} \ J/K)$", fontsize=16)
plt.savefig(folder + '/cv_vs_freq.png', dpi=300)
if not is_show_fig:
    plt.close()
else:
Example #4
0
def plot_dispersion(phonons,
                    n_k_points=300,
                    is_showing=True,
                    symprec=1e-3,
                    is_nw=None,
                    with_velocity=True,
                    color='b',
                    is_unfolding=False):
    atoms = phonons.atoms
    if is_nw is None and phonons.is_nw:
        is_nw = phonons.is_nw
    if is_nw:
        q = np.linspace(0, 0.5, n_k_points)
        k_list = np.zeros((n_k_points, 3))
        k_list[:, 0] = q
        k_list[:, 2] = q
        Q = [0, 0.5]
        point_names = ['$\\Gamma$', 'X']
    else:
        try:
            k_list, Q, point_names = create_k_and_symmetry_space(
                atoms, n_k_points=n_k_points, symprec=symprec)
            q = np.linspace(0, 1, k_list.shape[0])
        except seekpath.hpkot.SymmetryDetectionError as err:
            print(err)
            q = np.linspace(0, 0.5, n_k_points)
            k_list = np.zeros((n_k_points, 3))
            k_list[:, 0] = q
            k_list[:, 2] = q
            Q = [0, 0.5]
            point_names = ['$\\Gamma$', 'X']
    freqs_plot = []
    vel_plot = []
    vel_norm = []
    for q_point in k_list:
        phonon = HarmonicWithQ(
            q_point,
            phonons.forceconstants.second,
            distance_threshold=phonons.forceconstants.distance_threshold,
            storage='memory',
            is_unfolding=is_unfolding)
        freqs_plot.append(phonon.frequency.flatten())
        if with_velocity:
            val_value = phonon.velocity[0]
            vel_plot.append(val_value)
            vel_norm.append(np.linalg.norm(val_value, axis=-1))
    freqs_plot = np.array(freqs_plot)
    if with_velocity:
        vel_plot = np.array(vel_plot)
        vel_norm = np.array(vel_norm)
    fig1, ax1 = plt.subplots()
    plt.tick_params(axis='both', which='minor', labelsize=16)
    plt.ylabel("$\\nu$ (THz)", fontsize=16)
    plt.xlabel('$q$', fontsize=16)
    plt.tick_params(axis='both', which='major', labelsize=16)
    plt.xticks(Q, point_names)
    plt.xlim(q[0], q[-1])
    if color is not None:
        plt.plot(q, freqs_plot, '.', color=color, linewidth=4, markersize=4)
    else:
        plt.plot(q, freqs_plot, '.', linewidth=4, markersize=4)
    plt.grid()
    plt.ylim(freqs_plot.min(), freqs_plot.max() * 1.05)
    folder = get_folder_from_label(phonons, base_folder=DEFAULT_FOLDER)
    if not os.path.exists(folder):
        os.makedirs(folder)
    plt.subplots_adjust(left=0.1, right=0.9, top=0.9, bottom=0.1)
    fig1.savefig(folder + '/' + 'dispersion' + '.png')
    np.savetxt(folder + '/' + 'q', q)
    np.savetxt(folder + '/' + 'dispersion', freqs_plot)
    if is_showing:
        plt.show()
    else:
        plt.close()
    if with_velocity:
        for alpha in range(3):
            np.savetxt(folder + '/' + 'velocity_' + str(alpha),
                       vel_plot[:, :, alpha])
        fig2, ax2 = plt.subplots()
        plt.ylabel('$|v|(\AA/ps)$', fontsize=16)
        plt.xlabel('$q$', fontsize=16)
        plt.tick_params(axis='both', which='major', labelsize=16)
        plt.tick_params(axis='both', which='minor', labelsize=20)
        plt.xticks(Q, point_names)
        plt.xlim(q[0], q[-1])
        if color is not None:
            plt.plot(q,
                     vel_norm[:, :],
                     '.',
                     linewidth=4,
                     markersize=4,
                     color=color)
        else:
            plt.plot(q, vel_norm[:, :], '.', linewidth=4, markersize=4)

        plt.grid()
        plt.tick_params(axis='both', which='major', labelsize=16)
        fig2.savefig(folder + '/' + 'velocity.png')
        np.savetxt(folder + '/' + 'velocity_norm', vel_norm)
        if is_showing:
            plt.show()
        else:
            plt.close()