def test_vrtx_cc_apairs(self):
        """ This is to test a batch generation vertices for bilocal atomic pairs. """
        from pyscf.nao import system_vars_c, prod_basis_c
        from numpy import allclose
        import os

        dname = os.path.dirname(os.path.abspath(__file__))
        sv = system_vars_c().init_siesta_xml(label='water', cd=dname)
        pbb = prod_basis_c().init_prod_basis_pp_batch(sv)
        pba = prod_basis_c().init_prod_basis_pp(sv)

        for a, b in zip(pba.bp2info, pbb.bp2info):
            for a1, a2 in zip(a.atoms, b.atoms):
                self.assertEqual(a1, a2)
            for a1, a2 in zip(a.cc2a, b.cc2a):
                self.assertEqual(a1, a2)
            self.assertTrue(allclose(a.vrtx, b.vrtx))
            self.assertTrue(allclose(a.cc, b.cc))

        self.assertLess(
            abs(pbb.get_da2cc_coo().tocsr() -
                pba.get_da2cc_coo().tocsr()).sum(), 1e-9)
        self.assertLess(
            abs(pbb.get_dp_vertex_coo().tocsr() -
                pba.get_dp_vertex_coo().tocsr()).sum(), 1e-10)
Exemplo n.º 2
0
    def test_water_pp_pb(self):
        """ This is for initializing with SIESTA radial orbitals """
        from pyscf.nao import system_vars_c, prod_basis_c
        from numpy import einsum, array
        import os
        dname = os.path.dirname(os.path.abspath(__file__))
        sv = system_vars_c().init_siesta_xml(label='water', cd=dname)
        self.assertTrue(abs(sv.ucell).sum() > 0)
        pb = prod_basis_c().init_prod_basis_pp(sv)
        self.assertEqual(sv.norbs, 23)

        self.assertEqual(len(pb.bp2info), 3)
        vden = pb.get_ac_vertex_array()
        ccden = pb.get_da2cc_den()
        moms = pb.comp_moments()

        oref = sv.overlap_coo().toarray()
        over = einsum('lab,l->ab', vden, moms[0])

        dcoo = sv.dipole_coo()
        dref = array([dc.toarray() for dc in dcoo])
        dipo = einsum('lab,lx->xab', vden, moms[1])

        emean = (abs(oref - over).sum() / (oref.size))
        emax = (abs(oref - over).max())
        self.assertAlmostEqual(emean, 0.000102115844911, 4)
        self.assertAlmostEqual(emax, 0.00182562129245, 4)

        emean = (abs(dref - dipo).sum() / (dref.size))
        emax = (abs(dref - dipo).max())
        self.assertAlmostEqual(emean, 0.000618731257284, 4)
        self.assertAlmostEqual(emax, 0.0140744946617, 4)
Exemplo n.º 3
0
 def do_overlap_check_of_pb(self, **kvargs):
   from pyscf.nao import prod_basis_c, vertex_loop_c
   self.pb = prod_basis_c(self.sv, **kvargs)
   self.vl = vertex_loop_c(self.pb, **kvargs)
   self.mom0,self.mom1 = self.pb.prod_log.comp_moments()
   ad2cc = self.pb.get_ad2cc_den()
   pab2v = self.pb.get_vertex_array()
Exemplo n.º 4
0
    def test_tddft_iter_lda(self):
        """ Compute polarization with LDA TDDFT  """
        from pyscf.nao import system_vars_c, prod_basis_c, tddft_iter_c
        from pyscf.nao.m_comp_dm import comp_dm
        from timeit import default_timer as timer

        dname = os.path.dirname(os.path.abspath(__file__))
        sv = system_vars_c().init_siesta_xml(label='water', cd=dname)
        pb = prod_basis_c().init_prod_basis_pp(sv, jcutoff=7)
        td = tddft_iter_c(pb.sv,
                          pb,
                          tddft_iter_broadening=1e-2,
                          xc_code='LDA,PZ',
                          level=0)
        omegas = np.linspace(0.0, 2.0, 150) + 1j * td.eps
        pxx = -td.comp_polariz_xx(omegas).imag
        data = np.array([omegas.real * 27.2114, pxx])
        np.savetxt('water.tddft_iter_lda.omega.inter.pxx.txt',
                   data.T,
                   fmt=['%f', '%f'])
        data_ref = np.loadtxt(dname +
                              '/water.tddft_iter_lda.omega.inter.pxx.txt-ref')
        #print('    td.rf0_ncalls ', td.rf0_ncalls)
        #print(' td.matvec_ncalls ', td.matvec_ncalls)
        self.assertTrue(np.allclose(data_ref, data.T, rtol=1.0, atol=1e-05))
