chemistry_paradise 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +657 -0
- data/bin/chemistry_paradise +7 -0
- data/bin/wetter +7 -0
- data/chemistry_paradise.gemspec +46 -0
- data/doc/README.gen +595 -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/constants_for_chemical_formulas.rb +16 -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 +228 -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/utility_scripts/show_periodic_table.rb +996 -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 +139 -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 +175 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# === ChemistryParadise::SplitMoleculeNames
|
|
6
|
+
#
|
|
7
|
+
# Input to this class here can be something like 'C12H11O11'. See the
|
|
8
|
+
# bottom of this file to find out what can be done.
|
|
9
|
+
#
|
|
10
|
+
# Do not input the charge of the molecule in question.
|
|
11
|
+
# =========================================================================== #
|
|
12
|
+
# require 'chemistry_paradise/split_molecule_names.rb'
|
|
13
|
+
# =========================================================================== #
|
|
14
|
+
require 'chemistry_paradise/base/base.rb'
|
|
15
|
+
|
|
16
|
+
module ChemistryParadise
|
|
17
|
+
|
|
18
|
+
class SplitMoleculeNames < ::ChemistryParadise::Base
|
|
19
|
+
|
|
20
|
+
# ========================================================================= #
|
|
21
|
+
# === initialize
|
|
22
|
+
# ========================================================================= #
|
|
23
|
+
def initialize(
|
|
24
|
+
i = 'C12H11O11'
|
|
25
|
+
)
|
|
26
|
+
reset
|
|
27
|
+
set_input(i)
|
|
28
|
+
split # This is the actual run method.
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# ========================================================================= #
|
|
32
|
+
# === reset (reset tag)
|
|
33
|
+
# ========================================================================= #
|
|
34
|
+
def reset
|
|
35
|
+
super()
|
|
36
|
+
# ======================================================================= #
|
|
37
|
+
# === @result
|
|
38
|
+
# ======================================================================= #
|
|
39
|
+
@result = []
|
|
40
|
+
# ======================================================================= #
|
|
41
|
+
# === @total
|
|
42
|
+
# ======================================================================= #
|
|
43
|
+
@total = Hash.new(0) # Hash that keeps track of n elements each. Default value will be 0.
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# ========================================================================= #
|
|
47
|
+
# === result?
|
|
48
|
+
# ========================================================================= #
|
|
49
|
+
def result?
|
|
50
|
+
@result
|
|
51
|
+
end; alias result result? # === result
|
|
52
|
+
|
|
53
|
+
# ========================================================================= #
|
|
54
|
+
# === is_number?
|
|
55
|
+
#
|
|
56
|
+
# This returns true if the input is a number, else false. For this it
|
|
57
|
+
# uses the .to_i method trick, which returns 0 for non-numbers.
|
|
58
|
+
# ========================================================================= #
|
|
59
|
+
def is_number?(i)
|
|
60
|
+
result = (i.to_i.to_s == i)
|
|
61
|
+
return result
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# ========================================================================= #
|
|
65
|
+
# === split
|
|
66
|
+
#
|
|
67
|
+
# This method will return an array with all the elements.
|
|
68
|
+
# ========================================================================= #
|
|
69
|
+
def split(
|
|
70
|
+
i = @input
|
|
71
|
+
)
|
|
72
|
+
array = []
|
|
73
|
+
_ = ''.dup
|
|
74
|
+
i = i.first if i.is_a? Array
|
|
75
|
+
if i
|
|
76
|
+
chars = i.chars
|
|
77
|
+
chars.each_with_index {|token, index|
|
|
78
|
+
if is_number? token # We found a number here. We simply append it then.
|
|
79
|
+
_ << token # return the old data
|
|
80
|
+
elsif token.downcase == token
|
|
81
|
+
_ << token
|
|
82
|
+
else # Not a number, must be a character.
|
|
83
|
+
unless _.empty?
|
|
84
|
+
array << _
|
|
85
|
+
_ = ''.dup
|
|
86
|
+
end
|
|
87
|
+
_ = token
|
|
88
|
+
end
|
|
89
|
+
array << _ if (index + 1) == i.size
|
|
90
|
+
}
|
|
91
|
+
@result = array
|
|
92
|
+
determine_total
|
|
93
|
+
return array
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# ========================================================================= #
|
|
98
|
+
# === ignore_numbers
|
|
99
|
+
#
|
|
100
|
+
# This will ignore numbers in a guaranteed manner.
|
|
101
|
+
# ========================================================================= #
|
|
102
|
+
def ignore_numbers(i)
|
|
103
|
+
return i.gsub(/\d+/,'')
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# ========================================================================= #
|
|
107
|
+
# === return_n_elements
|
|
108
|
+
#
|
|
109
|
+
# Must return an Integer.
|
|
110
|
+
# ========================================================================= #
|
|
111
|
+
def return_n_elements(i)
|
|
112
|
+
result = 0
|
|
113
|
+
if i =~ /\d+/ # Ok has at least one number.
|
|
114
|
+
i = i[/(\d+)/][0]
|
|
115
|
+
else
|
|
116
|
+
i = 1
|
|
117
|
+
end
|
|
118
|
+
result = i.to_i
|
|
119
|
+
return result
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# ========================================================================= #
|
|
123
|
+
# === determine_total
|
|
124
|
+
#
|
|
125
|
+
# If the input is @result then it was already properly pre-sorted for us.
|
|
126
|
+
# ========================================================================= #
|
|
127
|
+
def determine_total(i = @result)
|
|
128
|
+
i.each {|entry|
|
|
129
|
+
this_real_key = ignore_numbers(entry)
|
|
130
|
+
if @total.has_key? this_real_key
|
|
131
|
+
@total[this_real_key] = @total[this_real_key]+return_n_elements(entry)
|
|
132
|
+
else # Else we must make a new key; the Laufindex kann aber 1-n sein.
|
|
133
|
+
@total[this_real_key] = return_n_elements(entry)
|
|
134
|
+
end
|
|
135
|
+
}
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# ========================================================================= #
|
|
139
|
+
# === total?
|
|
140
|
+
# ========================================================================= #
|
|
141
|
+
def total?
|
|
142
|
+
@total # This must always be a Hash.
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# ========================================================================= #
|
|
146
|
+
# === set_input
|
|
147
|
+
# ========================================================================= #
|
|
148
|
+
def set_input(i)
|
|
149
|
+
if i
|
|
150
|
+
i = i.join(' ').strip if i.is_a? Array
|
|
151
|
+
i = i.dup if i.frozen?
|
|
152
|
+
if i.include?(' ') and (i =~ /^\d+/) # starts with a number.
|
|
153
|
+
# Input is e. g. "5 H2O"
|
|
154
|
+
splitted = i.split(' ')
|
|
155
|
+
n_times = splitted.first.to_i
|
|
156
|
+
new_result = ''.dup
|
|
157
|
+
splitted.last.chars.each {|this_char|
|
|
158
|
+
if this_char =~ /\d+/
|
|
159
|
+
this_char = this_char.to_i * n_times
|
|
160
|
+
end
|
|
161
|
+
new_result << this_char.to_s
|
|
162
|
+
}
|
|
163
|
+
unless new_result[-1, 1] =~ /\d+/
|
|
164
|
+
new_result << n_times.to_s
|
|
165
|
+
end
|
|
166
|
+
i = new_result
|
|
167
|
+
end
|
|
168
|
+
i.tr!('₁', '1') if i.include? '₁'
|
|
169
|
+
i.tr!('₂', '2') if i.include? '₂'
|
|
170
|
+
i.tr!('₃', '3') if i.include? '₃'
|
|
171
|
+
i.tr!('₄', '4') if i.include? '₄'
|
|
172
|
+
i.tr!('₅', '5') if i.include? '₅'
|
|
173
|
+
i.tr!('₆', '6') if i.include? '₆'
|
|
174
|
+
i.tr!('₇', '7') if i.include? '₇'
|
|
175
|
+
i.tr!('₈', '8') if i.include? '₈'
|
|
176
|
+
i.tr!('₉', '9') if i.include? '₉'
|
|
177
|
+
i = convert_parens(i) if i.include? ')'
|
|
178
|
+
if i.include? ' '
|
|
179
|
+
i.strip!
|
|
180
|
+
if i.include? '+' # Ok, input here can be like: '2 Fe + 3 Cl2'
|
|
181
|
+
i.gsub!(/(\d)+ /,'\1')
|
|
182
|
+
i.gsub!(/ \+ /,'')
|
|
183
|
+
end
|
|
184
|
+
# ===================================================================== #
|
|
185
|
+
# But it can also include internal ' ', which we will remove next.
|
|
186
|
+
# ===================================================================== #
|
|
187
|
+
i.delete!(' ')
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
@input = i
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# =========================================================================== #
|
|
196
|
+
# === ChemistryParadise.split_this_molecular_formula_into_a_hash
|
|
197
|
+
# =========================================================================== #
|
|
198
|
+
def self.split_this_molecular_formula_into_a_hash(i)
|
|
199
|
+
i = i.first if i.is_a? Array
|
|
200
|
+
SplitMoleculeNames.new(i).result
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
if __FILE__ == $PROGRAM_NAME
|
|
206
|
+
include ChemistryParadise
|
|
207
|
+
alias e puts
|
|
208
|
+
puts 'Testing whether this class can properly Split Compound Names:'
|
|
209
|
+
if ARGV.empty?
|
|
210
|
+
pp SplitMoleculeNames.new.result
|
|
211
|
+
e
|
|
212
|
+
_ = 'P2O5'; e 'Input is: '+_; print ' '; pp SplitMoleculeNames.new(_).result
|
|
213
|
+
_ = 'C6H14N4O2'; e 'Input is: '+_; print ' '; pp SplitMoleculeNames.new(_).result
|
|
214
|
+
_ = 'Al2(SO4)3'; e 'Input is: '+_; print ' '; pp SplitMoleculeNames.new(_).result
|
|
215
|
+
_ = 'Fe(OH)3'; e 'Input is: '+_; print ' '; pp SplitMoleculeNames.new(_).result
|
|
216
|
+
_ = 'H2SO4'; e 'Input is: '+_; print ' '; pp SplitMoleculeNames.new(_).result
|
|
217
|
+
_ = '(NH₄)₂SO₄'; e 'Input is: '+_; print ' '; pp SplitMoleculeNames.new(_).result
|
|
218
|
+
_ = 'Fe2(SO4)3'; e 'Input is: '+_; print ' '; pp SplitMoleculeNames.new(_).result
|
|
219
|
+
_ = 'P2O5'; e 'Input is: '+_; print ' '; pp SplitMoleculeNames.new(_).result
|
|
220
|
+
_ = '5 H2O'; e 'Input is: '+_; print ' '; pp SplitMoleculeNames.new(_).result
|
|
221
|
+
e
|
|
222
|
+
pp SplitMoleculeNames.new('Fe2(SO4)3').total?
|
|
223
|
+
p 'Will test this input next: 2 Fe + 3 Cl2'
|
|
224
|
+
pp SplitMoleculeNames.new('2 Fe + 3 Cl2').result
|
|
225
|
+
else
|
|
226
|
+
SplitMoleculeNames.new(ARGV).result
|
|
227
|
+
end
|
|
228
|
+
end # $CHEMISTRY/split_molecule_names.rb
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'chemistry_paradise/toplevel_methods/atomgewichte.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
require 'chemistry_paradise/constants/file_constants.rb'
|
|
8
|
+
|
|
9
|
+
module ChemistryParadise
|
|
10
|
+
|
|
11
|
+
# ========================================================================= #
|
|
12
|
+
# === ChemistryParadise.file_atomgewichte
|
|
13
|
+
# ========================================================================= #
|
|
14
|
+
def self.file_atomgewichte
|
|
15
|
+
Constants::FILE_ATOMGEWICHTE
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# ========================================================================= #
|
|
19
|
+
# === ChemistryParadise.atomgewichte?
|
|
20
|
+
# ========================================================================= #
|
|
21
|
+
def self.atomgewichte?
|
|
22
|
+
require 'yaml'
|
|
23
|
+
YAML.load_file(Constants::FILE_ATOMGEWICHTE)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
if __FILE__ == $PROGRAM_NAME
|
|
29
|
+
puts ChemistryParadise.file_atomgewichte
|
|
30
|
+
pp ChemistryParadise.atomgewichte?
|
|
31
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'chemistry_paradise/toplevel_methods/convert_parens.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
module ChemistryParadise
|
|
8
|
+
|
|
9
|
+
# ========================================================================= #
|
|
10
|
+
# === ChemistryParadise.convert_parens
|
|
11
|
+
#
|
|
12
|
+
# This method will properly convert the () parens that can be found
|
|
13
|
+
# in a chemical formula.
|
|
14
|
+
#
|
|
15
|
+
# For instance:
|
|
16
|
+
#
|
|
17
|
+
# Al2(SO4)3
|
|
18
|
+
#
|
|
19
|
+
# Is effectively the same such as:
|
|
20
|
+
#
|
|
21
|
+
# Al2SO4SO4SO4
|
|
22
|
+
#
|
|
23
|
+
# ========================================================================= #
|
|
24
|
+
def self.convert_parens(i)
|
|
25
|
+
if i.is_a? Array
|
|
26
|
+
i.each {|entry| convert_parens(entry) }
|
|
27
|
+
else
|
|
28
|
+
i = i.dup if i.frozen?
|
|
29
|
+
i.tr!('₁', '1') if i.include? '₁'
|
|
30
|
+
i.tr!('₂', '2') if i.include? '₂'
|
|
31
|
+
i.tr!('₃', '3') if i.include? '₃'
|
|
32
|
+
i.tr!('₄', '4') if i.include? '₄'
|
|
33
|
+
i.tr!('₅', '5') if i.include? '₅'
|
|
34
|
+
i.tr!('₆', '6') if i.include? '₆'
|
|
35
|
+
i.tr!('₇', '7') if i.include? '₇'
|
|
36
|
+
i.tr!('₈', '8') if i.include? '₈'
|
|
37
|
+
i.tr!('₉', '9') if i.include? '₉'
|
|
38
|
+
if i.include? '('
|
|
39
|
+
n_parens = i.count('(')
|
|
40
|
+
if n_parens > 1 # Ok, this may be a really complex formula, like:
|
|
41
|
+
# Fe(OH)3 + H2SO4 -> Fe2(SO4)3 + H2O
|
|
42
|
+
splitted = i.split(' ')
|
|
43
|
+
splitted = splitted.map {|entry| convert_parens(entry) } # For now we remove some things.
|
|
44
|
+
return splitted.join(' ')
|
|
45
|
+
else
|
|
46
|
+
regex = /\((.+)\)(\d)([A-Za-z]{0,3}\d{0,3})/ # See: https://rubular.com/r/clShxRBIpzEtlF
|
|
47
|
+
i =~ regex
|
|
48
|
+
i = i[0, i.index('(')]
|
|
49
|
+
i << $1 * $2.to_i # Which group * n repetition
|
|
50
|
+
i << $3.dup if $3
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
return i
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
if __FILE__ == $PROGRAM_NAME
|
|
60
|
+
alias e puts
|
|
61
|
+
e ChemistryParadise.convert_parens('Al2(SO4)3')
|
|
62
|
+
e ChemistryParadise.convert_parens('(NH4)2SO4')
|
|
63
|
+
e ChemistryParadise.convert_parens('(NH₄)₂SO₄')
|
|
64
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'chemistry_paradise/toplevel_methods/display_where_the_molmasses_are_kept.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
require 'chemistry_paradise/toplevel_methods/e.rb'
|
|
8
|
+
require 'chemistry_paradise/requires/common_external_requires.rb'
|
|
9
|
+
require 'chemistry_paradise/constants/file_constants.rb'
|
|
10
|
+
|
|
11
|
+
module ChemistryParadise
|
|
12
|
+
|
|
13
|
+
# ========================================================================= #
|
|
14
|
+
# === ChemistryParadise.display_where_the_molmasses_are_kept
|
|
15
|
+
# ========================================================================= #
|
|
16
|
+
def self.display_where_the_molmasses_are_kept
|
|
17
|
+
Colours.e(Constants::FILE_ATOMGEWICHTE)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
if __FILE__ == $PROGRAM_NAME
|
|
23
|
+
ChemistryParadise.display_where_the_molmasses_are_kept
|
|
24
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'chemistry_paradise/toplevel_methods/e.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
module ChemistryParadise
|
|
8
|
+
|
|
9
|
+
# ========================================================================= #
|
|
10
|
+
# === ChemistryParadise.e
|
|
11
|
+
# ========================================================================= #
|
|
12
|
+
def self.e(i = '')
|
|
13
|
+
puts i
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'chemistry_paradise/toplevel_methods/kelvin.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
module ChemistryParadise
|
|
8
|
+
|
|
9
|
+
# ========================================================================= #
|
|
10
|
+
# === ChemistryParadise.kelvin
|
|
11
|
+
#
|
|
12
|
+
# This method will output how many Kelvin n Celsius are.
|
|
13
|
+
#
|
|
14
|
+
# The temperature T in Kelvin (K) is equal to the temperature T in
|
|
15
|
+
# degrees Celsius (°C) plus 273.1.
|
|
16
|
+
#
|
|
17
|
+
# The formula thus is:
|
|
18
|
+
#
|
|
19
|
+
# T(K) = T(°C) + 273.15
|
|
20
|
+
#
|
|
21
|
+
# ========================================================================= #
|
|
22
|
+
def self.kelvin(n_celsius)
|
|
23
|
+
if n_celsius.is_a? Array
|
|
24
|
+
n_celsius = n_celsius.first
|
|
25
|
+
end
|
|
26
|
+
n_kelvin = n_celsius.to_f + 273.15
|
|
27
|
+
return n_kelvin
|
|
28
|
+
end; self.instance_eval { alias celsius_to_kelvin kelvin } # === ChemistryParadise.celsius_to_kelvin
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
if __FILE__ == $PROGRAM_NAME
|
|
33
|
+
puts ChemistryParadise.kelvin(ARGV)
|
|
34
|
+
end # kelvin 37
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# This class can help set a different language for the project. By default,
|
|
6
|
+
# the german language is used, but you can call the module-method below,
|
|
7
|
+
# called ChemistryParadise.use_english, to enable english instead.
|
|
8
|
+
# =========================================================================== #
|
|
9
|
+
# require 'chemistry_paradise/toplevel_methods/language.rb'
|
|
10
|
+
# =========================================================================== #
|
|
11
|
+
module ChemistryParadise
|
|
12
|
+
|
|
13
|
+
# ========================================================================= #
|
|
14
|
+
# === @use_this_language
|
|
15
|
+
# ========================================================================= #
|
|
16
|
+
@use_this_language = :german
|
|
17
|
+
|
|
18
|
+
# ========================================================================= #
|
|
19
|
+
# === ChemistryParadise.set_use_this_language
|
|
20
|
+
# ========================================================================= #
|
|
21
|
+
def self.set_use_this_language(i = :german)
|
|
22
|
+
@use_this_language = i
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# ========================================================================= #
|
|
26
|
+
# === ChemistryParadise.use_which_language?
|
|
27
|
+
# ========================================================================= #
|
|
28
|
+
def self.use_which_language?
|
|
29
|
+
@use_this_language
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# ========================================================================= #
|
|
33
|
+
# === ChemistryParadise.do_use_english
|
|
34
|
+
#
|
|
35
|
+
# Use this method if you want to use the english language.
|
|
36
|
+
# ========================================================================= #
|
|
37
|
+
def self.do_use_english
|
|
38
|
+
set_use_this_language(:english)
|
|
39
|
+
end; self.instance_eval { alias use_english do_use_english } # === ChemistryParadise.use_english
|
|
40
|
+
|
|
41
|
+
# ========================================================================= #
|
|
42
|
+
# === ChemistryParadise.do_use_german
|
|
43
|
+
#
|
|
44
|
+
# Use this method if you want to use the german language.
|
|
45
|
+
# ========================================================================= #
|
|
46
|
+
def self.do_use_german
|
|
47
|
+
set_use_this_language(:german)
|
|
48
|
+
end; self.instance_eval { alias use_german do_use_german } # === ChemistryParadise.use_german
|
|
49
|
+
|
|
50
|
+
end
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'chemistry_paradise/toplevel_methods/misc.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
module ChemistryParadise
|
|
8
|
+
|
|
9
|
+
# ========================================================================= #
|
|
10
|
+
# === ChemistryParadise.row1
|
|
11
|
+
#
|
|
12
|
+
# Return the first row of the periodic table.
|
|
13
|
+
# ========================================================================= #
|
|
14
|
+
def self.row1
|
|
15
|
+
return %w( H He )
|
|
16
|
+
end; self.instance_eval { alias period1 row1 } # === ChemistryParadise.period1
|
|
17
|
+
|
|
18
|
+
# ========================================================================= #
|
|
19
|
+
# === ChemistryParadise.row2
|
|
20
|
+
#
|
|
21
|
+
# Return the second row of the periodic table.
|
|
22
|
+
# ========================================================================= #
|
|
23
|
+
def self.row2
|
|
24
|
+
return %w( Li Be B C N O F Ne )
|
|
25
|
+
end; self.instance_eval { alias period2 row2 } # === ChemistryParadise.period2
|
|
26
|
+
|
|
27
|
+
# ========================================================================= #
|
|
28
|
+
# === ChemistryParadise.row3
|
|
29
|
+
#
|
|
30
|
+
# Return the third row of the periodic table.
|
|
31
|
+
# ========================================================================= #
|
|
32
|
+
def self.row3
|
|
33
|
+
return %w( Na Mg Al Si P S Cl Ar )
|
|
34
|
+
end; self.instance_eval { alias period3 row3 } # === ChemistryParadise.period3
|
|
35
|
+
|
|
36
|
+
# ========================================================================= #
|
|
37
|
+
# === ChemistryParadise.row4
|
|
38
|
+
#
|
|
39
|
+
# Return the fourth row of the periodic table.
|
|
40
|
+
# ========================================================================= #
|
|
41
|
+
def self.row4
|
|
42
|
+
return %w( K Ca Sc Ti V Cr Mn Fe Co Ni Cu Zn Ga Ge As Se Br Kr )
|
|
43
|
+
end; self.instance_eval { alias period4 row4 } # === ChemistryParadise.period4
|
|
44
|
+
|
|
45
|
+
# ========================================================================= #
|
|
46
|
+
# === ChemistryParadise.row5
|
|
47
|
+
#
|
|
48
|
+
# Return the fifth row of the periodic table.
|
|
49
|
+
# ========================================================================= #
|
|
50
|
+
def self.row5
|
|
51
|
+
return %w( Rb Sr Y Zr Nb Mo Tc Ru Rh Pd Ag Cd In Sn Sb Te I Xe )
|
|
52
|
+
end; self.instance_eval { alias period5 row5 } # === ChemistryParadise.period5
|
|
53
|
+
|
|
54
|
+
# ========================================================================= #
|
|
55
|
+
# === ChemistryParadise.row6
|
|
56
|
+
#
|
|
57
|
+
# Return the sixth row of the periodic table.
|
|
58
|
+
# ========================================================================= #
|
|
59
|
+
def self.row6
|
|
60
|
+
return %w( Cs Ba Lu Hf Ta W Re Os Ir Pt Au Hg Tl Pb Bi Po At Rn )
|
|
61
|
+
end; self.instance_eval { alias period6 row6 } # === ChemistryParadise.period6
|
|
62
|
+
|
|
63
|
+
# ========================================================================= #
|
|
64
|
+
# === ChemistryParadise.row7
|
|
65
|
+
#
|
|
66
|
+
# Return the seventh row of the periodic table.
|
|
67
|
+
# ========================================================================= #
|
|
68
|
+
def self.row7
|
|
69
|
+
return %w( Fr Ra Lr Rf Db Sg Bh Hs Mt Ds Rg Cn Nh Fl Mc Lv Ts Og )
|
|
70
|
+
end; self.instance_eval { alias period7 row7 } # === ChemistryParadise.period7
|
|
71
|
+
|
|
72
|
+
# ========================================================================= #
|
|
73
|
+
# === ChemistryParadise.row8
|
|
74
|
+
#
|
|
75
|
+
# This is not a real row - just a helper row.
|
|
76
|
+
# ========================================================================= #
|
|
77
|
+
def self.row8
|
|
78
|
+
return %w( La Ce Pr Nd Pm Sm Eu Gd Tb Dy Ho Er Tm Yb )
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# ========================================================================= #
|
|
82
|
+
# === ChemistryParadise.row9
|
|
83
|
+
#
|
|
84
|
+
# This is not a real row - just a helper row.
|
|
85
|
+
# ========================================================================= #
|
|
86
|
+
def self.row9
|
|
87
|
+
return %w( Ac Th Pa U Np Pu Am Cm Bk Cf Es Fm Md No )
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# ========================================================================= #
|
|
91
|
+
# === ChemistryParadise.sanitize
|
|
92
|
+
#
|
|
93
|
+
# Usage example:
|
|
94
|
+
#
|
|
95
|
+
# ChemistryParadise.sanitize('C6H13N3O3') # => "C₆H₁₃N₃O₃"
|
|
96
|
+
#
|
|
97
|
+
# ========================================================================= #
|
|
98
|
+
def self.sanitize(i)
|
|
99
|
+
if i.is_a? Array
|
|
100
|
+
i = i.first
|
|
101
|
+
end
|
|
102
|
+
i = i.dup
|
|
103
|
+
i.gsub!(/1/, '₁')
|
|
104
|
+
i.gsub!(/2/, '₂')
|
|
105
|
+
i.gsub!(/3/, '₃')
|
|
106
|
+
i.gsub!(/4/, '₄')
|
|
107
|
+
i.gsub!(/5/, '₅')
|
|
108
|
+
i.gsub!(/6/, '₆')
|
|
109
|
+
i.gsub!(/7/, '₇')
|
|
110
|
+
i.gsub!(/8/, '₈')
|
|
111
|
+
i.gsub!(/9/, '₉')
|
|
112
|
+
i.gsub!(/0/, '₀')
|
|
113
|
+
return i
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# ========================================================================= #
|
|
117
|
+
# === ChemistryParadise.calculate_atomic_mass_based_on_isotope_percentage
|
|
118
|
+
#
|
|
119
|
+
# This method accepts as many arguments as the user wants to.
|
|
120
|
+
#
|
|
121
|
+
# It has to follow a specific format. The first entry must be
|
|
122
|
+
# the "Häufigkeit" and the second entry must be the corresponding
|
|
123
|
+
# atomic mass ("relative_atommasse").
|
|
124
|
+
#
|
|
125
|
+
# Usage example:
|
|
126
|
+
#
|
|
127
|
+
# ChemistryParadise.calculate_atomic_mass_based_on_isotope_percentage(78.99, 23.985, 10.00, 24.985, 11.01, 25.983)
|
|
128
|
+
#
|
|
129
|
+
# ========================================================================= #
|
|
130
|
+
def self.calculate_atomic_mass_based_on_isotope_percentage(*array)
|
|
131
|
+
round_to_n_positions = 3
|
|
132
|
+
result = 0
|
|
133
|
+
array.map! {|entry| entry.to_s.tr(',','.').to_f }
|
|
134
|
+
entries = array.each_slice(2)
|
|
135
|
+
entries.each {|häufigkeit, relative_atommasse|
|
|
136
|
+
if häufigkeit > 0
|
|
137
|
+
häufigkeit = häufigkeit / 100.0
|
|
138
|
+
end
|
|
139
|
+
zwischenergebnis = relative_atommasse * häufigkeit
|
|
140
|
+
result += zwischenergebnis
|
|
141
|
+
}
|
|
142
|
+
return result.round(round_to_n_positions)
|
|
143
|
+
end; self.instance_eval { alias berechne_atommasse calculate_atomic_mass_based_on_isotope_percentage } # === ChemistryParadise.berechne_atommasse
|
|
144
|
+
|
|
145
|
+
# ========================================================================= #
|
|
146
|
+
# === ChemistryParadise.torr_to_bar
|
|
147
|
+
#
|
|
148
|
+
# This method can be used to convert n Torr into n bar.
|
|
149
|
+
#
|
|
150
|
+
# The first argument is "n Torr".
|
|
151
|
+
#
|
|
152
|
+
# The result will be in "n bar".
|
|
153
|
+
# ========================================================================= #
|
|
154
|
+
def self.torr_to_bar(i = 720)
|
|
155
|
+
if i.is_a? Array
|
|
156
|
+
i = i.first
|
|
157
|
+
end
|
|
158
|
+
result = i.to_f * (1.013 / 760)
|
|
159
|
+
rounded_result = result.round(3)
|
|
160
|
+
beautified_result = '%.3f' % rounded_result
|
|
161
|
+
return beautified_result
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# ========================================================================= #
|
|
165
|
+
# === ChemistryParadise.log
|
|
166
|
+
#
|
|
167
|
+
# Calculate the log of something.
|
|
168
|
+
# ========================================================================= #
|
|
169
|
+
def self.log(of)
|
|
170
|
+
return Math.log10(of)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
require 'chemistry_paradise/constants/file_constants.rb'
|
|
174
|
+
require 'chemistry_paradise/split_molecule_names.rb'
|
|
175
|
+
# ========================================================================= #
|
|
176
|
+
# === ChemistryParadise.logempirische_formel
|
|
177
|
+
#
|
|
178
|
+
# This variant is german.
|
|
179
|
+
#
|
|
180
|
+
# We will assume 100 g as input.
|
|
181
|
+
# ========================================================================= #
|
|
182
|
+
def self.empirische_formel(
|
|
183
|
+
i = 'KClO4', # 'H2O'
|
|
184
|
+
round_to_n_decimal_positions = 2
|
|
185
|
+
)
|
|
186
|
+
i = i.to_s.strip.dup
|
|
187
|
+
require 'yaml'
|
|
188
|
+
dataset = YAML.load_file(Constants::FILE_ATOMGEWICHTE)
|
|
189
|
+
# ======================================================================= #
|
|
190
|
+
# So, 100 g H2O here.
|
|
191
|
+
# ======================================================================= #
|
|
192
|
+
array = SplitMoleculeNames.new(i).result
|
|
193
|
+
hash = {} # Store the mol here.
|
|
194
|
+
result = {}
|
|
195
|
+
# ======================================================================= #
|
|
196
|
+
# array may look like this: ["H2", "O"]
|
|
197
|
+
# ======================================================================= #
|
|
198
|
+
array.each {|entry|
|
|
199
|
+
n_times = 1
|
|
200
|
+
if entry =~ /\d+/ # At the least one number.
|
|
201
|
+
n_times = entry.scan(/\d+/).flatten.first.to_i
|
|
202
|
+
# =================================================================== #
|
|
203
|
+
# Now remove the number.
|
|
204
|
+
# =================================================================== #
|
|
205
|
+
entry.gsub!(/\d+/,'')
|
|
206
|
+
end
|
|
207
|
+
key = dataset[entry]
|
|
208
|
+
molmass = key * n_times
|
|
209
|
+
hash[entry] = molmass
|
|
210
|
+
}
|
|
211
|
+
total_mass = hash.values.sum
|
|
212
|
+
hash.each_pair {|key, value|
|
|
213
|
+
new_value = (100.0 / total_mass) * value
|
|
214
|
+
if round_to_n_decimal_positions
|
|
215
|
+
new_value = new_value.round(round_to_n_decimal_positions)
|
|
216
|
+
end
|
|
217
|
+
result[key] = new_value
|
|
218
|
+
}
|
|
219
|
+
return result
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
if __FILE__ == $PROGRAM_NAME
|
|
225
|
+
alias e puts
|
|
226
|
+
pp ChemistryParadise.empirische_formel
|
|
227
|
+
e ChemistryParadise.torr_to_bar(720).to_s+' bar'
|
|
228
|
+
end
|