Class: ChemistryParadise::ShowElectronConfiguration

Inherits:
Base
  • Object
show all
Defined in:
lib/chemistry_paradise/show_electron_configuration.rb

Overview

ChemistryParadise::ShowElectronConfiguration

Constant Summary collapse

DEFAULT_INPUT =
#

DEFAULT_INPUT

#
'Ca'
NEBENQUANTENZAHL =
#

NEBENQUANTENZAHL

#
{
  's' =>  2, 
  'p' =>  6,
  'd' => 10,
  'f' => 14
}
MAIN_HASH =
#
  1. Periode: 1s

  2. Periode: 2s 2p

  3. Periode: 3s 3p

  4. Periode: 4s 3d 4p

  5. Periode: 5s 4d 5p

  6. Periode: 6s 4f 5d 6p

  7. Periode: 7s 5f 6d

#

The following hash was taken from:

https://en.wikipedia.org/wiki/Electron_configuration#Other_exceptions_to_Madelung.27s_rule

and from:

https://en.wikipedia.org/wiki/Electron_configurations_of_the_elements_%28data_page%29
#
{
   1 => '1s¹',
   2 => '1s²',
   3 => '1s² 2s¹',
   4 => '1s² 2s²',
   5 => '1s² 2s² 2p¹',         #  (5) Bor
   6 => '1s² 2s² 2p²',         #  (6) Kohlenstoff
   7 => '1s² 2s² 2p³',         #  (7) Stickstoff
   8 => '1s² 2s² 2p⁴',         #  (8) Sauerstoff 
   9 => '1s² 2s² 2p⁵',         #  (9) Fluor
  10 => '1s² 2s² 2p⁶',         # (10) Neon
  11 => '1s² 2s² 2p⁶ 3s¹',     # (11) Sodium
  12 => '1s² 2s² 2p⁶ 3s²',     # (12) Magnesium
  13 => '1s² 2s² 2p⁶ 3s² 3p¹', # (13) Aluminium
  14 => '1s² 2s² 2p⁶ 3s² 3p²', # (14) Silicon
  15 => '1s² 2s² 2p⁶ 3s² 3p³', # (15) Phosphorus
  16 => '1s² 2s² 2p⁶ 3s² 3p⁴', # (16) Sulfur
  17 => '1s² 2s² 2p⁶ 3s² 3p⁵', # (17) Chlorine
  18 => '1s² 2s² 2p⁶ 3s² 3p⁶', # (18) Arsen
  19 => '1s² 2s² 2p⁶ 3s² 3p⁶', # (19) Potassium
  20 => '[Ar] 4s²',            # (20) Calcium
  21 => '[Ar] 4s² 3d¹',        # (21) Scandium
  22 => '[Ar] 4s² 3d²',        # (22) Titanium
  23 => '[Ar] 4s² 3d³',        # (23) Vanadium
  24 => '[Ar] 4s¹ 3d⁵',        # (24) Chromium
  25 => '[Ar] 4s² 3d⁵',        # (25) Manganese
  26 => '[Ar] 4s² 3d⁶',        # (26) Iron
  27 => '[Ar] 4s² 3d⁷',        # (27) Cobalt
  28 => '[Ar] 4s² 3d⁸',        # (28) Nickel 
  29 => '[Ar] 4s¹ 3d¹⁰',       # (29) Copper
  30 => '[Ar] 4s² 3d¹⁰',       # (30) Zinc
  31 => '[Ar] 3d¹⁰ 4s² 4p¹',   # (31) Gallium
  32 => '[Ar] 3d¹⁰ 4s² 4p²',   # (32) Germanium
  33 => '[Ar] 3d¹⁰ 4s² 4p³',   # (33) Arsenic
  34 => '[Ar] 3d¹⁰ 4s² 4p⁴',   # (34) Selenium
  35 => '[Ar] 3d¹⁰ 4s² 4p⁵',   # (35) Bromine
  36 => '[Ar] 3d¹⁰ 4s² 4p⁶',   # (36) Krypton
  37 => '[Kr] 5s¹',            # (37) Rubidium
  38 => '[Kr] 5s²',            # (38) Strontium
  39 => '[Kr] 4d¹ 5s²',        # (39) Yttrium
  40 => '[Kr] 4d² 5s²',        # (40) Zirconium
  41 => '[Kr] 4d⁴ 5s¹',        # (41) Niobium
  42 => '[Kr] 4d⁵ 5s¹',        # (42) Molybdenum 
  43 => '[Kr] 4d⁵ 5s²',       # (43) Technetium
  44 => '[Kr] 4d⁷ 5s¹',        # (44) Ruthenium
  45 => '[Kr] 4d⁸ 5s¹',        # (45) Rhodium
  46 => '[Kr] 4d¹⁰',           # (46) Palladium
  47 => '[Kr] 4d¹⁰ 5s¹',       # (47) Silver
  48 => '[Kr] 4d¹⁰ 5s²',       # (48) Cadmium
  49 => '[Kr] 4d¹⁰ 5s² 5p¹',   # (49) Indium
  50 => '[Kr] 4d¹⁰ 5s² 5p²',   # (50) Tin
  51 => '[Kr] 4d¹⁰ 5s² 5p³',   # (51) Antimony
  52 => '[Kr] 4d¹⁰ 5s² 5p⁴',   # (52) Tellurium
  53 => '[Kr] 4d¹⁰ 5s² 5p⁵',   # (53) Iodine
  54 => '[Kr] 4d¹⁰ 5s² 5p⁶',   # (54) Xenon
  55 => '[Xe] 6s¹',            # (55) Caesium
}
PERIODIC_TABLE_DATASET =
#

