First-principles study of graphene edge properties and flake shapes