def solve(frag, guess_1RDM, chempot_imp): # Augment OEI with the chemical potential OEI = frag.impham_OEI_C - chempot_imp # Get the RHF solution mol = gto.Mole() mol.spin = int(round(2 * frag.target_MS)) mol.verbose = 0 if frag.mol_output is None else 4 mol.output = frag.mol_output mol.build() mol.atom.append(('H', (0, 0, 0))) mol.nelectron = frag.nelec_imp #mol.incore_anyway = True #mf.get_hcore = lambda *args: OEI #mf.get_ovlp = lambda *args: np.eye(frag.norbs_imp) #mf._eri = ao2mo.restore(8, frag.impham_TEI, frag.norbs_imp) h1e = OEI eri = ao2mo.restore(8, frag.impham_TEI, frag.norbs_imp) ed = fci.FCI(mol, singlet=(frag.target_S == 0)) if frag.target_S != 0: s2_eval = frag.target_S * (frag.target_S + 1) fix_spin_(ed, ss=s2_eval) # Guess vector ci = None if len(frag.imp_cache) == 1: ci = frag.imp_cache[0] print("Taking initial ci vector from cache") t_start = time.time() ed.conv_tol = 1e-12 E_FCI, ci = ed.kernel(h1e, eri, frag.norbs_imp, frag.nelec_imp, ci0=ci) assert (ed.converged) frag.imp_cache = [ci] t_end = time.time() print( 'Impurity FCI energy (incl chempot): {}; spin multiplicity: {}; time to solve: {}' .format(frag.impham_CONST + E_FCI, ed.spin_square(ci, frag.norbs_imp, frag.nelec_imp)[1], t_end - t_start)) # oneRDM and twoCDM oneRDM_imp, twoRDM_imp = ed.make_rdm12(ci, frag.norbs_imp, frag.nelec_imp) oneRDMs_imp = ed.make_rdm1s(ci, frag.norbs_imp, frag.nelec_imp) twoCDM_imp = get_2CDM_from_2RDM(twoRDM_imp, oneRDMs_imp) # General impurity data frag.oneRDM_loc = symmetrize_tensor( frag.oneRDMfroz_loc + represent_operator_in_basis(oneRDM_imp, frag.imp2loc)) frag.twoCDM_imp = symmetrize_tensor(twoCDM_imp) frag.E_imp = frag.impham_CONST + E_FCI + np.einsum('ab,ab->', chempot_imp, oneRDM_imp) return None
h1e = reduce(numpy.dot, (m.mo_coeff.T, m.get_hcore(), m.mo_coeff)) eri = ao2mo.kernel(m._eri, m.mo_coeff, compact=False) eri = eri.reshape(norb, norb, norb, norb) e1, c1 = kernel(h1e, eri, norb, nelec) e2, c2 = direct_spin1.kernel(h1e, eri, norb, nelec) print(e1, e1 - -11.894559902235565, 'diff to FCI', e1 - e2) print(c1.shape, c2.shape) dm1_1 = make_rdm1(c1, norb, nelec) dm1_2 = direct_spin1.make_rdm1(c2, norb, nelec) print(abs(dm1_1 - dm1_2).sum()) dm2_1 = make_rdm2(c1, norb, nelec) dm2_2 = direct_spin1.make_rdm12(c2, norb, nelec)[1] print(abs(dm2_1 - dm2_2).sum()) myci = SelectedCI() e, c = kernel_fixed_space(myci, h1e, eri, norb, nelec, c1._strs) print(e - -11.894559902235565) print(myci.large_ci(c1, norb, nelec)) print( myci.spin_square(c1, norb, nelec)[0] - spin_op.spin_square0(to_fci(c1, norb, nelec), norb, nelec)[0]) myci = SelectedCI() myci = addons.fix_spin_(myci) e1, c1 = myci.kernel(h1e, eri, norb, nelec) print(e1, e1 - -11.89467612053687) print(myci.spin_square(c1, norb, nelec))
nelec = mol.nelectron h1e = reduce(numpy.dot, (m.mo_coeff.T, m.get_hcore(), m.mo_coeff)) eri = ao2mo.kernel(m._eri, m.mo_coeff, compact=False) eri = eri.reshape(norb,norb,norb,norb) e1, c1 = kernel(h1e, eri, norb, nelec) e2, c2 = direct_spin1.kernel(h1e, eri, norb, nelec) print(e1, e1 - -11.894559902235565, 'diff to FCI', e1-e2) print(c1.shape, c2.shape) dm1_1 = make_rdm1(c1, norb, nelec) dm1_2 = direct_spin1.make_rdm1(c2, norb, nelec) print(abs(dm1_1 - dm1_2).sum()) dm2_1 = make_rdm2(c1, norb, nelec) dm2_2 = direct_spin1.make_rdm12(c2, norb, nelec)[1] print(abs(dm2_1 - dm2_2).sum()) myci = SelectCI() e, c = kernel_fixed_space(myci, h1e, eri, norb, nelec, c1._strs) print(e - -11.894559902235565) print(myci.large_ci(c1, norb, nelec)) print(myci.spin_square(c1, norb, nelec)[0] - spin_op.spin_square0(to_fci(c1, norb, nelec), norb, nelec)[0]) myci = SelectCI() myci = addons.fix_spin_(myci) e1, c1 = myci.kernel(h1e, eri, norb, nelec) print(e1, e1 - -11.89467612053687) print(myci.spin_square(c1, norb, nelec))