Esempio n. 1
0
def phonon_dos(fcp_file):
    if 'fcc2x2x2' in fcp_file:
        prim = read(ref_fcc_conv2x2x2)
    else:
        prim = read(ref_fcc)
    fcp = ForceConstantPotential.read(fcp_file)
    mesh = [33, 33, 33]

    atoms_phonopy = PhonopyAtoms(symbols=prim.get_chemical_symbols(),
                                 scaled_positions=prim.get_scaled_positions(),
                                 cell=prim.cell)

    phonopy = Phonopy(atoms_phonopy,
                      supercell_matrix=5 * np.eye(3),
                      primitive_matrix=None)

    supercell = phonopy.get_supercell()
    supercell = Atoms(cell=supercell.cell,
                      numbers=supercell.numbers,
                      pbc=True,
                      scaled_positions=supercell.get_scaled_positions())
    fcs = fcp.get_force_constants(supercell)

    phonopy.set_force_constants(fcs.get_fc_array(order=2))
    phonopy.set_mesh(mesh, is_eigenvectors=True, is_mesh_symmetry=False)
    phonopy.run_total_dos()
    phonopy.plot_total_DOS()
    plt.savefig("phononDOS.png", dpi=200)

    Nq = 51
    G2X = get_band(np.array([0, 0, 0]), np.array([0.5, 0.5, 0]), Nq)
    X2K2G = get_band(np.array([0.5, 0.5, 1.0]), np.array([0, 0, 0]), Nq)
    G2L = get_band(np.array([0, 0, 0]), np.array([0.5, 0.5, 0.5]), Nq)
    bands = [G2X, X2K2G, G2L]

    phonopy.set_band_structure(bands)
    phonopy.plot_band_structure()
    xticks = plt.gca().get_xticks()
    xticks = [x * hbar * 1e15 for x in xticks]  # Convert THz to meV
    # plt.gca().set_xticks(xticks)
    plt.gca().set_xlabel("Frequency (THz)")
    plt.savefig("phononBand.png", dpi=200)
    phonopy.run_thermal_properties(t_step=10, t_max=800, t_min=100)
    tp_dict = phonopy.get_thermal_properties_dict()
    temperatures = tp_dict['temperatures']
    free_energy = tp_dict['free_energy']

    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    ax.plot(temperatures, free_energy)

    plt.show()
