First-principles studies of multiferroic and magnetoelectric materials