Exemple #1
0
  def test_water_pp_pb(self):
    """ This is for initializing with SIESTA radial orbitals """
    from numpy import einsum, array
    import os
    dname = os.path.dirname(os.path.abspath(__file__))
    sv = mf(label='water', cd=dname)
    sv.diag_check()
    self.assertTrue(abs(sv.ucell).sum()>0)
    pb = sv.pb
    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)
Exemple #2
0
  def test_dens_elec(self):
    """ Compute density in coordinate space with scf, integrate and compare with number of electrons """
    from timeit import default_timer as timer
    
    sv = mf(label='water', cd=os.path.dirname(os.path.abspath(__file__)))
    dm = sv.make_rdm1()
    #dm = sv.comp_dm()
    #print(sv.get_occupations())
    #print(dir(sv.ao_log) )
    #print((sv.ao_log.psi_log[0][0]**2 *sv.ao_log.rr**3 * np.log(sv.ao_log.rr[1]/sv.ao_log.rr[0])).sum())
    #print((sv.ao_log.psi_log[0][1]**2 *sv.ao_log.rr**3 * np.log(sv.ao_log.rr[1]/sv.ao_log.rr[0])).sum())
    #print((sv.ao_log.psi_log[0][2]**2 *sv.ao_log.rr**3 * np.log(sv.ao_log.rr[1]/sv.ao_log.rr[0])).sum())
    #print((sv.ao_log.psi_log[0][3]**2 *sv.ao_log.rr**3 * np.log(sv.ao_log.rr[1]/sv.ao_log.rr[0])).sum())
    #print((sv.ao_log.psi_log[0][4]**2 *sv.ao_log.rr**3 * np.log(sv.ao_log.rr[1]/sv.ao_log.rr[0])).sum())
    #
    #print((sv.ao_log.psi_log[1][0]**2 *sv.ao_log.rr**3 * np.log(sv.ao_log.rr[1]/sv.ao_log.rr[0])).sum())
    #print((sv.ao_log.psi_log[1][1]**2 *sv.ao_log.rr**3 * np.log(sv.ao_log.rr[1]/sv.ao_log.rr[0])).sum())
    #print((sv.ao_log.psi_log[1][2]**2 *sv.ao_log.rr**3 * np.log(sv.ao_log.rr[1]/sv.ao_log.rr[0])).sum())
    
    grid = sv.build_3dgrid_pp(level=5)
    
    #t1 = timer()
    #dens1 = sv.dens_elec_vec(grid.coords, dm)
    #t2 = timer(); print(t2-t1); t1 = timer()
    
    t1 = timer()
    dens = sv.dens_elec(grid.coords, dm)
    #t2 = timer(); print(t2-t1); t1 = timer()
    
    nelec = np.einsum("is,i", dens, grid.weights)[0]
    #t2 = timer(); print(t2-t1, nelec, sv.hsx.nelec, dens.shape); t1 = timer()

    self.assertAlmostEqual(nelec, sv.hsx.nelec, 2)
Exemple #3
0
 def test_aos_libnao(self):
   """ Computing of the atomic orbitals """
  
   sv = mf(label='water', cd=os.path.dirname(os.path.abspath(__file__)))
   cc = Cube(sv, nx=20, ny=20, nz=20)
   aos = sv.comp_aos_den(cc.get_coords())
   self.assertEqual(aos.shape[0], cc.nx*cc.ny*cc.nz)
   self.assertEqual(aos.shape[1], sv.norbs)
Exemple #4
0
    def test_aos_libnao(self):
        """ Computing of the atomic orbitals """

        sv = mf(label='water', cd=os.path.dirname(os.path.abspath(__file__)))
        cc = Cube(sv, nx=20, ny=20, nz=20)
        aos = sv.comp_aos_den(cc.get_coords())
        self.assertEqual(aos.shape[0], cc.nx * cc.ny * cc.nz)
        self.assertEqual(aos.shape[1], sv.norbs)
    def test_sv_after_gpaw(self):
        """ init ao_log_c with it radial orbitals from GPAW """

        if calc is None: return

        self.assertTrue(hasattr(calc, 'setups'))
        sv = mf(gpaw=calc)
        self.assertEqual(sv.ao_log.nr, 1024)
  def test_sv_after_gpaw(self):
    """ init ao_log_c with it radial orbitals from GPAW """

    if calc is None: return

    self.assertTrue(hasattr(calc, 'setups'))
    sv = mf(gpaw=calc)
    self.assertEqual(sv.ao_log.nr, 1024)
