本文整理汇总了Python中pyscf.ao2mo._ao2mo.nr_e2函数的典型用法代码示例。如果您正苦于以下问题:Python nr_e2函数的具体用法?Python nr_e2怎么用?Python nr_e2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了nr_e2函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: vind
def vind(xys):
nz = len(xys)
if wfnsym is not None and mol.symmetry:
# shape(nz,2,nocc,nvir): 2 ~ X,Y
xys = numpy.copy(xys).reshape(nz,2,nocc,nvir)
xys[:,:,sym_forbid] = 0
dms = numpy.empty((nz,nao,nao))
for i in range(nz):
x, y = xys[i].reshape(2,nocc,nvir)
# *2 for double occupancy
dmx = reduce(numpy.dot, (orbo, x*2, orbv.T))
dmy = reduce(numpy.dot, (orbv, y.T*2, orbo.T))
dms[i] = dmx + dmy # AX + BY
v1ao = vresp(dms)
v1ov = _ao2mo.nr_e2(v1ao, mo_coeff, (0,nocc,nocc,nmo)).reshape(-1,nocc,nvir)
v1vo = _ao2mo.nr_e2(v1ao, mo_coeff, (nocc,nmo,0,nocc)).reshape(-1,nvir,nocc)
hx = numpy.empty((nz,2,nocc,nvir), dtype=v1ov.dtype)
for i in range(nz):
x, y = xys[i].reshape(2,nocc,nvir)
hx[i,0] = v1ov[i]
hx[i,0]+= numpy.einsum('sp,qs->qp', fvv, x) # AX
hx[i,0]-= numpy.einsum('sp,pr->sr', foo, x) # AX
hx[i,1] =-v1vo[i].T
hx[i,1]-= numpy.einsum('sp,qs->qp', fvv, y) #-AY
hx[i,1]+= numpy.einsum('sp,pr->sr', foo, y) #-AY
if wfnsym is not None and mol.symmetry:
hx[:,:,sym_forbid] = 0
return hx.reshape(nz,-1)
开发者ID:chrinide,项目名称:pyscf,代码行数:30,代码来源:rhf.py
示例2: vind
def vind(mo1):
mo1aa, mo1ab, mo1ba, mo1bb = _split_mo1(mo1)
dm1aa = _dm1_mo2ao(mo1aa, orbva, orboa)
dm1ab = _dm1_mo2ao(mo1ab, orbva, orbob)
dm1ba = _dm1_mo2ao(mo1ba, orbvb, orboa)
dm1bb = _dm1_mo2ao(mo1bb, orbvb, orbob)
dm1 = lib.asarray([dm1aa+dm1aa.transpose(0,2,1),
dm1ab+dm1ba.transpose(0,2,1),
dm1ba+dm1ab.transpose(0,2,1),
dm1bb+dm1bb.transpose(0,2,1)])
v1 = vresp(dm1)
v1aa = _ao2mo.nr_e2(v1[0], mo_va_oa, (0,nvira,nvira,nvira+nocca))
v1ab = _ao2mo.nr_e2(v1[1], mo_va_ob, (0,nvira,nvira,nvira+noccb))
v1ba = _ao2mo.nr_e2(v1[2], mo_vb_oa, (0,nvirb,nvirb,nvirb+nocca))
v1bb = _ao2mo.nr_e2(v1[3], mo_vb_ob, (0,nvirb,nvirb,nvirb+noccb))
v1aa = v1aa.reshape(nset,nvira,nocca)
v1ab = v1ab.reshape(nset,nvira,noccb)
v1ba = v1ba.reshape(nset,nvirb,nocca)
v1bb = v1bb.reshape(nset,nvirb,noccb)
v1aa *= eai_aa
v1ab *= eai_ab
v1ba *= eai_ba
v1bb *= eai_bb
v1mo = numpy.hstack((v1aa.reshape(nset,-1),
v1ab.reshape(nset,-1),
v1ba.reshape(nset,-1),
v1bb.reshape(nset,-1)))
return v1mo.ravel()
开发者ID:chrinide,项目名称:pyscf,代码行数:28,代码来源:uhf.py
示例3: _trans_aapp_
def _trans_aapp_(mo, ncore, ncas, fload, ao_loc=None):
nmo = mo[0].shape[1]
nocc = (ncore[0] + ncas, ncore[1] + ncas)
c_nmo = ctypes.c_int(nmo)
klshape = (0, nmo, 0, nmo)
japcv = numpy.empty((ncas,nmo,ncore[0],nmo-ncore[0]))
aapp = numpy.empty((ncas,ncas,nmo,nmo))
aaPP = numpy.empty((ncas,ncas,nmo,nmo))
appa = numpy.empty((ncas,nmo,nmo,ncas))
apPA = numpy.empty((ncas,nmo,nmo,ncas))
apCV = numpy.empty((ncas,nmo,ncore[1],nmo-ncore[1]))
ppp = numpy.empty((nmo,nmo,nmo))
for i in range(ncas):
buf = _ao2mo.nr_e2(fload(ncore[0]+i), mo[0], klshape,
aosym='s4', mosym='s2', ao_loc=ao_loc)
lib.unpack_tril(buf, out=ppp)
aapp[i] = ppp[ncore[0]:nocc[0]]
appa[i] = ppp[:,:,ncore[0]:nocc[0]]
#japcp = avcp * 2 - acpv.transpose(0,2,1,3) - avcp.transpose(0,3,2,1)
japcv[i] = ppp[:,:ncore[0],ncore[0]:] * 2 \
- ppp[:ncore[0],:,ncore[0]:].transpose(1,0,2) \
- ppp[ncore[0]:,:ncore[0],:].transpose(2,1,0)
buf = _ao2mo.nr_e2(fload(ncore[0]+i), mo[1], klshape,
aosym='s4', mosym='s2', ao_loc=ao_loc)
lib.unpack_tril(buf, out=ppp)
aaPP[i] = ppp[ncore[0]:nocc[0]]
apPA[i] = ppp[:,:,ncore[1]:nocc[1]]
apCV[i] = ppp[:,:ncore[1],ncore[1]:]
return aapp, aaPP, appa, apPA, japcv, apCV
开发者ID:eronca,项目名称:pyscf,代码行数:33,代码来源:mc_ao2mo_uhf.py
示例4: vind
def vind(mo1):
mo1a = mo1.reshape(-1,nova+novb)[:,:nova].reshape(-1,nvira,nocca)
mo1b = mo1.reshape(-1,nova+novb)[:,nova:].reshape(-1,nvirb,noccb)
nset = mo1a.shape[0]
dm1a = _dm1_mo2ao(mo1a, orbva, orboa)
dm1b = _dm1_mo2ao(mo1b, orbvb, orbob)
dm1 = numpy.vstack([dm1a-dm1a.transpose(0,2,1),
dm1b-dm1b.transpose(0,2,1)])
v1 = vresp(dm1)
v1a = _ao2mo.nr_e2(v1[ :nset], mo_va_oa, (0,nvira,nvira,nvira+nocca))
v1b = _ao2mo.nr_e2(v1[nset: ], mo_vb_ob, (0,nvirb,nvirb,nvirb+noccb))
v1mo = numpy.hstack((v1a.reshape(nset,-1), v1b.reshape(nset,-1)))
return v1mo.ravel()
开发者ID:chrinide,项目名称:pyscf,代码行数:13,代码来源:test_uhf.py
示例5: trans_e1_incore
def trans_e1_incore(eri_ao, mo, ncore, ncas):
nmo = mo.shape[1]
nocc = ncore + ncas
eri1 = pyscf.ao2mo.incore.half_e1(eri_ao, (mo,mo[:,:nocc]), compact=False)
eri1 = eri1.reshape(nmo,nocc,-1)
klppshape = (0, nmo, 0, nmo)
klpashape = (0, nmo, ncore, nocc)
aapp = numpy.empty((ncas,ncas,nmo,nmo))
for i in range(ncas):
_ao2mo.nr_e2(eri1[ncore+i,ncore:nocc], mo, klppshape,
aosym='s4', mosym='s1', out=aapp[i])
ppaa = pyscf.lib.transpose(aapp.reshape(ncas*ncas,-1)).reshape(nmo,nmo,ncas,ncas)
aapp = None
papa = numpy.empty((nmo,ncas,nmo,ncas))
for i in range(nmo):
_ao2mo.nr_e2(eri1[i,ncore:nocc], mo, klpashape,
aosym='s4', mosym='s1', out=papa[i])
pp = numpy.empty((nmo,nmo))
j_cp = numpy.zeros((ncore,nmo))
k_pc = numpy.zeros((nmo,ncore))
for i in range(ncore):
_ao2mo.nr_e2(eri1[i,i:i+1], mo, klppshape, aosym='s4', mosym='s1', out=pp)
j_cp[i] = pp.diagonal()
j_pc = j_cp.T.copy()
pp = numpy.empty((ncore,ncore))
for i in range(nmo):
klshape = (i, i+1, 0, ncore)
_ao2mo.nr_e2(eri1[i,:ncore], mo, klshape, aosym='s4', mosym='s1', out=pp)
k_pc[i] = pp.diagonal()
return j_pc, k_pc, ppaa, papa
开发者ID:berquist,项目名称:pyscf,代码行数:34,代码来源:mc_ao2mo.py
示例6: vind
def vind(mo1):
dm1 = _dm1_mo2ao(mo1.reshape(nset,nvir,nocc), orbv, orbo*2) # *2 for double occupancy
dm1 = dm1 + dm1.transpose(0,2,1)
v1 = vresp(dm1)
v1 = _ao2mo.nr_e2(v1, mo_v_o, (0,nvir,nvir,nmo)).reshape(nset,nvir,nocc)
v1 *= eai
return v1.ravel()
开发者ID:chrinide,项目名称:pyscf,代码行数:7,代码来源:rhf.py
示例7: get_vind
def get_vind(self, zs):
mol = self.mol
mo_coeff = self._scf.mo_coeff
mo_energy = self._scf.mo_energy
nao, nmo = mo_coeff.shape
nocc = (self._scf.mo_occ>0).sum()
nvir = nmo - nocc
orbv = mo_coeff[:,nocc:]
orbo = mo_coeff[:,:nocc]
eai = pyscf.lib.direct_sum('a-i->ai', mo_energy[nocc:], mo_energy[:nocc])
dai = numpy.sqrt(eai).ravel()
nz = len(zs)
dmvo = numpy.empty((nz,nao,nao))
for i, z in enumerate(zs):
dm = reduce(numpy.dot, (orbv, (dai*z).reshape(nvir,nocc), orbo.T))
dmvo[i] = dm + dm.T # +cc for A+B and K_{ai,jb} in A == K_{ai,bj} in B
mem_now = pyscf.lib.current_memory()[0]
max_memory = max(2000, self.max_memory*.9-mem_now)
v1ao = _contract_xc_kernel(self, self._scf.xc, dmvo,
singlet=self.singlet, max_memory=max_memory)
if self.singlet:
vj = self._scf.get_j(mol, dmvo, hermi=1)
v1ao += vj * 2
v1vo = _ao2mo.nr_e2(v1ao, mo_coeff, (nocc,nmo,0,nocc)).reshape(-1,nvir*nocc)
edai = eai.ravel() * dai
for i, z in enumerate(zs):
# numpy.sqrt(eai) * (eai*dai*z + v1vo)
v1vo[i] += edai*z
v1vo[i] *= dai
return v1vo.reshape(nz,-1)
开发者ID:berquist,项目名称:pyscf,代码行数:34,代码来源:rks.py
示例8: _trans
def _trans(mo, ncore, ncas, fload, cvcv=None, ao_loc=None):
nao, nmo = mo.shape
nocc = ncore + ncas
nvir = nmo - nocc
nav = nmo - ncore
if cvcv is None:
cvcv = numpy.zeros((ncore*nvir,ncore*nvir))
pacv = numpy.empty((nmo,ncas,ncore*nvir))
aapp = numpy.empty((ncas,ncas,nmo*nmo))
papa = numpy.empty((nmo,ncas,nmo*ncas))
vcv = numpy.empty((nav,ncore*nvir))
apa = numpy.empty((ncas,nmo*ncas))
vpa = numpy.empty((nav,nmo*ncas))
app = numpy.empty((ncas,nmo*nmo))
for i in range(ncore):
buf = fload(i, i+1)
klshape = (0, ncore, nocc, nmo)
_ao2mo.nr_e2(buf, mo, klshape,
aosym='s4', mosym='s1', out=vcv, ao_loc=ao_loc)
cvcv[i*nvir:(i+1)*nvir] = vcv[ncas:]
pacv[i] = vcv[:ncas]
klshape = (0, nmo, ncore, nocc)
_ao2mo.nr_e2(buf[:ncas], mo, klshape,
aosym='s4', mosym='s1', out=apa, ao_loc=ao_loc)
papa[i] = apa
for i in range(ncas):
buf = fload(ncore+i, ncore+i+1)
klshape = (0, ncore, nocc, nmo)
_ao2mo.nr_e2(buf, mo, klshape,
aosym='s4', mosym='s1', out=vcv, ao_loc=ao_loc)
pacv[ncore:,i] = vcv
klshape = (0, nmo, ncore, nocc)
_ao2mo.nr_e2(buf, mo, klshape,
aosym='s4', mosym='s1', out=vpa, ao_loc=ao_loc)
papa[ncore:,i] = vpa
klshape = (0, nmo, 0, nmo)
_ao2mo.nr_e2(buf[:ncas], mo, klshape,
aosym='s4', mosym='s1', out=app, ao_loc=ao_loc)
aapp[i] = app
#pyscf.lib.transpose(aapp.reshape(ncas**2, -1), inplace=True)
ppaa = pyscf.lib.transpose(aapp.reshape(ncas**2,-1))
return (ppaa.reshape(nmo,nmo,ncas,ncas), papa.reshape(nmo,ncas,nmo,ncas),
pacv.reshape(nmo,ncas,ncore,nvir), cvcv)
开发者ID:ushnishray,项目名称:pyscf,代码行数:47,代码来源:icmpspt.py
示例9: loop_ao2mo
def loop_ao2mo(self, mo_coeff, nocc):
mo = numpy.asarray(mo_coeff, order='F')
nmo = mo.shape[1]
ijslice = (0, nocc, nocc, nmo)
Lov = None
for eri1 in self._scf.with_df.loop():
Lov = _ao2mo.nr_e2(eri1, mo, ijslice, aosym='s2', out=Lov)
yield Lov
开发者ID:eronca,项目名称:pyscf,代码行数:8,代码来源:dfmp2.py
示例10: ao2mo
def ao2mo(self, mo_coeffs, compact=True):
if isinstance(mo_coeffs, numpy.ndarray) and mo_coeffs.ndim == 2:
mo_coeffs = (mo_coeffs,) * 4
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)
mo_eri = numpy.zeros((nij_pair,nkl_pair))
sym = (iden_coeffs(mo_coeffs[0], mo_coeffs[2]) and
iden_coeffs(mo_coeffs[1], mo_coeffs[3]))
Lij = Lkl = None
for eri1 in self.loop():
Lij = _ao2mo.nr_e2(eri1, moij, ijslice, aosym='s2', mosym=ijmosym, out=Lij)
if sym:
Lkl = Lij
else:
Lkl = _ao2mo.nr_e2(eri1, mokl, klslice, aosym='s2', mosym=klmosym, out=Lkl)
lib.dot(Lij.T, Lkl, 1, mo_eri, 1)
return mo_eri
开发者ID:eronca,项目名称:pyscf,代码行数:17,代码来源:df.py
示例11: _trans_aapp_
def _trans_aapp_(mo, ncore, ncas, fload, ao_loc=None):
nmo = mo[0].shape[1]
nocc = (ncore[0] + ncas, ncore[1] + ncas)
c_nmo = ctypes.c_int(nmo)
funpack = pyscf.lib.numpy_helper._np_helper.NPdunpack_tril
klshape = (0, nmo, 0, nmo)
japcv = numpy.empty((ncas,nmo,ncore[0],nmo-ncore[0]))
aapp = numpy.empty((ncas,ncas,nmo,nmo))
aaPP = numpy.empty((ncas,ncas,nmo,nmo))
appa = numpy.empty((ncas,nmo,nmo,ncas))
apPA = numpy.empty((ncas,nmo,nmo,ncas))
apCV = numpy.empty((ncas,nmo,ncore[1],nmo-ncore[1]))
ppp = numpy.empty((nmo,nmo,nmo))
for i in range(ncas):
buf = _ao2mo.nr_e2(fload(ncore[0]+i), mo[0], klshape,
aosym='s4', mosym='s2', ao_loc=ao_loc)
for j in range(nmo):
funpack(c_nmo, buf[j].ctypes.data_as(ctypes.c_void_p),
ppp[j].ctypes.data_as(ctypes.c_void_p), ctypes.c_int(1))
aapp[i] = ppp[ncore[0]:nocc[0]]
appa[i] = ppp[:,:,ncore[0]:nocc[0]]
#japcp = avcp * 2 - acpv.transpose(0,2,1,3) - avcp.transpose(0,3,2,1)
japcv[i] = ppp[:,:ncore[0],ncore[0]:] * 2 \
- ppp[:ncore[0],:,ncore[0]:].transpose(1,0,2) \
- ppp[ncore[0]:,:ncore[0],:].transpose(2,1,0)
buf = _ao2mo.nr_e2(fload(ncore[0]+i), mo[1], klshape,
aosym='s4', mosym='s2', ao_loc=ao_loc)
for j in range(nmo):
funpack(c_nmo, buf[j].ctypes.data_as(ctypes.c_void_p),
ppp[j].ctypes.data_as(ctypes.c_void_p), ctypes.c_int(1))
aaPP[i] = ppp[ncore[0]:nocc[0]]
apPA[i] = ppp[:,:,ncore[1]:nocc[1]]
apCV[i] = ppp[:,:ncore[1],ncore[1]:]
return aapp, aaPP, appa, apPA, japcv, apCV
开发者ID:berquist,项目名称:pyscf,代码行数:38,代码来源:mc_ao2mo_uhf.py
示例12: vind
def vind(zs):
nz = len(zs)
dmov = numpy.empty((nz,nao,nao))
for i, z in enumerate(zs):
# *2 for double occupancy
dm = reduce(numpy.dot, (orbo, (d_ia*z).reshape(nocc,nvir)*2, orbv.T))
dmov[i] = dm + dm.T # +cc for A+B and K_{ai,jb} in A == K_{ai,bj} in B
v1ao = vresp(dmov)
v1ov = _ao2mo.nr_e2(v1ao, mo_coeff, (0,nocc,nocc,nmo)).reshape(-1,nocc*nvir)
for i, z in enumerate(zs):
# numpy.sqrt(e_ia) * (e_ia*d_ia*z + v1ov)
v1ov[i] += ed_ia*z
v1ov[i] *= d_ia
return v1ov.reshape(nz,-1)
开发者ID:chrinide,项目名称:pyscf,代码行数:14,代码来源:rks.py
示例13: vind
def vind(zs):
nz = len(zs)
if wfnsym is not None and mol.symmetry:
zs = numpy.copy(zs)
zs[:,sym_forbid] = 0
dmov = numpy.empty((2,nz,nao,nao))
for i in range(nz):
z = d_ia * zs[i]
za = z[:nocca*nvira].reshape(nocca,nvira)
zb = z[nocca*nvira:].reshape(noccb,nvirb)
dm = reduce(numpy.dot, (orboa, za, orbva.T))
dmov[0,i] = dm + dm.T
dm = reduce(numpy.dot, (orbob, zb, orbvb.T))
dmov[1,i] = dm + dm.T
v1ao = vresp(dmov)
v1a = _ao2mo.nr_e2(v1ao[0], mo_coeff[0], (0,nocca,nocca,nmo))
v1b = _ao2mo.nr_e2(v1ao[1], mo_coeff[1], (0,noccb,noccb,nmo))
hx = numpy.hstack((v1a.reshape(nz,-1), v1b.reshape(nz,-1)))
for i, z in enumerate(zs):
hx[i] += ed_ia * z
hx[i] *= d_ia
return hx
开发者ID:chrinide,项目名称:pyscf,代码行数:23,代码来源:uks.py
示例14: loop_ao2mo
def loop_ao2mo(self, mo_coeff, nocc):
mo = numpy.asarray(mo_coeff, order='F')
nmo = mo.shape[1]
ijslice = (0, nocc, nocc, nmo)
Lov = None
with_df = self.with_df
nvir = nmo - nocc
naux = with_df.get_naoaux()
mem_now = lib.current_memory()[0]
max_memory = max(2000, self.max_memory*.9-mem_now)
blksize = int(min(naux, max(with_df.blockdim,
(max_memory*1e6/8-nocc*nvir**2*2)/(nocc*nvir))))
for eri1 in with_df.loop(blksize=blksize):
Lov = _ao2mo.nr_e2(eri1, mo, ijslice, aosym='s2', out=Lov)
yield Lov
开发者ID:chrinide,项目名称:pyscf,代码行数:16,代码来源:dfmp2.py
示例15: _exact_paaa
def _exact_paaa(self, mo, u, out=None):
if self.with_df:
nmo = mo.shape[1]
ncore = self.ncore
ncas = self.ncas
nocc = ncore + ncas
mo1 = numpy.dot(mo, u)
mo1_cas = mo1[:,ncore:nocc]
paaa = numpy.zeros((nmo*ncas,ncas*ncas))
moij = numpy.asarray(numpy.hstack((mo1, mo1_cas)), order='F')
ijshape = (0, nmo, nmo, nmo+ncas)
for eri1 in self.with_df.loop():
bufpa = _ao2mo.nr_e2(eri1, moij, ijshape, 's2', 's1')
bufaa = numpy.asarray(buf1[ncore:nocc,:], order='C')
pyscf.lib.dot(bufpa.T, bufaa, 1, paaa, 1)
return paaa.reshape(nmo,ncas,ncas,ncas)
else:
return casscf_class._exact_paaa(self, mol, u, out)
开发者ID:berquist,项目名称:pyscf,代码行数:19,代码来源:df.py
示例16: _trans_cvcv_
def _trans_cvcv_(mo, ncore, ncas, fload, ao_loc=None):
nmo = mo[0].shape[1]
c_nmo = ctypes.c_int(nmo)
funpack = pyscf.lib.numpy_helper._np_helper.NPdunpack_tril
jc_pp = numpy.empty((ncore[0],nmo,nmo))
jc_PP = numpy.zeros((nmo,nmo))
kc_pp = numpy.empty((ncore[0],nmo,nmo))
jcvcv = numpy.zeros((ncore[0],nmo-ncore[0],ncore[0],nmo-ncore[0]))
cvCV = numpy.empty((ncore[0],nmo-ncore[0],ncore[1],nmo-ncore[1]))
vcp = numpy.empty((nmo-ncore[0],ncore[0],nmo))
cpp = numpy.empty((ncore[0],nmo,nmo))
for i in range(ncore[0]):
buf = fload(i)
klshape = (0, ncore[1], ncore[1], nmo)
_ao2mo.nr_e2(buf[ncore[0]:nmo], mo[1], klshape,
aosym='s4', mosym='s1', out=cvCV[i], ao_loc=ao_loc)
klshape = (0, nmo, 0, nmo)
tmp = _ao2mo.nr_e2(buf[i:i+1], mo[1], klshape, aosym='s4',
mosym='s1', ao_loc=ao_loc)
jc_PP += tmp.reshape(nmo,nmo)
klshape = (0, ncore[0], 0, nmo)
_ao2mo.nr_e2(buf[ncore[0]:nmo], mo[0], klshape,
aosym='s4', mosym='s1', out=vcp, ao_loc=ao_loc)
kc_pp[i,ncore[0]:] = vcp[:,i]
klshape = (0, nmo, 0, nmo)
_ao2mo.nr_e2(buf[:ncore[0]], mo[0], klshape,
aosym='s4', mosym='s2', out=buf[:ncore[0]],
ao_loc=ao_loc)
for j in range(ncore[0]):
funpack(c_nmo, buf[j].ctypes.data_as(ctypes.c_void_p),
cpp[j].ctypes.data_as(ctypes.c_void_p), ctypes.c_int(1))
jc_pp[i] = cpp[i]
kc_pp[i,:ncore[0]] = cpp[:,i]
#jcvcv = cvcv * 2 - cvcv.transpose(2,1,0,3) - ccvv.transpose(0,2,1,3)
jcvcv[i] = vcp[:,:,ncore[0]:] * 2 \
- vcp[:,:,ncore[0]:].transpose(2,1,0) \
- cpp[:,ncore[0]:,ncore[0]:].transpose(1,0,2)
return jc_pp, jc_PP, kc_pp, jcvcv, cvCV
开发者ID:berquist,项目名称:pyscf,代码行数:44,代码来源:mc_ao2mo_uhf.py
示例17: _add_vvVV
def _add_vvVV(mycc, t1, t2ab, eris, out=None):
'''Ht2 = np.einsum('iJcD,acBD->iJaB', t2ab, vvVV)
without using symmetry in t2ab or Ht2
'''
time0 = time.clock(), time.time()
if t2ab.size == 0:
return np.zeros_like(t2ab)
if t1 is not None:
t2ab = make_tau_ab(t2ab, t1, t1)
log = logger.Logger(mycc.stdout, mycc.verbose)
nocca, noccb, nvira, nvirb = t2ab.shape
if mycc.direct: # AO direct CCSD
if getattr(eris, 'mo_coeff', None) is not None:
mo_a, mo_b = eris.mo_coeff
else:
moidxa, moidxb = mycc.get_frozen_mask()
mo_a = mycc.mo_coeff[0][:,moidxa]
mo_b = mycc.mo_coeff[1][:,moidxb]
# Note tensor t2ab may be t2bbab from eom_uccsd code. In that
# particular case, nocca, noccb do not equal to the actual number of
# alpha/beta occupied orbitals. orbva and orbvb cannot be indexed as
# mo_a[:,nocca:] and mo_b[:,noccb:]
orbva = mo_a[:,-nvira:]
orbvb = mo_b[:,-nvirb:]
tau = lib.einsum('ijab,pa->ijpb', t2ab, orbva)
tau = lib.einsum('ijab,pb->ijap', tau, orbvb)
time0 = logger.timer_debug1(mycc, 'vvvv-tau mo2ao', *time0)
buf = eris._contract_vvVV_t2(mycc, tau, mycc.direct, out, log)
mo = np.asarray(np.hstack((orbva, orbvb)), order='F')
Ht2 = _ao2mo.nr_e2(buf.reshape(nocca*noccb,-1), mo.conj(),
(0,nvira,nvira,nvira+nvirb), 's1', 's1')
return Ht2.reshape(t2ab.shape)
else:
return eris._contract_vvVV_t2(mycc, t2ab, mycc.direct, out, log)
开发者ID:wmizukami,项目名称:pyscf,代码行数:36,代码来源:uccsd.py
示例18: kernel
def kernel(mp, t2, atmlst=None, mf_grad=None, verbose=logger.INFO):
if mf_grad is None: mf_grad = mp._scf.nuc_grad_method()
log = logger.new_logger(mp, verbose)
time0 = time.clock(), time.time()
log.debug('Build mp2 rdm1 intermediates')
d1 = mp2._gamma1_intermediates(mp, t2)
doo, dvv = d1
time1 = log.timer_debug1('rdm1 intermediates', *time0)
# Set nocc, nvir for half-transformation of 2pdm. Frozen orbitals are exculded.
# nocc, nvir should be updated to include the frozen orbitals when proceeding
# the 1-particle quantities later.
mol = mp.mol
with_frozen = not (mp.frozen is None or mp.frozen is 0)
OA, VA, OF, VF = _index_frozen_active(mp.get_frozen_mask(), mp.mo_occ)
orbo = mp.mo_coeff[:,OA]
orbv = mp.mo_coeff[:,VA]
nao, nocc = orbo.shape
nvir = orbv.shape[1]
# Partially transform MP2 density matrix and hold it in memory
# The rest transformation are applied during the contraction to ERI integrals
part_dm2 = _ao2mo.nr_e2(t2.reshape(nocc**2,nvir**2),
numpy.asarray(orbv.T, order='F'), (0,nao,0,nao),
's1', 's1').reshape(nocc,nocc,nao,nao)
part_dm2 = (part_dm2.transpose(0,2,3,1) * 4 -
part_dm2.transpose(0,3,2,1) * 2)
hf_dm1 = mp._scf.make_rdm1(mp.mo_coeff, mp.mo_occ)
if atmlst is None:
atmlst = range(mol.natm)
offsetdic = mol.offset_nr_by_atom()
diagidx = numpy.arange(nao)
diagidx = diagidx*(diagidx+1)//2 + diagidx
de = numpy.zeros((len(atmlst),3))
Imat = numpy.zeros((nao,nao))
fdm2 = lib.H5TmpFile()
vhf1 = fdm2.create_dataset('vhf1', (len(atmlst),3,nao,nao), 'f8')
# 2e AO integrals dot 2pdm
max_memory = max(0, mp.max_memory - lib.current_memory()[0])
blksize = max(1, int(max_memory*.9e6/8/(nao**3*2.5)))
Imat1 = 0
Imat2 = 0
for k, ia in enumerate(atmlst):
shl0, shl1, p0, p1 = offsetdic[ia]
ip1 = p0
vhf = numpy.zeros((3,nao,nao))
for b0, b1, nf in _shell_prange(mol, shl0, shl1, blksize):
ip0, ip1 = ip1, ip1 + nf
dm2buf = lib.einsum('pi,iqrj->pqrj', orbo[ip0:ip1], part_dm2)
dm2buf+= lib.einsum('qi,iprj->pqrj', orbo, part_dm2[:,ip0:ip1])
dm2buf = lib.einsum('pqrj,sj->pqrs', dm2buf, orbo)
dm2buf = dm2buf + dm2buf.transpose(0,1,3,2)
dm2buf = lib.pack_tril(dm2buf.reshape(-1,nao,nao)).reshape(nf,nao,-1)
dm2buf[:,:,diagidx] *= .5
shls_slice = (b0,b1,0,mol.nbas,0,mol.nbas,0,mol.nbas)
eri0 = mol.intor('int2e', aosym='s2kl', shls_slice=shls_slice)
Imat += lib.einsum('ipx,iqx->pq', eri0.reshape(nf,nao,-1), dm2buf)
eri0 = None
eri1 = mol.intor('int2e_ip1', comp=3, aosym='s2kl',
shls_slice=shls_slice).reshape(3,nf,nao,-1)
de[k] -= numpy.einsum('xijk,ijk->x', eri1, dm2buf) * 2
dm2buf = None
# HF part
for i in range(3):
eri1tmp = lib.unpack_tril(eri1[i]).reshape(nf*nao,-1)
eri1tmp = eri1tmp.reshape(nf,nao,nao,nao)
vhf[i] += numpy.einsum('ijkl,ij->kl', eri1tmp, hf_dm1[ip0:ip1])
vhf[i] -= numpy.einsum('ijkl,il->kj', eri1tmp, hf_dm1[ip0:ip1]) * .5
vhf[i,ip0:ip1] += numpy.einsum('ijkl,kl->ij', eri1tmp, hf_dm1)
vhf[i,ip0:ip1] -= numpy.einsum('ijkl,jk->il', eri1tmp, hf_dm1) * .5
eri1 = eri1tmp = None
vhf1[k] = vhf
log.debug('2e-part grad of atom %d %s = %s', ia, mol.atom_symbol(ia), de[k])
time1 = log.timer_debug1('2e-part grad of atom %d'%ia, *time1)
# Recompute nocc, nvir to include the frozen orbitals and make contraction for
# the 1-particle quantities, see also the kernel function in ccsd_grad module.
mo_coeff = mp.mo_coeff
mo_energy = mp._scf.mo_energy
nao, nmo = mo_coeff.shape
nocc = numpy.count_nonzero(mp.mo_occ > 0)
Imat = reduce(numpy.dot, (mo_coeff.T, Imat, mp._scf.get_ovlp(), mo_coeff)) * -1
dm1mo = numpy.zeros((nmo,nmo))
if with_frozen:
dco = Imat[OF[:,None],OA] / (mo_energy[OF,None] - mo_energy[OA])
dfv = Imat[VF[:,None],VA] / (mo_energy[VF,None] - mo_energy[VA])
dm1mo[OA[:,None],OA] = doo + doo.T
dm1mo[OF[:,None],OA] = dco
dm1mo[OA[:,None],OF] = dco.T
dm1mo[VA[:,None],VA] = dvv + dvv.T
dm1mo[VF[:,None],VA] = dfv
#.........这里部分代码省略.........
开发者ID:chrinide,项目名称:pyscf,代码行数:101,代码来源:mp2.py
示例19: general
def general(mol, mo_coeffs, erifile, auxbasis='weigend+etb', dataname='eri_mo', tmpdir=None,
int3c='cint3c2e_sph', aosym='s2ij', int2c='cint2c2e_sph', comp=1,
max_memory=2000, ioblk_size=256, verbose=0, compact=True):
''' Transform ij of (ij|L) to MOs.
'''
assert(aosym in ('s1', 's2ij'))
time0 = (time.clock(), time.time())
if isinstance(verbose, logger.Logger):
log = verbose
else:
log = logger.Logger(mol.stdout, verbose)
swapfile = tempfile.NamedTemporaryFile(dir=tmpdir)
cholesky_eri_b(mol, swapfile.name, auxbasis, dataname,
int3c, aosym, int2c, comp, ioblk_size, verbose=log)
fswap = h5py.File(swapfile.name, 'r')
time1 = log.timer('AO->MO eri transformation 1 pass', *time0)
nmoi = mo_coeffs[0].shape[1]
nmoj = mo_coeffs[1].shape[1]
nao = mo_coeffs[0].shape[0]
auxmol = incore.format_aux_basis(mol, auxbasis)
naoaux = auxmol.nao_nr()
aosym = _stand_sym_code(aosym)
if aosym == 's1':
nao_pair = nao * nao
aosym_as_nr_e2 = 's1'
else:
nao_pair = nao * (nao+1) // 2
aosym_as_nr_e2 = 's2kl'
ijmosym, nij_pair, moij, ijshape = \
ao2mo.incore._conc_mos(mo_coeffs[0], mo_coeffs[1],
compact and aosym != 's1')
if h5py.is_hdf5(erifile):
feri = h5py.File(erifile)
if dataname in feri:
del(feri[dataname])
else:
feri = h5py.File(erifile, 'w')
if comp == 1:
chunks = (min(int(64e3/nmoj),naoaux), nmoj) # 512K
h5d_eri = feri.create_dataset(dataname, (naoaux,nij_pair), 'f8',
chunks=chunks)
else:
chunks = (1, min(int(64e3/nmoj),naoaux), nmoj) # 512K
h5d_eri = feri.create_dataset(dataname, (comp,naoaux,nij_pair), 'f8',
chunks=chunks)
aopairblks = len(fswap[dataname+'/0'])
iolen = min(int(ioblk_size*1e6/8/(nao_pair+nij_pair)), naoaux)
totstep = (naoaux+iolen-1)//iolen * comp
buf = numpy.empty((iolen, nao_pair))
ti0 = time1
for icomp in range(comp):
istep = 0
for row0, row1 in prange(0, naoaux, iolen):
nrow = row1 - row0
istep += 1
log.debug('step 2 [%d/%d], [%d,%d:%d], row = %d',
istep, totstep, icomp, row0, row1, nrow)
col0 = 0
for ic in range(aopairblks):
dat = fswap['%s/%d/%d'%(dataname,icomp,ic)]
col1 = col0 + dat.shape[1]
buf[:nrow,col0:col1] = dat[row0:row1]
col0 = col1
buf1 = _ao2mo.nr_e2(buf[:nrow], moij, ijshape, aosym_as_nr_e2, ijmosym)
if comp == 1:
h5d_eri[row0:row1] = buf1
else:
h5d_eri[icomp,row0:row1] = buf1
ti0 = log.timer('step 2 [%d/%d], [%d,%d:%d], row = %d'%
(istep, totstep, icomp, row0, row1, nrow), *ti0)
fswap.close()
feri.close()
log.timer('AO->MO CD eri transformation 2 pass', *time1)
log.timer('AO->MO CD eri transformation', *time0)
return erifile
开发者ID:berquist,项目名称:pyscf,代码行数:84,代码来源:outcore.py
示例20: general
def general(eri_ao, mo_coeffs, verbose=0, compact=True):
r'''For the given four sets of orbitals, transfer the 8-fold or 4-fold 2e
AO integrals to MO integrals.
Args:
eri_ao : ndarray
AO integrals, can be either 8-fold or 4-fold symmetry.
mo_coeffs : 4-item list of ndarray
Four sets of orbital coefficients, corresponding to the four
indices of (ij|kl)
Kwargs:
verbose : int
Print level
compact : bool
When compact is True, depending on the four oribital sets, the
returned MO integrals has (up to 4-fold) permutation symmetry.
If it's False, the function will abandon any permutation symmetry,
and return the "plain" MO integrals
Returns:
2D array of transformed MO integrals. The MO integrals may or may not
have the permutation symmetry, depending on the given orbitals, and
the kwargs compact. If the four sets of orbitals are identical, the
MO integrals will at most have 4-fold symmetry.
Examples:
>>> from pyscf import gto
>>> from pyscf.scf import _vhf
>>> from pyscf import ao2mo
>>> mol = gto.M(atom='O 0 0 0; H 0 1 0; H 0 0 1', basis='sto3g')
>>> eri = _vhf.int2e_sph(mol._atm, mol._bas, mol._env)
>>> mo1 = numpy.random.random((mol.nao_nr(), 10))
>>> mo2 = numpy.random.random((mol.nao_nr(), 8))
>>> mo3 = numpy.random.random((mol.nao_nr(), 6))
>>> mo4 = numpy.random.random((mol.nao_nr(), 4))
>>> eri1 = ao2mo.incore.general(eri, (mo1,mo2,mo3,mo4))
>>> print(eri1.shape)
(80, 24)
>>> eri1 = ao2mo.incore.general(eri, (mo1,mo2,mo3,mo3))
>>> print(eri1.shape)
(80, 21)
>>> eri1 = ao2mo.incore.general(eri, (mo1,mo2,mo3,mo3), compact=False)
>>> print(eri1.shape)
(80, 36)
>>> eri1 = ao2mo.incore.general(eri, (mo1,mo1,mo2,mo2))
>>> print(eri1.shape)
(55, 36)
>>> eri1 = ao2mo.incore.general(eri, (mo1,mo2,mo1,mo2))
>>> print(eri1.shape)
(80, 80)
'''
if isinstance(verbose, logger.Logger):
log = verbose
else:
log = logger.Logger(sys.stdout, verbose)
nao = mo_coeffs[0].shape[0]
nao_pair = nao*(nao+1)//2
assert(eri_ao.size in (nao_pair**2, nao_pair*(nao_pair+1)//2))
# transform e1
eri1 = half_e1(eri_ao, mo_coeffs, compact)
klmosym, nkl_pair, mokl, klshape = _conc_mos(mo_coeffs[2], mo_coeffs[3], compact)
if eri1.shape[0] == 0 or nkl_pair == 0:
# 0 dimension sometimes causes blas problem
return numpy.zeros((nij_pair,nkl_pair))
# if nij_pair > nkl_pair:
# log.warn('low efficiency for AO to MO trans!')
# transform e2
eri1 = _ao2mo.nr_e2(eri1, mokl, klshape, aosym='s4', mosym=klmosym)
return eri1
开发者ID:berquist,项目名称:pyscf,代码行数:78,代码来源:incore.py
注:本文中的pyscf.ao2mo._ao2mo.nr_e2函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论