Esempio n. 1
0
File: mf.py Progetto: chrinide/pyscf
 def __init__(self, **kw):
   """ Constructor a mean field class (store result of a mean-field calc, deliver density matrix etc) """
   #print(__name__, 'before construct')
   nao.__init__(self, **kw)
   self.dtype = kw['dtype'] if 'dtype' in kw else np.float64
   self.pseudo = hasattr(self, 'sp2ion') 
   self.gen_pb = kw['gen_pb'] if 'gen_pb' in kw else True
   
   if 'mf' in kw:
     self.init_mo_from_pyscf(**kw)      
   elif 'label' in kw: # init KS orbitals with SIESTA
     self.init_mo_coeff_label(**kw)
     self.k2xyzw = self.xml_dict["k2xyzw"]
     self.xc_code = 'LDA,PZ' # just a guess...
   elif 'fireball' in kw: # init KS orbitals with Fireball
     self.init_mo_coeff_fireball(**kw)
     self.xc_code = 'GGA,PBE' # just a guess...
   elif 'gpaw' in kw:
     self.init_mo_coeff_label(**kw)
     self.k2xyzw = np.array([[0.0,0.0,0.0,1.0]])
     self.xc_code = 'LDA,PZ' # just a guess, but in case of GPAW there is a field...
   elif 'openmx' in kw:
     self.xc_code = 'GGA,PBE' # just a guess...
     pass
   else:
     raise RuntimeError('unknown constructor')
   if self.verbosity>0: print(__name__, ' pseudo ', self.pseudo)
   self.init_libnao()
   if self.gen_pb:
     self.pb = prod_basis(nao=self, **kw)
     if self.verbosity>0: print(__name__, ' dtype ', self.dtype, ' norbs ', self.norbs)
Esempio n. 2
0
    def __init__(self, **kw):
        """ Constructor a mean field class (store result of a mean-field calc, deliver density matrix etc) """
        #print(__name__, 'before construct')
        nao.__init__(self, **kw)
        self.dtype = kw['dtype'] if 'dtype' in kw else np.float64
        self.pseudo = hasattr(self, 'sp2ion')
        self.gen_pb = kw['gen_pb'] if 'gen_pb' in kw else True

        if 'mf' in kw:
            self.init_mo_from_pyscf(**kw)
        elif 'label' in kw:  # init KS orbitals with SIESTA
            self.init_mo_coeff_label(**kw)
            self.k2xyzw = self.xml_dict["k2xyzw"]
            self.xc_code = 'LDA,PZ'  # just a guess...
        elif 'fireball' in kw:  # init KS orbitals with Fireball
            self.init_mo_coeff_fireball(**kw)
            self.xc_code = 'GGA,PBE'  # just a guess...
        elif 'gpaw' in kw:
            self.init_mo_coeff_label(**kw)
            self.k2xyzw = np.array([[0.0, 0.0, 0.0, 1.0]])
            self.xc_code = 'LDA,PZ'  # just a guess, but in case of GPAW there is a field...
        elif 'openmx' in kw:
            self.xc_code = 'GGA,PBE'  # just a guess...
            pass
        else:
            raise RuntimeError('unknown constructor')
        if self.verbosity > 0: print(__name__, ' pseudo ', self.pseudo)
        self.init_libnao()
        if self.gen_pb:
            self.pb = prod_basis(nao=self, **kw)
            if self.verbosity > 0:
                print(__name__, ' dtype ', self.dtype, ' norbs ', self.norbs)
 def test_ls_contributing(self):
   """ To test the list of contributing centers """
   sv = nao(gto=mol)
   pb = prod_basis()
   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)
Esempio n. 4
0
  def test_gw(self):
    """ This is GW """
    mol = gto.M( verbose = 0, atom = '''Ag 0.0 0.0 -0.3707;  Ag 0.0 0.0 0.3707''', basis = 'cc-pvdz-pp',)
    gto_mf = scf.RHF(mol)#.density_fit()
    gto_mf.kernel()
    print('gto_mf.mo_energy:', gto_mf.mo_energy)
    s = nao(mf=gto_mf, gto=mol, verbosity=0)
    oref = s.overlap_coo().toarray()
    print('s.norbs:', s.norbs, oref.sum())

    pb = prod_basis(nao=s, algorithm='fp')
    pab2v = pb.get_ac_vertex_array()
    mom0,mom1=pb.comp_moments()
    orec = np.einsum('p,pab->ab', mom0, pab2v)
    print( abs(orec-oref).sum()/oref.size, np.amax(abs(orec-oref)) )
Esempio n. 5
0
    def __init__(self, **kw):
        """
    Constructor a mean field class
    store result of a mean-field calc, deliver density matrix etc
    """
        #print(__name__, 'before construct')
        nao.__init__(self, **kw)

        if 'mf' in kw:
            self.init_mo_from_pyscf(**kw)
        elif 'label' in kw:  # init KS orbitals with SIESTA
            self.k2xyzw = self.xml_dict["k2xyzw"]
            self.xc_code = 'LDA,PZ'  # just a guess...
        elif 'wfsx_fname' in kw:  # init KS orbitals with WFSX file from SIESTA output
            self.xc_code = 'LDA,PZ'  # just a guess...
        elif 'fireball' in kw:  # init KS orbitals with Fireball
            self.init_mo_coeff_fireball(**kw)
            self.xc_code = 'GGA,PBE'  # just a guess...
        elif 'gpaw' in kw:
            self.init_mo_coeff_label(**kw)
            self.k2xyzw = np.array([[0.0, 0.0, 0.0, 1.0]])
            self.xc_code = 'LDA,PZ'  # just a guess, but in case of GPAW there is a field...
        elif 'openmx' in kw:
            self.xc_code = 'GGA,PBE'  # just a guess...
            pass
        else:
            print(__name__, kw.keys())
            raise RuntimeError('unknown constructor')

        #_dft_common_init_(self)

        if self.verbosity > 0:
            print(__name__, '\t\t====> self.pseudo: ', self.pseudo)
            print(__name__, '\t\t====> Number of orbitals: ', self.norbs)

        self.init_libnao()

        self.gen_pb = kw['gen_pb'] if 'gen_pb' in kw else True
        if self.gen_pb:
            self.pb = pb = prod_basis(nao=self, **kw)
            self.v_dab = pb.get_dp_vertex_sparse(dtype=self.dtype).tocsr()
            self.cc_da = cc = pb.get_da2cc_sparse(dtype=self.dtype).tocsr()
            self.nprod = self.cc_da.shape[1]
            if self.verbosity > 0:
                print(
                    __name__,
                    '\t\t====> Number of dominant and atom-centered products {}'
                    .format(cc.shape))
  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)
Esempio n. 7
0
    def test_gw(self):
        """ This is GW """
        mol = gto.M(
            verbose=0,
            atom='''Ag 0.0 0.0 -0.3707;  Ag 0.0 0.0 0.3707''',
            basis='cc-pvdz-pp',
        )
        gto_mf = scf.RHF(mol)  #.density_fit()
        gto_mf.kernel()
        print('gto_mf.mo_energy:', gto_mf.mo_energy)
        s = nao(mf=gto_mf, gto=mol, verbosity=0)
        oref = s.overlap_coo().toarray()
        print('s.norbs:', s.norbs, oref.sum())

        pb = prod_basis(nao=s, algorithm='fp')
        pab2v = pb.get_ac_vertex_array()
        mom0, mom1 = pb.comp_moments()
        orec = np.einsum('p,pab->ab', mom0, pab2v)
        print(abs(orec - oref).sum() / oref.size, np.amax(abs(orec - oref)))
Esempio n. 8
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)