oqp.utils.dftb_trace

Parse and pretty-print openqp-dftb structured native diagnostics.

The openqp-dftb shared library cannot write into the OpenQP log directly (the
log unit belongs to liboqp's Fortran runtime), so the adapter captures the
library's flushed stdout.  At trace level 2 that capture carries one
machine-readable record per SCC/Davidson/Z-vector event
(``openqp_dftb_scc_iter ...``).  This module turns those records into the same
kind of human-readable iteration tables OpenQP prints for its native SCF,
Davidson, and Z-vector solvers, so a DFTB log reads like any other OpenQP log.

Attributes

HARTREE_TO_EV

AU_TO_DEBYE

Functions

parse_native_trace(text)

format_scc_pass(entry)

format_scc_post_update(entry)

format_scc_recoveries(recoveries[, verbose])

format_scc_block(trace[, verbose])

format_scc_summary_lines(trace)

format_davidson_block(solve[, method_display])

format_davidson_summary_line(solve)

collapse_repeats(lines)

format_zvector_block(solve)

format_zvector_dense_block(solve)

format_resolved_options(options)

format_step_timing(step_cpu, step_wall, total_cpu, ...)

format_energy_components(components[, reference_label])

point_charge_dipole(charges, coords_bohr)

format_charge_block(symbols, charges, dipole_au, title)

format_other_lines(trace)

map_spectrum_label(label[, state_prefix])

spectrum_from_ground(spectrum[, state_prefix])

final_energy_header(summary)

final_energy_annotation(summary, index)

final_energy_label(summary, index, default)

format_mo_table(mo)

spin_flip_pair(index, noca, nocb)

format_state_configurations(summary)

format_excited_state_summary(summary)

Module Contents

HARTREE_TO_EV = 27.211386245988
parse_native_trace(text)
Split a captured native stdout into structured events.

Returns a dict with ``scc_passes``, ``post_updates``, ``recoveries``,
``davidson``, ``zvector``, ``zvector_dense``, ``spectrum``, ``warnings``,
and ``other`` (verbatim unrecognized lines, e.g. ``[zvec-stage]`` timing
breakdowns).  The parser is tolerant: an unknown or malformed record line
degrades to ``other`` instead of failing the calculation log.
format_scc_pass(entry)
One OpenQP-style iteration table for a single SCC pass.
format_scc_post_update(entry)
format_scc_recoveries(recoveries, verbose=False)
format_scc_block(trace, verbose=False)
All SCC passes + final residual check + recoveries as one text block.
format_scc_summary_lines(trace)
One line per SCC pass -- used when the reference is merely re-solved.
format_davidson_block(solve, method_display='DFTB')
format_davidson_summary_line(solve)
collapse_repeats(lines)
Merge consecutive identical lines into one line with a repeat count.
format_zvector_block(solve)
format_zvector_dense_block(solve)
AU_TO_DEBYE = 2.541746451895
format_resolved_options(options)
Grouped table of the EFFECTIVE openqp-dftb options after resolution.

The values come from the native openqp_dftb_resolved_options record, so a
named preset (e.g. dtcam-tb) is expanded to its actual published parameter
vector without duplicating those numbers in Python.
format_step_timing(step_cpu, step_wall, total_cpu, total_wall)
The native-OpenQP style per-step + cumulative timing footer.
format_energy_components(components, reference_label='SCC reference')
OpenQP-style 'Energy components' block for the converged reference.

Semantics (from the native emitter): electronic = h0 + scc + spin +
exchange; total = electronic + repulsive; band = sum of occupied
eigenvalues (informational).
point_charge_dipole(charges, coords_bohr)
Dipole vector (a.u.) of net atomic point charges at coords (Bohr).
format_charge_block(symbols, charges, dipole_au, title)
Mulliken charge table + point-charge dipole, OpenQP style.
format_other_lines(trace)
map_spectrum_label(label, state_prefix='S')
Map a printed spectrum label to the public state label.

Closed-shell TDDFTB rows already carry ``S<n>`` labels.  Spin-flip and
MRSF rows are labeled ``root <n>``; within each spin manifold the public
label is zero-based from root 1 (root 1 = S0/T0).
spectrum_from_ground(spectrum, state_prefix='S')
Rows out of the lowest state, keyed by public final-state label.
final_energy_header(summary)
One header line naming the extra Final-Energy columns.
final_energy_annotation(summary, index)
Extra Final-Energy columns (VEE in eV, |mu|, f) for state row ``index``.

Numbers only -- the column names come from :func:`final_energy_header`.
``index`` is the row number in ``mol.energies``: for spin-flip/MRSF runs
row 0 is the internal reference and roots start at row 1; for closed-shell
TDDFTB row 0 is S0 itself.
final_energy_label(summary, index, default)
Public state label for Final-Energy row ``index`` (TDDFTB: S0..Sn).
format_mo_table(mo)
Molecular-orbital table: index, occupation, energies, irrep, markers.
spin_flip_pair(index, noca, nocb)
Map a 1-based spin-flip amplitude index to (occ, vir) MO numbers.

The exported SF/MRSF response vectors are ``amplitudes(noca, n_virt_beta)``
flattened column-major: index = (vir - nocb - 1) * noca + occ, with occ an
alpha-occupied MO (1..noca) and vir a beta-virtual MO (nocb+1..nbf).
format_state_configurations(summary)
AE-style per-state dominant configurations (coeff, OCC -> VIR).
format_excited_state_summary(summary)
The OpenQP-style excited-state summary + state-to-state tables.

``summary`` is the dict the adapter stores on the molecule:
``reference_energy``, ``reference_label``, ``state_labels`` (public),
``state_energies`` (total Hartree per root), ``spin_squares``,
``oscillator`` ({public label: spectrum row}), ``transitions``
(spectrum rows with public labels), ``approximation``.