def contract_2e(eri, fcivec, norb, nelec, link_index=None, **kwargs): if isinstance(nelec, (int, numpy.number)): sz = (nelec % 2) * .5 else: sz = abs(nelec[0]-nelec[1]) * .5 if ss_value is None: ss = sz*(sz+1) else: ss = ss_value ci0 = old_contract_2e(eri, fcivec, norb, nelec, link_index, **kwargs) if ss == 0: na = int(numpy.sqrt(fcivec.size)) ci0 = pyscf.lib.transpose_sum(ci0.reshape(na,na), inplace=True) ci0 *= .5 if ss < sz*(sz+1)+.1: # (S^2-ss_value)|Psi> to shift state other than the lowest state ci1 = spin_op.contract_ss(fcivec, norb, nelec).reshape(fcivec.shape) ci1 -= ss * fcivec else: # (S^2-ss_value)^2|Psi> to shift states except the given spin. # It still relies on the quality of initial guess tmp = spin_op.contract_ss(fcivec, norb, nelec).reshape(fcivec.shape) tmp -= ss * fcivec ci1 = -ss * tmp ci1 += spin_op.contract_ss(tmp, norb, nelec).reshape(fcivec.shape) tmp = None ci1 *= shift ci1 += ci0.reshape(fcivec.shape) return ci1
def contract_2e(eri, fcivec, norb, nelec, link_index=None, **kwargs): if ss_value is None: # (S^2-ss_value)|Psi> to shift state other than the lowest state if isinstance(nelec, (int, numpy.integer)): sz = (nelec % 2) * .5 else: sz = abs(nelec[0]-nelec[1]) * .5 ss = sz*(sz+1) ci1 = spin_op.contract_ss(fcivec, norb, nelec) ci1 -= ss * fcivec.reshape(ci1.shape) else: # (S^2-ss_value)^2|Psi> to shift states except the given spin. # It still relies on the quality of initial guess ss = ss_value tmp = spin_op.contract_ss(fcivec, norb, nelec) tmp -= ss * fcivec.reshape(tmp.shape) ci1 = -ss * tmp ci1 += spin_op.contract_ss(tmp, norb, nelec) tmp = None if ss == 0: ci1 = pyscf.lib.transpose_sum(ci1, inplace=True) * .5 ci1 *= shift ci1 += old_contract_2e(eri, fcivec, norb, nelec, link_index, **kwargs) return ci1
def contract_2e(eri, fcivec, norb, nelec, link_index=None, **kwargs): if isinstance(nelec, (int, numpy.number)): sz = (nelec % 2) * .5 else: sz = abs(nelec[0] - nelec[1]) * .5 if ss_value is None: ss = sz * (sz + 1) else: ss = ss_value ci0 = old_contract_2e(eri, fcivec, norb, nelec, link_index, **kwargs) if ss == 0: na = int(numpy.sqrt(fcivec.size)) ci0 = pyscf.lib.transpose_sum(ci0.reshape(na, na), inplace=True) ci0 *= .5 if ss < sz * (sz + 1) + .1: # (S^2-ss_value)|Psi> to shift state other than the lowest state ci1 = spin_op.contract_ss(fcivec, norb, nelec).reshape(fcivec.shape) ci1 -= ss * fcivec else: # (S^2-ss_value)^2|Psi> to shift states except the given spin. # It still relies on the quality of initial guess tmp = spin_op.contract_ss(fcivec, norb, nelec).reshape(fcivec.shape) tmp -= ss * fcivec ci1 = -ss * tmp ci1 += spin_op.contract_ss(tmp, norb, nelec) tmp = None ci1 *= shift ci1 += ci0.reshape(fcivec.shape) return ci1
def spin_square (fci, fcivec, norb, nelec): ss = 0.0 for ne in product (range (norb+1), repeat=2): c = fockspace.fock2hilbert (fcivec, norb, ne) ssc = spin_op.contract_ss (c, norb, ne) ss += c.conj ().ravel ().dot (ssc.ravel ()) s = np.sqrt(ss+.25) - .5 multip = s*2+1 return ss, multip
def contract_2e(eri, fcivec, norb, nelec, link_index=None, **kwargs): ci1 = old_contract_2e(eri, fcivec, norb, nelec, link_index, **kwargs) if isinstance(nelec, (int, numpy.integer)): sz = (nelec % 2) * .5 else: sz = abs(nelec[0]-nelec[1]) * .5 ci1 += shift * spin_op.contract_ss(fcivec, norb, nelec) ci1 -= sz*(sz+1)*shift * fcivec.reshape(ci1.shape) if isinstance(fciobj, direct_spin0.FCISolver): ci1 = pyscf.lib.transpose_sum(ci1, inplace=True) * .5 return ci1
def ham(las, h1, h2, ci_fr, idx_root, orbsym=None, wfnsym=None): mol = las.mol norb_f = las.ncas_sub nelec_fr = [[ _unpack_nelec(fcibox._get_nelec(solver, nelecas)) for solver, ix in zip(fcibox.fcisolvers, idx_root) if ix ] for fcibox, nelecas in zip(las.fciboxes, las.nelecas_sub)] ci, nelec = ci_outer_product(ci_fr, norb_f, nelec_fr) solver = fci.solver(mol).set(orbsym=orbsym, wfnsym=wfnsym) norb = sum(norb_f) h2eff = solver.absorb_h1e(h1, h2, norb, nelec, 0.5) ham_ci = [solver.contract_2e(h2eff, c, norb, nelec) for c in ci] s2_ci = [contract_ss(c, norb, nelec) for c in ci] ham_eff = np.array([[c.ravel().dot(hc.ravel()) for hc in ham_ci] for c in ci]) s2_eff = np.array([[c.ravel().dot(s2c.ravel()) for s2c in s2_ci] for c in ci]) ovlp_eff = np.array([[bra.ravel().dot(ket.ravel()) for ket in ci] for bra in ci]) return ham_eff, s2_eff, ovlp_eff
def contract_ss(self, fcivec, norb, nelec): from pyscf.fci import spin_op nelec = _unpack_nelec(nelec, self.spin) return spin_op.contract_ss(fcivec, norb, nelec)
def contract_ss(self, fcivec, norb, nelec): from pyscf.fci import spin_op return spin_op.contract_ss(fcivec, norb, nelec)