Esempio n. 2
0
def get_phonon_band(structure,
                    supercell_matrix,
                    force_constants,
                    band_paths=None,
                    npoints=51,
                    labels=None,
                    save_data=False,
                    save_fig=False):
    '''
    Return the phonon bandstructure

    Parameters
    ----------
    structure : pymatgen.Structure
        Unitcell (not supercell) of interest.
    supercell_matrix : numpy.ndarray
        3x3 matrix of the supercell deformation, e.g. [[3, 0, 0], [0, 3, 0], [0, 0, 3]].
    force_constants: list
        force constants
    band_paths :  list, multi dimention
        Sets of end points of paths, e.g. [[[0, 0, 0], [0.5, 0.5, 0], [0.5, 0.5, 0.5]], [[0.5, 0.25, 0.75], [0, 0, 0]]]
        If it equals None, it will determine the path automatically by phononpy
    npoints: int
        Number of q-points in each path including end points.
    labels: list of str
        The label of high symmetry points, if None, it will determine it automatically by phononpy
    save_data/save_fig: bool
        Determine if save the data/figure or not
    '''
    volume = structure.volume
    formula = structure.composition.reduced_formula
    filename = "{}-phonon-Vol{:.2f}".format(formula, volume)

    unitcell = get_phonopy_structure(structure)
    ph_band_obj = Phonopy(unitcell, supercell_matrix)
    ph_band_obj.set_force_constants(force_constants)

    if band_paths:
        qpoints, connections = get_band_qpoints_and_path_connections(
            band_paths, npoints=npoints)
        ph_band_obj.run_band_structure(qpoints,
                                       path_connections=connections,
                                       labels=labels)
    else:
        ph_band_obj.auto_band_structure()
    if save_fig:
        fig_band = ph_band_obj.plot_band_structure()
        fig_band.savefig(fname='{}-band.png'.format(filename))
        fig_band.close()
    if save_data:
        ph_band_obj.write_yaml_band_structure(
            filename='{}-band.yaml'.format(filename))
    return ph_band_obj
    def get_phonon(self, phonon, **kwargs):
        flag_savefig = kwargs.get('savefig', False)
        flag_savedata = kwargs.get('savedata', False)
        flag_band = kwargs.get('band', False)
        flag_dos = kwargs.get('phonon_dos', False)
        flag_pdos = kwargs.get('phonon_pdos', False)

        mesh = kwargs.get('mesh', [50, 50, 50])
        labels = kwargs.get('labels', None)

        if 'unitcell' not in phonon:
            raise FileNotFoundError(
                'There is no phonon result. Please run phonon first.')
        self.head = ['Temperature', 'F_vib', 'CV_vib', 'S_vib']
        self.unit = ['K', 'eV', 'eV/K', 'eV/K']
        self.data = np.vstack((phonon.pop('temperatures'), phonon.pop('F_vib'),
                               phonon.pop('CV_vib'), phonon.pop('S_vib'))).T
        filename = '{}-phonon-Vol{:.2f}'.format(self.formula, self.volume)

        unitcell = get_phonopy_structure(self.structure)
        supercell_matrix = phonon['supercell_matrix']
        force_constants = phonon['force_constants']
        ph = Phonopy(unitcell, supercell_matrix)
        ph.set_force_constants(force_constants)

        #for band structure
        if flag_band:
            if 'path' in kwargs:
                qpoints, connections = get_band_qpoints_and_path_connections(
                    path, npoints=51)
                ph.run_band_structure(qpoints,
                                      path_connections=connections,
                                      labels=labels)
            else:
                ph.auto_band_structure()
            if flag_savefig:
                fig_band = ph.plot_band_structure()
                fig_band.savefig(fname='{}-band.png'.format(filename))
                fig_band.close()
            if flag_savedata:
                ph.write_yaml_band_structure(
                    filename='{}-band.yaml'.format(filename))

        #for dos
        if flag_dos:
            ph.run_mesh(mesh)
            ph.run_total_dos()
            #phonon_dos_tmp = np.vstack((ph._total_dos._frequency_points, ph._total_dos._dos))
            #print(phonon_dos_tmp)
            #print(type(phonon_dos_tmp))
            if flag_savefig:
                fig_dos = ph.plot_total_dos()
                fig_dos.savefig(fname='{}-dos.png'.format(filename))
                fig_dos.close()
            if flag_savedata:
                ph.write_total_dos(filename='{}-dos.dat'.format(filename))
        #for pdos.
        if flag_pdos:
            ph.run_mesh(mesh, with_eigenvectors=True, is_mesh_symmetry=False)
            ph.run_projected_dos()
            if flag_savefig:
                ph.plot_projected_dos().savefig(
                    fname='{}-pdos.png'.format(filename))
            if flag_savedata:
                ph.write_projected_dos(filename='{}-pdos.dat'.format(filename))

        phonon.pop('_id')
        self.parameter = phonon
Esempio n. 4
0
# nac_params = {'born': born,
#               'factor': factors,
#               'dielectric': epsilon}
phonon.set_nac_params(nac_params)

# BAND = 0.0 0.0 0.0  0.5 0.0 0.0  0.5 0.5 0.0  0.0 0.0 0.0  0.5 0.5 0.5
bands = []
append_band(bands, [0.0, 0.0, 0.0], [0.5, 0.0, 0.0])
append_band(bands, [0.5, 0.0, 0.0], [0.5, 0.5, 0.0])
append_band(bands, [0.5, 0.5, 0.0], [0.0, 0.0, 0.0])
append_band(bands, [0.0, 0.0, 0.0], [0.5, 0.5, 0.5])
phonon.set_band_structure(bands)
q_points, distances, frequencies, eigvecs = phonon.get_band_structure()
for q, d, freq in zip(q_points, distances, frequencies):
    print q, d, freq
