Cobalt and beryllium in diamond: experimental and first-principles calculations of magnetic and electronic properties