Nanotube functionalization and polymer grafting: An ab initio study