module ChemistryParadise

#

require 'chemistry_paradise/base/colours.rb'

#
#

require 'chemistry_paradise/commandline/help.rb'

#
#

require 'chemistry_paradise/constants/german_names_of_elements_to_element_symbol.rb'

#

This .rb file will translate from the german name of an element towards the element symbol, if applicable. So, “Quecksilber” will become “Hg”.

See: de.wikipedia.org/wiki/Liste_der_chemischen_Elemente

#
#

require 'chemistry_paradise/project/project_base_directory.rb'

#
#

require 'chemistry_paradise/toplevel_methods/e.rb'

#
#

require 'chemistry_paradise/toplevel_methods/kelvin.rb'

#
#

This class can help set a different language for the project. By default, the german language is used, but you can call the module-method below, called ChemistryParadise.use_english, to enable english instead.

#

require 'chemistry_paradise/toplevel_methods/language.rb'

#
#

require 'chemistry_paradise/toplevel_methods/periodic_table.rb'

#
#

Purpose of this class is to explain what we are doing in a step-by-step wise fashion.

Right now this is a stub.

#
#

require 'chemistry_paradise/version/version.rb'

#

Constants

GERMAN_NAMES_OF_ELEMENTS_TO_ELEMENT_SYMBOL
#

ChemistryParadise::GERMAN_NAMES_OF_ELEMENTS_TO_ELEMENT_SYMBOL

#
LAST_UPDATE
#

LAST_UPDATE

#
PROJECT_BASE_DIRECTORY
#

ChemistryParadise::PROJECT_BASE_DIRECTORY

The constant must have a trailing '/' character.

#
VERSION
#

ChemistryParadise::VERSION

#

Public Class Methods

atomgewichte?() click to toggle source
#

ChemistryParadise.atomgewichte?

#
# File lib/chemistry_paradise/toplevel_methods/atomgewichte.rb, line 21
def self.atomgewichte?
  require 'yaml'
  YAML.load_file(Constants::FILE_ATOMGEWICHTE)
end
atomic_mass_of(i) click to toggle source
#

ChemistryParadise.atomic_mass_of

This method is a shortcut, to quickly calculate the molecular mass of a compound. See the usage example that follows.

Usage example:

ChemistryParadise.atomic_mass_of 'C10H13N5O3' # => "251.245"
#
# File lib/chemistry_paradise/calculate_atomic_mass.rb, line 439
def self.atomic_mass_of(i)
  ChemistryParadise::CalculateAtomicMass.parse(i)
end
display_where_the_molmasses_are_kept() click to toggle source
#

ChemistryParadise.display_where_the_molmasses_are_kept

#
# File lib/chemistry_paradise/toplevel_methods/display_where_the_molmasses_are_kept.rb, line 16
def self.display_where_the_molmasses_are_kept
  Colours.e(Constants::FILE_ATOMGEWICHTE)
end
do_use_english() click to toggle source
#

ChemistryParadise.do_use_english

Use this method if you want to use the english language.

#
# File lib/chemistry_paradise/toplevel_methods/language.rb, line 37
def self.do_use_english
  set_use_this_language(:english)
end
do_use_german() click to toggle source
#

ChemistryParadise.do_use_german

Use this method if you want to use the german language.

#
# File lib/chemistry_paradise/toplevel_methods/language.rb, line 46
def self.do_use_german
  set_use_this_language(:german)
end
e(i = '') click to toggle source
#

ChemistryParadise.e

#
# File lib/chemistry_paradise/toplevel_methods/e.rb, line 12
def self.e(i = '')
  puts i
end
file_atomgewichte() click to toggle source
#

ChemistryParadise.file_atomgewichte

#
# File lib/chemistry_paradise/toplevel_methods/atomgewichte.rb, line 14
def self.file_atomgewichte
  Constants::FILE_ATOMGEWICHTE
end
kelvin(n_celsius) click to toggle source
#

ChemistryParadise.kelvin

This method will output how many Kelvin n Celsius are.

The temperature T in Kelvin (K) is equal to the temperature T in degrees Celsius (°C) plus 273.1.

The formula thus is:

T(K) = T(°C) + 273.15
#
# File lib/chemistry_paradise/toplevel_methods/kelvin.rb, line 22
def self.kelvin(n_celsius)
  if n_celsius.is_a? Array
    n_celsius = n_celsius.first
  end
  n_kelvin = n_celsius.to_f + 273.15
  return n_kelvin
