docs: def as_spinmode(cls, obj):
          """Converts obj into a `SpinMode` instance"""
          if isinstance(obj, cls):
              return obj
          else:
              # Assume a string with mode
              try:
                  return _mode2spinvars[obj]
              except KeyError:
                  raise KeyError("Wrong value for spin_mode: %s" % str(obj))