Spin-induced metal–insulator transition and magnetic hysteresis in metal-based polyphthalocyanines