Class: Cube

Inherits:
Object
  • Object
show all
Defined in:
lib/aims/cube.rb

Instance Method Summary collapse

Instance Method Details

#parse(io) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/aims/cube.rb', line 4

def parse(io)
  # First two lines are comments
  io.readline
  io.readline
  # Third line is number of atoms and origin
  natoms, origin_x, origin_y, origin_z = io.readline.split.collect{|s| s.to_f}

  # 4th, 5th, and 6th lines define the voxels
  n1, n1x, n1y, n1z = io.readline.split.collect{|str| str.to_f}
  n2, n2x, n2y, n2z = io.readline.split.collect{|str| str.to_f}
  n3, n3x, n3y, n3z = io.readline.split.collect{|str| str.to_f}

  # Next the positions of the atoms
  natoms.to_i.times do 
    # Read in the atoms
    atomic_number, not_sure, x, y, z = io.readline.split.collect{|str| str.to_f}\
  end
  
  vals = Array.new(n1*n2*n3)
  nread = 0
  offset = 0
  io.each_line{|line|
    arr = line.split
    nread = arr.size
    vals[offset...offset+nread] = line.split
    offset = offset+nread
  }
  
  # Finally the field
  n1.to_i.times do |i|
    n2.to_i.times do |j|
      n3.to_i.times do |k|
        v = vals.shift.to_f
        x = i*n1x + j*n2x + k*n3x
        y = i*n1y + j*n2y + k*n3y
        z = i*n1z + j*n2z + k*n3z
        puts [x, y, z, v].join(" ")
      end
    end
  end
end