Labs · Optics and microscopy

BASF pyTEM TEM interface (pyTEM.Interface.Interface)

BASF pyTEM TEM interface (pyTEM.Interface.Interface), adapted from basf/pytem. It reads stage_home, beam_blanked, screen_position, column_valve_position and 5 more; sets stage_x, stage_y, stage_z, stage_alpha and 1 more; runs reset_stage_position and enter_safe_state. reset_stage_position: reset the stage to x=y=z=alpha=beta=0 (the native reset_stage_position). A hardware driver: the market serves its fake backend, so no instrument is needed.

hardwareRisk R3MITcontract_checkedserved on the fake backend
openai4s lab add labs/basf__pytem

Install

Three ways to run this device. Each one serves its fake backend: no instrument, no simulator install and no upstream checkout.

OpenAI4S (one command)

shell
openai4s lab add labs/basf__pytem

Installs the device into the OpenAI4S Lab on its fake backend and starts it. First time? See setup below.

Or, in the workbench, open the Lab tab → Market → Install.

Standalone MHS endpoint

shell
git clone --depth 1 https://github.com/PKU-YuanGroup/OpenMHS.git && cd OpenMHS
PYTHONPATH=MHS/sdk/src python3 -m mhs serve labs/basf__pytem --port 7400
# in a second terminal, from the same directory:
PYTHONPATH=MHS/sdk/src python3 -m mhs describe --endpoint http://127.0.0.1:7400

Serves the device as an MHS endpoint on port 7400 from an OpenMHS clone (Python 3.10 or later, standard library only); describe prints what it offers.

Any MCP host (Claude Desktop, Cursor, …)

mcp configuration
{
  "mcpServers": {
    "pytem": {
      "command": "python3",
      "args": [
        "-m",
        "mhs",
        "serve",
        "labs/basf__pytem",
        "--mcp"
      ],
      "env": {
        "PYTHONPATH": "/path/to/OpenMHS/MHS/sdk/src"
      }
    }
  }
}

Add this server to the host's MCP configuration and replace /path/to/OpenMHS with the path of your OpenMHS clone. The host starts the server and talks to it on stdin and stdout.

What it does

Measures

  • stage_home
  • beam_blanked
  • screen_position
  • column_valve_position
  • column_vacuum
  • accelerator_vacuum
  • mode
  • projection_mode
  • illumination_mode

Adjusts

  • stage_x
  • stage_y
  • stage_z
  • stage_alpha
  • stage_beta

Actions

reset_stage_position
Reset the stage to x=y=z=alpha=beta=0 (the native reset_stage_position)
enter_safe_state
Enter the native safe state: close the column valve, blank the beam and insert the screen

Names as the driver declares them. Units, limits and the safety declaration are in the package's REFERENCE.md.

First-time setup

The OpenAI4S workbench with the OpenMHS lab, from a source checkout:

shell
# OpenAI4S workbench with the OpenMHS lab (source checkout)
git clone --recursive https://github.com/PKU-YuanGroup/OpenAI4S.git
cd OpenAI4S && ./setup.sh && source .venv/bin/activate
openai4s lab add labs/basf__pytem
openai4s serve        # open the Lab tab

The standalone endpoint and the MCP server need only an OpenMHS clone and Python 3.10 or later. More in the market's getting-started guide and on the OpenAI4S host page.

Source and evidence

Upstream
basf/pytem
Pinned commit
d2b280032952
Licence
MIT
Stars
15
Evidence
contract_checked on the fake backend
Backends
fake, hardware

The driver package MHS/drivers/labs/basf__pytem wraps the upstream code at the pinned commit. Its REFERENCE.md documents the full contract: every value, action, unit, limit and the safety declaration.