Sha256: 84c8947bdbb3bc0e570d8f46123636be4ee11ce6eec177e2b4e6296b865a8bc8

Contents?: true

Size: 819 Bytes

Versions: 8

Compression:

Stored size: 819 Bytes

Contents

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

require "pp"

#
#
#
class VaspUtils::Potcar::Concatenater
  class NoPotcarError < Exception; end

  # 'potcar_path' indicates a storage directory of POTCARs.
  # 'elem_potcar' indicates a correspondence
  # between element symbol and prior POTCAR as Hash.
  def initialize(potcar_path, elem_potcar)
    @potcar_path = potcar_path
    @elem_potcar = elem_potcar
  end

  # Concatenate POTCARs.
  # Write to io if defined
  # Return string if io is nil.
  def dump(elements, io = nil)
    result = elements.map { |elem|
      raise NoPotcarError unless @elem_potcar.include? elem
      filename = @potcar_path + "/" + @elem_potcar[elem] + "/POTCAR"
      File.read filename
    }.join("")

    if io # is defined
      io.print result
    else
      return result
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
vasputils-0.1.7 lib/vasputils/potcar/concatenater.rb
vasputils-0.1.6 lib/vasputils/potcar/concatenater.rb
vasputils-0.1.5 lib/vasputils/potcar/concatenater.rb
vasputils-0.1.4 lib/vasputils/potcar/concatenater.rb
vasputils-0.1.3 lib/vasputils/potcar/concatenater.rb
vasputils-0.1.2 lib/vasputils/potcar/concatenater.rb
vasputils-0.1.1 lib/vasputils/potcar/concatenater.rb
vasputils-0.0.11 lib/vasputils/potcar/concatenater.rb