Exemple #7
0
 def test_exc(self):
   """ Compute exchange-correlation energy """
   from timeit import default_timer as timer
   
   sv = mf(label='water', cd=os.path.dirname(os.path.abspath(__file__)))
   dm = sv.make_rdm1()
   exc = sv.exc(dm, xc_code='1.0*LDA,1.0*PZ', level=4)
   #self.assertAlmostEqual(exc, -4.1422234271159333) ? redone water?
   self.assertAlmostEqual(exc, -4.1422239276270201)
 def test_mo_cube_libnao(self):
   """ Computing of the atomic orbitals """
  
   sv = mf(label='water', cd=os.path.dirname(os.path.abspath(__file__)))
   cc = Cube(sv, nx=40, ny=40, nz=40)
   co2val = sv.comp_aos_den(cc.get_coords())
   nocc_0t = int(sv.nelectron / 2)
   c2orb =  np.dot(co2val, sv.wfsx.x[0,0,nocc_0t,:,0]).reshape((cc.nx, cc.ny, cc.nz))
   cc.write(c2orb, "water_mo.cube", comment='H**O')
  def test_sv_after_gpaw(self):
    """ init ao_log_c with it radial orbitals from GPAW """
    if calc is None: return

    self.assertTrue(hasattr(calc, 'setups'))
    sv = mf(gpaw=calc)
    self.assertEqual(sv.ao_log.nr, 1024)
    over = sv.overlap_coo().toarray()
    error = sv.hsx.check_overlaps(over)
    self.assertLess(error, 1e-4)
    def test_mo_cube_libnao(self):
        """ Computing of the atomic orbitals """

        sv = mf(label='water', cd=os.path.dirname(os.path.abspath(__file__)))
        cc = Cube(sv, nx=40, ny=40, nz=40)
        co2val = sv.comp_aos_den(cc.get_coords())
        nocc_0t = int(sv.nelectron / 2)
        c2orb = np.dot(co2val, sv.wfsx.x[0, 0, nocc_0t, :, 0]).reshape(
            (cc.nx, cc.ny, cc.nz))
        cc.write(c2orb, "water_mo.cube", comment='H**O')
 def test_137_h2o_rks_nonin_pb(self):
     """ This  """
     mol = gto.M(verbose=1,
                 atom='O 0 0 0; H 0 0.489 1.074; H 0 0.489 -1.074',
                 basis='cc-pvdz')
     gto_mf = dft.RKS(mol)
     gto_mf.kernel()
     nao_mf = mf(gto=mol, mf=gto_mf, gen_pb=False)
     comega = np.arange(0.0, 2.0, 0.01) + 1j * 0.03
     pnonin = -nao_mf.polariz_nonin_ave_matelem(comega).imag
     data = np.array([comega.real * HARTREE2EV, pnonin])
     np.savetxt('test_137_h2o_rks_nonin_pb.txt', data.T, fmt=['%f', '%f'])
     data_ref = np.loadtxt('test_137_h2o_rks_nonin_pb.txt-ref').T
     self.assertTrue(np.allclose(data_ref, data, atol=1e-6, rtol=1e-3))
Exemple #12
0
    def test_dens_elec(self):
        """ Compute density in coordinate space with scf, integrate and compare with number of electrons """
        from timeit import default_timer as timer

        gto_mf = scf_gto.RKS(mol)
        gto_mf.kernel()

        sv = mf(mf=gto_mf, gto=mol)
        dm = sv.make_rdm1()
        grid = sv.build_3dgrid_pp(level=5)
        dens = sv.dens_elec(grid.coords, dm)
        nelec = np.einsum("is,i", dens, grid.weights)[0]

        self.assertAlmostEqual(nelec, sv.nelectron, 6)
