def canonicalize(mf, mo_coeff, mo_occ, fock=None): '''Canonicalization diagonalizes the UHF Fock matrix in occupied, virtual subspaces separatedly (without change occupancy). ''' mol = mf.mol if not mol.symmetry: return uhf.canonicalize(mf, mo_coeff, mo_occ, fock) mo_occ = numpy.asarray(mo_occ) assert(mo_occ.ndim == 2) if fock is None: dm = mf.make_rdm1(mo_coeff, mo_occ) fock = mf.get_hcore() + mf.get_jk(mol, dm) occidxa = mo_occ[0] == 1 occidxb = mo_occ[1] == 1 viridxa = mo_occ[0] == 0 viridxb = mo_occ[1] == 0 s = mf.get_ovlp() def eig_(fock, mo_coeff, idx, es, cs): if numpy.count_nonzero(idx) > 0: orb = mo_coeff[:,idx] f1 = reduce(numpy.dot, (orb.T.conj(), fock, orb)) e, c = scipy.linalg.eigh(f1) es[idx] = e c = numpy.dot(mo_coeff[:,idx], c) cs[:,idx] = hf_symm._symmetrize_canonicalization_(mf.mol, e, c, s) mo = numpy.empty_like(mo_coeff) mo_e = numpy.empty(mo_occ.shape) eig_(fock[0], mo_coeff[0], occidxa, mo_e[0], mo[0]) eig_(fock[0], mo_coeff[0], viridxa, mo_e[0], mo[0]) eig_(fock[1], mo_coeff[1], occidxb, mo_e[1], mo[1]) eig_(fock[1], mo_coeff[1], viridxb, mo_e[1], mo[1]) return mo_e, mo
def canonicalize(mf, mo_coeff, mo_occ, fock=None): '''Canonicalization diagonalizes the UHF Fock matrix in occupied, virtual subspaces separatedly (without change occupancy). ''' if not mf.mol.symmetry: return uhf.canonicalize(mf, mo_coeff, mo_occ, fock) mo_occ = numpy.asarray(mo_occ) assert(mo_occ.ndim == 2) if fock is None: dm = mf.make_rdm1(mo_coeff, mo_occ) fock = mf.get_hcore() + mf.get_jk(mol, dm) occidxa = mo_occ[0] == 1 occidxb = mo_occ[1] == 1 viridxa = mo_occ[0] == 0 viridxb = mo_occ[1] == 0 s = mf.get_ovlp() def eig_(fock, mo_coeff, idx, es, cs): if numpy.count_nonzero(idx) > 0: orb = mo_coeff[:,idx] f1 = reduce(numpy.dot, (orb.T.conj(), fock, orb)) e, c = scipy.linalg.eigh(f1) es[idx] = e c = numpy.dot(mo_coeff[:,idx], c) cs[:,idx] = hf_symm._symmetrize_canonicalization_(mf.mol, e, c, s) mo = numpy.empty_like(mo_coeff) mo_e = numpy.empty(mo_occ.shape) eig_(fock[0], mo_coeff[0], occidxa, mo_e[0], mo[0]) eig_(fock[0], mo_coeff[0], viridxa, mo_e[0], mo[0]) eig_(fock[1], mo_coeff[1], occidxb, mo_e[1], mo[1]) eig_(fock[1], mo_coeff[1], viridxb, mo_e[1], mo[1]) return mo_e, mo
def canonicalize(mf, mo_coeff, mo_occ, fock=None): '''Canonicalization diagonalizes the UHF Fock matrix in occupied, virtual subspaces separatedly (without change occupancy). ''' mol = mf.mol if not mol.symmetry: return uhf.canonicalize(mf, mo_coeff, mo_occ, fock) mo_occ = numpy.asarray(mo_occ) assert (mo_occ.ndim == 2) if fock is None: dm = mf.make_rdm1(mo_coeff, mo_occ) fock = mf.get_hcore() + mf.get_jk(mol, dm) occidxa = mo_occ[0] == 1 occidxb = mo_occ[1] == 1 viridxa = ~occidxa viridxb = ~occidxb mo = numpy.empty_like(mo_coeff) mo_e = numpy.empty(mo_occ.shape) if (hasattr(mo_coeff, 'orbsym') or (hasattr(mo_coeff[0], 'orbsym') and hasattr(mo_coeff[1], 'orbsym'))): orbsyma, orbsymb = get_orbsym(mol, mo_coeff) def eig_(fock, mo_coeff, idx, es, cs): if numpy.count_nonzero(idx) > 0: orb = mo_coeff[:, idx] f1 = reduce(numpy.dot, (orb.T.conj(), fock, orb)) e, c = scipy.linalg.eigh(f1) es[idx] = e cs[:, idx] = numpy.dot(mo_coeff[:, idx], c) for ir in set(orbsyma): idx_ir = orbsyma == ir eig_(fock[0], mo_coeff[0], idx_ir & occidxa, mo_e[0], mo[0]) eig_(fock[0], mo_coeff[0], idx_ir & viridxa, mo_e[0], mo[0]) for ir in set(orbsymb): idx_ir = orbsymb == ir eig_(fock[1], mo_coeff[1], idx_ir & occidxb, mo_e[1], mo[1]) eig_(fock[1], mo_coeff[1], idx_ir & viridxb, mo_e[1], mo[1]) else: s = mf.get_ovlp() def eig_(fock, mo_coeff, idx, es, cs): if numpy.count_nonzero(idx) > 0: orb = mo_coeff[:, idx] f1 = reduce(numpy.dot, (orb.T.conj(), fock, orb)) e, c = scipy.linalg.eigh(f1) es[idx] = e c = numpy.dot(mo_coeff[:, idx], c) cs[:, idx] = hf_symm._symmetrize_canonicalization_(mf, e, c, s) eig_(fock[0], mo_coeff[0], occidxa, mo_e[0], mo[0]) eig_(fock[0], mo_coeff[0], viridxa, mo_e[0], mo[0]) eig_(fock[1], mo_coeff[1], occidxb, mo_e[1], mo[1]) eig_(fock[1], mo_coeff[1], viridxb, mo_e[1], mo[1]) orbsyma, orbsymb = uhf_symm.get_orbsym(mol, mo, s, False) mo = hf_symm.attach_orbsym(mo, (orbsyma, orbsymb)) return mo_e, mo
def canonicalize(mf, mo_coeff, mo_occ, fock=None): '''Canonicalization diagonalizes the UHF Fock matrix in occupied, virtual subspaces separatedly (without change occupancy). ''' mol = mf.mol if not mol.symmetry: return uhf.canonicalize(mf, mo_coeff, mo_occ, fock) mo_occ = numpy.asarray(mo_occ) assert(mo_occ.ndim == 2) if fock is None: dm = mf.make_rdm1(mo_coeff, mo_occ) fock = mf.get_hcore() + mf.get_veff(mf.mol, dm) occidxa = mo_occ[0] == 1 occidxb = mo_occ[1] == 1 viridxa = ~occidxa viridxb = ~occidxb mo = numpy.empty_like(mo_coeff) mo_e = numpy.empty(mo_occ.shape) if (getattr(mo_coeff, 'orbsym', None) is not None or (getattr(mo_coeff[0], 'orbsym', None) is not None and getattr(mo_coeff[1], 'orbsym', None) is not None)): orbsyma, orbsymb = get_orbsym(mol, mo_coeff) def eig_(fock, mo_coeff, idx, es, cs): if numpy.count_nonzero(idx) > 0: orb = mo_coeff[:,idx] f1 = reduce(numpy.dot, (orb.T.conj(), fock, orb)) e, c = scipy.linalg.eigh(f1) es[idx] = e cs[:,idx] = numpy.dot(mo_coeff[:,idx], c) for ir in set(orbsyma): idx_ir = orbsyma == ir eig_(fock[0], mo_coeff[0], idx_ir & occidxa, mo_e[0], mo[0]) eig_(fock[0], mo_coeff[0], idx_ir & viridxa, mo_e[0], mo[0]) for ir in set(orbsymb): idx_ir = orbsymb == ir eig_(fock[1], mo_coeff[1], idx_ir & occidxb, mo_e[1], mo[1]) eig_(fock[1], mo_coeff[1], idx_ir & viridxb, mo_e[1], mo[1]) else: s = mf.get_ovlp() def eig_(fock, mo_coeff, idx, es, cs): if numpy.count_nonzero(idx) > 0: orb = mo_coeff[:,idx] f1 = reduce(numpy.dot, (orb.T.conj(), fock, orb)) e, c = scipy.linalg.eigh(f1) es[idx] = e c = numpy.dot(mo_coeff[:,idx], c) cs[:,idx] = hf_symm._symmetrize_canonicalization_(mf, e, c, s) eig_(fock[0], mo_coeff[0], occidxa, mo_e[0], mo[0]) eig_(fock[0], mo_coeff[0], viridxa, mo_e[0], mo[0]) eig_(fock[1], mo_coeff[1], occidxb, mo_e[1], mo[1]) eig_(fock[1], mo_coeff[1], viridxb, mo_e[1], mo[1]) orbsyma, orbsymb = get_orbsym(mol, mo, s, False) mo = (lib.tag_array(mo[0], orbsym=orbsyma), lib.tag_array(mo[1], orbsym=orbsymb)) return mo_e, mo