Skip to content

Commit

Permalink
Remove the numerical implementation of dVia/dx
Browse files Browse the repository at this point in the history
  • Loading branch information
henryw7 committed Jan 7, 2025
1 parent ad0e46b commit 9170172
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 44 deletions.
41 changes: 0 additions & 41 deletions gpu4pyscf/solvent/hessian/pcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,47 +153,6 @@ def pcm_grad_scanner(mol):
pcmobj.reset(pmol)
return de

def fd_grad_vmat(pcmobj, dm, mo_coeff, mo_occ, atmlst=None, verbose=None):
'''
dv_solv / da
slow version with finite difference
'''
log = logger.new_logger(pcmobj, verbose)
t1 = log.init_timer()
pmol = pcmobj.mol.copy()
mol = pmol.copy()
if atmlst is None:
atmlst = range(mol.natm)
nao, nmo = mo_coeff.shape
mocc = mo_coeff[:,mo_occ>0]
nocc = mocc.shape[1]
coords = mol.atom_coords(unit='Bohr')
def pcm_vmat_scanner(mol):
pcmobj.reset(mol)
e, v = pcmobj._get_vind(dm)
return v

mol.verbose = 0
vmat = cupy.empty([len(atmlst), 3, nao, nocc])
eps = 1e-3
for i0, ia in enumerate(atmlst):
for ix in range(3):
dv = numpy.zeros_like(coords)
dv[ia,ix] = eps
mol.set_geom_(coords + dv, unit='Bohr')
vmat0 = pcm_vmat_scanner(mol)

mol.set_geom_(coords - dv, unit='Bohr')
vmat1 = pcm_vmat_scanner(mol)

grad_vmat = (vmat0 - vmat1)/2.0/eps
grad_vmat = contract("ij,jq->iq", grad_vmat, mocc)
grad_vmat = contract("iq,ip->pq", grad_vmat, mo_coeff)
vmat[i0,ix] = grad_vmat
t1 = log.timer_debug1('computing solvent grad veff', *t1)
pcmobj.reset(pmol)
return vmat

def analytic_grad_vmat(pcmobj, dm, mo_coeff, mo_occ, atmlst=None, verbose=None):
'''
dv_solv / da
Expand Down
6 changes: 3 additions & 3 deletions gpu4pyscf/solvent/hessian/smd.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def make_h1(self, mo_coeff, mo_occ, chkfile=None, atmlst=None, verbose=None):
h1ao = super().make_h1(mo_coeff, mo_occ, atmlst=atmlst, verbose=verbose)
if isinstance(self.base, scf.hf.RHF):
dm = self.base.make_rdm1(ao_repr=True)
dv = pcm_hess.fd_grad_vmat(self.base.with_solvent, dm, mo_coeff, mo_occ, atmlst=atmlst, verbose=verbose)
dv = pcm_hess.analytic_grad_vmat(self.base.with_solvent, dm, mo_coeff, mo_occ, atmlst=atmlst, verbose=verbose)
for i0, ia in enumerate(atmlst):
h1ao[i0] += dv[i0]
return h1ao
Expand All @@ -163,8 +163,8 @@ def make_h1(self, mo_coeff, mo_occ, chkfile=None, atmlst=None, verbose=None):
solvent = self.base.with_solvent
dm = self.base.make_rdm1(ao_repr=True)
dm = dm[0] + dm[1]
dva = pcm_hess.fd_grad_vmat(solvent, dm, mo_coeff[0], mo_occ[0], atmlst=atmlst, verbose=verbose)
dvb = pcm_hess.fd_grad_vmat(solvent, dm, mo_coeff[1], mo_occ[1], atmlst=atmlst, verbose=verbose)
dva = pcm_hess.analytic_grad_vmat(solvent, dm, mo_coeff[0], mo_occ[0], atmlst=atmlst, verbose=verbose)
dvb = pcm_hess.analytic_grad_vmat(solvent, dm, mo_coeff[1], mo_occ[1], atmlst=atmlst, verbose=verbose)
for i0, ia in enumerate(atmlst):
h1aoa[i0] += dva[i0]
h1aob[i0] += dvb[i0]
Expand Down

0 comments on commit 9170172

Please sign in to comment.