Exemplo n.º 5
0
def run_tddft_iter(calculator, label, freq):
    from pyscf.nao import system_vars_c, prod_basis_c, tddft_iter_c
    if label == "siesta":
        sv = system_vars_c().init_siesta_xml()
    elif label == "gpaw":
        sv = system_vars_c().init_gpaw(calculator)
    else:
        raise ValueError("Only siesta or gpaw calculator for the moment!")

    pb = prod_basis_c().init_prod_basis_pp(sv)
    td = tddft_iter_c(pb.sv, pb, tddft_iter_broadening=1e-2)
    omegas = np.linspace(freq[0], freq[freq.shape[0] - 1],
                         freq.shape[0]) + 1j * td.eps

    pxx_nonin = np.zeros(omegas.shape[0], dtype=float)
    pxx_inter = np.zeros(omegas.shape[0], dtype=float)

    vext = np.transpose(td.moms1)
    for iomega, omega in enumerate(omegas):
        pxx_nonin[iomega] = -np.dot(td.apply_rf0(vext[0, :], omega),
                                    vext[0, :]).imag

    pxx_inter = -td.comp_polariz_xx(omegas).imag

    return pxx_nonin, pxx_inter
Exemplo n.º 6
0
    def test_bse_iter_rpa(self):
        """ Compute polarization with LDA TDDFT  """
        from timeit import default_timer as timer
        from pyscf.nao import system_vars_c, prod_basis_c, bse_iter_c
        from timeit import default_timer as timer

        dname = os.path.dirname(os.path.abspath(__file__))
        sv = system_vars_c().init_siesta_xml(label='water', cd=dname)
        pb = prod_basis_c().init_prod_basis_pp(sv)
        bse = bse_iter_c(pb.sv, pb, iter_broadening=1e-2)
        omegas = np.linspace(0.0, 2.0, 500) + 1j * bse.eps
        dab = [d.toarray() for d in sv.dipole_coo()]

        pxx = np.zeros(len(omegas))
        for iw, omega in enumerate(omegas):
            for ixyz in range(1):
                vab = bse.apply_l0(dab[ixyz], omega)
                pxx[iw] = pxx[iw] - (vab.imag * dab[ixyz]).sum()

        data = np.array([omegas.real * 27.2114, pxx])
        #np.savetxt('water.bse_iter.omega.nonin.pxx.txt', data.T, fmt=['%f','%f'])
        data_ref = np.loadtxt(dname +
                              '/water.bse_iter_rpa.omega.nonin.pxx.txt-ref')
        #print('    bse.l0_ncalls ', bse.l0_ncalls)
        self.assertTrue(np.allclose(data_ref, data.T, rtol=1.0, atol=1e-05))
Exemplo n.º 7
0
  def test_fxc(self):
    """ Compute TDDFT interaction kernel  """
    from timeit import default_timer as timer

    from pyscf.nao import system_vars_c, prod_basis_c
    from pyscf.nao.m_comp_dm import comp_dm
    from timeit import default_timer as timer
    
    sv = system_vars_c().init_siesta_xml(label='water', cd=os.path.dirname(os.path.abspath(__file__)))
    pb = prod_basis_c().init_prod_basis_pp(sv)
    dm = comp_dm(sv.wfsx.x, sv.get_occupations())
    fxc = pb.comp_fxc_lil(dm, xc_code='1.0*LDA,1.0*PZ', level=4)
