def get_atoms_of_residues(soup, res_indices, atom_types=None):
  """
  Return atoms of soup that belong to residues indicated by
  res_indices and in atom_types.
  """
  atoms = []
  for i in res_indices:
    res_atoms = soup.residue(i).atoms()
    if atom_types:
      res_atoms = [a for a in res_atoms if a.type in atom_types]
    atoms.extend(res_atoms)
  return atoms