def _index_map(ntype, natom, lmax, nzeta=None):'''Bijective map between the composite index (itype, iatom, l, zeta, m)and linearized orbital index mu.An atomic orbital is labeled by its type & atomic index, its angularmomentum quantum numbers l & m, and possibly a zeta number. Supposethere's a total of N orbitals, each orbital can also be assigned aunique index mu \in [0, N-1].This function returns a pair of bijective maps between the compositeindex (itype, iatom, l, zeta, m) and the linearized orbital index mu.The composite index is linearized in C-style (lexicographic order).Parameters----------ntype : intNumber of atom types.natom : list of intNumber of atoms for each type.lmax : list of intlmax[i] specifies the maximum angular momentum of type i.nzeta : list of list of intnzeta[i][l] specifies the number of zeta orbitals of theangular momentum l of type i.If None, nzeta is assumed to be 1 for all.Returns-------comp2mu : dictA dict that maps a composite index (itype, iatom, l, zeta, m)to its linearized index.mu2comp : dictA dict that maps a linearized index to its composite index.Notes-----The linearized index arranges m in accordance with ABACUS:0, 1, -1, 2, -2, 3, -3, ..., l, -l'''if nzeta is None:nzeta = [[1]*(lmax[itype]+1) for itype in range(ntype)]assert len(natom) == ntypeassert len(lmax) == ntypeassert lmax == [len(nzeta[itype])-1 for itype in range(ntype)]comp2mu = {}mu2comp = {}mu = 0for itype in range(ntype):for iatom in range(natom[itype]):for l in range(lmax[itype]+1):for zeta in range(nzeta[itype][l]):'''In ABACUS, real spherical harmonics Ylm arranges its min the following order:0, 1, -1, 2, -2, 3, -3, ..., l, -l(see source_base/ylm.cpp and source_base/math_ylmreal.cppfor details)'''for mm in range(0, 2*l+1):m = -mm // 2 if mm % 2 == 0 else (mm + 1) // 2comp2mu[(itype, iatom, l, zeta, m)] = mumu2comp[mu] = (itype, iatom, l, zeta, m)mu += 1return comp2mu, mu2comp############################################################# Test############################################################import unittestclass _TestIndexMap(unittest.TestCase):def test_index_map(self):ntype = 3natom = [2, 1, 3]lmax = [1, 2, 4]nzeta = [[2,3], [1,0,1], [1, 2, 2, 1, 3]]comp2mu, mu2comp = _index_map(ntype, natom, lmax, nzeta)# check the total number of orbitalsnao = sum(sum( (2*l+1) * nzeta[itype][l] for l in range(lmax[itype]+1) ) \* natom[itype] for itype in range(ntype))self.assertEqual( len(mu2comp.items()), nao )# check bijectivityfor mu in range(nao):self.assertEqual( comp2mu[mu2comp[mu]], mu )# check the first and the lastself.assertEqual( mu2comp[0], (0, 0, 0, 0, 0) )self.assertEqual( mu2comp[nao-1], \(ntype-1, natom[-1]-1, lmax[-1], nzeta[-1][-1]-1, -lmax[-1]) )if __name__ == '__main__':unittest.main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。