Helper function for grouping selection positions

Add a helper function that can be used to divide selection positions
into groups based on residues and/or molecules.
Currently, 'gmx sasa' uses a construct like this, and 'gmx rdf -surf'
will require it as well, as will a replacement for 'gmx mindist', so it
makes sense to have a common helper function.  The helper function can
then do extensive checking on the input just in one place, and it keeps
the tool code more readable by removing some complicated loops from
there.  Also, a single set of tests is necessary to cover all the paths,
and the tool tests can focus on the tool-specific functionality, without
needing to test also the different groupings.

Improve related documentation.

Change-Id: Iaa6904c4b4b7ff5b824f37d264c327bdf52da273