def test_j_kpts(self): numpy.random.seed(1) nao = cell.nao_nr() dm = numpy.random.random((4,nao,nao)) dm = dm + dm.transpose(0,2,1) mydf = df.DF(cell) mydf.kpts = numpy.random.random((4,3)) mydf.gs = numpy.asarray((5,)*3) mydf.auxbasis = 'weigend' vj = df_jk.get_j_kpts(mydf, dm, 1, mydf.kpts) self.assertAlmostEqual(finger(vj[0]), (0.49176565003742523-0.11891097171204273j ), 9) self.assertAlmostEqual(finger(vj[1]), (0.54901219181783034-0.046003618294160657j), 9) self.assertAlmostEqual(finger(vj[2]), (0.53648483057543039-0.083507647862465353j), 9) self.assertAlmostEqual(finger(vj[3]), (0.54896892736198399+0.007695802002441080j), 9)
def test_k_kpts_1(self): cell = pgto.Cell() cell.atom = 'He 1. .5 .5; He .1 1.3 2.1' cell.basis = {'He': [(0, (2.5, 1)), (0, (1., 1))]} cell.a = numpy.eye(3) * 2.5 cell.mesh = [11] * 3 cell.build() kpts = cell.get_abs_kpts([[-.25, -.25, -.25], [-.25, -.25, .25], [-.25, .25, -.25], [-.25, .25, .25], [.25, -.25, -.25], [.25, -.25, .25], [.25, .25, -.25], [.25, .25, .25]]) numpy.random.seed(1) nao = cell.nao_nr() dm = numpy.random.random((8, nao, nao)) mydf = df.DF(cell).set(auxbasis='weigend') mydf.linear_dep_threshold = 1e-7 mydf.kpts = kpts mydf.auxbasis = { 'He': [(0, (4.096, 1)), (0, (2.56, 1)), (0, (1.6, 1)), (0, (1., 1))] } mydf.exxdiv = None mydf.mesh = cell.mesh mydf.eta = 0.3 mydf.exp_to_discard = mydf.eta vk = df_jk.get_k_kpts(mydf, dm, 0, mydf.kpts) self.assertAlmostEqual(finger(vk[0]), (0.54220010040518218 - 0.00787204295681934j), 9) self.assertAlmostEqual(finger(vk[1]), (0.35987105007103914 + 0.0036047438452865574j), 9) self.assertAlmostEqual(finger(vk[2]), (0.46287057223452965 - 0.0065045318150024475j), 9) self.assertAlmostEqual(finger(vk[3]), (0.63677390788341914 + 0.0075132081533213447j), 9) self.assertAlmostEqual(finger(vk[4]), (0.53680188658523353 - 0.0076414750780774933j), 9) self.assertAlmostEqual(finger(vk[5]), (0.49613855046499666 + 0.0060603767383680838j), 9) self.assertAlmostEqual(finger(vk[6]), (0.45430752211150049 - 0.0068611602260866128j), 9) self.assertAlmostEqual(finger(vk[7]), (0.41856931218763038 + 0.0051073315205987522j), 9)
def test_jk_hermi0(self): numpy.random.seed(12) nao = cell.nao_nr() dm = numpy.random.random((nao, nao)) dm = dm + dm.T dm[:2, -3:] *= .5 jkdf = df.DF(cell) jkdf.auxbasis = 'weigend' jkdf.gs = (5, ) * 3 vj0, vk0 = jkdf.get_jk(dm, hermi=0, exxdiv=None) ej0 = numpy.einsum('ij,ji->', vj0, dm) ek0 = numpy.einsum('ij,ji->', vk0, dm) self.assertAlmostEqual(ej0, 242.041485393541, 8) self.assertAlmostEqual(ek0, 280.58441670694083, 8)
def test_jk_hermi0(self): numpy.random.seed(12) nao = cell.nao_nr() dm = numpy.random.random((nao, nao)) dm = dm + dm.T dm[:2, -3:] *= .5 jkdf = df.DF(cell).set(auxbasis='weigend') jkdf.gs = (5, ) * 3 jkdf.eta = 0.3 vj0, vk0 = jkdf.get_jk(dm, hermi=0, exxdiv=None) ej0 = numpy.einsum('ij,ji->', vj0, dm) ek0 = numpy.einsum('ij,ji->', vk0, dm) self.assertAlmostEqual(ej0, 242.04151204237999, 8) self.assertAlmostEqual(ek0, 280.58443171612089, 8)
def test_k_kpts_1(self): cell = pgto.Cell() cell.atom = 'He 1. .5 .5; He .1 1.3 2.1' cell.basis = {'He': [(0, (2.5, 1)), (0, (1., 1))]} cell.a = numpy.eye(3) * 2.5 cell.gs = [5] * 3 cell.build() kpts = cell.get_abs_kpts([[-.25, -.25, -.25], [-.25, -.25, .25], [-.25, .25, -.25], [-.25, .25, .25], [.25, -.25, -.25], [.25, -.25, .25], [.25, .25, -.25], [.25, .25, .25]]) numpy.random.seed(1) nao = cell.nao_nr() dm = numpy.random.random((8, nao, nao)) mydf = df.DF(cell).set(auxbasis='weigend') mydf.kpts = kpts mydf.auxbasis = { 'He': [(0, (4.096, 1)), (0, (2.56, 1)), (0, (1.6, 1)), (0, (1., 1))] } mydf.exxdiv = None mydf.gs = cell.gs mydf.eta = 0.3 vk = df_jk.get_k_kpts(mydf, dm, 0, mydf.kpts) self.assertAlmostEqual(finger(vk[0]), (0.54220010040518085 - 0.0078720429568215483j), 9) self.assertAlmostEqual(finger(vk[1]), (0.35987105007103337 + 0.0036047438452914572j), 9) self.assertAlmostEqual(finger(vk[2]), (0.46287057223452033 - 0.0065045318150074175j), 9) self.assertAlmostEqual(finger(vk[3]), (0.63677390788341892 + 0.007513208153323357j), 9) self.assertAlmostEqual(finger(vk[4]), (0.53680188658523043 - 0.0076414750780819194j), 9) self.assertAlmostEqual(finger(vk[5]), (0.49613855046498667 + 0.006060376738372739j), 9) self.assertAlmostEqual(finger(vk[6]), (0.45430752211148873 - 0.0068611602260907067j), 9) self.assertAlmostEqual(finger(vk[7]), (0.41856931218761884 + 0.0051073315206036857j), 9)
def test_k_kpts(self): numpy.random.seed(1) nao = cell.nao_nr() dm = numpy.random.random((4,nao,nao)) dm = dm + dm.transpose(0,2,1) mydf = df.DF(cell) mydf.kpts = numpy.random.random((4,3)) mydf.gs = numpy.asarray((5,)*3) mydf.exxdiv = None mydf.auxbasis = 'weigend' vk = df_jk.get_k_kpts(mydf, dm, 0, mydf.kpts) self.assertAlmostEqual(finger(vk[0]), (-2.8332405542539822 -1.0578703659011341j ), 9) self.assertAlmostEqual(finger(vk[1]), (-7.4404337144963018 +0.10233793208112751j), 9) self.assertAlmostEqual(finger(vk[2]), (-2.5718873173309404 -1.4487392786249131j ), 9) self.assertAlmostEqual(finger(vk[3]), (-0.79223061014449159+0.01169464922520067j), 9)
def test_eri1111(self): kpts = numpy.random.random((4, 3)) * .25 kpts[3] = -numpy.einsum('ij->j', kpts[:3]) with_df = df.DF(cell).set(auxbasis='weigend') with_df.kpts = kpts mo = (numpy.random.random((nao, nao)) + numpy.random.random( (nao, nao)) * 1j) eri = with_df.get_eri(kpts).reshape((nao, ) * 4) eri0 = numpy.einsum('pjkl,pi->ijkl', eri, mo.conj()) eri0 = numpy.einsum('ipkl,pj->ijkl', eri0, mo) eri0 = numpy.einsum('ijpl,pk->ijkl', eri0, mo.conj()) eri0 = numpy.einsum('ijkp,pl->ijkl', eri0, mo) eri1 = with_df.ao2mo(mo, kpts) self.assertAlmostEqual( abs(eri1.reshape(eri0.shape) - eri0).sum(), 0, 9)
def test_jk_hermi0_high_cost(self): numpy.random.seed(12) nao = cell.nao_nr() dm = numpy.random.random((nao,nao)) dm = dm + dm.T dm[:2,-3:] *= .5 jkdf = df.DF(cell).set(auxbasis='weigend') jkdf.linear_dep_threshold = 1e-7 jkdf.mesh = (11,)*3 jkdf.eta = 0.3 jkdf.exp_to_discard = jkdf.eta vj0, vk0 = jkdf.get_jk(dm, hermi=0, exxdiv=None) ej0 = numpy.einsum('ij,ji->', vj0, dm) ek0 = numpy.einsum('ij,ji->', vk0, dm) self.assertAlmostEqual(ej0, 242.04151204237999, 8) self.assertAlmostEqual(ek0, 280.58443171612089, 8)
def test_jk_hermi0(self): numpy.random.seed(12) nao = cell0.nao_nr() dm = numpy.random.random((nao,nao)) dm = dm + dm.T dm[:2,-3:] *= .5 jkdf = df.DF(cell0).set(auxbasis='weigend') jkdf.linear_dep_threshold = 1e-7 jkdf.mesh = (11,)*3 jkdf.eta = 0.3 jkdf.exp_to_discard = jkdf.eta vj0, vk0 = jkdf.get_jk(dm, hermi=0, exxdiv=None) ej0 = numpy.einsum('ij,ji->', vj0, dm) ek0 = numpy.einsum('ij,ji->', vk0, dm) self.assertAlmostEqual(ej0, 25.775008146164968, 8) self.assertAlmostEqual(ek0, 30.814023529860112, 8)
def test_j_kpts(self): numpy.random.seed(1) nao = cell.nao_nr() dm = numpy.random.random((4,nao,nao)) dm = dm + dm.transpose(0,2,1) mydf = df.DF(cell).set(auxbasis='weigend') mydf.kpts = numpy.random.random((4,3)) mydf.mesh = numpy.asarray((11,)*3) mydf.auxbasis = 'weigend' mydf.mesh = cell.mesh mydf.eta = 0.3 vj = df_jk.get_j_kpts(mydf, dm, 1, mydf.kpts) self.assertAlmostEqual(finger(vj[0]), (0.49176180692009197-0.11891083594538684j ), 9) self.assertAlmostEqual(finger(vj[1]), (0.54900852073326378-0.04600354345316908j ), 9) self.assertAlmostEqual(finger(vj[2]), (0.53648110926681891-0.083507522327029265j), 9) self.assertAlmostEqual(finger(vj[3]), (0.5489650266265671 +0.007695733246577244j), 9)
def test_eri0101(self): kpts = numpy.random.random((4, 3)) * .25 kpts[2] = kpts[0] kpts[3] = kpts[1] with_df = df.DF(cell) with_df.kpts = kpts mo = (numpy.random.random((nao, nao)) + numpy.random.random( (nao, nao)) * 1j) eri = with_df.get_eri(kpts).reshape((nao, ) * 4) eri0 = numpy.einsum('pjkl,pi->ijkl', eri, mo.conj()) eri0 = numpy.einsum('ipkl,pj->ijkl', eri0, mo) eri0 = numpy.einsum('ijpl,pk->ijkl', eri0, mo.conj()) eri0 = numpy.einsum('ijkp,pl->ijkl', eri0, mo).reshape(nao**2, -1) eri1 = with_df.ao2mo(mo, kpts) self.assertAlmostEqual( abs(eri1.reshape(eri0.shape) - eri0).sum(), 0, 9)
def test_j_kpts_high_cost(self): numpy.random.seed(1) nao = cell0.nao_nr() dm = numpy.random.random((4,nao,nao)) dm = dm + dm.transpose(0,2,1) mydf = df.DF(cell0).set(auxbasis='weigend') mydf.linear_dep_threshold = 1e-7 mydf.kpts = numpy.random.random((4,3)) mydf.auxbasis = 'weigend' mydf.eta = 0.3 mydf.exp_to_discard = mydf.eta vj = df_jk.get_j_kpts(mydf, dm, 1, mydf.kpts) self.assertAlmostEqual(lib.fp(vj[0]), (7.240207870630442-0.001010622364950332j) , 9) self.assertAlmostEqual(lib.fp(vj[1]), (7.248745538469966-0.001562604522803734j) , 9) self.assertAlmostEqual(lib.fp(vj[2]), (7.241193241602369-0.002518439407055759j) , 9) self.assertAlmostEqual(lib.fp(vj[3]), (7.2403591406956185+0.001475803952777666j), 9)
def test_k_kpts_2(self): cell = pgto.Cell() cell.atom = 'He 1. .5 .5; He .1 1.3 2.1' cell.basis = {'He': [(0, (2.5, 1)), (0, (1., 1))]} cell.a = numpy.eye(3) * 2.5 cell.mesh = [11] * 3 cell.build() kpts = cell.get_abs_kpts([[-.25, -.25, -.25], [-.25, -.25, .25], [-.25, .25, -.25], [-.25, .25, .25], [.25, -.25, -.25], [.25, -.25, .25], [.25, .25, -.25], [.25, .25, .25]]) mydf = df.DF(cell).set(auxbasis='weigend') mydf.linear_dep_threshold = 1e-7 mydf.kpts = kpts mydf.auxbasis = { 'He': [(0, (4.096, 1)), (0, (2.56, 1)), (0, (1.6, 1)), (0, (1., 1))] } mydf.exxdiv = None mydf.mesh = cell.mesh mydf.eta = 0.3 mydf.exp_to_discard = mydf.eta nao = cell.nao_nr() numpy.random.seed(1) dm = numpy.random.random((8, nao, nao)) dm = dm + dm.transpose(0, 2, 1) vk = df.df_jk.get_k_kpts(mydf, dm, 1, mydf.kpts) self.assertAlmostEqual(finger(vk[0]), (1.0940331326660724 - 0.01474246983191657j), 9) self.assertAlmostEqual(finger(vk[1]), (0.72106828546205248 + 0.008683360062569572j), 9) self.assertAlmostEqual(finger(vk[2]), (0.89868267009698988 - 0.011091489111877838j), 9) self.assertAlmostEqual(finger(vk[3]), (1.2604941401190835 + 0.015979544115384041j), 9) self.assertAlmostEqual(finger(vk[4]), (1.0492129520812594 - 0.012424653667344821j), 9) self.assertAlmostEqual(finger(vk[5]), (0.99271107721956797 + 0.012696925711370165j), 9) self.assertAlmostEqual(finger(vk[6]), (0.92184754518871648 - 0.012035727588110348j), 9) self.assertAlmostEqual(finger(vk[7]), (0.8518483148628242 + 0.010084767506077213j), 9)
def test_k_kpts_1(self): cell = pgto.Cell() cell.atom = 'He 1. .5 .5; He .1 1.3 2.1' cell.basis = {'He': [(0, (2.5, 1)), (0, (1., 1))]} cell.a = numpy.eye(3) * 2.5 cell.gs = [5] * 3 cell.build() kpts = cell.get_abs_kpts([[-.25, -.25, -.25], [-.25, -.25, .25], [-.25, .25, -.25], [-.25, .25, .25], [.25, -.25, -.25], [.25, -.25, .25], [.25, .25, -.25], [.25, .25, .25]]) numpy.random.seed(1) nao = cell.nao_nr() dm = numpy.random.random((8, nao, nao)) mydf = df.DF(cell) mydf.kpts = kpts mydf.auxbasis = { 'He': [(0, (4.096, 1)), (0, (2.56, 1)), (0, (1.6, 1)), (0, (1., 1))] } mydf.exxdiv = None vk = df_jk.get_k_kpts(mydf, dm, 0, mydf.kpts) self.assertAlmostEqual(finger(vk[0]), (0.5420051395935308 - 0.0078629895406937093j), 9) self.assertAlmostEqual(finger(vk[1]), (0.35967745300781129 + 0.0036013741011200534j), 9) self.assertAlmostEqual(finger(vk[2]), (0.46267875636311051 - 0.0064934210041723787j), 9) self.assertAlmostEqual(finger(vk[3]), (0.63657133813146305 + 0.0075058298866949071j), 9) self.assertAlmostEqual(finger(vk[4]), (0.53658686350689644 - 0.0076348273858712692j), 9) self.assertAlmostEqual(finger(vk[5]), (0.49596594079072709 + 0.0060524166304689085j), 9) self.assertAlmostEqual(finger(vk[6]), (0.45414482973739956 - 0.0068539768439524994j), 9) self.assertAlmostEqual(finger(vk[7]), (0.41836048318983377 + 0.0051095605455669692j), 9)
def test_k_kpts(self): numpy.random.seed(1) nao = cell.nao_nr() dm = numpy.random.random((4,nao,nao)) dm = dm + dm.transpose(0,2,1) mydf = df.DF(cell).set(auxbasis='weigend') mydf.kpts = numpy.random.random((4,3)) mydf.mesh = numpy.asarray((11,)*3) mydf.exxdiv = None mydf.mesh = cell.mesh mydf.eta = 0.3 mydf.auxbasis = 'weigend' vk = df_jk.get_k_kpts(mydf, dm, 0, mydf.kpts) self.assertAlmostEqual(finger(vk[0]), (-2.8332400193836929 -1.0578696472684668j ), 9) self.assertAlmostEqual(finger(vk[1]), (-7.440432864374058 +0.10233777556396761j ), 9) self.assertAlmostEqual(finger(vk[2]), (-2.5718862399533897 -1.4487403259747005j ), 9) self.assertAlmostEqual(finger(vk[3]), (-0.79223093737594863+0.011694427945090839j), 9)
def test_1d(self): cell.dimension = 1 kpts = numpy.random.random((4, 3)) * .25 kpts[3] = -numpy.einsum('ij->j', kpts[:3]) with_df = df.DF(cell) with_df.kpts = kpts with_df.gs = [5] * 3 mo = (numpy.random.random((nao, nao)) + numpy.random.random( (nao, nao)) * 1j) eri = with_df.get_eri(kpts).reshape((nao, ) * 4) eri0 = numpy.einsum('pjkl,pi->ijkl', eri, mo.conj()) eri0 = numpy.einsum('ipkl,pj->ijkl', eri0, mo) eri0 = numpy.einsum('ijpl,pk->ijkl', eri0, mo.conj()) eri0 = numpy.einsum('ijkp,pl->ijkl', eri0, mo) eri1 = with_df.ao2mo(mo, kpts) self.assertAlmostEqual( abs(eri1.reshape(eri0.shape) - eri0).sum(), 0, 9)
def test_k_kpts_high_cost(self): numpy.random.seed(1) nao = cell0.nao_nr() dm = numpy.random.random((4,nao,nao)) dm = dm + dm.transpose(0,2,1) mydf = df.DF(cell0).set(auxbasis='weigend') mydf.linear_dep_threshold = 1e-7 mydf.kpts = numpy.random.random((4,3)) mydf.exxdiv = None mydf.eta = 0.3 mydf.exp_to_discard = mydf.eta mydf.auxbasis = 'weigend' vk = df_jk.get_k_kpts(mydf, dm, 0, mydf.kpts) self.assertAlmostEqual(lib.fp(vk[0]), (4.831027586092549-0.12376435978940196j) , 9) self.assertAlmostEqual(lib.fp(vk[1]), (4.783208264204395-0.00585421470169705j) , 9) self.assertAlmostEqual(lib.fp(vk[2]), (4.823839360632854+0.002511545727704362j), 9) self.assertAlmostEqual(lib.fp(vk[3]), (4.833891390413435+0.0208696082684768j) , 9)
def test_k_kpts_2(self): cell = pgto.Cell() cell.atom = 'He 1. .5 .5; He .1 1.3 2.1' cell.basis = {'He': [(0, (2.5, 1)), (0, (1., 1))]} cell.a = numpy.eye(3) * 2.5 cell.gs = [5] * 3 cell.build() kpts = cell.get_abs_kpts([[-.25, -.25, -.25], [-.25, -.25, .25], [-.25, .25, -.25], [-.25, .25, .25], [.25, -.25, -.25], [.25, -.25, .25], [.25, .25, -.25], [.25, .25, .25]]) mydf = df.DF(cell).set(auxbasis='weigend') mydf.kpts = kpts mydf.auxbasis = { 'He': [(0, (4.096, 1)), (0, (2.56, 1)), (0, (1.6, 1)), (0, (1., 1))] } mydf.exxdiv = None mydf.gs = cell.gs mydf.eta = 0.3 nao = cell.nao_nr() numpy.random.seed(1) dm = numpy.random.random((8, nao, nao)) dm = dm + dm.transpose(0, 2, 1) vk = df.df_jk.get_k_kpts(mydf, dm, 1, mydf.kpts) self.assertAlmostEqual(finger(vk[0]), (1.0940331326660706 - 0.014742469831921495j), 9) self.assertAlmostEqual(finger(vk[1]), (0.72106828546203339 + 0.008683360062579130j), 9) self.assertAlmostEqual(finger(vk[2]), (0.89868267009697655 - 0.011091489111887209j), 9) self.assertAlmostEqual(finger(vk[3]), (1.2604941401190817 + 0.015979544115388003j), 9) self.assertAlmostEqual(finger(vk[4]), (1.0492129520812483 - 0.012424653667353895j), 9) self.assertAlmostEqual(finger(vk[5]), (0.99271107721955065 + 0.012696925711379314j), 9) self.assertAlmostEqual(finger(vk[6]), (0.92184754518869783 - 0.012035727588119237j), 9) self.assertAlmostEqual(finger(vk[7]), (0.851848314862798 + 0.010084767506087691j), 9)
def test_2d(self): kpts = numpy.random.random((4, 3)) * .25 kpts[3] = -numpy.einsum('ij->j', kpts[:3]) with_df = df.DF(cell).set(auxbasis='weigend') with_df.linear_dep_threshold = 1e-7 with_df.kpts = kpts mo = (numpy.random.random((nao, nao)) + numpy.random.random( (nao, nao)) * 1j) with lib.temporary_env(cell, dimension=2): eri = with_df.get_eri(kpts).reshape((nao, ) * 4) eri0 = numpy.einsum('pjkl,pi->ijkl', eri, mo.conj()) eri0 = numpy.einsum('ipkl,pj->ijkl', eri0, mo) eri0 = numpy.einsum('ijpl,pk->ijkl', eri0, mo.conj()) eri0 = numpy.einsum('ijkp,pl->ijkl', eri0, mo) with lib.temporary_env(cell, dimension=2): eri1 = with_df.ao2mo(mo, kpts) self.assertAlmostEqual( abs(eri1.reshape(eri0.shape) - eri0).sum(), 0, 9)
def test_k_kpts_2(self): cell = pgto.Cell() cell.atom = 'He 1. .5 .5; He .1 1.3 2.1' cell.basis = {'He': [(0, (2.5, 1)), (0, (1., 1))]} cell.a = numpy.eye(3) * 2.5 cell.gs = [5] * 3 cell.build() kpts = cell.get_abs_kpts([[-.25, -.25, -.25], [-.25, -.25, .25], [-.25, .25, -.25], [-.25, .25, .25], [.25, -.25, -.25], [.25, -.25, .25], [.25, .25, -.25], [.25, .25, .25]]) mydf = df.DF(cell) mydf.kpts = kpts mydf.auxbasis = { 'He': [(0, (4.096, 1)), (0, (2.56, 1)), (0, (1.6, 1)), (0, (1., 1))] } mydf.exxdiv = None nao = cell.nao_nr() numpy.random.seed(1) dm = numpy.random.random((8, nao, nao)) dm = dm + dm.transpose(0, 2, 1) vk = df.df_jk.get_k_kpts(mydf, dm, 1, mydf.kpts) self.assertAlmostEqual(finger(vk[0]), (1.0936431020073591 - 0.014722943557931367j), 9) self.assertAlmostEqual(finger(vk[1]), (0.72071018138503629 + 0.008672611686305542j), 9) self.assertAlmostEqual(finger(vk[2]), (0.89832293233163618 - 0.011069550356504438j), 9) self.assertAlmostEqual(finger(vk[3]), (1.2601082118723275 + 0.015960560764962047j), 9) self.assertAlmostEqual(finger(vk[4]), (1.0488000478468562 - 0.012410766448146473j), 9) self.assertAlmostEqual(finger(vk[5]), (0.99237174968627428 + 0.012676287846870899j), 9) self.assertAlmostEqual(finger(vk[6]), (0.92151251108591792 - 0.012017833726331088j), 9) self.assertAlmostEqual(finger(vk[7]), (0.85142552451225129 + 0.010081726860909411j), 9)
def test_k_kpts_1(self): cell = pgto.Cell() cell.atom = 'He 1. .5 .5; He .1 1.3 2.1' cell.basis = {'He': [(0, (2.5, 1)), (0, (1., 1))]} cell.a = numpy.eye(3) * 2.5 cell.gs = [5] * 3 cell.build() kpts = cell.get_abs_kpts([[-.25, -.25, -.25], [-.25, -.25, .25], [-.25, .25, -.25], [-.25, .25, .25], [.25, -.25, -.25], [.25, -.25, .25], [.25, .25, -.25], [.25, .25, .25]]) numpy.random.seed(1) nao = cell.nao_nr() dm = numpy.random.random((8, nao, nao)) mydf = df.DF(cell) mydf.kpts = kpts mydf.auxbasis = 'weigend' mydf.exxdiv = None vk = df_jk.get_k_kpts(mydf, dm, 0, mydf.kpts) self.assertAlmostEqual(finger(vk[0]), (0.54015197313324537 - 0.0079752072085274676j), 9) self.assertAlmostEqual(finger(vk[1]), (0.3582520398839657 + 0.0036801628264896014j), 9) self.assertAlmostEqual(finger(vk[2]), (0.46108289884408604 - 0.0066080922040621061j), 9) self.assertAlmostEqual(finger(vk[3]), (0.63466063181822774 + 0.0075857948337662746j), 9) self.assertAlmostEqual(finger(vk[4]), (0.53482612780118588 - 0.0077463092279198443j), 9) self.assertAlmostEqual(finger(vk[5]), (0.49433633153410605 + 0.0061326611410119211j), 9) self.assertAlmostEqual(finger(vk[6]), (0.45244565342177845 - 0.0069645425083198157j), 9) self.assertAlmostEqual(finger(vk[7]), (0.41675926649079686 + 0.0051848485986134649j), 9)
def test_jk_single_kpt_high_cost(self): mf0 = pscf.RHF(cell) mf0.exxdiv = None mf = df_jk.density_fit(mf0, auxbasis='weigend', mesh=(11,)*3) mf.with_df.mesh = cell.mesh mf.with_df.eta = 0.3 mf.with_df.exp_to_discard = 0.3 dm = mf.get_init_guess() vj, vk = mf.get_jk(cell, dm) ej1 = numpy.einsum('ij,ji->', vj, dm) ek1 = numpy.einsum('ij,ji->', vk, dm) j_ref = 48.283789539266174 # rsjk result k_ref = 32.30441176447805 # rsjk result self.assertAlmostEqual(ej1, j_ref, 4) self.assertAlmostEqual(ek1, k_ref, 2) self.assertAlmostEqual(ej1, 48.283745538383684, 8) self.assertAlmostEqual(ek1, 32.30260871417842 , 8) numpy.random.seed(12) nao = cell.nao_nr() dm = numpy.random.random((nao,nao)) dm = dm + dm.T vj1, vk1 = mf.get_jk(cell, dm, hermi=0) ej1 = numpy.einsum('ij,ji->', vj1, dm) ek1 = numpy.einsum('ij,ji->', vk1, dm) self.assertAlmostEqual(ej1, 242.04678235140264, 8) self.assertAlmostEqual(ek1, 280.15934926575903, 8) numpy.random.seed(1) kpt = numpy.random.random(3) mydf = df.DF(cell, [kpt]).set(auxbasis='weigend') mydf.linear_dep_threshold = 1e-7 mydf.mesh = cell.mesh mydf.eta = 0.3 mydf.exp_to_discard = mydf.eta vj, vk = mydf.get_jk(dm, 1, kpt, exxdiv=None) ej1 = numpy.einsum('ij,ji->', vj, dm) ek1 = numpy.einsum('ij,ji->', vk, dm) self.assertAlmostEqual(ej1, 241.15121903857556+0j, 8) self.assertAlmostEqual(ek1, 279.64649194057051+0j, 8) vj, vk = mydf.get_jk(dm, 1, kpt, with_j=False, exxdiv='ewald') ek1 = numpy.einsum('ij,ji->', vk, dm) self.assertAlmostEqual(ek1, 691.64624456329909+0j, 6)
def test_k_kpts(self): numpy.random.seed(1) nao = cell.nao_nr() dm = numpy.random.random((4, nao, nao)) dm = dm + dm.transpose(0, 2, 1) mydf = df.DF(cell) mydf.kpts = numpy.random.random((4, 3)) mydf.gs = numpy.asarray((5, ) * 3) mydf.exxdiv = None mydf.auxbasis = 'weigend' vk = df_jk.get_k_kpts(mydf, dm, 0, mydf.kpts) self.assertAlmostEqual(finger(vk[0]), (-2.8332383229536533 - 1.0578698917131759j), 9) self.assertAlmostEqual(finger(vk[1]), (-7.4404344284098975 + 0.10233829896587976j), 9) self.assertAlmostEqual(finger(vk[2]), (-2.5718877141164285 - 1.4487388139184783j), 9) self.assertAlmostEqual(finger(vk[3]), (-0.79223064808014754 + 0.01169455042040998j), 9)
def test_k_kpts(self): numpy.random.seed(1) nao = cell.nao_nr() dm = numpy.random.random((4, nao, nao)) dm = dm + dm.transpose(0, 2, 1) mydf = df.DF(cell) mydf.kpts = numpy.random.random((4, 3)) mydf.gs = numpy.asarray((5, ) * 3) mydf.exxdiv = None mydf.auxbasis = 'weigend' vk = df_jk.get_k_kpts(mydf, dm, 0, mydf.kpts) self.assertAlmostEqual(finger(vk[0]), (-2.8338631448322422 - 1.0571235846726912j), 9) self.assertAlmostEqual(finger(vk[1]), (-7.4393097135258062 + 0.10265042873875296j), 9) self.assertAlmostEqual(finger(vk[2]), (-2.5706492707654505 - 1.4482274480570361j), 9) self.assertAlmostEqual(finger(vk[3]), (-0.78973046762474153 + 0.01154399375447295j), 9)
def test_k_kpts_2(self): cell = pgto.Cell() cell.atom = 'He 1. .5 .5; He .1 1.3 2.1' cell.basis = {'He': [(0, (2.5, 1)), (0, (1., 1))]} cell.a = numpy.eye(3) * 2.5 cell.gs = [5] * 3 cell.build() kpts = cell.get_abs_kpts([[-.25, -.25, -.25], [-.25, -.25, .25], [-.25, .25, -.25], [-.25, .25, .25], [.25, -.25, -.25], [.25, -.25, .25], [.25, .25, -.25], [.25, .25, .25]]) mydf = df.DF(cell) mydf.kpts = kpts mydf.auxbasis = 'weigend' mydf.exxdiv = None nao = cell.nao_nr() numpy.random.seed(1) dm = numpy.random.random((8, nao, nao)) dm = dm + dm.transpose(0, 2, 1) vk = df_jk.get_k_kpts(mydf, dm, 1, mydf.kpts) self.assertAlmostEqual(finger(vk[0]), (1.0898939666590253 - 0.014906612874026948j), 9) self.assertAlmostEqual(finger(vk[1]), (0.71766985010790085 + 0.008841808731355736j), 9) self.assertAlmostEqual(finger(vk[2]), (0.89500717500394655 - 0.011255970881451824j), 9) self.assertAlmostEqual(finger(vk[3]), (1.2561632091272155 + 0.016131846517374523j), 9) self.assertAlmostEqual(finger(vk[4]), (1.0452056696649636 - 0.012591023244846416j), 9) self.assertAlmostEqual(finger(vk[5]), (0.98906700489431287 + 0.012847978938583308j), 9) self.assertAlmostEqual(finger(vk[6]), (0.91811462227257712 - 0.012200120679750136j), 9) self.assertAlmostEqual(finger(vk[7]), (0.84819570235790342 + 0.010245262542632964j), 9)
def test_j_kpts(self): numpy.random.seed(1) nao = cell.nao_nr() dm = numpy.random.random((4, nao, nao)) dm = dm + dm.transpose(0, 2, 1) mydf = df.DF(cell) mydf.kpts = numpy.random.random((4, 3)) mydf.gs = numpy.asarray((5, ) * 3) mydf.auxbasis = 'weigend' vj = df_jk.get_j_kpts(mydf, dm, 1, mydf.kpts) self.assertAlmostEqual(finger(vj[0]), (0.49176639512164577 - 0.11891092353150769j), 9) self.assertAlmostEqual(finger(vj[1]), (0.54901304965192832 - 0.046003580779851005j), 9) self.assertAlmostEqual(finger(vj[2]), (0.53648566446940738 - 0.083507597783243834j), 9) self.assertAlmostEqual(finger(vj[3]), (0.54896968903421772 + 0.007695795208980421j), 9)
def test_j_kpts(self): numpy.random.seed(1) nao = cell.nao_nr() dm = numpy.random.random((4, nao, nao)) dm = dm + dm.transpose(0, 2, 1) mydf = df.DF(cell) mydf.kpts = numpy.random.random((4, 3)) mydf.gs = numpy.asarray((5, ) * 3) mydf.auxbasis = 'weigend' vj = df_jk.get_j_kpts(mydf, dm, 1, mydf.kpts) self.assertAlmostEqual(finger(vj[0]), (0.49071716424863876 - 0.11866593764325209j), 9) self.assertAlmostEqual(finger(vj[1]), (0.54805564025672737 - 0.045780766515833224j), 9) self.assertAlmostEqual(finger(vj[2]), (0.53548588134342712 - 0.083269294794914239j), 9) self.assertAlmostEqual(finger(vj[3]), (0.54778931331075764 + 0.007709304083260985j), 9)
def test_k_kpts(self): numpy.random.seed(1) nao = cell.nao_nr() dm = numpy.random.random((4, nao, nao)) dm = dm + dm.transpose(0, 2, 1) mydf = df.DF(cell).set(auxbasis='weigend') mydf.kpts = numpy.random.random((4, 3)) mydf.gs = numpy.asarray((5, ) * 3) mydf.exxdiv = None mydf.gs = cell.gs mydf.eta = 0.3 mydf.auxbasis = 'weigend' vk = df_jk.get_k_kpts(mydf, dm, 0, mydf.kpts) self.assertAlmostEqual(finger(vk[0]), (-2.8332405542541035 - 1.0578703659011017j), 9) self.assertAlmostEqual(finger(vk[1]), (-7.4404337144965327 + 0.10233793208110664j), 9) self.assertAlmostEqual(finger(vk[2]), (-2.5718873173308587 - 1.4487392786249167j), 9) self.assertAlmostEqual(finger(vk[3]), (-0.79223061014463669 + 0.011694649225196911j), 9)
def test_j_kpts_high_cost(self): numpy.random.seed(1) nao = cell.nao_nr() dm = numpy.random.random((4, nao, nao)) dm = dm + dm.transpose(0, 2, 1) mydf = df.DF(cell).set(auxbasis='weigend') mydf.linear_dep_threshold = 1e-7 mydf.kpts = numpy.random.random((4, 3)) mydf.mesh = [n, n, n] mydf.auxbasis = 'weigend' mydf.eta = 0.3 mydf.exp_to_discard = mydf.eta vj = df_jk.get_j_kpts(mydf, dm, 1, mydf.kpts) self.assertAlmostEqual(lib.fp(vj[0]), (0.49176180692009197 - 0.11891083594538684j), 9) self.assertAlmostEqual(lib.fp(vj[1]), (0.54900852073326378 - 0.04600354345316908j), 9) self.assertAlmostEqual(lib.fp(vj[2]), (0.53648110926681891 - 0.083507522327029265j), 9) self.assertAlmostEqual(lib.fp(vj[3]), (0.5489650266265671 + 0.007695733246577244j), 9)
def test_eri0000(self): with_df = df.DF(cell).set(auxbasis='weigend') with_df.kpts = numpy.zeros((4, 3)) mo = (numpy.random.random((nao, nao)) + numpy.random.random( (nao, nao)) * 1j) eri = ao2mo.restore(1, with_df.get_eri(with_df.kpts), nao) eri0 = numpy.einsum('pjkl,pi->ijkl', eri, mo.conj()) eri0 = numpy.einsum('ipkl,pj->ijkl', eri0, mo) eri0 = numpy.einsum('ijpl,pk->ijkl', eri0, mo.conj()) eri0 = numpy.einsum('ijkp,pl->ijkl', eri0, mo) eri1 = with_df.ao2mo(mo, with_df.kpts) self.assertAlmostEqual( abs(eri1.reshape(eri0.shape) - eri0).sum(), 0, 9) mo = mo.real eri0 = numpy.einsum('pjkl,pi->ijkl', eri, mo.conj()) eri0 = numpy.einsum('ipkl,pj->ijkl', eri0, mo) eri0 = numpy.einsum('ijpl,pk->ijkl', eri0, mo.conj()) eri0 = numpy.einsum('ijkp,pl->ijkl', eri0, mo) eri1 = with_df.ao2mo(mo, with_df.kpts, compact=False) self.assertAlmostEqual( abs(eri1.reshape(eri0.shape) - eri0).sum(), 0, 9)