def ft_rdm1s(h1e, g2e, norb, nelec, T, m=50, nsamp=40, Tmin=10e-4): '''rdm of spin a and b at temperature T ''' if T < Tmin: e, c = kernel(h1e, g2e, norb, nelec) rdma, rdmb = direct_spin1.make_rdm1s(c, norb, nelec) return rdma, rdmb h2e = direct_spin1.absorb_h1e(h1e, g2e, norb, nelec, .5) if isinstance(nelec, (int, numpy.integer)): nelecb = nelec//2 neleca = nelec - nelecb else: neleca, nelecb = nelec na = cistring.num_strings(norb, neleca) nb = cistring.num_strings(norb, nelecb) def vecgen(n1=na, n2=nb): ci0 = numpy.random.randn(n1, n2) # ci0[0, 0] = 1. return ci0.reshape(-1) def hop(c): hc = direct_spin1.contract_2e(h2e, c, norb, nelec) return hc.reshape(-1) def qud(v1, v2): dma, dmb = direct_spin1.trans_rdm1s(v1, v2, norb, nelec) return dma, dmb # rdma, rdmb = flan.ht_rdm1s(qud, hop, vecgen, T, norb, m, nsamp) rdma, rdmb = flan.ftlan_rdm1s(qud, hop, vecgen, T, norb, m, nsamp) return rdma, rdmb
def ft_rdm1s(h1e, g2e, norb, nelec, T, m=50, nsamp=40, Tmin=10e-4): '''rdm of spin a and b at temperature T ''' if T < Tmin: e, c = kernel(h1e, g2e, norb, nelec) rdma, rdmb = direct_spin1.make_rdm1s(c, norb, nelec) return rdma, rdmb h2e = direct_spin1.absorb_h1e(h1e, g2e, norb, nelec, .5) if isinstance(nelec, (int, numpy.integer)): nelecb = nelec // 2 neleca = nelec - nelecb else: neleca, nelecb = nelec na = cistring.num_strings(norb, neleca) nb = cistring.num_strings(norb, nelecb) def vecgen(n1=na, n2=nb): ci0 = numpy.random.randn(n1, n2) # ci0[0, 0] = 1. return ci0.reshape(-1) def hop(c): hc = direct_spin1.contract_2e(h2e, c, norb, nelec) return hc.reshape(-1) def qud(v1, v2): dma, dmb = direct_spin1.trans_rdm1s(v1, v2, norb, nelec) return dma, dmb # rdma, rdmb = flan.ht_rdm1s(qud, hop, vecgen, T, norb, m, nsamp) rdma, rdmb = flan.ftlan_rdm1s(qud, hop, vecgen, T, norb, m, nsamp) return rdma, rdmb
def make_rdm1s (fci, fcivec, norb, nelec, **kwargs): dm1a = np.zeros ((norb,norb)) dm1b = np.zeros ((norb,norb)) for nelec in product (range (norb+1), repeat=2): ci = fockspace.fock2hilbert (fcivec, norb, nelec) da, db = direct_spin1.make_rdm1s (ci, norb, nelec, **kwargs) dm1a += da dm1b += db return dm1a, dm1b
def gen_rdm1s(h1e, g2e, norb, nelec, readfile=False): if readfile: ev = np.loadtxt("cards/eignV.dat") else: ew, ev = exdiagH(h1e, g2e, norb, nelec) # rdma, rdmb = [], [] ndim = len(ev) for i in range(ndim): tmpa, tmpb = direct_spin1.make_rdm1s(ev[:, i].copy(), norb, nelec) # tmpa, tmpb = direct_spin1.trans_rdm1s(ev[:, i], ev[:, i], norb, nelec) np.savetxt("cards/rdma/rdma%d"%i, tmpa) np.savetxt("cards/rdmb/rdmb%d"%i, tmpb)
def rdm1s_ft_smpl(h1e, g2e, norb, nelec, T, \ m=50, nsmpl=20000, Tmin=1e-3, symm='RHF', **kwargs): if symm is 'RHF': from pyscf.fci import direct_spin1 as fcisolver elif symm is 'SOC': from pyscf.fci import fci_slow_spinless as fcisolver elif symm is 'UHF': from pyscf.fci import direct_uhf as fcisolver else: from pyscf.fci import direct_spin1 as fcisolver if T < Tmin: e, c = fcisolver.kernel(h1e, g2e, norb, nelec) rdm1 = fcisolver.make_rdm1s(c, norb, nelec) return numpy.asarray(rdm1), e h2e = fcisolver.absorb_h1e(h1e, g2e, norb, nelec, .5) if symm is 'SOC': na = cistring.num_strings(norb, nelec) ci0 = numpy.random.randn(na) else: na = cistring.num_strings(norb, nelec // 2) ci0 = numpy.random.randn(na * na) ci0 = ci0 / numpy.linalg.norm(ci0) def hop(c): hc = fcisolver.contract_2e(h2e, c, norb, nelec) return hc.reshape(-1) def qud(v1): dm1 = fcisolver.make_rdm1s(v1, norb, nelec) return dm1 dm1, e = ftsmpl.ft_smpl_rdm1s(qud,\ hop, ci0, T, norb, nsamp=nsmpl,M=m) return dm1, e
def make_rdm1s(fcivec, norb, nelec, link_index=None): return direct_spin1.make_rdm1s(fcivec, norb, nelec, link_index)
def make_rdm1s(fcivec, norb, nelec, link_index=None): return direct_spin1.make_rdm1s(fcivec, norb, nelec, link_index)
mol.build() m = scf.RHF(mol) m.kernel() norb = m.mo_coeff.shape[1] nelec = mol.nelectron - 2 ne = mol.nelectron - 2 nelec = (nelec // 2, nelec - nelec // 2) h1e = reduce(numpy.dot, (m.mo_coeff.T, m.get_hcore(), m.mo_coeff)) eri = ao2mo.incore.general(m._eri, (m.mo_coeff, ) * 4, compact=False) eri = eri.reshape(norb, norb, norb, norb) e1, ci0 = kernel(h1e, eri, norb, ne) #FCI kernel print "T = 0, E = ", e1 rdma0, rdmb0 = direct_spin1.make_rdm1s(ci0, norb, nelec) print "*********************" print "zero rdm:\n", rdma0, "\n", rdmb0 print "*********************" rdma, rdmb = ft_rdm1s(h1e, eri, norb, nelec, 10., 10, 10) print rdma, "\n", rdmb # print numpy.sum(numpy.diag(rdma)) # print "T = 0, E = %10.10f"%e1 e2 = kernel_ft(h1e, eri, norb, nelec, 0.1, 40, 20) print "E(T) = %10.10f" % e2 e3 = kernel_ft_smpl( h1e, eri, norb, nelec,
mol.basis = 'sto-3g' mol.build() m = scf.RHF(mol) m.kernel() norb = m.mo_coeff.shape[1] nelec = mol.nelectron# - 2 ne = mol.nelectron# - 2 nelec = (nelec//2, nelec-nelec//2) h1e = reduce(numpy.dot, (m.mo_coeff.T, m.get_hcore(), m.mo_coeff)) eri = ao2mo.incore.general(m._eri, (m.mo_coeff,)*4, compact=False) eri = eri.reshape(norb,norb,norb,norb) e1, ci0 = kernel(h1e, eri, norb, ne) #FCI kernel # print "T = 0, E = ", e1 rdma0, rdmb0 = direct_spin1.make_rdm1s(ci0, norb, nelec) print "*********************" print "zero rdm:\n", rdma0, "\n", rdmb0 print "*********************" rdma, rdmb = ft_rdm1s(h1e, eri, norb, nelec, 10., 10, 10) print rdma, "\n", rdmb print numpy.sum(numpy.diag(rdma)) # print "T = 0, E = %10.10f"%e1 # e2 = kernel_ft(h1e, eri, norb, nelec, 0.01, 50, 20) # print "E(T) = %10.10f"%e2 ''' f = open("data/E-T_3.dat", "w") f.write("%2.4f %2.10f\n"%(0., e1)) for i in range(30): T = 0.1+0.2*i
def qud(v1): dm1 = fcisolver.make_rdm1s(v1, norb, nelec) return dm1