Skip to content

Commit

Permalink
Codestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
sunqm committed Oct 16, 2023
1 parent 501ed17 commit 6d51cee
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions pyscf/solvent/test/test_pcm_grad.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
import unittest
import numpy
from pyscf import scf, gto, mcscf, solvent, cc, lib, tddft, tdscf
from pyscf.solvent import pcm
from pyscf.solvent import pcm
from pyscf.solvent.grad import pcm as pcm_grad

def setUpModule():
global mol, epsilon, lebedev_order
mol = gto.Mole()
mol.atom = '''
mol.atom = '''
O 0.0000000000 -0.0000000000 0.1174000000
H -0.7570000000 -0.0000000000 -0.4696000000
H 0.7570000000 0.0000000000 -0.4696000000
Expand Down Expand Up @@ -51,10 +51,10 @@ def test_dA_dF(self):
cm.lebedev_order = 3
cm.method = 'IEF-PCM'
cm.build()

dF, dA = pcm_grad.get_dF_dA(cm.surface)
dD, dS, dSii = pcm_grad.get_dD_dS(cm.surface, dF, with_S=True, with_D=True)

def get_FADS(mol):
mol.build()
cm = pcm.PCM(mol)
Expand All @@ -66,7 +66,7 @@ def get_FADS(mol):
D = cm._intermediates['D']
S = cm._intermediates['S']
return F, A, D, S

eps = 1e-5
for ia in range(mol.natm):
p0,p1 = cm.surface['gslice_by_atom'][ia]
Expand All @@ -91,7 +91,7 @@ def get_FADS(mol):

assert numpy.linalg.norm(dF0 - dF[:,ia,j]) < 1e-8
assert numpy.linalg.norm(dA0 - dA[:,ia,j]) < 1e-8

# the diagonal entries are calcualted separately
assert numpy.linalg.norm(dSii[:,ia,j] - numpy.diag(dS0)) < 1e-8
numpy.fill_diagonal(dS0, 0)
Expand All @@ -100,12 +100,12 @@ def get_FADS(mol):
dS_ia[p0:p1] = dS[p0:p1,:,j]
dS_ia[:,p0:p1] -= dS[:,p0:p1,j]
assert numpy.linalg.norm(dS0 - dS_ia) < 1e-8

dD_ia = numpy.zeros_like(dD0)
dD_ia[p0:p1] = dD[p0:p1,:,j]
dD_ia[:,p0:p1] -= dD[:,p0:p1,j]
assert numpy.linalg.norm(dD0 - dD_ia) < 1e-8

def test_grad_CPCM(self):
cm = pcm.PCM(mol)
cm.eps = epsilon
Expand All @@ -116,18 +116,18 @@ def test_grad_CPCM(self):
mf.verbose = 0
mf.conv_tol = 1e-12
e_tot = mf.kernel()

g = mf.nuc_grad_method()
grad = g.kernel()

g0 = numpy.asarray([
[0.49773047433563E-15, -0.12128126037559E-15, -0.58936988992306E-01],
[0.22810111996954E-01, -0.68951901317025E-17, 0.29468494708267E-01],
[-0.22810111996957E-01, 0.12949813945902E-15, 0.29468494708266E-01]])

print(f"Gradient error in CPCM: {numpy.linalg.norm(g0 - grad)}")
assert numpy.linalg.norm(g0 - grad) < 1e-9

def test_grad_COSMO(self):
cm = pcm.PCM(mol)
cm.eps = epsilon
Expand All @@ -141,15 +141,15 @@ def test_grad_COSMO(self):

g = mf.nuc_grad_method()
grad = g.kernel()

g0 = numpy.asarray(
[[-1.33560836e-16, 8.70874355e-17, -5.89638726e-02],
[ 2.28202396e-02, 2.63784344e-17, 2.94819363e-02],
[-2.28202396e-02, -1.08799896e-16, 2.94819363e-02]])

print(f"Gradient error in COSMO: {numpy.linalg.norm(g0 - grad)}")
assert numpy.linalg.norm(g0 - grad) < 1e-9

def test_grad_IEFPCM(self):
cm = pcm.PCM(mol)
cm.eps = epsilon
Expand All @@ -160,17 +160,17 @@ def test_grad_IEFPCM(self):
mf.verbose = 0
mf.conv_tol = 1e-12
e_tot = mf.kernel()

g = mf.nuc_grad_method()
grad = g.kernel()

g0 = numpy.asarray([
[0.18357915015649E-14, 0.14192681822347E-15, -0.58988087999658E-01],
[0.22822709179063E-01, -0.10002010417168E-15, 0.29494044211805E-01],
[-0.22822709179066E-01, -0.31051364515588E-16, 0.29494044211806E-01]])
print(f"Gradient error in IEFPCM: {numpy.linalg.norm(g0 - grad)}")
assert numpy.linalg.norm(g0 - grad) < 1e-9

def test_grad_SSVPE(self):
cm = pcm.PCM(mol)
cm.eps = epsilon
Expand All @@ -184,14 +184,14 @@ def test_grad_SSVPE(self):

g = mf.nuc_grad_method()
grad = g.kernel()

g0 = numpy.asarray([
[0.76104817971710E-15, 0.11185701540547E-15, -0.58909172879217E-01],
[0.22862990009767E-01, -0.13861633974903E-15, 0.29454586651678E-01],
[-0.22862990009769E-01, 0.34988765678591E-16, 0.29454586651679E-01]])
print(f"Gradient error in SS(V)PE: {numpy.linalg.norm(g0 - grad)}")
assert numpy.linalg.norm(g0 - grad) < 1e-9

def test_casci_grad(self):
mf = scf.RHF(mol0).PCM().run()
mc = solvent.PCM(mcscf.CASCI(mf, 2, 2))
Expand All @@ -218,9 +218,9 @@ def test_casscf_grad(self):
mf = scf.RHF(mol2).run()
mc2 = solvent.PCM(mcscf.CASSCF(mf, 2, 2)).run(conv_tol=1e-9)
e2 = mc2.e_tot

self.assertAlmostEqual((e2-e1)/dx, de[0,2], 2)

def test_ccsd_grad(self):
mf = scf.RHF(mol0).PCM()
mf.conv_tol = 1e-12
Expand All @@ -239,7 +239,7 @@ def test_ccsd_grad(self):
mycc1.conv_tol = 1e-12
mycc1.kernel()
e1 = mycc1.e_tot

mf = scf.RHF(mol2)
mf.conv_tol = 1e-12
mf.run()
Expand All @@ -248,7 +248,7 @@ def test_ccsd_grad(self):
mycc2.conv_tol = 1e-12
mycc2.kernel()
e2 = mycc2.e_tot

self.assertAlmostEqual((e2-e1)/dx, de[0,2], 3)


Expand Down

0 comments on commit 6d51cee

Please sign in to comment.