I would like to create a dictionary to split all elements of a molecular formula. I tried using re module
Formula="C16H21NO2Na3"
pat = re.compile('(?P<name>[A-Z][a-z]+)\[0-9]+(?P<name2>[0-9]+)')
molecule= pat.findall(Formula)
print (molecule)
I expected this return:
{'C': 16, 'H': 21, 'N': '', 'O': 2, 'Na': 3}