r"""
Generates Janev cross section in LXCat format (understandable by Bolsig+).
==========================================================================

Janev cross sections informations can be found in [Janev2002]_ and [Janev2004]_.
They have been digitized and stored in JSON files, in `./data/kin/janev_cross_section_parameters`.
"""  # noqa: D205

import numpy as np

from rizer import __version__
from rizer.io.generate_janev_cross_section import JanevCrossSection
from rizer.misc.utils import get_path_to_data

# Compute the cross sections.
janev_cross_section = JanevCrossSection(
    energy_min=1e-4, energy_max=1e3, number_of_points=1000
)
janev_cross_section.load_all_cross_sections()

# Update the header for lxcat format.
janev_cross_section.LX.header += """
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
DATABASE:      Janev cross sections for CxHy, 0 <= x <= 3, 0 <= y <= 8.
REFERENCES:
.. [Janev2002] R. K. Janev, D. Reiter; Collision processes of CHy and CHy+ hydrocarbons with plasma
electrons and protons. Phys. Plasmas 1 September 2002; 9 (9): 4071-4081. `doi:10.1063/1.1500735 <https://doi.org/10.1063/1.1500735>`_
.. [Janev2004] R. K. Janev, D. Reiter; Collision processes of C2,3Hy and C2,3Hy+ hydrocarbons with
electrons and protons. Phys. Plasmas 1 February 2004; 11 (2): 780-829. `doi:10.1063/1.1630794 <https://doi.org/10.1063/1.1630794>`_
SCRIPT:        rizer/io/generate_janev_cross_section.py (on {0})
"""

janev_cross_section.LX.header += f"Rizer version:       {__version__}\n"
janev_cross_section.LX.header += (
    f"Min energy:    {np.min(janev_cross_section._energies)} eV\n"
)
janev_cross_section.LX.header += (
    f"Max energy:    {np.max(janev_cross_section._energies)} eV\n"
)
janev_cross_section.LX.header += (
    f"Number of points: {len(janev_cross_section._energies)}\n"
)
janev_cross_section.LX.header += """
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

------------------------------------------------------------"""

# Note: C is not included in Janev's cross sections.
C_neutral_species = ["CH", "CH2", "CH3", "CH4"]
C_ion_species = [f"{species}^+" for species in C_neutral_species]
# Note: C2 is not included in Janev's cross sections.
C2_neutral_species = ["C2H", "C2H2", "C2H3", "C2H4", "C2H5", "C2H6"]
C2_ion_species = [f"{species}^+" for species in C2_neutral_species] + ["C2^+"]

# Export cross sections for specific species only.
for species in C_neutral_species + C_ion_species + C2_neutral_species + C2_ion_species:
    cross_sections_path = get_path_to_data(
        f"kin/cross_section/{species}/janev_cross_sections_{species}.txt",
        force_return=True,
    )
    janev_cross_section.LX.export(
        file_name=cross_sections_path,
        overwrite=True,
        species_names=[species],
    )
