Structural, electronic and magnetic properties of chalcopyrite magnetic semiconductors: A first-principles study