Class: Cell
- Defined in:
- lib/cell/cell.rb,
lib/cell/lib/redef.rb,
lib/cell/lib/write.rb,
lib/cell/lib/private.rb,
lib/cell/lib/boundary.rb
Instance Attribute Summary collapse
-
#celldm ⇒ Object
Returns the value of attribute celldm.
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#units ⇒ Object
Returns the value of attribute units.
Instance Method Summary collapse
- #+(arg) ⇒ Object
- #<<(arg) ⇒ Object
- #dist(x, y) ⇒ Object
- #dup ⇒ Object
-
#initialize(params = {}) ⇒ Cell
constructor
A new instance of Cell.
- #insert(arg, index) ⇒ Object
- #move(*args) ⇒ Object
- #move!(*args) ⇒ Object
- #old_insert ⇒ Object
- #old_p ⇒ Object
- #old_plus ⇒ Object
- #old_push ⇒ Object
- #old_sort! ⇒ Object
- #old_unshift ⇒ Object
- #push(arg) ⇒ Object
- #reset_order ⇒ Object
- #reset_order! ⇒ Object
- #sort(*args) ⇒ Object
- #sort!(fields, tol = 0.5) ⇒ Object
- #to_pdb ⇒ Object
- #to_s ⇒ Object
- #to_xyz ⇒ Object
- #unshift(arg) ⇒ Object
- #wrap(tol = 0.5) ⇒ Object
- #wrap!(tol = 0.5) ⇒ Object
Methods inherited from Array
Constructor Details
#initialize(params = {}) ⇒ Cell
Returns a new instance of Cell.
9 10 11 12 13 14 15 16 17 |
# File 'lib/cell/cell.rb', line 9 def initialize params = {} add_to_atoms params[:atoms] unless params[:atoms].nil? params[:units].lowercase! if params[:units].is_a? String @units = params[:units] || :crystal @celldm = (@units == :crystal ? [1,1,1] : params[:celldm].dup) rescue @celldm = [] @realcelldm = (@units == :bohr ? params[:celldm].map{|v| v*0.52918} : params[:celldm]) rescue @realcelldm = [] @min = [] @max = [] end |
Instance Attribute Details
#celldm ⇒ Object
Returns the value of attribute celldm.
8 9 10 |
# File 'lib/cell/cell.rb', line 8 def celldm @celldm end |
#max ⇒ Object (readonly)
Returns the value of attribute max.
8 9 10 |
# File 'lib/cell/cell.rb', line 8 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
8 9 10 |
# File 'lib/cell/cell.rb', line 8 def min @min end |
#units ⇒ Object
Returns the value of attribute units.
8 9 10 |
# File 'lib/cell/cell.rb', line 8 def units @units end |
Instance Method Details
#+(arg) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/cell/lib/redef.rb', line 64 def + arg if arg.is_a?(Cell) update_mins_maxes arg.min update_mins_maxes arg.max self.old_plus(arg) else false end end |
#<<(arg) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/cell/lib/redef.rb', line 24 def << arg if arg.is_a?(Atom) cell_bindings arg update_mins_maxes arg.coor self.old_p(arg.dup) else false end end |
#dist(x, y) ⇒ Object
2 3 4 5 6 |
# File 'lib/cell/lib/boundary.rb', line 2 def dist x, y $stderr.puts "Distance in crystal units is usually not meaningful!" if @units == :crystal arr = wrap(0) return arr[x].dist arr[y] end |
#dup ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/cell/lib/redef.rb', line 72 def dup if @units == :bohr arr = Cell.new(:units => @units, :celldm => @celldm) else arr = Cell.new(:units => @units, :celldm => @realcelldm) end self.each do |atom| arr << atom.dup end return arr end |
#insert(arg, index) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/cell/lib/redef.rb', line 52 def insert arg, index if arg.is_a?(Atom) cell_bindings arg, index update_mins_maxes arg.coor self.each do |atom| atom.uid+=1 if atom uid >= index end self.old_insert(arg.dup, index) else false end end |
#move(*args) ⇒ Object
28 29 30 31 |
# File 'lib/cell/lib/boundary.rb', line 28 def move *args arr = self.dup return arr.move! *args end |
#move!(*args) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/cell/lib/boundary.rb', line 19 def move! *args args.flatten! args*=3 if args.length == 1 self.each do |atom| atom.move! args end for i in 0..2;@max[i]+=args[i];@min[i]+=args[i];end return self end |
#old_insert ⇒ Object
51 |
# File 'lib/cell/lib/redef.rb', line 51 alias :old_insert :insert |
#old_p ⇒ Object
23 |
# File 'lib/cell/lib/redef.rb', line 23 alias :old_p :<< |
#old_plus ⇒ Object
63 |
# File 'lib/cell/lib/redef.rb', line 63 alias :old_plus :+ |
#old_push ⇒ Object
42 |
# File 'lib/cell/lib/redef.rb', line 42 alias :old_push :push |
#old_sort! ⇒ Object
2 |
# File 'lib/cell/lib/redef.rb', line 2 alias :old_sort! :sort! |
#old_unshift ⇒ Object
32 |
# File 'lib/cell/lib/redef.rb', line 32 alias :old_unshift :unshift |
#push(arg) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/cell/lib/redef.rb', line 43 def push arg if arg.is_a?(Atom) cell_bindings arg update_mins_maxes arg.coor self.old_push(arg.dup) else false end end |
#reset_order ⇒ Object
36 37 38 39 |
# File 'lib/cell/lib/boundary.rb', line 36 def reset_order arr = self.dup return arr.reset_order! end |
#reset_order! ⇒ Object
32 33 34 35 |
# File 'lib/cell/lib/boundary.rb', line 32 def reset_order! self.old_sort!{|x,y| x.uid <=> y.uid} return self end |
#sort(*args) ⇒ Object
19 20 21 22 |
# File 'lib/cell/lib/redef.rb', line 19 def sort *args arr = self.dup return arr.sort!(*args) end |
#sort!(fields, tol = 0.5) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/cell/lib/redef.rb', line 3 def sort! fields, tol = 0.5 tol = [tol, tol, tol] unless tol.is_a? Array self.old_sort! do |a, b| g = fields.to_s.split(//) t = a.name <=> b.name x = a.x.approx_sort(b.x, tol[0]) y = a.y.approx_sort(b.y, tol[1]) z = a.z.approx_sort(b.z, tol[2]) result = 0 while result == 0 and g.length > 0 result = eval(g.shift) end result end return self end |
#to_pdb ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/cell/lib/write.rb', line 9 def to_pdb arr = (@units == :angstrom ? self : self.dup) arr.units = :angstrom output = "CRYST1%9.3f%9.3f%9.3f 90.00 90.00 90.00 P 1\n" % arr.celldm i = 0 arr.each do |atom| i += 1 output += "ATOM %5d %-4s X 1 %8.3f%8.3f%8.3f 1.00 1.00 %-2s\n" % ([i, atom.name] + atom.coor + [atom.name]) end return output end |
#to_s ⇒ Object
2 3 4 5 6 7 8 |
# File 'lib/cell/lib/write.rb', line 2 def to_s output = "" self.each do |atom| output += "%s\n" % atom.to_s end return output end |
#to_xyz ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cell/lib/write.rb', line 20 def to_xyz arr = (@units == :angstrom ? self : self.dup) arr.units = :angstrom output = "%d\n" % arr.length output += "Cell Dimensions %10.6f %10.6f %10.6f\n" % arr.celldm arr.each do |atom| output += "%-2s %10.6f %10.6f %10.6f\n" % ([atom.name] + atom.coor) end return output end |
#unshift(arg) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/cell/lib/redef.rb', line 33 def unshift arg if arg.is_a?(Atom) cell_bindings arg, 0 self.each{|atom| atom.uid+=1} update_mins_maxes arg.coor self.old_unshift(arg.dup) else false end end |
#wrap(tol = 0.5) ⇒ Object
15 16 17 18 |
# File 'lib/cell/lib/boundary.rb', line 15 def wrap tol = 0.5 arr = self.dup return arr.wrap!(tol) end |
#wrap!(tol = 0.5) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/cell/lib/boundary.rb', line 7 def wrap! tol = 0.5 self.each do |atom| (0..2).each {|i| atom.coor[i] -= @celldm[i] while atom.coor[i] - @celldm[i] > tol} (0..2).each {|i| atom.coor[i] += @celldm[i] while atom.coor[i] < -tol} end scan_mins_maxes return self end |