Back to Home

STM Python control: simulator and RL

amrl-transport library unifies STM control for RL agents. Simulator emulates atom manipulation physics, asyncio server replaces LabVIEW. Support for Createc/Nanonis, RabbitMQ task queues.

Atom control via Python and RL agents
Advertisement 728x90

Python Infrastructure for STM Control and Atomic Manipulation

The amrl-transport library offers a consistent interface for scanning tunneling microscopes (STM). The STMTransport class defines 12 methods using physical units: nanometers, millivolts, and picoamperes. Implementation varies by controller—Createc, Nanonis, or simulator.

from amrl_transport.transport.protocol import STMTransport

class STMTransport(ABC):
    def connect(self) -> None: ...
    def scan_image(self, size_nm, offset_nm, pixel, bias_mv) -> ScanResult: ...
    def lateral_manipulation(self, x_start_nm, y_start_nm, 
                             x_end_nm, y_end_nm, ...) -> ManipResult: ...
    def tip_shape(self, x_nm, y_nm, ...) -> bool: ...
    # plus 8 more methods

Methods include surface scanning, lateral and vertical atomic manipulation, tip shaping, and chemical operations. RL agents operate on an abstraction layer, independent of hardware platform.

Simulation for Development Without Hardware

SimulatorTransport emulates the full STM workflow. Surface atoms are generated with Gaussian distributions, and customizable noise is supported. Manipulation physics: atoms move under sufficient current; the tip dulls and sharpens over time.

Google AdInline article slot
from amrl_transport.transport import SimulatorTransport
import numpy as np

with SimulatorTransport(seed=42) as stm:
    img = stm.scan_image(
        size_nm=5.0,
        offset_nm=np.array([0.0, 0.0]),
        pixel=128,
        bias_mv=100,
    )
    # img.img_forward — numpy array 128x128

The simulator enables training RL agents directly on a laptop. Migrating to real hardware requires addressing the sim-to-real gap.

Replacing LabVIEW Server DeepSPM

DeepSPM (Nature Communications, 2020) uses a LabVIEW TCP server to communicate with Createc controllers. The protocol was reverse-engineered: 6 commands — scan, tipshaping, tipclean, getparam, approach, movearea. Responses are binary.

The Python implementation using asyncio is fully compatible:

Google AdInline article slot
python -m amrl_transport.deepspm --transport simulator

DeepSPM code connects to localhost:5556 without changes. LabVIEW (costing $3,500/year, Windows-only) is replaced with cross-platform MIT-licensed code.

Queue System for Parallel Tasks

RabbitMQ + Redis manage task distribution across multiple microscopes. Tasks are defined via Pydantic models: ManipulationTask, AtomTarget.

# Worker
python -m amrl_transport.cli worker --transport simulator --worker-id sim-01

# Submitting a task
python -m amrl_transport.cli submit --atoms '[[0,0],[1,0],[0.5,0.866]]'

Supports parallel scanning and manipulation across 3–5 instruments. Graceful shutdown and retry backoff in workers.

Google AdInline article slot

Integration with RL Environments

TransportEnv is a drop-in replacement for RealExpEnv from SINGROUP (Aalto University). Gym-compatible interface:

from amrl_transport.transport import SimulatorTransport
from amrl_transport.integration import TransportEnv

stm = SimulatorTransport(seed=42)
stm.connect()

env = TransportEnv(
    transport=stm,
    step_nm=0.2,
    max_mvolt=20,
    max_pcurrent_to_mvolt_ratio=2850,
    goal_nm=2.0,
)

state, info = env.reset()
next_state, reward, done, info = env.step(action)

Trained models transfer seamlessly from simulation to real hardware.

Key STM Control Features:

  • Atomic-resolution scanning
  • Lateral manipulation (~10 seconds per atom)
  • Vertical manipulation
  • Tip-induced chemistry
  • Autonomous control via RL agents

Testing and Architecture

41 tests cover protocols, simulator, COM/TCP mocks, asyncio server, queues, and integration. All run without physical equipment:

$ pytest tests/ -v
... 41 passed in 2.34s

Architecture:

amrl_transport/
├── transport/           # ABC + adapters
├── deepspm/            # asyncio server
├── queue/              # RabbitMQ/Redis
├── integration.py      # Gym Env
└── cli.py

Why It Matters

  • Unified API for Createc, Nanonis, and simulator
  • Full STM physics emulation without $500K equipment
  • Cross-platform LabVIEW alternative (MIT vs $3,500/year)
  • Drop-in Gym environment for atomic manipulation RL training
  • Parallel execution across multiple microscopes

— Editorial Team

Advertisement 728x90

Read Next