Ejemplo n.º 1
0
def get_phonon_dos(structure,
                   supercell_matrix,
                   force_constants,
                   qpoint_mesh=(50, 50, 50),
                   phonon_pdos=False,
                   save_data=False,
                   save_fig=False):
    '''
    Return the phonon dos

    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
    qpoint_mesh : list
        Mesh of q-points to calculate thermal properties on.
    phonon_pdos: bool
        Determine if calculate phonon pdos or not
    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_dos_obj = Phonopy(unitcell, supercell_matrix)
    ph_dos_obj.set_force_constants(force_constants)

    ph_dos_obj.run_mesh(qpoint_mesh)
    ph_dos_obj.run_total_dos()
    if save_fig:
        fig_dos = ph_dos_obj.plot_total_dos()
        fig_dos.savefig(fname='{}-dos.png'.format(filename))
        fig_dos.close()
    if save_data:
        ph_dos_obj.write_total_dos(filename='{}-dos.dat'.format(filename))

    if phonon_pdos:
        ph_dos_obj.run_mesh(qpoint_mesh,
                            with_eigenvectors=True,
                            is_mesh_symmetry=False)
        ph_dos_obj.run_projected_dos()
        if save_fig:
            ph_dos_obj.plot_projected_dos().savefig(
                fname='{}-pdos.png'.format(filename))
        if save_data:
            ph_dos_obj.write_projected_dos(
                filename='{}-pdos.dat'.format(filename))
    return ph_dos_obj
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
phonon.run_thermal_properties(t_step=10, t_max=1000, t_min=0)

# DOS
phonon.run_total_dos(sigma=0.1)
dos_dict = phonon.get_total_dos_dict()
for omega, dos in zip(dos_dict['frequency_points'], dos_dict['total_dos']):
    print("%15.7f%15.7f" % (omega, dos))
phonon.plot_total_dos().show()

# Thermal properties
tprop_dict = phonon.get_thermal_properties_dict()

for t, free_energy, entropy, cv in zip(tprop_dict['temperatures'],
                                       tprop_dict['free_energy'],
                                       tprop_dict['entropy'],
                                       tprop_dict['heat_capacity']):
    print(("%12.3f " + "%15.7f" * 3) % (t, free_energy, entropy, cv))
phonon.plot_thermal_properties().show()

# PDOS
phonon.run_mesh(mesh=[10, 10, 10],
                is_mesh_symmetry=False,
                with_eigenvectors=True)
phonon.run_projected_dos(use_tetrahedron_method=True)
pdos_dict = phonon.get_projected_dos_dict()
omegas = pdos_dict['frequency_points']
pdos = pdos_dict['projected_dos']
pdos_indices = [[0], [1]]
phonon.plot_projected_dos(pdos_indices=pdos_indices,
                          legend=pdos_indices).show()