Skip to content

Commit

Permalink
Fix LRC-RKS (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
fishjojo authored Apr 16, 2024
1 parent 4b51e90 commit 99a9d16
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
11 changes: 11 additions & 0 deletions pyscfad/dft/test/test_rks.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ def test_rks_nuc_grad_hybrid(get_mol):
assert abs(g1-g0).max() < 1e-6
assert abs(g2-g0).max() < 1e-6

def test_rks_nuc_grad_lrc(get_mol):
mol = get_mol()
mf = dft.RKS(mol)
mf.xc = 'HYB_GGA_XC_LRC_WPBE'
g1 = mf.energy_grad(mode="rev").coords
mf.kernel()
g2 = mf.energy_grad(mode="rev").coords
g0 = mf.nuc_grad_method().kernel()
assert abs(g1-g0).max() < 1e-6
assert abs(g2-g0).max() < 1e-6

#FIXME MGGA is broken since pyscf v2.1
def test_rks_nuc_grad_mgga_skip(get_mol, get_mol_p, get_mol_m):
mol = get_mol
Expand Down
21 changes: 12 additions & 9 deletions pyscfad/scf/hf.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,8 @@ def kernel(mf, conv_tol=1e-10, conv_tol_grad=None,
mf.with_df.build()
else:
if mf._eri is None:
if config.moleintor_opt:
mf._eri = mol.intor('int2e', aosym='s4')
else:
mf._eri = mol.intor('int2e', aosym='s1')
aosym = 's4' if config.moleintor_opt else 's1'
mf._eri = mol.intor('int2e', aosym=aosym)

scf_conv = False
mo_energy = mo_coeff = mo_occ = None
Expand Down Expand Up @@ -371,12 +369,17 @@ def get_jk(self, mol=None, dm=None, hermi=1, with_j=True, with_k=True,
mol = self.mol
if dm is None:
dm = self.make_rdm1()

aosym = 's4' if config.moleintor_opt else 's1'
if self._eri is None:
if config.moleintor_opt:
self._eri = self.mol.intor('int2e', aosym='s4')
else:
self._eri = self.mol.intor('int2e', aosym='s1')
vj, vk = dot_eri_dm(self._eri, dm, hermi, with_j, with_k)
self._eri = mol.intor('int2e', aosym=aosym)
if omega:
with mol.with_range_coulomb(omega):
_eri = mol.intor('int2e', aosym=aosym)
else:
_eri = self._eri

vj, vk = dot_eri_dm(_eri, dm, hermi, with_j, with_k)
return vj, vk

def get_init_guess(self, mol=None, key='minao'):
Expand Down
16 changes: 0 additions & 16 deletions pyscfad/scf/uhf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from jax import numpy as np
from pyscf.lib import module_method
from pyscf.scf import uhf as pyscf_uhf
from pyscfad import config
from pyscfad import util
from pyscfad.lib import logger, stop_grad
from pyscfad.scf import hf
Expand Down Expand Up @@ -100,21 +99,6 @@ def eig(self, h, s):
e_b, c_b = self._eigh(h[1], s)
return np.array((e_a,e_b)), np.array((c_a,c_b))

@wraps(pyscf_uhf.UHF.get_jk)
def get_jk(self, mol=None, dm=None, hermi=1, with_j=True, with_k=True,
omega=None):
if mol is None:
mol = self.mol
if dm is None:
dm = self.make_rdm1()
if self._eri is None:
if config.moleintor_opt:
self._eri = mol.intor('int2e', aosym='s4')
else:
self._eri = mol.intor('int2e', aosym='s1')
vj, vk = hf.dot_eri_dm(self._eri, dm, hermi, with_j, with_k)
return vj, vk

@wraps(pyscf_uhf.UHF.get_veff)
def get_veff(self, mol=None, dm=None, dm_last=0, vhf_last=0, hermi=1):
if mol is None:
Expand Down

0 comments on commit 99a9d16

Please sign in to comment.