The science: the physics behind the rendering, model by model
The science
Every model in Stochasm is a piece of statistical mechanics, and what unifies them is Boltzmann weighting, realised in two ways. The lattice models, and the bonding layer of Patchy Discs, accept or reject proposed changes by the Metropolis criterion, which passes energy-lowering moves outright and energy-raising ones with Boltzmann-suppressed probability, more readily the hotter the system. The Single Particle, and the disc motion of Patchy Discs, reach the same distribution by Langevin thermostatting instead. A single copy produces one trajectory. An ensemble of thousands produces independent samples of the same distribution, so the phase-space cloud is that distribution, bounded by theoretical envelopes where those are provable.
Every kernel is compiled from C to WebAssembly and runs locally in the browser. In ensemble mode the replicas are distributed across the available CPU cores, so thousands of systems step in real time, at over a hundred million site updates per second on a current multi-core laptop. An automated fidelity suite verifies each kernel against its reference on every build, byte-identically for the lattice models and to machine precision for the continuous ones. The JavaScript engines take over automatically when the compiled core is switched off, when the browser cannot run it, or when a configuration exceeds its fixed capacities.
Multi-Component Lattice
The lattice model runs kinetic Monte Carlo. Each step selects a random site and attempts a random eligible move, a flip or a swap, accepted with probability
P(success) = k · min(1, e−(Ef − Ei)/T)
where k is the rule’s Rate and Ei and Ef are the total energies of the affected sites before and after the move. A site’s energy has two parts, its type’s field plus half the sum of its pairwise interaction energies with the 4 or 8 sites of the chosen coordination shell. The factor of one half follows the original kernel’s convention and avoids double-counting each pair. Fields enter a flip and cancel in a swap, which exchanges two occupied sites.
A flip rule’s facilitation condition is evaluated first. Without the required number of neighbours the move cannot occur at all, which is a kinetic constraint that changes pathways without changing the equilibrium distribution. Swap rules carry no facilitation, but the same kinetic role is played by immobile types, which swaps cannot displace, and by masquerading, which lets one type satisfy another’s facilitation requirement. This combination, thermodynamics from fields and interactions and kinetics from rates and constraints, is why simple palettes produce phase separation, coarsening, glassy arrest and percolation.
In the ensemble, a site-type fraction plotted against same-type bond excess carries provable outer bounds on the accessible region, a phase-separated ceiling and an anti-clustered floor, drawn as amber dashed curves with the forbidden region shaded. Both track the coordination number, the floor lying at −1/4 for the 8-neighbour Moore shell, where the neighbourhood contains triangles, and −1/2 for the 4-neighbour von Neumann shell, where a checkerboard is attainable.
2D Ising
The canonical spin-½ Ising model, two states per site, evolving by single-spin Metropolis flips. The energy is the coupling J between neighbouring spins plus a uniform field H. The coupling is a live control spanning −2 to +2, so the model is ferromagnetic at the default J = 0.3 and antiferromagnetic for J < 0, where Néel ordering appears. Below the critical temperature like spins align into growing domains, and above it thermal noise dominates. The Launcher also draws the mean-field free energy
F(m) = −2Jm² − Hm + T[((1+m)/2)·ln((1+m)/2) + ((1−m)/2)·ln((1−m)/2)]
live as those controls move, so the double well opening below the critical point and closing above it can be read directly. In the ensemble the cloud of magnetisation against same-type bond excess traces the phase diagram, bounded by the theoretical phase-separated and Néel envelopes shown in the figure below.

