Exemplo n.º 1
0
    def test_prdred_eval(self):
        from pyscf.nao.m_prod_talman import prod_talman_c
        from pyscf.nao.m_ao_eval_libnao import ao_eval_libnao as ao_eval
        from pyscf.nao.m_csphar_talman_libnao import csphar_talman_libnao as csphar_jt
        from pyscf.nao.m_siesta_ion_xml import siesta_ion_xml
        from pyscf.nao import ao_log_c
        from numpy import sqrt, zeros, array

        import os

        dname = os.path.dirname(os.path.abspath(__file__))
        sp2ion = []
        sp2ion.append(siesta_ion_xml(dname + '/O.ion.xml'))

        aos = ao_log_c().init_ao_log_ion(sp2ion)
        jmx = aos.jmx
        pt = prod_talman_c(aos)

        spa, spb = 0, 0
        rav, rbv, rcv = array([0.0, 0.0, -1.0]), array([0.0, 0.0,
                                                        1.0]), zeros(3)
        coord = np.array(
            [0.4, 0.1, 0.22]
        )  # Point at which we will compute the expansion and the original product
        ylma, ylmb, ylmc = csphar_jt(coord - rav, jmx), csphar_jt(
            coord - rbv, jmx), csphar_jt(coord + rcv, pt.lbdmx)
        rcs = sqrt(sum((coord + rcv)**2))

        serr = 0.0
        merr = 0.0
        nval = 0
        for la, phia in zip(aos.sp_mu2j[spa], aos.psi_log[spa]):
            fa = pt.log_interp(phia, sqrt(sum((coord - rav)**2)))
            for lb, phib in zip(aos.sp_mu2j[spb], aos.psi_log[spb]):
                fb = pt.log_interp(phib, sqrt(sum((coord - rbv)**2)))

                jtb, clbdtb, lbdtb = pt.prdred_terms(la, lb)
                jtb, clbdtb, lbdtb, rhotb = pt.prdred_libnao(
                    phib, lb, rbv, phia, la, rav, rcv)
                rhointerp = pt.log_interp(rhotb, rcs)

                for ma in range(-la, la + 1):
                    aovala = ylma[la * (la + 1) + ma] * fa
                    for mb in range(-lb, lb + 1):
                        aovalb = ylmb[lb * (lb + 1) + mb] * fb

                        ffr, m = pt.prdred_further_scalar(
                            la, ma, lb, mb, rcv, jtb, clbdtb, lbdtb, rhointerp)
                        prdval = 0.0j
                        for j, fr in enumerate(ffr):
                            prdval = prdval + fr * ylmc[j * (j + 1) + m]

                        derr = abs(aovala * aovalb - prdval)
                        nval = nval + 1
                        serr = serr + derr
                        merr = max(merr, derr)

        self.assertTrue(merr < 1.0e-05)
        self.assertTrue(serr / nval < 1.0e-06)
Exemplo n.º 2
0
  def test_prdred_eval(self):
    from pyscf.nao.m_prod_talman import prod_talman_c
    from pyscf.nao.m_ao_eval_libnao import ao_eval_libnao as ao_eval
    from pyscf.nao.m_csphar_talman_libnao import csphar_talman_libnao as csphar_jt
    from pyscf.nao.m_siesta_ion_xml import siesta_ion_xml
    from pyscf.nao import ao_log_c
    from numpy import sqrt, zeros, array

    import os
    
    dname = os.path.dirname(os.path.abspath(__file__))
    sp2ion = []
    sp2ion.append(siesta_ion_xml(dname+'/O.ion.xml'))

    aos = ao_log_c().init_ao_log_ion(sp2ion)
    jmx = aos.jmx
    pt = prod_talman_c(aos)

    spa,spb=0,0
    rav,rbv,rcv = array([0.0,0.0,-1.0]),array([0.0,0.0,1.0]), zeros(3)
    coord = np.array([0.4, 0.1, 0.22]) # Point at which we will compute the expansion and the original product
    ylma,ylmb,ylmc = csphar_jt(coord-rav, jmx), csphar_jt(coord-rbv, jmx),csphar_jt(coord+rcv, pt.lbdmx)
    rcs = sqrt(sum((coord+rcv)**2))
 
    serr = 0.0
    merr = 0.0
    nval = 0
    for la,phia in zip(aos.sp_mu2j[spa], aos.psi_log[spa]):
      fa = pt.log_interp(phia, sqrt(sum((coord-rav)**2)))
      for lb,phib in zip(aos.sp_mu2j[spb], aos.psi_log[spb]):
        fb = pt.log_interp(phib, sqrt(sum((coord-rbv)**2)))

        jtb,clbdtb,lbdtb=pt.prdred_terms(la,lb)
        jtb,clbdtb,lbdtb,rhotb = pt.prdred_libnao(phib,lb,rbv,phia,la,rav,rcv)
        rhointerp = pt.log_interp(rhotb, rcs)
        
        for ma in range(-la,la+1):
          aovala = ylma[la*(la+1)+ma]*fa
          for mb in range(-lb,lb+1):
            aovalb = ylmb[lb*(lb+1)+mb]*fb

            ffr,m = pt.prdred_further_scalar(la,ma,lb,mb,rcv,jtb,clbdtb,lbdtb,rhointerp)
            prdval = 0.0j
            for j,fr in enumerate(ffr): prdval = prdval + fr*ylmc[j*(j+1)+m]

            derr = abs(aovala*aovalb-prdval)
            nval = nval + 1
            serr = serr + derr
            merr = max(merr, derr)

    self.assertTrue(merr<1.0e-05)
    self.assertTrue(serr/nval<1.0e-06)
Exemplo n.º 3
0
  def __init__(self, log_mesh, jmx=7, ngl=96, lbdmx=14):
    """
    Expansion of the products of two atomic orbitals placed at given locations and around a center between these locations 
    [1] Talman JD. Multipole Expansions for Numerical Orbital Products, Int. J. Quant. Chem. 107, 1578--1584 (2007)
      ngl : order of Gauss-Legendre quadrature
      log_mesh : instance of log_mesh_c defining the logarithmic mesh (rr and pp arrays)
      jmx : maximal angular momentum quantum number of each atomic orbital in a product
      lbdmx : maximal angular momentum quantum number used for the expansion of the product phia*phib
    """
    from numpy.polynomial.legendre import leggauss
    from pyscf.nao.m_log_interp import log_interp_c
    from pyscf.nao.m_csphar_talman_libnao import csphar_talman_libnao as csphar_jt
    assert ngl>2 
    assert jmx>-1
    assert hasattr(log_mesh, 'rr') 
    assert hasattr(log_mesh, 'pp')
    
    self.ngl = ngl
    self.lbdmx = lbdmx
    self.xx,self.ww = leggauss(ngl)
    log_mesh_c.__init__(self)
    self.init_log_mesh(log_mesh.rr, log_mesh.pp)

    self.plval=np.zeros([2*(self.lbdmx+jmx+1), ngl])
    self.plval[0,:] = 1.0
    self.plval[1,:] = self.xx
    for kappa in range(1,2*(self.lbdmx+jmx)+1):
      self.plval[kappa+1, :]= ((2*kappa+1)*self.xx*self.plval[kappa, :]-kappa*self.plval[kappa-1, :])/(kappa+1)

    self.log_interp = log_interp_c(self.rr)
    self.ylm_cr = csphar_jt([0.0,0.0,1.0], self.lbdmx+2*jmx)

    return
