Esempio n. 1
1
def validate_chemical_formula(chemical_formula):
    """ checks chemical formalae for plausibility """

    # first we check if the formula seems like a chemical formula
    m = re.match(chemical_formula)
    if m is None:
        raise ValidationError(u'%s does not seem to be a chemical formula' %
                              chemical_formula)

    # we outsource the checking of individual atoms to the chemlib
    result = checkatoms(chemical_formula)
    if result != 0:
        raise ValidationError(u'%s is not an atom' % result)
Esempio n. 2
0
def get_chemical_formula(chemical_formula):
    """ checks chemical formalae for plausibility """

    # first we check if the formula seems like a chemical formula
    m = atomregex.findall(chemical_formula)
    if m is not None:
        for form in m:
            if checkatoms(form[0]):
                return form[0]

    return u''
Esempio n. 3
0
def validate_chemical_formula(chemical_formula):
    """ checks chemical formalae for plausibility """

    # first we check if the formula seems like a chemical formula
    m = re.match(chemical_formula)
    if m is None:
        raise ValidationError(u'%s does not seem to be a chemical formula' % chemical_formula)

    # we outsource the checking of individual atoms to the chemlib
    result = checkatoms(chemical_formula)
    if result != 0:
        raise ValidationError(u'%s is not an atom' % result)