def gen_test_data(datadir: str, params_fd: dict, supercell): from gpaw.elph.electronphonon import ElectronPhononCoupling params_gs = copy.deepcopy(params_fd) atoms = Cluster(ase.build.bulk('C')) calc_gs = GPAW(**params_gs) atoms.calc = calc_gs atoms.get_potential_energy() atoms.calc.write("gs.gpw", mode="all") # Make sure the real space grid matches the original. # (basically we multiply the number of grid points in each dimension by the supercell dimension) params_fd['gpts'] = calc_gs.wfs.gd.N_c * list(supercell) if 'h' in params_fd: del params_fd['h'] del calc_gs if world.rank == 0: os.makedirs(datadir, exist_ok=True) calc_fd = GPAW(**params_fd) elph = ElectronPhononCoupling(atoms, calc=calc_fd, supercell=supercell, calculate_forces=True, name=f'{datadir}/elph') elph.run() calc_fd.wfs.gd.comm.barrier() elph = ElectronPhononCoupling(atoms, calc=calc_fd, supercell=supercell) elph.set_lcao_calculator(calc_fd) elph.calculate_supercell_matrix(dump=1)
def elph_do_supercell_matrix(log, calc, supercell): from gpaw.elph.electronphonon import ElectronPhononCoupling # calculate_supercell_matrix breaks if parallelized over domains so parallelize over kpt instead # (note: it prints messages from all processes but it DOES run faster with more processes) supercell_atoms = GPAW('supercell.eq.gpw', txt=log, parallel={'domain': (1,1,1), 'band': 1, 'kpt': world.size}).get_atoms() elph = ElectronPhononCoupling(calc.atoms, supercell=supercell, calc=supercell_atoms.calc) elph.set_lcao_calculator(supercell_atoms.calc) # to initialize bfs.M_a ensure_gpaw_setups_initialized(supercell_atoms.calc, supercell_atoms) elph.calculate_supercell_matrix(dump=1) world.barrier()
def main__brute_gpw(structure_path, supercell, log): from gpaw.elph.electronphonon import ElectronPhononCoupling from gpaw import GPAW calc = GPAW(structure_path) supercell_atoms = make_gpaw_supercell(calc, supercell, txt=log) # NOTE: confusingly, Elph wants primitive atoms, but a calc for the supercell elph = ElectronPhononCoupling(calc.atoms, calc=supercell_atoms.calc, supercell=supercell, calculate_forces=True) elph.run() supercell_atoms.calc.wfs.gd.comm.barrier() elph = ElectronPhononCoupling(calc.atoms, calc=supercell_atoms.calc, supercell=supercell) elph.set_lcao_calculator(supercell_atoms.calc) elph.calculate_supercell_matrix(dump=1) return
def get_elph_elements(atoms, gpw_name, calc_fd, sc=(1, 1, 1), basename=None, phononname='phonon'): """ Evaluates the dipole transition matrix elements Input ---------- params_fd : Calculation parameters used for the phonon calculation sc (tuple): Supercell, default is (1,1,1) used for gamma phonons basename : If you want give a specific name (gqklnn_{}.pckl) Output ---------- gqklnn.pckl, the electron-phonon matrix elements """ from ase.phonons import Phonons from gpaw.elph.electronphonon import ElectronPhononCoupling calc_gs = GPAW(gpw_name) world = calc_gs.wfs.world #calc_fd = GPAW(**params_fd) calc_gs.initialize_positions(atoms) kpts = calc_gs.get_ibz_k_points() nk = len(kpts) gamma_kpt = [[0, 0, 0]] nbands = calc_gs.wfs.bd.nbands qpts = gamma_kpt # calc_fd.get_potential_energy() # XXX needed to initialize C_nM ?????? # Phonon calculation, We'll read the forces from the elph.run function # This only looks at gamma point phonons ph = Phonons(atoms=atoms, name=phononname, supercell=sc) ph.read() frequencies, modes = ph.band_structure(qpts, modes=True) if world.rank == 0: print("Phonon frequencies are loaded.") # Find el-ph matrix in the LCAO basis elph = ElectronPhononCoupling(atoms, calc=None, supercell=sc) elph.set_lcao_calculator(calc_fd) elph.load_supercell_matrix() if world.rank == 0: print("Supercell matrix is loaded") # Non-root processes on GD comm seem to be missing kpoint data. assert calc_gs.wfs.gd.comm.size == 1, "domain parallelism not supported" # not sure how to fix this, sorry gcomm = calc_gs.wfs.gd.comm kcomm = calc_gs.wfs.kd.comm if gcomm.rank == 0: # Find the bloch expansion coefficients c_kn = np.empty((nk, nbands, calc_gs.wfs.setups.nao), dtype=complex) for k in range(calc_gs.wfs.kd.nibzkpts): c_k = calc_gs.wfs.collect_array("C_nM", k, 0) if kcomm.rank == 0: c_kn[k] = c_k kcomm.broadcast(c_kn, 0) # And we finally find the electron-phonon coupling matrix elements! g_qklnn = elph.bloch_matrix(c_kn=c_kn, kpts=kpts, qpts=qpts, u_ql=modes) if world.rank == 0: print("Saving the elctron-phonon coupling matrix") np.save("gqklnn{}.npy".format(make_suffix(basename)), np.array(g_qklnn))
'basis': 'dzp', 'symmetry': { 'point_group': False }, 'xc': 'PBE' } elph_calc = GPAW(**parameters) atoms.set_calculator(elph_calc) atoms.get_potential_energy() gamma_bands = elph_calc.wfs.kpt_u[0].C_nM elph = ElectronPhononCoupling(atoms, elph_calc, supercell=supercell, calculate_forces=True) elph.run() parameters['parallel'] = {'domain': 1} elph_calc = GPAW(**parameters) elph = ElectronPhononCoupling(atoms, calc=None, supercell=supercell) elph.set_lcao_calculator(elph_calc) elph.calculate_supercell_matrix(dump=1) ph = Phonons(atoms=atoms, name='phonons', supercell=supercell, calc=None) ph.read() kpts = [[0, 0, 0]] frequencies, modes = ph.band_structure(kpts, modes=True) c_kn = np.array([[gamma_bands[0]]]) g_qklnn = elph.bloch_matrix(c_kn=c_kn, kpts=kpts, qpts=kpts, u_ql=modes)