phonon.plot_band_structure().show()

# Mesh sampling 20x20x20
phonon.set_mesh([20, 20, 20])
phonon.set_thermal_properties(t_step=10,
                              t_max=1000,
                              t_min=0)

# DOS
phonon.set_total_DOS(sigma=0.1)
for omega, dos in np.array(phonon.get_total_DOS()).T:
    print "%15.7f%15.7f" % (omega, dos)
phonon.plot_total_DOS().show()

# Thermal properties
for t, free_energy, entropy, cv in np.array(phonon.get_thermal_properties()).T:
Esempio n. 5
0
# nac_params = {'born': born,
#               'factor': factors,
#               'dielectric': epsilon}
phonon.set_nac_params(nac_params)

# BAND = 0.0 0.0 0.0  0.5 0.0 0.0  0.5 0.5 0.0  0.0 0.0 0.0  0.5 0.5 0.5
bands = []
append_band(bands, [0.0, 0.0, 0.0], [0.5, 0.0, 0.0])
append_band(bands, [0.5, 0.0, 0.0], [0.5, 0.5, 0.0])
append_band(bands, [0.5, 0.5, 0.0], [0.0, 0.0, 0.0])
append_band(bands, [0.0, 0.0, 0.0], [0.5, 0.5, 0.5])
phonon.set_band_structure(bands)
q_points, distances, frequencies, eigvecs = phonon.get_band_structure()
for q, d, freq in zip(q_points, distances, frequencies):
    print q, d, freq
phonon.plot_band_structure().show()

# Mesh sampling 20x20x20
phonon.set_mesh([20, 20, 20])
phonon.set_thermal_properties(t_step=10, t_max=1000, t_min=0)

# DOS
phonon.set_total_DOS(sigma=0.1)
for omega, dos in np.array(phonon.get_total_DOS()).T:
    print "%15.7f%15.7f" % (omega, dos)
phonon.plot_total_DOS().show()

# Thermal properties
for t, free_energy, entropy, cv in np.array(phonon.get_thermal_properties()).T:
    print("%12.3f " + "%15.7f" * 3) % (t, free_energy, entropy, cv)
phonon.plot_thermal_properties().show()
Esempio n. 6
0
bands.append(band)

q_start = np.array([0, 0, 0])
q_end = np.array([1./3, 1./3, 1./2])
band = []
for i in range(51):
    band.append(q_start + ( q_end - q_start ) / 50 * i)
bands.append(band)

#*********************
# Matplotlib required
#*********************
print "\nPhonon dispersion:"
phonon.set_band_structure(bands,
                          is_eigenvectors=True)
phonon.plot_band_structure(["X", "$\Gamma$", "L"]).show()

bands = phonon.get_band_structure()
distances = bands[1]
frequencies = bands[2]
qpoints = bands[0]

for (qs_at_segments,
     dists_at_segments,
     freqs_at_segments) in zip(qpoints, distances, frequencies):

    for q, d, f in zip(qs_at_segments,
                       dists_at_segments,
                       freqs_at_segments):
        print "# %f %f %f" % tuple(q)
        print d, ("%f " * len(f)) % tuple(f)
