def parse_composition(self):
tmp_formula = self.formula<EOL>if "<STR_LIT:*>" in tmp_formula:<EOL><INDENT>warn("<STR_LIT>" % self.formula)<EOL>tmp_formula = self.formula.replace("<STR_LIT:*>", "<STR_LIT>")<EOL><DEDENT>if "<STR_LIT:(>" in tmp_formula or "<STR_LIT:)>" in tmp_formula:<EOL><INDENT>warn("<STR_LIT>" % self.formula)<EOL>return<EOL><DEDENT>composition = {}<EOL>parsed = element_re.findall(tmp_formula)<EOL>for (element, count) in parsed:<EOL><INDENT>if count == '<STR_LIT>':<EOL><INDENT>count = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>count = float(count)<EOL>int_count = int(count)<EOL>if count == int_count:<EOL><INDENT>count = int_count<EOL><DEDENT>else:<EOL><INDENT>warn("<STR_LIT>" %<EOL>(count, self.formula))<EOL><DEDENT><DEDENT>except ValueError:<EOL><INDENT>warn("<STR_LIT>" %<EOL>(count, self.formula))<EOL>self.elements = {}<EOL>return<EOL><DEDENT><DEDENT>if element in composition:<EOL><INDENT>composition[element] += count<EOL><DEDENT>else:<EOL><INDENT>composition[element] = count<EOL><DEDENT><DEDENT>self.elements = composition<EOL>
Breaks the chemical formula down by element.