def _nao_sub(mol, pre_occ, pre_nao, s=None): if s is None: s = mol.intor_symmetric('cint1e_ovlp_sph') core_lst, val_lst, rydbg_lst = _core_val_ryd_list(mol) nbf = mol.nao_nr() cnao = numpy.empty((nbf,nbf)) if core_lst: c = pre_nao[:,core_lst].copy() s1 = reduce(lib.dot, (c.T, s, c)) cnao[:,core_lst] = c1 = lib.dot(c, orth.lowdin(s1)) c = pre_nao[:,val_lst].copy() c -= reduce(lib.dot, (c1, c1.T, s, c)) else: c = pre_nao[:,val_lst] if val_lst: s1 = reduce(lib.dot, (c.T, s, c)) wt = pre_occ[val_lst] cnao[:,val_lst] = lib.dot(c, orth.weight_orth(s1, wt)) if rydbg_lst: cvlst = core_lst + val_lst c1 = cnao[:,cvlst].copy() c = pre_nao[:,rydbg_lst].copy() c -= reduce(lib.dot, (c1, c1.T, s, c)) s1 = reduce(lib.dot, (c.T, s, c)) cnao[:,rydbg_lst] = lib.dot(c, orth.lowdin(s1)) snorm = numpy.linalg.norm(reduce(lib.dot, (cnao.T, s, cnao)) - numpy.eye(nbf)) if snorm > 1e-9: logger.warn(mol, 'Weak orthogonality for localized orbitals %s', snorm) return cnao
def _nao_sub(mol, pre_occ, pre_nao, s=None): if s is None: s = mol.intor_symmetric('cint1e_ovlp_sph') core_lst, val_lst, rydbg_lst = _core_val_ryd_list(mol) nbf = mol.nao_nr() cnao = numpy.empty((nbf,nbf)) if core_lst: c = pre_nao[:,core_lst] s1 = reduce(numpy.dot, (c.T, s, c)) cnao[:,core_lst] = c1 = numpy.dot(c, orth.lowdin(s1)) c = pre_nao[:,val_lst] c -= reduce(numpy.dot, (c1, c1.T, s, c)) else: c = pre_nao[:,val_lst] s1 = reduce(numpy.dot, (c.T, s, c)) wt = pre_occ[val_lst] cnao[:,val_lst] = numpy.dot(c, orth.weight_orth(s1, wt)) if rydbg_lst: cvlst = core_lst + val_lst c1 = cnao[:,cvlst] c = pre_nao[:,rydbg_lst] c -= reduce(numpy.dot, (c1, c1.T, s, c)) s1 = reduce(numpy.dot, (c.T, s, c)) cnao[:,rydbg_lst] = numpy.dot(c, orth.lowdin(s1)) snorm = numpy.linalg.norm(reduce(numpy.dot, (cnao.T, s, cnao)) - numpy.eye(nbf)) if snorm > 1e-9: logger.warn(mol, 'Weak orthogonality for localized orbitals %s', snorm) return cnao
def _nao_sub(mol, pre_occ, pre_nao): core_lst, val_lst, rydbg_lst = _core_val_ryd_list(mol) s = mol.intor_symmetric('cint1e_ovlp_sph') nao = mol.nao_nr() cnao = numpy.zeros((nao,nao)) if core_lst: c = pre_nao[:,core_lst] s1 = reduce(numpy.dot, (c.T, s, c)) cnao[:,core_lst] = numpy.dot(c, orth.lowdin(s1)) c1 = cnao[:,core_lst] rm_core = numpy.eye(nao) - reduce(numpy.dot, (c1, c1.T, s)) c = numpy.dot(rm_core, pre_nao[:,val_lst]) s1 = reduce(numpy.dot, (c.T.conj(), s, c)) wt = pre_occ[val_lst] cnao[:,val_lst] = numpy.dot(c, orth.weight_orth(s1, wt)) if rydbg_lst: c1 = cnao[:,val_lst] rm_val = numpy.eye(nao)-reduce(numpy.dot, (c1, c1.T, s)) c = reduce(numpy.dot, (rm_core, rm_val, pre_nao[:,rydbg_lst])) s1 = reduce(numpy.dot, (c.T.conj(), s, c)) cnao[:,rydbg_lst] = numpy.dot(c, orth.lowdin(s1)) return cnao
def test_weight_orth(self): numpy.random.seed(10) n = 100 a = numpy.random.random((n,n)) s = numpy.dot(a.T, a) weight = numpy.random.random(n) c = orth.weight_orth(s, weight) self.assertTrue(numpy.allclose(reduce(numpy.dot, (c.T, s, c)), numpy.eye(n))) self.assertAlmostEqual(numpy.linalg.norm(c), 36.56738258719514, 9) self.assertAlmostEqual(abs(c).sum(), 1908.8535852660757, 7)
def test_weight_orth(self): numpy.random.seed(10) n = 100 a = numpy.random.random((n, n)) s = numpy.dot(a.T, a) weight = numpy.random.random(n) c = orth.weight_orth(s, weight) self.assertTrue( numpy.allclose(reduce(numpy.dot, (c.T, s, c)), numpy.eye(n))) self.assertAlmostEqual(numpy.linalg.norm(c), 36.56738258719514, 8) self.assertAlmostEqual(abs(c).sum(), 1908.8535852660757, 6)
def _nao_sub(mol, pre_occ, pre_nao, s=None): if s is None: if getattr(mol, 'pbc_intor', None): # whether mol object is a cell s = mol.pbc_intor('int1e_ovlp', hermi=1) else: s = mol.intor_symmetric('int1e_ovlp') core_lst, val_lst, rydbg_lst = _core_val_ryd_list(mol) nbf = mol.nao_nr() pre_nao = pre_nao.astype(s.dtype) cnao = numpy.empty((nbf, nbf), dtype=s.dtype) if core_lst: c = pre_nao[:, core_lst].copy() s1 = reduce(lib.dot, (c.conj().T, s, c)) cnao[:, core_lst] = c1 = lib.dot(c, orth.lowdin(s1)) c = pre_nao[:, val_lst].copy() c -= reduce(lib.dot, (c1, c1.conj().T, s, c)) else: c = pre_nao[:, val_lst] if val_lst: s1 = reduce(lib.dot, (c.conj().T, s, c)) wt = pre_occ[val_lst] cnao[:, val_lst] = lib.dot(c, orth.weight_orth(s1, wt)) if rydbg_lst: cvlst = core_lst + val_lst c1 = cnao[:, cvlst].copy() c = pre_nao[:, rydbg_lst].copy() c -= reduce(lib.dot, (c1, c1.conj().T, s, c)) s1 = reduce(lib.dot, (c.conj().T, s, c)) cnao[:, rydbg_lst] = lib.dot(c, orth.lowdin(s1)) snorm = numpy.linalg.norm( reduce(lib.dot, (cnao.conj().T, s, cnao)) - numpy.eye(nbf)) if snorm > 1e-9: logger.warn(mol, 'Weak orthogonality for localized orbitals %s', snorm) return cnao
def _nao_sub(mol, pre_occ, pre_nao, s=None): if s is None: if getattr(mol, 'pbc_intor', None): # whether mol object is a cell s = mol.pbc_intor('int1e_ovlp', hermi=1) else: s = mol.intor_symmetric('int1e_ovlp') core_lst, val_lst, rydbg_lst = _core_val_ryd_list(mol) nbf = mol.nao_nr() pre_nao = pre_nao.astype(s.dtype) cnao = numpy.empty((nbf,nbf), dtype=s.dtype) if core_lst: c = pre_nao[:,core_lst].copy() s1 = reduce(lib.dot, (c.conj().T, s, c)) cnao[:,core_lst] = c1 = lib.dot(c, orth.lowdin(s1)) c = pre_nao[:,val_lst].copy() c -= reduce(lib.dot, (c1, c1.conj().T, s, c)) else: c = pre_nao[:,val_lst] if val_lst: s1 = reduce(lib.dot, (c.conj().T, s, c)) wt = pre_occ[val_lst] cnao[:,val_lst] = lib.dot(c, orth.weight_orth(s1, wt)) if rydbg_lst: cvlst = core_lst + val_lst c1 = cnao[:,cvlst].copy() c = pre_nao[:,rydbg_lst].copy() c -= reduce(lib.dot, (c1, c1.conj().T, s, c)) s1 = reduce(lib.dot, (c.conj().T, s, c)) cnao[:,rydbg_lst] = lib.dot(c, orth.lowdin(s1)) snorm = numpy.linalg.norm(reduce(lib.dot, (cnao.conj().T, s, cnao)) - numpy.eye(nbf)) if snorm > 1e-9: logger.warn(mol, 'Weak orthogonality for localized orbitals %s', snorm) return cnao