chemistry_paradise 1.3.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 +522 -0
- data/bin/chemistry_paradise +7 -0
- data/bin/wetter +7 -0
- data/chemistry_paradise.gemspec +46 -0
- data/doc/README.gen +518 -0
- data/doc/bugs/BUGS.md +16 -0
- data/doc/formulas/biochemical_calculations.md +5 -0
- data/doc/todo/todo_for_the_chemistry_paradise_project.md +33 -0
- data/doc/todo/todo_for_the_wetter_project.md +7 -0
- data/lib/chemistry_paradise/base/base.rb +215 -0
- data/lib/chemistry_paradise/base/colours.rb +93 -0
- data/lib/chemistry_paradise/commandline/help.rb +40 -0
- data/lib/chemistry_paradise/commandline/menu.rb +88 -0
- data/lib/chemistry_paradise/commandline/parse_commandline.rb +94 -0
- data/lib/chemistry_paradise/constants/constants.rb +77 -0
- data/lib/chemistry_paradise/constants/file_constants.rb +33 -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 +143 -0
- data/lib/chemistry_paradise/converters/celsius_to_kelvin.rb +125 -0
- data/lib/chemistry_paradise/converters/fahrenheit_to_celsius.rb +132 -0
- data/lib/chemistry_paradise/converters/shared.rb +21 -0
- data/lib/chemistry_paradise/gui/gtk3/calculate_molecular_weight/calculate_molecular_weight.rb +34 -0
- data/lib/chemistry_paradise/gui/gtk3/show_periodic_table/show_periodic_table.rb +34 -0
- data/lib/chemistry_paradise/gui/gtk3/temperature_converter/temperature_converter.rb +112 -0
- data/lib/chemistry_paradise/gui/gtk3/wetter/wetter.rb +119 -0
- data/lib/chemistry_paradise/gui/libui/temperature_converter/temperature_converter.rb +100 -0
- data/lib/chemistry_paradise/gui/libui/wetter/wetter.rb +47 -0
- data/lib/chemistry_paradise/gui/shared_code/calculate_molecular_weight/calculate_molecular_weight_module.rb +171 -0
- data/lib/chemistry_paradise/gui/shared_code/show_periodic_table/show_periodic_table_module.rb +318 -0
- data/lib/chemistry_paradise/gui/shared_code/temperature_converter/temperature_converter_module.rb +192 -0
- data/lib/chemistry_paradise/gui/shared_code/wetter/wetter_module.rb +349 -0
- data/lib/chemistry_paradise/gui/swing/TemperatureConverter$1.class +0 -0
- data/lib/chemistry_paradise/gui/swing/TemperatureConverter.class +0 -0
- data/lib/chemistry_paradise/gui/swing/TemperatureConverter.java +133 -0
- data/lib/chemistry_paradise/gui/unified_widgets/wetter/wetter.rb +62 -0
- data/lib/chemistry_paradise/images/show_periodic_table.png +0 -0
- data/lib/chemistry_paradise/images/vienna_map.png +0 -0
- data/lib/chemistry_paradise/interactive_chemistry_shell.rb +246 -0
- data/lib/chemistry_paradise/project/project.rb +24 -0
- data/lib/chemistry_paradise/requires/common_external_requires.rb +17 -0
- data/lib/chemistry_paradise/requires/require_the_project.rb +21 -0
- data/lib/chemistry_paradise/requires/require_the_project_including_the_graphical_user_interface.rb +7 -0
- data/lib/chemistry_paradise/requires/require_the_project_including_the_web_interface.rb +4 -0
- data/lib/chemistry_paradise/shared.rb +130 -0
- data/lib/chemistry_paradise/show_electron_configuration.rb +250 -0
- data/lib/chemistry_paradise/show_element.rb +145 -0
- data/lib/chemistry_paradise/sinatra/sinatra.rb +131 -0
- data/lib/chemistry_paradise/sinatra/wetter/app.rb +68 -0
- data/lib/chemistry_paradise/sinatra/wetter/start_sinatra_interface.rb +31 -0
- data/lib/chemistry_paradise/split_molecule_names.rb +228 -0
- data/lib/chemistry_paradise/toplevel_methods/atomgewichte.rb +31 -0
- data/lib/chemistry_paradise/toplevel_methods/convert_parens.rb +64 -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/misc.rb +147 -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/roebe.rb +16 -0
- data/lib/chemistry_paradise/toplevel_methods/show_electron_negativity_chart.rb +26 -0
- data/lib/chemistry_paradise/utility_scripts/calculate_atomic_mass.rb +559 -0
- data/lib/chemistry_paradise/utility_scripts/combustion_analysis.rb +207 -0
- data/lib/chemistry_paradise/utility_scripts/electron_negativity_chart.rb +78 -0
- data/lib/chemistry_paradise/utility_scripts/equalize_chemical_formula.rb +84 -0
- data/lib/chemistry_paradise/utility_scripts/equation_solver.rb +130 -0
- data/lib/chemistry_paradise/utility_scripts/orbitals.rb +70 -0
- data/lib/chemistry_paradise/utility_scripts/show_electron_negativity_of_this_element.rb +103 -0
- data/lib/chemistry_paradise/verbose_chemical_calculation.rb +21 -0
- data/lib/chemistry_paradise/version/version.rb +19 -0
- data/lib/chemistry_paradise/wetter/wetter.rb +539 -0
- data/lib/chemistry_paradise/www/wetter/embeddable_interface.rb +78 -0
- data/lib/chemistry_paradise/www/wetter/wetter.cgi +28 -0
- data/lib/chemistry_paradise/yaml/atomgewichte.yml +113 -0
- data/lib/chemistry_paradise/yaml/colours_for_the_elements.yml +13 -0
- data/lib/chemistry_paradise/yaml/dichte.yml +21 -0
- data/lib/chemistry_paradise/yaml/electron_negativity_chart.yml +111 -0
- data/lib/chemistry_paradise/yaml/molecular_formula_of_different_molecules.yml +13 -0
- data/lib/chemistry_paradise/yaml/periodic_table_of_the_elements.yml +125 -0
- data/lib/chemistry_paradise.rb +1 -0
- data/test/testing_chemistry_paradise.rb +49 -0
- metadata +173 -0
@@ -0,0 +1,250 @@
|
|
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
|
+
#
|
12
|
+
# ChemistryParadise::ShowElectronConfiguration.new(ARGV)
|
13
|
+
#
|
14
|
+
# =========================================================================== #
|
15
|
+
# require 'chemistry_paradise/show_electron_configuration.rb'
|
16
|
+
# =========================================================================== #
|
17
|
+
require 'chemistry_paradise/base/base.rb'
|
18
|
+
|
19
|
+
module ChemistryParadise
|
20
|
+
|
21
|
+
class ShowElectronConfiguration < Base # === ChemistryParadise::ShowElectronConfiguration
|
22
|
+
|
23
|
+
# ========================================================================= #
|
24
|
+
# === DEFAULT_INPUT
|
25
|
+
# ========================================================================= #
|
26
|
+
DEFAULT_INPUT = 'Ca'
|
27
|
+
|
28
|
+
# ========================================================================= #
|
29
|
+
# === NEBENQUANTENZAHL
|
30
|
+
# ========================================================================= #
|
31
|
+
NEBENQUANTENZAHL = {
|
32
|
+
's' => 2,
|
33
|
+
'p' => 6,
|
34
|
+
'd' => 10,
|
35
|
+
'f' => 14
|
36
|
+
}
|
37
|
+
|
38
|
+
# ========================================================================= #
|
39
|
+
# 1. Periode: 1s
|
40
|
+
# 2. Periode: 2s 2p
|
41
|
+
# 3. Periode: 3s 3p
|
42
|
+
# 4. Periode: 4s 3d 4p
|
43
|
+
# 5. Periode: 5s 4d 5p
|
44
|
+
# 6. Periode: 6s 4f 5d 6p
|
45
|
+
# 7. Periode: 7s 5f 6d
|
46
|
+
# ========================================================================= #
|
47
|
+
# The following hash was taken from:
|
48
|
+
#
|
49
|
+
# https://en.wikipedia.org/wiki/Electron_configuration#Other_exceptions_to_Madelung.27s_rule
|
50
|
+
#
|
51
|
+
# and from:
|
52
|
+
#
|
53
|
+
# https://en.wikipedia.org/wiki/Electron_configurations_of_the_elements_%28data_page%29
|
54
|
+
#
|
55
|
+
# ========================================================================= #
|
56
|
+
MAIN_HASH = {
|
57
|
+
1 => '1s¹',
|
58
|
+
2 => '1s²',
|
59
|
+
3 => '1s² 2s¹',
|
60
|
+
4 => '1s² 2s²',
|
61
|
+
5 => '1s² 2s² 2p¹', # (5) Bor
|
62
|
+
6 => '1s² 2s² 2p²', # (6) Kohlenstoff
|
63
|
+
7 => '1s² 2s² 2p³', # (7) Stickstoff
|
64
|
+
8 => '1s² 2s² 2p⁴', # (8) Sauerstoff
|
65
|
+
9 => '1s² 2s² 2p⁵', # (9) Fluor
|
66
|
+
10 => '1s² 2s² 2p⁶', # (10) Neon
|
67
|
+
11 => '1s² 2s² 2p⁶ 3s¹', # (11) Sodium
|
68
|
+
12 => '1s² 2s² 2p⁶ 3s²', # (12) Magnesium
|
69
|
+
13 => '1s² 2s² 2p⁶ 3s² 3p¹', # (13) Aluminium
|
70
|
+
14 => '1s² 2s² 2p⁶ 3s² 3p²', # (14) Silicon
|
71
|
+
15 => '1s² 2s² 2p⁶ 3s² 3p³', # (15) Phosphorus
|
72
|
+
16 => '1s² 2s² 2p⁶ 3s² 3p⁴', # (16) Sulfur
|
73
|
+
17 => '1s² 2s² 2p⁶ 3s² 3p⁵', # (17) Chlorine
|
74
|
+
18 => '1s² 2s² 2p⁶ 3s² 3p⁶', # (18) Arsen
|
75
|
+
19 => '1s² 2s² 2p⁶ 3s² 3p⁶', # (19) Potassium
|
76
|
+
20 => '[Ar] 4s²', # (20) Calcium
|
77
|
+
21 => '[Ar] 4s² 3d¹', # (21) Scandium
|
78
|
+
22 => '[Ar] 4s² 3d²', # (22) Titanium
|
79
|
+
23 => '[Ar] 4s² 3d³', # (23) Vanadium
|
80
|
+
24 => '[Ar] 4s¹ 3d⁵', # (24) Chromium
|
81
|
+
25 => '[Ar] 4s² 3d⁵', # (25) Manganese
|
82
|
+
26 => '[Ar] 4s² 3d⁶', # (26) Iron
|
83
|
+
27 => '[Ar] 4s² 3d⁷', # (27) Cobalt
|
84
|
+
28 => '[Ar] 4s² 3d⁸', # (28) Nickel
|
85
|
+
29 => '[Ar] 4s¹ 3d¹⁰', # (29) Copper
|
86
|
+
30 => '[Ar] 4s² 3d¹⁰', # (30) Zinc
|
87
|
+
31 => '[Ar] 3d¹⁰ 4s² 4p¹', # (31) Gallium
|
88
|
+
32 => '[Ar] 3d¹⁰ 4s² 4p²', # (32) Germanium
|
89
|
+
33 => '[Ar] 3d¹⁰ 4s² 4p³', # (33) Arsenic
|
90
|
+
34 => '[Ar] 3d¹⁰ 4s² 4p⁴', # (34) Selenium
|
91
|
+
35 => '[Ar] 3d¹⁰ 4s² 4p⁵', # (35) Bromine
|
92
|
+
36 => '[Ar] 3d¹⁰ 4s² 4p⁶', # (36) Krypton
|
93
|
+
37 => '[Kr] 5s¹', # (37) Rubidium
|
94
|
+
38 => '[Kr] 5s²', # (38) Strontium
|
95
|
+
39 => '[Kr] 4d¹ 5s²', # (39) Yttrium
|
96
|
+
40 => '[Kr] 4d² 5s²', # (40) Zirconium
|
97
|
+
41 => '[Kr] 4d⁴ 5s¹', # (41) Niobium
|
98
|
+
42 => '[Kr] 4d⁵ 5s¹', # (42) Molybdenum
|
99
|
+
43 => '[Kr] 4d⁵ 5s²', # (43) Technetium
|
100
|
+
44 => '[Kr] 4d⁷ 5s¹', # (44) Ruthenium
|
101
|
+
45 => '[Kr] 4d⁸ 5s¹', # (45) Rhodium
|
102
|
+
46 => '[Kr] 4d¹⁰', # (46) Palladium
|
103
|
+
47 => '[Kr] 4d¹⁰ 5s¹', # (47) Silver
|
104
|
+
48 => '[Kr] 4d¹⁰ 5s²', # (48) Cadmium
|
105
|
+
49 => '[Kr] 4d¹⁰ 5s² 5p¹', # (49) Indium
|
106
|
+
50 => '[Kr] 4d¹⁰ 5s² 5p²', # (50) Tin
|
107
|
+
51 => '[Kr] 4d¹⁰ 5s² 5p³', # (51) Antimony
|
108
|
+
52 => '[Kr] 4d¹⁰ 5s² 5p⁴', # (52) Tellurium
|
109
|
+
53 => '[Kr] 4d¹⁰ 5s² 5p⁵', # (53) Iodine
|
110
|
+
54 => '[Kr] 4d¹⁰ 5s² 5p⁶', # (54) Xenon
|
111
|
+
55 => '[Xe] 6s¹', # (55) Caesium
|
112
|
+
}
|
113
|
+
|
114
|
+
_ = ChemistryParadise::Constants::FILE_PERIODIC_TABLE_OF_THE_ELEMENTS
|
115
|
+
|
116
|
+
# ========================================================================= #
|
117
|
+
# === PERIODIC_TABLE_DATASET
|
118
|
+
# ========================================================================= #
|
119
|
+
PERIODIC_TABLE_DATASET = YAML.load_file(_) if File.exist? _
|
120
|
+
|
121
|
+
# ========================================================================= #
|
122
|
+
# === initialize
|
123
|
+
# ========================================================================= #
|
124
|
+
def initialize(
|
125
|
+
optional_input = nil,
|
126
|
+
run_already = true
|
127
|
+
)
|
128
|
+
reset
|
129
|
+
set_input(optional_input)
|
130
|
+
run if run_already
|
131
|
+
end
|
132
|
+
|
133
|
+
# ========================================================================= #
|
134
|
+
# === reset
|
135
|
+
# ========================================================================= #
|
136
|
+
def reset
|
137
|
+
@n_electrons = 0
|
138
|
+
@_ = '' # The result string.
|
139
|
+
end
|
140
|
+
|
141
|
+
# ========================================================================= #
|
142
|
+
# === set_main_string
|
143
|
+
# ========================================================================= #
|
144
|
+
def set_main_string(i)
|
145
|
+
@_ = i
|
146
|
+
end
|
147
|
+
|
148
|
+
# ========================================================================= #
|
149
|
+
# === set_input
|
150
|
+
# ========================================================================= #
|
151
|
+
def set_input(i = N)
|
152
|
+
i = i.first if i.is_a? Array
|
153
|
+
i = DEFAULT_INPUT if i.nil?
|
154
|
+
i = i.to_s.dup.delete('/') # We don't need '/' characters.
|
155
|
+
i = periodic_table?.invert[i.to_i] if i =~ /^\d+$/
|
156
|
+
# ======================================================================= #
|
157
|
+
# Since as of June 2016, we will upcase the first character.
|
158
|
+
# ======================================================================= #
|
159
|
+
i = i.dup if i.frozen?
|
160
|
+
i[0,1] = i[0,1].upcase
|
161
|
+
@input = i
|
162
|
+
end
|
163
|
+
|
164
|
+
# ========================================================================= #
|
165
|
+
# === set_n_electrons
|
166
|
+
# ========================================================================= #
|
167
|
+
def set_n_electrons(i)
|
168
|
+
@n_electrons = i
|
169
|
+
end
|
170
|
+
|
171
|
+
# ========================================================================= #
|
172
|
+
# === periodic_table?
|
173
|
+
# ========================================================================= #
|
174
|
+
def periodic_table?
|
175
|
+
PERIODIC_TABLE_DATASET
|
176
|
+
end
|
177
|
+
|
178
|
+
# ========================================================================= #
|
179
|
+
# === default_colour
|
180
|
+
# ========================================================================= #
|
181
|
+
def default_colour
|
182
|
+
Colours::GREY
|
183
|
+
end
|
184
|
+
|
185
|
+
# ========================================================================= #
|
186
|
+
# === main_hash?
|
187
|
+
# ========================================================================= #
|
188
|
+
def main_hash?
|
189
|
+
MAIN_HASH
|
190
|
+
end
|
191
|
+
|
192
|
+
# ========================================================================= #
|
193
|
+
# === check_for_inclusion
|
194
|
+
# ========================================================================= #
|
195
|
+
def check_for_inclusion
|
196
|
+
if periodic_table?.has_key? @input
|
197
|
+
set_n_electrons periodic_table?[@input]
|
198
|
+
e rev+
|
199
|
+
'Found element '+sfancy(@input)+'. '+
|
200
|
+
'It has '+simp(@n_electrons.to_s)+' electrons.'
|
201
|
+
display_electron_configuration(@n_electrons)
|
202
|
+
else
|
203
|
+
e "Did not find element called `#{sfancy(@input)}`."
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
# ========================================================================= #
|
208
|
+
# === display_electron_configuration
|
209
|
+
#
|
210
|
+
# Show the specific electron configuration.
|
211
|
+
#
|
212
|
+
# For instance:
|
213
|
+
#
|
214
|
+
# 1s2 2s2 2p6 3s2 3p4
|
215
|
+
#
|
216
|
+
# ========================================================================= #
|
217
|
+
def display_electron_configuration(
|
218
|
+
i = @n_electrons
|
219
|
+
)
|
220
|
+
# ======================================================================= #
|
221
|
+
# Notify the user of invalid input.
|
222
|
+
# ======================================================================= #
|
223
|
+
unless main_hash?.has_key? i
|
224
|
+
e 'Note that the electron at position '+i.to_s+
|
225
|
+
' is not registered.'
|
226
|
+
end
|
227
|
+
set_main_string MAIN_HASH[i]
|
228
|
+
# ======================================================================= #
|
229
|
+
# Output it next:
|
230
|
+
# ======================================================================= #
|
231
|
+
e yellow(@_)
|
232
|
+
end
|
233
|
+
|
234
|
+
# ========================================================================= #
|
235
|
+
# === run (run tag)
|
236
|
+
# ========================================================================= #
|
237
|
+
def run
|
238
|
+
check_for_inclusion
|
239
|
+
end
|
240
|
+
|
241
|
+
end; end
|
242
|
+
|
243
|
+
if __FILE__ == $PROGRAM_NAME
|
244
|
+
include ChemistryParadise
|
245
|
+
if ARGV.first
|
246
|
+
ShowElectronConfiguration.new(ARGV.first)
|
247
|
+
else
|
248
|
+
ShowElectronConfiguration.new(ARGV)
|
249
|
+
end
|
250
|
+
end # $RUBY_CHEMISTRY/show_electron_configuration.rb
|
@@ -0,0 +1,145 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === ChemistryParadise::ShowElement
|
6
|
+
#
|
7
|
+
# Input should be something like this:
|
8
|
+
#
|
9
|
+
# show_element 'Xe+5'
|
10
|
+
#
|
11
|
+
# Usage example:
|
12
|
+
#
|
13
|
+
# ChemistryParadise::ShowElement.new(ARGV)
|
14
|
+
#
|
15
|
+
# =========================================================================== #
|
16
|
+
# require 'show_element'
|
17
|
+
# =========================================================================== #
|
18
|
+
require 'chemistry_paradise/base/base.rb'
|
19
|
+
|
20
|
+
module ChemistryParadise
|
21
|
+
|
22
|
+
class ShowElement < ::ChemistryParadise::Base # === ChemistryParadise::ShowElement
|
23
|
+
|
24
|
+
# ========================================================================= #
|
25
|
+
# === NAMESPACE
|
26
|
+
# ========================================================================= #
|
27
|
+
NAMESPACE = inspect
|
28
|
+
|
29
|
+
# ========================================================================= #
|
30
|
+
# === PERIODIC_TABLE
|
31
|
+
# ========================================================================= #
|
32
|
+
PERIODIC_TABLE = YAML.load_file(ChemistryParadise::Constants::FILE_PERIODIC_TABLE_OF_THE_ELEMENTS)
|
33
|
+
|
34
|
+
# ========================================================================= #
|
35
|
+
# === initialize
|
36
|
+
# ========================================================================= #
|
37
|
+
def initialize(
|
38
|
+
i = nil,
|
39
|
+
run_already = true
|
40
|
+
)
|
41
|
+
reset
|
42
|
+
set_input(i)
|
43
|
+
run if run_already
|
44
|
+
end
|
45
|
+
|
46
|
+
# ========================================================================= #
|
47
|
+
# === reset (reset tag)
|
48
|
+
# ========================================================================= #
|
49
|
+
def reset
|
50
|
+
set_name_of_the_element
|
51
|
+
set_relative_position
|
52
|
+
end
|
53
|
+
|
54
|
+
# ========================================================================= #
|
55
|
+
# === set_input
|
56
|
+
# ========================================================================= #
|
57
|
+
def set_input(i = '')
|
58
|
+
i = i.first if i.is_a? Array
|
59
|
+
i = i.to_s.dup if i
|
60
|
+
@input = i
|
61
|
+
process_input
|
62
|
+
end
|
63
|
+
|
64
|
+
# ========================================================================= #
|
65
|
+
# === set_relative_position
|
66
|
+
# ========================================================================= #
|
67
|
+
def set_relative_position(i = 0)
|
68
|
+
i = i.to_i if i
|
69
|
+
@relative_position = i
|
70
|
+
end
|
71
|
+
|
72
|
+
# ========================================================================= #
|
73
|
+
# === process_input
|
74
|
+
# ========================================================================= #
|
75
|
+
def process_input
|
76
|
+
if @input.include? '+'
|
77
|
+
set_batch('+')
|
78
|
+
elsif @input.include? '-'
|
79
|
+
set_batch('-')
|
80
|
+
else
|
81
|
+
set_name_of_the_element(@input)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# ========================================================================= #
|
86
|
+
# === set_batch
|
87
|
+
#
|
88
|
+
# This will set both (1) the name and (2) the relative position.
|
89
|
+
# ========================================================================= #
|
90
|
+
def set_batch(on_which_token = '+')
|
91
|
+
_ = @input.split(on_which_token)
|
92
|
+
set_name_of_the_element _[0]
|
93
|
+
_[1] = '-'+_[1].to_s if on_which_token == '-'
|
94
|
+
set_relative_position _[1]
|
95
|
+
end
|
96
|
+
|
97
|
+
# ========================================================================= #
|
98
|
+
# === new_position?
|
99
|
+
# ========================================================================= #
|
100
|
+
def new_position?
|
101
|
+
@relative_position
|
102
|
+
end
|
103
|
+
|
104
|
+
# ========================================================================= #
|
105
|
+
# === report_result
|
106
|
+
# ========================================================================= #
|
107
|
+
def report_result
|
108
|
+
current_position = PERIODIC_TABLE[@name_of_the_element]
|
109
|
+
current_position = current_position + new_position?
|
110
|
+
opnn; e PERIODIC_TABLE.invert[current_position]+' is at position '+
|
111
|
+
sfancy(current_position.to_s)+'.'
|
112
|
+
end
|
113
|
+
|
114
|
+
# ========================================================================= #
|
115
|
+
# === set_name_of_the_element
|
116
|
+
# ========================================================================= #
|
117
|
+
def set_name_of_the_element(i = nil)
|
118
|
+
# ======================================================================= #
|
119
|
+
# if the input is a number, we invert the PERIODIC_TABLE.
|
120
|
+
# ======================================================================= #
|
121
|
+
if i =~ /^\d+$/
|
122
|
+
i = PERIODIC_TABLE.invert[i.to_i]
|
123
|
+
end
|
124
|
+
@name_of_the_element = i
|
125
|
+
end
|
126
|
+
|
127
|
+
# ========================================================================= #
|
128
|
+
# === run
|
129
|
+
# ========================================================================= #
|
130
|
+
def run # (run tag)
|
131
|
+
report_result
|
132
|
+
end
|
133
|
+
|
134
|
+
# ========================================================================= #
|
135
|
+
# === opnn
|
136
|
+
# ========================================================================= #
|
137
|
+
def opnn
|
138
|
+
super(NAMESPACE)
|
139
|
+
end
|
140
|
+
|
141
|
+
end; end
|
142
|
+
|
143
|
+
if __FILE__ == $PROGRAM_NAME
|
144
|
+
ChemistryParadise::ShowElement.new(ARGV)
|
145
|
+
end # show_element 'Xe+5'
|
@@ -0,0 +1,131 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'chemistry_paradise/sinatra/sinatra.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'sinatra/base.rb'
|
8
|
+
|
9
|
+
module ChemistryParadise
|
10
|
+
|
11
|
+
class Sinatra < ::Sinatra::Base
|
12
|
+
|
13
|
+
require 'chemistry_paradise/toplevel_methods/misc.rb'
|
14
|
+
require 'chemistry_paradise/utility_scripts/calculate_atomic_mass.rb'
|
15
|
+
|
16
|
+
begin
|
17
|
+
require 'open'
|
18
|
+
rescue LoadError; end
|
19
|
+
|
20
|
+
begin
|
21
|
+
require 'colours'
|
22
|
+
include Colours
|
23
|
+
rescue LoadError; end
|
24
|
+
|
25
|
+
begin
|
26
|
+
require 'html_tags'
|
27
|
+
include HtmlTags::BaseModule
|
28
|
+
rescue LoadError; end
|
29
|
+
|
30
|
+
# ========================================================================= #
|
31
|
+
# === USE_THIS_PORT
|
32
|
+
# ========================================================================= #
|
33
|
+
USE_THIS_PORT = '4567'
|
34
|
+
|
35
|
+
set :port, USE_THIS_PORT
|
36
|
+
|
37
|
+
# ========================================================================= #
|
38
|
+
# === initialize
|
39
|
+
# ========================================================================= #
|
40
|
+
def initialize
|
41
|
+
super()
|
42
|
+
reset
|
43
|
+
if ::ChemistryParadise.is_on_roebe?
|
44
|
+
require 'open'
|
45
|
+
# ===================================================================== #
|
46
|
+
# Tell us which port will be used:
|
47
|
+
# ===================================================================== #
|
48
|
+
target = "http://localhost:#{USE_THIS_PORT}/"
|
49
|
+
e sfancy(target)
|
50
|
+
Thread.new {
|
51
|
+
Open.in_browser(target) {{ delay: '1.0 seconds' }}
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# ========================================================================= #
|
57
|
+
# === reset
|
58
|
+
# ========================================================================= #
|
59
|
+
def reset
|
60
|
+
end
|
61
|
+
|
62
|
+
# ========================================================================= #
|
63
|
+
# === return_default_header_and_title
|
64
|
+
# ========================================================================= #
|
65
|
+
def return_default_header_and_title
|
66
|
+
'<html><title>'\
|
67
|
+
'ChemistryParadise Web-API'\
|
68
|
+
'</title><body>'
|
69
|
+
end
|
70
|
+
|
71
|
+
# =========================================================================== #
|
72
|
+
# === /compound
|
73
|
+
#
|
74
|
+
# Usage Examples:
|
75
|
+
#
|
76
|
+
# http://localhost:4567/compound/H2SO4
|
77
|
+
#
|
78
|
+
# =========================================================================== #
|
79
|
+
get('/compound/*'){
|
80
|
+
_ = params[:splat]
|
81
|
+
_ = _.first if _.is_a? Array
|
82
|
+
return_default_header_and_title+
|
83
|
+
p(
|
84
|
+
'Mass of '+_.to_s+': <b>'+
|
85
|
+
ChemistryParadise.compound_mass?(_).to_s+' ame</b>'
|
86
|
+
)+
|
87
|
+
'</body></html>'
|
88
|
+
}
|
89
|
+
# =========================================================================== #
|
90
|
+
# === /compound
|
91
|
+
# =========================================================================== #
|
92
|
+
get('/compound'){
|
93
|
+
return_default_header_and_title+
|
94
|
+
p(
|
95
|
+
'Please provide an argument to <b>compound/</b>.'
|
96
|
+
)+
|
97
|
+
'</body></html>'
|
98
|
+
}
|
99
|
+
|
100
|
+
# =========================================================================== #
|
101
|
+
# === /
|
102
|
+
#
|
103
|
+
# Usage Examples:
|
104
|
+
#
|
105
|
+
# http://localhost:4567/
|
106
|
+
#
|
107
|
+
# =========================================================================== #
|
108
|
+
get('/'){
|
109
|
+
return_default_header_and_title+
|
110
|
+
p(
|
111
|
+
"Available components:<br>\n"+
|
112
|
+
'<a href="compound/">compound/</a>'
|
113
|
+
)+
|
114
|
+
'</body></html>'
|
115
|
+
}
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
# =========================================================================== #
|
120
|
+
# === ChemistryParadise.start_sinatra_interface
|
121
|
+
# =========================================================================== #
|
122
|
+
def self.start_sinatra_interface
|
123
|
+
puts 'Trying to start the sinatra-interface of ChemistryParadise next.'
|
124
|
+
::ChemistryParadise::Sinatra.run!
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
if __FILE__ == $PROGRAM_NAME
|
130
|
+
ChemistryParadise.start_sinatra_interface
|
131
|
+
end # bioroebe --sinatra
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === ChemistryParadise::Wetter::Sinatra
|
6
|
+
# =========================================================================== #
|
7
|
+
# require 'chemistry_paradise/sinatra/wetter/app.rb'
|
8
|
+
# =========================================================================== #
|
9
|
+
require 'sinatra/base.rb'
|
10
|
+
require 'chemistry_paradise/base/base.rb'
|
11
|
+
|
12
|
+
module ChemistryParadise
|
13
|
+
|
14
|
+
class Wetter < ::ChemistryParadise::Base # === ChemistryParadise::Wetter
|
15
|
+
|
16
|
+
class Sinatra < Sinatra::Base # === ChemistryParadise::Wetter::Sinatra
|
17
|
+
|
18
|
+
require 'chemistry_paradise/wetter/wetter.rb'
|
19
|
+
|
20
|
+
include Colours
|
21
|
+
|
22
|
+
require 'chemistry_paradise/www/wetter/embeddable_interface.rb'
|
23
|
+
include ChemistryParadise::Wetter::EmbeddableInterface
|
24
|
+
|
25
|
+
# ========================================================================= #
|
26
|
+
# === USE_THIS_PORT
|
27
|
+
# ========================================================================= #
|
28
|
+
USE_THIS_PORT = '4569'
|
29
|
+
|
30
|
+
set :port, USE_THIS_PORT
|
31
|
+
|
32
|
+
# ========================================================================= #
|
33
|
+
# === initialize
|
34
|
+
# ========================================================================= #
|
35
|
+
def initialize
|
36
|
+
super()
|
37
|
+
reset
|
38
|
+
if ::ChemistryParadise.is_on_roebe?
|
39
|
+
require 'open'
|
40
|
+
# ===================================================================== #
|
41
|
+
# Tell us which port will be used:
|
42
|
+
# ===================================================================== #
|
43
|
+
target = "http://localhost:#{USE_THIS_PORT}/"
|
44
|
+
Cyberweb.try_to_open_this_URL_via_the_browser(target, USE_THIS_PORT)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# ========================================================================= #
|
49
|
+
# === reset
|
50
|
+
# ========================================================================= #
|
51
|
+
def reset
|
52
|
+
end
|
53
|
+
|
54
|
+
# ========================================================================= #
|
55
|
+
# === / Entry point -> http://localhost:4569/
|
56
|
+
#
|
57
|
+
# This is the root of our web-application.
|
58
|
+
# ========================================================================= #
|
59
|
+
get('/') {
|
60
|
+
return_root_string
|
61
|
+
}
|
62
|
+
|
63
|
+
end; end; end
|
64
|
+
|
65
|
+
if __FILE__ == $PROGRAM_NAME
|
66
|
+
require 'wetter/www/start_sinatra_interface.rb'
|
67
|
+
ChemistryParadise::Wetter.start_sinatra_interface
|
68
|
+
end # wetter --sinatra
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === ChemistryParadise::Wetter
|
6
|
+
# =========================================================================== #
|
7
|
+
# require 'chemistry_paradise/sinatra/wetter/start_sinatra_interface.rb'
|
8
|
+
# =========================================================================== #
|
9
|
+
require 'chemistry_paradise/sinatra/wetter/app.rb'
|
10
|
+
require 'chemistry_paradise/base/base.rb'
|
11
|
+
|
12
|
+
module ChemistryParadise
|
13
|
+
|
14
|
+
class Wetter < ::ChemistryParadise::Base # === ChemistryParadise::Wetter
|
15
|
+
|
16
|
+
require 'cyberweb/toplevel_methods/misc.rb'
|
17
|
+
# ========================================================================= #
|
18
|
+
# === ChemistryParadise::Wetter.start_sinatra_interface
|
19
|
+
#
|
20
|
+
# This method can be used to start the sinatra interface.
|
21
|
+
# ========================================================================= #
|
22
|
+
def self.start_sinatra_interface
|
23
|
+
puts 'Trying to start the sinatra-interface for class Wetter next.'
|
24
|
+
::ChemistryParadise::Wetter::Sinatra.run!
|
25
|
+
end
|
26
|
+
|
27
|
+
end; end
|
28
|
+
|
29
|
+
if __FILE__ == $PROGRAM_NAME
|
30
|
+
ChemistryParadise::Wetter.start_sinatra_interface
|
31
|
+
end
|