Esempio n. 7
0
    def MVibrationauto(self, maxx=4500):
        import os
        import numpy as np
        from pymatgen.io.phonopy import get_phonopy_structure
        import pymatgen as pmg
        from pymatgen.io.vasp.outputs import Vasprun
        from pymatgen.io.vasp import Poscar
        from pymatgen.symmetry.kpath import KPathSeek, KPathBase
        from phonopy.phonon.band_structure import get_band_qpoints_and_path_connections
        from phonopy import Phonopy
        from phonopy.structure.atoms import Atoms as PhonopyAtoms
        from pymatgen.phonon.plotter import PhononBSPlotter
        from pymatgen.phonon.bandstructure import PhononBandStructureSymmLine
        import csv
        import pandas as pd
        import matplotlib.pyplot as plt

        os.chdir(self.dire)
        print(os.getcwd())

        poscar = Poscar.from_file("POSCAR")
        structure = poscar.structure
        scell = [[2, 0, 0], [0, 2, 0], [0, 0, 2]]
        vrun = Vasprun("vasprun.xml")
        phonopyAtoms = get_phonopy_structure(structure)
        phonon = Phonopy(phonopyAtoms, scell)

        phonon.set_force_constants(-vrun.force_constants)

        # labels = ["$\\Gamma$", "X", "U", "K", "L"]
        labels = ['K', "$\\Gamma$", 'L', 'W', 'X']
        # bands = []
        cd = KPathSeek(structure)
        cds = cd.kpath
        # print(cds)
        for k, v in cds.items():
            if "kpoints" in k:

                dics = v
            else:
                dicss = v
        print(dics)
        print(dicss)

        # bands=[]
        # for k,v in dics.items():
        #     if k in dicss[0]:
        #         bands.append(v)

        path = []
        #

        # bandd1=[]
        # for k,v in dics.items():
        #     for i in dicss[0]:
        #             if k in i:
        #                 bandd1.append(v)
        # path.append(bandd1)

        bandd1 = []
        for i in dicss[1]:
            for k, v in dics.items():
                if k in i:
                    bandd1.append(v)
        path.append(bandd1)
        print(dicss[1])
        qpoints, connections = get_band_qpoints_and_path_connections(
            path, npoints=51)
        phonon.run_band_structure(qpoints,
                                  path_connections=connections,
                                  labels=labels)

        print(path)

        # kpoints=cd.get_kpoints

        # print(kpoints)

        # phonon.set_band_structure(bands,labels=labels)

        phonon.plot_band_structure().show()
        phonon.plot_band_structure().savefig("BAND.png",
                                             bbox_inches='tight',
                                             transparent=True,
                                             dpi=300,
                                             format='png')
        # phonon.write_band_structure()
        mesh = [31, 31, 31]
        phonon.set_mesh(mesh)

        phonon.set_total_DOS()
        phonon.write_total_DOS()
        phonon.plot_total_DOS().show()
        phonon.plot_total_DOS().savefig("DOS.png")
        # c = np.fromfile('total_dos.dat', dtype=float)

        datContent = [
            i.strip().split() for i in open("./total_dos.dat").readlines()
        ]
        del datContent[0]
        x_ax = []
        y_ax = []
        for i in datContent:
            x_ax.append(1 / ((3 * (10**8) / (float(i[0]) * (10**12))) * 100))
            y_ax.append(float(i[1]))

        da = {'Density of states': x_ax, 'Frequency': y_ax}
        df = pd.DataFrame(da)  #构造原始数据文件
        df.to_excel("Wave number.xlsx")  #生成Excel文件,并存到指定文件路径下

        fig, ax = plt.subplots()

        line1 = ax.plot(x_ax, y_ax, c='grey')
        ax.set_xlim([maxx, 0])

        # 以下是XRD图片的格式设置
        #设置横纵坐标的名称以及对应字体格式
        font2 = {
            'family': 'Times New Roman',
            'weight': 'bold',
        }
        plt.xlabel('Wavenumber ($\mathregular{cm^-}$$\mathregular{^1}$)',
                   font2)
        plt.ylabel('Density of states', font2)

        #不显示Y轴的刻度
        plt.yticks([])

        #设置图例对应格式和字体
        font1 = {
            'family': 'Times New Roman',
            'weight': 'bold',
        }
        # ax.legend(edgecolor='none', prop=font1)

        # plt.legend(edgecolor='none', prop=font1)
        # plt.set_facecolor('none')
        ax.set_facecolor('none')

        #存储为
        fig.savefig('FTIR.png',
                    bbox_inches='tight',
                    transparent=True,
                    dpi=300,
                    format='png')  #指定分辨率,边界紧,背景透明
        plt.show()