PERIODIC_TABLE_DATASET

#
YAML.load_file(_)

Constants inherited from Base

Base::FILE_MOLECULAR_FORMULA_OF_DIFFERENT_MOLECULES, Base::NAMESPACE

Constants included from Shared

ChemistryParadise::Shared::ARRAY_TEST_THESE_MOLECULES

Constants included from Constants

Constants::ELECTRON_NEGATIVITY_CHART, Constants::FILE_ATOMGEWICHTE, Constants::FILE_ELECTRON_NEGATIVITY_CHART, Constants::FILE_PERIODIC_TABLE_OF_THE_ELEMENTS, Constants::N, Constants::PLANK_CONSTANT, Constants::PROPER_FILLORDER, Constants::SPEED_OF_LIGHT

Instance Method Summary collapse

Methods inherited from Base

#be_quiet, #be_verbose?, #cd, #cliner, #commandline_arguments?, #do_use_the_english_language, #do_use_the_german_language, #do_we_use_english?, #esystem, #first_argument?, #gold, #grey, #initialize_the_internal_hash, #internal_hash?, #is_on_roebe?, #mediumpurple, #namespace?, #olivedrab, #opnn, #rev, #royalblue, #set_be_verbose, #set_commandline_arguments, #sfancy, #steelblue, #teal, #tomato, #use_which_language?, #yellow

Methods included from Shared

#convert_parens, #is_number?, periodic_table?, #return_range_for_this_period, #square

Methods included from Constants

#electron_negativity_chart?

Constructor Details

#initialize(optional_input = nil, run_already = true) ⇒ ShowElectronConfiguration

#

initialize

#


124
125
126
127
128
129
130
131
# File 'lib/chemistry_paradise/show_electron_configuration.rb', line 124

def initialize(
    optional_input = nil,
    run_already    = true
  )
  reset
  set_input(optional_input)
  run if run_already
end

Instance Method Details

#check_for_inclusionObject

#

check_for_inclusion

#


195
196
197
198
199
200
201
202
203
204
205
# File 'lib/chemistry_paradise/show_electron_configuration.rb', line 195

def check_for_inclusion
  if periodic_table?.has_key? @input
    set_n_electrons periodic_table?[@input]
    e rev+
      'Found element '+sfancy(@input)+'. '+
      'It has '+simp(@n_electrons.to_s)+' electrons.'
    display_electron_configuration(@n_electrons)
  else
    e "Did not find element called `#{sfancy(@input)}`."
  end
end

#default_colourObject

#

default_colour

#


181
182
183
# File 'lib/chemistry_paradise/show_electron_configuration.rb', line 181

def default_colour
  Colours::GREY
end

#display_electron_configuration(i = @n_electrons) ⇒ Object

#

display_electron_configuration

Show the specific electron configuration.

For instance:

1s2 2s2 2p6 3s2 3p4
#


217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/chemistry_paradise/show_electron_configuration.rb', line 217

def display_electron_configuration(
    i = @n_electrons
  )
  # ======================================================================= #
  # Notify the user of invalid input.
  # ======================================================================= #
  unless main_hash?.has_key? i
    e 'Note that the electron at position '+i.to_s+
      ' is not registered.'
  end
  set_main_string MAIN_HASH[i]
  # ======================================================================= #
  # Output it next:
  # ======================================================================= #
  e yellow(@_)
end

#main_hash?Boolean

#

main_hash?

#

Returns:

  • (Boolean)


188
189
190
# File 'lib/chemistry_paradise/show_electron_configuration.rb', line 188

def main_hash?
  MAIN_HASH
end

#periodic_table?Boolean

#

periodic_table?

#

Returns:

  • (Boolean)


174
175
176
# File 'lib/chemistry_paradise/show_electron_configuration.rb', line 174

def periodic_table?
  PERIODIC_TABLE_DATASET
end

#resetObject

#

reset

#


136
137
138
139
# File 'lib/chemistry_paradise/show_electron_configuration.rb', line 136

def reset
  @n_electrons = 0
  @_ = '' # The result string.
end

#runObject

#

run (run tag)

#


237
238
239
# File 'lib/chemistry_paradise/show_electron_configuration.rb', line 237

def run
  check_for_inclusion
end

#set_input(i = N) ⇒ Object

#

set_input

#


151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/chemistry_paradise/show_electron_configuration.rb', line 151

def set_input(i = N)
  i = i.first if i.is_a? Array
  i = DEFAULT_INPUT if i.nil?
  i = i.to_s.dup.delete('/') # We don't need '/' characters.
  i = periodic_table?.invert[i.to_i] if i =~ /^\d+$/
  # ======================================================================= #
  # Since as of June 2016, we will upcase the first character.
  # ======================================================================= #
  i = i.dup if i.frozen?
  i[0,1] = i[0,1].upcase
  @input = i
end

#set_main_string(i) ⇒ Object

#

set_main_string

#


144
145
146
# File 'lib/chemistry_paradise/show_electron_configuration.rb', line 144

def set_main_string(i)
  @_ = i
end

#set_n_electrons(i) ⇒ Object

#

set_n_electrons

#


167
168
169
# File 'lib/chemistry_paradise/show_electron_configuration.rb', line 167

def set_n_electrons(i)
  @n_electrons = i
end