# Crystal & Diffraction Lab 1.0 — scientific basis and independent AI review

This is a generic educational workbench for ideal cubic structure prototypes. It
is not a calibrated diffractometer, experimental image generator, CIF parser or
refinement package. All basis sites have equal, real scalar scattering weight
f=1. Default a=4 angstrom and lambda=1.5406 angstrom are independent illustrative
settings, not a fitted material or a simulation of the Cu K-alpha doublet.

## Coordinates and structure

The incident wavevector is (0,0,+1/lambda). We use inverse angstrom without a
2pi factor: g=R(h,k,l)/a and g=k_out-k_in. The Ewald sphere is centered at -k_in
with radius 1/lambda. R=Rz Ry Rx acts on column vectors; positive detector X points
right and Y points up. The phase convention is exp(+2pi i u dot b).

The unique conventional-cell fractional basis lies in [0,1): SC has 1 site,
BCC 2, FCC 4, diamond 8. Diamond is an FCC Bravais lattice plus a basis, not a
fourth Bravais lattice. Boundary copies in the displayed cell are excluded from
scattering sums. Miller plane polygons satisfy h*x+k*y+l*z=m for integer m in
fractional cell coordinates. Atom radii, connectors, shading and mechanical
hardware are illustrative. Structure close-up and instrument atomic models have
separate display magnification. The 3D detector face nevertheless preserves its
width/distance ratio: 6.2 display units represents 200 mm and the face lies at
z=.031*L from the sample, so predicted rays meet the same detector coordinates.

The reciprocal view draws conventional-cell integer hkl candidate index points
in -3..3; the selected hkl is shown separately. Centering/basis cancellations
are not all nonzero reciprocal scattering nodes. Extinct candidates are hidden
by default and can be shown in gray.

## Elastic single-crystal detector

For each pixel center r=(X,Y,L), k_out=r/(|r|*lambda). Thus every outgoing ray is
elastic. u=a*R-transpose*(k_out-k_in) enters the continuous basis structure factor
F(u)=sum_j exp(2pi i u dot b_j). A finite N-by-N-by-N block of conventional cells
has amplitude F(u) times product over axes of sum_n=0..N-1 exp(2pi i n*u_axis).
The full geometric sum is used, with the integer limit N squared for its squared
magnitude. Intensity is divided by N^6 and the squared basis-site count. No
integer-only extinction shortcut, random spots, arbitrary excitation envelope
or isolated sinc approximation is substituted for this computation.

The detector covers 200-by-200 mm on a forward plane. Its central beamstop has
radius 2 mm. Bragg reachability (lambda*|g| <= 2) does not guarantee acceptance:
k_out.z must be positive and both intersection coordinates must lie within
+/-100 mm. For a=4,lambda=1.5406,400 is backward, though it satisfies Bragg.
The image uses pixel-center sampling and log contrast, not pixel-area integration.
Polarization, pixel solid angle, efficiency, absorption, thermal effects and
multiple/dynamical scattering are omitted. Values are relative point-scatterer
intensities, never experimental photon counts.

A worker computes from an immutable parameter snapshot. During updates the UI
identifies the previous calculated frame; synchronization is declared only after
the latest queued request completes. Interrupting an orientation animation commits
the exact final angle snapshot before declaring synchronization.

## Ideal random powder

All signed/permuted integer reciprocal candidates within the 8..120 degree 2theta
range are enumerated. Allowed |F_hkl|^2 values are summed into equal-d shells;
this already includes multiplicity. The common unpolarized random-powder LP
convention (1+cos^2(2theta))/(sin^2(theta)*cos(theta)) is applied, independently
of the single-crystal detector model. No second multiplicity correction is used.

Equal-d shells can contain distinct families: SC h^2+k^2+l^2=9 combines {300}
and {221}, with total shell multiplicity 30. JSON includes the full family list;
CSV explicitly labels representative h/k/l and shell_multiplicity. Individual
reflection families must not be assigned that combined multiplicity.

A separate constant FWHM Gaussian is area-normalized in degrees on the 2theta
axis. Displayed 1D curves are rescaled to their peak height, and detector colors
use the single highest-weight Gaussian peak height as reference before log
contrast. Powder rings are generated from exactly the same angular profile,
using 2theta=atan2(sqrt(X^2+Y^2),L). Powder rotation is statistically averaged;
single-crystal angles and N do not enter it. FWHM is not a Scherrer size estimate
and is not derived from the finite single-crystal N.

## Reference checks

1. IUCr, The reciprocal lattice — Ewald and Bragg construction:
   https://www.iucr.org/what-we-do/education/pamphlets/reciprocal-lattice
2. IUCr, Structure factor — complex basis sum:
   https://dictionary.iucr.org/Structure_factor
3. CCP4-ED, Compounds — centered and diamond basis examples:
   https://www.ccp4.ac.uk/ccp4-ed/misc/compounds/
   The diamond index-sum rule requires the FCC parity condition; 211 is extinct.
4. Official pymatgen XRDCalculator documentation — reciprocal enumeration,
   multiplicity and LP convention:
   https://pymatgen.org/pymatgen.analysis.diffraction.html
   Unlike that quantitative calculator, this workbench deliberately uses f=1
   rather than element-dependent atomic form factors.

## Independent AI review and numerical evidence

An independent AI reviewer checked the scientific design and implementation
against independent direct finite-crystal complex sums and reference numbers.
Baseline a=4 angstrom, lambda=1.5406 angstrom:
- 111: d=2.3094010767585034 angstrom, 2theta=38.96873821328758 degrees.
- Aligned 111 g=(.4082151565332153,0,-.14443125) inverse angstrom;
  k_out.z=.5046665041217708 and X/L=.8088810198402174.
- Aligned 400: k_out.z=-.12120224587822925; no forward detector projection.
- F^2 at continuous u=(.5,0,0): SC1, BCC2, FCC8, diamond27.313708498984766.
- Diamond 200/211/222 are extinct; 111 has F^2=32,220 has F^2=64.

The reviewer identified a missing endpoint on a cube-boundary Miller polygon.
A failing four-corner regression reproduced it; collecting both edge endpoints
corrected it. The reviewer also identified an orientation-interruption frame
synchronization gap. A browser regression reproduced up to about two degrees of
stale detector orientation; submitting the final snapshot corrected it to zero.
Ten scientific regression tests now cover Bragg limits, cubic geometry,
centering and diamond absences, continuous structure factors, independent direct
finite-block sums, Friedel symmetry, powder multiplicity, independent line weights,
forward/backward acceptance, complete cube faces and Gaussian integrated area.

Model SHA256 at review: `af3bfa6845b97dbb49fb09f247866d00ccdf119202ced4b7b3d33c784baff915`.
Final independent review closure and browser/release evidence are recorded in
VALIDATION.md. Independent AI review is not certification by a crystallography
expert; the declared model omissions remain applicable.
