def substitute(line, charges, current_residuum):
    """
	Look up the charge for an atom, and write into a string.

	Args:
	line: String containing an atom name, residuum name, and original charge.
	charges: DataFrame containing atom name, residuum names, new charges.

	Returns:
	line: the original line, with the charge updated from the `charges` table.
	"""
    current_atom = line[0:7].strip()
    mask = (charges.atom == current_atom) & (charges.residue ==
        current_residuum)
    new_charge = charges[mask].q.values[0]
    charge_string = '{: 1.6f}'.format(new_charge) + '  '
    modified_line = line[:24] + charge_string + line[34:]
    return modified_line
