def all_target_and_background_names(experiment_proto):
  """Determine names of all molecules for which to calculate affinities.

  Args:
    experiment_proto: selection_pb2.Experiment describing the experiment.

  Returns:
    List of strings giving names of target molecules followed by background
    molecules.
  """
  targets = set()
  backgrounds = set()

  for round_proto in experiment_proto.rounds.values():
    for k, v in round_proto.target_concentrations.items():
      # don't add targets with a concentration of exactly zero
      if v:
        targets.add(k)
    for k, v in round_proto.background_concentrations.items():
      if v:
        backgrounds.add(k)

  return sorted(targets) + [b for b in sorted(backgrounds) if b not in targets]