chemistry_paradise 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of chemistry_paradise might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/README.md +222 -0
- data/bin/chemistry_paradise +7 -0
- data/chemistry_paradise.gemspec +45 -0
- data/doc/BUGS.md +16 -0
- data/doc/README.gen +205 -0
- data/doc/TODO.md +13 -0
- data/lib/chemistry_paradise.rb +6 -0
- data/lib/chemistry_paradise/base/base.rb +101 -0
- data/lib/chemistry_paradise/base/colours.rb +65 -0
- data/lib/chemistry_paradise/calculate_atomic_mass.rb +487 -0
- data/lib/chemistry_paradise/combustion_analysis.rb +181 -0
- data/lib/chemistry_paradise/commandline/help.rb +35 -0
- data/lib/chemistry_paradise/commandline/menu.rb +80 -0
- data/lib/chemistry_paradise/commandline/parse_commandline.rb +94 -0
- data/lib/chemistry_paradise/constants/constants.rb +52 -0
- data/lib/chemistry_paradise/constants/file_constants.rb +27 -0
- data/lib/chemistry_paradise/constants/german_names_of_elements_to_element_symbol.rb +157 -0
- data/lib/chemistry_paradise/converters/celsius_to_fahrenheit.rb +134 -0
- data/lib/chemistry_paradise/converters/fahrenheit_to_celsius.rb +122 -0
- data/lib/chemistry_paradise/converters/shared.rb +15 -0
- data/lib/chemistry_paradise/electron_negativity_chart.rb +78 -0
- data/lib/chemistry_paradise/equalize_chemical_formula.rb +82 -0
- data/lib/chemistry_paradise/equation_solver.rb +130 -0
- data/lib/chemistry_paradise/interactive_chemistry_shell.rb +241 -0
- data/lib/chemistry_paradise/orbitals.rb +65 -0
- data/lib/chemistry_paradise/project/project_base_directory.rb +24 -0
- data/lib/chemistry_paradise/requires/common_external_requires.rb +17 -0
- data/lib/chemistry_paradise/shared.rb +162 -0
- data/lib/chemistry_paradise/show_electron_configuration.rb +243 -0
- data/lib/chemistry_paradise/show_electron_negativity_of_this_element.rb +101 -0
- data/lib/chemistry_paradise/show_element.rb +141 -0
- data/lib/chemistry_paradise/split_molecule_names.rb +185 -0
- data/lib/chemistry_paradise/toplevel_methods/atomgewichte.rb +31 -0
- data/lib/chemistry_paradise/toplevel_methods/display_where_the_molmasses_are_kept.rb +24 -0
- data/lib/chemistry_paradise/toplevel_methods/e.rb +16 -0
- data/lib/chemistry_paradise/toplevel_methods/kelvin.rb +34 -0
- data/lib/chemistry_paradise/toplevel_methods/language.rb +50 -0
- data/lib/chemistry_paradise/toplevel_methods/periodic_table.rb +16 -0
- data/lib/chemistry_paradise/toplevel_methods/remove_this_molecule_from.rb +63 -0
- data/lib/chemistry_paradise/toplevel_methods/show_electron_negativity_chart.rb +26 -0
- data/lib/chemistry_paradise/verbose_chemical_calculation.rb +21 -0
- data/lib/chemistry_paradise/version/version.rb +19 -0
- data/lib/chemistry_paradise/yaml/atomgewichte.yml +109 -0
- data/lib/chemistry_paradise/yaml/electron_negativity_chart.yml +109 -0
- data/lib/chemistry_paradise/yaml/molecular_formula_of_different_molecules.yml +12 -0
- data/test/testing_chemistry_paradise.rb +49 -0
- metadata +138 -0
@@ -0,0 +1,65 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === ChemistryParadise::Orbitals
|
6
|
+
#
|
7
|
+
# This will just output the amount of electrons residing
|
8
|
+
# in a specific orbital.
|
9
|
+
# =========================================================================== #
|
10
|
+
require 'chemistry_paradise/base/base.rb'
|
11
|
+
|
12
|
+
module ChemistryParadise
|
13
|
+
|
14
|
+
class Orbitals < Base # === ChemistryParadise::Orbitals
|
15
|
+
|
16
|
+
# ========================================================================= #
|
17
|
+
# === initialize
|
18
|
+
# ========================================================================= #
|
19
|
+
def initialize(
|
20
|
+
upto_n = 10,
|
21
|
+
run_already = true
|
22
|
+
)
|
23
|
+
reset
|
24
|
+
set_upto(upto_n)
|
25
|
+
run if run_already
|
26
|
+
end
|
27
|
+
|
28
|
+
# ========================================================================= #
|
29
|
+
# === set_upto
|
30
|
+
# ========================================================================= #
|
31
|
+
def set_upto(i = 10) # 10 is default.
|
32
|
+
@upto = i
|
33
|
+
end
|
34
|
+
|
35
|
+
# ========================================================================= #
|
36
|
+
# === reset
|
37
|
+
# ========================================================================= #
|
38
|
+
def reset
|
39
|
+
set_upto
|
40
|
+
end
|
41
|
+
|
42
|
+
# ========================================================================= #
|
43
|
+
# === run
|
44
|
+
# ========================================================================= #
|
45
|
+
def run
|
46
|
+
1.upto(@upto).each {|entry|
|
47
|
+
e ' '+entry.to_s.rjust(3)+' -> '+
|
48
|
+
sfancy(
|
49
|
+
calculate_for_this_orbital(entry).to_s.rjust(3)
|
50
|
+
)+' Orbitals.'
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
# ========================================================================= #
|
55
|
+
# === calculate_for_this_orbital
|
56
|
+
# ========================================================================= #
|
57
|
+
def calculate_for_this_orbital(n)
|
58
|
+
2 * (n ** 2)
|
59
|
+
end
|
60
|
+
|
61
|
+
end; end
|
62
|
+
|
63
|
+
if __FILE__ == $PROGRAM_NAME
|
64
|
+
ChemistryParadise::Orbitals.new(10)
|
65
|
+
end # orbitals
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'chemistry_paradise/project/project_base_directory.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module ChemistryParadise
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === ChemistryParadise::PROJECT_BASE_DIRECTORY
|
11
|
+
#
|
12
|
+
# The constant must have a trailing '/' character.
|
13
|
+
# ========================================================================= #
|
14
|
+
PROJECT_BASE_DIRECTORY =
|
15
|
+
File.absolute_path("#{__dir__}/..")+'/'
|
16
|
+
|
17
|
+
# ========================================================================= #
|
18
|
+
# === ChemistryParadise.project_base_directory?
|
19
|
+
# ========================================================================= #
|
20
|
+
def self.project_base_directory?
|
21
|
+
PROJECT_BASE_DIRECTORY
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'chemistry_paradise/requires/common_external_requires.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'yaml'
|
8
|
+
begin
|
9
|
+
require 'colours'
|
10
|
+
rescue LoadError; end
|
11
|
+
begin
|
12
|
+
require 'opn'
|
13
|
+
rescue LoadError; end
|
14
|
+
|
15
|
+
begin
|
16
|
+
require 'cliner'
|
17
|
+
rescue LoadError; end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === ChemistryParadise::Shared
|
6
|
+
#
|
7
|
+
# To load this file, do:
|
8
|
+
#
|
9
|
+
# require 'chemistry_paradise/shared.rb'
|
10
|
+
#
|
11
|
+
# =========================================================================== #
|
12
|
+
require 'chemistry_paradise/requires/common_external_requires.rb'
|
13
|
+
require 'chemistry_paradise/constants/constants.rb'
|
14
|
+
require 'chemistry_paradise/version/version.rb'
|
15
|
+
require 'chemistry_paradise/toplevel_methods/periodic_table.rb'
|
16
|
+
require 'chemistry_paradise/toplevel_methods/show_electron_negativity_chart.rb'
|
17
|
+
|
18
|
+
module ChemistryParadise # include ChemistryParadise::Shared
|
19
|
+
|
20
|
+
module Shared # === ChemistryParadise::Shared
|
21
|
+
|
22
|
+
include ChemistryParadise::Constants
|
23
|
+
|
24
|
+
# ========================================================================= #
|
25
|
+
# === ARRAY_TEST_THESE_MOLECULES
|
26
|
+
#
|
27
|
+
# Test these molecules. Default values.
|
28
|
+
# ========================================================================= #
|
29
|
+
ARRAY_TEST_THESE_MOLECULES = %w(
|
30
|
+
NH3
|
31
|
+
NH4
|
32
|
+
MnO2
|
33
|
+
P2O5
|
34
|
+
H2O
|
35
|
+
Pb3O4
|
36
|
+
H2SO4
|
37
|
+
C12H12N2
|
38
|
+
BaCO3
|
39
|
+
PbCrO4
|
40
|
+
Al2(SO4)3
|
41
|
+
Ca(OH)2
|
42
|
+
CH3COOH
|
43
|
+
C12H22O11
|
44
|
+
)
|
45
|
+
|
46
|
+
# ========================================================================= #
|
47
|
+
# === is_number?
|
48
|
+
#
|
49
|
+
# This method will return true if is a number, else false. For this it
|
50
|
+
# uses the .to_i method trick, which returns 0 for non-numbers.
|
51
|
+
# ========================================================================= #
|
52
|
+
def is_number?(i)
|
53
|
+
result = (i.to_i.to_s == i)
|
54
|
+
return result
|
55
|
+
end
|
56
|
+
|
57
|
+
# ========================================================================= #
|
58
|
+
# === square
|
59
|
+
#
|
60
|
+
# Die Wurzel aus 2 ist 1.414
|
61
|
+
# chem; square 2; sqr 3; sqr 4; sqr 5; sqr 6; sqr 7; sqr 8; sqr 9
|
62
|
+
# ========================================================================= #
|
63
|
+
def square(of)
|
64
|
+
Math.sqrt of
|
65
|
+
end; alias sqr square # === sqr
|
66
|
+
|
67
|
+
# ========================================================================= #
|
68
|
+
# === ChemistryParadise::Shared.convert_parens
|
69
|
+
#
|
70
|
+
# This method will properly convert the () parens that can be found
|
71
|
+
# in a chemical formula.
|
72
|
+
#
|
73
|
+
# For instance:
|
74
|
+
# Al2(SO4)3
|
75
|
+
#
|
76
|
+
# Is effectively the same such as:
|
77
|
+
# Al2SO4SO4SO4
|
78
|
+
# ========================================================================= #
|
79
|
+
def self.convert_parens(i)
|
80
|
+
if i.is_a? Array
|
81
|
+
i.each {|entry| convert_parens(entry) }
|
82
|
+
else
|
83
|
+
if i.include? '('
|
84
|
+
n_parens = i.count('(')
|
85
|
+
if n_parens > 1 # Ok, this may be a really complex formula, like:
|
86
|
+
# Fe(OH)3 + H2SO4 -> Fe2(SO4)3 + H2O
|
87
|
+
splitted = i.split(' ')
|
88
|
+
splitted = splitted.map {|entry| convert_parens(entry) } # For now we remove some things.
|
89
|
+
return splitted.join(' ')
|
90
|
+
else
|
91
|
+
regex = /\((.+)\)(\d)/
|
92
|
+
match = i.match(regex)
|
93
|
+
i = i[0, i.index('(')]
|
94
|
+
i << match[1] * match[2].to_i # Which group * n repetition
|
95
|
+
end
|
96
|
+
end
|
97
|
+
return i
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# ========================================================================= #
|
102
|
+
# === periodic_table?
|
103
|
+
# ========================================================================= #
|
104
|
+
def periodic_table?
|
105
|
+
return Shared.periodic_table?
|
106
|
+
end
|
107
|
+
|
108
|
+
# ========================================================================= #
|
109
|
+
# === ChemistryParadise::Shared.periodic_table?
|
110
|
+
# ========================================================================= #
|
111
|
+
def self.periodic_table?
|
112
|
+
::ChemistryParadise.periodic_table?
|
113
|
+
end
|
114
|
+
|
115
|
+
# ========================================================================= #
|
116
|
+
# === return_range_for_this_period
|
117
|
+
#
|
118
|
+
# This method will tell us the legal range of elements for any given
|
119
|
+
# period.
|
120
|
+
#
|
121
|
+
# The formula would be:
|
122
|
+
#
|
123
|
+
# 2+4n
|
124
|
+
#
|
125
|
+
# For instance:
|
126
|
+
# period 1 will return (1..2).
|
127
|
+
# period 2 will return (3..8).
|
128
|
+
# ========================================================================= #
|
129
|
+
def return_range_for_this_period(this_period = 1)
|
130
|
+
case this_period
|
131
|
+
when 1
|
132
|
+
(1..2)
|
133
|
+
when 2
|
134
|
+
(3..10)
|
135
|
+
when 3
|
136
|
+
(11..18)
|
137
|
+
when 4
|
138
|
+
(19..36)
|
139
|
+
when 5
|
140
|
+
(37..54)
|
141
|
+
when 6
|
142
|
+
(55..86)
|
143
|
+
when 7
|
144
|
+
(87..118)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# ========================================================================= #
|
149
|
+
# === convert_parens
|
150
|
+
# ========================================================================= #
|
151
|
+
def convert_parens(i)
|
152
|
+
ChemistryParadise::Shared.convert_parens(i)
|
153
|
+
end; alias parse convert_parens # === parse
|
154
|
+
|
155
|
+
end; end
|
156
|
+
|
157
|
+
if __FILE__ == $PROGRAM_NAME
|
158
|
+
include ChemistryParadise::Shared
|
159
|
+
pp convert_parens 'Al2(SO4)3'
|
160
|
+
pp convert_parens 'Fe(OH)3 + H2SO4 -> Fe2(SO4)3 + H2O'
|
161
|
+
ChemistryParadise::Shared.show_electron_negativity_chart
|
162
|
+
end # rb shared.rb
|
@@ -0,0 +1,243 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === ChemistryParadise::ShowElectronConfiguration
|
6
|
+
#
|
7
|
+
# Feed this class an element as input, such as Ca or Fe, and it will
|
8
|
+
# display the electron configuration of said element.
|
9
|
+
#
|
10
|
+
# Usage examples:
|
11
|
+
# ChemistryParadise::ShowElectronConfiguration.new
|
12
|
+
# =========================================================================== #
|
13
|
+
# require 'chemistry_paradise/show_electron_configuration.rb'
|
14
|
+
# =========================================================================== #
|
15
|
+
require 'chemistry_paradise/base/base.rb'
|
16
|
+
|
17
|
+
module ChemistryParadise
|
18
|
+
|
19
|
+
class ShowElectronConfiguration < Base # ShowElectronConfiguration.new
|
20
|
+
|
21
|
+
# ========================================================================= #
|
22
|
+
# === DEFAULT_INPUT
|
23
|
+
# ========================================================================= #
|
24
|
+
DEFAULT_INPUT = 'Ca'
|
25
|
+
|
26
|
+
# ========================================================================= #
|
27
|
+
# === NEBENQUANTENZAHL
|
28
|
+
# ========================================================================= #
|
29
|
+
NEBENQUANTENZAHL = {
|
30
|
+
's' => 2,
|
31
|
+
'p' => 6,
|
32
|
+
'd' => 10,
|
33
|
+
'f' => 14
|
34
|
+
}
|
35
|
+
|
36
|
+
# ========================================================================= #
|
37
|
+
# 1. Periode: 1s
|
38
|
+
# 2. Periode: 2s 2p
|
39
|
+
# 3. Periode: 3s 3p
|
40
|
+
# 4. Periode: 4s 3d 4p
|
41
|
+
# 5. Periode: 5s 4d 5p
|
42
|
+
# 6. Periode: 6s 4f 5d 6p
|
43
|
+
# 7. Periode: 7s 5f 6d
|
44
|
+
# ========================================================================= #
|
45
|
+
# The following hash was taken from:
|
46
|
+
#
|
47
|
+
# http://en.wikipedia.org/wiki/Electron_configuration#Other_exceptions_to_Madelung.27s_rule
|
48
|
+
#
|
49
|
+
# and from:
|
50
|
+
#
|
51
|
+
# http://en.wikipedia.org/wiki/Electron_configurations_of_the_elements_%28data_page%29
|
52
|
+
#
|
53
|
+
# ========================================================================= #
|
54
|
+
MAIN_HASH = {
|
55
|
+
1 => '1s1',
|
56
|
+
2 => '1s2',
|
57
|
+
3 => '1s2 2s1',
|
58
|
+
4 => '1s2 2s2',
|
59
|
+
5 => '1s2 2s2 2p1', # (5) Bor
|
60
|
+
6 => '1s2 2s2 2p2', # (6) Kohlenstoff
|
61
|
+
7 => '1s2 2s2 2p3', # (7) Stickstoff
|
62
|
+
8 => '1s2 2s2 2p4', # (8) Sauerstoff
|
63
|
+
9 => '1s2 2s2 2p5', # (9) Fluor
|
64
|
+
10 => '1s2 2s2 2p6', # (10) Neon
|
65
|
+
11 => '1s2 2s2 2p6 3s1', # (11) Sodium
|
66
|
+
12 => '1s2 2s2 2p6 3s2', # (12) Magnesium
|
67
|
+
13 => '1s2 2s2 2p6 3s2 3p1', # (13) Aluminium
|
68
|
+
14 => '1s2 2s2 2p6 3s2 3p2', # (14) Silicon
|
69
|
+
15 => '1s2 2s2 2p6 3s2 3p3', # (15) Phosphorus
|
70
|
+
16 => '1s2 2s2 2p6 3s2 3p4', # (16) Sulfur
|
71
|
+
17 => '1s2 2s2 2p6 3s2 3p5', # (17) Chlorine
|
72
|
+
18 => '1s2 2s2 2p6 3s2 3p6', # (18) Arsen
|
73
|
+
19 => '1s2 2s2 2p6 3s2 3p6', # (19) Potassium
|
74
|
+
20 => '[Ar] 4s2', # (20) Calcium
|
75
|
+
21 => '[Ar] 4s2 3d1', # (21) Scandium
|
76
|
+
22 => '[Ar] 4s2 3d2', # (22) Titanium
|
77
|
+
23 => '[Ar] 4s2 3d3', # (23) Vanadium
|
78
|
+
24 => '[Ar] 4s1 3d5', # (24) Chromium
|
79
|
+
25 => '[Ar] 4s2 3d5', # (25) Manganese
|
80
|
+
26 => '[Ar] 4s2 3d6', # (26) Iron
|
81
|
+
27 => '[Ar] 4s2 3d7', # (27) Cobalt
|
82
|
+
28 => '[Ar] 4s2 3d8', # (28) Nickel
|
83
|
+
29 => '[Ar] 4s1 3d10', # (29) Copper
|
84
|
+
30 => '[Ar] 4s2 3d10', # (30) Zinc
|
85
|
+
31 => '[Ar] 3d10 4s2 4p1', # (31) Gallium
|
86
|
+
32 => '[Ar] 3d10 4s2 4p2', # (32) Germanium
|
87
|
+
33 => '[Ar] 3d10 4s2 4p3', # (33) Arsenic
|
88
|
+
34 => '[Ar] 3d10 4s2 4p4', # (34) Selenium
|
89
|
+
35 => '[Ar] 3d10 4s2 4p5', # (35) Bromine
|
90
|
+
36 => '[Ar] 3d10 4s2 4p6', # (36) Krypton
|
91
|
+
37 => '[Kr] 5s1', # (37) Rubidium
|
92
|
+
38 => '[Kr] 5s2', # (38) Strontium
|
93
|
+
39 => '[Kr] 4d1 5s2', # (39) Yttrium
|
94
|
+
40 => '[Kr] 4d2 5s2', # (40) Zirconium
|
95
|
+
41 => '[Kr] 4d4 5s1', # (41) Niobium
|
96
|
+
42 => '[Kr] 4d5 5s1', # (42) Molybdenum
|
97
|
+
43 => '[Kr] 4d5 5s2 ', # (43) Technetium
|
98
|
+
44 => '[Kr] 4d7 5s1', # (44) Ruthenium
|
99
|
+
45 => '[Kr] 4d8 5s1', # (45) Rhodium
|
100
|
+
46 => '[Kr] 4d10', # (46) Palladium
|
101
|
+
47 => '[Kr] 4d10 5s1', # (47) Silver
|
102
|
+
48 => '[Kr] 4d10 5s2', # (48) Cadmium
|
103
|
+
49 => '[Kr] 4d10 5s2 5p1', # (49) Indium
|
104
|
+
50 => '[Kr] 4d10 5s2 5p2', # (50) Tin
|
105
|
+
51 => '[Kr] 4d10 5s2 5p3', # (51) Antimony
|
106
|
+
52 => '[Kr] 4d10 5s2 5p4', # (52) Tellurium
|
107
|
+
53 => '[Kr] 4d10 5s2 5p5', # (53) Iodine
|
108
|
+
54 => '[Kr] 4d10 5s2 5p6', # (54) Xenon
|
109
|
+
55 => '[Xe] 6s1', # (55) Caesium
|
110
|
+
}
|
111
|
+
|
112
|
+
_ = Shared.periodic_table?
|
113
|
+
|
114
|
+
# ========================================================================= #
|
115
|
+
# === PERIODIC_TABLE
|
116
|
+
# ========================================================================= #
|
117
|
+
PERIODIC_TABLE = YAML.load_file(_) if File.exist? _
|
118
|
+
|
119
|
+
# ========================================================================= #
|
120
|
+
# === initialize
|
121
|
+
# ========================================================================= #
|
122
|
+
def initialize(
|
123
|
+
optional_input = nil,
|
124
|
+
run_already = true
|
125
|
+
)
|
126
|
+
reset
|
127
|
+
set_input(optional_input)
|
128
|
+
run if run_already
|
129
|
+
end
|
130
|
+
|
131
|
+
# ========================================================================= #
|
132
|
+
# === reset
|
133
|
+
# ========================================================================= #
|
134
|
+
def reset
|
135
|
+
@n_electrons = 0
|
136
|
+
@_ = '' # The result string.
|
137
|
+
end
|
138
|
+
|
139
|
+
# ========================================================================= #
|
140
|
+
# === set_main_string
|
141
|
+
# ========================================================================= #
|
142
|
+
def set_main_string(i)
|
143
|
+
@_ = i
|
144
|
+
end
|
145
|
+
|
146
|
+
# ========================================================================= #
|
147
|
+
# === set_input
|
148
|
+
# ========================================================================= #
|
149
|
+
def set_input(i = N)
|
150
|
+
i = i.first if i.is_a? Array
|
151
|
+
i = DEFAULT_INPUT if i.nil?
|
152
|
+
i = i.to_s.dup.delete('/') # We don't need '/' characters.
|
153
|
+
i = periodic_table?.invert[i.to_i] if i =~ /^\d+$/
|
154
|
+
# ======================================================================= #
|
155
|
+
# Since as of June 2016, we will upcase the first character.
|
156
|
+
# ======================================================================= #
|
157
|
+
i = i.dup if i.frozen?
|
158
|
+
i[0,1] = i[0,1].upcase
|
159
|
+
@input = i
|
160
|
+
end
|
161
|
+
|
162
|
+
# ========================================================================= #
|
163
|
+
# === set_n_electrons
|
164
|
+
# ========================================================================= #
|
165
|
+
def set_n_electrons(i)
|
166
|
+
@n_electrons = i
|
167
|
+
end
|
168
|
+
|
169
|
+
# ========================================================================= #
|
170
|
+
# === periodic_table?
|
171
|
+
# ========================================================================= #
|
172
|
+
def periodic_table?
|
173
|
+
PERIODIC_TABLE
|
174
|
+
end
|
175
|
+
|
176
|
+
# ========================================================================= #
|
177
|
+
# === default_colour
|
178
|
+
# ========================================================================= #
|
179
|
+
def default_colour
|
180
|
+
Colours::GREY
|
181
|
+
end
|
182
|
+
|
183
|
+
# ========================================================================= #
|
184
|
+
# === main_hash?
|
185
|
+
# ========================================================================= #
|
186
|
+
def main_hash?
|
187
|
+
MAIN_HASH
|
188
|
+
end
|
189
|
+
|
190
|
+
# ========================================================================= #
|
191
|
+
# === check_for_inclusion
|
192
|
+
# ========================================================================= #
|
193
|
+
def check_for_inclusion
|
194
|
+
if periodic_table?.has_key? @input
|
195
|
+
set_n_electrons periodic_table?[@input]
|
196
|
+
e 'Found element '+sfancy(@input)+'. '+
|
197
|
+
'It has '+simp(@n_electrons.to_s)+' electrons.'
|
198
|
+
display_electron_configuration(@n_electrons)
|
199
|
+
else
|
200
|
+
e "Did not find element called `#{sfancy(@input)}`."
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
# ========================================================================= #
|
205
|
+
# === display_electron_configuration
|
206
|
+
#
|
207
|
+
# Show the specific electron configuration.
|
208
|
+
#
|
209
|
+
# For instance:
|
210
|
+
# 1s2 2s2 2p6 3s2 3p4
|
211
|
+
# ========================================================================= #
|
212
|
+
def display_electron_configuration(i = @n_electrons)
|
213
|
+
# ======================================================================= #
|
214
|
+
# Notify the user of invalid input.
|
215
|
+
# ======================================================================= #
|
216
|
+
unless main_hash?.has_key? i
|
217
|
+
e 'Note that the electron at position '+i.to_s+
|
218
|
+
' is not registered.'
|
219
|
+
end
|
220
|
+
set_main_string MAIN_HASH[i]
|
221
|
+
# ======================================================================= #
|
222
|
+
# Output it next:
|
223
|
+
# ======================================================================= #
|
224
|
+
e yellow(@_)
|
225
|
+
end
|
226
|
+
|
227
|
+
# ========================================================================= #
|
228
|
+
# === run (run tag)
|
229
|
+
# ========================================================================= #
|
230
|
+
def run
|
231
|
+
check_for_inclusion
|
232
|
+
end
|
233
|
+
|
234
|
+
end; end
|
235
|
+
|
236
|
+
if __FILE__ == $PROGRAM_NAME
|
237
|
+
include ChemistryParadise
|
238
|
+
if ARGV.first
|
239
|
+
ShowElectronConfiguration.new(ARGV.first)
|
240
|
+
else
|
241
|
+
ShowElectronConfiguration.new(ARGV)
|
242
|
+
end
|
243
|
+
end # $RUBY_CHEMISTRY/show_electron_configuration.rb
|