Single Particle
One particle in a one-dimensional potential, integrated with Langevin dynamics, which combine deterministic forces with friction and thermal noise at temperature T. The potential is either a harmonic trap V(q) = ½ω²q² or a symmetric double well whose barrier height and well separation are set together, with an added linear bias tilting it left or right. With friction γ > 0 the thermostat drives an ensemble of walkers to the Boltzmann distribution of the chosen potential, a Gaussian in a harmonic trap and a two-lobed cloud in a double well. A Thermal start draws the walkers from this distribution directly, in either potential, so the ensemble begins in equilibrium. A Coherent start places them instead in a narrow packet away from equilibrium, from which they relax. At γ = 0 the integrator is purely Hamiltonian, running velocity Verlet with no noise, so energy is conserved and no relaxation occurs. It is the clearest illustration in the app of an ensemble becoming a distribution.
Patchy Discs & Polymers
Off-lattice, and a hybrid of two dynamics. Discs move under Langevin dynamics, with inertia, friction and thermal noise, and repel through soft cores, so packing responds to temperature. Two kinds of attraction are available. A disc–disc rule adds an isotropic Lennard-Jones well between two bead types, handled directly by the molecular dynamics with no bonds involved, which is what drives condensation and demixing. A patch–patch rule adds a Monte-Carlo bonding layer on top. At the rule’s attempt rate a patch proposes to bind an eligible partner, in range and with the cones facing, or to release its current one, accepted by the same Metropolis criterion with a candidate-counting factor. That factor makes formation and breaking exactly reversible for pairs inside the bonding window, and a pair that has drifted outside the window has no reverse path, so its count is clamped and the well still has to be paid for on release. A formed bond is a short harmonic tether, U = ½k·d² − ε, so ε and T alone set how much bonding is present at equilibrium while the attempt rate sets only how quickly that equilibrium is reached. Equilibrium and kinetics are therefore independently adjustable.
A bead type may also be given an irregular shape. Polydispersity draws each particle’s base radius from a clamped Gaussian, and Smoothness below 1 adds a per-particle low-mode random radial profile. An irregular pair then interacts through the usual soft potential evaluated with the local contact distance, the sum of the two surface radii along the line joining the centres. The pair therefore exerts a tangential force and a torque as well as a central force, and patches sit on the true local surface, so bonding geometry follows each particle’s own boundary.
A disc can also be a bead in a permanently bonded chain. The backbone is a harmonic spring on the bead centres, at the same stiffness a patch bond uses and with its rest length at the bead contact distance. Unlike a patch bond, which pulls on off-centre patch points and therefore orients the discs, the backbone spring is central, exerting no torque and carrying no ε well. Stiffness against bending is the standard cosine potential U = κ(1 − cos θ) over consecutive bond vectors. In two dimensions the bond-bond correlation is 〈cos θ〉 = I1(κ/T)/I0(κ/T), so the persistence length approaches 2κ/T bonds in the stiff limit and falls short of that estimate as κ approaches T. At κ = 0 the chain is freely jointed. Neither term acts on orientation, so a bead’s patches remain independent of the backbone, and because the bending energy depends only on an angle it is scale-invariant and contributes exactly nothing to the pressure, which is why chains require no special treatment under NPT.
Which bead sits where along a chain is the molecule’s architecture. It is one species throughout, a diblock, a multiblock, a linear gradient, a random copolymer at a set composition, or a sequence written out bead by bead. The sequence is drawn once when the box is built, before its size is fixed, so every bead is priced at its own radius and the box area matches the drawn composition exactly. The realised packing fraction then lands at or slightly below the target, since whole molecules are dropped rather than shortened, and a mixed-radius design enlarges the box until its beads fit the seeding lattice.
Building that box is a topology problem as much as a packing one. In two dimensions chains cannot pass through one another, so any crossing present at the start persists for the entire run and no amount of simulation will remove it. Stochasm therefore grows each molecule as a self-avoiding walk on a periodic triangular lattice. Distinct edges of a triangulation never intersect and one bead per site excludes overlap, so both guarantees hold by construction rather than by relaxation. Rough or polydisperse beads can reach past the lattice spacing, and their overlaps are then relaxed. When that relaxation would pull one backbone through another, the whole lattice is instead scaled apart until every pair reaches its contact distance, which keeps the box crossing-free at a packing fraction below the target. The same constraint governs insertion into a running box, where there is no lattice to thread. A spawned chain is planned in the continuum with per-step rejection and backtracking, and is committed only if every bead is legal, so a tightly packed box may correctly refuse the insertion. Chain conformations are reported as the radius of gyration 〈Rg〉 and end-to-end distance 〈Re〉, both measured along the unwrapped backbone so a chain crossing the periodic boundary reads the same as one in the interior.
By default the box is fixed, in the NVT ensemble. Under NPT an isothermal-isobaric Martyna–Tobias–Klein barostat couples the box size to an extra degree of freedom driven by the difference between the system’s internal pressure, which is kinetic energy plus the force virial, and the target pressure, damped by a Langevin piston. The box then relaxes until the two pressures balance on average, so the discs reach the density the pressure implies rather than one fixed by hand.