Esempio n. 8
0
    def Vibration(self, maxx=4500):
        import os
        import numpy as np
        from pymatgen.io.phonopy import get_phonopy_structure
        import pymatgen as pmg
        from pymatgen.io.vasp.outputs import Vasprun
        from pymatgen.io.vasp import Poscar
        from pymatgen.symmetry.kpath import KPathSeek, KPathBase

        from phonopy import Phonopy
        from phonopy.structure.atoms import Atoms as PhonopyAtoms
        from pymatgen.phonon.plotter import PhononBSPlotter
        from pymatgen.phonon.bandstructure import PhononBandStructureSymmLine
        import csv
        import pandas as pd
        import matplotlib.pyplot as plt

        os.chdir(self.dire)
        print(os.getcwd())

        poscar = Poscar.from_file("POSCAR")
        structure = poscar.structure
        scell = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
        vrun = Vasprun("vasprun.xml")
        phonopyAtoms = get_phonopy_structure(structure)
        phonon = Phonopy(phonopyAtoms, scell)

        phonon.set_force_constants(-vrun.force_constants)

        labels = ["$\\Gamma$", "X", "U", "K", "$\\Gamma$", "L", "W"]
        bands = []

        # path 1
        q_start = np.array([0.0, 0.0, 0.0])
        q_end = np.array([0.5, 0.0, 0.0])
        band = []
        for i in range(51):
            band.append(q_start + (q_end - q_start) / 50 * i)
        bands.append(band)

        # path 2
        q_start = np.array([0.5, 0.0, 0.0])
        q_end = np.array([0.5, 0.5, 0.0])
        band = []
        for i in range(51):
            band.append(q_start + (q_end - q_start) / 50 * i)
        bands.append(band)

        # # path 3
        # q_start  = np.array([0.5, 0.5, 0.0])
        # q_end    = np.array([-0.0, -0.0, 0.0])
        # band = []
        # for i in range(51):
        #     band.append(q_start + (q_end - q_start) / 50 * i)
        # bands.append(band)

        # # path 4
        # q_start  = np.array([0.0, 0.0, 0.0])
        # q_end    = np.array([0.5, 0.5, 0.5])
        # band = []
        # for i in range(51):
        #     band.append(q_start + (q_end - q_start) / 50 * i)
        # bands.append(band)

        print(bands)

        phonon.set_band_structure(bands)

        phonon.plot_band_structure().show()
        phonon.plot_band_structure().savefig("BAND.png")
        mesh = [31, 31, 31]
        phonon.set_mesh(mesh)

        phonon.set_total_DOS()
        phonon.write_total_DOS()
        phonon.plot_total_DOS().show()
        phonon.plot_total_DOS().savefig("DOS.png")
        # c = np.fromfile('total_dos.dat', dtype=float)

        datContent = [
            i.strip().split() for i in open("./total_dos.dat").readlines()
        ]
        del datContent[0]
        x_ax = []
        y_ax = []
        for i in datContent:
            x_ax.append(1 / ((3 * (10**8) / (float(i[0]) * (10**12))) * 100))
            y_ax.append(float(i[1]))

        da = {'Density of states': x_ax, 'Frequency': y_ax}
        df = pd.DataFrame(da)  #构造原始数据文件
        df.to_excel("Wave number.xlsx")  #生成Excel文件,并存到指定文件路径下

        fig, ax = plt.subplots()

        line1 = ax.plot(x_ax, y_ax, c="grey")
        ax.set_xlim([maxx, 0])

        # 以下是XRD图片的格式设置
        #设置横纵坐标的名称以及对应字体格式
        font2 = {
            'family': 'Times New Roman',
            'weight': 'bold',
        }
        plt.xlabel('Wavenumber ($\mathregular{cm^-}$$\mathregular{^1}$)',
                   font2)
        plt.ylabel('Density of states', font2)

        #不显示Y轴的刻度
        plt.yticks([])

        #设置图例对应格式和字体
        font1 = {
            'family': 'Times New Roman',
            'weight': 'bold',
        }
        # ax.legend(edgecolor='none', prop=font1)

        # plt.legend(edgecolor='none', prop=font1)
        # plt.set_facecolor('none')
        ax.set_facecolor('none')

        #存储为
        fig.savefig('FTIR.png',
                    bbox_inches='tight',
                    transparent=True,
                    dpi=300,
                    format='png')  #指定分辨率,边界紧,背景透明
        plt.show()
