Class: VaspdirCommand

Inherits:
Thor
  • Object
show all
Defined in:
bin/vaspdir

Overview

Command template

Instance Method Summary collapse

Instance Method Details

#clean(*args) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'bin/vaspdir', line 190

def clean(* args)
  targets = args
  targets = [ENV['PWD']] if targets.empty?
  targets.each do |target_dir|
    puts "Directory: #{target_dir}"

    begin
      vd = VaspUtils::VaspDir.new(target_dir)
    rescue VaspUtils::VaspDir::InitializeError
      puts "  Do nothing due to not VaspDir."
      next
    end
    vd.reset_clean
  end
end

#execute(*args) ⇒ Object



170
171
172
# File 'bin/vaspdir', line 170

def execute(* args)
  VaspUtils::VaspDir.execute(args)
end

#init(*args) ⇒ Object



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'bin/vaspdir', line 207

def init(* args)
  targets = args
  targets = [ENV['PWD']] if targets.empty?
  targets.each do |target_dir|
    puts "Directory: #{target_dir}"

    begin
      vd = VaspUtils::VaspDir.new(target_dir)
    rescue VaspUtils::VaspDir::InitializeError
      puts "  Do nothing due to not VaspDir."
      next
    end
    vd.reset_initialize
  end
end

#qsub(*args) ⇒ Object



183
184
185
186
187
# File 'bin/vaspdir', line 183

def qsub(* args)
  new_options = Marshal.load(Marshal.dump(options))
  new_options[:command] = "#{__FILE__} execute"
  VaspUtils::VaspDir.qsub(args, new_options)
end

#show(*args) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'bin/vaspdir', line 75

def show(* args)
  tgt_properties = []
  show_dir_states = []

  show_dir_states << :finished   if options[:finished]
  show_dir_states << :yet        if options[:yet]
  show_dir_states << :terminated if options[:terminated]
  show_dir_states << :started    if options[:started]
  tgt_properties << :state       if options[:state]
  tgt_properties << :toten       if options[:toten]
  tgt_properties << :ionic_steps if options[:ionic_steps]
  tgt_properties << :last_update if options[:last_update]
  tgt_properties << :encut       if options[:encut]
  tgt_properties << :kpoints     if options[:kpoints]

  dirs = args
  dirs = ["."] if args.empty?

  if options[:all_items]
    tgt_properties = INSPECT_ALL_ITEMS
  elsif options[:dirs_with_matches]
    tgt_properties = [:dir]
  elsif tgt_properties == nil || tgt_properties.empty?
    tgt_properties = INSPECT_DEFAULT_ITEMS
  else
    tgt_properties = tgt_properties.push :dir
  end

  unless options[:dirs_with_matches]
    # show title of items.
    results = {
      :klass_name => "TYPE",
      :kpoints    => "KPOINTS",
      :encut      => "ENCUT",
      :state      => "STATE",
      :toten      => "TOTEN",
      :i_step     => "I_S", #I_S is ionic steps
      :e_step     => "E_S", #E_S is electronic steps
      :time       => "LAST_UPDATE_AGO",
      :dir        => "DIR"
    }
    show_items(results, tgt_properties)
  end

  dirs.each do |dir|
    next unless File.directory? dir
    begin
      klass_name = "VaspDir"
      calc = VaspUtils::VaspDir.new(dir)
      state = calc.state
      begin
        outcar = calc.outcar
        toten  = sprintf("%9.6f", outcar[:totens][-1].to_f)
        i_step = outcar[:ionic_steps]
        e_step = outcar[:electronic_steps]
        time = form_time(Time.now - calc.latest_modified_time)
        kp = calc.kpoints

        if kp.scheme == :automatic
          k_str = kp.mesh.join("x")
        else
          k_str = kp.points.size.to_s
        end

        encut = calc.incar["ENCUT"]
      rescue
        toten = i_step = e_step = time = k_str = encut = ""
      end

    rescue VaspUtils::VaspDir::InitializeError
      klass_name = "-------"
    end
    results = {
      :klass_name => klass_name,
      :kpoints    => k_str,
      :encut      => encut,
      :state      => state,
      :toten      => toten,
      :i_step     => i_step,
      :e_step     => e_step,
      :time       => time,
      :dir        => dir,
    }

    if show_dir_states.empty?
      show_items(results, tgt_properties)
    else
      if show_dir_states.include? results[:state]
        show_items(results, tgt_properties)
      end
    end
  end
end