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,101 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === ChemistryParadise::ShowElectronNegativityOfThisElement
6
+ #
7
+ # This class will report the electron negativity of the input-element,
8
+ # such as "S" or "Fe" and so forth (chemical elements).
9
+ #
10
+ # Usage example in ruby:
11
+ # Chemistry::ShowElectronNegativityOfThisElement.new
12
+ # =========================================================================== #
13
+ # require 'chemistry_paradise/show_electron_negativity_of_this_element.rb'
14
+ # =========================================================================== #
15
+ require 'chemistry_paradise/base/base.rb'
16
+
17
+ module ChemistryParadise
18
+
19
+ class ShowElectronNegativityOfThisElement < Base # === ChemistryParadise::ShowElectronNegativityOfThisElement.new
20
+
21
+ # ========================================================================= #
22
+ # === NAMESPACE
23
+ # ========================================================================= #
24
+ NAMESPACE = inspect
25
+
26
+ # ========================================================================= #
27
+ # === initialize
28
+ # ========================================================================= #
29
+ def initialize(
30
+ i = nil,
31
+ run_already = true
32
+ )
33
+ reset
34
+ set_input(i)
35
+ run if run_already
36
+ end
37
+
38
+ # ========================================================================= #
39
+ # === reset (reset tag)
40
+ # ========================================================================= #
41
+ def reset
42
+ super()
43
+ @dataset = Constants::ELECTRON_NEGATIVITY_CHART
44
+ end
45
+
46
+ # ========================================================================= #
47
+ # === set_input
48
+ # ========================================================================= #
49
+ def set_input(i = '')
50
+ i = [i] unless i.is_a? Array
51
+ @input = i
52
+ end
53
+
54
+ # ========================================================================= #
55
+ # === input?
56
+ # ========================================================================= #
57
+ def input?
58
+ @input
59
+ end
60
+
61
+ # ========================================================================= #
62
+ # === run (run tag)
63
+ # ========================================================================= #
64
+ def run
65
+ try_to_detect_the_electron_negativity_of_the_passed_elements
66
+ end
67
+
68
+ # ========================================================================= #
69
+ # === try_to_detect_the_electron_negativity_of_the_passed_elements
70
+ # ========================================================================= #
71
+ def try_to_detect_the_electron_negativity_of_the_passed_elements
72
+ dataset = @dataset
73
+ input?.each {|this_element|
74
+ if dataset.has_key? this_element
75
+ electron_negativity_value = dataset[this_element]
76
+ e "#{simp(this_element.ljust(2))} has an electron negativity of "\
77
+ "#{sfancy(electron_negativity_value)}"\
78
+ " (in this Pauling electronegativity scale)"
79
+ end
80
+ }
81
+ end
82
+
83
+ # ========================================================================= #
84
+ # === opnn
85
+ # ========================================================================= #
86
+ def opnn
87
+ super(NAMESPACE)
88
+ end
89
+
90
+ # ========================================================================= #
91
+ # === []
92
+ # ========================================================================= #
93
+ def self.[](i = '')
94
+ self.new(i)
95
+ end
96
+
97
+ end; end
98
+
99
+ if __FILE__ == $PROGRAM_NAME
100
+ ChemistryParadise::ShowElectronNegativityOfThisElement.new(ARGV)
101
+ end # show_electron_negativity_of_this_element S
@@ -0,0 +1,141 @@
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
+ # ChemistryParadise::ShowElement.new
13
+ # =========================================================================== #
14
+ require 'chemistry_paradise/base/base.rb'
15
+
16
+ module ChemistryParadise
17
+
18
+ class ShowElement < ::ChemistryParadise::Base # require 'show_element'; ShowElement.new
19
+
20
+ # ========================================================================= #
21
+ # === NAMESPACE
22
+ # ========================================================================= #
23
+ NAMESPACE = inspect
24
+
25
+ # ========================================================================= #
26
+ # === PERIODIC_TABLE
27
+ # ========================================================================= #
28
+ PERIODIC_TABLE = YAML.load_file(ChemistryParadise::Shared.periodic_table?)
29
+
30
+ # ========================================================================= #
31
+ # === initialize
32
+ # ========================================================================= #
33
+ def initialize(
34
+ i = nil,
35
+ run_already = true
36
+ )
37
+ reset
38
+ set_input(i)
39
+ run if run_already
40
+ end
41
+
42
+ # ========================================================================= #
43
+ # === reset
44
+ # ========================================================================= #
45
+ def reset # (reset tag)
46
+ set_name_of_the_element
47
+ set_relative_position
48
+ end
49
+
50
+ # ========================================================================= #
51
+ # === set_input
52
+ # ========================================================================= #
53
+ def set_input(i = '')
54
+ i = i.first if i.is_a? Array
55
+ i = i.to_s.dup if i
56
+ @input = i
57
+ process_input
58
+ end
59
+
60
+ # ========================================================================= #
61
+ # === set_relative_position
62
+ # ========================================================================= #
63
+ def set_relative_position(i = 0)
64
+ i = i.to_i if i
65
+ @relative_position = i
66
+ end
67
+
68
+ # ========================================================================= #
69
+ # === process_input
70
+ # ========================================================================= #
71
+ def process_input
72
+ if @input.include? '+'
73
+ set_batch('+')
74
+ elsif @input.include? '-'
75
+ set_batch('-')
76
+ else
77
+ set_name_of_the_element(@input)
78
+ end
79
+ end
80
+
81
+ # ========================================================================= #
82
+ # === set_batch
83
+ #
84
+ # This will set both (1) the name and (2) the relative position.
85
+ # ========================================================================= #
86
+ def set_batch(on_which_token = '+')
87
+ _ = @input.split(on_which_token)
88
+ set_name_of_the_element _[0]
89
+ _[1] = '-'+_[1].to_s if on_which_token == '-'
90
+ set_relative_position _[1]
91
+ end
92
+
93
+ # ========================================================================= #
94
+ # === new_position?
95
+ # ========================================================================= #
96
+ def new_position?
97
+ @relative_position
98
+ end
99
+
100
+ # ========================================================================= #
101
+ # === report_result
102
+ # ========================================================================= #
103
+ def report_result
104
+ current_position = PERIODIC_TABLE[@name_of_the_element]
105
+ current_position = current_position + new_position?
106
+ opnn; e PERIODIC_TABLE.invert[current_position]+' is at position '+
107
+ sfancy(current_position.to_s)+'.'
108
+ end
109
+
110
+ # ========================================================================= #
111
+ # === set_name_of_the_element
112
+ # ========================================================================= #
113
+ def set_name_of_the_element(i = nil)
114
+ # ======================================================================= #
115
+ # if the input is a number, we invert the PERIODIC_TABLE.
116
+ # ======================================================================= #
117
+ if i =~ /^\d+$/
118
+ i = PERIODIC_TABLE.invert[i.to_i]
119
+ end
120
+ @name_of_the_element = i
121
+ end
122
+
123
+ # ========================================================================= #
124
+ # === run
125
+ # ========================================================================= #
126
+ def run # (run tag)
127
+ report_result
128
+ end
129
+
130
+ # ========================================================================= #
131
+ # === opnn
132
+ # ========================================================================= #
133
+ def opnn
134
+ super(NAMESPACE)
135
+ end
136
+
137
+ end; end
138
+
139
+ if __FILE__ == $PROGRAM_NAME
140
+ ChemistryParadise::ShowElement.new(ARGV)
141
+ end # show_element 'Xe+5'
@@ -0,0 +1,185 @@
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
33
+ # ========================================================================= #
34
+ def reset
35
+ super()
36
+ @result = []
37
+ @total = Hash.new(0) # Hash that keeps track of n elements each. Default value will be 0.
38
+ end
39
+
40
+ # ========================================================================= #
41
+ # === result?
42
+ # ========================================================================= #
43
+ def result?
44
+ @result
45
+ end; alias result result? # === result
46
+
47
+ # ========================================================================= #
48
+ # === is_number?
49
+ #
50
+ # This returns true if the input is a number, else false. For this it
51
+ # uses the .to_i method trick, which returns 0 for non-numbers.
52
+ # ========================================================================= #
53
+ def is_number?(i)
54
+ result = (i.to_i.to_s == i)
55
+ return result
56
+ end
57
+
58
+ # ========================================================================= #
59
+ # === split
60
+ #
61
+ # This method will return an array with all the elements.
62
+ # ========================================================================= #
63
+ def split(i = @input)
64
+ array = []
65
+ _ = ''.dup
66
+ if i
67
+ i.chars.each_with_index {|token, index|
68
+ if is_number? token # We found a number here. We simply append it then.
69
+ _ << token # return the old data
70
+ elsif token.downcase == token
71
+ _ << token
72
+ else # Not a number, must be a character.
73
+ unless _.empty?
74
+ array << _
75
+ _ = ''.dup
76
+ end
77
+ _ = token
78
+ end
79
+ array << _ if (index + 1) == i.size
80
+ }
81
+ @result = array
82
+ determine_total
83
+ return array
84
+ end
85
+ end
86
+
87
+ # ========================================================================= #
88
+ # === ignore_numbers
89
+ #
90
+ # This will ignore numbers in a guaranteed manner.
91
+ # ========================================================================= #
92
+ def ignore_numbers(i)
93
+ return i.gsub(/\d+/,'')
94
+ end
95
+
96
+ # ========================================================================= #
97
+ # === return_n_elements
98
+ #
99
+ # Must return an Integer.
100
+ # ========================================================================= #
101
+ def return_n_elements(i)
102
+ result = 0
103
+ if i =~ /\d+/ # Ok has at least one number.
104
+ i = i[/(\d+)/][0]
105
+ else
106
+ i = 1
107
+ end
108
+ result = i.to_i
109
+ return result
110
+ end
111
+
112
+ # ========================================================================= #
113
+ # === determine_total
114
+ #
115
+ # If the input is @result then it was already properly pre-sorted for us.
116
+ # ========================================================================= #
117
+ def determine_total(i = @result)
118
+ i.each {|entry|
119
+ this_real_key = ignore_numbers(entry)
120
+ if @total.has_key? this_real_key
121
+ @total[this_real_key] = @total[this_real_key]+return_n_elements(entry)
122
+ else # Else we must make a new key; the Laufindex kann aber 1-n sein.
123
+ @total[this_real_key] = return_n_elements(entry)
124
+ end
125
+ }
126
+ end
127
+
128
+ # ========================================================================= #
129
+ # === total?
130
+ # ========================================================================= #
131
+ def total?
132
+ @total # This must always be a Hash.
133
+ end
134
+
135
+ # ========================================================================= #
136
+ # === set_input
137
+ # ========================================================================= #
138
+ def set_input(i)
139
+ if i
140
+ i = convert_parens(i) if i.include? ')'
141
+ if i.include? ' '
142
+ i.strip!
143
+ if i.include? '+' # Ok, input here can be like: '2 Fe + 3 Cl2'
144
+ i = i.gsub(/(\d)+ /,'\1')
145
+ i = i.gsub(/ \+ /,'')
146
+ end
147
+ # ===================================================================== #
148
+ # But it can also include internal ' ', which we will remove next.
149
+ # ===================================================================== #
150
+ i.delete!(' ')
151
+ end
152
+ end
153
+ @input = i
154
+ end
155
+
156
+ end
157
+
158
+ # =========================================================================== #
159
+ # === ChemistryParadise.split_this_molecular_formula_into_a_hash
160
+ # =========================================================================== #
161
+ def self.split_this_molecular_formula_into_a_hash(i)
162
+ i = i.first if i.is_a? Array
163
+ SplitMoleculeNames.new(i).result
164
+ end
165
+
166
+ end
167
+
168
+ if __FILE__ == $PROGRAM_NAME
169
+ include ChemistryParadise
170
+ puts 'Testing whether this class can properly Split Compound Names:'
171
+ if ARGV.empty?
172
+ pp SplitMoleculeNames.new.result
173
+ pp SplitMoleculeNames.new('P2O5').result
174
+ pp SplitMoleculeNames.new('C6H14N4O2').result
175
+ pp SplitMoleculeNames.new('Al2(SO4)3').result
176
+ pp SplitMoleculeNames.new('Fe(OH)3').result
177
+ pp SplitMoleculeNames.new('H2SO4').result
178
+ pp SplitMoleculeNames.new('Fe2(SO4)3').result
179
+ pp SplitMoleculeNames.new('Fe2(SO4)3').total?
180
+ p 'Will test this input next: 2 Fe + 3 Cl2'
181
+ pp SplitMoleculeNames.new('2 Fe + 3 Cl2').result
182
+ else
183
+ SplitMoleculeNames.new(ARGV).result
184
+ end
185
+ 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