end
periodic_table?() click to toggle source
#

ChemistryParadise.periodic_table?

#
# File lib/chemistry_paradise/toplevel_methods/periodic_table.rb, line 12
def self.periodic_table?
  '/Users/x/DATA/SCIENCE/YAML/periodic_table.yml'
end
project_base_directory?() click to toggle source
#

ChemistryParadise.project_base_directory?

#
# File lib/chemistry_paradise/project/project_base_directory.rb, line 20
def self.project_base_directory?
  PROJECT_BASE_DIRECTORY
end
remove_this_molecule_from( this_molecule = 'OH', from = 'C2H5NO2' ) click to toggle source
#

ChemistryParadise.remove_this_molecule_from

The first argument is the molecule that should be deducted from the formula.

#
# File lib/chemistry_paradise/toplevel_methods/remove_this_molecule_from.rb, line 17
def self.remove_this_molecule_from(
    this_molecule = 'OH',
    from          = 'C2H5NO2'
  )
  array_big_molecule  = ::ChemistryParadise.split_this_molecular_formula_into_a_hash(from)
  array_this_molecule = ::ChemistryParadise.split_this_molecular_formula_into_a_hash(this_molecule)
  # ======================================================================= #
  # Next, iterate over the small molecule.
  # ======================================================================= #
  array_this_molecule.each {|this_compound|
    unless this_compound =~ /\d+/
      this_compound << '1' # Must be at the least one.
    end
    # ===================================================================== #
    # Select the entry that is the correct one.
    # ===================================================================== #
    this_entry = array_big_molecule.find {|entry|
      entry[0,1] == this_compound[0,1]
    }
    begin
      n_times_in_the_big_molecule   = /(\d{1,3})/.match(this_entry)[1].to_i
      n_times_in_the_small_molecule = /(\d{1,3})/.match(this_compound)[1].to_i
      new_n_times = n_times_in_the_big_molecule - n_times_in_the_small_molecule
      new_entry = this_compound[0,1]+new_n_times.to_s
      # ===================================================================== #
      # Now we have the new entry; we need to re-insert it into the big
      # original Array.
      # ===================================================================== #
      proper_index = array_big_molecule.index {|entry|
        entry[0,1] == this_compound[0,1]
      }
      array_big_molecule[proper_index] = new_entry
    rescue NoMethodError => error
      pp error
    end
  }
  return array_big_molecule.join # Join it up again.
end
return_element_symbol_from_this_german_name(i) click to toggle source
#

ChemistryParadise.return_element_symbol_from_this_german_name

#
# File lib/chemistry_paradise/constants/german_names_of_elements_to_element_symbol.rb, line 142
def self.return_element_symbol_from_this_german_name(i)
  i = i.dup if i.frozen?
  i.capitalize!
  if GERMAN_NAMES_OF_ELEMENTS_TO_ELEMENT_SYMBOL.has_key? i
    GERMAN_NAMES_OF_ELEMENTS_TO_ELEMENT_SYMBOL[i]
  else
    nil
  end
end
set_use_this_language(i = :german) click to toggle source
#

ChemistryParadise.set_use_this_language

#
# File lib/chemistry_paradise/toplevel_methods/language.rb, line 21
def self.set_use_this_language(i = :german)
  @use_this_language = i
end
show_electron_negativity_chart() click to toggle source
#

ChemistryParadise.show_electron_negativity_chart

#
# File lib/chemistry_paradise/toplevel_methods/show_electron_negativity_chart.rb, line 14
def self.show_electron_negativity_chart
  Constants::ELECTRON_NEGATIVITY_CHART.each_pair {|key, value|
    value = value.to_f
    value = '%.2f' % value 
    puts key.ljust(2)+' -> '+value.to_s.rjust(2)
  }
end
split_this_molecular_formula_into_a_hash(i) click to toggle source
#

ChemistryParadise.split_this_molecular_formula_into_a_hash

#
# File lib/chemistry_paradise/split_molecule_names.rb, line 161
def self.split_this_molecular_formula_into_a_hash(i)
  i = i.first if i.is_a? Array
  SplitMoleculeNames.new(i).result
end
use_which_language?() click to toggle source
#

ChemistryParadise.use_which_language?

#
# File lib/chemistry_paradise/toplevel_methods/language.rb, line 28
def self.use_which_language?
  @use_this_language
end