Class: PW

Inherits:
Object show all
Defined in:
lib/pw.rb

Class Method Summary collapse

Class Method Details

.input(ifile) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/pw.rb', line 6

def self.input ifile
  cell = nil
  File.open(ifile, 'r') do |f|
    nat = f.ff(/nat/).readline.split(/[ ,]/).numbers![0]
    celldm = []
    while f.ff(/celldm/)
      celldm.push f.readline.split(/[ ,]/).numbers!
    end
    celldm.map!{|v| v == celldm[0] ? v * 0.52918 : v * celldm[0]}
    f.ff(/ATOMIC_POSITIONS/)
    unit = unit? f.readline
    cell = Cell.new(:celldm => celldm, :units => unit)
    f.head(nat, true).map{|v| v.split.numerify!}.each do |atom|
      cell << Atom.new(:name => atom[0], :coor => atom[1,4], :fixed => !atom[4].nil?)
    end
  end
  return cell
end

.output(ofile) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pw.rb', line 24

def self.output ofile
  cell = nil
  File.open(ofile, 'r') do |f|
    nat = f.ff(/number of atoms/).readline.split.numbers![0]
    celldm = f.ff(/celldm/).readline.split.numbers!
    celldm.map!{|v| v == celldm[0] ? v * 0.52918 : v * celldm[0]}
    f.seek f.size
    unit = unit? f.rew(/ATOMIC_POSITIONS/).readline
    cell = Cell.new(:celldm => celldm, :units => unit)
    f.head(nat, true).map{|v| v.split.numerify!}.each do |atom|
      cell << Atom.new(:name => atom[0], :coor => atom[1,3], :fixed => !atom[4].nil?)
    end
  end
  return cell
end