def get_lcao_xc(calc, P_aqMi, bfs=None, spin=0): nq = len(calc.wfs.ibzk_qc) nao = calc.wfs.setups.nao dtype = calc.wfs.dtype if bfs is None: bfs = get_bfs(calc) if calc.density.nt_sg is None: calc.density.interpolate() nt_sg = calc.density.nt_sg vxct_sg = calc.density.finegd.zeros(calc.wfs.nspins) calc.hamiltonian.xc.calculate(calc.density.finegd, nt_sg, vxct_sg) vxct_G = calc.wfs.gd.zeros() calc.hamiltonian.restrict(vxct_sg[spin], vxct_G) Vxc_qMM = np.zeros((nq, nao, nao), dtype) for q, Vxc_MM in enumerate(Vxc_qMM): bfs.calculate_potential_matrix(vxct_G, Vxc_MM, q) tri2full(Vxc_MM, "L") # Add atomic PAW corrections for a, P_qMi in P_aqMi.items(): D_sp = calc.density.D_asp[a][:] H_sp = np.zeros_like(D_sp) calc.wfs.setups[a].xc_correction.calculate(calc.hamiltonian.xc, D_sp, H_sp) H_ii = unpack(H_sp[spin]) for Vxc_MM, P_Mi in zip(Vxc_qMM, P_qMi): Vxc_MM += dots(P_Mi, H_ii, P_Mi.T.conj()) return Vxc_qMM * Hartree
def get_lcao_xc(calc, P_aqMi, bfs=None, spin=0): nq = len(calc.wfs.kd.ibzk_qc) nao = calc.wfs.setups.nao dtype = calc.wfs.dtype if bfs is None: bfs = get_bfs(calc) if calc.density.nt_sg is None: calc.density.interpolate_pseudo_density() nt_sg = calc.density.nt_sg vxct_sg = calc.density.finegd.zeros(calc.wfs.nspins) calc.hamiltonian.xc.calculate(calc.density.finegd, nt_sg, vxct_sg) vxct_G = calc.wfs.gd.zeros() calc.hamiltonian.restrict_and_collect(vxct_sg[spin], vxct_G) Vxc_qMM = np.zeros((nq, nao, nao), dtype) for q, Vxc_MM in enumerate(Vxc_qMM): bfs.calculate_potential_matrix(vxct_G, Vxc_MM, q) tri2full(Vxc_MM, 'L') # Add atomic PAW corrections for a, P_qMi in P_aqMi.items(): D_sp = calc.density.D_asp[a][:] H_sp = np.zeros_like(D_sp) calc.hamiltonian.xc.calculate_paw_correction(calc.wfs.setups[a], D_sp, H_sp) H_ii = unpack(H_sp[spin]) for Vxc_MM, P_Mi in zip(Vxc_qMM, P_qMi): Vxc_MM += dots(P_Mi, H_ii, P_Mi.T.conj()) return Vxc_qMM * Hartree
def __init__( self, gpwfilename, fixedenergy=0.0, spin=0, ibl=True, basis="sz", zero_fermi=False, pwfbasis=None, lcaoatoms=None, projection_data=None, ): calc = GPAW(gpwfilename, txt=None, basis=basis) assert calc.wfs.gd.comm.size == 1 assert calc.wfs.kpt_comm.size == 1 assert calc.wfs.band_comm.size == 1 if zero_fermi: try: Ef = calc.get_fermi_level() except NotImplementedError: Ef = calc.get_homo_lumo().mean() else: Ef = 0.0 self.ibzk_kc = calc.get_ibz_k_points() self.nk = len(self.ibzk_kc) self.eps_kn = [calc.get_eigenvalues(kpt=q, spin=spin) - Ef for q in range(self.nk)] self.M_k = [sum(eps_n <= fixedenergy) for eps_n in self.eps_kn] print "Fixed states:", self.M_k self.calc = calc self.dtype = self.calc.wfs.dtype self.spin = spin self.ibl = ibl self.pwf_q = [] self.norms_qn = [] self.S_qww = [] self.H_qww = [] if ibl: if pwfbasis is not None: pwfmask = basis_subset2(calc.atoms.get_chemical_symbols(), basis, pwfbasis) if lcaoatoms is not None: lcaoindices = get_bfi2(calc.atoms.get_chemical_symbols(), basis, lcaoatoms) else: lcaoindices = None self.bfs = get_bfs(calc) if projection_data is None: V_qnM, H_qMM, S_qMM, self.P_aqMi = get_lcao_projections_HSP( calc, bfs=self.bfs, spin=spin, projectionsonly=False ) else: V_qnM, H_qMM, S_qMM, self.P_aqMi = projection_data H_qMM -= Ef * S_qMM for q, M in enumerate(self.M_k): if pwfbasis is None: pwf = ProjectedWannierFunctionsIBL(V_qnM[q], S_qMM[q], M, lcaoindices) else: pwf = PWFplusLCAO(V_qnM[q], S_qMM[q], M, pwfmask, lcaoindices) self.pwf_q.append(pwf) self.norms_qn.append(pwf.norms_n) self.S_qww.append(pwf.S_ww) self.H_qww.append(pwf.rotate_matrix(self.eps_kn[q][:M], H_qMM[q])) else: if projection_data is None: V_qnM = get_lcao_projections_HSP(calc, spin=spin) else: V_qnM = projection_data for q, M in enumerate(self.M_k): pwf = ProjectedWannierFunctionsFBL(V_qnM[q], M, ortho=False) self.pwf_q.append(pwf) self.norms_qn.append(pwf.norms_n) self.S_qww.append(pwf.S_ww) self.H_qww.append(pwf.rotate_matrix(self.eps_kn[q])) for S in self.S_qww: print "Condition number: %0.1e" % condition_number(S)
def __init__(self, gpwfilename, fixedenergy=0., spin=0, ibl=True, basis='sz', zero_fermi=False, pwfbasis=None, lcaoatoms=None, projection_data=None): calc = GPAW(gpwfilename, txt=None, basis=basis) assert calc.wfs.gd.comm.size == 1 assert calc.wfs.kd.comm.size == 1 assert calc.wfs.bd.comm.size == 1 if zero_fermi: try: Ef = calc.get_fermi_level() except NotImplementedError: Ef = calc.get_homo_lumo().mean() else: Ef = 0.0 self.ibzk_kc = calc.get_ibz_k_points() self.nk = len(self.ibzk_kc) self.eps_kn = [ calc.get_eigenvalues(kpt=q, spin=spin) - Ef for q in range(self.nk) ] self.M_k = [sum(eps_n <= fixedenergy) for eps_n in self.eps_kn] print('Fixed states:', self.M_k) self.calc = calc self.dtype = self.calc.wfs.dtype self.spin = spin self.ibl = ibl self.pwf_q = [] self.norms_qn = [] self.S_qww = [] self.H_qww = [] if ibl: if pwfbasis is not None: pwfmask = basis_subset2(calc.atoms.get_chemical_symbols(), basis, pwfbasis) if lcaoatoms is not None: lcaoindices = get_bfi2(calc.atoms.get_chemical_symbols(), basis, lcaoatoms) else: lcaoindices = None self.bfs = get_bfs(calc) if projection_data is None: V_qnM, H_qMM, S_qMM, self.P_aqMi = get_lcao_projections_HSP( calc, bfs=self.bfs, spin=spin, projectionsonly=False) else: V_qnM, H_qMM, S_qMM, self.P_aqMi = projection_data H_qMM -= Ef * S_qMM for q, M in enumerate(self.M_k): if pwfbasis is None: pwf = ProjectedWannierFunctionsIBL(V_qnM[q], S_qMM[q], M, lcaoindices) else: pwf = PWFplusLCAO(V_qnM[q], S_qMM[q], M, pwfmask, lcaoindices) self.pwf_q.append(pwf) self.norms_qn.append(pwf.norms_n) self.S_qww.append(pwf.S_ww) self.H_qww.append( pwf.rotate_matrix(self.eps_kn[q][:M], H_qMM[q])) else: if projection_data is None: V_qnM = get_lcao_projections_HSP(calc, spin=spin) else: V_qnM = projection_data for q, M in enumerate(self.M_k): pwf = ProjectedWannierFunctionsFBL(V_qnM[q], M, ortho=False) self.pwf_q.append(pwf) self.norms_qn.append(pwf.norms_n) self.S_qww.append(pwf.S_ww) self.H_qww.append(pwf.rotate_matrix(self.eps_kn[q])) for S in self.S_qww: print('Condition number: %0.1e' % condition_number(S))
spos_ac = bulk.get_scaled_positions() tci = TwoCenterIntegrals(calc.wfs.gd, setups, calc.wfs.gamma, calc.wfs.ibzk_qc) tci.set_positions(spos_ac) # Calculate projector overlaps, and (lower triangle of-) S and T matrices S_qMM = np.zeros((nq, nao, nao), dtype) T_qMM = np.zeros((nq, nao, nao), dtype) P_aqMi = {} for a in range(len(spos_ac)): ni = calc.wfs.setups[a].ni P_aqMi[a] = np.zeros((nq, nao, ni), dtype) tci.calculate(spos_ac, S_qMM, T_qMM, P_aqMi) # Calculate projections using BFS bfs = get_bfs(calc) V_qnM = np.zeros((nq, nbands, nao), dtype) for q, V_nM in enumerate(V_qnM): bfs.integrate2(kpt_q[q].psit_nG[:], V_nM, q) for a, P_ni in kpt_q[q].P_ani.items(): P_Mi = P_aqMi[a][q] V_nM += np.dot(np.dot(P_ni, setups[a].dO_ii), P_Mi.T.conj()) bfs_qnM = V_qnM.copy() # Calculate projections using LFC lfc = get_lfc(calc) V_qnM = np.zeros((nq, nbands, nao), dtype) V_qAni = [lfc.dict(nbands) for q in range(nq)] for q, V_Ani in enumerate(V_qAni): lfc.integrate(kpt_q[q].psit_nG[:], V_Ani, q)
tci = TwoCenterIntegrals(calc.wfs.gd, setups, calc.wfs.gamma, calc.wfs.ibzk_qc) tci.set_positions(spos_ac) # Calculate projector overlaps, and (lower triangle of-) S and T matrices S_qMM = np.zeros((nq, nao, nao), dtype) T_qMM = np.zeros((nq, nao, nao), dtype) P_aqMi = {} for a in range(len(spos_ac)): ni = calc.wfs.setups[a].ni P_aqMi[a] = np.zeros((nq, nao, ni), dtype) tci.calculate(spos_ac, S_qMM, T_qMM, P_aqMi) # Calculate projections using BFS bfs = get_bfs(calc) V_qnM = np.zeros((nq, nbands, nao), dtype) for q, V_nM in enumerate(V_qnM): bfs.integrate2(kpt_q[q].psit_nG[:], V_nM, q) for a, P_ni in kpt_q[q].P_ani.items(): P_Mi = P_aqMi[a][q] V_nM += np.dot(np.dot(P_ni, setups[a].dO_ii), P_Mi.T.conj()) bfs_qnM = V_qnM.copy() # Calculate projections using LFC lfc = get_lfc(calc) V_qnM = np.zeros((nq, nbands, nao), dtype) V_qAni = [lfc.dict(nbands) for q in range(nq)] for q, V_Ani in enumerate(V_qAni):