Exemplo n.º 8
0
 def test_ls_contributing(self):
     """ To test the list of contributing centers """
     from pyscf.nao import system_vars_c, prod_basis_c
     sv = system_vars_c().init_pyscf_gto(mol)
     pb = prod_basis_c()
     pb.sv = sv
     pb.sv.ao_log.sp2rcut[0] = 10.0
     pb.prod_log = sv.ao_log
     pb.prod_log.sp2rcut[0] = 10.0
     pb.ac_rcut = max(sv.ao_log.sp2rcut)
     pb.ac_npc_max = 10
     lsc = pb.ls_contributing(0, 1)
     self.assertEqual(len(lsc), 10)
     lsref = [0, 1, 13, 7, 5, 43, 42, 39, 38, 10]
     for i, ref in enumerate(lsref):
         self.assertEqual(lsc[i], ref)
Exemplo n.º 9
0
    def test_bse_rpa(self):
        """ Compute polarization with RPA via 2-point non-local potentials (BSE solver)  """
        from timeit import default_timer as timer
        from pyscf.nao import system_vars_c, prod_basis_c, bse_iter_c
        from timeit import default_timer as timer

        dname = os.path.dirname(os.path.abspath(__file__))
        sv = system_vars_c().init_siesta_xml(label='water', cd=dname)
        pb = prod_basis_c().init_prod_basis_pp(sv)
        bse = bse_iter_c(pb.sv, pb, iter_broadening=1e-2)
        omegas = np.linspace(0.0, 2.0, 150) + 1j * bse.eps

        pxx = np.zeros(len(omegas))
        for iw, omega in enumerate(omegas):
            for ixyz in range(1):
                vab = bse.apply_l(bse.dab[ixyz], omega)
                pxx[iw] = pxx[iw] - (vab.imag * bse.dab[ixyz]).sum()

        data = np.array([omegas.real * 27.2114, pxx])
        #np.savetxt('water.bse_iter_rpa.omega.inter.pxx.txt', data.T, fmt=['%f','%f'])
        data_ref = np.loadtxt(dname +
                              '/water.bse_iter_rpa.omega.inter.pxx.txt-ref')
Exemplo n.º 10
0
    """ Our standard minimal check """
    dipcoo = self.sv.dipole_coo(**kw)
    mom0,mom1 = self.comp_moments()
    vpab = self.get_ac_vertex_array()
    xyz2err = []
    for i,dref in enumerate(dipcoo):
      dref = dref.toarray()
      dprd = np.einsum('p,pab->ab', mom1[:,i],vpab)
      xyz2err.append([abs(dprd-dref).sum()/dref.size, np.amax(abs(dref-dprd))])
    return xyz2err

#
#
#
if __name__=='__main__':
  from pyscf.nao import prod_basis_c, nao
  from pyscf.nao.m_overlap_coo import overlap_coo
  from pyscf import gto
  import numpy as np
  
  mol = gto.M(atom='O 0 0 0; H 0 0 0.5; H 0 0.5 0', basis='ccpvdz') # coordinates in Angstrom!
  sv = nao(gto=mol)
  print(sv.atom2s)
  s_ref = overlap_coo(sv).todense()
  pb = prod_basis_c()
  pb.init_prod_basis_pp_batch(sv)
  mom0,mom1=pb.comp_moments()
  pab2v = pb.get_ac_vertex_array()
  s_chk = einsum('pab,p->ab', pab2v,mom0)
  print(abs(s_chk-s_ref).sum()/s_chk.size, abs(s_chk-s_ref).max())
Exemplo n.º 11
0
# Copyright 2014-2018 The PySCF Developers. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function, division
import numpy as np
from pyscf.nao import system_vars_c, prod_basis_c, tddft_iter_c

sv = system_vars_c().init_siesta_xml(label='siesta', cd='.', force_gamma=True)
pb = prod_basis_c().init_prod_basis_pp(sv)
td = tddft_iter_c(pb.sv, pb)
omegas = np.linspace(0.0,0.25,150)+1j*td.eps
pxx = -td.comp_polariz_xx(omegas).imag
data = np.array([omegas.real*27.2114, pxx])
print('    td.rf0_ncalls ', td.rf0_ncalls)
print(' td.matvec_ncalls ', td.matvec_ncalls)
np.savetxt('tddft_iter.omega.inter.pxx.txt', data.T, fmt=['%f','%f'])
Exemplo n.º 12
0
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function, division
import os, unittest, numpy as np
from pyscf.nao import system_vars_c, prod_basis_c, tddft_iter_c
import h5py

dname = os.path.dirname(os.path.abspath(__file__))
sv = system_vars_c().init_siesta_xml(label='water', cd=dname)
pb = prod_basis_c().init_prod_basis_pp(sv, jcutoff=7)
td = tddft_iter_c(pb.sv, pb, tddft_iter_broadening=1e-2, xc_code='RPA')

np.savetxt("kernel.txt", td.kernel)
np.save("kernel.npy", td.kernel)

hdf = h5py.File("kernel.hdf5", "w")
hdf.create_dataset("kernel_pack", data=td.kernel)
hdf.close()


class KnowValues(unittest.TestCase):
    def test_non_inter_polariz(self):
        """ This is non-interacting polarizability TDDFT with SIESTA starting point """
        omegas = np.linspace(0.0, 2.0, 500) + 1j * td.eps
        pxx = td.comp_nonin(omegas).imag
Exemplo n.º 13
0
from __future__ import print_function, division
import numpy as np
from pyscf.nao import system_vars_c, prod_basis_c, tddft_iter_c

sv = system_vars_c().init_siesta_xml(label='siesta', cd='.', force_gamma=True)
pb = prod_basis_c().init_prod_basis_pp(sv)
td = tddft_iter_c(pb.sv, pb)
omegas = np.linspace(0.0, 0.25, 150) + 1j * td.eps
pxx = -td.comp_polariz_xx(omegas).imag
data = np.array([omegas.real * 27.2114, pxx])
print('    td.rf0_ncalls ', td.rf0_ncalls)
print(' td.matvec_ncalls ', td.matvec_ncalls)
np.savetxt('tddft_iter.omega.inter.pxx.txt', data.T, fmt=['%f', '%f'])
Exemplo n.º 14
0
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function, division
from timeit import default_timer as timer
import os
from pyscf.nao import system_vars_c, prod_basis_c, tddft_iter_c
from numpy import allclose


t1 = timer()
sv = system_vars_c().init_siesta_xml(label='siesta', cd='.', force_gamma=True)
t2 = timer(); print(t2-t1); t1 = timer()

pbb = prod_basis_c().init_prod_basis_pp_batch(sv)
t2 = timer(); print(t2-t1); t1 = timer()

pba = prod_basis_c().init_prod_basis_pp(sv)
t2 = timer(); print(t2-t1); t1 = timer()

for a,b in zip(pba.bp2info,pbb.bp2info):
  for a1,a2 in zip(a.atoms,b.atoms): assert a1==a2
  for a1,a2 in zip(a.cc2a, b.cc2a): assert a1==a2
  assert allclose(a.vrtx, b.vrtx)
  assert allclose(a.cc, b.cc)

print(abs(pbb.get_da2cc_coo().tocsr()-pba.get_da2cc_coo().tocsr()).sum(), \
      abs(pbb.get_dp_vertex_coo().tocsr()-pba.get_dp_vertex_coo().tocsr()).sum())

Exemplo n.º 15
0
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function, division
from os.path import abspath, dirname
from pyscf.nao import system_vars_c, prod_basis_c
import unittest, numpy as np

sv = system_vars_c().init_siesta_xml(label='water',
                                     cd=dirname(abspath(__file__)))
pb = prod_basis_c().init_prod_basis_pp_batch(sv)
vab_arr_ref = pb.get_dp_vertex_array()


