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
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
for q, d, freq in zip(q_path, d_path, freq_path): print(("%10.5f %5.2f %5.2f %5.2f " + (" %7.3f" * len(freq))) % ((d, q[0], q[1], q[2]) + tuple(freq))) phonon.plot_band_structure().show() # Mesh sampling 20x20x20 phonon.run_mesh(mesh=[20, 20, 20]) 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)