"""Generate formula candidates for an observed m/z value."""

import time

import emzed

neutral_mass = emzed.mass.of("C6H12O6")

t0 = time.perf_counter()
candidates = emzed.chemistry.formula_table(
    neutral_mass - 0.01,
    neutral_mass + 0.01,
    c_range=(0, 12),
    h_range=(0, 24),
    n_range=(0, 2),
    o_range=(0, 12),
    p_range=(0, 1),
    s_range=(0, 1),
    apply_rules=False,
)
dt = time.perf_counter() - t0

candidates.add_column(
    "error_ppm",
    1e6 * (candidates.m0 - neutral_mass) / neutral_mass,
    float,
)
candidates = candidates.sort_by("error_ppm")

print(f"neutral mass target: {neutral_mass:.6f}")
print(f"formula fit runtime: {dt:.4f} s")
print()

top = candidates.extract_columns("mf", "m0", "error_ppm")
print(top[:10])
