Skip to content

Commit

Permalink
Enable numpy array of get_k_kpts in df_jk.py
Browse files Browse the repository at this point in the history
Dear all,

I found that if the user gives a set of mo_occ or mo_coeff (in numpy array form) to the kmf with GDF, the current will raise an error. 
It assume the mo_coeff, mo_occ is list of tuple.
  • Loading branch information
zhcui authored and sunqm committed Jan 3, 2024
1 parent 429313f commit 558d443
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pyscf/pbc/df/df_jk.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,15 @@ def get_k_kpts(mydf, dm_kpts, hermi=1, kpts=numpy.zeros((1,3)), kpts_band=None,
skmoR = skmo2R = None
if not mydf.force_dm_kbuild:
if mo_coeff is not None:
if isinstance(mo_coeff[0], (list, tuple)):
if isinstance(mo_coeff[0], (list, tuple)) or \
isinstance(mo_coeff[0], numpy.ndarray and mo_coeff[0] == 3):
mo_coeff = [mo for mo1 in mo_coeff for mo in mo1]
if len(mo_coeff) != nset*nkpts: # wrong shape
log.warn('mo_coeff from dm tag has wrong shape. '
'Calculating mo from dm instead.')
mo_coeff = None
elif isinstance(mo_occ[0], (list, tuple)):
elif isinstance(mo_occ[0], (list, tuple)) or \
isinstance(mo_occ[0], numpy.ndarray and mo_occ[0] == 2):
mo_occ = [mo for mo1 in mo_occ for mo in mo1]
if mo_coeff is not None:
skmoR, skmoI = _format_mo(mo_coeff, mo_occ, shape=(nset,nkpts), order='F',
Expand Down Expand Up @@ -704,13 +706,15 @@ def get_k_kpts_kshift(mydf, dm_kpts, kshift, hermi=0, kpts=numpy.zeros((1,3)), k
skmoR = skmo2R = None
if not mydf.force_dm_kbuild:
if mo_coeff is not None:
if isinstance(mo_coeff[0], (list, tuple)):
if isinstance(mo_coeff[0], (list, tuple)) or \
isinstance(mo_coeff[0], numpy.ndarray and mo_coeff[0] == 3):
mo_coeff = [mo for mo1 in mo_coeff for mo in mo1]
if len(mo_coeff) != nset*nkpts: # wrong shape
log.warn('mo_coeff from dm tag has wrong shape. '
'Calculating mo from dm instead.')
mo_coeff = None
elif isinstance(mo_occ[0], (list, tuple)):
elif isinstance(mo_occ[0], (list, tuple)) or \
isinstance(mo_occ[0], numpy.ndarray and mo_occ[0] == 2):
mo_occ = [mo for mo1 in mo_occ for mo in mo1]
if mo_coeff is not None:
skmoR, skmoI = _format_mo(mo_coeff, mo_occ, shape=(nset,nkpts), order='F',
Expand Down

0 comments on commit 558d443

Please sign in to comment.