added check for decimal points in formula

This commit is contained in:
=shimwell 2020-03-24 12:06:56 +00:00
parent 5fe6576a9c
commit 430b426098

View file

@ -598,7 +598,7 @@ class Material(IDManagerMixin):
formula : str
Formula to add, e.g., 'C2O', 'C6H12O6', or (NH4)2SO4.
Note this is case sensitive, elements must start with an uppercase
character. Any numbers will be converted to integers (rounded down).
character. Multiplier numbers must be integers.
percent_type : {'ao', 'wo'}, optional
'ao' for atom percent and 'wo' for weight percent. Defaults to atom
percent.
@ -622,6 +622,11 @@ class Material(IDManagerMixin):
"""
cv.check_type('formula', formula, str)
if '.' in formula:
msg = 'Non-integer multiplier values are not accepted. The ' \
'input formula {} contains a "." character.'.format(formula)
raise ValueError(msg)
# Tokenizes the formula and check validity of tokens
tokens = re.findall(r"([A-Z][a-z]*)(\d*)|(\()|(\))(\d*)", formula)
for row in tokens: