def s2n(N, tmpdir='/tmp', Sg=1, Sv=1): """ S[2]*N linear transformation: <[q,k]> = <[E(Sg)_{ij}, k_{kl}, E(Sv)_{kl}]> = = k_{kl} [E_{il}d(kj) - E(kj)d(il)] = k(jl)E(SgSv)(il) - k(ki)E(SgSv)(kj) = D(SgSv)k.T(ij) - k.TD(SgSv)(ij) = [D(SgSv), k.T](ij) """ SIRIFC = os.path.join(tmpdir, 'SIRIFC') AOONEINT = os.path.join(tmpdir, 'AOONEINT') AOTWOINT = os.path.join(tmpdir, 'AOTWOINT') LUINDF = os.path.join(tmpdir, 'LUINDF') ifc = sirifc.sirifc(SIRIFC) cmo = ifc.cmo.unblock() S = one.read('OVERLAP', filename=AOONEINT).unblock().unpack() da, db = dens.Dab(SIRIFC) kN = rspvec.tomat(N, ifc, tmpdir=tmpdir).T kn = cmo*kN*cmo.T dak = (kn.T*S*da - da*S*kn.T) dbk = (kn.T*S*db - db*S*kn.T)*Sv gv = -rspvec.tovec(cmo.T*S*(dak+Sg*dbk)*S*cmo, ifc) return gv
def test_tovec(self): Nx = rspvec.read("XDIPLEN", propfile=self.RSPVEC)["XDIPLEN"] kx = rspvec.tomat(Nx, self.ifc, tmpdir=self.tmpdir) Nx = rspvec.tovec(kx, self.ifc, tmpdir=self.tmpdir) this = Nx[44] ref = 0.75732690 assert this == approx(ref)
def e2n(N, tmpdir='/tmp', hfx=1, Sg=1, Sv=1): """ E[2]*N linear transformation: [k,F] = [k(pq)E(Sv)(pq), F(rs)E(rs)] = k(pq)F(rs) (E(ps)d(rq) - E(rq)d(ps)) = k(pq)F(ps)E(ps) - k(pq)F(rp)E(rq) = [k,F](pq)E(pq) = kF <[q,kF]> = <[E_{pq}, kF(rs)E(rs)]> = kF(rs) <E(ps)d(rq) - E(rq)d(ps)> = kF(qs)D(ps) - kF(rp)D(rq) = [D, kF.T](pq) kD = <[k, E(pq)]> = <[k(rs) E(rs), E(pq)]> = k(rs) (E(rq)d(ps) - E(ps)d(rq)) = k(rp)D(rq) - k(qs)D(ps) = [k.T, D](p,q) Fk = F[kD] """ SIRIFC = os.path.join(tmpdir, 'SIRIFC') AOONEINT = os.path.join(tmpdir, 'AOONEINT') AOTWOINT = os.path.join(tmpdir, 'AOTWOINT') LUINDF = os.path.join(tmpdir, 'LUINDF') ifc = sirifc.sirifc(SIRIFC) cmo = get_cmo(AOONEINT, SIRIFC) h = one.read('ONEHAMIL', filename=AOONEINT).unblock().unpack() S = one.read('OVERLAP', filename=AOONEINT).unblock().unpack().view(util.full.matrix) da, db = get_densities(SIRIFC) kN = rspvec.tomat(N, ifc, tmpdir=tmpdir).view(util.full.matrix).T kn = (cmo*kN*cmo.T).view(util.full.matrix) dak = (kn.T*S*da - da*S*kn.T) dbk = (kn.T*S*db - db*S*kn.T)*Sv (fa, fb), = two.fockab((da, db), filename=AOTWOINT, hfx=hfx) fa += h; fb += h (fak, fbk), = two.fockab((dak, dbk), filename=AOTWOINT, hfx=hfx) kfa = (S*kn*fa - fa*kn*S) kfb = (S*kn*fb - fb*kn*S)*Sv fa = fak + kfa fb = fbk + kfb gao = S*(da*fa.T + Sg*db*fb.T) - (fa.T*da + Sg*fb.T*db)*S gm = cmo.T*gao*cmo # sign convention <[q,[k,F]]> = -E[2]*N gv = - rspvec.tovec(gm, ifc) return gv
def A2B(*args, **kwargs): pA, pB, ifc = args tmpdir = kwargs.get("tmpdir", ".") AOONEINT = os.path.join(tmpdir, "AOONEINT") S = one.read(label = "OVERLAP", filename = AOONEINT).unblock().unpack() cmo = ifc.cmo.unblock() mA = pA["matrix"] kB = cmo*pB["kappa"]*cmo.T BA = S*kB*mA - mA*kB*S da, db = dens.Dab(ifc_=ifc) G = cmo.T*(S*(da*BA.T + db*BA.T) - (BA.T*da + BA.T*db)*S)*cmo Gv = rspvec.tovec(G, ifc) return Gv
def B2C(*args, **kwargs): pB, pC, ifc = args tmpdir = kwargs.get("tmpdir", ".") AOONEINT = os.path.join(tmpdir, "AOONEINT") S = one.read(label = "OVERLAP", filename = AOONEINT).unblock().unpack() cmo = ifc.cmo.unblock() mB = pB["matrix"] mC = pC["matrix"] kB = cmo*pB["kappa"]*cmo.T kC = cmo*pC["kappa"]*cmo.T kBmC = S*kB*mC - mC*kB*S kCmB = S*kC*mB - mB*kC*S BC = kBmC + kCmB da, db = dens.Dab(ifc_=ifc) G = cmo.T*(S*(da*BC.T + db*BC.T) - (BC.T*da + BC.T*db)*S)*cmo Gv = rspvec.tovec(G, ifc) return Gv
def E3(pB, pC, ifc, **kwargs): """ Emulate the so called E3 contribution to a quadratic response function <<A; B, C>> = NA E3 (NB NC + NC NB) + A2 (NB NC + NC NB) + NA (B2 NC + C2 NB) Emulation of current Dalton implementation in terms of high spin fock matrices Closed and open shell matrices Dc = inactive Do = -active Fc = Fa+Q Fo = ? CHECK Formulas 1/2*[qa, [kb, [kc, H]]] + P(b,c) [kc, H] = (p~q|rs)H(Sc, 0) + (pq|r~s) H(0, Sc) [kb, [kc, H]] = (p~~q|rs)H(SbSc, 0) + (p~q|r~s) H(Sb, Sc) + (p~q|r~s)H(Sc, Sb) + (pq|r~~s) H(0, SbSc) and for H(S1, S2) generates Fock from (D(S1) g D(S2) - Da g Da - Db g Db F(S1, S2) = E(S1) g D(S2) - D(S1) g E(S2) - Ea g Da - Da g Ea - Eb g Db - Db g Eb = Ea [ g D(S2) - D(S1) g - g Da - Da g ] + Eb [ S1 g D(S2) - D(S1) g S2 - g Db - Db g ] """ tmpdir = kwargs.get('tmpdir', '/tmp') AOONEINT = os.path.join(tmpdir, "AOONEINT") h = one.read(label='ONEHAMIL', filename=AOONEINT).unpack().unblock() S = one.read(label='OVERLAP', filename=AOONEINT).unblock().unpack() AOTWOINT = os.path.join(tmpdir, "AOTWOINT") kwargs['filename'] = AOTWOINT cmo = ifc.cmo.unblock() kB = cmo*pB["kappa"]*cmo.T kC = cmo*pC["kappa"]*cmo.T kB_ = kB*S _kB = S*kB kC_ = kC*S _kC = S*kC sB = pB.get("spin", 1) sC = pC.get("spin", 1) # # Fock matrices # da, db = dens.Dab(ifc_=ifc) (fa, fb), = two.fockab((da, db), **kwargs) fa += h fb += h Bfa, Bfb = [_kB*f - f*kB_ for f in (fa, sB*fb)] Cfa, Cfb = [_kC*f - f*kC_ for f in (fa, sC*fb)] BCfa, BCfb = [_kB*Cf - Cf*kB_ for Cf in (Cfa, sB*Cfb)] CBfa, CBfb = [_kC*Bf - Bf*kC_ for Bf in (Bfa, sC*Bfb)] daB, dbB = [_kB.T*d - d*kB_.T for d in (da, sB*db)] (faB, fbB), = two.fockab((daB, dbB), **kwargs) CfaB, CfbB = [_kC*fB - fB*kC_ for fB in (faB, sC*fbB)] daC, dbC = [_kC.T*d - d*kC_.T for d in (da, sC*db)] (faC, fbC), = two.fockab((daC, dbC), **kwargs) BfaC, BfbC = [_kB*fC - fC*kB_ for fC in (faC, sB*fbC)] daBC, dbBC = (_kB.T*dC - dC*kB_.T for dC in (daC, sB*dbC)) daCB, dbCB = (_kC.T*dB - dB*kC_.T for dB in (daB, sC*dbB)) daBC = 0.5*(daBC + daCB) dbBC = 0.5*(dbBC + dbCB) (faBC, fbBC), = two.fockab((daBC, dbBC), **kwargs) # # Add all focks # fa = faBC + BfaC + CfaB + .5*(BCfa + CBfa) fb = fbBC + BfbC + CfbB + .5*(BCfb + CBfb) G = cmo.T*(S*(da*fa.T + db*fb.T) - (fa.T*da + fb.T*db)*S)*cmo #G = cmo.T*(S*da*fa.T - fa.T*da *S)*cmo + \ # cmo.T*(S*db*fb.T - fb.T*db *S)*cmo Gv = rspvec.tovec(G, ifc) #print Gv return Gv
def mat2vec(self, mat): ifc = self._sirifc() mat = rspvec.tovec(np.array(mat), ifc) return mat
def test_tovec(self): ref = rspvec.read("XDIPLEN", propfile=self.RSPVEC)["XDIPLEN"] kx = rspvec.tomat(ref, self.ifc, tmpdir=self.tmpdir) this = rspvec.tovec(kx, self.ifc, tmpdir=self.tmpdir) np.testing.assert_almost_equal(this, ref)