本文整理汇总了Python中pyscf.lib.transpose_sum函数的典型用法代码示例。如果您正苦于以下问题:Python transpose_sum函数的具体用法?Python transpose_sum怎么用?Python transpose_sum使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了transpose_sum函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _check_
def _check_(c):
c = lib.transpose_sum(c, inplace=True)
c *= .5
norm = numpy.linalg.norm(c)
if abs(norm-1) > 1e-6:
raise ValueError('State not singlet %g' % abs(numpy.linalg.norm(c)-1))
return c/norm
开发者ID:eronca,项目名称:pyscf,代码行数:7,代码来源:direct_spin0.py
示例2: part_eri_hermi
def part_eri_hermi(eri, norb, nimp):
eri1 = ao2mo.restore(4, eri, norb)
for i in range(eri1.shape[0]):
tmp = lib.unpack_tril(eri1[i])
tmp[nimp:] = 0
eri1[i] = lib.pack_tril(tmp + tmp.T)
eri1 = lib.transpose_sum(eri1, inplace=True)
return ao2mo.restore(8, eri1, norb) * 0.25
开发者ID:BB-Goldstein,项目名称:pydmet-1,代码行数:8,代码来源:impsolver.py
示例3: reorder_rdm
def reorder_rdm(rdm1, rdm2, inplace=False):
nmo = rdm1.shape[0]
if not inplace:
rdm2 = rdm2.copy()
for k in range(nmo):
rdm2[:,k,k,:] -= rdm1.T
#return rdm1, rdm2
rdm2 = lib.transpose_sum(rdm2.reshape(nmo*nmo,-1), inplace=True) * .5
return rdm1, rdm2.reshape(nmo,nmo,nmo,nmo)
开发者ID:sunqm,项目名称:pyscf,代码行数:9,代码来源:rdm.py
示例4: contract_2e
def contract_2e(eri, fcivec, norb, nelec, link_index=None):
fcivec = numpy.asarray(fcivec, order='C')
eri = ao2mo.restore(4, eri, norb)
lib.transpose_sum(eri, inplace=True)
eri *= .5
link_index = _unpack(norb, nelec, link_index)
na, nlink = link_index.shape[:2]
assert(fcivec.size == na**2)
ci1 = numpy.empty((na,na))
libfci.FCIcontract_2e_spin0(eri.ctypes.data_as(ctypes.c_void_p),
fcivec.ctypes.data_as(ctypes.c_void_p),
ci1.ctypes.data_as(ctypes.c_void_p),
ctypes.c_int(norb), ctypes.c_int(na),
ctypes.c_int(nlink),
link_index.ctypes.data_as(ctypes.c_void_p))
# no *.5 because FCIcontract_2e_spin0 only compute half of the contraction
return lib.transpose_sum(ci1, inplace=True).reshape(fcivec.shape)
开发者ID:eronca,项目名称:pyscf,代码行数:18,代码来源:direct_spin0.py
示例5: test_transpose_sum
def test_transpose_sum(self):
a = numpy.random.random((3,400,400))
self.assertAlmostEqual(abs(a[0]+a[0].T - lib.hermi_sum(a[0])).max(), 0, 12)
self.assertAlmostEqual(abs(a+a.transpose(0,2,1) - lib.hermi_sum(a,(0,2,1))).max(), 0, 12)
self.assertAlmostEqual(abs(a+a.transpose(0,2,1) - lib.hermi_sum(a,(0,2,1), inplace=True)).max(), 0, 12)
a = numpy.random.random((3,400,400)) + numpy.random.random((3,400,400)) * 1j
self.assertAlmostEqual(abs(a[0]+a[0].T.conj() - lib.hermi_sum(a[0])).max(), 0, 12)
self.assertAlmostEqual(abs(a+a.transpose(0,2,1).conj() - lib.hermi_sum(a,(0,2,1))).max(), 0, 12)
self.assertAlmostEqual(abs(a+a.transpose(0,2,1) - lib.hermi_sum(a,(0,2,1),hermi=3)).max(), 0, 12)
self.assertAlmostEqual(abs(a+a.transpose(0,2,1).conj() - lib.hermi_sum(a,(0,2,1),inplace=True)).max(), 0, 12)
a = numpy.random.random((400,400))
b = a + a.T.conj()
c = lib.transpose_sum(a)
self.assertAlmostEqual(abs(b-c).max(), 0, 12)
a = (a*1000).astype(numpy.int32)
b = a + a.T
c = lib.transpose_sum(a)
self.assertAlmostEqual(abs(b-c).max(), 0, 12)
self.assertTrue(c.dtype == numpy.int32)
开发者ID:sunqm,项目名称:pyscf,代码行数:21,代码来源:test_numpy_helper.py
示例6: contract_1e
def contract_1e(f1e, fcivec, norb, nelec, link_index=None):
fcivec = numpy.asarray(fcivec, order='C')
link_index = _unpack(norb, nelec, link_index)
na, nlink = link_index.shape[:2]
assert(fcivec.size == na**2)
ci1 = numpy.empty_like(fcivec)
f1e_tril = lib.pack_tril(f1e)
libfci.FCIcontract_1e_spin0(f1e_tril.ctypes.data_as(ctypes.c_void_p),
fcivec.ctypes.data_as(ctypes.c_void_p),
ci1.ctypes.data_as(ctypes.c_void_p),
ctypes.c_int(norb), ctypes.c_int(na),
ctypes.c_int(nlink),
link_index.ctypes.data_as(ctypes.c_void_p))
# no *.5 because FCIcontract_2e_spin0 only compute half of the contraction
return lib.transpose_sum(ci1, inplace=True).reshape(fcivec.shape)
开发者ID:eronca,项目名称:pyscf,代码行数:15,代码来源:direct_spin0.py
示例7: incore
def incore(eri, dm, hermi=0):
assert(not numpy.iscomplexobj(eri))
eri = numpy.ascontiguousarray(eri)
dm = numpy.ascontiguousarray(dm)
nao = dm.shape[0]
vj = numpy.empty((nao,nao))
vk = numpy.empty((nao,nao))
npair = nao*(nao+1)//2
if eri.ndim == 2 and npair*npair == eri.size: # 4-fold symmetry eri
fdrv = getattr(libcvhf, 'CVHFnrs4_incore_drv')
# 'ijkl,kl->ij'
fvj = _fpointer('CVHFics4_kl_s2ij')
# 'ijkl,il->jk'
fvk = _fpointer('CVHFics4_il_s1jk')
# or
## 'ijkl,ij->kl'
#fvj = _fpointer('CVHFics4_ij_s2kl')
## 'ijkl,jk->il'
#fvk = _fpointer('CVHFics4_jk_s1il')
tridm = dm
elif eri.ndim == 1 and npair*(npair+1)//2 == eri.size: # 8-fold symmetry eri
fdrv = getattr(libcvhf, 'CVHFnrs8_incore_drv')
fvj = _fpointer('CVHFics8_tridm_vj')
if hermi == 1:
fvk = _fpointer('CVHFics8_jk_s2il')
else:
fvk = _fpointer('CVHFics8_jk_s1il')
tridm = lib.pack_tril(lib.transpose_sum(dm))
i = numpy.arange(nao)
tridm[i*(i+1)//2+i] *= .5
else:
raise RuntimeError('Array shape not consistent: DM %s, eri %s'
% (dm.shape, eri.shape))
fdrv(eri.ctypes.data_as(ctypes.c_void_p),
tridm.ctypes.data_as(ctypes.c_void_p),
vj.ctypes.data_as(ctypes.c_void_p),
dm.ctypes.data_as(ctypes.c_void_p),
vk.ctypes.data_as(ctypes.c_void_p),
ctypes.c_int(nao), fvj, fvk)
if hermi != 0:
vj = lib.hermi_triu(vj, hermi)
vk = lib.hermi_triu(vk, hermi)
else:
vj = lib.hermi_triu(vj, 1)
return vj, vk
开发者ID:chrinide,项目名称:pyscf,代码行数:46,代码来源:_vhf.py
示例8: contract_2e
def contract_2e(eri, civec_strs, norb, nelec, link_index=None, orbsym=None):
ci_coeff, nelec, ci_strs = selected_ci._unpack(civec_strs, nelec)
if link_index is None:
link_index = selected_ci._all_linkstr_index(ci_strs, norb, nelec)
cd_indexa, dd_indexa, cd_indexb, dd_indexb = link_index
na, nlinka = nb, nlinkb = cd_indexa.shape[:2]
eri = ao2mo.restore(1, eri, norb)
eri1 = eri.transpose(0,2,1,3) - eri.transpose(0,2,3,1)
idx,idy = numpy.tril_indices(norb, -1)
idx = idx * norb + idy
eri1 = lib.take_2d(eri1.reshape(norb**2,-1), idx, idx) * 2
lib.transpose_sum(eri1, inplace=True)
eri1 *= .5
eri1, dd_indexa, dimirrep = selected_ci_symm.reorder4irrep(eri1, norb, dd_indexa, orbsym, -1)
fcivec = ci_coeff.reshape(na,nb)
ci1 = numpy.zeros_like(fcivec)
# (aa|aa)
if nelec[0] > 1:
ma, mlinka = mb, mlinkb = dd_indexa.shape[:2]
libfci.SCIcontract_2e_aaaa_symm(eri1.ctypes.data_as(ctypes.c_void_p),
fcivec.ctypes.data_as(ctypes.c_void_p),
ci1.ctypes.data_as(ctypes.c_void_p),
ctypes.c_int(norb),
ctypes.c_int(na), ctypes.c_int(nb),
ctypes.c_int(ma), ctypes.c_int(mlinka),
dd_indexa.ctypes.data_as(ctypes.c_void_p),
dimirrep.ctypes.data_as(ctypes.c_void_p),
ctypes.c_int(len(dimirrep)))
h_ps = numpy.einsum('pqqs->ps', eri) * (.5/nelec[0])
eri1 = eri.copy()
for k in range(norb):
eri1[:,:,k,k] += h_ps
eri1[k,k,:,:] += h_ps
eri1 = ao2mo.restore(4, eri1, norb)
lib.transpose_sum(eri1, inplace=True)
eri1 *= .5
eri1, cd_indexa, dimirrep = selected_ci_symm.reorder4irrep(eri1, norb, cd_indexa, orbsym)
# (bb|aa)
libfci.SCIcontract_2e_bbaa_symm(eri1.ctypes.data_as(ctypes.c_void_p),
fcivec.ctypes.data_as(ctypes.c_void_p),
ci1.ctypes.data_as(ctypes.c_void_p),
ctypes.c_int(norb),
ctypes.c_int(na), ctypes.c_int(nb),
ctypes.c_int(nlinka), ctypes.c_int(nlinkb),
cd_indexa.ctypes.data_as(ctypes.c_void_p),
cd_indexa.ctypes.data_as(ctypes.c_void_p),
dimirrep.ctypes.data_as(ctypes.c_void_p),
ctypes.c_int(len(dimirrep)))
lib.transpose_sum(ci1, inplace=True)
return selected_ci._as_SCIvector(ci1.reshape(ci_coeff.shape), ci_strs)
开发者ID:chrinide,项目名称:pyscf,代码行数:53,代码来源:selected_ci_spin0_symm.py
示例9: contract_2e
def contract_2e(eri, fcivec, norb, nelec, link_index=None, orbsym=None, wfnsym=0):
if orbsym is None:
return direct_spin0.contract_2e(eri, fcivec, norb, nelec, link_index)
eri = ao2mo.restore(4, eri, norb)
neleca, nelecb = direct_spin1._unpack_nelec(nelec)
assert(neleca == nelecb)
link_indexa = direct_spin0._unpack(norb, nelec, link_index)
na, nlinka = link_indexa.shape[:2]
eri_irs, rank_eri, irrep_eri = direct_spin1_symm.reorder_eri(eri, norb, orbsym)
totirrep = len(eri_irs)
strsa = numpy.asarray(cistring.gen_strings4orblist(range(norb), neleca))
aidx, link_indexa = direct_spin1_symm.gen_str_irrep(strsa, orbsym, link_indexa,
rank_eri, irrep_eri, totirrep)
Tirrep = ctypes.c_void_p*totirrep
linka_ptr = Tirrep(*[x.ctypes.data_as(ctypes.c_void_p) for x in link_indexa])
eri_ptrs = Tirrep(*[x.ctypes.data_as(ctypes.c_void_p) for x in eri_irs])
dimirrep = (ctypes.c_int*totirrep)(*[x.shape[0] for x in eri_irs])
fcivec_shape = fcivec.shape
fcivec = fcivec.reshape((na,na), order='C')
ci1new = numpy.zeros_like(fcivec)
nas = (ctypes.c_int*8)(*[x.size for x in aidx])
ci0 = []
ci1 = []
for ir in range(totirrep):
ma, mb = aidx[ir].size, aidx[wfnsym^ir].size
ci0.append(numpy.zeros((ma,mb)))
ci1.append(numpy.zeros((ma,mb)))
if ma > 0 and mb > 0:
lib.take_2d(fcivec, aidx[ir], aidx[wfnsym^ir], out=ci0[ir])
ci0_ptrs = Tirrep(*[x.ctypes.data_as(ctypes.c_void_p) for x in ci0])
ci1_ptrs = Tirrep(*[x.ctypes.data_as(ctypes.c_void_p) for x in ci1])
libfci.FCIcontract_2e_symm1(eri_ptrs, ci0_ptrs, ci1_ptrs,
ctypes.c_int(norb), nas, nas,
ctypes.c_int(nlinka), ctypes.c_int(nlinka),
linka_ptr, linka_ptr, dimirrep,
ctypes.c_int(totirrep), ctypes.c_int(wfnsym))
for ir in range(totirrep):
if ci0[ir].size > 0:
lib.takebak_2d(ci1new, ci1[ir], aidx[ir], aidx[wfnsym^ir])
return lib.transpose_sum(ci1new, inplace=True).reshape(fcivec_shape)
开发者ID:eronca,项目名称:pyscf,代码行数:44,代码来源:direct_spin0_symm.py
示例10: make_hdiag
def make_hdiag(h1e, eri, norb, nelec):
if isinstance(nelec, (int, numpy.number)):
neleca = nelec//2
else:
neleca, nelecb = nelec
assert(neleca == nelecb)
h1e = numpy.ascontiguousarray(h1e)
eri = ao2mo.restore(1, eri, norb)
strs = numpy.asarray(cistring.gen_strings4orblist(range(norb), neleca))
na = len(strs)
hdiag = numpy.empty((na,na))
jdiag = numpy.asarray(numpy.einsum('iijj->ij',eri), order='C')
kdiag = numpy.asarray(numpy.einsum('ijji->ij',eri), order='C')
libfci.FCImake_hdiag(hdiag.ctypes.data_as(ctypes.c_void_p),
h1e.ctypes.data_as(ctypes.c_void_p),
jdiag.ctypes.data_as(ctypes.c_void_p),
kdiag.ctypes.data_as(ctypes.c_void_p),
ctypes.c_int(norb), ctypes.c_int(na),
ctypes.c_int(neleca),
strs.ctypes.data_as(ctypes.c_void_p))
# symmetrize hdiag to reduce numerical error
hdiag = lib.transpose_sum(hdiag, inplace=True) * .5
return hdiag.ravel()
开发者ID:eronca,项目名称:pyscf,代码行数:23,代码来源:direct_spin0.py
示例11: IX_intermediates
def IX_intermediates(mycc, t1, t2, l1, l2, eris=None, d1=None, d2=None):
if eris is None:
# Note eris are in Chemist's notation
eris = ccsd._ERIS(mycc)
if d1 is None:
doo, dvv = ccsd_rdm.gamma1_intermediates(mycc, t1, t2, l1, l2)
else:
doo, dvv = d1
if d2 is None:
d2 = ccsd_rdm.gamma2_incore(mycc, t1, t2, l1, l2)
dovov, dvvvv, doooo, doovv, dovvo, dvvov, dovvv, dooov = d2
log = logger.Logger(mycc.stdout, mycc.verbose)
nocc, nvir = t1.shape
nov = nocc * nvir
# Note Ioo, Ivv are not hermitian
Ioo = numpy.zeros((nocc,nocc))
Ivv = numpy.zeros((nvir,nvir))
Ivo = numpy.zeros((nvir,nocc))
Xvo = numpy.zeros((nvir,nocc))
eris_oooo = _cp(eris.oooo)
eris_ooov = _cp(eris.ooov)
d_oooo = _cp(doooo)
d_oooo = _cp(d_oooo + d_oooo.transpose(1,0,2,3))
#:Ioo += numpy.einsum('jmlk,imlk->ij', d_oooo, eris_oooo) * 2
Ioo += lib.dot(eris_oooo.reshape(nocc,-1), d_oooo.reshape(nocc,-1).T, 2)
d_oooo = _cp(d_oooo.transpose(0,2,3,1))
#:Xvo += numpy.einsum('iljk,ljka->ai', d_oooo, eris_ooov) * 2
Xvo += lib.dot(eris_ooov.reshape(-1,nvir).T, d_oooo.reshape(nocc,-1).T, 2)
Xvo +=(numpy.einsum('kj,kjia->ai', doo, eris_ooov) * 4
- numpy.einsum('kj,ikja->ai', doo+doo.T, eris_ooov))
eris_oooo = eris_ooov = d_oooo = None
d_ooov = _cp(dooov)
eris_oooo = _cp(eris.oooo)
eris_ooov = _cp(eris.ooov)
#:Ivv += numpy.einsum('ijkb,ijka->ab', d_ooov, eris_ooov)
#:Ivo += numpy.einsum('jlka,jlki->ai', d_ooov, eris_oooo)
Ivv += lib.dot(eris_ooov.reshape(-1,nvir).T, d_ooov.reshape(-1,nvir))
Ivo += lib.dot(d_ooov.reshape(-1,nvir).T, eris_oooo.reshape(-1,nocc))
#:Ioo += numpy.einsum('klja,klia->ij', d_ooov, eris_ooov)
#:Xvo += numpy.einsum('kjib,kjba->ai', d_ooov, eris.oovv)
eris_oovv = _cp(eris.oovv)
tmp = _cp(d_ooov.transpose(0,1,3,2).reshape(-1,nocc))
tmpooov = _cp(eris_ooov.transpose(0,1,3,2))
Ioo += lib.dot(tmpooov.reshape(-1,nocc).T, tmp)
Xvo += lib.dot(eris_oovv.reshape(-1,nvir).T, tmp)
eris_oooo = tmp = None
d_ooov = d_ooov + d_ooov.transpose(1,0,2,3)
eris_ovov = _cp(eris.ovov)
#:Ioo += numpy.einsum('jlka,ilka->ij', d_ooov, eris_ooov)
#:Xvo += numpy.einsum('ijkb,kbja->ai', d_ooov, eris.ovov)
Ioo += lib.dot(eris_ooov.reshape(nocc,-1), d_ooov.reshape(nocc,-1).T)
Xvo += lib.dot(eris_ovov.reshape(-1,nvir).T,
_cp(d_ooov.transpose(0,2,3,1).reshape(nocc,-1)).T)
d_ooov = None
#:Ioo += numpy.einsum('kjba,kiba->ij', d_oovv, eris.oovv)
#:Ivv += numpy.einsum('ijcb,ijca->ab', d_oovv, eris.oovv)
#:Ivo += numpy.einsum('kjba,kjib->ai', d_oovv, eris.ooov)
d_oovv = _cp(doovv + doovv.transpose(1,0,3,2))
for i in range(nocc):
Ioo += lib.dot(eris_oovv[i].reshape(nocc, -1), d_oovv[i].reshape(nocc,-1).T)
Ivv += lib.dot(eris_oovv.reshape(-1,nvir).T, d_oovv.reshape(-1,nvir))
Ivo += lib.dot(d_oovv.reshape(-1,nvir).T, tmpooov.reshape(-1,nocc))
d_oovv = _ccsd.precontract(d_oovv.reshape(-1,nvir,nvir)).reshape(nocc,nocc,-1)
eris_ooov = tmpooov = None
blksize = 4
d_ovov = numpy.empty((nocc,nvir,nocc,nvir))
for p0, p1 in prange(0, nocc, blksize):
d_ovov[p0:p1] = _cp(dovov[p0:p1])
d_ovvo = _cp(dovvo[p0:p1])
for i in range(p0,p1):
d_ovov[i] += d_ovvo[i-p0].transpose(0,2,1)
d_ovvo = None
#:d_ovov = d_ovov + d_ovov.transpose(2,3,0,1)
lib.transpose_sum(d_ovov.reshape(nov,nov), inplace=True)
#:Ivo += numpy.einsum('jbka,jbki->ai', d_ovov, eris.ovoo)
Ivo += lib.dot(d_ovov.reshape(-1,nvir).T, _cp(eris.ovoo).reshape(-1,nocc))
#:Ioo += numpy.einsum('jakb,iakb->ij', d_ovov, eris.ovov)
#:Ivv += numpy.einsum('jcib,jcia->ab', d_ovov, eris.ovov)
Ioo += lib.dot(eris_ovov.reshape(nocc,-1), d_ovov.reshape(nocc,-1).T)
Ivv += lib.dot(eris_ovov.reshape(-1,nvir).T, d_ovov.reshape(-1,nvir))
nvir_pair = nvir * (nvir+1) // 2
bufe_ovvv = numpy.empty((blksize,nvir,nvir,nvir))
bufc_ovvv = numpy.empty((blksize,nvir,nvir_pair))
bufc_ovvv.data = bufe_ovvv.data
c_vvvo = numpy.empty((nvir_pair,nvir,nocc))
for p0, p1 in prange(0, nocc, blksize):
d_ovvv = numpy.empty((p1-p0,nvir,nvir,nvir))
#:Ivo += numpy.einsum('jadc,jidc->ai', d_ovvv, eris_oovv)
for i in range(p1-p0):
lib.dot(dovvv[p0+i].reshape(nvir,-1),
eris_oovv[p0+i].reshape(nocc,-1).T, 1, Ivo, 1)
#.........这里部分代码省略.........
开发者ID:matk86,项目名称:pyscf,代码行数:101,代码来源:ccsd_grad_incore.py
示例12: make_hdiag
def make_hdiag(h1e, eri, norb, nelec):
hdiag = direct_spin1.make_hdiag(h1e, eri, norb, nelec)
na = int(numpy.sqrt(hdiag.size))
# symmetrize hdiag to reduce numerical error
hdiag = lib.transpose_sum(hdiag.reshape(na,na), inplace=True) * .5
return hdiag.ravel()
开发者ID:chrinide,项目名称:pyscf,代码行数:6,代码来源:direct_spin0.py
示例13: make_hdiag
def make_hdiag(h1e, eri, ci_strs, norb, nelec):
hdiag = select_ci.make_hdiag(h1e, eri, ci_strs, norb, nelec)
na = len(ci_strs[0])
lib.transpose_sum(hdiag.reshape(na,na), inplace=True)
hdiag *= .5
return hdiag
开发者ID:eronca,项目名称:pyscf,代码行数:6,代码来源:select_ci_spin0.py
示例14: get_eri
def get_eri(mydf, kpts=None, compact=True):
cell = mydf.cell
if kpts is None:
kptijkl = numpy.zeros((4,3))
elif numpy.shape(kpts) == (3,):
kptijkl = numpy.vstack([kpts]*4)
else:
kptijkl = numpy.reshape(kpts, (4,3))
if mydf._cderi is None:
mydf.build()
kpti, kptj, kptk, kptl = kptijkl
auxcell = mydf.auxcell
nao = cell.nao_nr()
naux = auxcell.nao_nr()
nao_pair = nao * (nao+1) // 2
max_memory = max(2000, (mydf.max_memory - lib.current_memory()[0]) * .8)
####################
# gamma point, the integral is real and with s4 symmetry
if abs(kptijkl).sum() < 1e-9:
eriR = numpy.zeros((nao_pair,nao_pair))
for LpqR, LpqI, j3cR, j3cI in mydf.sr_loop(kptijkl[:2], max_memory, True):
lib.ddot(j3cR.T, LpqR, 1, eriR, 1)
eriR = lib.transpose_sum(eriR, inplace=True)
coulG = tools.get_coulG(cell, kptj-kpti, gs=mydf.gs) / cell.vol
max_memory = (mydf.max_memory - lib.current_memory()[0]) * .8
trilidx = numpy.tril_indices(nao)
for pqkR, pqkI, p0, p1 \
in mydf.pw_loop(cell, mydf.gs, kptijkl[:2], max_memory=max_memory):
pqkR = numpy.asarray(pqkR.reshape(nao,nao,-1)[trilidx], order='C')
pqkI = numpy.asarray(pqkI.reshape(nao,nao,-1)[trilidx], order='C')
vG = numpy.sqrt(coulG[p0:p1])
pqkR *= vG
pqkI *= vG
lib.dot(pqkR, pqkR.T, 1, eriR, 1)
lib.dot(pqkI, pqkI.T, 1, eriR, 1)
if not compact:
eriR = ao2mo.restore(1, eriR, nao).reshape(nao**2,-1)
return eriR
####################
# (kpt) i == j == k == l != 0
#
# (kpt) i == l && j == k && i != j && j != k =>
# both vbar and ovlp are zero. It corresponds to the exchange integral.
#
# complex integrals, N^4 elements
elif (abs(kpti-kptl).sum() < 1e-9) and (abs(kptj-kptk).sum() < 1e-9):
eriR = numpy.zeros((nao*nao,nao*nao))
eriI = numpy.zeros((nao*nao,nao*nao))
for LpqR, LpqI, j3cR, j3cI in mydf.sr_loop(kptijkl[:2], max_memory, False):
zdotNC(j3cR.T, j3cI.T, LpqR, LpqI, 1, eriR, eriI, 1)
zdotNC(LpqR.T, LpqI.T, j3cR, j3cI, 1, eriR, eriI, 1)
LpqR = LpqI = j3cR = j3cI = None
coulG = tools.get_coulG(cell, kptj-kpti, gs=mydf.gs) / cell.vol
for pqkR, pqkI, p0, p1 \
in mydf.pw_loop(cell, mydf.gs, kptijkl[:2], max_memory=max_memory):
vG = numpy.sqrt(coulG[p0:p1])
pqkR *= vG
pqkI *= vG
# rho_pq(G+k_pq) * conj(rho_rs(G-k_rs))
zdotNC(pqkR, pqkI, pqkR.T, pqkI.T, 1, eriR, eriI, 1)
# transpose(0,1,3,2) because
# j == k && i == l =>
# (L|ij).transpose(0,2,1).conj() = (L^*|ji) = (L^*|kl) => (M|kl)
# rho_rs(-G+k_rs) = conj(transpose(rho_sr(G+k_sr), (0,2,1)))
return (eriR.reshape((nao,)*4).transpose(0,1,3,2) +
eriI.reshape((nao,)*4).transpose(0,1,3,2)*1j).reshape(nao**2,-1)
####################
# aosym = s1, complex integrals
#
# kpti == kptj => kptl == kptk
# If kpti == kptj, (kptl-kptk)*a has to be multiples of 2pi because of the wave
# vector symmetry. k is a fraction of reciprocal basis, 0 < k/b < 1, by definition.
# So kptl/b - kptk/b must be -1 < k/b < 1.
#
else:
eriR = numpy.zeros((nao*nao,nao*nao))
eriI = numpy.zeros((nao*nao,nao*nao))
for (LpqR, LpqI, jpqR, jpqI), (LrsR, LrsI, jrsR, jrsI) in \
lib.izip(mydf.sr_loop(kptijkl[:2], max_memory, False),
mydf.sr_loop(kptijkl[2:], max_memory, False)):
zdotNN(jpqR.T, jpqI.T, LrsR, LrsI, 1, eriR, eriI, 1)
zdotNN(LpqR.T, LpqI.T, jrsR, jrsI, 1, eriR, eriI, 1)
LpqR = LpqI = jpqR = jpqI = LrsR = LrsI = jrsR = jrsI = None
coulG = tools.get_coulG(cell, kptj-kpti, gs=mydf.gs) / cell.vol
max_memory = (mydf.max_memory - lib.current_memory()[0]) * .4
for (pqkR, pqkI, p0, p1), (rskR, rskI, q0, q1) in \
lib.izip(mydf.pw_loop(cell, mydf.gs, kptijkl[:2], max_memory=max_memory),
mydf.pw_loop(cell, mydf.gs,-kptijkl[2:], max_memory=max_memory)):
pqkR *= coulG[p0:p1]
pqkI *= coulG[p0:p1]
# rho'_rs(G-k_rs) = conj(rho_rs(-G+k_rs))
# = conj(rho_rs(-G+k_rs) - d_{k_rs:Q,rs} * Q(-G+k_rs))
#.........这里部分代码省略.........
开发者ID:berquist,项目名称:pyscf,代码行数:101,代码来源:mdf_ao2mo.py
示例15: _rdm2_mo2ao
def _rdm2_mo2ao(mycc, d2, mo_coeff, fsave=None):
# dm2 = ccsd_rdm._make_rdm2(mycc, None, d2, with_dm1=False)
# dm2 = numpy.einsum('pi,ijkl->pjkl', mo_coeff, dm2)
# dm2 = numpy.einsum('pj,ijkl->ipkl', mo_coeff, dm2)
# dm2 = numpy.einsum('pk,ijkl->ijpl', mo_coeff, dm2)
# dm2 = numpy.einsum('pl,ijkl->ijkp', mo_coeff, dm2)
# dm2 = dm2 + dm2.transpose(1,0,2,3)
# dm2 = dm2 + dm2.transpose(0,1,3,2)
# return ao2mo.restore(4, dm2*.5, nmo)
log = logger.Logger(mycc.stdout, mycc.verbose)
time1 = time.clock(), time.time()
if fsave is None:
incore = True
fsave = lib.H5TmpFile()
else:
incore = False
dovov, dvvvv, doooo, doovv, dovvo, dvvov, dovvv, dooov = d2
nocc, nvir = dovov.shape[:2]
mo_coeff = numpy.asarray(mo_coeff, order='F')
nao, nmo = mo_coeff.shape
nao_pair = nao * (nao+1) // 2
nvir_pair = nvir * (nvir+1) //2
fdrv = getattr(_ccsd.libcc, 'AO2MOnr_e2_drv')
ftrans = _ccsd.libcc.AO2MOtranse2_nr_s1
fmm = _ccsd.libcc.CCmmm_transpose_sum
pao_loc = ctypes.POINTER(ctypes.c_void_p)()
def _trans(vin, orbs_slice, out=None):
nrow = vin.shape[0]
if out is None:
out = numpy.empty((nrow,nao_pair))
fdrv(ftrans, fmm,
out.ctypes.data_as(ctypes.c_void_p),
vin.ctypes.data_as(ctypes.c_void_p),
mo_coeff.ctypes.data_as(ctypes.c_void_p),
ctypes.c_int(nrow), ctypes.c_int(nao),
(ctypes.c_int*4)(*orbs_slice), pao_loc, ctypes.c_int(0))
return out
fswap = lib.H5TmpFile()
max_memory = mycc.max_memory - lib.current_memory()[0]
blksize = int(max_memory*1e6/8/(nao_pair+nmo**2))
blksize = min(nvir_pair, max(ccsd.BLKMIN, blksize))
chunks_vv = (int(min(blksize,4e8/blksize)), blksize)
fswap.create_dataset('v', (nao_pair,nvir_pair), 'f8', chunks=chunks_vv)
for p0, p1 in lib.prange(0, nvir_pair, blksize):
fswap['v'][:,p0:p1] = _trans(lib.unpack_tril(_cp(dvvvv[p0:p1])),
(nocc,nmo,nocc,nmo)).T
time1 = log.timer_debug1('_rdm2_mo2ao pass 1', *time1)
# transform dm2_ij to get lower triangular (dm2+dm2.transpose(0,1,3,2))
blksize = int(max_memory*1e6/8/(nao_pair+nmo**2))
blksize = min(nao_pair, max(ccsd.BLKMIN, blksize))
fswap.create_dataset('o', (nmo,nocc,nao_pair), 'f8', chunks=(nocc,nocc,blksize))
buf1 = numpy.zeros((nocc,nocc,nmo,nmo))
buf1[:,:,:nocc,:nocc] = doooo
buf1[:,:,nocc:,nocc:] = _cp(doovv)
buf1 = _trans(buf1.reshape(nocc**2,-1), (0,nmo,0,nmo))
fswap['o'][:nocc] = buf1.reshape(nocc,nocc,nao_pair)
dovoo = numpy.asarray(dooov).transpose(2,3,0,1)
for p0, p1 in lib.prange(nocc, nmo, nocc):
buf1 = numpy.zeros((nocc,p1-p0,nmo,nmo))
buf1[:,:,:nocc,:nocc] = dovoo[:,p0-nocc:p1-nocc]
buf1[:,:,nocc:,:nocc] = dovvo[:,p0-nocc:p1-nocc]
buf1[:,:,:nocc,nocc:] = dovov[:,p0-nocc:p1-nocc]
buf1[:,:,nocc:,nocc:] = dovvv[:,p0-nocc:p1-nocc]
buf1 = buf1.transpose(1,0,3,2).reshape((p1-p0)*nocc,-1)
buf1 = _trans(buf1, (0,nmo,0,nmo))
fswap['o'][p0:p1] = buf1.reshape(p1-p0,nocc,nao_pair)
time1 = log.timer_debug1('_rdm2_mo2ao pass 2', *time1)
dovoo = buf1 = None
# transform dm2_kl then dm2 + dm2.transpose(2,3,0,1)
gsave = fsave.create_dataset('dm2', (nao_pair,nao_pair), 'f8', chunks=chunks_vv)
for p0, p1 in lib.prange(0, nao_pair, blksize):
buf1 = numpy.zeros((p1-p0,nmo,nmo))
buf1[:,nocc:,nocc:] = lib.unpack_tril(_cp(fswap['v'][p0:p1]))
buf1[:,:,:nocc] = fswap['o'][:,:,p0:p1].transpose(2,0,1)
buf2 = _trans(buf1, (0,nmo,0,nmo))
if p0 > 0:
buf1 = _cp(gsave[:p0,p0:p1])
buf1[:p0,:p1-p0] += buf2[:p1-p0,:p0].T
buf2[:p1-p0,:p0] = buf1[:p0,:p1-p0].T
gsave[:p0,p0:p1] = buf1
lib.transpose_sum(buf2[:,p0:p1], inplace=True)
gsave[p0:p1] = buf2
time1 = log.timer_debug1('_rdm2_mo2ao pass 3', *time1)
if incore:
return fsave['dm2'].value
else:
return fsave
开发者ID:chrinide,项目名称:pyscf,代码行数:92,代码来源:ccsd.py
示例16: _rdm2_mo2ao
def _rdm2_mo2ao(mycc, d2, mo_coeff, fsave=None):
log = logger.Logger(mycc.stdout, mycc.verbose)
time1 = time.clock(), time.time()
if fsave is None:
incore = True
fsave = lib.H5TmpFile()
else:
incore = False
dovov, dovOV, dOVov, dOVOV = d2[0]
dvvvv, dvvVV, dVVvv, dVVVV = d2[1]
doooo, dooOO, dOOoo, dOOOO = d2[2]
doovv, dooVV, dOOvv, dOOVV = d2[3]
dovvo, dovVO, dOVvo, dOVVO = d2[4]
dvvov, dvvOV, dVVov, dVVOV = d2[5]
dovvv, dovVV, dOVvv, dOVVV = d2[6]
dooov, dooOV, dOOov, dOOOV = d2[7]
mo_a = numpy.asarray(mo_coeff[0], order='F')
mo_b = numpy.asarray(mo_coeff[1], order='F')
nocca, nvira, noccb, nvirb = dovOV.shape
nao, nmoa = mo_a.shape
nmob = mo_b.shape[1]
nao_pair = nao * (nao+1) // 2
nvira_pair = nvira * (nvira+1) //2
nvirb_pair = nvirb * (nvirb+1) //2
fdrv = getattr(_ccsd.libcc, 'AO2MOnr_e2_drv')
ftrans = _ccsd.libcc.AO2MOtranse2_nr_s1
fmm = _ccsd.libcc.CCmmm_transpose_sum
pao_loc = ctypes.POINTER(ctypes.c_void_p)()
def _trans(vin, mo_coeff, orbs_slice, out=None):
nrow = vin.shape[0]
if out is None:
out = numpy.empty((nrow,nao_pair))
fdrv(ftrans, fmm,
out.ctypes.data_as(ctypes.c_void_p),
vin.ctypes.data_as(ctypes.c_void_p),
mo_coeff.ctypes.data_as(ctypes.c_void_p),
ctypes.c_int(nrow), ctypes.c_int(nao),
(ctypes.c_int*4)(*orbs_slice), pao_loc, ctypes.c_int(0))
return out
fswap = lib.H5TmpFile()
max_memory = mycc.max_memory - lib.current_memory()[0]
blksize_a = int(max_memory*.9e6/8/(nao_pair+nmoa**2))
blksize_a = min(nvira_pair, max(ccsd.BLKMIN, blksize_a))
chunks_a = (int(min(nao_pair, 4e8/blksize_a)), blksize_a)
v_aa = fswap.create_dataset('v_aa', (nao_pair,nvira_pair), 'f8',
chunks=chunks_a)
for p0, p1 in lib.prange(0, nvira_pair, blksize_a):
v_aa[:,p0:p1] = _trans(lib.unpack_tril(dvvvv[p0:p1]*.25), mo_a,
(nocca,nmoa,nocca,nmoa)).T
v_ba = fswap.create_dataset('v_ab', (nao_pair,nvira_pair), 'f8',
chunks=chunks_a)
dvvOP = fswap.create_dataset('dvvOP', (nvira_pair,noccb,nmob), 'f8',
chunks=(int(min(blksize_a,4e8/nmob)),1,nmob))
for i in range(noccb):
buf1 = numpy.empty((nmob,nvira,nvira))
buf1[:noccb] = dOOvv[i] * .5
buf1[noccb:] = dOVvv[i]
buf1 = buf1.transpose(1,2,0) + buf1.transpose(2,1,0)
dvvOP[:,i] = buf1[numpy.tril_indices(nvira)]
for p0, p1 in lib.prange(0, nvira_pair, blksize_a):
buf1 = numpy.zeros((p1-p0,nmob,nmob))
buf1[:,noccb:,noccb:] = lib.unpack_tril(dvvVV[p0:p1] * .5)
buf1[:,:noccb,:] = dvvOP[p0:p1] * .5
v_ba[:,p0:p1] = _trans(buf1, mo_b, (0,nmob,0,nmob)).T
dvvOO = dvvOV = None
blksize_b = int(max_memory*.9e6/8/(nao_pair+nmob**2))
blksize_b = min(nvirb_pair, max(ccsd.BLKMIN, blksize_b))
chunks_b = (int(min(nao_pair, 4e8/blksize_b)), blksize_b)
v_bb = fswap.create_dataset('v_bb', (nao_pair,nvirb_pair), 'f8',
chunks=chunks_b)
for p0, p1 in lib.prange(0, nvirb_pair, blksize_b):
v_bb[:,p0:p1] = _trans(lib.unpack_tril(dVVVV[p0:p1]*.25), mo_b,
(noccb,nmob,noccb,nmob)).T
time1 = log.timer_debug1('_rdm2_mo2ao pass 1', *time1)
# transform dm2_ij to get lower triangular (dm2+dm2.transpose(0,1,3,2))
blksize = int(max_memory*.9e6/8/(nao_pair+nmoa**2))
blksize = min(nao_pair, max(ccsd.BLKMIN, blksize))
o_aa = fswap.create_dataset('o_aa', (nmoa,nocca,nao_pair), 'f8', chunks=(nocca,nocca,blksize))
o_ab = fswap.create_dataset('o_ab', (nmoa,nocca,nao_pair), 'f8', chunks=(nocca,nocca,blksize))
o_bb = fswap.create_dataset('o_bb', (nmob,noccb,nao_pair), 'f8', chunks=(noccb,noccb,blksize))
buf1 = numpy.zeros((nocca,nocca,nmoa,nmoa))
buf1[:,:,:nocca,:nocca] = _cp(doooo) * .25
buf1[:,:,nocca:,nocca:] = _cp(doovv) * .5
buf1 = _trans(buf1.reshape(nocca**2,-1), mo_a, (0,nmoa,0,nmoa))
o_aa[:nocca] = buf1.reshape(nocca,nocca,nao_pair)
buf1 = numpy.zeros((nocca,nocca,nmob,nmob))
buf1[:,:,:noccb,:noccb] = _cp(dooOO) * .5
buf1[:,:,:noccb,noccb:] = _cp(dooOV)
buf1[:,:,noccb:,noccb:] = _cp(dooVV) * .5
buf1 = _trans(buf1.reshape(nocca**2,-1), mo_b, (0,nmob,0,nmob))
o_ab[:nocca] = buf1.reshape(nocca,nocca,nao_pair)
buf1 = numpy.zeros((noccb,noccb,nmob,nmob))
#.........这里部分代码省略.........
开发者ID:chrinide,项目名称:pyscf,代码行数:101,代码来源:uccsd.py
示例17: update_amps
def update_amps(cc, t1, t2, eris, blksize=1):
time1 = time0 = time.clock(), time.time()
log = logger.Logger(cc.stdout, cc.verbose)
nocc = cc.nocc
nmo = cc.nmo
nvir = nmo - nocc
nov = nocc*nvir
fock = eris.fock
t1new = numpy.zeros_like(t1)
t2new = numpy.zeros_like(t2)
#** make_inter_F
fov = fock[:nocc,nocc:].copy()
foo = fock[:nocc,:nocc].copy()
foo[range(nocc),range(nocc)] = 0
foo += .5 * numpy.einsum('ia,ja->ij', fock[:nocc,nocc:], t1)
fvv = fock[nocc:,nocc:].copy()
fvv[range(nvir),range(nvir)] = 0
fvv -= .5 * numpy.einsum('ia,ib->ab', t1, fock[:nocc,nocc:])
#: woooo = numpy.einsum('la,ikja->ikjl', t1, eris.ooov)
eris_ooov = numpy.asarray(eris.ooov)
woooo = lib.dot(eris_ooov.reshape(-1,nvir), t1.T).reshape((nocc,)*4)
woooo = lib.transpose_sum(woooo.reshape(nocc*nocc,-1), inplace=True)
woooo = woooo.reshape(nocc,nocc,nocc,nocc) + numpy.asarray(eris.oooo)
woooo = numpy.asarray(woooo.transpose(0,2,1,3), order='C')
time1 = log.timer_debug1('woooo', *time0)
for p0, p1 in prange(0, nocc, blksize):
# ==== read eris.ovvv ====
eris_ovvv = numpy.asarray(eris.ovvv[p0:p1])
eris_ovvv = unpack_tril(eris_ovvv.reshape((p1-p0)*nvir,-1))
eris_ovvv = eris_ovvv.reshape(p1-p0,nvir,nvir,nvir)
eris_ooov = numpy.asarray(eris.ooov[p0:p1])
fvv += numpy.einsum('kc,kcba->ab', 2*t1[p0:p1], eris_ovvv)
fvv += numpy.einsum('kc,kbca->ab', -t1[p0:p1], eris_ovvv)
foo[:,p0:p1] += numpy.einsum('kc,jikc->ij', 2*t1, eris.ooov[p0:p1])
foo[:,p0:p1] += numpy.einsum('kc,jkic->ij', -t1, eris.ooov[p0:p1])
#: tau = t2 + numpy.einsum('ia,jb->ijab', t1, t1)
#: tmp = numpy.einsum('ijcd,kcdb->ijbk', tau, eris.ovvv)
#: t2new += numpy.einsum('ka,ijbk->jiba', -t1, tmp)
#: eris_vvov = eris_ovvv.transpose(1,2,0,3).copy()
eris_vvov = eris_ovvv.transpose(1,2,0,3).reshape(nvir*nvir,-1)
tmp = numpy.empty((nocc,nocc,p1-p0,nvir))
for j0, j1 in prange(0, nocc, blksize):
tau = make_tau(t2[j0:j1], t1[j0:j1], t1, 1)
#: tmp[j0:j1] += numpy.einsum('ijcd,cdkb->ijkb', tau, eris_vvov)
lib.dot(tau.reshape(-1,nvir*nvir), eris_vvov, 1,
tmp[j0:j1].reshape((j1-j0)*nocc,-1), 0)
#: t2new += numpy.einsum('ka,ijkb->jiba', -t1[p0:p1], tmp)
tmp = numpy.asarray(tmp.transpose(1,0,3,2).reshape(-1,p1-p0), order='C')
lib.dot(tmp, t1[p0:p1], -1, t2new.reshape(-1,nvir), 1)
tau = tmp = eris_vvov = None
#==== mem usage blksize*(nvir**3*2+nvir*nocc**2*2)
#: wovvo += numpy.einsum('iabc,jc->ijab', eris.ovvv, t1)
#: wovvo -= numpy.einsum('jbik,ka->jiba', eris.ovoo, t1)
#: t2new += woVoV.transpose()
#: wovvo = -numpy.einsum('jbik,ka->ijba', eris.ovoo[p0:p1], t1)
tmp = numpy.asarray(eris.ovoo[p0:p1].transpose(2,0,1,3), order='C')
wovvo = lib.dot(tmp.reshape(-1,nocc), t1, -1)
wovvo = wovvo.reshape(nocc,p1-p0,nvir,nvir)
#: wovvo += numpy.einsum('iabc,jc->jiab', eris_ovvv, t1)
lib.dot(t1, eris_ovvv.reshape(-1,nvir).T, 1, wovvo.reshape(nocc,-1), 1)
t2new[p0:p1] += wovvo.transpose(1,0,2,3)
#: woVoV = numpy.einsum('ka,ijkb->ijba', t1, eris.ooov[p0:p1])
#: woVoV -= numpy.einsum('jc,icab->ijab', t1, eris_ovvv)
woVoV = lib.dot(numpy.asarray(eris_ooov.transpose(0,1,3,2),
order='C').reshape(-1,nocc), t1)
woVoV = woVoV.reshape(p1-p0,nocc,nvir,nvir)
for i in range(eris_ovvv.shape[0]):
lib.dot(t1, eris_ovvv[i].reshape(nvir,-1), -1,
woVoV[i].reshape(nocc,-1), 1)
#: theta = t2.transpose(0,1,3,2) * 2 - t2
#: t1new += numpy.einsum('ijcb,jcba->ia', theta, eris.ovvv)
theta = make_theta(t2[p0:p1])
#: t1new += numpy.einsum('jibc,jcba->ia', theta, eris_ovvv)
lib.dot(theta.transpose(1,0,3,2).reshape(nocc,-1),
eris_ovvv.reshape(-1,nvir), 1, t1new, 1)
eris_ovvv = None
time2 = log.timer_debug1('ovvv [%d:%d]'%(p0, p1), *time1)
#==== mem usage blksize*(nvir**3+nocc*nvir**2*4)
# ==== read eris.oOVv ====
eris_oOVv = numpy.asarray(eris.ovov[p0:p1].transpose(0,2,3,1), order='C')
#==== mem usage blksize*(nocc*nvir**2*4)
for i in range(p1-p0):
t2new[p0+i] += eris_oOVv[i].transpose(0,2,1) * .5
fov[p0:p1] += numpy.einsum('kc,ikca->ia', t1, eris_oOVv) * 2
fov[p0:p1] -= numpy.einsum('kc,ikac->ia', t1, eris_oOVv)
#.........这里部分代码省略.........
开发者ID:diradical,项目名称:pyscf,代码行数:101,代码来源:ccsd.py
示例18: general
def general(mydf, mo_coeffs, kpts=None, compact=True):
if mydf._cderi is None:
mydf.build()
cell = mydf.cell
kptijkl = _format_kpts(kpts)
kpti, kptj, kptk, kptl = kptijkl
if isinstance(mo_coeffs, numpy.ndarray) and mo_coeffs.ndim == 2:
mo_coeffs = (mo_coeffs,) * 4
eri_mo = pwdf_ao2mo.general(mydf, mo_coeffs, kptijkl, compact)
all_real = not any(numpy.iscomplexobj(mo) for mo in mo_coeffs)
max_memory = max(2000, (mydf.max_memory - lib.current_memory()[0]) * .5)
####################
# gamma point, the integral is real and with s4 symmetry
if abs(kptijkl).sum() < KPT_DIFF_TOL and all_real:
ijmosym, nij_pair, moij, ijslice = _conc_mos(mo_coeffs[0], mo_coeffs[1], compact)
klmosym, nkl_pair, mokl, klslice = _conc_mos(mo_coeffs[2], mo_coeffs[3], compact)
sym = (iden_coeffs(mo_coeffs[0], mo_coeffs[2]) and
iden_coeffs(mo_coeffs[1], mo_coeffs[3]))
if sym:
eri_mo *= .5 # because we'll do +cc later
ijR = klR = None
for LpqR, LpqI, j3cR, j3cI in mydf.sr_loop(kptijkl[:2], max_memory, True):
ijR, klR = _dtrans(LpqR, ijR, ijmosym, moij, ijslice,
j3cR, klR, klmosym, mokl, klslice, False)
lib.ddot(ijR.T, klR, 1, eri_mo, 1)
if not sym:
ijR, klR = _dtrans(j3cR, ijR, ijmosym, moij, ijslice,
LpqR, klR, klmosym, mokl, klslice, False)
lib.ddot(ijR.T, klR, 1, eri_mo, 1)
LpqR = LpqI = j3cR = j3cI = None
if sym:
eri_mo = lib.transpose_sum(eri_mo, inplace=True)
return eri_mo
####################
# (kpt) i == j == k == l != 0
#
# (kpt) i == l && j == k && i != j && j != k =>
# both vbar and ovlp are zero. It corresponds to the exchange integral.
#
# complex integrals, N^4 elements
elif (abs(kpti-kptl).sum() < KPT_DIFF_TOL) and (abs(kptj-kptk).sum() < KPT_DIFF_TOL):
mo_coeffs = _mo_as_complex(mo_coeffs)
nij_pair, moij, ijslice = _conc_mos(mo_coeffs[0], mo_coeffs[1])[1:]
nlk_pair, molk, lkslice = _conc_mos(mo_coeffs[3], mo_coeffs[2])[1:]
eri_lk = numpy.zeros((nij_pair,nlk_pair), dtype=numpy.complex)
sym = (iden_coeffs(mo_coeffs[0], mo_coeffs[3]) and
iden_coeffs(mo_coeffs[1], mo_coeffs[2]))
zij = zlk = buf = None
for LpqR, LpqI, j3cR, j3cI in mydf.sr_loop(kptijkl[:2], max_memory, False):
bufL = LpqR+LpqI*1j
bufj = j3cR+j3cI*1j
zij, zlk = _ztrans(bufL, zij, moij, ijslice,
bufj, zlk, molk, lkslice, False)
lib.dot(zij.T, zlk.conj(), 1, eri_lk, 1)
if not sym:
zij, zlk = _ztrans(bufj, zij, moij, ijslice,
bufL, zlk, molk, lkslice, False)
lib.dot(zij.T, zlk.conj(), 1, eri_lk, 1)
LpqR = LpqI = j3cR = j3cI = bufL = bufj = None
if sym:
eri_lk += lib.transpose(eri_lk).conj()
nmok = mo_coeffs[2].shape[1]
nmol = mo_coeffs[3].shape[1]
eri_lk = lib.transpose(eri_lk.reshape(-1,nmol,nmok), axes=(0,2,1))
eri_mo += eri_lk.reshape(nij_pair,nlk_pair)
return eri_mo
####################
# aosym = s1, complex integrals
#
# kpti == kptj => kptl == kptk
# If kpti == kptj, (kptl-kptk)*a has to be multiples of 2pi because of the wave
# vector symmetry. k is a fraction of reciprocal basis, 0 < k/b < 1, by definition.
# So kptl/b - kptk/b must be -1 < k/b < 1.
#
else:
mo_coeffs = _mo_as_complex(mo_coeffs)
nij_pair, moij, ijslice = _conc_mos(mo_coeffs[0], mo_coeffs[1])[1:]
nkl_pair, mokl, klslice = _conc_mos(mo_coeffs[2], mo_coeffs[3])[1:]
max_memory *= .5
zij = zkl = None
for (LpqR, LpqI, jpqR, jpqI), (LrsR, LrsI, jrsR, jrsI) in \
lib.izip(mydf.sr_loop(kptijkl[:2], max_memory, False),
mydf.sr_loop(kptijkl[2:], max_memory, False)):
zij, zkl = _ztrans(LpqR+LpqI*1j, zij, moij, ijslice,
jrsR+jrsI*1j, zkl, mokl, klslice, False)
lib.dot(zij.T, zkl, 1, eri_mo, 1)
zij, zkl = _ztrans(jpqR+jpqI*1j, zij, moij, ijslice,
LrsR+LrsI*1j, zkl, mokl, klslice, False)
lib.dot(zij.T, zkl, 1, eri_mo, 1)
LpqR = LpqI = jpqR = jpqI = LrsR = LrsI = jrsR = jrsI = None
return eri_mo
开发者ID:eronca,项目名称:pyscf,代码行数:100,代码来源:mdf_ao2mo.py
|
请发表评论