def ion_balance_proportional(anion_charges, cation_charges, zs, n_anions, <EOL>n_cations, balance_error, method):
anion_zs = zs[<NUM_LIT:0>:n_anions]<EOL>cation_zs = zs[n_anions:n_cations+n_anions]<EOL>anion_balance_error = sum([zi*ci for zi, ci in zip(anion_zs, anion_charges)])<EOL>cation_balance_error = sum([zi*ci for zi, ci in zip(cation_zs, cation_charges)])<EOL>if method == '<STR_LIT>':<EOL><INDENT>if balance_error < <NUM_LIT:0>:<EOL><INDENT>multiplier = -anion_balance_error/cation_balance_error<EOL>cation_zs = [i*multiplier for i in cation_zs]<EOL><DEDENT>else:<EOL><INDENT>multiplier = -cation_balance_error/anion_balance_error<EOL>anion_zs = [i*multiplier for i in anion_zs]<EOL><DEDENT><DEDENT>elif method == '<STR_LIT>':<EOL><INDENT>if balance_error < <NUM_LIT:0>:<EOL><INDENT>multiplier = -cation_balance_error/anion_balance_error<EOL>anion_zs = [i*multiplier for i in anion_zs]<EOL><DEDENT>else:<EOL><INDENT>multiplier = -anion_balance_error/cation_balance_error<EOL>cation_zs = [i*multiplier for i in cation_zs]<EOL><DEDENT><DEDENT>elif method == '<STR_LIT>':<EOL><INDENT>multiplier = -anion_balance_error/cation_balance_error<EOL>cation_zs = [i*multiplier for i in cation_zs]<EOL><DEDENT>elif method == '<STR_LIT>':<EOL><INDENT>multiplier = -cation_balance_error/anion_balance_error<EOL>anion_zs = [i*multiplier for i in anion_zs]<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>' %charge_balance_methods)<EOL><DEDENT>z_water = <NUM_LIT:1.> - sum(anion_zs) - sum(cation_zs)<EOL>return anion_zs, cation_zs, z_water<EOL>
Helper method for balance_ions for the proportional family of methods. 
    See balance_ions for a description of the methods; parameters are fairly
    obvious.