Sha256: e59fc3ce653383398ee550e4d70b7de5d5a3d318075468550903d4227d19929e

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

#! /usr/bin/env ruby
# coding: utf-8

require "vasputils.rb"

# Module dearing with KPOINTS.
module VaspUtils::Kpoints
  def self.parse(io)
    results = {}
    results[:comment] = io.readline.chomp

    raise "Not automatic generating KPOINTS! 2nd line must be 0." unless io.readline == "0\n"

    line = io.readline
    case line
    when /^m/i; then; results[:type] = :monkhorst
    when /^g/i; then; results[:type] = :gamma_center
    else
      raise "Kpoints module can deal with only monkhorst and gamma-center."
    end

    #pp io.readline.strip.split(/\s+/).map{|i| i.to_i}
    results[:mesh] = io.readline.strip.split(/\s+/).map{|i| i.to_i}
    #pp io.readline.strip.split(/\s+/).map{|i| i.to_f}
    results[:shift] = io.readline.strip.split(/\s+/).map{|i| i.to_f}

    return results
  end

  # 
  def self.load_file(file)
    self.parse(File.open(file, "r"))
  end

  def self.dump(data, io)
    io.puts "Automatic mesh"
    io.puts "0"
    io.puts data[:type].to_s.capitalize
    io.puts data[:mesh].join(" ")
    io.puts data[:shift].join(" ")
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vasputils-0.0.10 lib/vasputils/kpoints.rb