Repository: pyscf/pyscf — pull request #2577 (python)
Title: Fix GTH-PP integrals (fix #2575)


Resolved issues:
title: Possible bug in GTH PP
body: MWE
```
from pyscf.pbc import gto
import numpy as np

cell= gto.Cell(atom='''Cu .0 .0 .0''',
               a=np.array([[0.5, 0.5, 0], [0, 0.5, 0.5], [0.5, 0, 0.5]])* 3.0,
               basis='gth-dzvp-molopt-sr',
               pseudo='gth-pbe-q11',
               verbose=4
              ).build()
kpts = cell.make_kpts([2,2,2])
mf = cell.KRKS(xc='pbe0', kpts=kpts).density_fit()
mf.max_cycle=2
mf.run()
```
traceback
```
  File "/share/home/srwang/pbc/gthpp.py", line 15, in <module>
    mf.run()
  File "/share/home/srwang/pyscf2/pyscf/lib/misc.py", line 638, in run
    self.kernel(*args)
  File "<string>", line 2, in kernel
  File "/share/home/srwang/pyscf2/pyscf/scf/hf.py", line 2000, in scf
    kernel(self, self.conv_tol, self.conv_tol_grad,
  File "/share/home/srwang/pyscf2/pyscf/scf/hf.py", line 128, in kernel
    h1e = mf.get_hcore(mol)
  File "/share/home/srwang/pyscf2/pyscf/pbc/scf/khf.py", line 77, in get_hcore
    nuc = lib.asarray(mf.with_df.get_pp(kpts))
  File "/share/home/srwang/pyscf2/pyscf/pbc/df/df.py", line 393, in get_pp
    vpp = dfbuilder.get_pp()
  File "/share/home/srwang/pyscf2/pyscf/pbc/df/rsdf_builder.py", line 1031, in get_pp
    vpp += pp2builder.get_pp_loc_part2()
ValueError: operands could not be broadcast together with shapes (8,25,25) (8,) (8,25,25)
```

Hints:

Fix patch:
diff --git a/pyscf/pbc/df/aft.py b/pyscf/pbc/df/aft.py
index 1440cc7f63..87a1d323a3 100644
--- a/pyscf/pbc/df/aft.py
+++ b/pyscf/pbc/df/aft.py
@@ -329,7 +329,8 @@ def get_pp_loc_part2(self):
             else:
                 lib.logger.warn(cell, 'cell.pseudo was specified but its elements %s '
                                 'were not found in the system.', cell._pseudo.keys())
-            vpploc = [0] * nkpts
+            nao = cell.nao
+            vpploc = np.zeros((nkpts, nao, nao))
             return vpploc
 
         rcut = self._estimate_rcut_3c1e(rs_cell, fake_cells)
diff --git a/pyscf/tdscf/_lr_eig.py b/pyscf/tdscf/_lr_eig.py
index 28beab7ffd..0eaa964bf5 100644
--- a/pyscf/tdscf/_lr_eig.py
+++ b/pyscf/tdscf/_lr_eig.py
@@ -524,10 +524,7 @@ def real_eig(aop, x0, precond, tol_residual=1e-5, nroots=1, x0sym=None, pick=Non
     assert pick is None
     assert callable(precond)
 
-    if isinstance(verbose, logger.Logger):
-        log = verbose
-    else:
-        log = logger.Logger(sys.stdout, verbose)
+    log = logger.new_logger(verbose)
 
     assert x0.ndim == 2
     A_size = x0.shape[1] // 2


Test patch:
diff --git a/pyscf/pbc/df/test/test_aft.py b/pyscf/pbc/df/test/test_aft.py
index f637883643..c3cfc14e7d 100644
--- a/pyscf/pbc/df/test/test_aft.py
+++ b/pyscf/pbc/df/test/test_aft.py
@@ -352,6 +352,20 @@ def test_aft_get_pp(self):
         self.assertAlmostEqual(abs(v0 - v3).max(), 0, 8)
         self.assertAlmostEqual(lib.fp(v0) - (-5.7070290795125445-0.00038722541238732697j), 0, 8)
 
+    # issue 2575
+    def test_aft_get_pp1(self):
+        cell = pgto.M(atom='Cu .0 .0 .0', a=np.eye(3)*3, spin=1,
+               basis=[[1, [1, 1]]], pseudo='''Cu
+1    0   10
+0.53    0
+1
+0.26    1   1.8''')
+        kpts = cell.make_kpts([2,1,1])
+        ref = fft.FFTDF(cell, kpts).get_pp()
+        v = aft.AFTDF(cell, kpts).get_pp()
+        self.assertAlmostEqual(abs(v - ref).max(), 0, 8)
+        self.assertAlmostEqual(lib.fp(v), 0.37494551685809624, 8)
+
     def test_aft_get_nuc(self):
         v0 = fft.FFTDF(cell, kpts[0]).get_nuc()
         v1 = aft.AFTDF(cell, kpts[0]).get_nuc()