def test_0069_vnucele_coulomb_water_ae(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 = scf.RHF(mol)
        gto_mf.kernel()
        vne = mol.intor_symmetric('int1e_nuc')
        dm_gto = gto_mf.make_rdm1()
        E_ne_gto = (vne * dm_gto).sum() * 0.5
        self.assertAlmostEqual(E_ne_gto, -97.67612964579993)

        tk = mol.intor_symmetric('int1e_kin')
        E_kin_gto = (tk * dm_gto).sum()
        self.assertAlmostEqual(E_kin_gto, 75.37551418889902)
        #print(__name__, E_ne_gto)

        mf = mf_c(gto=mol, mf=gto_mf)
        vne_nao = mf.vnucele_coo_coulomb().toarray()
        dm_nao = mf.make_rdm1().reshape((mf.norbs, mf.norbs))
        E_ne_nao = (vne_nao * dm_nao).sum() * 0.5
        #print(__name__, E_ne_nao)
        self.assertAlmostEqual(E_ne_nao, -97.67612893873279)

        tk_nao = -0.5 * mf.laplace_coo().toarray()
        E_kin_nao = (tk_nao * dm_nao).sum()
        #print(__name__, E_ne_nao)
        self.assertAlmostEqual(E_kin_nao, 75.37551418889902)
Beispiel #2
0
 def test_vneutral_atom_matrix_elements(self):
   """ reSCF then G0W0 """
   
   dname = os.path.dirname(os.path.abspath(__file__))
   mf = mf_c(label='lih', cd=dname)
   vna = mf.vna_coo(level=1).toarray()
   rdm = mf.make_rdm1()[0,0,:,:,0]
   Ena = 27.2114*(-0.5)*(vna*rdm).sum()
   #print('Ena   = ', Ena)
   self.assertAlmostEqual(Ena, 6.0251859727456596) # this does compares badly with lih.out 
Beispiel #3
0
 def test_vneutral_atom_matrix_elements(self):
   """ reSCF then G0W0 """
   
   dname = os.path.dirname(os.path.abspath(__file__))
   mf = mf_c(label='n2', cd=dname)
   vna = mf.vna_coo(level=1).toarray()
   rdm = mf.make_rdm1()[0,0,:,:,0]
   Ena = 27.2114*(-0.5)*(vna*rdm).sum()
   #print('Ena   = ', Ena)
   self.assertAlmostEqual(Ena, 133.24203392039948)
    def test_vneutral_atom_matrix_elements(self):
        """ reSCF then G0W0 """

        dname = os.path.dirname(os.path.abspath(__file__))
        mf = mf_c(label='lih', cd=dname)
        vna = mf.vna_coo(level=1).toarray()
        rdm = mf.make_rdm1()[0, 0, :, :, 0]
        Ena = 27.2114 * (-0.5) * (vna * rdm).sum()
        #print('Ena   = ', Ena)
        self.assertAlmostEqual(
            Ena, 6.0251859727456596)  # this does compares badly with lih.out
Beispiel #5
0
    def test_0073_vna_vnl_N2(self):
        """ Test the Ena energy and indirectly VNA matrix elements """

        dname = os.path.dirname(os.path.abspath(__file__))
        mf = mf_c(label='n2', cd=dname)
        vna = mf.vna_coo(level=3).toarray()
        rdm = mf.make_rdm1()[0, 0, :, :, 0]
        Ena = HARTREE2EV * (-0.5) * (vna * rdm).sum()
        self.assertAlmostEqual(Ena, 133.24212864149359)
        # siesta: Ena     =       133.196299

        vnl = mf.vnl_coo().toarray()
        Enl = HARTREE2EV * (vnl * rdm).sum()
        self.assertAlmostEqual(Enl, -61.604522776730128)
 def test_double_sparse(self):
   """ This is a test of a double-sparse storage of the vertex """
   dname = os.path.dirname(os.path.abspath(__file__))
   mf = mf_c(label='water', cd=dname)
   pb = mf.pb
   v_dab_array = pb.get_dp_vertex_array()
   nnn = v_dab_array.size
   vds = pb.get_dp_vertex_doubly_sparse(axis=0)
   self.assertEqual(vds.shape, v_dab_array.shape)
   self.assertTrue(abs(vds.toarray()-v_dab_array).sum()/nnn<1e-14)
   vds = pb.get_dp_vertex_doubly_sparse(axis=1)
   self.assertTrue(abs(vds.toarray()-v_dab_array).sum()/nnn<1e-14)
   vds = pb.get_dp_vertex_doubly_sparse(axis=2)
   self.assertTrue(abs(vds.toarray()-v_dab_array).sum()/nnn<1e-14)
Beispiel #7
0
 def test_double_sparse(self):
     """ This is a test of a double-sparse storage of the vertex """
     dname = os.path.dirname(os.path.abspath(__file__))
     mf = mf_c(label='water', cd=dname)
     pb = mf.pb
     v_dab_array = pb.get_dp_vertex_array()
     nnn = v_dab_array.size
     vds = pb.get_dp_vertex_doubly_sparse(axis=0)
     self.assertEqual(vds.shape, v_dab_array.shape)
     self.assertTrue(abs(vds.toarray() - v_dab_array).sum() / nnn < 1e-14)
     vds = pb.get_dp_vertex_doubly_sparse(axis=1)
     self.assertTrue(abs(vds.toarray() - v_dab_array).sum() / nnn < 1e-14)
     vds = pb.get_dp_vertex_doubly_sparse(axis=2)
     self.assertTrue(abs(vds.toarray() - v_dab_array).sum() / nnn < 1e-14)
Beispiel #8
0
    def test_0074_vna_vnl_LiH(self):
        """ reSCF then G0W0 """

        dname = os.path.dirname(os.path.abspath(__file__))
        mf = mf_c(label='lih', cd=dname)
        vna = mf.vna_coo(level=1).toarray()
        rdm = mf.make_rdm1()[0, 0, :, :, 0]
        Ena = HARTREE2EV * (-0.5) * (vna * rdm).sum()
        self.assertAlmostEqual(
            Ena, 6.0251828965429937)  # This compares badly with lih.out
        # siesta: Ena     =         9.253767

        vnl = mf.vnl_coo().toarray()
        Enl = HARTREE2EV * (vnl * rdm).sum()
        self.assertAlmostEqual(
            Enl, -2.8533506650656162)  # This compares ok with lih.out
 def test_0078_vhartree_pbc_water(self):
     """ Test Hartree potential on equidistant grid with Periodic Boundary Conditions """
     import os
     dname = os.path.dirname(os.path.abspath(__file__))
     mf = mf_c(label='water', cd=dname, gen_pb=False, Ecut=100.0)
     d = abs(np.dot(mf.ucell_mom(), mf.ucell) -
             (2 * np.pi) * np.eye(3)).sum()
     self.assertTrue(d < 1e-15)
     g = mf.mesh3d.get_3dgrid()
     dens = mf.dens_elec(g.coords, mf.make_rdm1()).reshape(mf.mesh3d.shape)
     ts = timer()
     vh = mf.vhartree_pbc(dens)
     tf = timer()
     #print(__name__, tf-ts)
     E_Hartree = 0.5 * (vh * dens * g.weights).sum() * HARTREE2EV
     self.assertAlmostEqual(E_Hartree, 382.8718239023864)
Beispiel #10
0
 def test_matelem_speed(self):
   """ Test the computation of atomic orbitals in coordinate space """
   
   dname = os.path.dirname(os.path.abspath(__file__))
   mf = mf_c(verbosity=0, label='water', cd=dname, gen_pb=False, force_gamma=True, Ecut=50)
   g = mf.mesh3d.get_3dgrid()
   t0 = timer()
   vna = mf.vna(g.coords)
   t1 = timer()
   ab2v1 = mf.matelem_int3d_coo(g, vna)
   t2 = timer()
   ab2v2 = mf.matelem_int3d_coo_ref(g, vna)
   t3 = timer()
   #print(__name__, 't1 t2: ', t1-t0, t2-t1, t3-t2)
   #print(abs(ab2v1.toarray()-ab2v2.toarray()).sum()/ab2v2.size, (abs(ab2v1.toarray()-ab2v2.toarray()).max()))
       
   self.assertTrue(np.allclose(ab2v1.toarray(), ab2v2.toarray()))
  def test_0079_recomp_hamilt_water(self):
    """ Recomputing all parts of KS Hamiltonian a la SIESTA """
    import os
    dname = os.path.dirname(os.path.abspath(__file__))
    mf = mf_c(label='water', cd=dname, gen_pb=False, Ecut=100.0)
    dm = mf.make_rdm1().reshape((mf.norbs, mf.norbs))

    hamilt1 = mf.get_hamiltonian()[0].toarray()
    Ebs1 = (hamilt1*dm).sum()*HARTREE2EV
    self.assertAlmostEqual(Ebs1, -103.13708410565928)

    vh = mf.vhartree_pbc_coo().toarray()
    Ehartree = (vh*dm).sum()*0.5*HARTREE2EV
    self.assertAlmostEqual(Ehartree, 382.8718239023866)

    tkin = -0.5*mf.laplace_coo().toarray()
    Ekin = (tkin*dm).sum()*HARTREE2EV
    self.assertAlmostEqual(Ekin, 351.7667746178386)

    dvh  = mf.vhartree_pbc_coo(density_factors=[1,1]).toarray()
    Edvh = (dvh*dm).sum()*0.5*HARTREE2EV
    self.assertAlmostEqual(Edvh, -120.65336476645524)
    
    Exc  =  mf.exc()*HARTREE2EV
    self.assertAlmostEqual(Exc, -112.71570171625233)
    vxc_lil = mf.vxc_lil()
    vxc  = vxc_lil[0].toarray()

    vna  = mf.vna_coo().toarray()
    Ena = (vna*dm).sum()*HARTREE2EV
    self.assertAlmostEqual(Ena, -265.011709776208)

    vnl  = mf.vnl_coo().toarray()
    Enl = (vnl*dm).sum()*HARTREE2EV
    self.assertAlmostEqual(Enl, -62.17621375282889)

    for f1 in [1.0]:
      for f2 in [-2.0, -1.0, -0.5, 0.0, 0.5, 1.0, 2.0]:
        for f3 in [1.0]:
          for f4 in [1.0]:
            for f5 in [1.0]:
              hamilt2 = f1*tkin + f2*vna + f3*vnl + f4*dvh + f5*vxc
              Ebs2 = (hamilt2*dm).sum()*HARTREE2EV
              if abs(Ebs2+103.137894)<10.0:
                print(f1,f2,f3,f4,f5, Ebs2, -103.137894, Ebs2+103.137894, abs(hamilt2-hamilt1).sum())
    def test_0166_cn_uhf_spin_contamination(self):
        """ Interacting case """
        spin = 1
        mol = gto.M(verbose=0,
                    atom='C 0 0 -0.6;N 0 0 0.52',
                    basis='cc-pvdz',
                    spin=spin)
        gto_mf = scf.UHF(mol)
        gto_mf.kernel()

        #print( ' gto_mf.spin_square() ', gto_mf.spin_square(), spin*0.5*(spin*0.5+1), spin+1 )

        ss_2sp1 = gto_mf.spin_square()
        self.assertTrue(
            np.allclose(ss_2sp1, (0.9768175623447295, 2.2152359353754889)))

        nao_mf = mf_c(gto=mol, mf=gto_mf, verbosity=0, gen_pb=False)

        ss_2sp1 = nao_mf.spin_square()
        self.assertTrue(
            np.allclose(ss_2sp1, (0.9767930087836918, 2.2152137673675574)))
Beispiel #13
0
    def test_ao_eval_speed(self):
        """ Test the computation of atomic orbitals in coordinate space """

        dname = os.path.dirname(os.path.abspath(__file__))
        mf = mf_c(verbosity=0,
                  label='water',
                  cd=dname,
                  gen_pb=False,
                  force_gamma=True,
                  Ecut=20)
        g = mf.mesh3d.get_3dgrid()
        t0 = timer()
        oc2v1 = mf.comp_aos_den(g.coords)
        t1 = timer()
        oc2v2 = mf.comp_aos_py(g.coords)
        t2 = timer()

        print(__name__, 't1 t2: ', t1 - t0, t2 - t1)

        print(
            abs(oc2v1 - oc2v2).sum() / oc2v2.size, (abs(oc2v1 - oc2v2).max()))

        self.assertTrue(np.allclose(oc2v1, oc2v2, atol=3.5e-5))
    def test_0379_recomp_hamilt_oxygen(self):
        """ Recomputing all parts of KS Hamiltonian a la SIESTA """
        import os
        dname = os.path.dirname(os.path.abspath(__file__))
        F = -0.27012188215107336
        mf = mf_c(verbosity=1,
                  label='oxygen',
                  cd=dname,
                  gen_pb=False,
                  fermi_energy=F,
                  Ecut=125.0)

        mf.overlap_check()
        mf.diag_check()

        dm = mf.make_rdm1().reshape((mf.norbs, mf.norbs))
        hamilt1 = mf.get_hamiltonian()[0].toarray()
        Ebs1 = (hamilt1 * dm).sum() * HARTREE2EV
        #self.assertAlmostEqual(Ebs1, -73.18443295100552)

        g = mf.mesh3d.get_3dgrid()
        dens = mf.dens_elec(g.coords,
                            dm=mf.make_rdm1()).reshape(mf.mesh3d.shape)
        mf.mesh3d.write('0379_dens_elec.cube',
                        mol=mf,
                        field=dens,
                        comment='density')
        vh3d = mf.vhartree_pbc(dens)
        Ehartree = (vh3d * dens).sum() * 0.5 * HARTREE2EV * g.weights
        #self.assertAlmostEqual(Ehartree, 225.386052971981)

        vh = mf.vhartree_pbc_coo().toarray()
        Ehartree = (vh * dm).sum() * 0.5 * HARTREE2EV
        #self.assertAlmostEqual(Ehartree, 225.386052971981)

        tkin = -0.5 * mf.laplace_coo().toarray()
        Ekin = (tkin * dm).sum() * HARTREE2EV
        #self.assertAlmostEqual(Ekin, 308.28672736957884)

        dens_atom = mf.vna(g.coords,
                           sp2v=mf.ao_log.sp2chlocal,
                           sp2rcut=mf.ao_log.sp2rcut_chlocal).reshape(
                               mf.mesh3d.shape)
        dvh3d = mf.vhartree_pbc(dens + dens_atom)
        mf.mesh3d.write('0379_dvh.cube', mol=mf, field=dvh3d, comment='dVH')

        dvh = mf.vhartree_pbc_coo(density_factors=[1, 1]).toarray()
        Edvh = (dvh * dm).sum() * 0.5 * HARTREE2EV
        #self.assertAlmostEqual(Edvh, -109.5022234053683) # ???

        vhatom = mf.vhartree_pbc_coo(density_factors=[0, 1]).toarray()
        Ena_atom = (vhatom * dm).sum() * 0.5 * HARTREE2EV
        #self.assertAlmostEqual(Ena_atom, -334.88827637734926) # ???

        Exc = mf.exc() * HARTREE2EV
        #self.assertAlmostEqual(Exc, -87.78500822036436)  # Exc     =       -87.785701
        vxc_lil = mf.vxc_lil()
        vxc = vxc_lil[0].toarray()

        vna = mf.vna_coo().toarray()
        Ena = (vna * dm).sum() * HARTREE2EV
        #self.assertAlmostEqual(Ena, -217.77241233140285) # Enascf  =      -217.774110

        vnl = mf.vnl_coo().toarray()
        Enl = (vnl * dm).sum() * HARTREE2EV
        #self.assertAlmostEqual(Enl, -43.272671826080604) # Enl     =       -43.273074

        for f1 in [1.0]:
            for f2 in [-2.0, -1.0, -0.5, 0.0, 0.5, 1.0, 2.0]:
                for f3 in [1.0]:
                    for f4 in [1.0]:
                        for f5 in [1.0]:
                            hamilt2 = f1 * tkin + f2 * vna + f3 * vnl + f4 * dvh + f5 * vxc
                            Ebs2 = (hamilt2 * dm).sum() * HARTREE2EV
                            print(__name__, f2, Ebs2)
                            if abs(Ebs2 + 73.185007) < 10.0:
                                print(f1, f2, f3, f4, f5, Ebs2, -73.185007,
                                      Ebs2 + 73.185007,
                                      abs(hamilt2 - hamilt1).sum())