basis.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:exatomic 作者: exa-analytics 项目源码 文件源码
def clean_sh(sh):
    """Turns symbolic solid harmonic functions into string representations
    to be using in generating basis functions.

    Args
        sh (OrderedDict): Output from exatomic.algorithms.basis.solid_harmonics

    Returns
        clean (OrderedDict): cleaned strings
    """
    _replace = {'x': '{x}', 'y': '{y}', 'z': '{z}', ' - ': ' -'}
    _repatrn = re.compile('|'.join(_replace.keys()))
    clean = OrderedDict()
    for key, sym in sh.items():
        if isinstance(sym, (Mul, Add)):
            string = str(sym.expand()).replace(' + ', ' ')#.replace(' - ', ' -')
            string = _repatrn.sub(lambda x: _replace[x.group(0)], string)
            clean[key] = [pre + '*' for pre in string.split()]
        else: clean[key] = ['']
    return clean
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号