import numpy as np


def get_atomic_weight(element: str):
    """
    Parser function to return atomic weight.

    :param element: Atomic number of name
    :type element: str
    :return: Atomic weight
    :rtype: float
    """
    _element = element.capitalize()
    mask = np.isin(periodic_table, _element)
    if np.any(mask):
        return Atomic_Weight[mask.nonzero()[0][0]]
    else:
        raise NameError("A given element is not searchable. \n"
                        "The searchable types of name are: 'He', 'HE, 'he' or 'Helium', 'HELIUM','helium' or '2' "
                        "for the case of He atom. \n"
                        "Please check the name of elements.")


periodic_table = np.array([
    ['Short_name', 'Full_name', 'Atomic_number'],
    ['H', 'Hydrogen', '1'],
    ['He', 'Helium', '2'],
    ['Li', 'Lithium', '3'],
    ['Be', 'Beryllium', '4'],
    ['B', 'Boron', '5'],
    ['C', 'Carbon', '6'],
    ['N', 'Nitrogen', '7'],
    ['O', 'Oxygen', '8'],
    ['F', 'Fluorine', '9'],
    ['Ne', 'Neon', '10'],
    ['Na', 'Sodium', '11'],
    ['Mg', 'Magnesium', '12'],
    ['Al', 'Aluminium', '13'],
    ['Si', 'Silicon', '14'],
    ['P', 'Phosphorus', '15'],
    ['S', 'Sulfur', '16'],
    ['Cl', 'Chlorine', '17'],
    ['Ar', 'Argon', '18'],
    ['K', 'Potassium', '19'],
    ['Ca', 'Calcium', '20'],
    ['Sc', 'Scandium', '21'],
    ['Ti', 'Titanium', '22'],
    ['V', 'Vanadium', '23'],
    ['Cr', 'Chromium', '24'],
    ['Mn', 'Manganese', '25'],
    ['Fe', 'Iron', '26'],
    ['Co', 'Cobalt', '27'],
    ['Ni', 'Nickel', '28'],
    ['Cu', 'Copper', '29'],
    ['Zn', 'Zinc', '30'],
    ['Ga', 'Gallium', '31'],
    ['Ge', 'Germanium', '32'],
    ['As', 'Arsenic', '33'],
    ['Se', 'Selenium', '34'],
    ['Br', 'Bromine', '35'],
    ['Kr', 'Krypton', '36'],
    ['Rb', 'Rubidium', '37'],
    ['Sr', 'Strontium', '38'],
    ['Y', 'Yttrium', '39'],
    ['Zr', 'Zirconium', '40'],
    ['Nb', 'Niobium', '41'],
    ['Mo', 'Molybdenum', '42'],
    ['Tc', 'Technetium', '43'],
    ['Ru', 'Ruthenium', '44'],
    ['Rh', 'Rhodium', '45'],
    ['Pd', 'Palladium', '46'],
    ['Ag', 'Silver', '47'],
    ['Cd', 'Cadmium', '48'],
    ['In', 'Indium', '49'],
    ['Sn', 'Tin', '50'],
    ['Sb', 'Antimony', '51'],
    ['Te', 'Tellurium', '52'],
    ['I', 'Iodine', '53'],
    ['Xe', 'Xenon', '54'],
    ['Cs', 'Caesium', '55'],
    ['Ba', 'Barium', '56'],
    ['La', 'Lanthanum', '57'],
    ['Ce', 'Cerium', '58'],
    ['Pr', 'Praseodymium', '59'],
    ['Nd', 'Neodymium', '60'],
    ['Pm', 'Promethium', '61'],
    ['Sm', 'Samarium', '62'],
    ['Eu', 'Europium', '63'],
    ['Gd', 'Gadolinium', '64'],
    ['Tb', 'Terbium', '65'],
    ['Dy', 'Dysprosium', '66'],
    ['Ho', 'Holmium', '67'],
    ['Er', 'Erbium', '68'],
    ['Tm', 'Thulium', '69'],
    ['Yb', 'Ytterbium', '70'],
    ['Lu', 'Lutetium', '71'],
    ['Hf', 'Hafnium', '72'],
    ['Ta', 'Tantalum', '73'],
    ['W', 'Tungsten', '74'],
    ['Re', 'Rhenium', '75'],
    ['Os', 'Osmium', '76'],
    ['Ir', 'Iridium', '77'],
    ['Pt', 'Platinum', '78'],
    ['Au', 'Gold', '79'],
    ['Hg', 'Mercury', '80'],
    ['Tl', 'Thallium', '81'],
    ['Pb', 'Lead', '82'],
    ['Bi', 'Bismuth', '83'],
    ['Po', 'Polonium', '84'],
    ['At', 'Astatine', '85'],
    ['Rn', 'Radon', '86'],
    ['Fr', 'Francium', '87'],
    ['Ra', 'Radium', '88'],
    ['Ac', 'Actinium', '89'],
    ['Th', 'Thorium', '90'],
    ['Pa', 'Protactinium', '91'],
    ['U', 'Uranium', '92'],
    ['Np', 'Neptunium', '93'],
    ['Pu', 'Plutonium', '94'],
    ['Am', 'Americium', '95'],
    ['Cm', 'Curium', '96'],
    ['Bk', 'Berkelium', '97'],
    ['Cf', 'Californium', '98'],
    ['Es', 'Einsteinium', '99'],
    ['Fm', 'Fermium', '100'],
    ['Md', 'Mendelevium', '101'],
    ['No', 'Nobelium', '102'],
    ['Lr', 'Lawrencium', '103'],
    ['Rf', 'Rutherfordium', '104'],
    ['Db', 'Dubnium', '105'],
    ['Sg', 'Seaborgium', '106'],
    ['Bh', 'Bohrium', '107'],
    ['Hs', 'Hassium', '108'],
    ['Mt', 'Meitnerium', '109'],
    ['Ds', 'Darmstadtium', '110'],
    ['Rg', 'Roentgenium', '111'],
    ['Cn', 'Copernicium', '112'],
    ['Nh', 'Nihonium', '113'],
    ['Fl', 'Flerovium', '114'],
    ['Mc', 'Moscovium', '115'],
    ['Lv', 'Livermorium', '116'],
    ['Ts', 'Tennessine', '117'],
    ['Og', 'Oganesson', '118'],
])

