Class: Atom
Instance Attribute Summary collapse
-
#celldm ⇒ Object
Returns the value of attribute celldm.
-
#coor ⇒ Object
Returns the value of attribute coor.
-
#fixed ⇒ Object
Returns the value of attribute fixed.
-
#uid ⇒ Object
Returns the value of attribute uid.
Instance Method Summary collapse
- #dist(other) ⇒ Object
- #dup ⇒ Object
-
#initialize(params = {}) ⇒ Atom
constructor
A new instance of Atom.
- #move(*args) ⇒ Object
- #move!(*args) ⇒ Object
- #name ⇒ Object
- #name=(nm) ⇒ Object
- #to_s ⇒ Object
- #x ⇒ Object
- #x=(num) ⇒ Object
- #y ⇒ Object
- #y=(num) ⇒ Object
- #z ⇒ Object
- #z=(num) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Atom
Returns a new instance of Atom.
4 5 6 7 8 9 10 11 |
# File 'lib/cell/lib/atom.rb', line 4 def initialize params = {} @name = params[:name].to_sym rescue @name = :X @coor = params[:coor].dup rescue @coor = [] @uid = params[:uid] || nil @fixed = params[:fixed]||false @celldm = params[:celldm] || nil # element = params[:element] || #TODO element constants. dont forget fixing dup end |
Instance Attribute Details
#celldm ⇒ Object
Returns the value of attribute celldm.
2 3 4 |
# File 'lib/cell/lib/atom.rb', line 2 def celldm @celldm end |
#coor ⇒ Object
Returns the value of attribute coor.
3 4 5 |
# File 'lib/cell/lib/atom.rb', line 3 def coor @coor end |
#fixed ⇒ Object
Returns the value of attribute fixed.
2 3 4 |
# File 'lib/cell/lib/atom.rb', line 2 def fixed @fixed end |
#uid ⇒ Object
Returns the value of attribute uid.
2 3 4 |
# File 'lib/cell/lib/atom.rb', line 2 def uid @uid end |
Instance Method Details
#dist(other) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/cell/lib/atom.rb', line 39 def dist other if other.is_a? Atom arr = other.coor elsif other.is_a? Array and other.length = 3 arr = other else return nil end d = [] for i in 0..2 d.push (@coor[i] - arr[i]).abs d[i] = @celldm[i] - d[i] if (!@celldm.nil? and d[i] > @celldm[i]/2) end return (d[0]**2+d[1]**2+d[2]**2).sqrt end |
#dup ⇒ Object
36 37 38 |
# File 'lib/cell/lib/atom.rb', line 36 def dup Atom.new(:name => @name, :coor => @coor, :uid => @uid, :fixed => @fixed, :celldm => @celldm) end |
#move(*args) ⇒ Object
27 28 29 30 |
# File 'lib/cell/lib/atom.rb', line 27 def move *args a = self.dup return a.move!(*args) end |
#move!(*args) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/cell/lib/atom.rb', line 21 def move! *args args.flatten! args = args * 3 if args.length == 1 for i in 0..2;coor[i]+=args[i];end return self end |
#name ⇒ Object
14 |
# File 'lib/cell/lib/atom.rb', line 14 def name; @name.to_s; end |
#name=(nm) ⇒ Object
13 |
# File 'lib/cell/lib/atom.rb', line 13 def name= nm; @name = nm.to_sym; end |
#to_s ⇒ Object
31 32 33 34 35 |
# File 'lib/cell/lib/atom.rb', line 31 def to_s l = (@fixed ? " 0 0 0" : "") output = "%-4s%14.9f%14.9f%14.9f%s" % [@name, coor[0], coor[1], coor[2], l] return output end |
#x ⇒ Object
15 |
# File 'lib/cell/lib/atom.rb', line 15 def x; @coor[0]; end |
#x=(num) ⇒ Object
18 |
# File 'lib/cell/lib/atom.rb', line 18 def x= num; @coor[0] = num; end |
#y ⇒ Object
16 |
# File 'lib/cell/lib/atom.rb', line 16 def y; @coor[1]; end |
#y=(num) ⇒ Object
19 |
# File 'lib/cell/lib/atom.rb', line 19 def y= num; @coor[1] = num; end |
#z ⇒ Object
17 |
# File 'lib/cell/lib/atom.rb', line 17 def z; @coor[2]; end |
#z=(num) ⇒ Object
20 |
# File 'lib/cell/lib/atom.rb', line 20 def z= num; @coor[2] = num; end |