On a generalization of the Rapini-Papoular expression of the surface free energy for nematic liquid crystals