First-Principle Studies of Permanent-Magnet Materials