Exemple #13
0
    def test_siesta2sv_df(self):
        import subprocess
        import os

        siesta_fdf = """
    xml.write                  .true.
    PAO.EnergyShift            100 meV
    %block ChemicalSpeciesLabel
     1  11  Na
    %endblock ChemicalSpeciesLabel
    
    NumberOfAtoms       2
    NumberOfSpecies     1
    %block AtomicCoordinatesAndAtomicSpecies
        0.77573521    0.00000000    0.00000000   1
       -0.77573521    0.00000000    0.00000000   1
    %endblock AtomicCoordinatesAndAtomicSpecies
    
    MD.NumCGsteps              0
    COOP.Write                 .true.
    WriteDenchar               .true.
    """
        label = 'siesta'
        fi = open(label + '.fdf', 'w')
        print(siesta_fdf, file=fi)
        fi.close()
        for sp in ['Na']:
            try:
                os.remove(sp + '.psf')
            except:
                pass
            try:
                pppath = get_pseudo(sp)
            except:
                print('get_pseudo( ' + sp +
                      ' ) is not working--> skip siesta run')
                return
            os.symlink(pppath, sp + '.psf')
        errorcode = subprocess.call(get_siesta_command(label), shell=True)
        if errorcode:
            raise RuntimeError(
                'siesta returned an error: {0}'.format(errorcode))

        # run test system_vars
        from pyscf.nao import mf
        sv = mf(label=label)
        self.assertEqual(sv.norbs, 10)
        self.assertTrue(sv.diag_check())
        self.assertTrue(sv.overlap_check())
  def test_vrtx_cc_apairs(self):
    """ This is to test a batch generation vertices for bilocal atomic pairs. """
    from numpy import allclose

    dname = os.path.dirname(os.path.abspath(__file__))
    sv = mf(label='water', cd=dname)
    pbb = sv.pb
    pba = prod_basis(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_sparse().tocsr()-pba.get_da2cc_sparse().tocsr()).sum(), 1e-9)
    self.assertLess(abs(pbb.get_dp_vertex_sparse().tocsr()-pba.get_dp_vertex_sparse().tocsr()).sum(), 1e-10)
Exemple #15
0
  def test_siesta2sv_df(self):
    import subprocess
    import os

    siesta_fdf = """
    xml.write                  .true.
    PAO.EnergyShift            100 meV
    %block ChemicalSpeciesLabel
     1  11  Na
    %endblock ChemicalSpeciesLabel
    
    NumberOfAtoms       2
    NumberOfSpecies     1
    %block AtomicCoordinatesAndAtomicSpecies
        0.77573521    0.00000000    0.00000000   1
       -0.77573521    0.00000000    0.00000000   1
    %endblock AtomicCoordinatesAndAtomicSpecies
    
    MD.NumCGsteps              0
    COOP.Write                 .true.
    WriteDenchar               .true.
    """
    label = 'siesta'
    fi = open(label+'.fdf', 'w')
    print(siesta_fdf, file=fi)
    fi.close()
    for sp in ['Na']: 
      try:
        os.remove(sp+'.psf')
      except :
        pass
      try:
        pppath = get_pseudo(sp)
      except:
        print('get_pseudo( '+sp+' ) is not working--> skip siesta run' )
        return
      os.symlink(pppath, sp+'.psf')
    errorcode = subprocess.call(get_siesta_command(label), shell=True)
    if errorcode: raise RuntimeError('siesta returned an error: {0}'.format(errorcode))

    # run test system_vars
    from pyscf.nao import mf
    sv  = mf(label=label)
    self.assertEqual(sv.norbs, 10)
    self.assertTrue( sv.diag_check() )
    self.assertTrue( sv.overlap_check())
