# Path: utility/getdata.py
# DEFAULT_SETUP = 'getdata_setup.xml'
# class GetData(AccessData):
#     def __init__(self,
#                  data_path_name=None,
#                  data_key=[],
#                  data_format="pandas"):
#     def read_data(self):
#     def read_h5_to_pandas(self):
#     def read_h5_to_array(self):
#     def read_txt_to_str(self):
#     def read_txt_to_array(self):
#     def read_xml(self):
#     def get_data(self):
#     def download_private_data(self):
#     def download_public_data(self):
#     def ensure_dir(file_path):
# 
# Path: crm_solver/neutral_db.py
# class NeutralDB(object):
#     def __init__(self, param=None, components=None, resolved=None):
#         self.param = param
#         self.__set_atomic_resolution(resolved=resolved)
#         self.__load_neutral_cross_section(components=components)
#         self.__get_atomic_levels()
# 
#     def __set_atomic_resolution(self, resolved):
#         projectile = self.param.getroot().find('body').find('beamlet_species').text
#         if resolved is None:
#             if projectile == 'H' or projectile == 'D' or projectile == 'T':
#                 self.resolved = 'bundled_n'
#             elif projectile == 'Li' or projectile == 'Na':
#                 self.resolved = 'nl'
#         else:
#             self.resolved = resolved
# 
#     def __create_neutral_cross_section_db(self, components):
#         self.neutral_cross_sections = {}
#         self.neutral_target_count = len([comp for comp in components['q'] if int(comp) == 0])
#         for index in range(self.neutral_target_count):
#             self.neutral_cross_sections.update({'neutral'+str(index+1): None})
# 
#     def __set_neutral_cross_section_path(self, target='H'):
#         file_name = target + '_' + self.resolved + '_' + \
#                     self.param.getroot().find('body').find('beamlet_energy').text + '.txt'
# 
#         return os.path.join('atomic_data', self.param.getroot().find('body').find('beamlet_species').text,
#                             'cross_sections', 'neutral', file_name)
# 
#     def __identify_neutral_target(self, component):
#         if isinstance(component['Molecule'], str):
#             return component['Molecule']
#         else:
#             if component['Z'] == 1 and component['A'] == 1:
#                 return 'H'
#             elif component['Z'] == 1 and component['A'] == 2:
#                 return 'D'
#             elif component['Z'] == 1 and component['A'] == 3:
#                 return 'T'
#             else:
#                 raise NotImplementedError('The requested atomic gas is not supported yet.')
# 
#     def __load_neutral_cross_section(self, components):
#         self.__create_neutral_cross_section_db(components=components)
#         for index in range(self.neutral_target_count):
#             name = 'neutral'+str(index+1)
#             target = self.__identify_neutral_target(component=components.T[name])
#             path = self.__set_neutral_cross_section_path(target=target)
#             self.neutral_cross_sections[name] = GetData(data_path_name=path, data_format="array").data
# 
#     def __get_atomic_levels(self):
#         for index in range(self.neutral_target_count):
#             atomic_levels = self.neutral_cross_sections['neutral'+str(index+1)].shape[0]
#             if not hasattr(self, 'atomic_level'):
#                 self.atomic_levels = atomic_levels
#             elif self.atomic_levels > atomic_levels:
#                 self.atomic_levels = atomic_levels
# 
#     def get_neutral_impact_loss(self, target, from_level):
#         return uc.convert_from_cm2_to_m2(self.neutral_cross_sections[target][from_level, from_level])
# 
#     def get_neutral_impact_transition(self, target, from_level, to_level):
#         if from_level == to_level:
#             raise RenateNotValidTransitionError('The requested atomic transition is not valid. '
#                                                 'Requested transition is an ionization.')
#         return uc.convert_from_cm2_to_m2(self.neutral_cross_sections[target][from_level, to_level])


import os
import numpy
import utility.convert as uc
import matplotlib.pyplot as plt
import pandas
from lxml import etree
from utility import getdata
from scipy.interpolate import interp1d
from crm_solver.neutral_db import NeutralDB
        assert isinstance(self.param, etree._ElementTree)
        self.__set_impurity_mass_scaling_dictionary()
        self.__projectile_parameters()
        self.__set_atomic_dictionary()
        self.__set_rates_path(rate_type)
        self.__set_charge_state_lib()

    def __set_impurity_mass_scaling_dictionary(self):
        self.impurity_mass_normalization = {'charge-1': 1,
                                            'charge-2': 4,
                                            'charge-3': 7,
                                            'charge-4': 9,
                                            'charge-5': 11,
                                            'charge-6': 12,
                                            'charge-7': 14,
                                            'charge-8': 16,
                                            'charge-9': 19,
                                            'charge-10': 20,
                                            'charge-11': 23}

    def __projectile_parameters(self):
        self.energy = self.param.getroot().find('body').find('beamlet_energy').text
        self.species = self.param.getroot().find('body').find('beamlet_species').text
        self.__get_atomic_mass()
        self.__get_projectile_velocity()

    def __get_atomic_mass(self):
        data_path_name = os.path.join('atomic_data', self.param.getroot().find('body').find('beamlet_species').text,
                                      'supplementary_data', 'default', self.param.getroot().
                                      find('body').find('beamlet_species').text + '_m.txt')

