class CrystalCell::Element
Class for elements and their information.
Constants
- ATOMIC_RADII
- SYMBOLS
Public Class Methods
atomic_radius(id)
click to toggle source
Return atomic radius. 'id' can be indicated by number and elemet symbol.
# File lib/crystalcell/element.rb, line 52 def self.atomic_radius(id) id = self.symbol_to_num(id) if id.class == String ATOMIC_RADII[id] end
num_to_symbol(num)
click to toggle source
Return element symbols from atomic number 'num', e.g., 1 to H If not found, raise CrystalCell::Element::NotExistError
.
# File lib/crystalcell/element.rb, line 44 def self.num_to_symbol(num) raise NotExistError, "#{num} is not Fixnum." if (num.class != Fixnum) raise NotExistError, "#{num} is out of range." if (num <= 0 || SYMBOLS.size <= num) SYMBOLS[num] end
symbol_to_num(str)
click to toggle source
Return atomic number from element symbol, e.g., H to 1. If not found, raise CrystalCell::Element::NotExistError
.
# File lib/crystalcell/element.rb, line 36 def self.symbol_to_num(str) symbol = SYMBOLS.index( str ) raise NotExistError, "Symbol #{str} not found." if (symbol == nil || symbol == 0) symbol end