Skip to content

Commit

Permalink
Fix df-grad for UHF when symmetry is enabled (issue pyscf#2054)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunqm committed Feb 3, 2024
1 parent 0e0345b commit 4437ce0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pyscf/df/grad/rhf.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ def _decompose_rdm1 (mf_grad, mol, dm):
if hasattr (dm, 'mo_coeff') and hasattr (dm, 'mo_occ'):
mo_coeff = dm.mo_coeff
mo_occ = dm.mo_occ
if getattr(mo_occ, 'ndim', None) == 1: # RHF orbitals
mo_coeff = [mo_coeff]
mo_occ = [mo_occ]
else:
s0 = mol.intor ('int1e_ovlp')
mo_occ = []
Expand All @@ -352,10 +355,7 @@ def _decompose_rdm1 (mf_grad, mol, dm):
mo_occ.append (n)
mo_coeff.append (c)
mo_occ = numpy.stack (mo_occ, axis=0)
nmo = mo_occ.shape[-1]

mo_coeff = numpy.asarray(mo_coeff).reshape(-1,nao,nmo)
mo_occ = numpy.asarray(mo_occ).reshape(-1,nmo)
orbor = []
orbol = []
for i in range(nset):
Expand Down
1 change: 1 addition & 0 deletions pyscf/df/test/test_df_grad.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def test_uhf_grad(self):
['O' , (0. , 0. , 0.)],
[1 , (0. , -0.757 , 0.587)],
[1 , (0. , 0.757 , 0.587)] ]
mol.symmetry = True
mol.verbose = 0
mol.basis = '631g'
mol.spin = 2
Expand Down
2 changes: 1 addition & 1 deletion pyscf/scf/uhf_symm.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ def _finalize(self):
mo_b = lib.tag_array(self.mo_coeff[1][:,idxb], orbsym=orbsymb,
degen_mapping=degen_b)
self.mo_coeff = (mo_a, mo_b)
self.mo_occ = (self.mo_occ[0][idxa], self.mo_occ[1][idxb])
self.mo_occ = numpy.asarray([self.mo_occ[0][idxa], self.mo_occ[1][idxb]])
if self.chkfile:
chkfile.dump_scf(self.mol, self.chkfile, self.e_tot, self.mo_energy,
self.mo_coeff, self.mo_occ, overwrite_mol=False)
Expand Down

0 comments on commit 4437ce0

Please sign in to comment.