{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://laue.pasahome.org/schema/laue-1.schema.json",
  "title": "Laue document, format version 1",
  "description": "A .laue file (UTF-8 JSON) is a crystal, a tiling (plane or frieze group) or a quasicrystal, given by its group, its cell and the sites of its asymmetric unit — never by a list of every atom: readers apply the symmetry. Written by Laue and Laue Plan (Mac, iPad, Windows). Readers must ignore members they do not know; a file whose version is higher than they read is refused. Specification: https://laue.pasahome.org/schema/",
  "type": "object",
  "required": ["format", "version", "kind", "title"],
  "properties": {
    "format": { "const": "laue" },
    "version": { "type": "integer", "minimum": 1, "maximum": 1 },
    "kind": { "enum": ["crystal", "tiling", "quasicrystal"] },
    "title": { "type": "string" },
    "summary": { "type": "string" },
    "group": {
      "type": "string",
      "description": "Crystal: a space group in any setting of the International Tables, by Hermann-Mauguin symbol (\"Fm-3m\", \"P 1 21/c 1\", \"Fd-3m:2\"), number and setting (\"227:1\") or Hall symbol (\"Hall: -P 2ybc\"). Tiling: a plane group (\"p4gm\", short \"p4g\", orbifold \"4*2\", number \"12\") or a frieze group (\"frieze p2mg\"). Empty or absent for a quasicrystal. Rosette (a figure around a point, a mandala): \"rosette Cn\" (n rotations) or \"rosette Dn\" (n rotations and n mirrors), n from 1 to 24; its sites and strokes are then Cartesian coordinates around the centre, the radius of the figure being 1, and \"colouring\": \"alternate\" alternates the second colour between neighbouring copies."
    },
    "cell": { "$ref": "#/$defs/cell" },
    "sites": { "type": "array", "items": { "$ref": "#/$defs/site" } },
    "strokes": {
      "description": "Tilings: lines drawn in one cell and repeated by the group.",
      "type": "array", "items": { "$ref": "#/$defs/stroke" }
    },
    "quasicrystal": { "$ref": "#/$defs/quasicrystal" },
    "colouring": {
      "description": "Tilings: a two-colour (black-and-white) group. One digit per generator of the group, in Laue's order of generators (then a and b): 1 if it exchanges the colours. \"1000\" in p4mm: the 4-fold rotation exchanges them. Rosettes: \"alternate\" — in Cₙ every other rotation takes the second colour, in Dₙ the mirror images.",
      "type": "string",
      "anyOf": [{ "pattern": "^[01]+$" }, { "const": "alternate" }]
    },
    "secondColor": { "$ref": "#/$defs/color", "description": "Tilings: the colour of the copies whose colour is exchanged." },
    "background": { "$ref": "#/$defs/color", "description": "Tilings and quasicrystals: the colour behind the pattern; absent for the default near-white." },
    "magnetism": { "$ref": "#/$defs/magnetism" },
    "temperature": { "type": "number", "minimum": 0, "description": "Crystals: the temperature of the crystal (K), when its thermal agitation is taken into account: the vibrations of the lattice, the Debye–Waller factors of the diffraction, the Monte-Carlo of the spins. Absent: the crystal at rest." },
    "gruneisen": { "type": "number", "minimum": 0, "description": "Crystals: the Grüneisen parameter γ of the thermal expansion (measured); 2 when absent." },
    "parents": { "type": "array", "items": { "$ref": "#/$defs/parent" }, "description": "Crystals: the groups the crystal came down from by maximal subgroups (a phase transition on cooling), the highest first." },
    "colourCentres": { "type": "array", "items": { "$ref": "#/$defs/colourCentre" }, "description": "Crystals: colour centres in an otherwise perfect crystal; they change no symmetry, only the absorption of light." },
    "backdrop": { "$ref": "#/$defs/backdrop" },
    "views": { "type": "array", "items": { "$ref": "#/$defs/view" } },
    "exercise": { "$ref": "#/$defs/exercise" },
    "checks": { "$ref": "#/$defs/checks" },
    "powder": { "$ref": "#/$defs/powder" },
    "translations": {
      "description": "The document's texts in other languages, by language code (\"fr\", \"de\", \"pt-BR\", \"zh-Hans\").",
      "type": "object",
      "additionalProperties": { "$ref": "#/$defs/texts" }
    }
  },
  "$defs": {
    "parent": {
      "type": "object",
      "description": "A group the crystal came down from, as it was, and the change of cell and origin to the next one down: x' = Q⁻¹ x − p.",
      "required": ["group", "cell", "sites", "transform", "origin", "kind", "index"],
      "properties": {
        "group": { "type": "string" },
        "cell": { "$ref": "#/$defs/cell" },
        "sites": { "type": "array", "items": { "$ref": "#/$defs/site" } },
        "transform": { "type": "array", "items": { "type": "string" }, "minItems": 9, "maxItems": 9, "description": "Q row by row, exact (\"1\", \"-1/2\")." },
        "origin": { "type": "array", "items": { "type": "string" }, "minItems": 3, "maxItems": 3, "description": "p, in the coordinates of the group below." },
        "kind": { "enum": ["t", "k"], "description": "translationengleiche or klassengleiche." },
        "index": { "type": "integer", "minimum": 2 }
      },
      "additionalProperties": false
    },
    "colourCentre": {
      "type": "object",
      "required": ["kind", "strength"],
      "additionalProperties": false,
      "properties": {
        "kind": { "enum": ["chromium", "F", "band", "ion"], "description": "chromium: Cr³⁺ on the cation site `site` (Tanabe–Sugano); F: an electron in an anion vacancy on `site` (Mollwo–Ivey); band: a band given by its energy and width; ion: the transition-metal ion `ion` on the cation site `site` (Tanabe–Sugano, tetrahedral or octahedral by the site's neighbours). A reader that does not know a kind skips that centre." },
        "site": { "type": "string", "description": "The host site's label." },
        "energy": { "type": "number", "description": "band: its centre (eV)." },
        "width": { "type": "number", "description": "band: its full width at half maximum (eV)." },
        "name": { "type": "string", "description": "band: its name (Fe²⁺–Ti⁴⁺)." },
        "ion": { "enum": ["Ti³⁺", "V³⁺", "V²⁺", "Fe²⁺", "Co²⁺", "Cu²⁺"], "description": "ion: which one." },
        "strength": { "type": "number", "description": "Optical density at the strongest band, through the thickness looked through." }
      }
    },
    "color": { "type": "string", "pattern": "^#[0-9A-Fa-f]{6}$" },
    "fraction": {
      "description": "An exact coordinate: an integer, a fraction or a decimal, as text (\"0\", \"1/4\", \"-2/3\", \"0.4697\"). A plain JSON number is accepted and read through its decimal form.",
      "oneOf": [
        { "type": "string", "pattern": "^-?[0-9]+(\\.[0-9]+)?(/[0-9]+)?$" },
        { "type": "number" }
      ]
    },
    "cell": {
      "description": "Lengths in ångström for a crystal (any unit for a tiling, a = 1 usually), angles in degrees. Only the parameters the crystal system leaves free are needed; the others follow from the group (a cubic cell needs a alone).",
      "type": "object",
      "required": ["a"],
      "properties": {
        "a": { "type": "number", "exclusiveMinimum": 0 },
        "b": { "type": "number", "exclusiveMinimum": 0 },
        "c": { "type": "number", "exclusiveMinimum": 0 },
        "alpha": { "type": "number" },
        "beta": { "type": "number" },
        "gamma": { "type": "number" }
      }
    },
    "site": {
      "description": "One site of the asymmetric unit; its orbit under the group gives every copy in the cell.",
      "type": "object",
      "required": ["label", "position"],
      "properties": {
        "label": { "type": "string", "description": "Unique within the document." },
        "element": { "type": "string", "description": "Crystals: the chemical symbol (\"Na\", \"O\")." },
        "color": { "$ref": "#/$defs/color", "description": "Tilings: the motif's colour." },
        "position": {
          "description": "Fractional coordinates: three for a crystal, two for a tiling.",
          "type": "array", "minItems": 2, "maxItems": 3, "items": { "$ref": "#/$defs/fraction" }
        },
        "shape": { "enum": ["circle", "triangle", "square", "diamond", "pentagon", "hexagon", "star", "arrow"], "description": "Tilings: the motif is this shape (default: a dot)." },
        "glyph": { "type": "string", "description": "Tilings: the motif is this character or emoji." },
        "image": { "type": "string", "contentEncoding": "base64", "contentMediaType": "image/png", "description": "Tilings: the motif is this picture." },
        "size": { "type": "number", "exclusiveMinimum": 0, "description": "Tilings: the motif's height in units of the cell edge a." },
        "rotation": { "type": "number", "description": "Tilings: the motif's turn in degrees, anticlockwise." },
        "occupancy": {
          "description": "Crystals: a site shared by several elements (an alloy, a solid solution), each with its fraction, or one element on part of its sites (fractions under 1: vacancies). The fractions add up to 1 at most; `element` stays the main occupant. Absent: `element` fills the site.",
          "type": "array", "minItems": 1,
          "items": {
            "type": "object", "required": ["element", "fraction"], "additionalProperties": false,
            "properties": {
              "element": { "type": "string", "description": "Chemical symbol." },
              "fraction": { "type": "number", "minimum": 0, "maximum": 1 }
            }
          }
        }
      }
    },
    "stroke": {
      "type": "object",
      "required": ["color", "width", "points"],
      "properties": {
        "color": { "$ref": "#/$defs/color" },
        "width": { "type": "number", "exclusiveMinimum": 0, "description": "In points at the default zoom (a cell about 175 points wide)." },
        "style": { "enum": ["solid", "dashed", "dotted", "powder"], "description": "How the line is drawn; absent is solid. Powder: coloured sand poured along the line, its grains scattered on either side (seeded by the points, so the same at every opening)." },
        "spread": { "type": "number", "exclusiveMinimum": 0, "description": "Powder only: the fall radius of the grains, in line widths (default 2)." },
        "points": {
          "description": "Fractional coordinates of the polyline's vertices.",
          "type": "array", "items": { "type": "array", "minItems": 2, "maxItems": 2, "items": { "type": "number" } }
        }
      }
    },
    "quasicrystal": {
      "type": "object",
      "required": ["tiling", "offsets", "method", "generations"],
      "properties": {
        "tiling": { "enum": ["penrose", "ammannBeenker", "dodecagonal"] },
        "offsets": { "description": "One offset per grid of de Bruijn's construction; moving them is a phason.", "type": "array", "items": { "type": "number" } },
        "method": { "enum": ["grids", "inflation"], "description": "\"inflation\": Penrose only, by Robinson triangles." },
        "generations": { "type": "integer", "minimum": 0, "description": "Inflation steps." },
        "pointSet": {
          "description": "When present, the document shows this point set instead of the tiling: the k-free points of a lattice (k = 1: the visible points).",
          "type": "object",
          "required": ["lattice"],
          "properties": {
            "lattice": { "enum": ["square", "triangular"] },
            "power": { "type": "integer", "minimum": 1, "default": 1 }
          }
        },
        "tiles": {
          "description": "The look of each kind of tile, keyed by its acute angle in degrees (\"36\" and \"72\" for Penrose, \"45\" and \"90\" for Ammann-Beenker, \"30\", \"60\" and \"90\" for the dodecagonal tiling). Lines and motifs are given in the tile's own coordinates (s, t): the point origin + s·(first edge) + t·(second edge), (0, 0) to (1, 1) covering the tile. The origin is, for Penrose, the corner the matching rules single out (index 1 or 4 of the pentagrid, corner C of the Robinson triangles), otherwise an acute corner; the edges are taken anticlockwise. Every tile of the kind carries the decoration turned with it.",
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "properties": {
              "color": { "$ref": "#/$defs/color" },
              "strokes": { "type": "array", "items": { "$ref": "#/$defs/stroke" }, "description": "Lines in tile coordinates; their width is a fraction of the edge length." },
              "motifs": { "type": "array", "items": { "$ref": "#/$defs/site" }, "description": "Motifs (shape, glyph or image) at position [\"s\", \"t\"]; size as a fraction of the edge length, rotation in degrees from the tile's first edge." }
            }
          }
        },
        "edgeColor": { "$ref": "#/$defs/color", "description": "The colour of the edges between tiles." },
        "edgeWidth": { "type": "number", "minimum": 0, "description": "The width of the edges in points; 0 hides them." }
      }
    },
    "backdrop": {
      "description": "Tilings: a photograph under the pattern, to find the group of a real pattern.",
      "type": "object",
      "required": ["image", "x", "y", "width", "rotation", "opacity"],
      "properties": {
        "image": { "type": "string", "contentEncoding": "base64", "contentMediaType": "image/jpeg" },
        "x": { "type": "number", "description": "Centre, in units of the cell edge a." },
        "y": { "type": "number" },
        "width": { "type": "number", "exclusiveMinimum": 0 },
        "rotation": { "type": "number", "description": "Degrees." },
        "opacity": { "type": "number", "minimum": 0, "maximum": 1 }
      }
    },
    "view": {
      "description": "A view of a crystal saved for a presentation.",
      "type": "object",
      "required": ["name", "right", "up", "toward", "zoom", "perspective", "show", "cells"],
      "properties": {
        "name": { "type": "string" },
        "right": { "$ref": "#/$defs/vector3" },
        "up": { "$ref": "#/$defs/vector3" },
        "toward": { "$ref": "#/$defs/vector3" },
        "zoom": { "type": "number" },
        "perspective": { "type": "boolean" },
        "show": { "type": "array", "items": { "enum": ["bonds", "axes", "planes", "centres", "tables", "stereogram", "fill", "powder", "laue", "laue-back", "stubs", "bands"] } },
        "cells": { "type": "integer", "minimum": 1 }
      }
    },
    "hkl": { "type": "array", "minItems": 3, "maxItems": 3, "items": { "type": "integer" } },
    "vector3": { "type": "array", "minItems": 3, "maxItems": 3, "items": { "type": "number" } },
    "exercise": {
      "description": "Steps for the Tutor: the app checks each one against the document as it stands.",
      "type": "object",
      "required": ["steps"],
      "properties": {
        "hide": { "type": "array", "items": { "enum": ["group", "elements", "diffraction"] } },
        "audience": { "type": "array", "items": { "enum": ["design", "teaching", "science"] }, "description": "For whom, as the uses of the app; everyone when absent." },
        "theme": { "enum": ["first-steps", "plane-groups", "friezes", "rosettes", "quasicrystals", "lattices", "space-groups", "wyckoff", "structures", "diffraction", "powder", "bands"], "description": "The theme the exercise is shelved under." },
        "steps": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["prompt", "check"],
            "properties": {
              "prompt": { "type": "string" },
              "hints": { "type": "array", "items": { "type": "string" } },
              "solution": { "type": "string", "description": "The worked answer, shown once the step is right or the hints are spent." },
              "check": {
                "type": "object",
                "required": ["kind"],
                "oneOf": [
                  { "properties": { "kind": { "const": "siteOnWyckoff" }, "element": { "type": "string" }, "wyckoff": { "type": "string" } }, "required": ["wyckoff"] },
                  { "properties": { "kind": { "const": "atomsInCell" }, "count": { "type": "integer" } }, "required": ["count"] },
                  { "properties": { "kind": { "const": "multiplicity" }, "wyckoff": { "type": "string" } }, "required": ["wyckoff"] },
                  { "properties": { "kind": { "const": "group" }, "answer": { "type": "string", "description": "Ignored: the answer is the document's own group (kept for files written by Laue 1.0)." } } },
                  { "properties": { "kind": { "const": "siteSymmetry" }, "site": { "type": "string" } }, "required": ["site"] },
                  { "properties": { "kind": { "const": "atomCount" } }, "description": "Typed: the atoms in the cell, computed." },
                  { "properties": { "kind": { "const": "rotationOrder" } }, "description": "Typed: the highest rotation of the pattern, or of a quasicrystal's diffraction." },
                  { "properties": { "kind": { "const": "tileRatio" } }, "description": "Typed: the limit ratio of the two tiles of a quasicrystal (φ, √2)." },
                  { "properties": { "kind": { "const": "density" } }, "description": "Typed: the density of a point set, 1/ζ(2k)." },
                  { "properties": { "kind": { "const": "crystalClass" } }, "description": "Typed: the point group of the document's group (Hermann–Mauguin)." },
                  { "properties": { "kind": { "const": "laueClass" } }, "description": "Typed: the crystal class with the inversion added." },
                  { "properties": { "kind": { "const": "formulaUnits" } }, "description": "Typed: Z, the formula units per cell." },
                  { "properties": { "kind": { "const": "crystalDensity" } }, "description": "Typed: the density in g/cm³, within 1 %." },
                  { "properties": { "kind": { "const": "dSpacing" }, "hkl": { "$ref": "#/$defs/hkl" } }, "required": ["hkl"], "description": "Typed: d of the planes (h k l) in Å, within 0.5 %." },
                  { "properties": { "kind": { "const": "twoTheta" }, "hkl": { "$ref": "#/$defs/hkl" } }, "required": ["hkl"], "description": "Typed: 2θ of the line with Cu Kα₁ (1.54056 Å), within 0.05°." },
                  { "properties": { "kind": { "const": "lineMultiplicity" }, "hkl": { "$ref": "#/$defs/hkl" } }, "required": ["hkl"], "description": "Typed: the reflections present in the powder line of h k l." },
                  { "properties": { "kind": { "const": "firstLines" }, "count": { "type": "integer" } }, "required": ["count"], "description": "Typed: the indices of the first lines of the powder pattern, in order (any equivalent indices)." },
                  { "properties": { "kind": { "const": "coordination" }, "site": { "type": "string" } }, "required": ["site"], "description": "Typed: the atoms within 10 % of the shortest distance from the site." },
                  { "properties": { "kind": { "const": "laueSymmetry" }, "beam": { "$ref": "#/$defs/hkl" } }, "required": ["beam"], "description": "Typed: the symmetry of the Laue pattern, the beam along [u v w] — the operations of the Laue class that leave the beam in place." },
                  { "properties": { "kind": { "const": "laueDeviation" }, "radius": { "type": "number" }, "distance": { "type": "number" } }, "required": ["radius", "distance"], "description": "Typed: 2θ of a spot `radius` mm from the centre of a film `distance` mm behind the crystal, tan 2θ = r/D, within 0.2°." },
                  { "properties": { "kind": { "const": "laueNormal" }, "beam": { "$ref": "#/$defs/hkl" }, "spot": { "type": "array", "minItems": 2, "maxItems": 2, "items": { "type": "number" } }, "distance": { "type": "number" } }, "required": ["beam", "spot", "distance"], "description": "Typed: the planes h k l that make the spot at (x, y) mm, the beam along [u v w], the film `distance` mm behind; any multiple of h k l." },
                  { "properties": { "kind": { "const": "valenceElectrons" } }, "description": "Typed: the valence electrons per primitive cell, as the band model counts them." },
                  { "properties": { "kind": { "const": "bandGap" } }, "description": "Typed: the gap in eV, read on the bands the viewer shows first, within 0.05 eV or 3 %; 0 for a metal." },
                  { "properties": { "kind": { "const": "gapPlaces" } }, "description": "Typed: where the top of the valence bands and the bottom of the conduction bands lie — each a point (Γ, X, L…) or the line it lies on (Δ, Λ…)." },
                  { "properties": { "kind": { "const": "edgeWavelength" }, "gap": { "type": "number" } }, "required": ["gap"], "description": "Typed: the wavelength in nm from which a crystal with a gap of `gap` eV absorbs, λ = hc/E_g, within 1 %." },
                  { "properties": { "kind": { "const": "opticAxes" } }, "description": "Typed: the optic axes of the crystal — 0 (cubic), 1 (tetragonal, trigonal, hexagonal), 2 (lower)." }
                ]
              }
            }
          }
        }
      }
    },
    "magnetism": {
      "description": "Crystals: spins on some sites, the order of their directions and the exchange couplings shell by shell. H = −Σ_{i<j} J S_i·S_j − Σ g μ_B B·S_i − D Σ (S·m̂)²; J > 0 favours parallel spins; couplings in meV.",
      "type": "object", "required": ["moments", "k", "couplings"], "additionalProperties": false,
      "properties": {
        "moments": {
          "type": "array",
          "items": {
            "type": "object", "required": ["site", "spin", "g", "up"], "additionalProperties": false,
            "properties": {
              "site": { "type": "string", "description": "The site's label." },
              "spin": { "type": "number", "description": "The spin S (an effective one for the itinerant metals)." },
              "g": { "type": "number" },
              "up": { "type": "boolean", "description": "The site's direction in the reference cell." },
              "signs": { "type": "array", "items": { "enum": [1, -1] }, "description": "Signs of the site's copies in the order of its orbit, when they differ within the cell (Cr₂O₃)." }
            }
          }
        },
        "k": { "type": "array", "items": { "enum": [0, 1, 2] }, "minItems": 3, "maxItems": 3, "description": "Propagation vector in halves of the reciprocal axes: 0, 1 (½) or 2 (1)." },
        "couplings": { "type": "array", "items": { "type": "number" }, "description": "J of each shell of magnetic neighbours, nearest first (meV)." },
        "direction": { "type": "array", "items": { "type": "number" }, "minItems": 3, "maxItems": 3, "description": "The moments' direction, cell axes [u, v, w]." },
        "field": { "type": "number", "description": "An applied field (tesla), along the moments." },
        "source": { "type": "string", "description": "Where the couplings come from." },
        "measured": { "type": "number", "description": "The measured ordering temperature (K)." },
        "anisotropy": { "type": "number", "description": "Easy-axis single-ion anisotropy D (meV)." }
      }
    },
    "checks": {
      "description": "Expected values, verified by Laue's test suite and command-line tool (laue check).",
      "type": "object",
      "properties": {
        "multiplicities": { "type": "object", "additionalProperties": { "type": "integer" } },
        "siteSymmetries": { "type": "object", "additionalProperties": { "type": "string" } },
        "atomsInCell": { "type": "integer" },
        "distances": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["from", "to", "angstrom"],
            "properties": {
              "from": { "type": "string" },
              "to": { "type": "string" },
              "angstrom": { "type": "number" },
              "tolerance": { "type": "number" }
            }
          }
        }
      }
    },
    "powder": {
      "description": "Crystals: a measured powder pattern, and the profile of its last fit (Laue 1.1).",
      "type": "object",
      "required": ["name", "radiation", "wavelength", "pattern"],
      "properties": {
        "name": { "type": "string", "description": "The file it was read from." },
        "radiation": { "enum": ["xray", "neutron"] },
        "wavelength": { "type": "number", "exclusiveMinimum": 0, "description": "Ångström." },
        "pattern": {
          "type": "object",
          "required": ["twoTheta", "intensity"],
          "properties": {
            "twoTheta": { "type": "array", "items": { "type": "number" }, "description": "Degrees, increasing." },
            "intensity": { "type": "array", "items": { "type": "number" } },
            "sigma": { "type": "array", "items": { "type": "number" } }
          }
        },
        "profile": {
          "type": "object",
          "description": "scale, zero shift (degrees), Chebyshev background, Caglioti u, v, w, pseudo-Voigt mixing eta, and the free cell parameters.",
          "properties": {
            "scale": { "type": "number" }, "zero": { "type": "number" },
            "background": { "type": "array", "items": { "type": "number" } },
            "u": { "type": "number" }, "v": { "type": "number" }, "w": { "type": "number" }, "eta": { "type": "number" },
            "cell": { "type": "object", "additionalProperties": { "type": "number" } }
          }
        }
      }
    },
    "texts": {
      "type": "object",
      "properties": {
        "title": { "type": "string" },
        "summary": { "type": "string" },
        "steps": {
          "type": "array",
          "items": { "type": "object", "properties": { "prompt": { "type": "string" }, "hints": { "type": "array", "items": { "type": "string" } }, "solution": { "type": "string" } } }
        }
      }
    }
  }
}
