mspire library holding constants for mass lookup. Uses NIST masses (where applicable). See mspire-isotope for complete isotope information (including masses). See mspire-molecular_formula for mass or m/z methods for larger molecular formulas.
gem install mspire-mass
A simple hash may be accessed directly from the various modules:
require 'mspire/mass'
Mspire::Mass::Element::MONO_STRING['C'] # => 12.0
Mspire::Mass::AA::MONO_STRING['C'] # => 103.0091844778 (residue)
Mspire::Mass::Subatomic::MONO_STRING['NEUTRON'] # => 1.0086649156
Mspire::Mass::Common::MONO_STRING['H2O'] # => 18.0105646837
# similar for average masses
Mspire::Mass::Element::AVG_STRING['C'] # => 12.0107
# note that elements are accessed in mixed case by default
Mspire::Mass::Element::MONO_STRING['Se'] # => 79.9165213
A hash where everything but the amino acids is downcased can also be accessed
require 'mspire/mass/merged' # <- must be required explicitly
Mspire::Mass::Merged::MONO_STRING['C'] # (cysteine) => 103.0091844778
Mspire::Mass::Merged::MONO_STRING['c'] # (carbon) => 12.0
Mspire::Mass::Merged::MONO_STRING['h2o'] # (water) => 18.0105646837
Mspire::Mass::Merged::MONO_STRING['e'] # (or 'electron') => 0.0005486
# Mspire::Mass::Merged::AVG_STRING also available
MONO_STRING and AVG_STRING are only for quick, low-level access. They are purposefully ugly to encourage you to use the beautiful interface shown directly below!
A mass hash can be created in a variety of forms depending on your needs/preferences.
---------------------------------
<default>
---------------------------------
type = :mono | :avg
by = :symbol | :string | :both
case = :up | :down | :both
NOTE: it defaults to symbols, not strings.
el_masses = Mspire::Mass::Element.masses
# which defaults to this
el_masses = Mspire::Mass::Element.masses(type: :mono, by: :symbol, case: :up)
el_masses[:C] # (carbon) => 12.0
aas = Mspire::Mass::AA.masses(type: :avg, by: :string)
aas['C'] # (cysteine) => 103.1429
subatomic = Mspire::Mass::Subatomic.masses
subatomic[:PROTON] # (same as subatomic[:'H+'] or subatomic[:H_PLUS]) # => 1.00727643207
A merged hash can be created in a similar way, but :up and :down aren't respected since it merges by upcasing amino acids and downcasing all else.
merged = Mspire::Mass::Merged.masses(type: :mono)
merged[:C] # (cysteine) => 103.0091844778
merged[:c] # (carbon) => 12.0
The strings that play nice are defined as constants on Mspire::Mass so you can do this:
Mspire::Mass::ELECTRON #=> 0.0005486
Mspire::Mass::PROTON #=> 1.00727643207
Mspire::Mass::NEUTRON #=> 1.0086649156