Class: Mspire::Isotope

Inherits:
Object
  • Object
show all
Defined in:
lib/mspire/isotope.rb,
lib/mspire/isotope/aa.rb,
lib/mspire/isotope/distribution.rb,
lib/mspire/isotope/distribution.rb

Defined Under Namespace

Modules: AA, Distribution Classes: Updater

Constant Summary collapse

MEMBERS =
[:atomic_number, :element, :mass_number, :atomic_mass, :relative_abundance, :average_mass, :mono]
INFO_FILE =
'nist_isotope_info.yml'
INFO_FILE_FULL_PATH =
File.expand_path(File.dirname(__FILE__) + "/isotope/#{INFO_FILE}")
ISOTOPES =
YAML.load_file(INFO_FILE_FULL_PATH).map {|ar| Mspire::Isotope.new *ar }
BY_ELEMENT =
ISOTOPES.group_by(&:element)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Isotope

Returns a new instance of Isotope.



12
13
14
# File 'lib/mspire/isotope.rb', line 12

def initialize(*args)
  MEMBERS.zip(args) {|k,val| self.send("#{k}=", val) }
end

Class Method Details

.from_nist_line(*args) ⇒ Object

Creates an isotope from a nist entry. Sets mono to false, which is not always correct (but needs to be corrected with additional info)



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mspire/isotope.rb', line 18

def self.from_nist_line(*args)
  # atomic_number and mass_number are ints
  [0,2].each {|i| args[i] = args[i].to_i }
  # element is a downcase sym
  args[1] = args[1].downcase.to_sym
  # atomic_mass, relative_abundance, and average_mass as floats
  [3, 4, 5].each {|i| args[i] = args[i][/([\w.]*)/].to_f }
  # by default call every isotope the non-monoisotopic peak
  # (will correct it as a group)
  args << false
  self.new(*args)
end