Structural, electronic and magnetic properties of metal phthalocyanines