Metadata-Version: 2.4
Name: RayCrafter
Version: 0.0.6
Summary: Raytracing GUI for simple optical systems using off-the-shelf lenses and Optiland
Author-email: Rob Campbell <git@raacampbell.com>
License-Expression: MIT
Project-URL: Source Code, https://github.com/raycrafter-optical-design/raycrafter
Project-URL: Bug Tracker, https://github.com/raycrafter-optical-design/raycrafter/issues
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Operating System :: OS Independent
Classifier: Topic :: Scientific/Engineering :: Physics
Requires-Python: >=3.12.0
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: optiland<0.7,>=0.6.3
Requires-Dist: numpy
Requires-Dist: scipy
Requires-Dist: matplotlib
Requires-Dist: pillow
Requires-Dist: PyQt6>=6.8
Requires-Dist: pyqtgraph>=0.14
Requires-Dist: pyopengl>=3.1.7
Requires-Dist: markdown>=3.5
Provides-Extra: mcp
Requires-Dist: mcp<2.4,>=2.3; extra == "mcp"
Provides-Extra: cad
Requires-Dist: cadquery-ocp-novtk<8.1,>=8.0; extra == "cad"
Provides-Extra: dev
Requires-Dist: mcp<2.4,>=2.3; extra == "dev"
Requires-Dist: cadquery-ocp-novtk<8.1,>=8.0; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: coverage; extra == "dev"
Requires-Dist: tox; extra == "dev"
Requires-Dist: mypy; extra == "dev"
Requires-Dist: pre-commit; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Requires-Dist: setuptools-scm; extra == "dev"
Dynamic: license-file

# RayCrafter

