#!/bin/bash
#
# autopkgtest for python3-denss
#
# Verify that the "denss" command-line entry point runs to completion on
# the upstream sample GNOM .out data (6lyz.out and lysozyme.out).
#
# The reconstructions are kept deliberately tiny (-s 5 steps, -n 16 grid
# points, plotting disabled) so the test stays fast while still exercising
# the full ab-initio reconstruction code path (input parsing, Dmax
# extraction, FFT, iterations and MRC/log output).
set -e

# --- Factorisation des fichiers d'entrée ---
out_files=(6lyz.out lysozyme.out)

cp "${out_files[@]}" "$AUTOPKGTEST_TMP"

# --- Boucle sur les .out via la variable factorisée ---
for f in "${out_files[@]}"; do
    base=${f%.out}
    echo "== denss -f $f =="
    if ! denss -f "$f" -s 5 -n 16 --plot_off --output "$base"; then
        echo "FAIL: denss exited non-zero for $f" >&2
        exit 1
    fi
    # denss must write the electron density map and the log file.
    if [ ! -s "$base.mrc" ] || [ ! -s "$base.log" ]; then
        echo "FAIL: expected outputs ($base.mrc, $base.log) missing for $f" >&2
        exit 1
    fi
    echo "ok: $f -> $base.mrc"
done

echo "autopkgtest: denss -f *.out passed"
