Sha256: 62d4ab1266d113d9fafef9ae830d16b86a09df9657591789546de749907a3428

Contents?: true

Size: 1.84 KB

Versions: 5

Compression:

Stored size: 1.84 KB

Contents

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

require "vasputils"
require 'thor'

class IncarCommand < Thor
  desc "generate [option] settings", "Generate INCAR"
  long_desc <<HERE
    Generate INCAR file.
    'settings' can be allowed in two style;
      if including '=' word like 'key=val', include the setting pair into incar.
      if word without '=', find the name in incar setting in ~/.vasputils.
        and append the settings.
HERE
  #option :opt

  option :enmax,
    banner: '[POTCAR]',
    desc: 'Use the highest value of ENMAXes in POTCAR',
    lazy_default: 'POTCAR'
  option :enmax130,
    banner: '[POTCAR]',
    desc: 'Like --enmax option, but multiplied by 1.3',
    lazy_default: 'POTCAR'
  option :load, banner: '[INCAR]', desc: 'Load INCAR'
  option :overwrite, banner: '[INCAR]', desc: 'Load and overwrite INCAR'
  def generate(*args)
    incar = VaspUtils::Incar.new

    if options[:load] || options[:overwrite]
      incar = VaspUtils::Incar.load_file(options[:load] || options[:overwrite])
    end
    args.each do |str|
      if /(.*)=(.*)/ =~ str
        key = $1.strip
        val = $2.strip
        incar[key] = val
      else
        setting = VaspUtils::Setting.new
        begin
          setting["incar"][str].each do |key,val|
            incar[key] = val
          end
        rescue 
          puts "No entry in #{setting.filename}: #{str}"
          puts "Exit"
          exit
        end
      end
    end

    if options[:enmax]
      potcar = VaspUtils::Potcar.load_file(options[:enmax])
      incar['ENCUT'] = potcar.enmaxes.max
    end
    if options[:enmax130]
      potcar = VaspUtils::Potcar.load_file(options[:enmax130])
      incar['ENCUT'] = potcar.enmaxes.max * 1.3
    end

    if options[:overwrite]
      io = File.open( options[:overwrite], 'w')
    else
      io = STDOUT
    end
    incar.dump(io)
  end
end

IncarCommand.start(ARGV)

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vasputils-0.1.7 bin/incar
vasputils-0.1.6 bin/incar
vasputils-0.1.5 bin/incar
vasputils-0.1.4 bin/incar
vasputils-0.1.3 bin/incar