Class: Atom
- Defined in:
- lib/lib/atom/atom.rb,
lib/lib/atom/lib/atom.rb,
lib/lib/atom/lib/elements.rb
Constant Summary collapse
- Elements =
{ :O => { :z => 8, :m => 15.999, :fname => "Oxygen", :name => :O, :pp => [] }, :Ti => { :z => 22, :m => 47.867, :fname => "Titanium", :name => :Ti, :pp => [] }, :X => { :z => 1, :m => 1, :fname => "Unspecified", :name => :X, :pp => [] } }
Instance Attribute Summary collapse
-
#crystal ⇒ Object
Returns the value of attribute crystal.
-
#fixed ⇒ Object
Returns the value of attribute fixed.
-
#pos ⇒ Object
Returns the value of attribute pos.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #dist(other) ⇒ Object
- #dup ⇒ Object
- #evaluate(str, b = nil) ⇒ Object
- #has_crystal? ⇒ Boolean
-
#initialize(params = {}) ⇒ Atom
constructor
A new instance of Atom.
- #inspect ⇒ Object
- #move(v, n = 1) ⇒ Object
- #move!(v, n = 1) ⇒ Object
- #name ⇒ Object
- #name=(s) ⇒ Object
- #to_hash ⇒ Object
- #to_s(f = '%8.4f') ⇒ Object
- #x ⇒ Object
- #x=(p) ⇒ Object
- #y ⇒ Object
- #y=(p) ⇒ Object
- #z ⇒ Object
- #z=(p) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Atom
Returns a new instance of Atom.
5 6 7 8 9 10 11 |
# File 'lib/lib/atom/atom.rb', line 5 def initialize params = {} @type = Elements[params[:type]] || Elements[:X] @name = (params[:name]||@type.name).to_sym @pos = (params[:pos].to_v rescue nil) @crystal = params[:crystal] @fixed = params[:fixed] end |
Instance Attribute Details
#crystal ⇒ Object
Returns the value of attribute crystal.
4 5 6 |
# File 'lib/lib/atom/atom.rb', line 4 def crystal @crystal end |
#fixed ⇒ Object
Returns the value of attribute fixed.
4 5 6 |
# File 'lib/lib/atom/atom.rb', line 4 def fixed @fixed end |
#pos ⇒ Object
Returns the value of attribute pos.
4 5 6 |
# File 'lib/lib/atom/atom.rb', line 4 def pos @pos end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/lib/atom/atom.rb', line 4 def type @type end |
Instance Method Details
#dist(other) ⇒ Object
23 24 25 26 |
# File 'lib/lib/atom/lib/atom.rb', line 23 def dist other pos = other.is_a?(Atom) ? other.pos : other.to_v has_crystal? ? crystal.dist(self, other):(@pos - pos).magnitude end |
#evaluate(str, b = nil) ⇒ Object
30 31 32 33 |
# File 'lib/lib/atom/atom.rb', line 30 def evaluate str, b=nil str = str.gsub(/={1,2}/,"==").gsub(/(\[[^\]]*\])/,'\1.to_v') eval(str) ? true : false end |
#has_crystal? ⇒ Boolean
14 |
# File 'lib/lib/atom/lib/atom.rb', line 14 def has_crystal?() !(@crystal.nil?) end |
#inspect ⇒ Object
36 37 38 |
# File 'lib/lib/atom/lib/atom.rb', line 36 def inspect to_hash.to_s end |
#move(v, n = 1) ⇒ Object
19 20 21 22 |
# File 'lib/lib/atom/lib/atom.rb', line 19 def move v, n = 1 ret = self.dup ret.move! v,n end |
#move!(v, n = 1) ⇒ Object
15 16 17 18 |
# File 'lib/lib/atom/lib/atom.rb', line 15 def move! v, n = 1 @pos += v.to_v * n self end |
#name ⇒ Object
16 |
# File 'lib/lib/atom/atom.rb', line 16 def name() @name.to_s end |
#name=(s) ⇒ Object
17 18 19 |
# File 'lib/lib/atom/atom.rb', line 17 def name=(s) @name = s.to_sym end |
#to_hash ⇒ Object
30 31 32 |
# File 'lib/lib/atom/lib/atom.rb', line 30 def to_hash { :type => @type.name.to_sym, :name => @name, :pos => @pos, :fixed => @fixed, :crystal => @crystal } end |
#to_s(f = '%8.4f') ⇒ Object
33 34 35 |
# File 'lib/lib/atom/lib/atom.rb', line 33 def to_s f = '%8.4f' ("%-6s" + "#{f} " * 3) % ([name] + pos.to_a) + (fixed.nil? ? "" : fixed.map{|v| v ? 0 : 1}.join(" ")) end |
#x ⇒ Object
2 |
# File 'lib/lib/atom/lib/atom.rb', line 2 def x() @pos[0] end |
#y ⇒ Object
3 |
# File 'lib/lib/atom/lib/atom.rb', line 3 def y() @pos[1] end |
#z ⇒ Object
4 |
# File 'lib/lib/atom/lib/atom.rb', line 4 def z() @pos[2] end |