def test_153_bse_h2b_uks_rpa(self): """ This example is with discrepancies... """ mol = gto.M(verbose=1, atom='B 0 0 0; H 0 0.489 1.074; H 0 0.489 -1.074', basis='cc-pvdz', spin=3) gto_mf = scf.UKS(mol) gto_mf.kernel() gto_td = tddft.dRPA(gto_mf) gto_td.nstates = 190 gto_td.kernel() omegas = np.arange(0.0, 2.0, 0.01) + 1j * 0.03 p_ave = -polariz_freq_osc_strength( gto_td.e, gto_td.oscillator_strength(), omegas).imag data = np.array([omegas.real * HARTREE2EV, p_ave]) np.savetxt('test_0153_bse_h2b_uks_rpa_pyscf.txt', data.T, fmt=['%f', '%f']) data_ref = np.loadtxt('test_0153_bse_h2b_uks_rpa_pyscf.txt-ref').T self.assertTrue(np.allclose(data_ref, data, atol=1e-6, rtol=1e-3)) nao_td = bse_iter(mf=gto_mf, gto=mol, verbosity=0, xc_code='RPA') polariz = -nao_td.comp_polariz_inter_ave(omegas).imag data = np.array([omegas.real * HARTREE2EV, polariz]) np.savetxt('test_0153_bse_h2b_uks_rpa_nao.txt', data.T, fmt=['%f', '%f']) data_ref = np.loadtxt('test_0153_bse_h2b_uks_rpa_nao.txt-ref').T self.assertTrue(np.allclose(data_ref, data, atol=1e-6, rtol=1e-3))
def test_0163_bse_h2o_spin2_uhf_rpa(self): """ This """ mol = gto.M(verbose=1,atom='O 0 0 0; H 0 0.489 1.074; H 0 0.489 -1.074',basis='cc-pvdz',spin=2) gto_mf = scf.UKS(mol) gto_mf.xc = 'hf' gto_mf.kernel() gto_td = tddft.dRPA(gto_mf) gto_td.nstates = 190 gto_td.kernel() omegas = np.arange(0.0, 2.0, 0.01) + 1j*0.03 p_ave = -polariz_freq_osc_strength(gto_td.e, gto_td.oscillator_strength(), omegas).imag data = np.array([omegas.real*HARTREE2EV, p_ave]) np.savetxt('test_0163_bse_h2o_spin2_uhf_rpa_pyscf.txt', data.T, fmt=['%f','%f']) data_ref = np.loadtxt('test_0163_bse_h2o_spin2_uhf_rpa_pyscf.txt-ref').T self.assertTrue(np.allclose(data_ref, data, atol=1e-6, rtol=1e-3)) nao_td = bse_iter(mf=gto_mf, gto=mol, verbosity=0, xc_code='RPA') polariz = -nao_td.comp_polariz_inter_ave(omegas).imag data = np.array([omegas.real*HARTREE2EV, polariz]) np.savetxt('test_0163_bse_h2o_spin2_uhf_rpa_nao.txt', data.T, fmt=['%f','%f']) data_ref = np.loadtxt('test_0163_bse_h2o_spin2_uhf_rpa_nao.txt-ref').T self.assertTrue(np.allclose(data_ref, data, atol=1e-5, rtol=1e-3), \ msg="{}".format(abs(data_ref-data).sum()/data.size))
def test_0146_bse_h2o_rhf_rpa(self): """ Interacting case """ mol = gto.M( verbose=0, atom='O 0 0 0;H 0 0.489 1.074;H 0 0.489 -1.074', basis='cc-pvdz', ) gto_hf = scf.RKS(mol) gto_hf.xc = 'hf' gto_hf.kernel() gto_td = tddft.dRPA(gto_hf) gto_td.nstates = 95 gto_td.kernel() omegas = np.arange(0.0, 2.0, 0.01) + 1j * 0.03 #p_ave = -polariz_inter_ave(gto_hf, mol, gto_td, omegas).imag p_ave = -polariz_freq_osc_strength( gto_td.e, gto_td.oscillator_strength(), omegas).imag data = np.array([omegas.real * HARTREE2EV, p_ave]) np.savetxt('test_0146_bse_h2o_rhf_rpa_pyscf.txt', data.T, fmt=['%f', '%f']) data_ref = np.loadtxt('test_0146_bse_h2o_rhf_rpa_pyscf.txt-ref').T self.assertTrue(np.allclose(data_ref, data, atol=1e-6, rtol=1e-3)) nao_td = bse_iter(mf=gto_hf, gto=mol, verbosity=0, xc_code='RPA') p_iter = -nao_td.comp_polariz_inter_ave(omegas).imag data = np.array([omegas.real * HARTREE2EV, p_iter]) np.savetxt('test_0146_bse_h2o_rhf_rpa_nao.txt', data.T, fmt=['%f', '%f']) data_ref = np.loadtxt('test_0146_bse_h2o_rhf_rpa_nao.txt-ref').T self.assertTrue(np.allclose(data_ref, data, atol=1e-6, rtol=1e-3))
def test_nao_in_tdscf(self): """ Attempt to use algorithms implemented in PySCF for diagonalizing the RPA Hamiltonian """ from pyscf import gto, tddft, scf from pyscf.tdscf.rhf import TDA mol = gto.M( verbose=2, atom='''H 0.0 0.0 -0.3707; H 0.0 0.0 0.3707''', basis='cc-pvdz', ) gto_hf = scf.RKS(mol) gto_hf.xc = 'hf' gto_hf.kernel() nocc = mol.nelectron // 2 nmo = gto_hf.mo_energy.size nvir = nmo - nocc gto_td = tddft.dRPA(gto_hf) gto_td.nstates = min(100, nocc * nvir) gto_td.kernel() gto_gw = GW(gto_hf, gto_td) gto_gw.kernel() ww = np.arange(0.0, 4.0, 0.01) + 1j * 0.02 pxx_xpy = -polariz_inter_xx(gto_hf, mol, gto_td, ww).imag data = np.array([ww.real * 27.2114, pxx_xpy]) fname = dname + '/h2_rpa_xpy_0099.omega.inter.pxx.txt' np.savetxt(fname, data.T, fmt=['%f', '%f']) gw_nao = gw(gto=mol, mf=gto_hf, tdscf=gto_td) gw_nao.chkfile = None
def test_nao_in_gw_pyscf(self): """ This is interacting polarizability with SIESTA starting point """ from pyscf import gto, tddft, scf mol = gto.M( verbose = 0, atom = '''H 0.0 0.0 -0.3707; H 0.0 0.0 0.3707''', basis = 'cc-pvdz',) gto_hf = scf.RKS(mol) gto_hf.xc = 'hf' gto_hf.kernel() nocc = mol.nelectron//2 nmo = gto_hf.mo_energy.size nvir = nmo-nocc gto_td = tddft.dRPA(gto_hf) gto_td.nstates = min(100, nocc*nvir) gto_td.kernel() gto_gw = GW(gto_hf, gto_td) gto_gw.kernel() ww = np.arange(0.0,4.0,0.01)+1j*0.02 pxx_xpy = -polariz_inter_xx(gto_hf, mol, gto_td, ww).imag data = np.array([ww.real*27.2114, pxx_xpy]) fname = dname+'/h2_rpa_xpy_0098.omega.inter.pxx.txt' np.savetxt(fname, data.T, fmt=['%f','%f']) data_ref = np.loadtxt(fname+'-ref') self.assertTrue(np.allclose(data_ref,data.T, rtol=0.1, atol=1e-05)) gw_nao = gw(gto=mol, mf=gto_hf, tdscf=gto_td) x = gw_nao.moms1[:,0] rf_nao = gw_nao.rf( ww ) pxx_nao = np.einsum('p,wpq,q->w', x, -rf_nao.imag, x) data = np.array([ww.real*27.2114, pxx_nao]) fname = dname+'/h2_rpa_nao_0098.omega.inter.pxx.txt' np.savetxt(fname, data.T, fmt=['%f','%f']) data_ref = np.loadtxt(fname+'-ref') self.assertTrue(np.allclose(data_ref,data.T, rtol=0.1, atol=1e-05)) rf_gto = gw_nao.rf_pyscf( ww ) pxx_gto = np.einsum('p,wpq,q->w', x, -rf_gto.imag, x) data = np.array([ww.real*27.2114, pxx_gto]) fname = dname+'/h2_rpa_gto_0098.omega.inter.pxx.txt' np.savetxt(fname, data.T, fmt=['%f','%f']) data_ref = np.loadtxt(fname+'-ref') self.assertTrue(np.allclose(data_ref,data.T, rtol=0.1, atol=1e-05))
def test_qchem_irf(self): """ Test """ gto_hf = dft.RKS(mol) gto_hf.kernel() nocc = mol.nelectron//2 nmo = gto_hf.mo_energy.size nvir = nmo-nocc gto_td = tddft.dRPA(gto_hf) gto_td.nstates = min(100, nocc*nvir) gto_td.kernel() gto_gw = GW(gto_hf, gto_td) gto_gw.kernel() nao_td = tddft_iter(mf=gto_hf, gto=mol, xc_code='RPA') eps = 0.02 omegas = np.arange(0.0,2.0,eps/2.0)+1j*eps p_iter = -nao_td.comp_polariz_inter_ave(omegas).imag data = np.array([omegas.real*27.2114, p_iter]) np.savetxt('NH.tddft_iter_rpa.omega.inter.pav.txt', data.T, fmt=['%f','%f']) np.set_printoptions(linewidth=180)
def test_qchem_irf(self): """ Test """ gto_hf = dft.RKS(mol) gto_hf.kernel() nocc = mol.nelectron // 2 nmo = gto_hf.mo_energy.size nvir = nmo - nocc gto_td = tddft.dRPA(gto_hf) gto_td.nstates = min(100, nocc * nvir) gto_td.kernel() gto_gw = GW(gto_hf, gto_td) gto_gw.kernel() nao_td = tddft_iter(mf=gto_hf, gto=mol, xc_code='RPA') eps = 0.02 omegas = np.arange(0.0, 2.0, eps / 2.0) + 1j * eps p_iter = -nao_td.comp_polariz_inter_ave(omegas).imag data = np.array([omegas.real * 27.2114, p_iter]) np.savetxt('NH.tddft_iter_rpa.omega.inter.pav.txt', data.T, fmt=['%f', '%f']) np.set_printoptions(linewidth=180)
mol = gto.Mole() mol.verbose = 5 mol.atom = [[8, (0., 0., 0.)], [1, (0., -0.757, 0.587)], [1, (0., 0.757, 0.587)]] mol.basis = 'cc-pvdz' mol.build() mf = dft.RKS(mol) mf.xc = 'hf' mf.kernel() nocc = mol.nelectron // 2 nmo = mf.mo_energy.size nvir = nmo - nocc td = tddft.dRPA(mf) td.nstates = min(100, nocc * nvir) td.kernel() gw = GW(mf, td) gw.kernel() print(gw.mo_energy) # [-20.10555946 -1.2264067 -0.68160939 -0.53066326 -0.44679868 # 0.17291986 0.24457082 0.74758227 0.80045129 1.11748735 # 1.1508353 1.19081928 1.40406947 1.43593681 1.63324734 # 1.81839838 1.86943727 2.37827782 2.48829939 3.26028229 # 3.3247595 3.4958492 3.77735135 4.14572189] gw.linearized = True gw.kernel(orbs=[nocc - 1, nocc]) print(gw.mo_energy[nocc - 1] - -0.44684106)
mol.atom = [ [8 , (0. , 0. , 0.)], [1 , (0. , -0.757 , 0.587)], [1 , (0. , 0.757 , 0.587)]] mol.basis = 'cc-pvdz' mol.build() mf = dft.RKS(mol) mf.xc = 'hf' mf.kernel() nocc = mol.nelectron//2 nmo = mf.mo_energy.size nvir = nmo-nocc td = tddft.dRPA(mf) td.nstates = min(100, nocc*nvir) td.kernel() gw = GW(mf, td) gw.kernel() print(gw.mo_energy) # [-20.10555946 -1.2264067 -0.68160939 -0.53066326 -0.44679868 # 0.17291986 0.24457082 0.74758227 0.80045129 1.11748735 # 1.1508353 1.19081928 1.40406947 1.43593681 1.63324734 # 1.81839838 1.86943727 2.37827782 2.48829939 3.26028229 # 3.3247595 3.4958492 3.77735135 4.14572189] gw.linearized = True gw.kernel(orbs=[nocc-1,nocc]) print(gw.mo_energy[nocc-1] - -0.44684106)
mol.basis = 'aug-cc-pvtz' mol.build() def diagonalize(a, b): nocc, nvir = a.shape[:2] aa = a.reshape(nocc * nvir, nocc * nvir) bb = b.reshape(nocc * nvir, nocc * nvir) e = numpy.linalg.eig(numpy.bmat([[aa, bb], [-bb.conj(), -aa.conj()]]))[0] e = numpy.sort(e[e > 0]) return e nroots = 5 mf = dft.RKS(mol) mf.xc = 'pbe,pbe' mf.kernel() a, b = tddft.dRPA(mf).get_ab() e = diagonalize(a, b) print('dTD:', e[:nroots]) nocc, nvir = a.shape[:2] a = a.reshape(nocc * nvir, nocc * nvir) etda = numpy.linalg.eig(a)[0] etda = numpy.sort(etda) print('dTDA:', etda[:nroots]) e_corr = 0.5 * sum(e - etda) print('dRPA correlation energy', e_corr)