Magnetic anisotropy of 3d transition metal clusters and ultrathin films