Class: VaspUtils::Kpoints

Inherits:
Object
  • Object
show all
Defined in:
lib/vasputils/kpoints.rb

Overview

Class to dearl with KPOINTS. This can deal with only Automatic mesh style of KPOINTS, i.e., this cannot deal with other various styles of KPOINTS.

Defined Under Namespace

Classes: UnsupportedFormat

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Kpoints

Returns a new instance of Kpoints.



13
14
15
16
17
18
19
20
21
22
# File 'lib/vasputils/kpoints.rb', line 13

def initialize(hash)
  hash.each do |key,val|
    @comment = val if :comment == key
    @mesh    = val if :mesh    == key
    @points  = val if :points  == key
    @scheme  = val if :scheme  == key
    @shift   = val if :shift   == key
    @type    = val if :type    == key
  end
end

Instance Attribute Details

#commentObject (readonly)

Returns the value of attribute comment.



9
10
11
# File 'lib/vasputils/kpoints.rb', line 9

def comment
  @comment
end

#meshObject (readonly)

Returns the value of attribute mesh.



9
10
11
# File 'lib/vasputils/kpoints.rb', line 9

def mesh
  @mesh
end

#pointsObject (readonly)

Returns the value of attribute points.



9
10
11
# File 'lib/vasputils/kpoints.rb', line 9

def points
  @points
end

#schemeObject (readonly)

Returns the value of attribute scheme.



9
10
11
# File 'lib/vasputils/kpoints.rb', line 9

def scheme
  @scheme
end

#shiftObject (readonly)

Returns the value of attribute shift.



9
10
11
# File 'lib/vasputils/kpoints.rb', line 9

def shift
  @shift
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/vasputils/kpoints.rb', line 9

def type
  @type
end

Class Method Details

.load_file(path) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/vasputils/kpoints.rb', line 24

def self.load_file(path)
  io = File.open(path, "r")
  comment = io.readline.chomp

  #raise "Not automatic generating KPOINTS! 2nd line must be 0." unless io.readline =~ /^0$/
  num = io.readline.to_i
  if num == 0
    scheme = :automatic
    line = io.readline
    case line
    when /^m/i; then; type = :monkhorst
    when /^g/i; then; type = :gamma_center
    else
      raise "Unsupported automatic generation of KPOINTS."
    end

    mesh = io.readline.strip.split(/\s+/).map{|i| i.to_i}
    shift = io.readline.strip.split(/\s+/).map{|i| i.to_f}
    points = nil
  else
    scheme = :explicit
    mesh = nil
    points = []

    coordinate_style = io.readline
    unless coordinate_style =~ /^[c|k]/i
      raise "Unsupported coordinate style of KPOINTS."
    end
    num.times do |i|
      points << io.readline.strip.split(/\s+/).map{|v| v.to_f}
    end
  end

  options = {
    :comment => comment,
    :mesh    => mesh   ,
    :points  => points ,
    :scheme  => scheme ,
    :shift   => shift  ,
    :type    => type   ,
  }
  self.new(options)
end

Instance Method Details

#dump(io) ⇒ Object

Dump in KPOINTS style. Only automatic generation scheme is supported.



70
71
72
73
74
75
76
# File 'lib/vasputils/kpoints.rb', line 70

def dump(io)
  io.puts "Automatic mesh"
  io.puts "0"
  io.puts @type.to_s.capitalize
  io.puts @mesh.join(" ")
  io.puts @shift.join(" ")
end