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
评论列表
文章目录