# Atomic

# Atomic

Package `@ferret/physics-atomic`, capability `atomic`.

## What it is for

A hydrogen atom whose electron goes round by itself; a red photon sent at it that is taken or passes by; an electron that falls back and gives off a photon of the right colour; a uranium nucleus that takes a neutron and splits; two hydrogens docked into H₂ and two hydrogens and an oxygen into water at the right angle. It is the physics under the `.fmdl` atom models: the models carry the numbers (mass, charge, binding energy), this capability moves them.

## The ideas

- **True values, drawn bigger.** Everything inside is SI (metres, joules, kilograms). The scene sees them multiplied by `drawn` (scene metres per true metre; set it from the model's `scale.drawn`).
- **The planetary atom with the Bohr rule.** An electron goes round on a circle of quantum number *n* at the energy *Eₙ = −Ry·(μ/mₑ)·Z²/n²* (μ the reduced mass). Exact for one electron round a nucleus (H, He⁺ ...). For atoms with more electrons each shell feels the nuclear charge less the screening of the others (Slater's rules): the usual approximation, and only that. Shell *n* holds 2n² electrons; a jump needs a place to land.
- **Lines.** A photon is taken when its energy matches a transition within `tolerance` (a fraction, 2·10⁻³ by default: wider than the natural line so that "656 nm" lifts the 2 → 3 line at 656.47 nm). A photon too strong for the level frees the electron, which then moves under the Coulomb forces of the ion (velocity Verlet, a grid with a cut-off). A photon that matches nothing passes. A photon of 656 nm does nothing to a hydrogen atom in the ground state: only an excited one has that line.
- **Falling.** An excited electron falls by itself at the rate the hydrogen wave functions give (`einsteinA`: 2p → 1s is 6.265·10⁸ per second), to a lower level that has room, and gives off a photon with exactly the energy difference; its colour follows from the wavelength.
- **Two clocks.** The true ratio of an orbit (10⁻¹⁶ s) to a lifetime (10⁻⁹ s) is 10⁷, which no picture can show. `orbitClock` (true seconds per scene second, 10⁻¹⁶: the ground orbit of hydrogen takes 1.5 s) drives orbits and free charges; `decayClock` (10⁻⁹) drives spontaneous emission.
- **Nuclei.** Atomic masses are tabled (AME2020); the binding energy is worked out from them (He-4 28.30, C-12 92.16, U-235 1783.9 MeV). A neutron fired at U-235 does what the cross sections say (fission 85.6 %, capture 14.4 %), or what `outcome` forces. Fission gives Ba-141, Kr-92 and three neutrons; the energy is the rest mass lost (173.3 MeV), shared out as kinetic energy with momentum conserved; the electrons go with the fragments in proportion to their charges. Capture makes U-236 and a gamma ray of 6.5 MeV.
- **Bonds.** Docked atoms make a bond of the tabled length and energy (H–H 74.1 pm, 4.52 eV; O–H 95.8 pm, 4.8 eV; C–H, N–H) and are placed in the molecule's shape: water 104.45°, ammonia 107.8°, methane 109.47°. A pair with no data, or an atom with no valence left, is refused. Heat given to a molecule adds up; the weakest bond breaks when it holds what the bond holds.
- **One energy account.** `atomic.energy` sums the rest and bound energy of nuclei and electrons, photons, neutrons, free charges (with their Coulomb energy), bonds, heat and what has flown away. A photon or neutron sent in, a level set by hand, a bond pulled apart: all booked as `external`. *total − external* stays where it started through every transition, ionisation, fission and bond.

## Using it

```ts
import { PhysicsHost } from '@ferret/physics';
import { atomic } from '@ferret/physics-atomic';

const cap = atomic({ seed: 1, drawn: 1e10 });
const host = world.addService(new PhysicsHost({ capabilities: [cap] }));
host.enable('atomic');

cap.addAtom('h', { nuclide: 'H-1', position: [0, 0, 0] });
cap.excite('h', 0, 2);                                  // the level n = 2, the energy booked as external
cap.firePhoton({ toward: 'h', nm: 656 });               // Balmer alpha: 2 -> 3
world.run(10);
world.events.on('atomic:emission', e => console.log(e.nm));   // 656.5 when it falls back
```

The nucleus's mass and the binding energy come from the `.fmdl` packages; the tables here are the same physics seen from the other side, and the tests keep them equal (the mass of helium-4 the packer writes is the one `nuclearMass` gives).

## Values

| Value | Default | Meaning |
|---|---|---|
| `orbitClock` | 1e-16 | true seconds per scene second for orbits and free charges |
| `decayClock` | 1e-9 | true seconds per scene second for spontaneous emission |
| `photonSpeed` | 3 | scene metres per second a photon flies at (light, slowed so it can be seen); heavy products of a fission keep their ratio to *c* |
| `tolerance` | 2e-3 | how far a photon may be off a line, as a fraction |
| `captureMargin` | 1.5 | the radius a photon meets an atom at, in outer-orbit radii |
| `cutoff` | 1e-8 | Coulomb cut-off for free charges, m |
| `range` | 12 | how far a photon flies on past the atom it was aimed at, scene m |

## Events and commands

Events on the world's bus: `atomic:transition` { atom, electron, from, to, energy, nm, cause }, `atomic:emission`, `atomic:absorption`, `atomic:ionization`, `atomic:fission` { nucleus, products, neutrons, Q }, `atomic:capture`, `atomic:bond`, `atomic:bond-break`.

Commands: `atomic.info`, `atomic.add`, `atomic.atom`, `atomic.excite`, `atomic.firePhoton`, `atomic.fireNeutron`, `atomic.dock`, `atomic.undock`, `atomic.heat`, `atomic.energy`, `atomic.lines`, `atomic.binding`. Programs of the motion language may call them (`atomic.` is on the allow list) and, with `atomicForms(bridge, cap, host)`, use `(fire-photon atom nm)`, `(fire-neutron atom mev)`, `(excite atom n)`, `(wait-emission atom)` (lasts until the atom gives off a photon; the value is its wavelength) and `(line n m)`. `(dock a b)` and `(undock a)` are words of `@ferret/levels` (`installDockForms`, docs/fmdl/SPEC.md 6.3); `atomicDocks(cap)` is the backend that bonds the atoms they dock.

## What this model is not

Hydrogen-like atoms are exact; many-electron atoms are screened-hydrogenic (their level energies are not the measured ionisation energies). Only transitions between levels, with every sublevel equally occupied, are modelled (no fine structure, no selection rules beyond the radial rates). One fission channel (Ba-141 + Kr-92 + 3n) is tabled; the neutrons carry 2 MeV each on average. Nuclides without a tabled mass are refused by name.

## Orbitals, X-rays, many nuclei, the chain reaction

These were added for the teaching lab (`examples/education`), all pure functions or classes that need no scene:

- **Orbitals.** `hydrogenicRadial(n, l, Z, r)`, `realHarmonic(l, m, theta, phi)` and `sampleOrbital(n, l, m, Z, count, seed)` give the point clouds of the s, p, d and f shapes; `sommerfeldOrbit` and `orbitPoint` give the elliptic orbit of a state, for the planetary picture. `mulberry(seed)` is the seeded random source.
- **X-rays.** `kleinNishina`, `kleinNishinaTotal` and `sampleComptonAngle` for the Compton scatter; `fillVacancy` (a hole in an inner shell is filled by a line photon or by an Auger electron, with the fluorescence yield); `sampleBremsstrahlung(kV, rand)` for the continuous spectrum of a tube. The photoelectric cross section follows the empirical law σ = 1.67·10⁻²³·Z^4.26/E³ cm² (E in keV).
- **Many nuclei.** `NucleiPopulation` keeps a count of each nuclide, one exponential decay moment per nucleus in a min-heap, the daughters and the energy sum, so a decay chain and a half-life can be watched to the nucleus.
- **The chain reaction.** `ChainReaction` is a bare ball of fissile material with neutrons flying: capture, fission, leak. `kTheory` and the critical radius (found by bisection) are reported with the counts; a ball under the critical radius dies out, over it the reaction runs away.

## Tests

`packages/physics-atomic/test/atomic.test.ts` checks the laws, not numbers seen once: the Balmer, Lyman and Paschen wavelengths, the Rydberg formula with the reduced mass, the Bohr rule on every orbit, the Einstein rates (Lyman α 6.265·10⁸ per second; H α; the Z⁴ scaling), binding energies from the mass tables, the Coulomb force at the Bohr radius and the grid against the brute force, energy conserved through emission, absorption, ionisation, fission and bonds, momentum through fission, the decay law of 400 seeded atoms, determinism by seed, and the water angle.

## Atoms from models

A `.fmdl` model that stands for an atom has `physics.modules.atom = { nuclide: "H-1" }` (or `Z`, `A`, `electrons`). `bindAtomModels(world.events, stage, cap)` makes the atom of the capability when the actor appears (`fmdl:appear`) at its place, under the actor's name, and removes it when the actor vanishes; an isotope is a child model that replaces the entry. See docs/fmdl/SPEC.md 9.1.
