def nuclear_attraction(alpha1, lmn1, A, alpha2, lmn2, B, C): """ Full form of the nuclear attraction integral >>> isnear(nuclear_attraction(1,(0,0,0),array((0,0,0),'d'),1,(0,0,0),array((0,0,0),'d'),array((0,0,0),'d')),-3.141593) True """ l1, m1, n1 = lmn1 l2, m2, n2 = lmn2 gamma = alpha1 + alpha2 P = gaussian_product_center(alpha1, A, alpha2, B) rab2 = norm2(A - B) rcp2 = norm2(C - P) dPA = P - A dPB = P - B dPC = P - C Ax = A_array(l1, l2, dPA[0], dPB[0], dPC[0], gamma) Ay = A_array(m1, m2, dPA[1], dPB[1], dPC[1], gamma) Az = A_array(n1, n2, dPA[2], dPB[2], dPC[2], gamma) total = 0. for I in range(l1 + l2 + 1): for J in range(m1 + m2 + 1): for K in range(n1 + n2 + 1): total += Ax[I] * Ay[J] * Az[K] * Fgamma( I + J + K, rcp2 * gamma) return -2 * pi / gamma * exp(-alpha1 * alpha2 * rab2 / gamma) * total
def coulomb_repulsion(xyza, norma, lmna, alphaa, xyzb, normb, lmnb, alphab, xyzc, normc, lmnc, alphac, xyzd, normd, lmnd, alphad): """ Return the coulomb repulsion between four primitive gaussians a,b,c,d with the given origin , x,y,z, normalization constants norm, angular momena l,m,n, and exponent alpha. >>> p1 = array((0.,0.,0.),'d') >>> p2 = array((0.,0.,1.),'d') >>> lmn = (0,0,0) >>> isclose(coulomb_repulsion(p1,1.,lmn,1.,p1,1.,lmn,1.,p1,1.,lmn,1.,p1,1.,lmn,1.),4.373355) True >>> isclose(coulomb_repulsion(p1,1.,lmn,1.,p1,1.,lmn,1.,p2,1.,lmn,1.,p2,1.,lmn,1.),3.266127) True >>> isclose(coulomb_repulsion(p1,1.,lmn,1.,p2,1.,lmn,1.,p1,1.,lmn,1.,p2,1.,lmn,1.),1.6088672) True """ la, ma, na = lmna lb, mb, nb = lmnb lc, mc, nc = lmnc ld, md, nd = lmnd xa, ya, za = xyza xb, yb, zb = xyzb xc, yc, zc = xyzc xd, yd, zd = xyzd rab2 = norm2(xyza - xyzb) rcd2 = norm2(xyzc - xyzd) xyzp = gaussian_product_center(alphaa, xyza, alphab, xyzb) xp, yp, zp = xyzp xyzq = gaussian_product_center(alphac, xyzc, alphad, xyzd) xq, yq, zq = xyzq rpq2 = norm2(xyzp - xyzq) gamma1 = alphaa + alphab gamma2 = alphac + alphad delta = 0.25 * (1 / gamma1 + 1 / gamma2) Bx = B_array(la, lb, lc, ld, xp, xa, xb, xq, xc, xd, gamma1, gamma2, delta) By = B_array(ma, mb, mc, md, yp, ya, yb, yq, yc, yd, gamma1, gamma2, delta) Bz = B_array(na, nb, nc, nd, zp, za, zb, zq, zc, zd, gamma1, gamma2, delta) sum = 0. for I in range(la + lb + lc + ld + 1): for J in range(ma + mb + mc + md + 1): for K in range(na + nb + nc + nd + 1): sum = sum + Bx[I] * By[J] * Bz[K] * Fgamma( I + J + K, 0.25 * rpq2 / delta) return 2*pow(pi,2.5)/(gamma1*gamma2*sqrt(gamma1+gamma2)) \ *exp(-alphaa*alphab*rab2/gamma1) \ *exp(-alphac*alphad*rcd2/gamma2)*sum*norma*normb*normc*normd
def term0(aexpn, xyza, bexpn, xyzb, cexpn, xyzc, dexpn, xyzd, mtot): zeta, eta = float(aexpn + bexpn), float(cexpn + dexpn) zpe = zeta + eta xyzp = gaussian_product_center(aexpn, xyza, bexpn, xyzb) xyzq = gaussian_product_center(cexpn, xyzc, dexpn, xyzd) rab2 = norm2(xyza - xyzb) Kab = sqrt(2)*pow(pi,1.25)/(aexpn+bexpn)\ *exp(-aexpn*bexpn/(aexpn+bexpn)*rab2) rcd2 = norm2(xyzc - xyzd) Kcd = sqrt(2)*pow(pi,1.25)/(cexpn+dexpn)\ *exp(-cexpn*dexpn/(cexpn+dexpn)*rcd2) rpq2 = norm2(xyzp - xyzq) T = zeta * eta / zpe * rpq2 return [Fgamma(m, T) * Kab * Kcd / sqrt(zpe) for m in xrange(mtot + 1)]
def vrr(xyza, norma, lmna, alphaa, xyzb, normb, alphab, xyzc, normc, lmnc, alphac, xyzd, normd, alphad, M): la, ma, na = lmna lc, mc, nc = lmnc xa, ya, za = xyza xb, yb, zb = xyzb xc, yc, zc = xyzc xd, yd, zd = xyzd px, py, pz = xyzp = gaussian_product_center(alphaa, xyza, alphab, xyzb) qx, qy, qz = xyzq = gaussian_product_center(alphac, xyzc, alphad, xyzd) zeta, eta = float(alphaa + alphab), float(alphac + alphad) wx, wy, wz = xyzw = gaussian_product_center(zeta, xyzp, eta, xyzq) rab2 = pow(xa - xb, 2) + pow(ya - yb, 2) + pow(za - zb, 2) Kab = sqrt(2)*pow(pi,1.25)/(alphaa+alphab)\ *exp(-alphaa*alphab/(alphaa+alphab)*rab2) rcd2 = pow(xc - xd, 2) + pow(yc - yd, 2) + pow(zc - zd, 2) Kcd = sqrt(2)*pow(pi,1.25)/(alphac+alphad)\ *exp(-alphac*alphad/(alphac+alphad)*rcd2) rpq2 = pow(px - qx, 2) + pow(py - qy, 2) + pow(pz - qz, 2) T = zeta * eta / (zeta + eta) * rpq2 mtot = la + ma + na + lc + mc + nc + M Fgterms = [0] * (mtot + 1) Fgterms[mtot] = Fgamma(mtot, T) for im in range(mtot - 1, -1, -1): Fgterms[im] = (2. * T * Fgterms[im + 1] + exp(-T)) / (2. * im + 1) # Todo: setup this as a regular array # Store the vrr values as a 7 dimensional array # vrr_terms[la,ma,na,lc,mc,nc,m] vrr_terms = {} for im in range(mtot + 1): vrr_terms[0, 0, 0, 0, 0, 0, im] = (norma * normb * normc * normd * Kab * Kcd / sqrt(zeta + eta) * Fgterms[im]) # Todo: use itertools.product() for the nested for loops for i in range(la): for im in range(mtot - i): vrr_terms[i + 1, 0, 0, 0, 0, 0, im] = ((px - xa) * vrr_terms[i, 0, 0, 0, 0, 0, im] + (wx - px) * vrr_terms[i, 0, 0, 0, 0, 0, im + 1]) if i: vrr_terms[i + 1, 0, 0, 0, 0, 0, im] += ( i / 2. / zeta * (vrr_terms[i - 1, 0, 0, 0, 0, 0, im] - eta / (zeta + eta) * vrr_terms[i - 1, 0, 0, 0, 0, 0, im + 1])) for j in range(ma): for i in range(la + 1): for im in range(mtot - i - j): vrr_terms[i, j + 1, 0, 0, 0, 0, im] = ( (py - ya) * vrr_terms[i, j, 0, 0, 0, 0, im] + (wy - py) * vrr_terms[i, j, 0, 0, 0, 0, im + 1]) if j: vrr_terms[i, j + 1, 0, 0, 0, 0, im] += (j / 2. / zeta * ( vrr_terms[i, j - 1, 0, 0, 0, 0, im] - eta / (zeta + eta) * vrr_terms[i, j - 1, 0, 0, 0, 0, im + 1]) ) for k in range(na): for j in range(ma + 1): for i in range(la + 1): for im in range(mtot - i - j - k): vrr_terms[i, j, k + 1, 0, 0, 0, im] = ( (pz - za) * vrr_terms[i, j, k, 0, 0, 0, im] + (wz - pz) * vrr_terms[i, j, k, 0, 0, 0, im + 1]) if k: vrr_terms[i, j, k + 1, 0, 0, 0, im] += ( k / 2. / zeta * (vrr_terms[i, j, k - 1, 0, 0, 0, im] - eta / (zeta + eta) * vrr_terms[i, j, k - 1, 0, 0, 0, im + 1])) for q in range(lc): for k in range(na + 1): for j in range(ma + 1): for i in range(la + 1): for im in range(mtot - i - j - k - q): vrr_terms[i, j, k, q + 1, 0, 0, im] = ( (qx - xc) * vrr_terms[i, j, k, q, 0, 0, im] + (wx - qx) * vrr_terms[i, j, k, q, 0, 0, im + 1]) if q: vrr_terms[i, j, k, q + 1, 0, 0, im] += ( q / 2. / eta * (vrr_terms[i, j, k, q - 1, 0, 0, im] - zeta / (zeta + eta) * vrr_terms[i, j, k, q - 1, 0, 0, im + 1])) if i: vrr_terms[i, j, k, q + 1, 0, 0, im] += ( i / 2. / (zeta + eta) * vrr_terms[i - 1, j, k, q, 0, 0, im + 1]) for r in range(mc): for q in range(lc + 1): for k in range(na + 1): for j in range(ma + 1): for i in range(la + 1): for im in range(mtot - i - j - k - q - r): vrr_terms[i, j, k, q, r + 1, 0, im] = ( (qy - yc) * vrr_terms[i, j, k, q, r, 0, im] + (wy - qy) * vrr_terms[i, j, k, q, r, 0, im + 1]) if r: vrr_terms[i, j, k, q, r + 1, 0, im] += ( r / 2. / eta * (vrr_terms[i, j, k, q, r - 1, 0, im] - zeta / (zeta + eta) * vrr_terms[i, j, k, q, r - 1, 0, im + 1])) if j: vrr_terms[i, j, k, q, r + 1, 0, im] += ( j / 2. / (zeta + eta) * vrr_terms[i, j - 1, k, q, r, 0, im + 1]) for s in range(nc): for r in range(mc + 1): for q in range(lc + 1): for k in range(na + 1): for j in range(ma + 1): for i in range(la + 1): for im in range(mtot - i - j - k - q - r - s): vrr_terms[i, j, k, q, r, s + 1, im] = ( (qz - zc) * vrr_terms[i, j, k, q, r, s, im] + (wz - qz) * vrr_terms[i, j, k, q, r, s, im + 1]) if s: vrr_terms[i, j, k, q, r, s + 1, im] += ( s / 2. / eta * (vrr_terms[i, j, k, q, r, s - 1, im] - zeta / (zeta + eta) * vrr_terms[ i, j, k, q, r, s - 1, im + 1])) if k: vrr_terms[i, j, k, q, r, s + 1, im] += (k / 2. / (zeta + eta) * vrr_terms[i, j, k - 1, q, r, s, im + 1]) return vrr_terms[la, ma, na, lc, mc, nc, M]
def vrr_array(xyza, lmna, alphaa, xyzb, alphab, xyzc, lmnc, alphac, xyzd, alphad): la, ma, na = lmna lc, mc, nc = lmnc xa, ya, za = xyza xb, yb, zb = xyzb xc, yc, zc = xyzc xd, yd, zd = xyzd px, py, pz = xyzp = gaussian_product_center(alphaa, xyza, alphab, xyzb) qx, qy, qz = xyzq = gaussian_product_center(alphac, xyzc, alphad, xyzd) zeta, eta = float(alphaa + alphab), float(alphac + alphad) wx, wy, wz = xyzw = gaussian_product_center(zeta, xyzp, eta, xyzq) zpe = zeta + eta rab2 = norm2(xyza - xyzb) Kab = sqrt(2)*pow(pi,1.25)/(alphaa+alphab)\ *exp(-alphaa*alphab/(alphaa+alphab)*rab2) rcd2 = norm2(xyzc - xyzd) Kcd = sqrt(2)*pow(pi,1.25)/(alphac+alphad)\ *exp(-alphac*alphad/(alphac+alphad)*rcd2) rpq2 = norm2(xyzp - xyzq) T = zeta * eta / zpe * rpq2 mtot = sum(lmna) + sum(lmnc) vrr_terms = {} #zeros((la+1,ma+1,na+1,lc+1,mc+1,nc+1,mtot+1),'d') for m in xrange(mtot + 1): vrr_terms[0, 0, 0, 0, 0, 0, m] = Fgamma(m, T) * Kab * Kcd / sqrt(zpe) for i in xrange(la): for m in xrange(mtot - i): vrr_terms[i+1,0,0, 0,0,0, m] = (px-xa)*vrr_terms[i,0,0, 0,0,0, m] +\ (wx-px)*vrr_terms[i,0,0, 0,0,0, m+1] if i > 0: vrr_terms[i + 1, 0, 0, 0, 0, 0, m] += i / 2. / zeta * ( vrr_terms[i - 1, 0, 0, 0, 0, 0, m] - eta / zpe * vrr_terms[i - 1, 0, 0, 0, 0, 0, m + 1]) for i, j in product(xrange(la + 1), xrange(ma)): for m in range(mtot - i - j): vrr_terms[i,j+1,0, 0,0,0, m] = (py-ya)*vrr_terms[i,j,0, 0,0,0, m] +\ (wy-py)*vrr_terms[i,j,0, 0,0,0, m+1] if j > 0: vrr_terms[i, j + 1, 0, 0, 0, 0, m] += j / 2. / zeta * ( vrr_terms[i, j - 1, 0, 0, 0, 0, m] - eta / zpe * vrr_terms[i, j - 1, 0, 0, 0, 0, m + 1]) for i, j, k in product(xrange(la + 1), xrange(ma + 1), xrange(na)): for m in range(mtot - i - j - k): vrr_terms[i,j,k+1, 0,0,0, m] = (pz-za)*vrr_terms[i,j,k, 0,0,0, m] +\ (wz-pz)*vrr_terms[i,j,k, 0,0,0, m+1] if k > 0: vrr_terms[i, j, k + 1, 0, 0, 0, m] += k / 2. / zeta * ( vrr_terms[i, j, k - 1, 0, 0, 0, m] - eta / zpe * vrr_terms[i, j, k - 1, 0, 0, 0, m + 1]) for i, j, k, q in product(xrange(la + 1), xrange(ma + 1), xrange(na + 1), xrange(lc)): for m in range(mtot - i - j - k - q): vrr_terms[i,j,k, q+1,0,0, m] = (qx-xc)*vrr_terms[i,j,k, q,0,0, m] +\ (wx-qx)*vrr_terms[i,j,k, q,0,0, m+1] if q > 0: vrr_terms[i, j, k, q + 1, 0, 0, m] += q / 2. / eta * ( vrr_terms[i, j, k, q - 1, 0, 0, m] - zeta / zpe * vrr_terms[i, j, k, q - 1, 0, 0, m + 1]) if i > 0: vrr_terms[i, j, k, q + 1, 0, 0, m] += i / 2. / zpe * vrr_terms[i - 1, j, k, q, 0, 0, m + 1] for i, j, k, q, r in product(xrange(la + 1), xrange(ma + 1), xrange(na + 1), xrange(lc + 1), xrange(mc)): for m in range(mtot - i - j - k - q - r): vrr_terms[i,j,k, q,r+1,0, m] = (qy-yc)*vrr_terms[i,j,k, q,r,0, m] +\ (wy-qy)*vrr_terms[i,j,k, q,r,0, m+1] if r > 0: vrr_terms[i, j, k, q, r + 1, 0, m] += r / 2. / eta * ( vrr_terms[i, j, k, q, r - 1, 0, m] - zeta / zpe * vrr_terms[i, j, k, q, r - 1, 0, m + 1]) if j > 0: vrr_terms[i, j, k, q, r + 1, 0, m] += j / 2. / zpe * vrr_terms[i, j - 1, k, q, r, 0, m + 1] for i, j, k, q, r, s in product(xrange(la + 1), xrange(ma + 1), xrange(na + 1), xrange(lc + 1), xrange(mc + 1), xrange(nc)): for m in range(mtot - i - j - k - q - r - s): vrr_terms[i,j,k,q,r,s+1,m] = (qz-zc)*vrr_terms[i,j,k,q,r,s,m] +\ (wz-qz)*vrr_terms[i,j,k,q,r,s,m+1] if s > 0: vrr_terms[i, j, k, q, r, s + 1, m] += s / 2. / eta * ( vrr_terms[i, j, k, q, r, s - 1, m] - zeta / zpe * vrr_terms[i, j, k, q, r, s - 1, m + 1]) if k > 0: vrr_terms[i, j, k, q, r, s + 1, m] += k / 2. / zpe * vrr_terms[i, j, k - 1, q, r, s, m + 1] return vrr_terms