  We present the new public version of the KETJU supermassive black hole (SMBH)
dynamics module, as implemented into GADGET-4. KETJU adds a small region around
each SMBH where the dynamics of the SMBHs and stellar particles are integrated
using an algorithmically regularised integrator instead of the leapfrog
integrator with gravitational softening used by GADGET-4. This enables
modelling SMBHs as point particles even during close interactions with stellar
particles or other SMBHs, effectively removing the spatial resolution
limitation caused by gravitational softening. KETJU also includes
post-Newtonian corrections, which allows following the dynamics of SMBH
binaries to sub-parsec scales and down to tens of Schwarzschild radii. Systems
with multiple SMBHs are also supported, with the code also including the
leading non-linear cross terms that appear in the post-Newtonian equations for
such systems. We present tests of the code showing that it correctly captures,
at sufficient mass resolution, the sinking driven by dynamical friction and
binary hardening driven by stellar scattering. We also present an example
application demonstrating how the code can be applied to study the dynamics of
SMBHs in mergers of multiple galaxies and the effect they have on the
properties of the surrounding galaxy. We expect that the presented KETJU SMBH
dynamics module can also be straightforwardly incorporated into other codes
similar to GADGET-4, which would allow coupling small-scale SMBH dynamics to
the rich variety of galactic physics models that exist in the literature.
