def calculate_dofs(conf, atom_idxs, selstring):
    """Calculates interatomic distances or dihedral-angle values based on the
    configuration `conf`, on a matrix of atom indexes `atom_idxs` (either with 2
    or with 4 columns) and on a string `selstring` identifying the type of
    parameter.
    """
    if atom_idxs.size != 0: # do something only if list is not empty
        if (selstring == 'cs6') or (selstring == 'cs12'):
            if atom_idxs.shape[1] != 2:
                raise ValueError
            return conf.getDistances(atom_idxs[:,0], atom_idxs[:,1])
        else:
            if atom_idxs.shape[1] != 4:
                raise ValueError
            return conf.getDihedrals(atom_idxs[:,0], atom_idxs[:,1], atom_idxs[:,2],
                                    atom_idxs[:,3])
    else:
        return []