def test_hfw(self): with lib.light_speed(10) as c: x2c_1 = sfx2c1e.SpinFreeX2C(mol1) x2c_2 = sfx2c1e.SpinFreeX2C(mol2) x2cobj = sfx2c1e.SpinFreeX2C(mol) fh_ref = (x2c_1.get_hcore() - x2c_2.get_hcore()) / 0.0002 * lib.param.BOHR fh = x2cobj.hcore_deriv_generator(deriv=1) self.assertAlmostEqual(abs(fh(0)[2] - fh_ref).max(), 0, 7) x2c_1.xuncontract = 0 x2c_2.xuncontract = 0 x2cobj.xuncontract = 0 fh_ref = (x2c_1.get_hcore() - x2c_2.get_hcore()) / 0.0002 * lib.param.BOHR fh = x2cobj.hcore_deriv_generator(deriv=1) self.assertAlmostEqual(abs(fh(0)[2] - fh_ref).max(), 0, 7) x2c_1.xuncontract = 1 x2c_2.xuncontract = 1 x2cobj.xuncontract = 1 x2c_1.approx = 'ATOM1E' x2c_2.approx = 'ATOM1E' x2cobj.approx = 'ATOM1E' fh_ref = (x2c_1.get_hcore() - x2c_2.get_hcore()) / 0.0002 * lib.param.BOHR fh = x2cobj.hcore_deriv_generator(deriv=1) self.assertAlmostEqual(abs(fh(0)[2] - fh_ref).max(), 0, 7)
def writeSOCIntegrals(mc, ncasorbs=None, rdm1=None, pictureChange1e="bp", pictureChange2e="bp", uncontract=True): from pyscf.x2c import x2c, sfx2c1e from pyscf.lib.parameters import LIGHT_SPEED LIGHT_SPEED = 137.0359895000 alpha = 1.0 / LIGHT_SPEED if (uncontract): xmol, contr_coeff = x2c.X2C().get_xmol(mc.mol) else: xmol, contr_coeff = mc.mol, numpy.eye(mc.mo_coeff.shape[0]) rdm1ao = rdm1 if (rdm1 is None): rdm1ao = 1. * mc.make_rdm1() if len(rdm1ao.shape) > 2: rdm1ao = (rdm1ao[0] + rdm1ao[1]) if (uncontract): dm = reduce(numpy.dot, (contr_coeff, rdm1ao, contr_coeff.T)) else: dm = 1. * rdm1ao np, nc = contr_coeff.shape[0], contr_coeff.shape[1] hso1e = numpy.zeros((3, np, np)) h1e_1c, x, rp = sfx2c1e.SpinFreeX2C(mc.mol).get_hxr(mc.mol, uncontract=uncontract) #two electron terms if (pictureChange2e == "bp"): h2ao = -(alpha)**2 * 0.5 * xmol.intor( 'cint2e_p1vxp1_sph', comp=3, aosym='s1') h2ao = h2ao.reshape(3, np, np, np, np) hso1e += 1. * (numpy.einsum('ijklm,lm->ijk', h2ao, dm) - 1.5 * (numpy.einsum('ijklm, kl->ijm', h2ao, dm) + numpy.einsum('ijklm,mj->ilk', h2ao, dm))) elif (pictureChange2e == "x2c"): dm1 = dm / 2. pLL, pLS, pSS = get_p(dm1, x, rp) #kint = get_kint(xmol) #hso1e += -(alpha)**2*0.5*get_fso2e_withkint(kint,x,rp,pLL,pLS,pSS) hso1e += -(alpha)**2 * 0.5 * get_fso2e(xmol, x, rp, pLL, pLS, pSS) elif (pictureChange2e == "none"): hso1e *= 0.0 else: print(pictureChane2e, "not a valid option") exit(0) #MF 1 electron term if (pictureChange1e == "bp"): hso1e += (alpha)**2 * 0.5 * get_wso(xmol) elif (pictureChange1e == "x2c1"): dm /= 2. pLL, pLS, pSS = get_p(dm, x, rp) wso = (alpha)**2 * 0.5 * get_wso(xmol) hso1e += get_hso1e(wso, x, rp) elif (pictureChange1e == "x2cn"): h1e_2c = x2c.get_hcore(xmol) for i in range(np): for j in range(np): if (abs(h1e_2c[2 * i, 2 * j + 1].imag) > 1.e-8): hso1e[0][i, j] -= h1e_2c[2 * i, 2 * j + 1].imag * 2. if (abs(h1e_2c[2 * i, 2 * j + 1].real) > 1.e-8): hso1e[1][i, j] -= h1e_2c[2 * i, 2 * j + 1].real * 2. if (abs(h1e_2c[2 * i, 2 * j].imag) > 1.e-8): hso1e[2][i, j] -= h1e_2c[2 * i, 2 * j].imag * 2. else: print(pictureChane1e, "not a valid option") exit(0) h1ao = numpy.zeros((3, nc, nc)) if (uncontract): for ic in range(3): h1ao[ic] = reduce(numpy.dot, (contr_coeff.T, hso1e[ic], contr_coeff)) else: h1ao = 1. * hso1e ncore, ncas = mc.ncore, mc.ncas if (ncasorbs is not None): ncas = ncasorbs mo_coeff = mc.mo_coeff h1 = numpy.einsum('xpq,pi,qj->xij', h1ao, mo_coeff, mo_coeff)[:, ncore:ncore + ncas, ncore:ncore + ncas] print1Int(h1, 'SOC')
print(v.shape) # Transform dipole operator r x2cobj = x2c.X2C(mol) with mol.with_common_orig((0., 0., 0.)): # Function picture_change also supports operators in matrix representation c = lib.param.LIGHT_SPEED xmol = x2cobj.get_xmol()[0] rLL = xmol.intor('int1e_r_spinor') rSS = xmol.intor('int1e_sprsp_spinor') * (.5 / c)**2 even_operator = (rLL, rSS) v = x2cobj.picture_change(even_operator) print(v.shape) # Transform operator 1/|r-R_O| under spin-free X2c framework x2cobj = sfx2c1e.SpinFreeX2C(mol) with mol.with_rinv_origin((0., 0., 0.)): v = x2cobj.picture_change(('int1e_rinv', 'int1e_prinvp')) print(v.shape) # Transform the Hamiltonian using the picture_change function x2cobj = sfx2c1e.SpinFreeX2C(mol) c = lib.param.LIGHT_SPEED xmol = x2cobj.get_xmol()[0] t = xmol.intor_symmetric('int1e_kin') w = xmol.intor_symmetric('int1e_pnucp') v = 'int1e_nuc' h1 = x2cobj.picture_change(even_operator=(v, w * (.5 / c)**2 - t), odd_operator=t) print(abs(h1 - x2cobj.get_hcore()).max())