def main(): li = Molecule('Li', atomlist = [(3,(0,0,0))], units='Angs', multiplicity=2) en,orbe,orbs = dft(li,ETemp=1e4) return en
def main(): r = 0.7 h2 = Molecule('h2', atomlist=[(1, (0, 0, r / 2.)), (1, (0, 0, -r / 2.))], units='Angs') en, orbe, orbs = dft(h2, ETemp=1e4) return en
def main(**opts): r = opts.get('r', 1.0) lih = Molecule('lih', atomlist=[(3, (0, 0, 0)), (1, (0, 0, r))], units='Angs') en, orbe, orbs = dft(lih, **opts) return en
def main(**opts): r = opts.get('r',0.70) h2 = Molecule('h2', atomlist = [(1,(0,0,r/2.)), (1,(0,0,-r/2.))], units='Angs') en,orbe,orbs = dft(h2,**opts) return en
def main(): r = 0.7 h2 = Molecule('h2', atomlist = [(1,(0,0,r/2.)), (1,(0,0,-r/2.))], units='Angs') en,orbe,orbs = dft(h2,ETemp=1e4) return en
def main(**opts): r = opts.get('r',1.0) lih = Molecule('lih', atomlist = [(3,(0,0,0)), (1,(0,0,r))], units='Angs') en,orbe,orbs = dft(lih,**opts) return en
def test_exx(): logging.basicConfig(filename='test_exx.log', level=logging.INFO, format="%(message)s", filemode='w') logging.info("Testing EXX functions") logging.info(time.asctime()) h2o = Molecule('H2O', atomlist = [(8,(0,0,0)), # the geo corresponds to the (1,(0.959,0,0)),# one that Yang used (1,(-.230,0.930,0))], units = 'Angstrom') h2 = Molecule('H2', atomlist = [(1,(0.,0.,0.7)),(1,(0.,0.,-0.7))], units = 'Bohr') he = Molecule('He',atomlist = [(2,(0,0,0))]) ne = Molecule('Ne',atomlist = [(10,(0,0,0))]) ohm = Molecule('OH-',atomlist = [(8,(0.0,0.0,0.0)), (1,(0.971,0.0,0.0))], units = 'Angstrom', charge = -1) be = Molecule('Be',atomlist = [(4,(0.0,0.0,0.0))], units = 'Angstrom') lih = Molecule('LiH', atomlist = [(1,(0,0,1.5)),(3,(0,0,-1.5))], units = 'Bohr') #for atoms in [h2,he,be,lih,ohm,ne,h2o]: for atoms in [h2,lih]: logging.info("--%s--" % atoms.name) # Caution: the rydberg molecules (He, Ne) will need a # much much larger basis set than the default returned # by getbasis (which is 6-31G**) bfs = getbasis(atoms) S,h,Ints = getints(bfs,atoms) enhf,orbehf,orbshf = rhf(atoms,integrals=(S,h,Ints)) logging.info("HF total energy = %f"% enhf) enlda,orbelda,orbslda = dft(atoms, integrals=(S,h,Ints), bfs = bfs) logging.info("LDA total energy = %f" % enlda) energy,orbe_exx,orbs_exx = exx(atoms,orbslda, integrals=(S,h,Ints), bfs = bfs, verbose=True, opt_method="BFGS") logging.info("EXX total energy = %f" % energy) return
def test_grad(atoms,**opts): basis = opts.get('basis',None) verbose = opts.get('verbose',False) bfs = getbasis(atoms,basis) S,h,Ints = getints(bfs,atoms) nel = atoms.get_nel() enuke = atoms.get_enuke() energy, orbe, orbs = dft(atoms,return_flag=1) nclosed,nopen = atoms.get_closedopen() D = mkdens_spinavg(orbs,nclosed,nopen) # Now set up a minigrid on which to evaluate the density and gradients: npts = opts.get('npts',1) d = opts.get('d',1e-4) # generate any number of random points, and compute # analytical and numeric gradients: print "Computing Grad Rho for Molecule %s" % atoms.name maxerr = -1 for i in range(npts): x,y,z = rand_xyz() rho = get_rho(x,y,z,D,bfs) rho_px = get_rho(x+d,y,z,D,bfs) rho_mx = get_rho(x-d,y,z,D,bfs) rho_py = get_rho(x,y+d,z,D,bfs) rho_my = get_rho(x,y-d,z,D,bfs) rho_pz = get_rho(x,y,z+d,D,bfs) rho_mz = get_rho(x,y,z-d,D,bfs) gx,gy,gz = get_grad_rho(x,y,z,D,bfs) gx_num = (rho_px-rho_mx)/2/d gy_num = (rho_py-rho_my)/2/d gz_num = (rho_pz-rho_mz)/2/d dx,dy,dz = gx-gx_num,gy-gy_num,gz-gz_num error = sqrt(dx*dx+dy*dy+dz*dz) maxerr = max(error,maxerr) print " Point %10.6f %10.6f %10.6f %10.6f" % (x,y,z,error) print " Numerical %10.6f %10.6f %10.6f" % (gx_num,gy_num,gz_num) print " Analytic %10.6f %10.6f %10.6f" % (gx,gy,gz) print "The maximum error in the gradient calculation is ",maxerr return
def dissoc(**opts): rmin = opts.get('rmin', 0.65) rmax = opts.get('rmax', 1.01) step = opts.get('step', 0.05) doplot = opts.get('doplot', False) rs = arange(rmin, rmax, step) E = [] for r in rs: lih = Molecule('lih', atomlist=[(3, (0, 0, 0)), (1, (0, 0, r))], units='Angs') en, orbe, orbs = dft(lih, **opts) print "%.3f %.5f" % (r, en) E.append(en) if doplot: from pylab import plot plot(rs, E, 'bo-') return
def main(**opts): functional = opts.get('functional', 'BLYP') h = Molecule('H', atomlist=[(1, (0, 0, 0))], multiplicity=2) he = Molecule('He', atomlist=[(2, (0, 0, 0))]) li = Molecule('Li', atomlist=[(3, (0, 0, 0))], multiplicity=2) be = Molecule('Be', atomlist=[(4, (0, 0, 0))]) b = Molecule('B', atomlist=[(5, (0, 0, 0))], multiplicity=2) c = Molecule('C', atomlist=[(6, (0, 0, 0))], multiplicity=3) n = Molecule('N', atomlist=[(7, (0, 0, 0))], multiplicity=4) o = Molecule('O', atomlist=[(8, (0, 0, 0))], multiplicity=3) f = Molecule('F', atomlist=[(9, (0, 0, 0))], multiplicity=2) ne = Molecule('Ne', atomlist=[(10, (0, 0, 0))]) #for atoms in [h,he,li,be,b,c,n,o,f,ne]: # Just do singlets now, since higher multiplicities are off # b/c of Average Open Shell issues print "Running Pople atom tests using %s functional" % functional for atoms in [he, be, ne]: en, orbe, orbs = dft(atoms, functional=functional) print atoms.name, en return
def dissoc(**opts): rmin = opts.get('rmin',0.65) rmax = opts.get('rmax',1.01) step = opts.get('step',0.05) doplot = opts.get('doplot',False) rs = arange(rmin,rmax,step) E = [] for r in rs: lih = Molecule('lih', atomlist = [(3,(0,0,0)), (1,(0,0,r))], units='Angs') en,orbe,orbs = dft(lih,**opts) print "%.3f %.5f" % (r,en) E.append(en) if doplot: from pylab import plot plot(rs,E,'bo-') return
def main(): he = Molecule('He',atomlist=[(2,(0,0,0))]) be = Molecule('Be',atomlist=[(4,(0,0,0))]) ne = Molecule('Ne',atomlist=[(10,(0,0,0))]) h2 = Molecule('H2',atomlist = [(1,(0,0,0.70)), (1,(0,0,-0.70))]) #mols = [he,h2,be] mols = [he,h2,be,ne] #mols = [ne] for mol in mols: #for functional in ['SVWN','BLYP','PBE']: #for functional in ['S0','PBE']: for functional in ['PBE']: en,orbe,orbs = dft(mol,functional = functional) if (mol.name,functional) in results: worked = is_close(en,results[mol.name,functional]) else: worked = None print mol.name,functional,en,worked return
def main(): he = Molecule('He',atomlist=[(2,(0,0,0))]) ne = Molecule('Ne',atomlist=[(10,(0,0,0))]) he3 = Molecule('He3',atomlist=[(2,(0,0,0))],multiplicity=3) # S0 functional en,orbe,orbs = dft(he,functional='S0',basis=basis_data) print "He S0 sb %10.5f is %10.5f" % (-2.7229973821,en) en,orbe,orbs = dft(ne,functional='S0',basis=basis_data) print "Ne S0 sb %10.5f is %10.5f" % (-127.4597878033,en) en,orbe,orbs = dft(he3,functional='S0',basis=basis_data) print "He3 S0 sb %10.5f is %10.5f" % (-1.7819689849,en) # SVWN functional en,orbe,orbs = dft(he,functional='SVWN',basis=basis_data) print "He SVWN sb %10.5f is %10.5f" % (-2.834247,en) en,orbe,orbs = dft(ne,functional='SVWN',basis=basis_data) print "Ne SVWN sb %10.5f is %10.5f" % (-127.203239,en) en,orbe,orbs = dft(he3,functional='SVWN',basis=basis_data) print "He3 SVWN sb %10.5f is %10.5f" % (-1.833287,en) # XPBE functional return
def main(): he = Molecule('He', atomlist=[(2, (0, 0, 0))]) ne = Molecule('Ne', atomlist=[(10, (0, 0, 0))]) he3 = Molecule('He3', atomlist=[(2, (0, 0, 0))], multiplicity=3) # S0 functional en, orbe, orbs = dft(he, functional='S0', basis=basis_data) print "He S0 sb %10.5f is %10.5f" % (-2.7229973821, en) en, orbe, orbs = dft(ne, functional='S0', basis=basis_data) print "Ne S0 sb %10.5f is %10.5f" % (-127.4597878033, en) en, orbe, orbs = dft(he3, functional='S0', basis=basis_data) print "He3 S0 sb %10.5f is %10.5f" % (-1.7819689849, en) # SVWN functional en, orbe, orbs = dft(he, functional='SVWN', basis=basis_data) print "He SVWN sb %10.5f is %10.5f" % (-2.834247, en) en, orbe, orbs = dft(ne, functional='SVWN', basis=basis_data) print "Ne SVWN sb %10.5f is %10.5f" % (-127.203239, en) en, orbe, orbs = dft(he3, functional='SVWN', basis=basis_data) print "He3 SVWN sb %10.5f is %10.5f" % (-1.833287, en) # XPBE functional return
#!/usr/bin/env python from PyQuante import Molecule from PyQuante.dft import dft coord = [(1, (0.0998334, 0.995004, -0.6)), (1, (0.911616, 0.411044, 1.6)), (1, (0.811782, -0.58396, -0.6)), (1, (-0.0998334, -0.995004, 1.6)), (1, (-0.911616, -0.411044, -0.6)), (1, (-0.811782, 0.583961, 1.6)), (6, (0, 0, 0)), (6, (0, 0, 1))] ethane = Molecule('ethane', coord, units="Angstrom") en, orbe, orbs = dft(ethane, functional="LDA", basis="sto-3g")
def main(): atomlist = Molecule('Li',atomlist = [(3,(0,0,0))],multiplicity=2) en,orbe,orbs = dft(atomlist,verbose=True) return en
def H2O_Molecule(tst, info, auX, auZ): H2O = Molecule('H2O', [('O', (0.0, 0.0, 0.0)), ('H', (auX, 0.0, auZ)), ('H', (-auX, 0.0, auZ))], units='Bohr') # Get a better energy estimate if dft: print "# info=%s A.U.=(%g,%g) " % (info, auX, auZ) edft, orbe2, orbs2 = dft(H2O, functional='SVWN') bfs = getbasis(H2O, basis_data=basis_data) #S is overlap of 2 basis funcs #h is (kinetic+nucl) 1 body term #ints is 2 body terms S, h, ints = getints(bfs, H2O) #enhf is the Hartee-Fock energy #orbe is the orbital energies #orbs is the orbital overlaps enhf, orbe, orbs = rhf(H2O, integrals=(S, h, ints)) enuke = Molecule.get_enuke(H2O) # print "orbe=%d" % len(orbe) temp = matrixmultiply(h, orbs) hmol = matrixmultiply(transpose(orbs), temp) MOInts = TransformInts(ints, orbs) if single: print "h = \n", h print "S = \n", S print "ints = \n", ints print "orbe = \n", orbe print "orbs = \n", orbs print "" print "Index 0: 1 or 2 in the paper, Index 1: 3 or 4 in the paper (for pqrs)" print "" print "hmol = \n", hmol print "MOInts:" print "I,J,K,L = PQRS order: Cre1,Cre2,Ann1,Ann2" if 1: print "tst=%d info=%s nuc=%.9f Ehf=%.9f" % (tst, info, enuke, enhf), cntOrbs = 0 maxOrb = 0 npts = len(hmol[:]) for i in xrange(npts): for j in range(i, npts): if abs(hmol[i, j]) > 1.0e-7: print "%d,%d=%.9f" % (i, j, hmol[i, j]), cntOrbs += 1 if i > maxOrb: maxOrb = i if j > maxOrb: maxOrb = j nbf, nmo = orbs.shape mos = range(nmo) for i in mos: for j in xrange(i + 1): ij = i * (i + 1) / 2 + j for k in mos: for l in xrange(k + 1): kl = k * (k + 1) / 2 + l if ij >= kl: ijkl = ijkl2intindex(i, j, k, l) if abs(MOInts[ijkl]) > 1.0e-7: print "%d,%d,%d,%d=%.9f" % (l, i, j, k, MOInts[ijkl]), cntOrbs += 1 if i > maxOrb: maxOrb = i if j > maxOrb: maxOrb = j print "" return (maxOrb, cntOrbs)
gradient_diatomic(sol, smoothing=0.005) # In[33]: from PyQuante.Molecule import Molecule from PyQuante.dft import dft h2 = Molecule('h2',[(1,(0,0,0)),(1,(1.4,0,0))]) # In[35]: en,orbe,orbs = dft(h2,functional='LDA') # In[ ]: # In[8]: gradient_diatomic(sol, smoothing=0.2) # In[14]:
#!/usr/bin/env python from PyQuante import Molecule from PyQuante.dft import dft lih = Molecule('LiH', [(1, (0, 0, -1.210905)), (3, (0, 0, 0.403635))], units="Bohr") en, orbe, orbs = dft(lih, functional="LDA", basis="sto-3g")
def main(): atomlist = Molecule("H", atomlist=[(1, (0, 0, 0))], multiplicity=2) en, orbe, orbs = dft(atomlist) return en
def main(): atomlist = Molecule('H', atomlist=[(1, (0, 0, 0))], multiplicity=2) en, orbe, orbs = dft(atomlist) return en
""" Calculates the Boron atom using DFT. """ from PyQuante import SCF, Molecule, dft, Atom B = Molecule('Boron',[(5, (0,0,0))]) B.multiplicity = 2 E, eigs, orbitals = dft.dft(B) print "total energy:", E print "KS energies:", eigs
def H2O_Molecule(tst,info,auX,auZ): H2O = Molecule('H2O', [('O', ( 0.0, 0.0, 0.0)), ('H', ( auX, 0.0, auZ)), ('H', (-auX, 0.0, auZ))], units='Bohr') # Get a better energy estimate if dft: print "# info=%s A.U.=(%g,%g) " % (info,auX,auZ) edft,orbe2,orbs2 = dft(H2O,functional='SVWN') bfs= getbasis(H2O,basis_data=basis_data) #S is overlap of 2 basis funcs #h is (kinetic+nucl) 1 body term #ints is 2 body terms S,h,ints=getints(bfs,H2O) #enhf is the Hartee-Fock energy #orbe is the orbital energies #orbs is the orbital overlaps enhf,orbe,orbs=rhf(H2O,integrals=(S,h,ints)) enuke = Molecule.get_enuke(H2O) # print "orbe=%d" % len(orbe) temp = matrixmultiply(h,orbs) hmol = matrixmultiply(transpose(orbs),temp) MOInts = TransformInts(ints,orbs) if single: print "h = \n",h print "S = \n",S print "ints = \n",ints print "orbe = \n",orbe print "orbs = \n",orbs print "" print "Index 0: 1 or 2 in the paper, Index 1: 3 or 4 in the paper (for pqrs)" print "" print "hmol = \n",hmol print "MOInts:" print "I,J,K,L = PQRS order: Cre1,Cre2,Ann1,Ann2" if 1: print "tst=%d info=%s nuc=%.9f Ehf=%.9f" % (tst,info,enuke,enhf), cntOrbs = 0 maxOrb = 0 npts = len(hmol[:]) for i in xrange(npts): for j in range(i,npts): if abs(hmol[i,j]) > 1.0e-7: print "%d,%d=%.9f" % (i,j,hmol[i,j]), cntOrbs += 1 if i > maxOrb: maxOrb = i if j > maxOrb: maxOrb = j nbf,nmo = orbs.shape mos = range(nmo) for i in mos: for j in xrange(i+1): ij = i*(i+1)/2+j for k in mos: for l in xrange(k+1): kl = k*(k+1)/2+l if ij >= kl: ijkl = ijkl2intindex(i,j,k,l) if abs(MOInts[ijkl]) > 1.0e-7: print "%d,%d,%d,%d=%.9f" % (l,i,j,k,MOInts[ijkl]), cntOrbs += 1 if i > maxOrb: maxOrb = i if j > maxOrb: maxOrb = j print "" return (maxOrb,cntOrbs)
__author__ = 'yutongpang' from PyQuante.Molecule import Molecule h2 = Molecule('H2', [(1, (0.00000000, 0.00000000, 0.36628549)), (1, (0.00000000, 0.00000000, -0.36628549))], units='Angstrom') from PyQuante.dft import dft en,orbe,orbs = dft(h2) print "HF Energy = ",orbs