コード例 #1
0
     H                  3.80373444    3.80373444    2.54626556
     H                  2.54626556    3.80373444    3.80373444
     H                  3.80373444    2.54626556    3.80373444
    '''
    cell.basis = 'sto-3g'
    cell.a = np.eye(3) * 6.35
    cell.gs = [15] * 3
    cell.verbose = 5
    cell.build()

    nk = [1, 1, 1]
    abs_kpts = cell.make_kpts(nk)
    kmf = dft.KRKS(cell, abs_kpts).mix_density_fit()
    kmf.xc = 'pbe'
    ekpt = kmf.run()
    pywannier90.save_kmf(kmf, 'chk_mf')  # Save the wave function

    # Run pyWannier90 and plot WFs using pyWannier90
    num_wann = 4
    keywords = \
    '''
    exclude_bands : 1,6-9
    begin projections
    C:sp3
    end projections
    '''

    # To use the saved wave function, replace kmf with 'chk_mf'
    w90 = pywannier90.W90(kmf, cell, nk, num_wann, other_keywords=keywords)
    w90.kernel()
    w90.plot_wf(grid=[25, 25, 25], supercell=[1, 1, 1])
コード例 #2
0
    def self_consistent(self, get_band=False):
        '''
        Do self-consistent pDMET
        '''

        tprint.print_msg(
            "--------------------------------------------------------------------"
        )
        tprint.print_msg("- SELF-CONSISTENT DMET CALCULATION ... STARTING -")
        tprint.print_msg("  Convergence criteria")
        tprint.print_msg("    Threshold :", self.SC_threshold)
        tprint.print_msg("  Fitting 1-RDM of :", self.SC_CFtype)
        if self.dft_CF is True:
            tprint.print_msg("  DF-like cost function:", self.xc)
        if self.damping != 1.0:
            tprint.print_msg("  Damping factor   :", self.damping)
        if self.DIIS:
            tprint.print_msg(
                "  DIIS start at %dth cycle and using %d previous umats" %
                (self.DIIS_m, self.DIIS_n))
        #------------------------------------#
        #---- SELF-CONSISTENT PROCEDURE ----#
        #------------------------------------#

        rdm1_kpts, rdm1_R0 = self.local.make_loc_1RDM(self.umat, self.OEH_type)
        for cycle in range(self.SC_maxcycle):

            tprint.print_msg("- CYCLE %d:" % (cycle + 1))
            umat_old = self.umat
            rdm1_R0_old = rdm1_R0

            # Do one-shot with each uvec
            self.one_shot(umat=self.umat)
            tprint.print_msg("   + Chemical potential        : %12.8f" %
                             (self.chempot))

            # Optimize uvec to minimize the cost function
            if self.dft_CF == True:
                result = optimize.minimize(self.CF,
                                           self.uvec,
                                           method='L-BFGS-B',
                                           jac=None,
                                           options={
                                               'disp': False,
                                               'gtol': 1e-6
                                           },
                                           bounds=self.bounds)
            else:
                result = optimize.minimize(self.CF,
                                           self.uvec,
                                           method=self.SC_method,
                                           jac=self.CF_grad,
                                           options={
                                               'disp': False,
                                               'gtol': 1e-12
                                           })
                # result = optimize.minimize(self.CF, self.uvec, method = self.SC_method , options = {'disp': False, 'gtol': 1e-12})

            if result.success == False:
                tprint.print_msg(
                    "     WARNING: Correlation potential is not converged")

            uvec = result.x
            self.umat = self.uvec2umat(uvec)

            #rdm1_kpts, rdm1_R0 = self.local.make_loc_1RDM(self.umat, self.OEH_type)

            # Construct new global 1RDM in k-space
            global_corr_1RDM = self.local.get_1RDM_Rs(self.loc_corr_1RDM_R0)
            global_corr_1RDM = 0.5 * (global_corr_1RDM.T.conj() +
                                      global_corr_1RDM)
            loc_1RDM_R0 = global_corr_1RDM[:, :self.Nimp].reshape(
                self.Nkpts, self.Nimp, self.Nimp)
            rdm1_R0 = loc_1RDM_R0

            # Remove arbitrary chemical potential shifts
            if self.dft_CF == False:
                self.umat = self.umat - np.eye(
                    self.umat.shape[0]) * np.average(np.diag(self.umat))

            if self.verbose > 0:
                tprint.print_msg("   + Correlation potential vector    : ",
                                 uvec)

            umat_diff = umat_old - self.umat
            rdm_diff = rdm1_R0_old - rdm1_R0
            norm_u = np.linalg.norm(umat_diff)
            norm_rdm = np.linalg.norm(rdm_diff)

            tprint.print_msg("   + Cost function             : %20.15f" %
                             (result.fun))
            tprint.print_msg("   + 2-norm of umat difference : %20.15f" %
                             (norm_u))
            tprint.print_msg("   + 2-norm of rdm1 difference : %20.15f" %
                             (norm_rdm))

            # Export band structure at every cycle:
            if get_band:
                band = self.get_bands()
                print("BAND", band.mo_energy_kpts[0])
                print(
                    "Gap", 27.211 *
                    (band.mo_energy_kpts[0][4] - band.mo_energy_kpts[0][3]))
                pywannier90.save_kmf(
                    band,
                    str(self.solver) + '_band_cyc_' + str(cycle + 1))

            # Check convergence of 1-RDM
            if self.dft_CF == True:
                if (norm_rdm <= self.SC_threshold): break
            elif (norm_u <= self.SC_threshold):
                break

            if self.DIIS == True:
                self.umat = self._diis.update(cycle, self.umat, umat_diff)

            if self.damping != 1.0:
                self.umat = (
                    1.0 - self.damping) * umat_old + self.damping * self.umat

            self.uvec = self.umat2uvec(self.umat)
            tprint.print_msg()

        tprint.print_msg("- SELF-CONSISTENT DMET CALCULATION ... DONE -")
        tprint.print_msg(
            "--------------------------------------------------------------------"
        )
コード例 #3
0
    def projected_DMET(self, get_band=False):
        '''
        Do projected DMET
        '''

        tprint.print_msg(
            "--------------------------------------------------------------------"
        )
        tprint.print_msg("- p-DMET CALCULATION ... STARTING -")
        tprint.print_msg("  Convergence criteria")
        tprint.print_msg("    Threshold :", self.SC_threshold)
        tprint.print_msg("  Fitting 1-RDM of :", self.SC_CFtype)

        if self.damping != 1.0:
            tprint.print_msg("  Damping factor   :", self.damping)
        if self.DIIS:
            tprint.print_msg(
                "  DIIS start at %dth cycle and using %d previous umats" %
                (self.DIIS_m, self.DIIS_n))

        #------------------------------------#
        #---- SELF-CONSISTENT PROCEDURE ----#
        #------------------------------------#
        self.loc_1RDM_kpts, self.loc_1RDM_R0 = self.local.make_loc_1RDM(
            0.0, self.OEH_type)
        global_corr_1RDM = self.local.k_to_R(self.loc_1RDM_kpts)
        for cycle in range(self.SC_maxcycle):
            tprint.print_msg("- CYCLE %d:" % (cycle + 1))
            global_corr_1RDM_old = global_corr_1RDM
            self.one_shot(proj_DMET=True)

            if self._is_gamma == False:
                tprint.print_msg("   + Chemical potential        : %12.8f" %
                                 (self.chempot))

            # Construct new global 1RDM in k-space
            global_corr_1RDM = self.local.get_1RDM_Rs(self.loc_corr_1RDM_R0)
            global_corr_1RDM = 0.5 * (global_corr_1RDM.T.conj() +
                                      global_corr_1RDM)
            global_corr_1RDM_residual = global_corr_1RDM_old - global_corr_1RDM
            norm_1RDM = np.linalg.norm(
                global_corr_1RDM_residual) / self.kpts.shape[0]
            tprint.print_msg("   + 2-norm of rdm1 difference : %20.15f" %
                             (norm_1RDM))

            if get_band == True:
                band = self.get_bands()
                pywannier90.save_kmf(
                    band,
                    str(self.solver) + '_band_cyc_' + str(cycle + 1))

            # Check convergence of 1-RDM
            if norm_1RDM <= self.SC_threshold:
                break

            if self.DIIS == True:
                global_corr_1RDM = self._diis.update(
                    cycle, global_corr_1RDM, global_corr_1RDM_residual)

            if self.damping != 1.0:
                global_corr_1RDM = self.damping * global_corr_1RDM + (
                    1 - self.damping) * global_corr_1RDM_old

            # Construct new mean-field 1-RDM from the correlated one
            eigenvals, eigenvecs = np.linalg.eigh(global_corr_1RDM)
            idx = (-eigenvals).argsort()
            eigenvals = eigenvals[idx]
            eigenvecs = eigenvecs[:, idx]
            num_pairs = self.Nelec_total // 2
            global_mf_1RDM = 2 * eigenvecs[:, :num_pairs].dot(
                eigenvecs[:, :num_pairs].T)
            if self._is_gamma == True:
                self.loc_1RDM_R0 = global_mf_1RDM.reshape(
                    1, self.Norbs, self.Norbs) + self.loc_core_1RDM
            else:
                self.loc_1RDM_R0 = global_mf_1RDM[:, :self.Nimp].reshape(
                    self.Nkpts, self.Nimp, self.Nimp)

            self.loc_1RDM_kpts = self.local.R0_to_k(self.loc_1RDM_R0)
            tprint.print_msg()

        tprint.print_msg("- p-DMET CALCULATION ... DONE -")
        tprint.print_msg(
            "--------------------------------------------------------------------"
        )
コード例 #4
0
ファイル: pywannier90.py プロジェクト: chrinide/pyscf
     H                  2.54626556    3.80373444    3.80373444
     H                  3.80373444    2.54626556    3.80373444
    '''
    cell.basis = 'sto-3g'
    cell.a = np.eye(3) * 6.35
    cell.gs = [15] * 3
    cell.verbose = 5
    cell.build()


    nk = [1, 1, 1]
    abs_kpts = cell.make_kpts(nk)
    kmf = dft.KRKS(cell, abs_kpts).mix_density_fit()
    kmf.xc = 'pbe'
    ekpt = kmf.run()
    pywannier90.save_kmf(kmf, 'chk_mf')  # Save the wave function
        
    # Run pyWannier90 and plot WFs using pyWannier90        
    num_wann = 4
    keywords = \
    '''
    exclude_bands : 1,6-9
    begin projections
    C:sp3
    end projections
    '''
    
    # To use the saved wave function, replace kmf with 'chk_mf'
    w90 = pywannier90.W90(kmf, cell, nk, num_wann, other_keywords = keywords)
    w90.kernel()
    w90.plot_wf(grid=[25,25,25], supercell = [1,1,1])