# The atomic weights below are arranged in the order of atomic number.
# The elements with integer mass correspond to the elements with no stable isotopes.
# Source: https://ptable.com/?lang=en#Properties
Atomic_Weight = (None,      # 0
                 1.008,     # 1
                 4.0026,    # 2
                 6.94,      # 3
                 9.0122,    # 4
                 10.81,     # 5
                 12.011,    # 6
                 14.007,    # 7
                 15.999,    # 8
                 18.998,    # 9
                 20.180,    # 10
                 22.990,    # 11
                 24.305,    # 12
                 26.982,    # 13
                 28.085,    # 14
                 30.974,    # 15
                 32.06,     # 16
                 35.45,     # 17
                 39.948,    # 18
                 39.098,    # 19
                 40.078,    # 20
                 44.956,    # 21
                 47.867,    # 22
                 50.942,    # 23
                 51.996,    # 24
                 54.938,    # 25
                 55.845,    # 26
                 58.933,    # 27
                 58.693,    # 28
                 63.546,    # 29
                 65.38,     # 30
                 69.723,    # 31
                 72.630,    # 32
                 74.922,    # 33
                 78.971,    # 34
                 79.904,    # 35
                 83.798,    # 36
                 85.468,    # 37
                 87.62,     # 38
                 88.906,    # 39
                 91.224,    # 40
                 92.906,    # 41
                 95.95,     # 42
                 98,        # 43
                 101.07,    # 44
                 102.91,    # 45
                 106.42,    # 46
                 107.87,    # 47
                 112.41,    # 48
                 114.82,    # 49
                 118.71,    # 50
                 121.76,    # 51
                 127.60,    # 52
                 126.90,    # 53
                 131.29,    # 54
                 132.91,    # 55
                 137.33,    # 56
                 138.91,    # 57
                 140.12,    # 58
                 140.91,    # 59
                 144.24,    # 60
                 145,       # 61
                 150.36,    # 62
                 151.96,    # 63
                 157.25,    # 64
                 158.93,    # 65
                 162.50,    # 66
                 164.93,    # 67
                 167.26,    # 68
                 168.93,    # 69
                 173.05,    # 70
                 174.97,    # 71
                 178.49,    # 72
                 180.95,    # 73
                 183.84,    # 74
                 186.21,    # 75
                 190.23,    # 76
                 192.22,    # 77
                 195.08,    # 78
                 196.97,    # 79
                 200.59,    # 80
                 204.38,    # 81
                 207.2,     # 82
                 208.98,    # 83
                 209,       # 84
                 210,       # 85
                 222,       # 86
                 223,       # 87
                 226,       # 88
                 227,       # 89
                 232.04,    # 90
                 231.04,    # 91
                 238.03,    # 92
                 237,       # 93
                 244,       # 94
                 243,       # 95
                 247,       # 96
                 247,       # 97
                 251,       # 98
                 252,       # 99
                 257,       # 100
                 258,       # 101
                 259,       # 102
                 266,       # 103
                 267,       # 104
                 268,       # 105
                 269,       # 106
                 270,       # 107
                 277,       # 108
                 278,       # 109
                 281,       # 110
                 282,       # 111
                 285,       # 112
                 286,       # 113
                 289,       # 114
                 290,       # 115
                 293,       # 116
                 294,       # 117
                 294,       # 118
                 )
