def _call_vhf1(mol, dm): c1 = .5 / lib.param.LIGHT_SPEED n2c = dm.shape[0] // 2 dmll = dm[:n2c,:n2c].copy() dmls = dm[:n2c,n2c:].copy() dmsl = dm[n2c:,:n2c].copy() dmss = dm[n2c:,n2c:].copy() vj = numpy.zeros((3,n2c*2,n2c*2), dtype=numpy.complex) vk = numpy.zeros((3,n2c*2,n2c*2), dtype=numpy.complex) vj[:,:n2c,:n2c], vk[:,:n2c,:n2c] = \ _vhf.rdirect_mapdm('int2e_ip1_spinor', 's2kl', ('lk->s1ij', 'jk->s1il'), dmll, 3, mol._atm, mol._bas, mol._env) vj[:,n2c:,n2c:], vk[:,n2c:,n2c:] = \ _vhf.rdirect_mapdm('int2e_ipspsp1spsp2_spinor', 's2kl', ('lk->s1ij', 'jk->s1il'), dmss, 3, mol._atm, mol._bas, mol._env) * c1**4 vx = _vhf.rdirect_bindm('int2e_ipspsp1_spinor', 's2kl', ('lk->s1ij', 'jk->s1il'), (dmll, dmsl), 3, mol._atm, mol._bas, mol._env) * c1**2 vj[:,n2c:,n2c:] += vx[0] vk[:,n2c:,:n2c] += vx[1] vx = _vhf.rdirect_bindm('int2e_ip1spsp2_spinor', 's2kl', ('lk->s1ij', 'jk->s1il'), (dmss, dmls), 3, mol._atm, mol._bas, mol._env) * c1**2 vj[:,:n2c,:n2c] += vx[0] vk[:,:n2c,n2c:] += vx[1] return vj, vk
def _call_giao_vhf1(mol, dm): c1 = .5/mol.light_speed n2c = dm.shape[0] // 2 dmll = dm[:n2c,:n2c].copy() dmls = dm[:n2c,n2c:].copy() dmsl = dm[n2c:,:n2c].copy() dmss = dm[n2c:,n2c:].copy() vj = numpy.zeros((3,n2c*2,n2c*2), dtype=numpy.complex) vk = numpy.zeros((3,n2c*2,n2c*2), dtype=numpy.complex) vx = _vhf.rdirect_mapdm('cint2e_g1', 'a4ij', ('lk->s2ij', 'jk->s1il'), dmll, 3, mol._atm, mol._bas, mol._env) vj[:,:n2c,:n2c] = vx[0] vk[:,:n2c,:n2c] = vx[1] vx = _vhf.rdirect_mapdm('cint2e_spgsp1spsp2', 'a4ij', ('lk->s2ij', 'jk->s1il'), dmss, 3, mol._atm, mol._bas, mol._env) * c1**4 vj[:,n2c:,n2c:] = vx[0] vk[:,n2c:,n2c:] = vx[1] vx = _vhf.rdirect_bindm('cint2e_g1spsp2', 'a4ij', ('lk->s2ij', 'jk->s1il'), (dmss,dmls), 3, mol._atm, mol._bas, mol._env) * c1**2 vj[:,:n2c,:n2c] += vx[0] vk[:,:n2c,n2c:] += vx[1] vx = _vhf.rdirect_bindm('cint2e_spgsp1', 'a4ij', ('lk->s2ij', 'jk->s1il'), (dmll,dmsl), 3, mol._atm, mol._bas, mol._env) * c1**2 vj[:,n2c:,n2c:] += vx[0] vk[:,n2c:,:n2c] += vx[1] for i in range(3): vj[i] = pyscf.lib.hermi_triu(vj[i], 1) vk[i] = vk[i] + vk[i].T.conj() return vj, vk
def _call_giao_vhf1(mol, dm): c1 = .5 / mol.light_speed n2c = dm.shape[0] // 2 dmll = dm[:n2c, :n2c].copy() dmls = dm[:n2c, n2c:].copy() dmsl = dm[n2c:, :n2c].copy() dmss = dm[n2c:, n2c:].copy() vj = numpy.zeros((3, n2c * 2, n2c * 2), dtype=numpy.complex) vk = numpy.zeros((3, n2c * 2, n2c * 2), dtype=numpy.complex) vx = _vhf.rdirect_mapdm('cint2e_g1', 'a4ij', ('lk->s2ij', 'jk->s1il'), dmll, 3, mol._atm, mol._bas, mol._env) vj[:, :n2c, :n2c] = vx[0] vk[:, :n2c, :n2c] = vx[1] vx = _vhf.rdirect_mapdm('cint2e_spgsp1spsp2', 'a4ij', ('lk->s2ij', 'jk->s1il'), dmss, 3, mol._atm, mol._bas, mol._env) * c1**4 vj[:, n2c:, n2c:] = vx[0] vk[:, n2c:, n2c:] = vx[1] vx = _vhf.rdirect_bindm('cint2e_g1spsp2', 'a4ij', ('lk->s2ij', 'jk->s1il'), (dmss, dmls), 3, mol._atm, mol._bas, mol._env) * c1**2 vj[:, :n2c, :n2c] += vx[0] vk[:, :n2c, n2c:] += vx[1] vx = _vhf.rdirect_bindm('cint2e_spgsp1', 'a4ij', ('lk->s2ij', 'jk->s1il'), (dmll, dmsl), 3, mol._atm, mol._bas, mol._env) * c1**2 vj[:, n2c:, n2c:] += vx[0] vk[:, n2c:, :n2c] += vx[1] for i in range(3): vj[i] = pyscf.lib.hermi_triu(vj[i], 1) vk[i] = vk[i] + vk[i].T.conj() return vj, vk
def _call_vhf1(mol, dm): c1 = .5/mol.light_speed n2c = dm.shape[0] // 2 dmll = dm[:n2c,:n2c].copy() dmls = dm[:n2c,n2c:].copy() dmsl = dm[n2c:,:n2c].copy() dmss = dm[n2c:,n2c:].copy() vj = numpy.zeros((3,n2c*2,n2c*2), dtype=numpy.complex) vk = numpy.zeros((3,n2c*2,n2c*2), dtype=numpy.complex) vj[:,:n2c,:n2c], vk[:,:n2c,:n2c] = \ _vhf.rdirect_mapdm('cint2e_ip1', 's2kl', ('lk->s1ij', 'jk->s1il'), dmll, 3, mol._atm, mol._bas, mol._env) vj[:,n2c:,n2c:], vk[:,n2c:,n2c:] = \ _vhf.rdirect_mapdm('cint2e_ipspsp1spsp2', 's2kl', ('lk->s1ij', 'jk->s1il'), dmss, 3, mol._atm, mol._bas, mol._env) * c1**4 vx = _vhf.rdirect_bindm('cint2e_ipspsp1', 's2kl', ('lk->s1ij', 'jk->s1il'), (dmll, dmsl), 3, mol._atm, mol._bas, mol._env) * c1**2 vj[:,n2c:,n2c:] += vx[0] vk[:,n2c:,:n2c] += vx[1] vx = _vhf.rdirect_bindm('cint2e_ip1spsp2', 's2kl', ('lk->s1ij', 'jk->s1il'), (dmss, dmls), 3, mol._atm, mol._bas, mol._env) * c1**2 vj[:,:n2c,:n2c] += vx[0] vk[:,:n2c,n2c:] += vx[1] return vj, vk
def _call_rmb_vhf1(mol, dm, key='giao'): c1 = .5 / mol.light_speed n2c = dm.shape[0] // 2 dmll = dm[:n2c, :n2c].copy() dmls = dm[:n2c, n2c:].copy() dmsl = dm[n2c:, :n2c].copy() dmss = dm[n2c:, n2c:].copy() vj = numpy.zeros((3, n2c * 2, n2c * 2), dtype=numpy.complex) vk = numpy.zeros((3, n2c * 2, n2c * 2), dtype=numpy.complex) vx = _vhf.rdirect_mapdm('cint2e_' + key + '_sa10sp1spsp2', 's2kl', ('ji->s2kl', 'lk->s1ij', 'jk->s1il', 'li->s1kj'), dmss, 3, mol._atm, mol._bas, mol._env) * c1**4 for i in range(3): vx[0, i] = pyscf.lib.hermi_triu(vx[0, i], 2) vj[:, n2c:, n2c:] = vx[0] + vx[1] vk[:, n2c:, n2c:] = vx[2] + vx[3] vx = _vhf.rdirect_bindm('cint2e_' + key + '_sa10sp1', 's2kl', ('lk->s1ij', 'ji->s2kl', 'jk->s1il', 'li->s1kj'), (dmll, dmss, dmsl, dmls), 3, mol._atm, mol._bas, mol._env) * c1**2 for i in range(3): vx[1, i] = pyscf.lib.hermi_triu(vx[1, i], 2) vj[:, n2c:, n2c:] += vx[0] vj[:, :n2c, :n2c] += vx[1] vk[:, n2c:, :n2c] += vx[2] vk[:, :n2c, n2c:] += vx[3] for i in range(3): vj[i] = vj[i] + vj[i].T.conj() vk[i] = vk[i] + vk[i].T.conj() return vj, vk
def test_rdirect_mapdm(self): numpy.random.seed(1) n2c = nao * 2 dm = numpy.random.random((n2c,n2c)) + \ numpy.random.random((n2c,n2c)) * 1j eri0 = numpy.zeros((3, n2c, n2c, n2c, n2c), dtype=numpy.complex) c_atm = numpy.array(mol._atm, dtype=numpy.int32) c_bas = numpy.array(mol._bas, dtype=numpy.int32) c_env = numpy.array(mol._env) i0 = 0 for i in range(mol.nbas): j0 = 0 for j in range(mol.nbas): k0 = 0 for k in range(mol.nbas): l0 = 0 for l in range(mol.nbas): buf = gto.getints_by_shell('int2e_g1_spinor', (i, j, k, l), c_atm, c_bas, c_env, 3) di, dj, dk, dl = buf.shape[1:] eri0[:, i0:i0 + di, j0:j0 + dj, k0:k0 + dk, l0:l0 + dl] = buf l0 += dl k0 += dk j0 += dj i0 += di vk0 = numpy.einsum('nijkl,jk->nil', eri0, dm) vj1, vk1 = _vhf.rdirect_mapdm('int2e_g1_spinor', 'a4ij', ('lk->s2ij', 'jk->s1il'), dm, 3, mol._atm, mol._bas, mol._env) self.assertTrue(numpy.allclose(vk0, vk1))
def test_rdirect_mapdm(self): numpy.random.seed(1) n2c = nao*2 dm = numpy.random.random((n2c,n2c)) + \ numpy.random.random((n2c,n2c)) * 1j eri0 = numpy.zeros((3,n2c,n2c,n2c,n2c),dtype=numpy.complex) c_atm = numpy.array(mol._atm, dtype=numpy.int32) c_bas = numpy.array(mol._bas, dtype=numpy.int32) c_env = numpy.array(mol._env) i0 = 0 for i in range(mol.nbas): j0 = 0 for j in range(mol.nbas): k0 = 0 for k in range(mol.nbas): l0 = 0 for l in range(mol.nbas): buf = gto.getints_by_shell('cint2e_g1', (i,j,k,l), c_atm, c_bas, c_env, 3) di,dj,dk,dl = buf.shape[1:] eri0[:,i0:i0+di,j0:j0+dj,k0:k0+dk,l0:l0+dl] = buf l0 += dl k0 += dk j0 += dj i0 += di vk0 = numpy.einsum('nijkl,jk->nil', eri0, dm) vj1, vk1 = _vhf.rdirect_mapdm('cint2e_g1', 'a4ij', ('lk->s2ij', 'jk->s1il'), dm, 3, mol._atm, mol._bas, mol._env) self.assertTrue(numpy.allclose(vk0,vk1))
def _call_rmb_vhf1(mol, dm, key='giao'): c1 = .5/mol.light_speed n2c = dm.shape[0] // 2 dmll = dm[:n2c,:n2c].copy() dmls = dm[:n2c,n2c:].copy() dmsl = dm[n2c:,:n2c].copy() dmss = dm[n2c:,n2c:].copy() vj = numpy.zeros((3,n2c*2,n2c*2), dtype=numpy.complex) vk = numpy.zeros((3,n2c*2,n2c*2), dtype=numpy.complex) vx = _vhf.rdirect_mapdm('cint2e_'+key+'_sa10sp1spsp2', 's2kl', ('ji->s2kl', 'lk->s1ij', 'jk->s1il', 'li->s1kj'), dmss, 3, mol._atm, mol._bas, mol._env) * c1**4 for i in range(3): vx[0,i] = pyscf.lib.hermi_triu(vx[0,i], 2) vj[:,n2c:,n2c:] = vx[0] + vx[1] vk[:,n2c:,n2c:] = vx[2] + vx[3] vx = _vhf.rdirect_bindm('cint2e_'+key+'_sa10sp1', 's2kl', ('lk->s1ij', 'ji->s2kl', 'jk->s1il', 'li->s1kj'), (dmll,dmss,dmsl,dmls), 3, mol._atm, mol._bas, mol._env) * c1**2 for i in range(3): vx[1,i] = pyscf.lib.hermi_triu(vx[1,i], 2) vj[:,n2c:,n2c:] += vx[0] vj[:,:n2c,:n2c] += vx[1] vk[:,n2c:,:n2c] += vx[2] vk[:,:n2c,n2c:] += vx[3] for i in range(3): vj[i] = vj[i] + vj[i].T.conj() vk[i] = vk[i] + vk[i].T.conj() return vj, vk
def test_rdirect_mapdm(self): numpy.random.seed(1) n2c = nao*2 dm = (numpy.random.random((n2c,n2c)) + numpy.random.random((n2c,n2c)) * 1j) eri0 = mol.intor('int2e_g1_spinor', comp=3).reshape(3,n2c,n2c,n2c,n2c) vk0 = numpy.einsum('nijkl,jk->nil', eri0, dm) vj1, vk1 = _vhf.rdirect_mapdm('int2e_g1_spinor', 'a4ij', ('lk->s2ij', 'jk->s1il'), dm, 3, mol._atm, mol._bas, mol._env) self.assertTrue(numpy.allclose(vk0,vk1)) vj1 = _vhf.rdirect_mapdm('int2e_g1_spinor', 's1', 'lk->s1ij', dm, 3, mol._atm, mol._bas, mol._env) vj0 = numpy.einsum('nijkl,lk->nij', eri0, dm) self.assertTrue(numpy.allclose(vj0,vj1))
def get_jk(mol, dm, hermi=1, mf_opt=None): n2c = dm.shape[0] dd = numpy.zeros((n2c * 2, ) * 2, dtype=numpy.complex) dd[:n2c, :n2c] = dm dhf._call_veff_llll(mol, dd, hermi, None) vj, vk = _vhf.rdirect_mapdm('cint2e', 's8', ('ji->s2kl', 'jk->s1il'), dm, 1, mol._atm, mol._bas, mol._env, mf_opt) return dhf._jk_triu_(vj, vk, hermi)
def get_jk(mol, dm, hermi=1, mf_opt=None): n2c = dm.shape[0] dd = numpy.zeros((n2c*2,)*2, dtype=numpy.complex) dd[:n2c,:n2c] = dm dhf._call_veff_llll(mol, dd, hermi, None) vj, vk = _vhf.rdirect_mapdm('cint2e', 's8', ('ji->s2kl', 'jk->s1il'), dm, 1, mol._atm, mol._bas, mol._env, mf_opt) return dhf._jk_triu_(vj, vk, hermi)
def _call_vhf1_llll(mol, dm): n2c = dm.shape[0] // 2 dmll = dm[:n2c,:n2c].copy() vj = numpy.zeros((3,n2c*2,n2c*2), dtype=numpy.complex) vk = numpy.zeros((3,n2c*2,n2c*2), dtype=numpy.complex) vj[:,:n2c,:n2c], vk[:,:n2c,:n2c] = \ _vhf.rdirect_mapdm('cint2e_ip1', 's2kl', ('lk->s1ij', 'jk->s1il'), dmll, 3, mol._atm, mol._bas, mol._env) return vj, vk
def _call_veff_llll(mol, dm, hermi=1, mf_opt=None): if isinstance(dm, numpy.ndarray) and dm.ndim == 2: n2c = dm.shape[0] // 2 dms = dm[:n2c, :n2c].copy() else: n2c = dm.shape[1] // 2 dms = dm[:, :n2c, :n2c].copy() vj, vk = _vhf.rdirect_mapdm('int2e_spinor', 's8', ('ji->s2kl', 'jk->s1il'), dms, 1, mol._atm, mol._bas, mol._env, mf_opt) return _jk_triu_(mol, vj, vk, hermi)
def _call_vhf1_llll(mol, dm): n2c = dm.shape[0] // 2 dmll = dm[:n2c,:n2c].copy() vj = numpy.zeros((3,n2c*2,n2c*2), dtype=numpy.complex) vk = numpy.zeros((3,n2c*2,n2c*2), dtype=numpy.complex) vj[:,:n2c,:n2c], vk[:,:n2c,:n2c] = \ _vhf.rdirect_mapdm('int2e_ip1_spinor', 's2kl', ('lk->s1ij', 'jk->s1il'), dmll, 3, mol._atm, mol._bas, mol._env) return vj, vk
def get_jk(mol, dm, hermi=1, mf_opt=None, with_j=True, with_k=True): '''J/K matrices in the j-adapted spinor basis. ''' n2c = dm.shape[0] dd = numpy.zeros((n2c * 2, ) * 2, dtype=numpy.complex128) dd[:n2c, :n2c] = dm dhf._call_veff_llll(mol, dd, hermi, None) vj, vk = _vhf.rdirect_mapdm('int2e_spinor', 's8', ('ji->s2kl', 'jk->s1il'), dm, 1, mol._atm, mol._bas, mol._env, mf_opt) return dhf._jk_triu_(vj, vk, hermi)
def get_jk(mol, dm, hermi=1, mf_opt=None, with_j=True, with_k=True, omega=None): '''non-relativistic J/K matrices (without SSO,SOO etc) in the j-adapted spinor basis. ''' vj, vk = _vhf.rdirect_mapdm('int2e_spinor', 's8', ('ji->s2kl', 'jk->s1il'), dm, 1, mol._atm, mol._bas, mol._env, mf_opt) vj = vj.reshape(dm.shape) vk = vk.reshape(dm.shape) return dhf._jk_triu_(mol, vj, vk, hermi)
def _call_veff_llll(mol, dm, hermi=1, mf_opt=None): if isinstance(dm, numpy.ndarray) and dm.ndim == 2: n2c = dm.shape[0] // 2 dms = dm[:n2c, :n2c].copy() else: n2c = dm[0].shape[0] // 2 dms = [] for dmi in dm: dms.append(dmi[:n2c, :n2c].copy()) vj, vk = _vhf.rdirect_mapdm("cint2e", "s8", ("ji->s2kl", "jk->s1il"), dms, 1, mol._atm, mol._bas, mol._env, mf_opt) return _jk_triu_(vj, vk, hermi)
def _call_veff_llll(mol, dm, hermi=1, mf_opt=None): if isinstance(dm, numpy.ndarray) and dm.ndim == 2: n2c = dm.shape[0] // 2 dms = dm[:n2c, :n2c].copy() else: n2c = dm[0].shape[0] // 2 dms = [] for dmi in dm: dms.append(dmi[:n2c, :n2c].copy()) vj, vk = _vhf.rdirect_mapdm('cint2e', 's8', ('ji->s2kl', 'jk->s1il'), dms, 1, mol._atm, mol._bas, mol._env, mf_opt) return _jk_triu_(vj, vk, hermi)
def _call_veff_ssss(mol, dm, hermi=1, mf_opt=None): c1 = .5/mol.light_speed if isinstance(dm, numpy.ndarray) and dm.ndim == 2: n2c = dm.shape[0] // 2 dms = dm[n2c:,n2c:].copy() else: n2c = dm[0].shape[0] // 2 dms = [] for dmi in dm: dms.append(dmi[n2c:,n2c:].copy()) vj, vk = _vhf.rdirect_mapdm('cint2e_spsp1spsp2', 's8', ('ji->s2kl', 'jk->s1il'), dms, 1, mol._atm, mol._bas, mol._env, mf_opt) * c1**4 return _jk_triu_(vj, vk, hermi)
def _call_veff_ssss(mol, dm, hermi=1, mf_opt=None): c1 = .5 / lib.param.LIGHT_SPEED if isinstance(dm, numpy.ndarray) and dm.ndim == 2: n2c = dm.shape[0] // 2 dms = dm[n2c:, n2c:].copy() else: n2c = dm[0].shape[0] // 2 dms = [] for dmi in dm: dms.append(dmi[n2c:, n2c:].copy()) vj, vk = _vhf.rdirect_mapdm('int2e_spsp1spsp2_spinor', 's8', ('ji->s2kl', 'jk->s1il'), dms, 1, mol._atm, mol._bas, mol._env, mf_opt) * c1**4 return _jk_triu_(vj, vk, hermi)