Esempio n. 1
0
    def debug_matrixelements(self):

        eigvals, eigvecs = np.linalg.eigh(self.activeFOCK)
        eigvecs = eigvecs[:, eigvals.argsort()]
        assert (self.nelec_tot % 2 == 0)
        numPairs = self.nelec_tot // 2
        DMguess = 2 * np.dot(eigvecs[:, :numPairs], eigvecs[:, :numPairs].T)
        '''
        if self._eri is not None:
            DMloc = wm_rhf.solve_ERI( self.activeOEI, self._eri, DMguess, numPairs, num_mf_stab_checks )
        else:
        '''
        DMloc = wm_rhf.solve_JK(self.activeOEI, self.mol, self.ao2loc, DMguess,
                                numPairs)
        newFOCKloc = self.loc_rhf_fock_bis(DMloc)
        newRHFener = self.activeCONST + 0.5 * np.einsum(
            'ij,ij->', DMloc, self.activeOEI + newFOCKloc)
        print(
            "2-norm difference of RDM(self.activeFOCK) and RDM(self.active{OEI,ERI})  =",
            np.linalg.norm(DMguess - DMloc))
        print(
            "2-norm difference of self.activeFOCK and FOCK(RDM(self.active{OEI,ERI})) =",
            np.linalg.norm(self.activeFOCK - newFOCKloc))
        print("RHF energy of mean-field input           =", self.fullEhf)
        print("RHF energy based on self.active{OEI,ERI} =", newRHFener)
Esempio n. 2
0
    def get_wm_1RDM_from_scf_on_OEI(self,
                                    OEI,
                                    nelec=None,
                                    loc2wrk=None,
                                    oneRDMguess_loc=None,
                                    output=None,
                                    working_const=0):

        nelec = nelec or self.nelec_idem
        loc2wrk = loc2wrk if np.any(loc2wrk) else self.loc2idem
        oneRDM_wrk = represent_operator_in_basis(
            oneRDMguess_loc, loc2wrk) if np.any(oneRDMguess_loc) else None
        nocc = nelec // 2

        # DON'T call self.get_wm_1RDM_from_OEIidem here because you need to hold oneRDMcorr_loc frozen until the end of the scf!
        OEI_wrk = represent_operator_in_basis(OEI, loc2wrk)
        if oneRDM_wrk is None:
            oneRDM_wrk = 2 * get_1RDM_from_OEI(OEI_wrk, nocc)
        ao2wrk = np.dot(self.ao2loc, loc2wrk)
        wrk2symm = get_subspace_symmetry_blocks(loc2wrk, self.loc2symm)
        if self.enforce_symmetry:
            assert (is_operator_block_adapted(
                oneRDM_wrk, wrk2symm)), measure_operator_blockbreaking(
                    oneRDM_wrk, wrk2symm)
        oneRDM_wrk = wm_rhf.solve_JK(working_const,
                                     OEI_wrk,
                                     ao2wrk,
                                     oneRDM_wrk,
                                     nocc,
                                     self.num_mf_stab_checks,
                                     self.get_veff_ao,
                                     self.get_jk_ao,
                                     groupname=self.symmetry,
                                     symm_orb=wrk2symm,
                                     irrep_name=self.mol.irrep_name,
                                     irrep_id=self.mol.irrep_id,
                                     enforce_symmetry=self.enforce_symmetry,
                                     output=output)
        if self.enforce_symmetry:
            assert (is_operator_block_adapted(
                oneRDM_wrk, wrk2symm)), measure_operator_blockbreaking(
                    oneRDM_wrk, wrk2symm)
        oneRDM_loc = represent_operator_in_basis(oneRDM_wrk, loc2wrk.T)
        if self.enforce_symmetry:
            assert (is_operator_block_adapted(
                oneRDM_loc, self.loc2symm)), measure_operator_blockbreaking(
                    oneRDM_loc, self.loc2symm)
        return oneRDM_loc + self.oneRDMcorr_loc
Esempio n. 3
0
    def get_wm_1RDM_from_scf_on_OEI(self,
                                    OEI,
                                    nelec=None,
                                    loc2wrk=None,
                                    oneRDMguess_loc=None,
                                    output=None):

        nelec = nelec or self.nelec_idem
        loc2wrk = loc2wrk if np.any(loc2wrk) else self.loc2idem
        oneRDM_wrk = represent_operator_in_basis(
            oneRDMguess_loc, loc2wrk) if np.any(oneRDMguess_loc) else None
        nocc = nelec // 2

        # DON'T call self.get_wm_1RDM_from_OEIidem here because you need to hold oneRDMcorr_loc frozen until the end of the scf!
        OEI_wrk = represent_operator_in_basis(OEI, loc2wrk)
        if oneRDM_wrk is None:
            oneRDM_wrk = 2 * get_1RDM_from_OEI(OEI_wrk, nocc)
        '''
        if self._eri is not None:
            # I just need a view of self._eri with different tags. ao2loc . loc2wrk = ao2wrk
            wrk2loc    = loc2wrk.conjugate ().T
            ERI_wrk    = self._eri.view ()
            ERI_wrk    = tag_array (ERI_wrk, loc2eri_bas = lambda x: self._eri.loc2eri_bas (np.dot (loc2wrk, x)))
            ERI_wrk    = tag_array (ERI_wrk, loc2eri_op = lambda x: self._eri.loc2eri_op (reduce (np.dot, (loc2wrk, x, wrk2loc))))
            ERI_wrk    = tag_array (ERI_wrk, eri2loc_bas = lambda x: np.dot (wrk2loc, self._eri.eri2loc_bas (x)))
            ERI_wrk    = tag_array (ERI_wrk, eri2loc_op = lambda x: reduce (np.dot, (wrk2loc, self._eri.eri2loc_op (x), loc2wrk)))
            oneRDM_wrk = wm_rhf.solve_ERI(OEI_wrk, ERI_wrk, oneRDM_wrk, nocc, self.num_mf_stab_checks)
        else:
        '''
        ao2wrk = np.dot(self.ao2loc, loc2wrk)
        oneRDM_wrk = wm_rhf.solve_JK(OEI_wrk,
                                     ao2wrk,
                                     oneRDM_wrk,
                                     nocc,
                                     self.num_mf_stab_checks,
                                     self.get_veff_ao,
                                     self.get_jk_ao,
                                     output=output)
        oneRDM_loc = represent_operator_in_basis(oneRDM_wrk, loc2wrk.T)
        return oneRDM_loc + self.oneRDMcorr_loc