Ab initio calculation of a graphene-ribbon-based molecular switch