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.

Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +222 -0
  3. data/bin/chemistry_paradise +7 -0
  4. data/chemistry_paradise.gemspec +45 -0
  5. data/doc/BUGS.md +16 -0
  6. data/doc/README.gen +205 -0
  7. data/doc/TODO.md +13 -0
  8. data/lib/chemistry_paradise.rb +6 -0
  9. data/lib/chemistry_paradise/base/base.rb +101 -0
  10. data/lib/chemistry_paradise/base/colours.rb +65 -0
  11. data/lib/chemistry_paradise/calculate_atomic_mass.rb +487 -0
  12. data/lib/chemistry_paradise/combustion_analysis.rb +181 -0
  13. data/lib/chemistry_paradise/commandline/help.rb +35 -0
  14. data/lib/chemistry_paradise/commandline/menu.rb +80 -0
  15. data/lib/chemistry_paradise/commandline/parse_commandline.rb +94 -0
  16. data/lib/chemistry_paradise/constants/constants.rb +52 -0
  17. data/lib/chemistry_paradise/constants/file_constants.rb +27 -0
  18. data/lib/chemistry_paradise/constants/german_names_of_elements_to_element_symbol.rb +157 -0
  19. data/lib/chemistry_paradise/converters/celsius_to_fahrenheit.rb +134 -0
  20. data/lib/chemistry_paradise/converters/fahrenheit_to_celsius.rb +122 -0
  21. data/lib/chemistry_paradise/converters/shared.rb +15 -0
  22. data/lib/chemistry_paradise/electron_negativity_chart.rb +78 -0
  23. data/lib/chemistry_paradise/equalize_chemical_formula.rb +82 -0
  24. data/lib/chemistry_paradise/equation_solver.rb +130 -0
  25. data/lib/chemistry_paradise/interactive_chemistry_shell.rb +241 -0
  26. data/lib/chemistry_paradise/orbitals.rb +65 -0
  27. data/lib/chemistry_paradise/project/project_base_directory.rb +24 -0
  28. data/lib/chemistry_paradise/requires/common_external_requires.rb +17 -0
  29. data/lib/chemistry_paradise/shared.rb +162 -0
  30. data/lib/chemistry_paradise/show_electron_configuration.rb +243 -0
  31. data/lib/chemistry_paradise/show_electron_negativity_of_this_element.rb +101 -0
  32. data/lib/chemistry_paradise/show_element.rb +141 -0
  33. data/lib/chemistry_paradise/split_molecule_names.rb +185 -0
  34. data/lib/chemistry_paradise/toplevel_methods/atomgewichte.rb +31 -0
  35. data/lib/chemistry_paradise/toplevel_methods/display_where_the_molmasses_are_kept.rb +24 -0
  36. data/lib/chemistry_paradise/toplevel_methods/e.rb +16 -0
  37. data/lib/chemistry_paradise/toplevel_methods/kelvin.rb +34 -0
  38. data/lib/chemistry_paradise/toplevel_methods/language.rb +50 -0
  39. data/lib/chemistry_paradise/toplevel_methods/periodic_table.rb +16 -0
  40. data/lib/chemistry_paradise/toplevel_methods/remove_this_molecule_from.rb +63 -0
  41. data/lib/chemistry_paradise/toplevel_methods/show_electron_negativity_chart.rb +26 -0
  42. data/lib/chemistry_paradise/verbose_chemical_calculation.rb +21 -0
  43. data/lib/chemistry_paradise/version/version.rb +19 -0
  44. data/lib/chemistry_paradise/yaml/atomgewichte.yml +109 -0
  45. data/lib/chemistry_paradise/yaml/electron_negativity_chart.yml +109 -0
  46. data/lib/chemistry_paradise/yaml/molecular_formula_of_different_molecules.yml +12 -0
  47. data/test/testing_chemistry_paradise.rb +49 -0
  48. metadata +138 -0