Esempio n. 9
0
phonon_scell.set_displacement_dataset(
    force_set)  # force_set is a list of forces and displacements

if NAC == True:
    nac_params = PhonIO.get_born_parameters(
        open("BORN"), phonon_scell.get_primitive(),
        phonon_scell.get_primitive_symmetry())
    if nac_params['factor'] == None:
        physical_units = get_default_physical_units(interface_mode)
        nac_params['factor'] = physical_units['nac_factor']
    phonon_scell._nac_params = nac_params

phonon_scell.produce_force_constants()
phonon_scell.symmetrize_force_constants()
api_ph.write_ShengBTE_FC2(phonon_scell.get_force_constants(),
                          filename='FORCE_CONSTANTS_2ND')
# phonopy 2.7 changed format, ShengBTE won't read, use the file in api_qpv to write.

# calc and plot bandstructure
bands = api_ph.qpoints_Band_paths(Qpoints, Band_points)
phonon_scell.set_band_structure(bands,
                                is_eigenvectors=True,
                                labels=band_labels)
phonon_scell.write_yaml_band_structure()
bs_plt = phonon_scell.plot_band_structure()
bs_plt.xlabel("")
bs_plt.ylabel("Frequency (THz)", fontsize=16)
bs_plt.xticks(fontsize=16)
bs_plt.yticks(fontsize=16)
bs_plt.savefig("Bands_quip.png", dpi=300, bbox_inches='tight')
Esempio n. 10
0
    band.append(q_start + (q_end - q_start) / 50 * i)
bands.append(band)

q_start = np.array([0.0, 0.0, 0.0])  # Gamma to L
q_end = np.array([0.5, 0.5, 0.5])
band = []
for i in range(51):
    band.append(q_start + (q_end - q_start) / 50 * i)
bands.append(band)

dir_labels = [r'$\Gamma$', '$X$', '$W$', '$X$', '$K$', r'$\Gamma$', '$L$']

# plot the band structure
clf()
phonon.set_band_structure(bands)
phonon.plot_band_structure(dir_labels)
ylim(0, 20.)

# save results to file band.yaml
bs = BandStructure(bands,
                   phonon.dynamical_matrix,
                   phonon.primitive,
                   factor=VaspToTHz)

if write_yaml:
    bs.write_yaml()

# add vertical lines to plot
for p in bs.special_point:
    axvline(p, color='k')
