def serialize_formula(formula):
charge = charge_from_formula(formula)<EOL>element_dict = nested_formula_parser(formula)<EOL>base = atoms_to_Hill(element_dict)<EOL>if charge  == <NUM_LIT:0>:<EOL><INDENT>pass<EOL><DEDENT>elif charge > <NUM_LIT:0>:<EOL><INDENT>if charge == <NUM_LIT:1>:<EOL><INDENT>base += '<STR_LIT:+>'<EOL><DEDENT>else:<EOL><INDENT>base += '<STR_LIT:+>' + str(charge)<EOL><DEDENT><DEDENT>elif charge < <NUM_LIT:0>:<EOL><INDENT>if charge == -<NUM_LIT:1>:<EOL><INDENT>base += '<STR_LIT:->'<EOL><DEDENT>else:<EOL><INDENT>base +=  str(charge)<EOL><DEDENT><DEDENT>return base<EOL>
r'''Basic formula serializer to construct a consistently-formatted formula.
    This is necessary for handling user-supplied formulas, which are not always
    well formatted.

    Performs no sanity checking that elements are actually elements.

    Parameters
    ----------
    formula : str
        Formula string as parseable by the method nested_formula_parser, [-]

    Returns
    -------
    formula : str
        A consistently formatted formula to describe a molecular formula, [-]

    Notes
    -----

    Examples
    --------
    >>> serialize_formula('Pd(NH3)4+3')
    'H12N4Pd+3'