Exemple #16
0
    def test_vrtx_cc_apairs(self):
        """ This is to test a batch generation vertices for bilocal atomic pairs. """
        from numpy import allclose

        dname = os.path.dirname(os.path.abspath(__file__))
        sv = mf(label='water', cd=dname)
        pbb = sv.pb
        pba = prod_basis(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_sparse().tocsr() -
                pba.get_da2cc_sparse().tocsr()).sum(), 1e-9)
        self.assertLess(
            abs(pbb.get_dp_vertex_sparse().tocsr() -
                pba.get_dp_vertex_sparse().tocsr()).sum(), 1e-10)
    def test_read_siesta_bulk_spin(self):
        """ Test reading of bulk, spin-resolved SIESTA calculation  """

        chdir = os.path.dirname(os.path.abspath(__file__)) + '/ice'
        sv = mf(label='siesta', cd=chdir)
        sv.diag_check()
Exemple #18
0
 def test_fireball(self):
     """ Test computation of matrix elements of overlap after fireball """
     sv = mf(fireball="fireball.out", gen_pb=False)
     s_ref = sv.hsx.s4_csr.toarray()
     s = sv.overlap_coo().toarray()
Exemple #19
0
    def test_dft_sv(self):
        """ Try to compute the xc potential """

        sv = mf(label='water', cd=os.path.dirname(os.path.abspath(__file__)))
        vxc = sv.vxc_lil()
Exemple #20
0
 def test_sf_gw_res_corr(self):
   """ This is choice of wmin and wmax in GW """
   mol = gto.M( verbose = 1, atom = '''H 0 0 0;  H 0.17 0.7 0.587''', basis = 'cc-pvdz',)
   gto_mf = scf.RHF(mol)
   gto_mf.kernel()
   s = mf(mf=gto_mf, gto=mol)
Exemple #21
0
from __future__ import print_function, division
import os,unittest,numpy as np
from pyscf.nao import mf

dname = os.path.dirname(os.path.abspath(__file__))
dft = mf(label='water', cd=dname)

class KnowValues(unittest.TestCase):

  def test_dos(self):
    """ This is DoS with the KS eigenvalues """
    omegas = np.linspace(-1.0,1.0,500)+1j*0.01
    dos = dft.dos(omegas)
    data = np.array([27.2114*omegas.real, dos])
    np.savetxt('water.dos.txt', data.T, fmt=['%f','%f'])
    data_ref = np.loadtxt(dname+'/water.dos.txt-ref')
    self.assertTrue(np.allclose(data_ref,data.T, rtol=1.0, atol=1e-05))
    
  def test_pdos(self):
    """ This is PDoS with SIESTA starting point """
    omegas = np.linspace(-1.0,1.0,500)+1j*0.01
    pdos = dft.pdos(omegas)
    data = np.array([27.2114*omegas.real, pdos[0], pdos[1], pdos[2]])
    np.savetxt('water.pdos.txt', data.T)
    data_ref = np.loadtxt(dname+'/water.pdos.txt-ref')
    self.assertTrue(np.allclose(data_ref,data.T, rtol=1.0, atol=1e-05))


if __name__ == "__main__": unittest.main()
Exemple #22
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 os,unittest
from pyscf.nao import mf

sv = mf(label='water', cd=os.path.dirname(os.path.abspath(__file__)))

class KnowValues(unittest.TestCase):

  def test_init_sv_libnao(self):
    """ Init system variables on libnao's site """
    sv.init_libnao()
    

if __name__ == "__main__": unittest.main()
 def test_read_siesta_bulk_spin(self):
   """ Test reading of bulk, spin-resolved SIESTA calculation  """
   
   chdir = os.path.dirname(os.path.abspath(__file__))+'/ice'
   sv  = mf(label='siesta', cd=chdir)
   sv.diag_check()
Exemple #24
0
        s = np.sqrt(ss + 0.25) - 0.5

        return ss, s * 2 + 1


#
# Example of reading pySCF mean-field calculation.
#
if __name__ == "__main__":
    from pyscf import gto, scf as scf_gto
    from pyscf.nao import nao, mf
    """ Interpreting small Gaussian calculation """
    mol = gto.M(atom='O 0 0 0; H 0 0 1; H 0 1 0; Be 1 0 0',
                basis='ccpvdz')  # coordinates in Angstrom!
    dft = scf_gto.RKS(mol)
    dft.kernel()

    sv = mf(mf=dft, gto=dft.mol, rcut_tol=1e-9, nr=512, rmin=1e-6)

    print(sv.ao_log.sp2norbs)
    print(sv.ao_log.sp2nmult)
    print(sv.ao_log.sp2rcut)
    print(sv.ao_log.sp_mu2rcut)
    print(sv.ao_log.nr)
    print(sv.ao_log.rr[0:4], sv.ao_log.rr[-1:-5:-1])
    print(sv.ao_log.psi_log[0].shape, sv.ao_log.psi_log_rl[0].shape)
    print(dir(sv.pb))
    print(sv.pb.norbs)
    print(sv.pb.npdp)
    print(sv.pb.c2s[-1])
Exemple #25
0
 def test_fireball(self):
   """ Test computation of matrix elements of overlap after fireball """
   sv = mf(fireball="fireball.out", gen_pb=False)
   s_ref = sv.hsx.s4_csr.toarray()
   s = sv.overlap_coo().toarray()
   print(abs(s-s_ref).sum())
Exemple #26
0
    ax.grid(True, which='both')
    ax.axhline(y=0, color='k')
    ax.axvline(x=0, color='k')
    plt.ylim(-3.0,3.0)
    plt.show()

#
# Example of reading pySCF mean-field calculation.
#
if __name__=="__main__":
  from pyscf import gto, scf as scf_gto
  from pyscf.nao import nao, mf
  """ Interpreting small Gaussian calculation """
  mol = gto.M(atom='O 0 0 0; H 0 0 1; H 0 1 0; Be 1 0 0', basis='ccpvdz') # coordinates in Angstrom!
  dft = scf_gto.RKS(mol)
  dft.kernel()
  
  sv = mf(mf=dft, gto=dft.mol, rcut_tol=1e-9, nr=512, rmin=1e-6)
  
  print(sv.ao_log.sp2norbs)
  print(sv.ao_log.sp2nmult)
  print(sv.ao_log.sp2rcut)
  print(sv.ao_log.sp_mu2rcut)
  print(sv.ao_log.nr)
  print(sv.ao_log.rr[0:4], sv.ao_log.rr[-1:-5:-1])
  print(sv.ao_log.psi_log[0].shape, sv.ao_log.psi_log_rl[0].shape)
  print(dir(sv.pb))
  print(sv.pb.norbs)
  print(sv.pb.npdp)
  print(sv.pb.c2s[-1])
Exemple #27
0
from __future__ import print_function, division
import os, unittest, numpy as np
from pyscf.nao import mf

dname = os.path.dirname(os.path.abspath(__file__))
dft = mf(label='water', cd=dname)


class KnowValues(unittest.TestCase):
    def test_dos(self):
        """ This is DoS with the KS eigenvalues """
        omegas = np.linspace(-1.0, 1.0, 500) + 1j * 0.01
        dos = dft.dos(omegas)
        data = np.array([27.2114 * omegas.real, dos])
        np.savetxt('water.dos.txt', data.T, fmt=['%f', '%f'])
        data_ref = np.loadtxt(dname + '/water.dos.txt-ref')
        self.assertTrue(np.allclose(data_ref, data.T, rtol=1.0, atol=1e-05))

    def test_pdos(self):
        """ This is PDoS with SIESTA starting point """
        omegas = np.linspace(-1.0, 1.0, 500) + 1j * 0.01
        pdos = dft.pdos(omegas)
        data = np.array([27.2114 * omegas.real, pdos[0], pdos[1], pdos[2]])
        np.savetxt('water.pdos.txt', data.T)
        data_ref = np.loadtxt(dname + '/water.pdos.txt-ref')
        self.assertTrue(np.allclose(data_ref, data.T, rtol=1.0, atol=1e-05))


if __name__ == "__main__":
    unittest.main()
# 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
from os.path import abspath, dirname
from pyscf.nao import mf
import unittest, numpy as np

sv = mf(label='water', cd=dirname(abspath(__file__)))
pb = sv.pb
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. """