  Context. On the sun, the magnetic field vector is measured routinely only in
the photosphere. By using these photospheric measurements as boundary
condition, we developed the magnetohydrostatic (MHS) extrapolation to model the
solar atmosphere. The model makes assumption about the relative importance of
magnetic and non-magnetic forces. While the solar corona is force-free, this is
not the case in photosphere and chromosphere.
  Aim. The model has been tested with an exact equilibria in \cite{zw18}. Here
we present a more challenging and realistic test of our model with radiative
MHD simulation of a solar flare.
  Methods. By using the optimization method, the MHS model computes
self-consistently the magnetic field, plasma pressure and density. The
nonlinear force-free field (NLFFF) and gravity stratified atmosphere along the
field line are assumed as the initial condition of the optimization.
  Results. Compared with NLFFF, the MHS model gives an improved magnetic field
not only in magnitude and direction, but also in the magnetic connectivity.
Besides, the MHS model is able to recover the main structure of the plasma in
the photosphere and chromosphere.