# Path: utility/getdata.py
# DEFAULT_SETUP = 'getdata_setup.xml'
# class GetData(AccessData):
#     def __init__(self,
#                  data_path_name=None,
#                  data_key=[],
#                  data_format="pandas"):
#     def read_data(self):
#     def read_h5_to_pandas(self):
#     def read_h5_to_array(self):
#     def read_txt_to_str(self):
#     def read_txt_to_array(self):
#     def read_xml(self):
#     def get_data(self):
#     def download_private_data(self):
#     def download_public_data(self):
#     def ensure_dir(file_path):
# 
# Path: crm_solver/neutral_db.py
# class NeutralDB(object):
#     def __init__(self, param=None, components=None, resolved=None):
#         self.param = param
#         self.__set_atomic_resolution(resolved=resolved)
#         self.__load_neutral_cross_section(components=components)
#         self.__get_atomic_levels()
# 
#     def __set_atomic_resolution(self, resolved):
#         projectile = self.param.getroot().find('body').find('beamlet_species').text
#         if resolved is None:
#             if projectile == 'H' or projectile == 'D' or projectile == 'T':
#                 self.resolved = 'bundled_n'
#             elif projectile == 'Li' or projectile == 'Na':
#                 self.resolved = 'nl'
#         else:
#             self.resolved = resolved
# 
#     def __create_neutral_cross_section_db(self, components):
#         self.neutral_cross_sections = {}
#         self.neutral_target_count = len([comp for comp in components['q'] if int(comp) == 0])
#         for index in range(self.neutral_target_count):
#             self.neutral_cross_sections.update({'neutral'+str(index+1): None})
# 
#     def __set_neutral_cross_section_path(self, target='H'):
#         file_name = target + '_' + self.resolved + '_' + \
#                     self.param.getroot().find('body').find('beamlet_energy').text + '.txt'
# 
#         return os.path.join('atomic_data', self.param.getroot().find('body').find('beamlet_species').text,
#                             'cross_sections', 'neutral', file_name)
# 
#     def __identify_neutral_target(self, component):
#         if isinstance(component['Molecule'], str):
#             return component['Molecule']
#         else:
#             if component['Z'] == 1 and component['A'] == 1:
#                 return 'H'
#             elif component['Z'] == 1 and component['A'] == 2:
#                 return 'D'
#             elif component['Z'] == 1 and component['A'] == 3:
#                 return 'T'
#             else:
#                 raise NotImplementedError('The requested atomic gas is not supported yet.')
# 
#     def __load_neutral_cross_section(self, components):
#         self.__create_neutral_cross_section_db(components=components)
#         for index in range(self.neutral_target_count):
#             name = 'neutral'+str(index+1)
#             target = self.__identify_neutral_target(component=components.T[name])
#             path = self.__set_neutral_cross_section_path(target=target)
#             self.neutral_cross_sections[name] = GetData(data_path_name=path, data_format="array").data
# 
#     def __get_atomic_levels(self):
#         for index in range(self.neutral_target_count):
#             atomic_levels = self.neutral_cross_sections['neutral'+str(index+1)].shape[0]
#             if not hasattr(self, 'atomic_level'):
#                 self.atomic_levels = atomic_levels
#             elif self.atomic_levels > atomic_levels:
#                 self.atomic_levels = atomic_levels
# 
#     def get_neutral_impact_loss(self, target, from_level):
#         return uc.convert_from_cm2_to_m2(self.neutral_cross_sections[target][from_level, from_level])
# 
#     def get_neutral_impact_transition(self, target, from_level, to_level):
#         if from_level == to_level:
#             raise RenateNotValidTransitionError('The requested atomic transition is not valid. '
#                                                 'Requested transition is an ionization.')
#         return uc.convert_from_cm2_to_m2(self.neutral_cross_sections[target][from_level, to_level])


# Path: crm_solver/atomic_db.py
import os
import numpy
import utility.convert as uc
import matplotlib.pyplot as plt
import pandas
from lxml import etree
from utility import getdata
from scipy.interpolate import interp1d
from crm_solver.neutral_db import NeutralDB

        assert isinstance(self.param, etree._ElementTree)
        self.__set_impurity_mass_scaling_dictionary()
        self.__projectile_parameters()
        self.__set_atomic_dictionary()
        self.__set_rates_path(rate_type)
        self.__set_charge_state_lib()

    def __set_impurity_mass_scaling_dictionary(self):
        self.impurity_mass_normalization = {'charge-1': 1,
                                            'charge-2': 4,
                                            'charge-3': 7,
                                            'charge-4': 9,
                                            'charge-5': 11,
                                            'charge-6': 12,
                                            'charge-7': 14,
                                            'charge-8': 16,
                                            'charge-9': 19,
                                            'charge-10': 20,
                                            'charge-11': 23}

    def __projectile_parameters(self):
        self.energy = self.param.getroot().find('body').find('beamlet_energy').text
        self.species = self.param.getroot().find('body').find('beamlet_species').text
        self.__get_atomic_mass()
        self.__get_projectile_velocity()

    def __get_atomic_mass(self):
        data_path_name = os.path.join('atomic_data', self.param.getroot().find('body').find('beamlet_species').text,
                                      'supplementary_data', 'default', self.param.getroot().
                                      find('body').find('beamlet_species').text + '_m.txt')

        mass_str = getdata.GetData(data_path_name=data_path_name, data_format="array").data