Exemplo n.º 4
0
    def __init__(self, log_mesh, jmx=7, ngl=96, lbdmx=14):
        """
    Expansion of the products of two atomic orbitals placed at given locations and around a center between these locations 
    [1] Talman JD. Multipole Expansions for Numerical Orbital Products, Int. J. Quant. Chem. 107, 1578--1584 (2007)
      ngl : order of Gauss-Legendre quadrature
      log_mesh : instance of log_mesh_c defining the logarithmic mesh (rr and pp arrays)
      jmx : maximal angular momentum quantum number of each atomic orbital in a product
      lbdmx : maximal angular momentum quantum number used for the expansion of the product phia*phib
    """
        from numpy.polynomial.legendre import leggauss
        from pyscf.nao.m_log_interp import log_interp_c
        from pyscf.nao.m_csphar_talman_libnao import csphar_talman_libnao as csphar_jt
        assert ngl > 2
        assert jmx > -1
        assert hasattr(log_mesh, 'rr')
        assert hasattr(log_mesh, 'pp')

        self.ngl = ngl
        self.lbdmx = lbdmx
        self.xx, self.ww = leggauss(ngl)
        log_mesh_c.__init__(self)
        self.init_log_mesh(log_mesh.rr, log_mesh.pp)

        self.plval = np.zeros([2 * (self.lbdmx + jmx + 1), ngl])
        self.plval[0, :] = 1.0
        self.plval[1, :] = self.xx
        for kappa in range(1, 2 * (self.lbdmx + jmx) + 1):
            self.plval[kappa + 1, :] = (
                (2 * kappa + 1) * self.xx * self.plval[kappa, :] -
                kappa * self.plval[kappa - 1, :]) / (kappa + 1)

        self.log_interp = log_interp_c(self.rr)
        self.ylm_cr = csphar_jt([0.0, 0.0, 1.0], self.lbdmx + 2 * jmx)

        return
Exemplo n.º 5
0
  def prdred_further(self, ja,ma,jb,mb,rcen,jtb,clbdtb,lbdtb,rhotb):
    """ Evaluate the Talman's expansion at given Cartesian coordinates"""
    from pyscf.nao.m_thrj import thrj
    from pyscf.nao.m_fact import sgn
    from pyscf.nao.m_csphar_talman_libnao import csphar_talman_libnao as csphar_jt
    from numpy import zeros, sqrt, pi, array
    
    assert all(rcen == zeros(3)) # this works only when center is at the origin
    nterm = len(jtb)
    assert nterm == len(clbdtb)
    assert nterm == len(lbdtb)
    assert nterm == rhotb.shape[0]
    assert self.nr == rhotb.shape[1]

    ffr = zeros([self.lbdmx+1,self.nr], np.complex128)
    m = mb + ma
    ylm_cr = csphar_jt([0.0,0.0,1.0], lbdtb.max())
    for j,clbd,lbd,rho in zip(jtb,clbdtb,lbdtb,rhotb):
      ffr[clbd,:]=ffr[clbd,:] + thrj(ja,jb,j,ma,mb,-m)*thrj(j,clbd,lbd,-m,m,0)*rho*ylm_cr[lbd*(lbd+1)]
    return ffr,m
Exemplo n.º 6
0
    def prdred_further(self, ja, ma, jb, mb, rcen, jtb, clbdtb, lbdtb, rhotb):
        """ Evaluate the Talman's expansion at given Cartesian coordinates"""
        from pyscf.nao.m_thrj import thrj
        from pyscf.nao.m_fact import sgn
        from pyscf.nao.m_csphar_talman_libnao import csphar_talman_libnao as csphar_jt
        from numpy import zeros, sqrt, pi, array

        assert all(
            rcen == zeros(3))  # this works only when center is at the origin
        nterm = len(jtb)
        assert nterm == len(clbdtb)
        assert nterm == len(lbdtb)
        assert nterm == rhotb.shape[0]
        assert self.nr == rhotb.shape[1]

        ffr = zeros([self.lbdmx + 1, self.nr], np.complex128)
        m = mb + ma
        ylm_cr = csphar_jt([0.0, 0.0, 1.0], lbdtb.max())
        for j, clbd, lbd, rho in zip(jtb, clbdtb, lbdtb, rhotb):
            ffr[clbd, :] = ffr[clbd, :] + thrj(ja, jb, j, ma, mb, -m) * thrj(
                j, clbd, lbd, -m, m, 0) * rho * ylm_cr[lbd * (lbd + 1)]
        return ffr, m