@@ -0,0 +1,181 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === ChemistryParadise::CombustionAnalysis
6
+ #
7
+ # This class can be used to calculate the molar coefficients of
8
+ # a compound that has been analysed through a combustion analysis.
9
+ #
10
+ # Usage example:
11
+ #
12
+ # ChemistryParadise::CombustionAnalysis.new(ARGV)
13
+ #
14
+ # =========================================================================== #
15
+ # require 'chemistry_paradise/combustion_analysis.rb'
16
+ # ChemistryParadise::CombustionAnalysis.new(ARGV)
17
+ # =========================================================================== #
18
+ require 'chemistry_paradise/base/base.rb'
19
+
20
+ module ChemistryParadise
21
+
22
+ class CombustionAnalysis < Base # === ChemistryParadise::CombustionAnalysis
23
+
24
+ # ========================================================================= #
25
+ # === initialize
26
+ # ========================================================================= #
27
+ def initialize(
28
+ commandline_arguments = nil,
29
+ run_already = true
30
+ )
31
+ reset
32
+ set_commandline_arguments(
33
+ commandline_arguments
34
+ )
35
+ run if run_already
36
+ end
37
+
38
+ # ========================================================================= #
39
+ # === reset (reset tag)
40
+ # ========================================================================= #
41
+ def reset
42
+ super()
43
+ # ======================================================================= #
44
+ # === @hash_ratio
45
+ # ======================================================================= #
46
+ @hash_ratio = {}
47
+ end
48
+
49
+ # ========================================================================= #
50
+ # === parse_the_main_input
51
+ # ========================================================================= #
52
+ def parse_the_main_input(i)
53
+ dataset = YAML.load_file(FILE_ATOMGEWICHTE)
54
+ # ======================================================================= #
55
+ # Currently we require that the String has '%' inserted appropriately.
56
+ # ======================================================================= #
57
+ if i.is_a?(String) and i.include?('%')
58
+ splitted = i.split('%').map(&:strip)
59
+ # ===================================================================== #
60
+ # splitted is now:
61
+ #
62
+ # ["K 28,93", "S 23,72", "O 47.35"]
63
+ #
64
+ # ===================================================================== #
65
+ splitted.each {|entry|
66
+ entry.tr!(',','.')
67
+ inner_splitted = entry.split(' ')
68
+ first = inner_splitted.first
69
+ last = inner_splitted.last.to_f
70
+ @hash_ratio[first] = last / dataset[first]
71
+ }
72
+ end
73
+ end
74
+
75
+ # ========================================================================= #
76
+ # === work_on_the_hash_ratio
77
+ # ========================================================================= #
78
+ def work_on_the_hash_ratio
79
+ # ======================================================================= #
80
+ # The Hash may look like this:
81
+ #
82
+ # { "K"=>0.7399355465752724,
83
+ # "S"=>0.7397473881178855,
84
+ # "O"=>2.959559972498281}
85
+ #
86
+ # ======================================================================= #
87
+ min_element = @hash_ratio.min
88
+ ratio = 1.0 / min_element.last
89
+ @hash_ratio.transform_values! {|values|
90
+ (values * ratio).round(1)
91
+ }
92
+ if does_the_main_hash_have_an_uneven_value?
93
+ further_process_the_main_hash
94
+ end
95
+ end
96
+
97
+ # ========================================================================= #
98
+ # === further_process_the_main_hash
99
+ #
100
+ # This method is specifically to turn e. g. a 1.5 into a 3.0.
101
+ # ========================================================================= #
102
+ def further_process_the_main_hash
103
+ first_zero_point_result = @hash_ratio.select {|key, value|
104
+ value - value.floor == 0.5
105
+ }
106
+ if first_zero_point_result
107
+ # ===================================================================== #
108
+ # This may be:
109
+ #
110
+ # {"S"=>1.5}
111
+ #
112
+ # ===================================================================== #
113
+ @hash_ratio.transform_values! {|value|
114
+ value * 2.0
115
+ }
116
+ end
117
+ end
118
+
119
+ # ========================================================================= #
120
+ # === does_the_main_hash_have_an_uneven_value?
121
+ #
122
+ # This method will return true if we have an uneven value in the
123
+ # main Hash, such as 1.5.
124
+ # ========================================================================= #
125
+ def does_the_main_hash_have_an_uneven_value?
126
+ @hash_ratio.values.any? {|entry|
127
+ (entry - entry.floor) > 0
128
+ }
129
+ end
130
+
131
+ # ========================================================================= #
132
+ # === hash_ratio?
133
+ # ========================================================================= #
134
+ def hash_ratio?
135
+ @hash_ratio
136
+ end; alias hash? hash_ratio? # === hash?
137
+
138
+ # ========================================================================= #
139
+ # === report
140
+ # ========================================================================= #
141
+ def report
142
+ result = @hash_ratio.map {|k, v|
143
+ v = v.to_i
144
+ case v
145
+ when 1
146
+ v = ''
147
+ when 2
148
+ v = '₂'
149
+ when 3
150
+ v = '₃'
151
+ when 4
152
+ v = '₄'
153
+ end
154
+ "#{k}#{v}"
155
+ }.join
156
+ e result
157
+ end
158
+
159
+ # ========================================================================= #
160
+ # === run (run tag)
161
+ # ========================================================================= #
162
+ def run
163
+ _ = first?
164
+ parse_the_main_input(_)
165
+ work_on_the_hash_ratio
166
+ report
167
+ end
168
+
169
+ # ========================================================================= #
170
+ # === CombustionAnalysis[]
171
+ # ========================================================================= #
172
+ def self.[](i = '')
173
+ new(i)
174
+ end
175
+
176
+ end; end
177
+
178
+ if __FILE__ == $PROGRAM_NAME
179
+ ChemistryParadise::CombustionAnalysis.new(ARGV)
180
+ end # combustionanalysis "K 28,93% S 23,72% O 47.35%"
181
+ # combustionanalysis "Al 15,77% O 56,12% S 28,11%"
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'chemistry_paradise/commandline/help.rb'
6
+ # =========================================================================== #
7
+ module ChemistryParadise
8
+
9
+ class ParseCommandline < ::ChemistryParadise::Base
10
+
11
+ # ========================================================================= #
12
+ # === show_help
13
+ #
14
+ # The help options can be queried via:
15
+ # chemistry_paradise --help
16
+ # ========================================================================= #
17
+ def show_help
18
+ e 'The following options are documented:'
19
+ e
20
+ e ' --molmassen? # show '\
21
+ 'where the molmasses are kept (a file)'
22
+ e ' --electronegativity-of=F/Fe # report '\
23
+ 'the electronegativitiy of the elements F '\
24
+ 'and Fe (Fluor and Iron)'
25
+ e ' --show_electron_negativity_chart # show '\
26
+ 'the electron negativity chart of the atoms'
27
+ e ' /Quecksilber/ # use '\
28
+ 'a pseudo-regex to obtain the element-symbol '\
29
+ 'from a german name'
30
+ e ' ^^^ the above // is called a pseudo-regex; pseudo '\
31
+ 'because it is actually a String and not a regex'
32
+ e
33
+ end
34
+
35
+ end; end
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === ChemistryParadise::ParseCommandline
6
+ # =========================================================================== #
7
+ # require 'chemistry_paradise/commandline/menu.rb'
8
+ # =========================================================================== #
9
+ require 'chemistry_paradise/base/base.rb'
10
+ require 'chemistry_paradise/toplevel_methods/display_where_the_molmasses_are_kept.rb'
11
+ require 'chemistry_paradise/toplevel_methods/show_electron_negativity_chart.rb'
12
+ require 'chemistry_paradise/show_electron_negativity_of_this_element.rb'
13
+
14
+ module ChemistryParadise
15
+
16
+ class ParseCommandline < ::ChemistryParadise::Base # === ChemistryParadise::ParseCommandline
17
+
18
+ # ========================================================================= #
19
+ # === menu (menu tag)
20
+ # ========================================================================= #
21
+ def menu(
22
+ i = @commandline
23
+ )
24
+ if i.is_a? Array
25
+ i.each {|entry| menu(entry) }
26
+ else
27
+ case i
28
+ # ===================================================================== #
29
+ # === chemistry_paradise --periodic-table
30
+ # ===================================================================== #
31
+ when /^-?-?periodic(_|-)?table$/i
32
+ show_the_periodic_table
33
+ exit
34
+ # ===================================================================== #
35
+ # === chemistry_paradise --electronegativity-of=F/Fe
36
+ # ===================================================================== #
37
+ when /-?-?electronegativity(_|-)?of=(.+)/
38
+ these_elements = $2.to_s.dup.strip
39
+ if these_elements.include? '/'
40
+ these_elements = these_elements.split('/')
41
+ end
42
+ ChemistryParadise::ShowElectronNegativityOfThisElement.new(these_elements)
43
+ # ===================================================================== #
44
+ # === chemistry_paradise show_electron_negativity_chart
45
+ # ===================================================================== #
46
+ when /show(_|-)?electron(_|-)?negativity(_|-)?chart/
47
+ show_electron_negativity_chart
48
+ # ===================================================================== #
49
+ # === chemistry_paradise test_which_molecules?
50
+ # ===================================================================== #
51
+ when /test(_|-)?which(_|-)?molecules\??/
52
+ pp ARRAY_TEST_THESE_MOLECULES
53
+ # ===================================================================== #
54
+ # === chemistry_paradise --molmassen?
55
+ # ===================================================================== #
56
+ when /molmassen\??/,
57
+ /display(_|-)?molmassen(_|-)?file/,
58
+ /display(_|-)?where(_|-)?the(_|-)?molmasses(_|-)?are(_|-)?kept/
59
+ ::ChemistryParadise.display_where_the_molmasses_are_kept
60
+ # ===================================================================== #
61
+ # === chemistry_paradise --help
62
+ # ===================================================================== #
63
+ when /^-?-?help/
64
+ show_help
65
+ else
66
+ if i.start_with?('/') and i.end_with?('/')
67
+ # ================================================================= #
68
+ # Assume this to be a pseudo-regex.
69
+ # ================================================================= #
70
+ search_for_this_element = i.delete('/').capitalize
71
+ _ = ChemistryParadise.return_element_symbol_from_this_german_name(search_for_this_element)
72
+ if _
73
+ e simp(search_for_this_element)+' corresponds to '+sfancy(_)+'.'
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end; alias check_against_menu menu # === check_against_menu
79
+
80
+ end; end
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === ChemistryParadise::ParseCommandline
6
+ #
7
+ # Use this class in order to parse the commandline.
8
+ # =========================================================================== #
9
+ # require 'chemistry_paradise/commandline/parse_commandline.rb'
10
+ # =========================================================================== #
11
+ require 'chemistry_paradise/base/base.rb'
12
+ require 'chemistry_paradise/commandline/menu.rb'
13
+ require 'chemistry_paradise/commandline/help.rb'
14
+
15
+ module ChemistryParadise
16
+
17
+ class ParseCommandline < ::ChemistryParadise::Base # === ChemistryParadise::ParseCommandline
18
+
19
+ # ========================================================================= #
20
+ # === initialize
21
+ # ========================================================================= #
22
+ def initialize(
23
+ optional_input = ARGV,
24
+ run_already = true
25
+ )
26
+ set_commandline(optional_input)
27
+ reset
28
+ run if run_already
29
+ end
30
+
31
+ # ========================================================================= #
32
+ # === reset
33
+ # ========================================================================= #
34
+ def reset
35
+ super()
36
+ end
37
+
38
+ # ========================================================================= #
39
+ # === show_the_periodic_table
40
+ # ========================================================================= #
41
+ def show_the_periodic_table
42
+ _ = ::ChemistryParadise.periodic_table?
43
+ if File.exist? _
44
+ YAML.load_file(_).each_pair {|key, value|
45
+ e ' '+(key.to_s+ ':').ljust(3)+' '+value.to_s.rjust(2)
46
+ }
47
+ end
48
+ end
49
+
50
+ # ========================================================================= #
51
+ # === set_commandline
52
+ # ========================================================================= #
53
+ def set_commandline(i)
54
+ i = [i] unless i.is_a? Array
55
+ @commandline = i
56
+ end
57
+
58
+ # ========================================================================= #
59
+ # === run
60
+ # ========================================================================= #
61
+ def run
62
+ menu
63
+ end
64
+
65
+ # ========================================================================= #
66
+ # === berechne_atomgewicht
67
+ # ========================================================================= #
68
+ def berechne_atomgewicht(i)
69
+ pp i
70
+ if i.is_a? Array
71
+ i.flatten.each {|entry|
72
+ berechne_atomgewicht(i)
73
+ }
74
+ else
75
+ if i == :test_default_molecules
76
+ i = ARRAY_TEST_THESE_MOLECULES
77
+ end
78
+ if i.is_a? Array
79
+ berechne_atomgewicht(i)
80
+ else
81
+ e sprintf(
82
+ 'The mass number of %-4s is %3s',
83
+ i,
84
+ ChemistryParadise::CalculateAtomicMass.new(i).result.to_s
85
+ )
86
+ end
87
+ end
88
+ end
89
+
90
+ end; end
91
+
92
+ if __FILE__ == $PROGRAM_NAME
93
+ ChemistryParadise::ParseCommandline.new(ARGV)
94
+ end
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'chemistry_paradise/constants/constants.rb'
6
+ # =========================================================================== #
7
+ require 'yaml'
8
+ require 'chemistry_paradise/constants/file_constants.rb'
9
+
10
+ module ChemistryParadise
11
+
12
+ module Constants # include ChemistryParadise::Constants
13
+
14
+ # ========================================================================= #
15
+ # === N
16
+ # ========================================================================= #
17
+ N = "\n"
18
+
19
+ # ========================================================================= #
20
+ # === ELECTRON_NEGATIVITY_CHART
21
+ # ========================================================================= #
22
+ if File.exist? FILE_ELECTRON_NEGATIVITY_CHART
23
+ ELECTRON_NEGATIVITY_CHART = YAML.load_file(FILE_ELECTRON_NEGATIVITY_CHART)
24
+ else
25
+ ELECTRON_NEGATIVITY_CHART = nil
26
+ end
27
+
28
+ # ========================================================================= #
29
+ # === electron_negativity_chart?
30
+ # ========================================================================= #
31
+ def electron_negativity_chart?
32
+ ELECTRON_NEGATIVITY_CHART
33
+ end
34
+
35
+ # ========================================================================= #
36
+ # === SPEED_OF_LIGHT
37
+ #
38
+ # The speed of light, in m / sec.
39
+ #
40
+ # You can refer to this constant in your ruby scripts too:
41
+ # c = ChemistryParadise::Constants::SPEED_OF_LIGHT
42
+ # ========================================================================= #
43
+ SPEED_OF_LIGHT = 299_792_458
44
+
45
+ # ========================================================================= #
46
+ # === PLANK_CONSTANT
47
+ #
48
+ # h = ChemistryParadise::Constants::PLANK_CONSTANT
49
+ # ========================================================================= #
50
+ PLANK_CONSTANT = 6.62607004 * (10 ** -34)
51
+
52
+ end; end
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'chemistry_paradise/constants/file_constants.rb'
6
+ # =========================================================================== #
7
+ require 'chemistry_paradise/project/project_base_directory.rb'
8
+
9
+ module ChemistryParadise
10
+
11
+ module Constants # === ChemistryParadise::Constants
12
+
13
+ # ========================================================================= #
14
+ # === FILE_ELECTRON_NEGATIVITY_CHART
15
+ #
16
+ # bl $RUBY_SRC/chemistry_paradise/lib/chemistry_paradise/yaml/electron_negativity_chart.yml
17
+ # ========================================================================= #
18
+ FILE_ELECTRON_NEGATIVITY_CHART =
19
+ "#{PROJECT_BASE_DIRECTORY}yaml/electron_negativity_chart.yml"
20
+
21
+ # ========================================================================= #
22
+ # === FILE_ATOMGEWICHTE
23
+ # ========================================================================= #
24
+ FILE_ATOMGEWICHTE =
25
+ "#{PROJECT_BASE_DIRECTORY}yaml/atomgewichte.yml"
26
+
27
+ end; end