def polarizability(base_dir="./", mode="df", fermi_shift=None): curr_dir = os.path.dirname(os.path.abspath(__file__)) es_gpw = os.path.join(base_dir, "es.gpw") param_file = os.path.join(curr_dir, "../parameters.json") if os.path.exists(param_file): params = json.load(open(param_file, "r")) else: raise FileNotFoundError("no parameter file!") if not os.path.exists(es_gpw): raise FileNotFoundError("Excited state not calculated!") if mode not in ("df", "tetra"): raise ValueError("Mode should be df or tetra") if fermi_shift is None: data_file = os.path.join(base_dir, "polarizability_{}.npz".format(mode)) else: data_file = os.path.join(base_dir, "polarizability_{}_{:.2f}.npz".format(mode, fermi_shift)) params[mode]["intraband"] = True if os.path.exists(data_file): parprint("Polarizability file exists!") return 0 df = DielectricFunction(calc=es_gpw, **params[mode], gate_voltage=fermi_shift) # add energy shift alpha0x, alphax = df.get_polarizability(q_c=[0, 0, 0], direction="x", pbc=[True, True, False], filename=None) alpha0y, alphay = df.get_polarizability(q_c=[0, 0, 0], direction="y", pbc=[True, True, False], filename=None) alpha0z, alphaz = df.get_polarizability(q_c=[0, 0, 0], direction="z", pbc=[True, True, False], filename=None) freq = df.get_frequencies() data = dict(frequencies=freq, alpha_x=alphax, alpha_y=alphay, alpha_z=alphaz, alpha_x0=alpha0x, alpha_y0=alpha0y, alpha_z0=alpha0z,) from ase.parallel import world import numpy if world.rank == 0: numpy.savez_compressed(data_file, **data)
def permittivity(base_dir="./", mode="df"): curr_dir = os.path.dirname(os.path.abspath(__file__)) es_gpw = os.path.join(base_dir, "es.gpw") param_file = os.path.join(curr_dir, "../parameters.json") if os.path.exists(param_file): params = json.load(open(param_file, "r")) else: raise FileNotFoundError("no parameter file!") if not os.path.exists(es_gpw): raise FileNotFoundError("Excited state not calculated!") if mode not in ("df", "tetra"): raise ValueError("Mode should be df or tetra") data_file = os.path.join(base_dir, "polarizability_{}.npz".format(mode)) if os.path.exists(data_file): parprint("Polarizability file exists!") return 0 df = DielectricFunction(calc=es_gpw, **params[mode]) eps0x, epsx = df.get_dielectric_function( q_c=[0, 0, 0], direction="x", #pbc=[True, True, False], filename=None) eps0y, epsy = df.get_dielectric_function( q_c=[0, 0, 0], direction="y", #pbc=[True, True, False], filename=None) eps0z, epsz = df.get_dielectric_function( q_c=[0, 0, 0], direction="z", #pbc=[True, True, False], filename=None) freq = df.get_frequencies() data = dict( frequencies=freq, eps_x=epsx, eps_y=epsy, eps_z=epsz, eps_x0=eps0x, eps_y0=eps0y, eps_z0=eps0z, ) from ase.parallel import world import numpy if world.rank == 0: numpy.savez_compressed(data_file, **data)
def get_hydrogen_chain_dielectric_function(NH, NK): a = Atoms('H', cell=[1, 1, 1], pbc=True) a.center() a = a.repeat((1, 1, NH)) a.calc = GPAW(mode=PW(200), kpts={'size': (1, 1, NK), 'gamma': True}, parallel={'band': 1}, dtype=complex, gpts=(10, 10, 10 * NH)) a.get_potential_energy() a.calc.diagonalize_full_hamiltonian(nbands=2 * NH) a.calc.write('H_chain.gpw', 'all') DF = DielectricFunction('H_chain.gpw', ecut=1e-3, hilbert=False, omega2=np.inf, intraband=False) eps_NLF, eps_LF = DF.get_dielectric_function(direction='z') omega_w = DF.get_frequencies() return omega_w, eps_LF
def get_hydrogen_chain_dielectric_function(NH, NK): a = Atoms('H', cell=[1, 1, 1], pbc=True) a.center() a = a.repeat((1, 1, NH)) a.calc = GPAW(mode=PW(200, force_complex_dtype=True), kpts={'size': (1, 1, NK), 'gamma': True}, parallel={'band': 1}, gpts=(10, 10, 10 * NH)) a.get_potential_energy() a.calc.diagonalize_full_hamiltonian(nbands=2 * NH) a.calc.write('H_chain.gpw', 'all') DF = DielectricFunction('H_chain.gpw', ecut=1e-3, hilbert=False, omega2=np.inf, intraband=False) eps_NLF, eps_LF = DF.get_dielectric_function(direction='z') omega_w = DF.get_frequencies() return omega_w, eps_LF
def dielectric(self, method="rpa"): method = method.lower() if method not in ("rpa", "gw"): raise ValueError("Dielectric Method not known!") if not os.path.exists(self.__es_file): raise FileNotFoundError("Ground state not calculated!") self.__eps_file = self.__eps_file_template.format(method) if os.path.exists(self.__eps_file): parprint(("Dielectricfunction using" " method {} already calculated!").format(method)) return True if os.path.exists(self.__es_file): parprint("Excited state done, will use directly!") if method == "rpa": df = DielectricFunction(calc=self.__es_file, **self.params[method]) epsx0, epsx = df.get_dielectric_function(direction="x", filename=None) epsy0, epsy = df.get_dielectric_function(direction="y", filename=None) epsz0, epsz = df.get_dielectric_function(direction="z", filename=None) freq = df.get_frequencies() data = dict(frequencies=freq, eps_x=epsx, eps_x0=epsx0, eps_y=epsy, eps_y0=epsy0, eps_z=epsz, eps_z0=epsz) # write result if rank == 0: numpy.savez(self.__eps_file, **data) parprint("Dielectric function using {} calculated!".format(method)) return True else: raise NotImplementedError("{} not implemented".format(method))
responseGS.get_potential_energy() responseGS.write('TaS2-gsresponse.gpw', 'all') # 3) Dielectric function df = DielectricFunction('TaS2-gsresponse.gpw', eta=25e-3, domega0=0.01, integrationmode='tetrahedron integration') df1tetra_w, df2tetra_w = df.get_dielectric_function(direction='x') df = DielectricFunction('TaS2-gsresponse.gpw', eta=25e-3, domega0=0.01) df1_w, df2_w = df.get_dielectric_function(direction='x') omega_w = df.get_frequencies() if world.rank == 0: plt.figure(figsize=(6, 6)) plt.plot(omega_w, df2tetra_w.real, label='tetra Re') plt.plot(omega_w, df2tetra_w.imag, label='tetra Im') plt.plot(omega_w, df2_w.real, label='Re') plt.plot(omega_w, df2_w.imag, label='Im') plt.xlabel('Frequency (eV)') plt.ylabel('$\\varepsilon$') plt.xlim(0, 10) plt.ylim(-20, 20) plt.legend() plt.tight_layout() plt.savefig('tas2_eps.png', dpi=600) # plt.show()