# Path: pyneb/utils/init.py
# ELEM_LIST = ['Ag', 'Al', 'Ar', 'As', 'Au', 'B', 'Ba', 'Be', 'Bi', 'Br',
#      'C', 'Ca', 'Cd', 'Ce', 'Cl', 'Co', 'Cr', 'Cs', 'Cu', 'Dy', 'Er', 'Eu', 'F', 'Fe', 'Ga', 'Gd', 'Ge',
#      'H', 'He', 'Hf', 'Hg', 'Ho', 'I', 'In', 'Ir', 'K', 'Kr', 'La', 'Li', 'Lu', 'Mg', 'Mn', 'Mo',
#      'N', 'Na', 'Nb', 'Nd', 'Ne', 'Ni', 'O', 'Os', 'P', 'Pb', 'Pd', 'Pm', 'Pr', 'Pt',
#      'Rb', 'Re', 'Rh', 'Ru', 'S', 'Sb', 'Sc', 'Se', 'Si', 'Sm', 'Sn', 'Sr',
#      'Ta', 'Tb', 'Te', 'Tc', 'Th', 'Ti', 'Tl','Tm', 'U', 'V', 'W', 'Xe', 'Y', 'Yb', 'Zn', 'Zr', '3He']
# 
# SPEC_LIST = ['1', '2', '3', '4', '5', '6', '7']
# 
# Path: pyneb/utils/misc.py
# def parseAtom(atom):
#     '''
#     Parses an atom label into the element and spectrum parts
#     '''
# 
#     iso = ''
#     elem = ''
#     spec = ''
#     cont = True
#     firstdigit = True
#     for l in atom:
#         if l.isalpha() and cont:
#             elem += l
#             firstdigit = False
#         elif l.isdigit():
#             if firstdigit:
#                 iso += l
#             else:
#                 spec += l
#                 cont = False
#     return iso+str.capitalize(elem), spec


import numpy as np
import pyneb as pn
import random
from pyneb.utils.init import ELEM_LIST, SPEC_LIST
from pyneb.utils.misc import parseAtom
           - use_MC       If True and if the ICF definition includes error informations, the ICF will be multiplied
                           by some factor taking into account the error.
        Usage:
            atom_abun = {'O2': 0.001, 'O3': 0.002, 'Ne3': 1.2e-5}
            getElemAbundance(atom_abun)
         
        """
        if type(icf_list) == type(''):
            icf_list = [icf_list]
        # List of all existing atoms. Necessary to initialize the ionic abundance dictionary
        if icf_family is not None:
            icf_list = [icf for icf in self.all_icfs.keys() if icf_family in icf]
        atom_list = []
        for elem in ELEM_LIST:
            for spec in SPEC_LIST:
                atom_list.append(elem + str(spec)) 
        atom_list.extend(['He2', 'He3', 'He1r', 'He2r', 'O2r'])
    
        # Initialize the ionic abundances so that the code does not crash when a specific abundance is invoked
        # TODO : Check that the same ion is not present as collisional and recombination !!
        abun = {}
        for atom in atom_list:
            # Set those abundances which are different from 0. These determine which ICFs can be computed        
            if atom in atom_abun:
                if atom[-1] == 'r':
                    elem, spec = parseAtom(atom[:-1])
                    atomc = elem + str(int(spec)+1)
                    if (not use_coll) or (atomc not in atom_abun):
                        abun[atomc] = atom_abun[atom]
                else:

# Path: pyneb/utils/init.py
# ELEM_LIST = ['Ag', 'Al', 'Ar', 'As', 'Au', 'B', 'Ba', 'Be', 'Bi', 'Br',
#      'C', 'Ca', 'Cd', 'Ce', 'Cl', 'Co', 'Cr', 'Cs', 'Cu', 'Dy', 'Er', 'Eu', 'F', 'Fe', 'Ga', 'Gd', 'Ge',
#      'H', 'He', 'Hf', 'Hg', 'Ho', 'I', 'In', 'Ir', 'K', 'Kr', 'La', 'Li', 'Lu', 'Mg', 'Mn', 'Mo',
#      'N', 'Na', 'Nb', 'Nd', 'Ne', 'Ni', 'O', 'Os', 'P', 'Pb', 'Pd', 'Pm', 'Pr', 'Pt',
#      'Rb', 'Re', 'Rh', 'Ru', 'S', 'Sb', 'Sc', 'Se', 'Si', 'Sm', 'Sn', 'Sr',
#      'Ta', 'Tb', 'Te', 'Tc', 'Th', 'Ti', 'Tl','Tm', 'U', 'V', 'W', 'Xe', 'Y', 'Yb', 'Zn', 'Zr', '3He']
# 
# SPEC_LIST = ['1', '2', '3', '4', '5', '6', '7']
# 
# Path: pyneb/utils/misc.py
# def parseAtom(atom):
#     '''
#     Parses an atom label into the element and spectrum parts
#     '''
# 
#     iso = ''
#     elem = ''
#     spec = ''
#     cont = True
#     firstdigit = True
#     for l in atom:
#         if l.isalpha() and cont:
#             elem += l
#             firstdigit = False
#         elif l.isdigit():
#             if firstdigit:
#                 iso += l
#             else:
#                 spec += l
#                 cont = False
#     return iso+str.capitalize(elem), spec


# Path: pyneb/core/icf.py
import numpy as np
import pyneb as pn
import random
from pyneb.utils.init import ELEM_LIST, SPEC_LIST
from pyneb.utils.misc import parseAtom

           - use_MC       If True and if the ICF definition includes error informations, the ICF will be multiplied
                           by some factor taking into account the error.
        Usage:
            atom_abun = {'O2': 0.001, 'O3': 0.002, 'Ne3': 1.2e-5}
            getElemAbundance(atom_abun)
         
        """
        if type(icf_list) == type(''):
            icf_list = [icf_list]
        # List of all existing atoms. Necessary to initialize the ionic abundance dictionary
        if icf_family is not None:
            icf_list = [icf for icf in self.all_icfs.keys() if icf_family in icf]
        atom_list = []
        for elem in ELEM_LIST:
            for spec in SPEC_LIST:
                atom_list.append(elem + str(spec)) 
        atom_list.extend(['He2', 'He3', 'He1r', 'He2r', 'O2r'])
    
        # Initialize the ionic abundances so that the code does not crash when a specific abundance is invoked
        # TODO : Check that the same ion is not present as collisional and recombination !!
        abun = {}
        for atom in atom_list:
            # Set those abundances which are different from 0. These determine which ICFs can be computed        
            if atom in atom_abun:
                if atom[-1] == 'r':
                    elem, spec = parseAtom(atom[:-1])
                    atomc = elem + str(int(spec)+1)
                    if (not use_coll) or (atomc not in atom_abun):
                        abun[atomc] = atom_abun[atom]
                else:

                    elem, spec = parseAtom(atom)