First-principles study of C6M2 (M = B, Al, Mg, Li), C7B and related compounds