Defective fullerenes and nanotubes as molecular magnets: An ab initio study