def pyq2_rohf(atomtuples=[(2, 0, 0, 0)], basis='6-31G**', maxit=10, xcname='svwn', mult=3): import pyquante2 as pyq2 print("pyq2 ROHF run") geo = pyq2.molecule(atomtuples, multiplicity=mult) bfs = pyq2.basisset(geo, name=basis) i1 = pyq2.onee_integrals(bfs, geo) i2 = pyq2.twoe_integrals(bfs) h = i1.T + i1.V orbe, orbs = pyq2.geigh(h, i1.S) eold = 0 E0 = geo.nuclear_repulsion() nalpha, nbeta = geo.nup(), geo.ndown() norbs = len(bfs) for i in range(maxit): Da = pyq2.dmat(orbs, nalpha) Db = pyq2.dmat(orbs, nbeta) E1 = 0.5 * pyq2.trace2(Da + Db, h) Ja, Ka = i2.get_j(Da), i2.get_k(Da) Jb, Kb = i2.get_j(Db), i2.get_k(Db) Fa = h + Ja + Jb - Ka Fb = h + Ja + Jb - Kb E2 = 0.5 * (pyq2.trace2(Fa, Da) + pyq2.trace2(Fb, Db)) energy = E0 + E1 + E2 print(energy, E1, E2, E0) Fa = pyq2.utils.simx(Fa, orbs) Fb = pyq2.utils.simx(Fb, orbs) F = 0.5 * (Fa + Fb) K = Fb - Fa # Make explicit slice objects to simplify this do = slice(0, nbeta) so = slice(nbeta, nalpha) uo = slice(nalpha, norbs) F[do, do] -= K[do, do] F[uo, uo] += K[uo, uo] F[do, so] += 0.5 * K[do, so] F[so, do] += 0.5 * K[so, do] F[so, uo] -= 0.5 * K[so, uo] F[uo, so] -= 0.5 * K[uo, so] E, cmo = np.linalg.eigh(F) orbs = np.dot(orbs, cmo) return
def pyq2_dft(atomtuples=[(2,0,0,0)],basis = '6-31G**',maxit=10,xcname='svwn'): import pyquante2 as pyq2 print ("pyq2 DFT run") geo = pyq2.molecule(atomtuples) bfs = pyq2.basisset(geo,name=basis) i1 = pyq2.onee_integrals(bfs,geo) i2 = pyq2.twoe_integrals(bfs) grid = pyq2.grid(geo) h = i1.T + i1.V orbe,orbs = pyq2.geigh(h,i1.S) eold = 0 grid.setbfamps(bfs) E0 = geo.nuclear_repulsion() for i in range(maxit): D = pyq2.dmat(orbs,geo.nocc()) E1 = 2*pyq2.trace2(h,D) J = i2.get_j(D) Ej = 2*pyq2.trace2(J,D) Exc,Vxc = pyq2.get_xc(grid,0.5*D,xcname=xcname) energy = E0+E1+Ej+Exc F = h+2*J+Vxc orbe,orbs = pyq2.geigh(F,i1.S) print (i,energy,E1,Ej,Exc,E0) if np.isclose(energy,eold): break eold = energy return energy
def pyq2_rohf(atomtuples=[(2,0,0,0)],basis = '6-31G**',maxit=10,xcname='svwn', mult=3): import pyquante2 as pyq2 print ("pyq2 ROHF run") geo = pyq2.molecule(atomtuples,multiplicity=mult) bfs = pyq2.basisset(geo,name=basis) i1 = pyq2.onee_integrals(bfs,geo) i2 = pyq2.twoe_integrals(bfs) h = i1.T + i1.V orbe,orbs = pyq2.geigh(h,i1.S) eold = 0 E0 = geo.nuclear_repulsion() nalpha,nbeta = geo.nup(),geo.ndown() norbs = len(bfs) for i in range(maxit): Da = pyq2.dmat(orbs,nalpha) Db = pyq2.dmat(orbs,nbeta) E1 = 0.5*pyq2.trace2(Da+Db,h) Ja,Ka = i2.get_j(Da),i2.get_k(Da) Jb,Kb = i2.get_j(Db),i2.get_k(Db) Fa = h + Ja + Jb - Ka Fb = h + Ja + Jb - Kb E2 = 0.5*(pyq2.trace2(Fa,Da)+pyq2.trace2(Fb,Db)) energy = E0+E1+E2 print (energy,E1,E2,E0) Fa = pyq2.utils.simx(Fa,orbs) Fb = pyq2.utils.simx(Fb,orbs) F = 0.5*(Fa+Fb) K = Fb-Fa # Make explicit slice objects to simplify this do = slice(0,nbeta) so = slice(nbeta,nalpha) uo = slice(nalpha,norbs) F[do,do] -= K[do,do] F[uo,uo] += K[uo,uo] F[do,so] += 0.5*K[do,so] F[so,do] += 0.5*K[so,do] F[so,uo] -= 0.5*K[so,uo] F[uo,so] -= 0.5*K[uo,so] E,cmo = np.linalg.eigh(F) orbs = np.dot(orbs,cmo) return
def pyq2_dft(atomtuples=[(2, 0, 0, 0)], basis='6-31G**', maxit=10, xcname='svwn'): import pyquante2 as pyq2 print("pyq2 DFT run") geo = pyq2.molecule(atomtuples) bfs = pyq2.basisset(geo, name=basis) i1 = pyq2.onee_integrals(bfs, geo) i2 = pyq2.twoe_integrals(bfs) grid = pyq2.grid(geo) h = i1.T + i1.V orbe, orbs = pyq2.geigh(h, i1.S) eold = 0 grid.setbfamps(bfs) E0 = geo.nuclear_repulsion() for i in range(maxit): D = pyq2.dmat(orbs, geo.nocc()) E1 = 2 * pyq2.trace2(h, D) J = i2.get_j(D) Ej = 2 * pyq2.trace2(J, D) Exc, Vxc = pyq2.get_xc(grid, 0.5 * D, xcname=xcname) energy = E0 + E1 + Ej + Exc F = h + 2 * J + Vxc orbe, orbs = pyq2.geigh(F, i1.S) print(i, energy, E1, Ej, Exc, E0) if np.isclose(energy, eold): break eold = energy return energy