Esempio n. 11
0
    phonon.produce_force_constants()

    mesh = [nqx, nqy, nqz]
    phonon.set_mesh(mesh, is_eigenvectors=True)
    qpoints, weights, frequencies, eigvecs = phonon.get_mesh()

    #SHOW DOS STRUCTURE
    phonon.set_total_DOS(freq_min=0.0, freq_max=12.0, tetrahedron_method=False)
    phonon.get_total_DOS()
    phonon.write_total_DOS()
    phonon.plot_total_DOS().show()

    #BAND STRUCTURE
    phonon.set_band_structure(paths, is_eigenvectors=False, is_band_connection=True)
    phonon.get_band_structure()
    ph_plot = phonon.plot_band_structure(labels=["G", "N", "P"])
    ph_plot.show()
    #WRITE ANIMATION MODE
    phonon.write_animation()
    #TEMPERATURE
    phonon.set_thermal_properties(t_step=10, t_max=1000, t_min=0)
    temp_plot = open('temp_plot.dat', 'w')
    for t, free_energy, entropy, cv in np.array(phonon.get_thermal_properties()).T:
        print >> temp_plot, ("%12.3f " + "%15.7f" * 3) % ( t, free_energy, entropy, cv )
    phonon.plot_thermal_properties().show()
    #Finally write parametrs of calculation i.e. supercell size for force_constant
    #and qpoint mesh

    with open('subgb.json','w') as f:
        gb_dict = {}
        gb_dict['n_sup_cell'] = [n_sup_x, n_sup_y, n_sup_z]
Esempio n. 12
0
bands.append(band)

q_start = np.array([0, 0, 0])
q_end = np.array([1./3, 1./3, 1./2])
band = []
for i in range(51):
    band.append(q_start + ( q_end - q_start ) / 50 * i)
bands.append(band)

#*********************
# Matplotlib required
#*********************
print "\nPhonon dispersion:"
phonon.set_band_structure(bands,
                          is_eigenvectors=True)
band_plot = phonon.plot_band_structure(["X", "$\Gamma$", "L"])
band_plot.show()

bands = phonon.get_band_structure()
distances = bands[1]
frequencies = bands[2]
qpoints = bands[0]

for (qs_at_segments,
     dists_at_segments,
     freqs_at_segments) in zip(qpoints, distances, frequencies):

    for q, d, f in zip(qs_at_segments,
                       dists_at_segments,
                       freqs_at_segments):
        print "# %f %f %f" % tuple(q)
Esempio n. 13
0
    band.append(q_start + (q_end - q_start) / 50 * i)
bands.append(band)

q_start = np.array([0, 0, 0])
q_end = np.array([1. / 3, 1. / 3, 1. / 2])
band = []
for i in range(51):
    band.append(q_start + (q_end - q_start) / 50 * i)
bands.append(band)

#*********************
# Matplotlib required
#*********************
print "\nPhonon dispersion:"
phonon.set_band_structure(bands, is_eigenvectors=True)
band_plot = phonon.plot_band_structure(["X", "$\Gamma$", "L"])
band_plot.show()

bands = phonon.get_band_structure()
distances = bands[1]
frequencies = bands[2]
qpoints = bands[0]

for (qs_at_segments, dists_at_segments,
     freqs_at_segments) in zip(qpoints, distances, frequencies):

    for q, d, f in zip(qs_at_segments, dists_at_segments, freqs_at_segments):
        print "# %f %f %f" % tuple(q)
        print d, ("%f " * len(f)) % tuple(f)

# If you just want to plot along q-points of all band segments, the
                    cell=structure.cell)

phonon = Phonopy(bulk,
                 phonopy_input['supercell'],
                 primitive_matrix=phonopy_input['primitive'],
                 distance=phonopy_input['distance'])

phonon.set_force_constants(force_constants)

# Save band structure to PDF
bands = []
q_start = np.array([0.5, 0.5, 0.0])
q_end = np.array([0.0, 0.0, 0.0])
band = []
for i in range(51):
    band.append(q_start + (q_end - q_start) / 50 * i)
bands.append(band)

q_start = np.array([0.0, 0.0, 0.0])
q_end = np.array([0.5, 0.0, 0.0])
band = []
for i in range(51):
    band.append(q_start + (q_end - q_start) / 50 * i)
bands.append(band)

phonon.set_band_structure(bands)
phonon.write_yaml_band_structure()

plt = phonon.plot_band_structure()
plt.savefig("phonon_band_structure.pdf")