def test_log_interp_sparse_coeffs(self): """ Test the computation of interpolation coefficients """ rr,pp = funct_log_mesh(512, 0.01, 200.0) lgi = log_interp_c(rr) rrs = np.linspace(0.05, 250.0, 20000) kr2c_csr,j2r = lgi.coeffs_csr(rrs, rcut=10.0) j2r,j2k,ij2c = lgi.coeffs_rcut(rrs, rcut=10.0) for r,k,cc in zip(j2r[0], j2k, ij2c.T): for i in range(6): self.assertEqual(cc[i], kr2c_csr[k+i,r])
def test_log_interp_sv_call(self): """ Test the interpolation facility for an array arguments from the class log_interp_c """ rr, pp = funct_log_mesh(256, 0.01, 20.0) lgi = log_interp_c(rr) gc = 1.2030 ff = np.array([np.exp(-gc * r**2) for r in rr]) rvecs = np.linspace(0.05, 25.0, 200) r2yy = lgi(ff, rvecs) for ir, r in enumerate(rvecs): yref = np.exp(-gc * r**2) y1 = lgi(ff, r) self.assertAlmostEqual(y1, yref) self.assertAlmostEqual(r2yy[ir], yref)
def test_log_interp_coeffs_vec(self): """ Test the interpolation facility for an array arguments from the class log_interp_c """ rr, pp = funct_log_mesh(1024, 0.01, 20.0) lgi = log_interp_c(rr) rvecs = np.linspace(0.00, 25.0, 20) kk1, cc1 = np.zeros(len(rvecs), dtype=np.int32), np.zeros( (6, len(rvecs))) for i, rv in enumerate(rvecs): kk1[i], cc1[:, i] = lgi.coeffs(rv) kk2, cc2 = lgi.coeffs_vv(rvecs) for k1, c1, k2, c2 in zip(kk1, cc1, kk2, cc2): self.assertEqual(k1, k2) for y1, y2 in zip(c1, c2): self.assertAlmostEqual(y1, y2)
def test_log_interp_vv_speed(self): """ Test the interpolation facility for an array arguments from the class log_interp_c """ rr,pp = funct_log_mesh(1024, 0.01, 200.0) lgi = log_interp_c(rr) gcs = np.array([1.2030, 3.2030, 0.7, 10.0, 5.3]) ff = np.array([[np.exp(-gc*r**2) for r in rr] for gc in gcs]) rr = np.linspace(0.05, 250.0, 2000000) t1 = timer() fr2yy = lgi.interp_rcut(ff, rr, rcut=16.0) t2 = timer() #print(__name__, 't2-t1: ', t2-t1) yyref = np.exp(-(gcs.reshape(gcs.size,1)) * (rr.reshape(1,rr.size)**2)) self.assertTrue(np.allclose(fr2yy, yyref) )
def test_log_interp_vv(self): """ Test the interpolation facility for an array arguments from the class log_interp_c """ rr, pp = funct_log_mesh(256, 0.01, 20.0) lgi = log_interp_c(rr) gcs = np.array([1.2030, 3.2030, 0.7, 10.0]) ff = np.array([[np.exp(-gc * r**2) for r in rr] for gc in gcs]) rvecs = np.linspace(0.05, 25.0, 200) fr2yy = lgi.interp_vv(ff, rvecs) yy_vv1 = np.zeros((len(ff), len(rvecs))) for ir, r in enumerate(rvecs): yyref = np.exp(-gcs * r**2) yy = yy_vv1[:, ir] = lgi.interp_vv(ff, r) for y1, yref, y2 in zip(yy, yyref, fr2yy[:, ir]): self.assertAlmostEqual(y1, yref) self.assertAlmostEqual(y2, yref)
def __init__(self, **kw): from pyscf.nao.log_mesh import funct_log_mesh """ Constructor G0W0 class """ # how to exclude from the input the dtype and xc_code ? scf.__init__(self, **kw) print(__name__, ' dtype ', self.dtype) self.xc_code_scf = copy(self.xc_code) self.niter_max_ev = kw['niter_max_ev'] if 'niter_max_ev' in kw else 15 self.tol_ev = kw['tol_ev'] if 'tol_ev' in kw else 1e-6 self.perform_gw = kw['perform_gw'] if 'perform_gw' in kw else False self.rescf = kw['rescf'] if 'rescf' in kw else False self.bsize = kw['bsize'] if 'bsize' in kw else min(40, self.norbs) self.tdscf = kw['tdscf'] if 'tdscf' in kw else None self.frozen_core = kw['frozen_core'] if 'frozen_core' in kw else None self.write_w = kw['write_w'] if 'write_w' in kw else False self.restart_w = kw['restart_w'] if 'restart_w' in kw else False if sum(self.nelec) == 1: raise RuntimeError('Not implemented H, sorry :-) Look into scf/__init__.py for HF1e class...') if self.nspin==1: self.nocc_0t = nocc_0t = np.array([int((self.nelec+1)/2)]) elif self.nspin==2: self.nocc_0t = nocc_0t = self.nelec else: raise RuntimeError('nspin>2?') if self.verbosity>0: mess = """====> Number of: * occupied states = {}, * states up to fermi level= {}, * nspin = {}, * magnetization = {}""".format(nocc_0t,self.nfermi,self.nspin,self.spin) print(__name__, mess) if 'nocc' in kw: s2nocc = [kw['nocc']] if type(kw['nocc'])==int else kw['nocc'] self.nocc = array([min(i,j) for i,j in zip(s2nocc,nocc_0t)]) else : self.nocc = array([min(6,j) for j in nocc_0t]) if 'nvrt' in kw: s2nvrt = [kw['nvrt']] if type(kw['nvrt'])==int else kw['nvrt'] self.nvrt = array([min(i,j) for i,j in zip(s2nvrt,self.norbs-nocc_0t)]) else : self.nvrt = array([min(6,j) for j in self.norbs-nocc_0t]) if self.verbosity>0: print(__name__,'\t\t====> Number of ocupied states are gonna correct (nocc) = {}, Number of virtual states are gonna correct (nvrt) = {}'.format(self.nocc, self.nvrt)) #self.start_st,self.finish_st = self.nocc_0t-self.nocc, self.nocc_0t+self.nvrt frozen_core = kw['frozen_core'] if 'frozen_core' in kw else self.frozen_core if frozen_core is not None: st_fi = get_str_fin (self, algo=frozen_core, **kw) self.start_st, self.finish_st = st_fi[0], st_fi[1] else: self.start_st = self.nocc_0t-self.nocc self.finish_st = self.nocc_0t+self.nvrt if self.verbosity>0: print(__name__,'\t\t====> Indices of states to be corrected start from {} to {} \n'.format(self.start_st,self.finish_st)) self.nn = [range(self.start_st[s], self.finish_st[s]) for s in range(self.nspin)] # list of states if 'nocc_conv' in kw: s2nocc_conv = [kw['nocc_conv']] if type(kw['nocc_conv'])==int else kw['nocc_conv'] self.nocc_conv = array([min(i,j) for i,j in zip(s2nocc_conv,nocc_0t)]) else : self.nocc_conv = self.nocc if self.verbosity>0: print(__name__, __LINE__()) if 'nvrt_conv' in kw: s2nvrt_conv = [kw['nvrt_conv']] if type(kw['nvrt_conv'])==int else kw['nvrt_conv'] self.nvrt_conv = array([min(i,j) for i,j in zip(s2nvrt_conv,self.norbs-nocc_0t)]) else : self.nvrt_conv = self.nvrt print(__name__, __LINE__()) if self.rescf: self.kernel_scf() # here is rescf with HF functional tacitly assumed print(__name__, __LINE__()) self.nff_ia = kw['nff_ia'] if 'nff_ia' in kw else 32 #number of grid points self.tol_ia = kw['tol_ia'] if 'tol_ia' in kw else 1e-10 (wmin_def,wmax_def,tmin_def,tmax_def) = self.get_wmin_wmax_tmax_ia_def(self.tol_ia) self.wmin_ia = kw['wmin_ia'] if 'wmin_ia' in kw else wmin_def self.wmax_ia = kw['wmax_ia'] if 'wmax_ia' in kw else wmax_def self.tmin_ia = kw['tmin_ia'] if 'tmin_ia' in kw else tmin_def self.tmax_ia = kw['tmax_ia'] if 'tmax_ia' in kw else tmax_def self.tt_ia, self.ww_ia = funct_log_mesh(self.nff_ia, self.tmin_ia, self.tmax_ia, self.wmax_ia) #print('self.tmin_ia, self.tmax_ia, self.wmax_ia') #print(self.tmin_ia, self.tmax_ia, self.wmax_ia) #print(self.ww_ia[0], self.ww_ia[-1]) print(__name__, __LINE__()) self.dw_ia = self.ww_ia*(log(self.ww_ia[-1])-log(self.ww_ia[0]))/(len(self.ww_ia)-1) self.dw_excl = self.ww_ia[0] assert self.cc_da.shape[1]==self.nprod self.kernel_sq = self.hkernel_den #self.v_dab_ds = self.pb.get_dp_vertex_doubly_sparse(axis=2) self.x = require(self.mo_coeff[0,:,:,:,0], dtype=self.dtype, requirements='CW') if self.perform_gw: self.kernel_gw() self.snmw2sf_ncalls = 0 print(__name__, __LINE__())