def is_negatively_charged_oxygen(atom_name, resname):
  """
  Determine whether the oxygen atom of interest is either negatively charged
  (usually a carboxyl group or sulfate/phosphate), or has a lone pair (and
  no hydrogen atom) that would similarly repel anions.

  Parameters
  -----------
  atom_name : str
  resname : str

  Returns
  -------
  bool
  """
  if ((atom_name in ["OD1","OD2","OE1","OE2"]) and
      (resname in ["GLU","ASP","GLN","ASN"])):
    return True
  elif ((atom_name == "O") and (not resname in ["HOH","WAT"])):
    return True # sort of - the lone pair acts this way
  elif ((len(atom_name) == 3) and (atom_name[0:2] in ["O1","O2","O3"]) and
        (atom_name[2] in ["A","B","G"])):
    return True
  elif (resname in ["SO4","PO4"]):
    return True
  return False