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 count_electrons(bas_file, quad_file): from daltools import dens nel = 0 cfunc = set_cfunc(bas_file) Da, Db = dens.Dab() D = Da + Db for x, y, z, w in quaditer(quad_file): f = eval_cfunc(cfunc, (x, y, z)) n = f & (D * f) nel += w * n return nel
def integrator(*args, **kwargs): "Integrate list of args, defined as functionals of density" from daltools import dens bf = kwargs['bf'] qf = kwargs['qf'] cfunc = set_cfunc(bf) Da, Db = dens.Dab() res = [0 for a in args] for x, y, z, w in quaditer(qf): cx = eval_cfunc(cfunc, (x, y, z)) rhoax = cx & (Da * cx) rhobx = cx & (Db * cx) for i, a in enumerate(args): res[i] += w * a(rhoax, rhobx) return res
def main(*args, **kwargs): labs = args tmpdir = kwargs.get("tmpdir", ".") ranks = kwargs.get('rank', (0, 0, 0)) pars = [ (-1)**r for r in ranks] ifc = sirifc.sirifc(os.path.join(tmpdir, "SIRIFC")) cmo = ifc.cmo.unblock() AOONEINT = os.path.join(tmpdir, "AOONEINT") AOPROPER = os.path.join(tmpdir, "AOPROPER") RSPVEC = os.path.join(tmpdir, "RSPVEC") vecs = rspvec.read(*labs, propfile=RSPVEC)[0] kappa = [rspvec.tomat(vec, ifc).T for vec in vecs] kappa[0] = kappa[0].T a, b, c = [cmo.T*x*cmo for x in prop.read(*labs, filename=AOPROPER)] NA = vecs[0] kA, kB, kC = kappa pA, pB, pC = [{ "lab":lab, "rank":rank, 'kappa':k} for lab, rank, k in zip(labs, ranks, kappa)] da, db = dens.Dab(ifc_=ifc) d = da + db S = one.read(label = "OVERLAP", filename = AOONEINT).unblock().unpack() D = cmo.T*S*d*S*cmo E3BC = E3(pB, pC, ifc, tmpdir=tmpdir) AE3BC = -NA&E3BC B2C = (-(kA^(kC^b))&D) C2B = (-(kA^(kB^c))&D) A2B = (.5*(kC^(kB^a))&D) A2C = (.5*(kB^(kC^a))&D) #print "E3BC",E3BC val = AE3BC print("E3 %14.8f %14.8f" % (AE3BC, val)) val += B2C print("B2C %14.8f %14.8f" % (B2C, val)) val += C2B print("C2B %14.8f %14.8f" % (C2B, val)) val += A2B print("A2B %14.8f %14.8f" % (A2B, val)) val += A2C print("A2C %14.8f %14.8f" % (A2C, val)) return val
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 setUp(self): n, e = os.path.splitext(__file__) self.suppdir = n + ".d" self.A = "XDIPLEN" self.B = "YDIPLEN" self.C = "XDIPLEN" AOONEINT = os.path.join(self.suppdir, 'AOONEINT') S = one.read(label="OVERLAP", filename=AOONEINT).unblock().unpack() SIRIFC = os.path.join(self.suppdir, 'SIRIFC') self.ifc = sirifc.sirifc(SIRIFC) cmo = self.ifc.cmo.unblock() da, db = dens.Dab(ifc_=self.ifc) self.D = cmo.T * S * (da + db) * S * cmo RSPVEC = os.path.join(self.suppdir, 'RSPVEC') rspvecs = rspvec.read(self.A, self.B, self.C, propfile=RSPVEC) self.NA = rspvecs[(self.A, 0)] self.NB = rspvecs[(self.B, 0)] self.NC = rspvecs[(self.C, 0)] self.kA = rspvec.tomat(self.NA, self.ifc, tmpdir=self.suppdir) self.kB = rspvec.tomat(self.NB, self.ifc, tmpdir=self.suppdir).T self.kC = rspvec.tomat(self.NC, self.ifc, tmpdir=self.suppdir).T AOPROPER = os.path.join(self.suppdir, 'AOPROPER') #a, b, c = [cmo.T*x*cmo for x in prop.read(A, B, C, filename=AOPROPER, unpack=True)] global pmat pmat = prop.read(self.A, self.B, self.C, filename=AOPROPER, unpack=True) self.a, self.b, self.c = [cmo.T * x * cmo for x in pmat]
def get_densities(SIRIFC): da, db = [d.view(util.full.matrix) for d in dens.Dab(SIRIFC)] return da, db
def get_density_matrix(self): D = sum(dens.Dab(filename=self.sirifc)) return D
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