def sd_norm_head
import bend-prot@0.1.0.0/sim.bend as Simimport Base
import bend-prot@0.1.0.0/geom.bend as G
218# Steepest descent over state (fixed fuel; CLI reports convergedness).
219# Normalized steps (fixed distance along each force) relax clashes that
220# raw F*dt would overshoot; raw forces still feed MD and max-force.
221def sd_norm_head(h: DynAtom, +step: F32) -> DynAtom:
222 match h:
223 case DA{serial, elem, pos, vel, +frc, mass}:
224 +n2 = G.Vec3.norm2(frc)
225 DA{serial, elem, G.Vec3.add(pos, G.Vec3.scale(step, Bool.pick(G.Vec3, F32.is_eq(n2, 0.0), G.V3{0.0, 0.0, 0.0}, G.Vec3.scale((1.0 / F32.sqrt(n2) : F32), frc)))), vel, frc, mass}