[![Python Version](https://img.shields.io/pypi/pyversions/raycrafter.svg)](https://pypi.org/project/raycrafter)
[![PyPI Version](https://img.shields.io/pypi/v/raycrafter.svg)](https://pypi.org/project/raycrafter)
[![License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/raycrafter-optical-design/raycrafter/blob/main/LICENSE)
[![Build Status](https://img.shields.io/github/actions/workflow/status/raycrafter-optical-design/raycrafter/test_and_deploy.yml?branch=main&label=CI)](https://github.com/raycrafter-optical-design/raycrafter/actions/workflows/test_and_deploy.yml)
[![Code style: Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
[![codecov](https://codecov.io/gh/raycrafter-optical-design/raycrafter/branch/main/graph/badge.svg)](https://codecov.io/gh/raycrafter-optical-design/raycrafter)

RayCrafter is an early proof of principle for a lens-level optical design tool. You place
off-the-shelf lenses on an optical axis, drag them around, and see the spot diagram,
through-focus curve, MTF, ray fan, field curvature and distortion update as you go. The ray
tracing is done by [Optiland](https://github.com/optiland/optiland).

- **Lenses:** the Thorlabs spherical lenses, achromats, air-spaced doublets, triplets and
  matched pairs, plus ideal (paraxial) lenses.
- **Layout:** type the gaps between lenses and lock them; group lenses into assemblies (such
  as Plossl pairs) and save them as your own parts.
- **Beams:** any number, each with its own width, angle, vergence, offset and wavelength.
- **3D view:** View > Show 3D View shows the lenses and rays in a window you can rotate.
- **Files:** save designs as RayCrafter project files, import and export Zemax `.zmx` files,
  and open a report with a 3D view in your browser, which updates as you change the design
  and can be saved as one file to send to others.
- **Scripting:** drive it from Python, or let an AI agent do so (see below).

[Documentation](https://raycrafter-optical-design.github.io/raycrafter-docs/)

**Status:** pre-alpha. Expect anything to change, including the API.
Detailed validation against Zemax is in the pipeline but is not yet started.
Preliminary results, however, indicate good alignment with Zemax on many metrics.


## Install and run

```
pip install raycrafter
raycrafter
```

Or, with [uv](https://docs.astral.sh/uv/): `uvx raycrafter`.

To run the current development version from the `main` branch on GitHub, use uv directly
(no clone or install step needed):

```
uvx --from git+https://github.com/raycrafter-optical-design/raycrafter@main raycrafter
```

The MCP server from `main` can be run the same way (see below):

```
uvx --from "raycrafter[mcp] @ git+https://github.com/raycrafter-optical-design/raycrafter@main" raycrafter-mcp
```

`main` may contain changes not yet in the PyPI release, so behaviour may differ from
`pip install raycrafter`.


## Export to CAD (STEP)

File > Export STEP writes the lenses (an exact solid for each glass element) and, if wanted,
the rays (as thin rods), in mm with z along the optical axis. It needs an optional CAD library
(about 60 MB to download):

```
pip install "raycrafter[cad]"
```

Edge flats and chamfers are not modelled, and paraxial lenses,
apertures and the detector are not exported. From a script, use
`bench.save_step("my_design.step", ray_rings=2)`.


## Use it from Python

```python
from raycrafter import Bench

bench = Bench(empty=True)  # or Bench.connect() to drive the open window
bench.add_lens("AC254-100-A")
bench.add_lens("AC254-050-A", front_z_mm=150)
bench.autofocus()
print(bench.summary())
bench.plot("spot_diagram").savefig("spot.png")
```

Every method is documented, with examples, in `raycrafter/api.py`.


## Use it from an AI agent

RayCrafter includes an [MCP](https://modelcontextprotocol.io) server, so an AI agent such as
Claude can search for lenses, build and edit a design, and read back the optics.

If a RayCrafter window is open, the agent controls that window: you watch its changes happen,
and you can also move lenses yourself and ask the agent about the result. (The window listens
only on your own computer, and writes a private file in `~/.raycrafter` so the server can find
it. Start with `raycrafter --no-agent-link` to turn this off.) If no window is open, the server
works on a design of its own, with no picture. Every result says which one it came from.

**1. Install the MCP extra.**

- With pip: `pip install "raycrafter[mcp]"`. This installs the `raycrafter-mcp` command.
- With [uv](https://docs.astral.sh/uv/): `uv tool install "raycrafter[mcp]"` installs both
  `raycrafter` and `raycrafter-mcp`. Or install nothing and let uv fetch it on demand; see the
  `uvx` setting below.

**2. Tell your MCP client where it is.** In the Claude desktop app, open Settings, then
Developer, then Edit Config. This opens the file `claude_desktop_config.json`, which is at
`~/Library/Application Support/Claude/` on macOS and `%APPDATA%\Claude\` on Windows. Add
RayCrafter under `mcpServers`, then quit and reopen the app:

```json
{
  "mcpServers": {
    "raycrafter": {
      "command": "/full/path/to/raycrafter-mcp"
    }
  }
}
```

The path must be written out in full: the app does not expand `~`, and it may not see the same
`PATH` as your terminal. Find the path with `which raycrafter-mcp` (macOS, Linux) or
`where raycrafter-mcp` (Windows).

If you use uv and installed nothing, run RayCrafter through `uvx` instead (find its path with
`which uvx`):

```json
{
  "mcpServers": {
    "raycrafter": {
      "command": "/full/path/to/uvx",
      "args": ["--from", "raycrafter[mcp]", "raycrafter-mcp"]
    }
  }
}
```

Other MCP clients (for example Claude Code: `claude mcp add raycrafter -- raycrafter-mcp`) take
the same command.


## An agent-generated project

The code in this repository is written by AI coding agents, working with the project's
developers. Due to time constraints, the project is only possible because of agentic
coding.

We nonetheless aim for well-designed, readable code that people who use little or no AI can
understand and contribute to. The rules the agents follow are in [CLAUDE.md](CLAUDE.md), and
significant decisions, with their reasons, are recorded in the topic files of
[agent_docs/](agent_docs/README.md). How agents use those notes, and how to run several agents
at once, is explained in [AGENT_WORKFLOW.md](AGENT_WORKFLOW.md).
