def run_phonolammps(): n = 2 phlammps = Phonolammps('in.graphene', supercell_matrix=[[n, 0, 0], [0, n, 0], [0, 0, n]]) unitcell = phlammps.get_unitcell() force_constants = phlammps.get_force_constants() supercell_matrix = phlammps.get_supercell_matrix() print('unitcell') print('*' * 50) print(unitcell) print('force const') print('*' * 50) print(force_constants) print('supercell') print('*' * 50) print(supercell_matrix) from phonopy import Phonopy phonon = Phonopy(unitcell, supercell_matrix) print(phonon) print(dir(phonon)) phonon.set_force_constants(force_constants) phonon.set_mesh([20, 20, 20]) # phonon.write_yaml_band_structure('band.conf') # phonon.set_band_structure('band.conf') # phonon.plot_band_structure().savefig('band.png') # phonon.set_total_DOS() # phonon.plot_total_DOS().savefig('dos.png') phonon.set_thermal_properties() # print(phonon.get_thermal_properties_dict()) phonon.plot_thermal_properties().savefig('therm.png')
# Integration with phonopy from phonolammps import Phonolammps from phonopy import Phonopy phlammps = Phonolammps('in.lammps', supercell_matrix=[[3, 0, 0], [0, 3, 0], [0, 0, 3]]) unitcell = phlammps.get_unitcell() force_constants = phlammps.get_force_constants() supercell_matrix = phlammps.get_supercell_matrix() phonon = Phonopy(unitcell, supercell_matrix) phonon.set_force_constants(force_constants) phonon.set_mesh([20, 20, 20]) phonon.set_total_DOS() phonon.plot_total_DOS().show() phonon.set_thermal_properties() phonon.plot_thermal_properties().show()
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() # PDOS phonon.set_mesh([10, 10, 10], is_mesh_symmetry=False, is_eigenvectors=True) phonon.set_partial_DOS(tetrahedron_method=True) omegas, pdos = phonon.get_partial_DOS() pdos_indices = [[0], [1]] phonon.plot_partial_DOS(pdos_indices=pdos_indices, legend=pdos_indices).show()
def test_phonolammps(): os.chdir('data') with open('data.si', 'w') as f: f.write('''Generated using dynaphopy 8 atoms 1 atom types 0.0000000000 5.4500000000 xlo xhi 0.0000000000 5.4500000000 ylo yhi 0.0000000000 5.4500000000 zlo zhi 0.0000000000 0.0000000000 0.0000000000 xy xz yz Masses 1 28.0855000000 Atoms 1 1 4.7687500000 4.7687500000 4.7687500000 2 1 4.7687500000 2.0437500000 2.0437500000 3 1 2.0437500000 4.7687500000 2.0437500000 4 1 2.0437500000 2.0437500000 4.7687500000 5 1 0.6812500000 0.6812500000 0.6812500000 6 1 0.6812500000 3.4062500000 3.4062500000 7 1 3.4062500000 0.6812500000 3.4062500000 8 1 3.4062500000 3.4062500000 0.6812500000 ''') with open('si.in', 'w') as f: f.write(''' units metal boundary p p p box tilt large atom_style atomic read_data data.si pair_style tersoff pair_coeff * * SiCGe.tersoff Si(C) neighbor 0.3 bin ''') supercell = [[2, 0, 0], [0, 2, 0], [0, 0, 2]] print(supercell) phlammps = Phonolammps('si.in', supercell_matrix=supercell) print(phlammps) unitcell = phlammps.get_unitcell() force_constants = phlammps.get_force_constants() supercell_matrix = phlammps.get_supercell_matrix() print(unitcell) print(force_constants) print(supercell_matrix) os.chdir('..') return phonon = Phonopy(unitcell, supercell_matrix) phonon.set_force_constants(force_constants) phonon.set_mesh([20, 20, 20]) phonon.set_total_DOS() phonon.plot_total_DOS().show() phonon.set_thermal_properties() phonon.plot_thermal_properties().show()
class PhononFromModel(object): """ This class uses frozen phonon method to calculate the phonon dispersion curves and thermodynamic properties of a structure. The steps are as follows: 1. Displaced structures are obtained from pristine structure via phonopy. 2. The forces of each displaced structures are calculated by model 3. The forces are passed to phonopy object and the force constant are produced 4. Phonon is calculated once the force constant matrix is available. Args: model (model object): a model object that has a method "calculate_forces" that takes in a list of structures and return a list of N*3 forces, where N are the number of atoms in each structures structure (pymatgen structure): a pristine pymatgen structure atom_disp (float): small displacements in Angstrom """ def __init__(self, model=None, structure=None, atom_disp=0.015, **kwargs): self.model = model self.structure = structure self.atom_disp = atom_disp self.qpoints, self.vertices = get_qpoints_and_vertices(self.structure) is_plusminus = kwargs.get('is_plusminus', True) is_diagonal = kwargs.get('is_diagonal', True) is_trigonal = kwargs.get('is_diagonal', False) supercell_matrix = kwargs.get('is_diagonal', None) ph_structure = get_phonopy_structure(self.structure) if supercell_matrix is None: supercell_matrix = np.eye(3) * np.array((1, 1, 1)) self.phonon = Phonopy(unitcell=ph_structure, supercell_matrix=supercell_matrix) self.phonon.generate_displacements(distance=self.atom_disp, is_plusminus=is_plusminus, is_diagonal=is_diagonal, is_trigonal=is_trigonal) disp_supercells = self.phonon.get_supercells_with_displacements() # Perfect supercell structure init_supercell = self.phonon.get_supercell() # Structure list to be returned self.structure_list = [get_pmg_structure(init_supercell)] for c in disp_supercells: if c is not None: self.structure_list.append(get_pmg_structure(c)) forces = self.model.calculate_forces(self.structure_list) self.phonon.set_forces(forces[1:]) self.phonon.produce_force_constants() logging.info("Force constant produced") def get_thermo_properties(self, mesh=[8, 8, 8], t_step=10, t_max=3000, t_min=0): self.phonon.set_mesh(mesh=mesh) self.phonon.set_thermal_properties(t_step=t_step, t_max=t_max, t_min=t_min) plt = self.phonon.plot_thermal_properties() return plt def get_bs_plot(self, points_per_line=50, figsize=(6, 4), ylim=[-1, 5]): bands = [] bands = append_bands(bands, self.qpoints, points_per_line) self.phonon.set_band_structure(bands) q_points, self.distances, self.frequencies, eigvecs = self.phonon.get_band_structure() special_points = self.phonon._band_structure._special_points distance = self.phonon._band_structure._distance plt.figure(figsize=figsize) for j, (d, f) in enumerate(zip(self.distances, self.frequencies)): for i, freqs in enumerate(f.T): if i == 0 and j == 0: plt.plot(d, freqs, "b-", lw=1) else: plt.plot(d, freqs, "b-", lw=1) for sp in special_points: plt.axvline(x=sp, linestyle=':', linewidth=1, color='k') plt.axhline(y=0, linestyle=':', linewidth=1, color='k') plt.xticks(special_points, ["$\mathrm{%s}$" % i for i in self.vertices]) plt.xlabel("Wave vector") plt.ylabel("Frequency (THz)") plt.xlim(0, distance) plt.ylim(ylim) plt.yticks(list(range(ylim[0], ylim[-1]+1))) plt.tight_layout() return plt