# Bragg Diffraction API
> X-ray crystallography maths as an API, computed locally and deterministically. The angle endpoint applies Bragg’s law, n·λ = 2·d·sinθ, to give the diffraction angle θ and the experimentally plotted 2θ from a crystal’s inter-planar spacing and the X-ray wavelength, defaulting to the common Cu Kα source at 0.15406 nm and reporting the highest observable order ⌊2d/λ⌋ — a 0.2 nm plane spacing diffracts Cu Kα to θ ≈ 22.65°, a 2θ peak near 45.3°. The spacing endpoint inverts the law, d = n·λ/(2·sinθ), reading the lattice spacing straight off a measured XRD peak — the everyday job of indexing a diffraction pattern, so a 2θ of 31.77° for table salt gives the 0.2814 nm (200) spacing. The wavelength endpoint solves λ = 2·d·sinθ/n to identify or calibrate the source. Lengths are entered in nanometres or ångström and angles in degrees, and any diffraction order n is supported. Everything is computed locally and deterministically, so it is instant and private. Ideal for materials-science, crystallography, mineralogy, XRD, semiconductor and solid-state-physics app developers, lattice-spacing and pattern-indexing tools, and laboratory software. Pure local computation — no key, no third-party service, instant. Live, nothing stored. 3 endpoints. This is reflection-geometry Bragg diffraction with the 2d factor; for optical double-slit and grating diffraction use a wave-optics diffraction API.

## Authentication
All requests require your oanor API key in the `x-oanor-key` header. Get one at https://www.oanor.com/developer/keys.

```bash
curl -H "x-oanor-key: oanor_live_…" "https://api.oanor.com/bragg-api/..."
```

## Pricing
- **Free** (Free) — 3,500 calls/Mo, 2 req/s
- **Starter** ($6/Mo) — 33,000 calls/Mo, 6 req/s
- **Pro** ($19/Mo) — 168,000 calls/Mo, 15 req/s
- **Mega** ($59/Mo) — 1,020,000 calls/Mo, 40 req/s

## Endpoints

### Bragg

#### `GET /v1/angle` — Bragg angle from spacing

**Parameters:**
- `spacing_nm` (query, optional, string) — Inter-planar spacing d (nm) Example: `0.2`
- `spacing_angstrom` (query, optional, string) — d-spacing (ångström)
- `wavelength_nm` (query, optional, string) — Wavelength (nm, default Cu Kα 0.15406)
- `order` (query, optional, string) — Diffraction order n Example: `1`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/bragg-api/v1/angle?spacing_nm=0.2&order=1"
```

**Response:**
```json
{
    "data": {
        "note": "Bragg's law n·λ = 2·d·sinθ. θ is the glancing angle from the planes; XRD patterns are plotted against 2θ. Default wavelength is Cu Kα = 0.15406 nm.",
        "inputs": {
            "order": 1,
            "spacing_nm": 0.2,
            "wavelength_nm": 0.15406
        },
        "max_order": 2,
        "theta_deg": 22.653053,
        "two_theta_deg": 45.306106
    },
    "meta": {
        "timestamp": "2026-06-05T19:50:23.738Z",
        "request_id": "4c0f0c3e-e224-4083-97e6-35875f0ef856"
    },
    "status": "ok",
    "message": "Bragg angle",
    "success": true
}
```

#### `GET /v1/spacing` — d-spacing from angle

**Parameters:**
- `two_theta` (query, optional, string) — Measured 2θ (deg) Example: `45.31`
- `theta` (query, optional, string) — Or θ (deg)
- `wavelength_nm` (query, optional, string) — Wavelength (nm, default Cu Kα)
- `order` (query, optional, string) — Diffraction order n Example: `1`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/bragg-api/v1/spacing?two_theta=45.31&order=1"
```

**Response:**
```json
{
    "data": {
        "note": "Inter-planar spacing d = n·λ/(2·sinθ). This is how a crystal's lattice spacing is read off an XRD peak.",
        "inputs": {
            "order": 1,
            "theta_deg": 22.655,
            "wavelength_nm": 0.15406
        },
        "spacing_nm": 0.19998371,
        "spacing_angstrom": 1.999837
    },
    "meta": {
        "timestamp": "2026-06-05T19:50:23.819Z",
        "request_id": "36c08afd-efaf-4aef-8304-2ec7eef4eef5"
    },
    "status": "ok",
    "message": "d-spacing",
    "success": true
}
```

#### `GET /v1/wavelength` — Wavelength from spacing & angle

**Parameters:**
- `spacing_nm` (query, optional, string) — d-spacing (nm) Example: `0.2`
- `spacing_angstrom` (query, optional, string) — d-spacing (ångström)
- `two_theta` (query, optional, string) — 2θ (deg) Example: `45.31`
- `theta` (query, optional, string) — Or θ (deg)
- `order` (query, optional, string) — Order n Example: `1`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/bragg-api/v1/wavelength?spacing_nm=0.2&two_theta=45.31&order=1"
```

**Response:**
```json
{
    "data": {
        "note": "Wavelength λ = 2·d·sinθ/n — used to calibrate or identify the X-ray source from a known reflection.",
        "inputs": {
            "order": 1,
            "theta_deg": 22.655,
            "spacing_nm": 0.2
        },
        "wavelength_nm": 0.15407255,
        "wavelength_angstrom": 1.540725
    },
    "meta": {
        "timestamp": "2026-06-05T19:50:23.900Z",
        "request_id": "61d2dadc-7021-4c5e-9e3a-2f501f36f036"
    },
    "status": "ok",
    "message": "Wavelength",
    "success": true
}
```

### Meta

#### `GET /v1/meta` — Spec

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/bragg-api/v1/meta"
```

**Response:**
```json
{
    "data": {
        "notes": "Lengths in nm or ångström, angles in degrees. Reflection (Bragg) geometry with the 2d factor; for optical double-slit/grating diffraction use a wave-optics diffraction API.",
        "service": "bragg-api",
        "constants": {
            "cu_k_alpha_nm": 0.15406
        },
        "endpoints": {
            "GET /v1/meta": "This document.",
            "GET /v1/angle": "Bragg angle θ and 2θ from d-spacing and wavelength.",
            "GET /v1/spacing": "Inter-planar spacing from the Bragg angle.",
            "GET /v1/wavelength": "Wavelength from spacing and angle."
        },
        "description": "Bragg's law for X-ray crystallography: diffraction angle, inter-planar d-spacing and wavelength from n·λ = 2·d·sinθ."
    },
    "meta": {
        "timestamp": "2026-06-05T19:50:23.973Z",
        "request_id": "b6ed4da5-044e-46d4-b43a-c553f33c0581"
    },
    "status": "ok",
    "message": "Meta",
    "success": true
}
```


---
Marketplace page: https://www.oanor.com/api/bragg-api
OpenAPI spec: https://www.oanor.com/api/bragg-api/openapi.json
