Class: Atom

Inherits:
Object show all
Defined in:
lib/cell/lib/atom.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#celldmObject

Returns the value of attribute celldm.



2
3
4
# File 'lib/cell/lib/atom.rb', line 2

def celldm
  @celldm
end

#coorObject

Returns the value of attribute coor.



3
4
5
# File 'lib/cell/lib/atom.rb', line 3

def coor
  @coor
end

#fixedObject

Returns the value of attribute fixed.



2
3
4
# File 'lib/cell/lib/atom.rb', line 2

def fixed
  @fixed
end

#uidObject

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

#dupObject



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

#nameObject



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_sObject



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

#xObject



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

#yObject



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

#zObject



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