"""Lab to Code — 2026 Nobel Prize in Chemistry (Kagan, Soai): a toy model of non-linear autocatalysis.

Not the real Soai mechanism: a minimal model where the speed depends on the enantiomeric excess,
which is enough to amplify a tiny imbalance until only one "hand" is left.
"""
L, D = 1.001, 1.000           # two mirror forms, 0.1 % apart
K, ALPHA, DT = 0.9, 0.9, 0.01  # base speed, weight of the excess, time step


def ee(l, d):
    """Enantiomeric excess, from -1 (all D) to +1 (all L)."""
    return (l - d) / (l + d)


hist = []
for step in range(4000):
    e = ee(L, D)
    L += K * L * (1 + ALPHA * e) * DT   # the speed depends on the excess: that's the non-linear part
    D += K * D * (1 - ALPHA * e) * DT
    hist.append((step * DT, ee(L, D)))

start, final = hist[0][1], hist[-1][1]
t99 = next(t for t, e in hist if max(e, 0.99) == e)   # first time the excess reaches 99 %
print(f"start ee: {start * 100:.2f} %")
print(f"final ee: {final * 100:.2f} %")
print(f"time to 99 % ee: {t99:.1f} (model units)")
print(f"amplification: {final / start:,.0f}x")