class KnowValues(unittest.TestCase):
    def test_pb_doubly_sparse(self):
        """ This is to test generation of a doubly sparse format. """
        self.assertEqual(len(vab_arr_ref.shape), 3)
        self.assertEqual(vab_arr_ref.shape, (pb.npdp, pb.norbs, pb.norbs))
        vab_ds = pb.get_dp_vertex_doubly_sparse(axis=2)
        vab_arr = vab_ds.toarray()
        self.assertLess(abs(vab_arr - vab_arr_ref).sum() / vab_arr.size, 1e-15)

    def test_pb_sparse(self):
        """ This is to test generation of a doubly sparse format. """
        self.assertEqual(len(vab_arr_ref.shape), 3)
Exemplo n.º 16
0
        self.vdata = np.zeros(self.i2inf[-1][0])
        for i in range(niter):
            s, f, c, tr = self.i2inf[i][0], self.i2inf[
                i + 1][0], self.i2inf[i][3], self.i2inf[i][10]
            if tr == 0:
                self.vdata[s:f] = self.c2d[c]["vertex"].reshape(f - s)
            elif tr == 1:
                self.vdata[s:f] = einsum('pab->pba',
                                         self.c2d[c]["vertex"]).reshape(f - s)
            else:
                raise RuntimeError('!tr?')


#
#
#
if __name__ == '__main__':
    from pyscf.nao import system_vars_c, prod_basis_c, vertex_loop_c
    from pyscf import gto
    import numpy as np
    from timeit import default_timer as timer
    import matplotlib.pyplot as plt

    mol = gto.M(atom='O 0 0 0; H 0 0 1; H 0 1 0',
                basis='ccpvdz')  # coordinates in Angstrom!
    sv = system_vars_c(gto=mol)
    pb = prod_basis_c(sv)
    vl = vertex_loop_c(pb)
    print(dir(vl))
    print(vl.vdata.sum())
Exemplo n.º 17
0
        for i, dref in enumerate(dipcoo):
            dref = dref.toarray()
            dprd = np.einsum('p,pab->ab', mom1[:, i], vpab)
            xyz2err.append([
                abs(dprd - dref).sum() / dref.size,
                np.amax(abs(dref - dprd))
            ])
        return xyz2err


#
#
#
if __name__ == '__main__':
    from pyscf.nao import prod_basis_c, nao
    from pyscf.nao.m_overlap_coo import overlap_coo
    from pyscf import gto
    import numpy as np

    mol = gto.M(atom='O 0 0 0; H 0 0 0.5; H 0 0.5 0',
                basis='ccpvdz')  # coordinates in Angstrom!
    sv = nao(gto=mol)
    print(sv.atom2s)
    s_ref = overlap_coo(sv).todense()
    pb = prod_basis_c()
    pb.init_prod_basis_pp_batch(sv)
    mom0, mom1 = pb.comp_moments()
    pab2v = pb.get_ac_vertex_array()
    s_chk = einsum('pab,p->ab', pab2v, mom0)
    print(abs(s_chk - s_ref).sum() / s_chk.size, abs(s_chk - s_ref).max())
Exemplo n.º 18
0
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function, division
from timeit import default_timer as timer
import os
from pyscf.nao import system_vars_c, prod_basis_c, tddft_iter_c
from numpy import allclose

t1 = timer()
sv = system_vars_c().init_siesta_xml(label='siesta', cd='.', force_gamma=True)
t2 = timer()
print('system_vars_c().init_siesta_xml ', t2 - t1)
t1 = timer()

pbb = prod_basis_c().init_prod_basis_pp_batch(sv)
t2 = timer()
print('prod_basis_c().init_prod_basis_pp_batch(sv) ', t2 - t1)
t1 = timer()

pba = prod_basis_c().init_prod_basis_pp(sv)
t2 = timer()
print('prod_basis_c().init_prod_basis_pp(sv) ', t2 - t1)
t1 = timer()

for a, b in zip(pba.bp2info, pbb.bp2info):
    for a1, a2 in zip(a.atoms, b.atoms):
        assert a1 == a2
    for a1, a2 in zip(a.cc2a, b.cc2a):
        assert a1 == a2
    assert allclose(a.vrtx, b.vrtx)