Skip to content

Commit

Permalink
Fix the class of supercell scf object for the k2gamma conversion (pys…
Browse files Browse the repository at this point in the history
  • Loading branch information
sunqm committed Jan 26, 2024
1 parent 35835bc commit e2f122f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
27 changes: 24 additions & 3 deletions pyscf/pbc/tools/k2gamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def k2gamma(kmf, kmesh=None):
C_{\nu ' n'} = C_{\vecR\mu, \veck m} = \frac{1}{\sqrt{N_{\UC}}}
\e^{\ii \veck\cdot\vecR} C^{\veck}_{\mu m}
'''
from pyscf.pbc import scf
from pyscf.pbc import scf, dft
def transform(mo_energy, mo_coeff, mo_occ):
if isinstance(kmf.kpts, KPoints):
kpts = kmf.kpts.kpts
Expand All @@ -228,17 +228,38 @@ def transform(mo_energy, mo_coeff, mo_occ):

if isinstance(kmf, scf.khf.KRHF):
scell, E_g, C_gamma, mo_occ = transform(mo_energy, mo_coeff, mo_occ)
mf = scf.RHF(scell)
elif isinstance(kmf, scf.kuhf.KUHF):
scell, Ea, Ca, occ_a = transform(mo_energy[0], mo_coeff[0], mo_occ[0])
scell, Eb, Cb, occ_b = transform(mo_energy[1], mo_coeff[1], mo_occ[1])
mf = scf.UHF(scell)
E_g = [Ea, Eb]
C_gamma = [Ca, Cb]
mo_occ = [occ_a, occ_b]
else:
raise NotImplementedError('SCF object %s not supported' % kmf)

known_cls = {
dft.kuks.KUKS : dft.uks.UKS ,
dft.kroks.KROKS: dft.roks.ROKS,
dft.krks.KRKS : dft.rks.RKS ,
dft.kgks.KGKS : dft.gks.GKS ,
scf.kuhf.KUHF : scf.uhf.UHF ,
scf.krohf.KROHF: scf.rohf.ROHF,
scf.khf.KRHF : scf.hf.RHF ,
scf.kghf.KGHF : scf.ghf.GHF ,
}
if kmf.__class__ in known_cls:
mf = known_cls[kmf.__class__](scell)
mf.exxdiv = kmf.exxdiv
if isinstance(mf, KohnShamDFT):
mf.xc = kmf.xc
else:
kmf.warn(f'Unknown SCF object {kmf}. '
'The supercell SCF object is initialized to an HF object.')
if isinstance(kmf, scf.khf.KRHF):
mf = scf.RHF(scell)
else:
mf = scf.UHF(scell)

mf.mo_coeff = C_gamma
mf.mo_energy = E_g
mf.mo_occ = mo_occ
Expand Down
6 changes: 5 additions & 1 deletion pyscf/pbc/tools/test/test_k2gamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,14 @@ def test_k2gamma_ksymm(self):
kpts = cell.make_kpts(kmesh, space_group_symmetry=True)
kmf = scf.KRKS(cell, kpts).density_fit()
kmf.kernel()
c_g_ao = k2gamma.k2gamma(kmf).mo_coeff
mf = k2gamma.k2gamma(kmf)
c_g_ao = mf.mo_coeff

scell = tools.super_cell(cell, kmesh)
mf_sc = scf.RKS(scell).density_fit()
self.assertEqual(mf.__class__, mf_sc.__class__)
self.assertEqual(mf.xc, kmf.xc)

s = mf_sc.get_ovlp()
mf_sc.run()
sc_mo = mf_sc.mo_coeff
Expand Down

0 comments on commit e2f122f

Please sign in to comment.