docs: def patch_environ(nogui=True):
      """
      Patch current environment variables so Chimera can start up and we can import its modules.
  
      Be warned that calling this function WILL restart your interpreter. Otherwise, Python
      won't catch the new LD_LIBRARY_PATH (or platform equivalent) and Chimera won't find its
      libraries during import.
  
      Parameters
      ----------
      nogui : bool, optional, default=False
          If the GUI is not going to be launched, try to locate a headless
          Chimera build to enable inline Chimera visualization.
      """
      if 'CHIMERA' in os.environ:
          return
  
      paths = guess_chimera_path(search_all=nogui)
      CHIMERA_BASE = paths[0]
      if nogui:  # try finding a headless version
          try:
              CHIMERA_BASE = next(p for p in paths if 'headless' in p)
          except StopIteration:
              pass
  
      if not os.path.isdir(CHIMERA_BASE):
          sys.exit("Could not find UCSF Chimera.\n{}".format(_INSTRUCTIONS))
      os.environ['CHIMERA'] = CHIMERA_BASE
      CHIMERA_LIB = os.path.join(CHIMERA_BASE, 'lib')
  
      # Set Tcl/Tk for gui mode
      if 'TCL_LIBRARY' in os.environ:
          os.environ['CHIMERA_TCL_LIBRARY'] = os.environ['TCL_LIBRARY']
      os.environ['TCL_LIBRARY'] = os.path.join(CHIMERA_LIB, 'tcl8.6')
  
      if 'TCLLIBPATH' in os.environ:
          os.environ['CHIMERA_TCLLIBPATH'] = os.environ['TCLLIBPATH']
      os.environ['TCLLIBPATH'] = '{' + CHIMERA_LIB + '}'
  
      if 'TK_LIBRARY' in os.environ:
          os.environ['CHIMERA_TK_LIBRARY'] = os.environ['TK_LIBRARY']
          del os.environ['TK_LIBRARY']
  
      if 'TIX_LIBRARY' in os.environ:
          os.environ['CHIMERA_TIX_LIBRARY'] = os.environ['TIX_LIBRARY']
          del os.environ['TIX_LIBRARY']
  
      if 'PYTHONNOUSERSITE' in os.environ:
          os.environ['CHIMERA_PYTHONNOUSERSITE'] = os.environ['PYTHONNOUSERSITE']
      os.environ['PYTHONNOUSERSITE'] = '1'
  
      # Check interactive and IPython
      if in_ipython() and hasattr(sys, 'ps1') and not sys.argv[0].endswith('ipython'):
          sys.argv.insert(1, 'ipython')
  
      # Platform-specific patches
      patch_environ_for_platform(CHIMERA_BASE, CHIMERA_LIB, nogui=nogui)
      os.execve(sys.executable, [sys.executable] + sys.argv, os.environ)