def test_ewald(): cell = pbcgto.Cell() cell.unit = 'B' Lx = 6. Ly = 9. Lz = 30. cell.a = np.array([[Lx,0.5,0.5], [0.5,Ly,0.5], [0.5,0.5,Lz]]) cell.gs = np.array([20,20,20]) cell.atom.extend([['He', (1, 0.5*Ly, 0.5*Lz)], ['He', (2, 0.5*Ly, 0.5*Lz)]]) # these are some exponents which are not hard to integrate cell.basis = {'He': [[0, (1.0, 1.0)]]} cell.verbose = 5 cell.build() ew_eta0, ew_cut0 = cell.get_ewald_params(1.e-3) print ew_eta0, ew_cut0 ew_cut = (20,20,20) for ew_eta in [0.05, 0.07, 0.1, 0.3]: print pbchf.ewald(cell, ew_eta, ew_cut) # 4.53091146255 for precision in [1.e-3, 1.e-5, 1.e-7, 1.e-9]: ew_eta0, ew_cut0 = cell.get_ewald_params(precision) print "precision", precision, ew_eta0, ew_cut0 print pbchf.ewald(cell, ew_eta0, ew_cut0)
def test_ewald(): cell = pbcgto.Cell() cell.unit = "B" Lx = Ly = Lz = 5.0 cell.a = np.diag([Lx, Ly, Lz]) cell.gs = np.array([20, 20, 20]) cell.atom.extend([["He", (2, 0.5 * Ly, 0.5 * Lz)], ["He", (3, 0.5 * Ly, 0.5 * Lz)]]) # these are some exponents which are not hard to integrate cell.basis = {"He": [[0, (1.0, 1.0)]]} cell.verbose = 5 cell.build() ew_eta0, ew_cut0 = cell.get_ewald_params(1.0e-3) print ew_eta0, ew_cut0 ew_cut = (20, 20, 20) for ew_eta in [0.05, 0.1, 0.2, 1]: print pbchf.ewald(cell, ew_eta, ew_cut) # -0.468640671931 for precision in [1.0e-3, 1.0e-5, 1.0e-7, 1.0e-9]: ew_eta0, ew_cut0 = cell.get_ewald_params(precision) print "precision", precision, ew_eta0, ew_cut0 print pbchf.ewald(cell, ew_eta0, ew_cut0)
def test_ewald(): cell = pbcgto.Cell() cell.unit = 'B' Lx = 6. Ly = 9. Lz = 30. cell.h = np.array([[Lx,0.5,0.5], [0.5,Ly,0.5], [0.5,0.5,Lz]]) cell.gs = np.array([20,20,20]) cell.nimgs = [1,1,1] cell.atom.extend([['He', (1, 0.5*Ly, 0.5*Lz)], ['He', (2, 0.5*Ly, 0.5*Lz)]]) # these are some exponents which are not hard to integrate cell.basis = {'He': [[0, (1.0, 1.0)]]} cell.verbose = 5 cell.build() ew_eta0, ew_cut0 = cell.get_ewald_params(1.e-3) print ew_eta0, ew_cut0 ew_cut = (20,20,20) for ew_eta in [0.05, 0.07, 0.1, 0.3]: print pbchf.ewald(cell, ew_eta, ew_cut) # 4.53091146255 for precision in [1.e-3, 1.e-5, 1.e-7, 1.e-9]: ew_eta0, ew_cut0 = cell.get_ewald_params(precision) print "precision", precision, ew_eta0, ew_cut0 print pbchf.ewald(cell, ew_eta0, ew_cut0)
def test_ewald(): cell = pbcgto.Cell() cell.unit = 'B' Lx = Ly = Lz = 5. cell.a = np.diag([Lx, Ly, Lz]) cell.gs = np.array([20, 20, 20]) cell.atom.extend([['He', (2, 0.5 * Ly, 0.5 * Lz)], ['He', (3, 0.5 * Ly, 0.5 * Lz)]]) # these are some exponents which are not hard to integrate cell.basis = {'He': [[0, (1.0, 1.0)]]} cell.verbose = 5 cell.build() ew_eta0, ew_cut0 = cell.get_ewald_params(1.e-3) print ew_eta0, ew_cut0 ew_cut = 20 for ew_eta in [0.05, 0.1, 0.2, 1]: print pbchf.ewald(cell, ew_eta, ew_cut) # -0.468640671931 for precision in [1.e-3, 1.e-5, 1.e-7, 1.e-9]: ew_eta0, ew_cut0 = cell.get_ewald_params(precision) print "precision", precision, ew_eta0, ew_cut0 print pbchf.ewald(cell, ew_eta0, ew_cut0)
def test_ewald(self): cell = pbcgto.Cell() cell.unit = "B" Lx = Ly = Lz = 5.0 cell.h = np.diag([Lx, Ly, Lz]) cell.gs = np.array([20, 20, 20]) cell.nimgs = [1, 1, 1] cell.atom.extend([["He", (2, 0.5 * Ly, 0.5 * Lz)], ["He", (3, 0.5 * Ly, 0.5 * Lz)]]) # these are some exponents which are not hard to integrate cell.basis = {"He": [[0, (1.0, 1.0)]]} cell.verbose = 5 cell.output = "/dev/null" cell.build() ew_cut = (20, 20, 20) self.assertAlmostEqual(pbchf.ewald(cell, 0.05, ew_cut), -0.468640671931, 9) self.assertAlmostEqual(pbchf.ewald(cell, 0.1, ew_cut), -0.468640671931, 9) self.assertAlmostEqual(pbchf.ewald(cell, 0.2, ew_cut), -0.468640671931, 9) self.assertAlmostEqual(pbchf.ewald(cell, 1, ew_cut), -0.468640671931, 9) def check(precision, eta_ref, ewald_ref): ew_eta0, ew_cut0 = cell.get_ewald_params(precision) self.assertAlmostEqual(ew_eta0, eta_ref) self.assertAlmostEqual(pbchf.ewald(cell, ew_eta0, ew_cut0), ewald_ref, 9) check(0.001, 4.78124933741, -0.469112631739) check(1e-05, 3.70353981157, -0.468642153932) check(1e-07, 3.1300624293, -0.468640678042) check(1e-09, 2.76045559201, -0.468640671959)
def madelung(cell, kpts): from pyscf.pbc import gto as pbcgto from pyscf.pbc.scf.hf import ewald Nk = get_monkhorst_pack_size(cell, kpts) ecell = pbcgto.Cell() ecell.atom = 'H 0. 0. 0.' ecell.spin = 1 ecell.gs = cell.gs ecell.precision = 1e-16 ecell.unit = 'B' ecell.h = cell._h * Nk ecell.build(False, False) return -2 * ewald(ecell, ecell.ew_eta, ecell.ew_cut)
def madelung(cell, kpts): from pyscf.pbc import gto as pbcgto from pyscf.pbc.scf.hf import ewald Nk = get_monkhorst_pack_size(cell, kpts) ecell = pbcgto.Cell() ecell.atom = 'H 0. 0. 0.' ecell.spin = 1 ecell.gs = cell.gs ecell.precision = 1e-16 ecell.unit = 'B' ecell.h = cell._h * Nk ecell.build(False,False) return -2*ewald(ecell, ecell.ew_eta, ecell.ew_cut)
def test_components(pseudo=None): # The molecular calculation mol = gto.Mole() mol.unit = 'B' L = 60 mol.atom.extend([['He', (L/2.,L/2.,L/2.)], ]) mol.basis = 'sto-3g' mol.build() m = rks.RKS(mol) m.xc = 'LDA,VWN_RPA' print(m.scf()) # -2.90705411168 dm = m.make_rdm1() # The periodic calculation cell = pbcgto.Cell() cell.unit = 'B' cell.a = np.diag([L,L,L]) cell.gs = np.array([80,80,80]) cell.atom = mol.atom cell.basis = mol.basis cell.pseudo = pseudo cell.build() # These should match reasonably well (roughly with accuracy of normalization) print "Kinetic energy" tao = pbchf.get_t(cell) tao2 = mol.intor_symmetric('cint1e_kin_sph') print np.dot(np.ravel(tao), np.ravel(dm)) # 2.82793077196 print np.dot(np.ravel(tao2), np.ravel(dm)) # 2.82352636524 print "Overlap" sao = pbchf.get_ovlp(cell) print np.dot(np.ravel(sao), np.ravel(dm)) # 1.99981725342 print np.dot(np.ravel(m.get_ovlp()), np.ravel(dm)) # 2.0 # The next two entries should *not* match, since G=0 component is removed print "Coulomb (G!=0)" jao = pbchf.get_j(cell, dm) print np.dot(np.ravel(dm),np.ravel(jao)) # 4.03425518427 print np.dot(np.ravel(dm),np.ravel(m.get_j(dm))) # 4.22285177049 # The next two entries should *not* match, since G=0 component is removed print "Nuc-el (G!=0)" if cell.pseudo: vppao = pbchf.get_pp(cell) print np.dot(np.ravel(dm), np.ravel(vppao)) else: neao = pbchf.get_nuc(cell) print np.dot(np.ravel(dm), np.ravel(neao)) # -6.50203360062 vne = mol.intor_symmetric('cint1e_nuc_sph') print np.dot(np.ravel(dm), np.ravel(vne)) # -6.68702326551 print "Normalization" coords = gen_uniform_grids(cell) aoR = eval_ao(cell, coords) rhoR = eval_rho(cell, aoR, dm) print cell.vol/len(rhoR)*np.sum(rhoR) # 1.99981725342 (should be 2.0) print "(Hartree + vne) * DM" print np.dot(np.ravel(dm),np.ravel(m.get_j(dm)))+np.dot(np.ravel(dm), np.ravel(vne)) if cell.pseudo: print np.einsum("ij,ij", dm, vppao + jao + pbchf.get_jvloc_G0(cell)) else: print np.einsum("ij,ij", dm, neao + jao) ew_cut = (40,40,40) ew_eta = 0.05 for ew_eta in [0.1, 0.5, 1.]: ew = pbchf.ewald(cell, ew_eta, ew_cut) print "Ewald (eta, energy)", ew_eta, ew # should be same for all eta print "Ewald divergent terms summation", ew # These two should now match if the box is reasonably big to # remove images, and ngs is big. print "Total coulomb (analytic) ", print (.5*np.dot(np.ravel(dm), np.ravel(m.get_j(dm))) + np.dot(np.ravel(dm), np.ravel(vne)) ) # -4.57559738004 if not cell.pseudo: print "Total coulomb (fft coul + ewald)", print np.einsum("ij,ij", dm, neao + .5*jao) + ew # -4.57948259115 # Exc cell.ew_eta, cell.ew_cut = ew_eta, ew_cut mf = pbcdft.RKS(cell) mf.xc = 'LDA,VWN_RPA' rks.get_veff(mf, cell, dm) print "Exc", mf._exc # -1.05967570089
def test_components(pseudo=None): # The molecular calculation mol = gto.Mole() mol.unit = 'B' L = 60 mol.atom.extend([ ['He', (L / 2., L / 2., L / 2.)], ]) mol.basis = 'sto-3g' mol.build() m = rks.RKS(mol) m.xc = 'LDA,VWN_RPA' print(m.scf()) # -2.90705411168 dm = m.make_rdm1() # The periodic calculation cell = pbcgto.Cell() cell.unit = 'B' cell.a = np.diag([L, L, L]) cell.gs = np.array([80, 80, 80]) cell.atom = mol.atom cell.basis = mol.basis cell.pseudo = pseudo cell.build() # These should match reasonably well (roughly with accuracy of normalization) print "Kinetic energy" tao = pbchf.get_t(cell) tao2 = mol.intor_symmetric('cint1e_kin_sph') print np.dot(np.ravel(tao), np.ravel(dm)) # 2.82793077196 print np.dot(np.ravel(tao2), np.ravel(dm)) # 2.82352636524 print "Overlap" sao = pbchf.get_ovlp(cell) print np.dot(np.ravel(sao), np.ravel(dm)) # 1.99981725342 print np.dot(np.ravel(m.get_ovlp()), np.ravel(dm)) # 2.0 # The next two entries should *not* match, since G=0 component is removed print "Coulomb (G!=0)" jao = pbchf.get_j(cell, dm) print np.dot(np.ravel(dm), np.ravel(jao)) # 4.03425518427 print np.dot(np.ravel(dm), np.ravel(m.get_j(dm))) # 4.22285177049 # The next two entries should *not* match, since G=0 component is removed print "Nuc-el (G!=0)" if cell.pseudo: vppao = pbchf.get_pp(cell) print np.dot(np.ravel(dm), np.ravel(vppao)) else: neao = pbchf.get_nuc(cell) print np.dot(np.ravel(dm), np.ravel(neao)) # -6.50203360062 vne = mol.intor_symmetric('cint1e_nuc_sph') print np.dot(np.ravel(dm), np.ravel(vne)) # -6.68702326551 print "Normalization" coords = gen_uniform_grids(cell) aoR = eval_ao(cell, coords) rhoR = eval_rho(cell, aoR, dm) print cell.vol / len(rhoR) * np.sum(rhoR) # 1.99981725342 (should be 2.0) print "(Hartree + vne) * DM" print np.dot(np.ravel(dm), np.ravel(m.get_j(dm))) + np.dot( np.ravel(dm), np.ravel(vne)) if cell.pseudo: print np.einsum("ij,ij", dm, vppao + jao + pbchf.get_jvloc_G0(cell)) else: print np.einsum("ij,ij", dm, neao + jao) ew_cut = (40, 40, 40) ew_eta = 0.05 for ew_eta in [0.1, 0.5, 1.]: ew = pbchf.ewald(cell, ew_eta, ew_cut) print "Ewald (eta, energy)", ew_eta, ew # should be same for all eta print "Ewald divergent terms summation", ew # These two should now match if the box is reasonably big to # remove images, and ngs is big. print "Total coulomb (analytic) ", print(.5 * np.dot(np.ravel(dm), np.ravel(m.get_j(dm))) + np.dot(np.ravel(dm), np.ravel(vne))) # -4.57559738004 if not cell.pseudo: print "Total coulomb (fft coul + ewald)", print np.einsum("ij,ij", dm, neao + .5 * jao) + ew # -4.57948259115 # Exc cell.ew_eta, cell.ew_cut = ew_eta, ew_cut mf = pbcdft.RKS(cell) mf.xc = 'LDA,VWN_RPA' rks.get_veff(mf, cell, dm) print "Exc", mf._exc # -1.05967570089
def check(precision, eta_ref, ewald_ref): ew_eta0, ew_cut0 = cell.get_ewald_params(precision) self.assertAlmostEqual(ew_eta0, eta_ref) self.assertAlmostEqual(pbchf.ewald(cell, ew_eta0, ew_cut0), ewald_ref, 9)