Class: VaspUtils::VaspGeometryOptimizer

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

Defined Under Namespace

Classes: LatestDirStartedError, NoIntegerEndedNameError, NoVaspDirError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ VaspGeometryOptimizer

Returns a new instance of VaspGeometryOptimizer.



22
23
24
25
26
# File 'lib/vasputils/vaspgeometryoptimizer.rb', line 22

def initialize(dir)
  super(dir)
  @lockdir    = "lock_vaspgeomopt"
  latest_dir # to check.
end

Class Method Details

.next_name(name) ⇒ Object

Return incremented name. If the name of VaspDir ends with string of integer, return incremental value with the basename. If not ended with integer, this method assume “00”



32
33
34
35
36
# File 'lib/vasputils/vaspgeometryoptimizer.rb', line 32

def self.next_name(name)
  basename = name.sub(/(\d*)$/, "")
  new_num = $1.to_i + 1
  return basename + sprintf("%02d", new_num)
end

Instance Method Details

#calculateObject

注目した VaspDir が yet なら実行し、続ける。 yet 以外なら例外。 VaspDir になっているか。



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/vasputils/vaspgeometryoptimizer.rb', line 41

def calculate
  #pp latest_dir.dir
  $stdout.puts "Calculate #{latest_dir.dir}"
  $stdout.flush

  #pp latest_dir

  latest_dir.start
  #dir = latest_dir
  #while (! finished?)
  #  raise LatestDirStartedError if dir.state == :started
  #  dir.start
  #  if dir.finished?
  #    break
  #  else
  #    #dir = prepare_next
  #    puts "Geometry optimization fihished. Exit."
  #  end
  #end
  #puts "Geometry optimization fihished. Exit."
  #sleep 1 # for interrupt
end

#finished?Boolean

latest_dir から返って来る最新の VaspDir が finished? で真を返し、 かつ Iteration が 1 であるか。 Note: even when the geometry optimization does not include lattice shape,

calculate will continued till to converge to Iter 1 calculation.

Returns:

  • (Boolean)


68
69
70
71
72
# File 'lib/vasputils/vaspgeometryoptimizer.rb', line 68

def finished?
  return false unless latest_dir.finished?
  return false unless latest_dir.outcar[:ionic_steps] == 1
  return true
end

#latest_dirObject

Find latest VaspDir. Return a last VaspDir which has the name by name sort and which can be made as a VaspDir instance. Note: in a series of geometry optimization,

the directory names should have a rule of naming
which can define a method <=>.
Usually, it is simple sort of String.

Raises:



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/vasputils/vaspgeometryoptimizer.rb', line 81

def latest_dir
  Dir.glob("#{@dir}/*").sort.reverse.find do |dir|
    begin
      vd = VaspUtils::VaspDir.new(dir)
      return vd
    rescue VaspUtils::VaspDir::InitializeError
      next
    end
  end
  raise NoVaspDirError, @dir
end